Completed
Branch BUG-10236-FIX-RESET-CAPABILITI... (cbd980)
by
unknown
26:22 queued 14:04
created
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 3 patches
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
     {
26 26
         parent::__construct($routing);
27 27
         if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
28
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
29
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
30
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
31 31
         }
32 32
     }
33 33
 
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
     protected function _extend_page_config()
37 37
     {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
38
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
39 39
         //is there a evt_id in the request?
40 40
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41 41
             ? $this->_req_data['EVT_ID']
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273 273
         //make sure this is only when editing
274 274
         if ( ! empty($id)) {
275
-            $href  = EE_Admin_Page::add_query_args_and_nonce(
275
+            $href = EE_Admin_Page::add_query_args_and_nonce(
276 276
                 array('action' => 'duplicate_event', 'EVT_ID' => $id),
277 277
                 $this->_admin_base_url
278 278
             );
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
     {
320 320
         wp_register_script(
321 321
             'ee-event-editor-heartbeat',
322
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
322
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
323 323
             array('ee_admin_js', 'heartbeat'),
324 324
             EVENT_ESPRESSO_VERSION,
325 325
             true
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
     public function add_additional_datetime_button($template, $template_args)
345 345
     {
346 346
         return EEH_Template::display_template(
347
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
347
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
348 348
             $template_args,
349 349
             true
350 350
         );
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
     public function add_datetime_clone_button($template, $template_args)
361 361
     {
362 362
         return EEH_Template::display_template(
363
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
363
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
364 364
             $template_args,
365 365
             true
366 366
         );
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
     public function datetime_timezones_template($template, $template_args)
377 377
     {
378 378
         return EEH_Template::display_template(
379
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
379
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
380 380
             $template_args,
381 381
             true
382 382
         );
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
         $orig_ven = $orig_event->get_many_related('Venue');
527 527
         //reset the ID and modify other details to make it clear this is a dupe
528 528
         $new_event->set('EVT_ID', 0);
529
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
529
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
530 530
         $new_event->set('EVT_name', $new_name);
531 531
         $new_event->set(
532 532
             'EVT_slug',
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
             $new_event->_add_relation_to($new_dtt, 'Datetime');
592 592
             $new_event->save();
593 593
             //now let's get the ticket relations setup.
594
-            foreach ((array)$orig_tkts as $orig_tkt) {
594
+            foreach ((array) $orig_tkts as $orig_tkt) {
595 595
                 //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
596 596
                 if ( ! $orig_tkt instanceof EE_Ticket) {
597 597
                     continue;
@@ -685,8 +685,8 @@  discard block
 block discarded – undo
685 685
             array('action' => 'sample_export_file'),
686 686
             $this->_admin_base_url
687 687
         );
688
-        $content                                    = EEH_Template::display_template(
689
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
688
+        $content = EEH_Template::display_template(
689
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
690 690
             $this->_template_args,
691 691
             true
692 692
         );
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
      */
705 705
     protected function _import_events()
706 706
     {
707
-        require_once(EE_CLASSES . 'EE_Import.class.php');
707
+        require_once(EE_CLASSES.'EE_Import.class.php');
708 708
         $success = EE_Import::instance()->import();
709 709
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
710 710
     }
@@ -733,9 +733,9 @@  discard block
 block discarded – undo
733 733
             'action' => 'all_event_data',
734 734
             'EVT_ID' => $event_ids,
735 735
         );
736
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
737
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
738
-            require_once(EE_CLASSES . 'EE_Export.class.php');
736
+        $this->_req_data = array_merge($this->_req_data, $new_request_args);
737
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
738
+            require_once(EE_CLASSES.'EE_Export.class.php');
739 739
             $EE_Export = EE_Export::instance($this->_req_data);
740 740
             $EE_Export->export();
741 741
         }
@@ -756,9 +756,9 @@  discard block
 block discarded – undo
756 756
             'action'       => 'categories',
757 757
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
758 758
         );
759
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
760
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
761
-            require_once(EE_CLASSES . 'EE_Export.class.php');
759
+        $this->_req_data = array_merge($this->_req_data, $new_request_args);
760
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
761
+            require_once(EE_CLASSES.'EE_Export.class.php');
762 762
             $EE_Export = EE_Export::instance($this->_req_data);
763 763
             $EE_Export->export();
764 764
         }
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
         $this->_set_add_edit_form_tags('update_template_settings');
793 793
         $this->_set_publish_post_box_vars(null, false, false, null, false);
794 794
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
795
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
795
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
796 796
             $this->_template_args,
797 797
             true
798 798
         );
@@ -909,7 +909,7 @@  discard block
 block discarded – undo
909 909
             $default_reg_status_values
910 910
         );
911 911
         EEH_Template::display_template(
912
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
912
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
913 913
             $template_args
914 914
         );
915 915
     }
@@ -1016,13 +1016,13 @@  discard block
 block discarded – undo
1016 1016
     {
1017 1017
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1018 1018
             'DTT_EVT_start',
1019
-            date('Y-m-d') . ' 00:00:00',
1019
+            date('Y-m-d').' 00:00:00',
1020 1020
             'Y-m-d H:i:s',
1021 1021
             'UTC'
1022 1022
         );
1023
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1023
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1024 1024
             'DTT_EVT_start',
1025
-            date('Y-m-d') . ' 23:59:59',
1025
+            date('Y-m-d').' 23:59:59',
1026 1026
             'Y-m-d H:i:s',
1027 1027
             'UTC'
1028 1028
         );
@@ -1049,13 +1049,13 @@  discard block
 block discarded – undo
1049 1049
         $days_this_month = date('t');
1050 1050
         $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1051 1051
             'DTT_EVT_start',
1052
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1052
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1053 1053
             'Y-m-d H:i:s',
1054 1054
             'UTC'
1055 1055
         );
1056 1056
         $end = EEM_Datetime::instance()->convert_datetime_for_query(
1057 1057
             'DTT_EVT_start',
1058
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1058
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1059 1059
             'Y-m-d H:i:s',
1060 1060
             'UTC'
1061 1061
         );
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
         $offset       = ($current_page - 1) * $per_page;
1121 1121
         $limit        = array($offset, $per_page);
1122 1122
         if (isset($this->_req_data['s'])) {
1123
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1123
+            $sstr         = '%'.$this->_req_data['s'].'%';
1124 1124
             $_where['OR'] = array(
1125 1125
                 'TKT_name'        => array('LIKE', $sstr),
1126 1126
                 'TKT_description' => array('LIKE', $sstr),
Please login to merge, or discard this patch.
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     /**
340 340
      * @param $template
341 341
      * @param $template_args
342
-     * @return mixed
342
+     * @return string
343 343
      */
344 344
     public function add_additional_datetime_button($template, $template_args)
345 345
     {
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
     /**
356 356
      * @param $template
357 357
      * @param $template_args
358
-     * @return mixed
358
+     * @return string
359 359
      */
360 360
     public function add_datetime_clone_button($template, $template_args)
361 361
     {
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
     /**
372 372
      * @param $template
373 373
      * @param $template_args
374
-     * @return mixed
374
+     * @return string
375 375
      */
376 376
     public function datetime_timezones_template($template, $template_args)
377 377
     {
Please login to merge, or discard this patch.
Indentation   +1221 added lines, -1221 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -16,1226 +16,1226 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Extend_Events_Admin_Page constructor.
21
-     *
22
-     * @param bool $routing
23
-     */
24
-    public function __construct($routing = true)
25
-    {
26
-        parent::__construct($routing);
27
-        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
-        }
32
-    }
33
-
34
-
35
-
36
-    protected function _extend_page_config()
37
-    {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
-        //is there a evt_id in the request?
40
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
-            ? $this->_req_data['EVT_ID']
42
-            : 0;
43
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
-        //tkt_id?
45
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
-            ? $this->_req_data['TKT_ID']
47
-            : 0;
48
-        $new_page_routes = array(
49
-            'duplicate_event'          => array(
50
-                'func'       => '_duplicate_event',
51
-                'capability' => 'ee_edit_event',
52
-                'obj_id'     => $evt_id,
53
-                'noheader'   => true,
54
-            ),
55
-            'ticket_list_table'        => array(
56
-                'func'       => '_tickets_overview_list_table',
57
-                'capability' => 'ee_read_default_tickets',
58
-            ),
59
-            'trash_ticket'             => array(
60
-                'func'       => '_trash_or_restore_ticket',
61
-                'capability' => 'ee_delete_default_ticket',
62
-                'obj_id'     => $tkt_id,
63
-                'noheader'   => true,
64
-                'args'       => array('trash' => true),
65
-            ),
66
-            'trash_tickets'            => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_tickets',
69
-                'noheader'   => true,
70
-                'args'       => array('trash' => true),
71
-            ),
72
-            'restore_ticket'           => array(
73
-                'func'       => '_trash_or_restore_ticket',
74
-                'capability' => 'ee_delete_default_ticket',
75
-                'obj_id'     => $tkt_id,
76
-                'noheader'   => true,
77
-            ),
78
-            'restore_tickets'          => array(
79
-                'func'       => '_trash_or_restore_ticket',
80
-                'capability' => 'ee_delete_default_tickets',
81
-                'noheader'   => true,
82
-            ),
83
-            'delete_ticket'            => array(
84
-                'func'       => '_delete_ticket',
85
-                'capability' => 'ee_delete_default_ticket',
86
-                'obj_id'     => $tkt_id,
87
-                'noheader'   => true,
88
-            ),
89
-            'delete_tickets'           => array(
90
-                'func'       => '_delete_ticket',
91
-                'capability' => 'ee_delete_default_tickets',
92
-                'noheader'   => true,
93
-            ),
94
-            'import_page'              => array(
95
-                'func'       => '_import_page',
96
-                'capability' => 'import',
97
-            ),
98
-            'import'                   => array(
99
-                'func'       => '_import_events',
100
-                'capability' => 'import',
101
-                'noheader'   => true,
102
-            ),
103
-            'import_events'            => array(
104
-                'func'       => '_import_events',
105
-                'capability' => 'import',
106
-                'noheader'   => true,
107
-            ),
108
-            'export_events'            => array(
109
-                'func'       => '_events_export',
110
-                'capability' => 'export',
111
-                'noheader'   => true,
112
-            ),
113
-            'export_categories'        => array(
114
-                'func'       => '_categories_export',
115
-                'capability' => 'export',
116
-                'noheader'   => true,
117
-            ),
118
-            'sample_export_file'       => array(
119
-                'func'       => '_sample_export_file',
120
-                'capability' => 'export',
121
-                'noheader'   => true,
122
-            ),
123
-            'update_template_settings' => array(
124
-                'func'       => '_update_template_settings',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ),
128
-        );
129
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
-        //partial route/config override
131
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
-        $this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
-        $this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
-        $this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
-        $this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
-        //add tickets tab but only if there are more than one default ticket!
138
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
-            array(array('TKT_is_default' => 1)),
140
-            'TKT_ID',
141
-            true
142
-        );
143
-        if ($tkt_count > 1) {
144
-            $new_page_config = array(
145
-                'ticket_list_table' => array(
146
-                    'nav'           => array(
147
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
148
-                        'order' => 60,
149
-                    ),
150
-                    'list_table'    => 'Tickets_List_Table',
151
-                    'require_nonce' => false,
152
-                ),
153
-            );
154
-        }
155
-        //template settings
156
-        $new_page_config['template_settings'] = array(
157
-            'nav'           => array(
158
-                'label' => esc_html__('Templates', 'event_espresso'),
159
-                'order' => 30,
160
-            ),
161
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
-            'help_tabs'     => array(
163
-                'general_settings_templates_help_tab' => array(
164
-                    'title'    => esc_html__('Templates', 'event_espresso'),
165
-                    'filename' => 'general_settings_templates',
166
-                ),
167
-            ),
168
-            'help_tour'     => array('Templates_Help_Tour'),
169
-            'require_nonce' => false,
170
-        );
171
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
172
-        //add filters and actions
173
-        //modifying _views
174
-        add_filter(
175
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
-            array($this, 'add_additional_datetime_button'),
177
-            10,
178
-            2
179
-        );
180
-        add_filter(
181
-            'FHEE_event_datetime_metabox_clone_button_template',
182
-            array($this, 'add_datetime_clone_button'),
183
-            10,
184
-            2
185
-        );
186
-        add_filter(
187
-            'FHEE_event_datetime_metabox_timezones_template',
188
-            array($this, 'datetime_timezones_template'),
189
-            10,
190
-            2
191
-        );
192
-        //filters for event list table
193
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
-        add_filter(
195
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
-            array($this, 'extra_list_table_actions'),
197
-            10,
198
-            2
199
-        );
200
-        //legend item
201
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
-        add_action('admin_init', array($this, 'admin_init'));
203
-        //heartbeat stuff
204
-        add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
-    }
206
-
207
-
208
-
209
-    /**
210
-     * admin_init
211
-     */
212
-    public function admin_init()
213
-    {
214
-        EE_Registry::$i18n_js_strings = array_merge(
215
-            EE_Registry::$i18n_js_strings,
216
-            array(
217
-                'image_confirm'          => esc_html__(
218
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
-                    'event_espresso'
220
-                ),
221
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
-            )
227
-        );
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
-     * accordingly.
235
-     *
236
-     * @param array $response The existing heartbeat response array.
237
-     * @param array $data     The incoming data package.
238
-     * @return array  possibly appended response.
239
-     */
240
-    public function heartbeat_response($response, $data)
241
-    {
242
-        /**
243
-         * check whether count of tickets is approaching the potential
244
-         * limits for the server.
245
-         */
246
-        if ( ! empty($data['input_count'])) {
247
-            $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
-                $data['input_count']
249
-            );
250
-        }
251
-        return $response;
252
-    }
253
-
254
-
255
-
256
-    protected function _add_screen_options_ticket_list_table()
257
-    {
258
-        $this->_per_page_screen_option();
259
-    }
260
-
261
-
262
-
263
-    /**
264
-     * @param string $return
265
-     * @param int    $id
266
-     * @param string $new_title
267
-     * @param string $new_slug
268
-     * @return string
269
-     */
270
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
-    {
272
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
-        //make sure this is only when editing
274
-        if ( ! empty($id)) {
275
-            $href  = EE_Admin_Page::add_query_args_and_nonce(
276
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
-                $this->_admin_base_url
278
-            );
279
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
280
-            $return .= '<a href="'
281
-                       . $href
282
-                       . '" title="'
283
-                       . $title
284
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
-                       . $title
286
-                       . '</button>';
287
-        }
288
-        return $return;
289
-    }
290
-
291
-
292
-
293
-    public function _set_list_table_views_ticket_list_table()
294
-    {
295
-        $this->_views = array(
296
-            'all'     => array(
297
-                'slug'        => 'all',
298
-                'label'       => esc_html__('All', 'event_espresso'),
299
-                'count'       => 0,
300
-                'bulk_action' => array(
301
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
-                ),
303
-            ),
304
-            'trashed' => array(
305
-                'slug'        => 'trashed',
306
-                'label'       => esc_html__('Trash', 'event_espresso'),
307
-                'count'       => 0,
308
-                'bulk_action' => array(
309
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
-                ),
312
-            ),
313
-        );
314
-    }
315
-
316
-
317
-
318
-    public function load_scripts_styles_edit()
319
-    {
320
-        wp_register_script(
321
-            'ee-event-editor-heartbeat',
322
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
-            array('ee_admin_js', 'heartbeat'),
324
-            EVENT_ESPRESSO_VERSION,
325
-            true
326
-        );
327
-        wp_enqueue_script('ee-accounting');
328
-        //styles
329
-        wp_enqueue_style('espresso-ui-theme');
330
-        wp_enqueue_script('event_editor_js');
331
-        wp_enqueue_script('ee-event-editor-heartbeat');
332
-    }
333
-
334
-
335
-
336
-    /**
337
-     * @param $template
338
-     * @param $template_args
339
-     * @return mixed
340
-     */
341
-    public function add_additional_datetime_button($template, $template_args)
342
-    {
343
-        return EEH_Template::display_template(
344
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
345
-            $template_args,
346
-            true
347
-        );
348
-    }
349
-
350
-
351
-
352
-    /**
353
-     * @param $template
354
-     * @param $template_args
355
-     * @return mixed
356
-     */
357
-    public function add_datetime_clone_button($template, $template_args)
358
-    {
359
-        return EEH_Template::display_template(
360
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
361
-            $template_args,
362
-            true
363
-        );
364
-    }
365
-
366
-
367
-
368
-    /**
369
-     * @param $template
370
-     * @param $template_args
371
-     * @return mixed
372
-     */
373
-    public function datetime_timezones_template($template, $template_args)
374
-    {
375
-        return EEH_Template::display_template(
376
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
377
-            $template_args,
378
-            true
379
-        );
380
-    }
381
-
382
-
383
-
384
-    protected function _set_list_table_views_default()
385
-    {
386
-        parent::_set_list_table_views_default();
387
-        $new_views = array(
388
-            'today' => array(
389
-                'slug'        => 'today',
390
-                'label'       => esc_html__('Today', 'event_espresso'),
391
-                'count'       => $this->total_events_today(),
392
-                'bulk_action' => array(
393
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
394
-                ),
395
-            ),
396
-            'month' => array(
397
-                'slug'        => 'month',
398
-                'label'       => esc_html__('This Month', 'event_espresso'),
399
-                'count'       => $this->total_events_this_month(),
400
-                'bulk_action' => array(
401
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
-                ),
403
-            ),
404
-        );
405
-        $this->_views = array_merge($this->_views, $new_views);
406
-    }
407
-
408
-
409
-
410
-    /**
411
-     * @param array     $action_links
412
-     * @param \EE_Event $event
413
-     * @return array
414
-     */
415
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
416
-    {
417
-        if (
418
-        EE_Registry::instance()->CAP->current_user_can(
419
-            'ee_read_registrations',
420
-            'espresso_registrations_reports',
421
-            $event->ID()
422
-        )
423
-        ) {
424
-            $reports_query_args = array(
425
-                'action' => 'reports',
426
-                'EVT_ID' => $event->ID(),
427
-            );
428
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
429
-            $action_links[]     = '<a href="'
430
-                                  . $reports_link
431
-                                  . '" title="'
432
-                                  . esc_attr__('View Report', 'event_espresso')
433
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
434
-                                  . "\n\t";
435
-        }
436
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
437
-            EE_Registry::instance()->load_helper('MSG_Template');
438
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
439
-                'see_notifications_for',
440
-                null,
441
-                array('EVT_ID' => $event->ID())
442
-            );
443
-        }
444
-        return $action_links;
445
-    }
446
-
447
-
448
-
449
-    /**
450
-     * @param $items
451
-     * @return mixed
452
-     */
453
-    public function additional_legend_items($items)
454
-    {
455
-        if (
456
-        EE_Registry::instance()->CAP->current_user_can(
457
-            'ee_read_registrations',
458
-            'espresso_registrations_reports'
459
-        )
460
-        ) {
461
-            $items['reports'] = array(
462
-                'class' => 'dashicons dashicons-chart-bar',
463
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
464
-            );
465
-        }
466
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
467
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
468
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
469
-                $items['view_related_messages'] = array(
470
-                    'class' => $related_for_icon['css_class'],
471
-                    'desc'  => $related_for_icon['label'],
472
-                );
473
-            }
474
-        }
475
-        return $items;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * This is the callback method for the duplicate event route
482
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
483
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
484
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
485
-     * After duplication the redirect is to the new event edit page.
486
-     *
487
-     * @return void
488
-     * @access protected
489
-     * @throws EE_Error If EE_Event is not available with given ID
490
-     */
491
-    protected function _duplicate_event()
492
-    {
493
-        // first make sure the ID for the event is in the request.
494
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
495
-        if ( ! isset($this->_req_data['EVT_ID'])) {
496
-            EE_Error::add_error(
497
-                esc_html__(
498
-                    'In order to duplicate an event an Event ID is required.  None was given.',
499
-                    'event_espresso'
500
-                ),
501
-                __FILE__,
502
-                __FUNCTION__,
503
-                __LINE__
504
-            );
505
-            $this->_redirect_after_action(false, '', '', array(), true);
506
-            return;
507
-        }
508
-        //k we've got EVT_ID so let's use that to get the event we'll duplicate
509
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
510
-        if ( ! $orig_event instanceof EE_Event) {
511
-            throw new EE_Error(
512
-                sprintf(
513
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
514
-                    $this->_req_data['EVT_ID']
515
-                )
516
-            );
517
-        }
518
-        //k now let's clone the $orig_event before getting relations
519
-        $new_event = clone $orig_event;
520
-        //original datetimes
521
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
522
-        //other original relations
523
-        $orig_ven = $orig_event->get_many_related('Venue');
524
-        //reset the ID and modify other details to make it clear this is a dupe
525
-        $new_event->set('EVT_ID', 0);
526
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
527
-        $new_event->set('EVT_name', $new_name);
528
-        $new_event->set(
529
-            'EVT_slug',
530
-            wp_unique_post_slug(
531
-                sanitize_title($orig_event->name()),
532
-                0,
533
-                'publish',
534
-                'espresso_events',
535
-                0
536
-            )
537
-        );
538
-        $new_event->set('status', 'draft');
539
-        //duplicate discussion settings
540
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
541
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
542
-        //save the new event
543
-        $new_event->save();
544
-        //venues
545
-        foreach ($orig_ven as $ven) {
546
-            $new_event->_add_relation_to($ven, 'Venue');
547
-        }
548
-        $new_event->save();
549
-        //now we need to get the question group relations and handle that
550
-        //first primary question groups
551
-        $orig_primary_qgs = $orig_event->get_many_related(
552
-            'Question_Group',
553
-            array(array('Event_Question_Group.EQG_primary' => 1))
554
-        );
555
-        if ( ! empty($orig_primary_qgs)) {
556
-            foreach ($orig_primary_qgs as $id => $obj) {
557
-                if ($obj instanceof EE_Question_Group) {
558
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
559
-                }
560
-            }
561
-        }
562
-        //next additional attendee question groups
563
-        $orig_additional_qgs = $orig_event->get_many_related(
564
-            'Question_Group',
565
-            array(array('Event_Question_Group.EQG_primary' => 0))
566
-        );
567
-        if ( ! empty($orig_additional_qgs)) {
568
-            foreach ($orig_additional_qgs as $id => $obj) {
569
-                if ($obj instanceof EE_Question_Group) {
570
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
571
-                }
572
-            }
573
-        }
574
-        //now save
575
-        $new_event->save();
576
-        //k now that we have the new event saved we can loop through the datetimes and start adding relations.
577
-        $cloned_tickets = array();
578
-        foreach ($orig_datetimes as $orig_dtt) {
579
-            if ( ! $orig_dtt instanceof EE_Datetime) {
580
-                continue;
581
-            }
582
-            $new_dtt   = clone $orig_dtt;
583
-            $orig_tkts = $orig_dtt->tickets();
584
-            //save new dtt then add to event
585
-            $new_dtt->set('DTT_ID', 0);
586
-            $new_dtt->set('DTT_sold', 0);
587
-            $new_dtt->save();
588
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
589
-            $new_event->save();
590
-            //now let's get the ticket relations setup.
591
-            foreach ((array)$orig_tkts as $orig_tkt) {
592
-                //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
593
-                if ( ! $orig_tkt instanceof EE_Ticket) {
594
-                    continue;
595
-                }
596
-                //is this ticket archived?  If it is then let's skip
597
-                if ($orig_tkt->get('TKT_deleted')) {
598
-                    continue;
599
-                }
600
-                // does this original ticket already exist in the clone_tickets cache?
601
-                //  If so we'll just use the new ticket from it.
602
-                if (isset($cloned_tickets[$orig_tkt->ID()])) {
603
-                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
604
-                } else {
605
-                    $new_tkt = clone $orig_tkt;
606
-                    //get relations on the $orig_tkt that we need to setup.
607
-                    $orig_prices = $orig_tkt->prices();
608
-                    $new_tkt->set('TKT_ID', 0);
609
-                    $new_tkt->set('TKT_sold', 0);
610
-                    $new_tkt->set('TKT_reserved', 0);
611
-                    $new_tkt->save(); //make sure new ticket has ID.
612
-                    //price relations on new ticket need to be setup.
613
-                    foreach ($orig_prices as $orig_price) {
614
-                        $new_price = clone $orig_price;
615
-                        $new_price->set('PRC_ID', 0);
616
-                        $new_price->save();
617
-                        $new_tkt->_add_relation_to($new_price, 'Price');
618
-                        $new_tkt->save();
619
-                    }
620
-                }
621
-                // k now we can add the new ticket as a relation to the new datetime
622
-                // and make sure its added to our cached $cloned_tickets array
623
-                // for use with later datetimes that have the same ticket.
624
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
625
-                $new_dtt->save();
626
-                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
627
-            }
628
-        }
629
-        //clone taxonomy information
630
-        $taxonomies_to_clone_with = apply_filters(
631
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
632
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
633
-        );
634
-        //get terms for original event (notice)
635
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
636
-        //loop through terms and add them to new event.
637
-        foreach ($orig_terms as $term) {
638
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
639
-        }
640
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
641
-        //now let's redirect to the edit page for this duplicated event if we have a new event id.
642
-        if ($new_event->ID()) {
643
-            $redirect_args = array(
644
-                'post'   => $new_event->ID(),
645
-                'action' => 'edit',
646
-            );
647
-            EE_Error::add_success(
648
-                esc_html__(
649
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
650
-                    'event_espresso'
651
-                )
652
-            );
653
-        } else {
654
-            $redirect_args = array(
655
-                'action' => 'default',
656
-            );
657
-            EE_Error::add_error(
658
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
659
-                __FILE__,
660
-                __FUNCTION__,
661
-                __LINE__
662
-            );
663
-        }
664
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
665
-    }
666
-
667
-
668
-    protected function _import_page()
669
-    {
670
-        $title                                      = esc_html__('Import', 'event_espresso');
671
-        $intro                                      = esc_html__(
672
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
673
-            'event_espresso'
674
-        );
675
-        $form_url                                   = EVENTS_ADMIN_URL;
676
-        $action                                     = 'import_events';
677
-        $type                                       = 'csv';
678
-        $this->_template_args['form']               = EE_Import::instance()->upload_form(
679
-            $title, $intro, $form_url, $action, $type
680
-        );
681
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
682
-            array('action' => 'sample_export_file'),
683
-            $this->_admin_base_url
684
-        );
685
-        $content                                    = EEH_Template::display_template(
686
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
687
-            $this->_template_args,
688
-            true
689
-        );
690
-        $this->_template_args['admin_page_content'] = $content;
691
-        $this->display_admin_page_with_sidebar();
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * _import_events
698
-     * This handles displaying the screen and running imports for importing events.
699
-     *
700
-     * @return void
701
-     */
702
-    protected function _import_events()
703
-    {
704
-        require_once(EE_CLASSES . 'EE_Import.class.php');
705
-        $success = EE_Import::instance()->import();
706
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * _events_export
713
-     * Will export all (or just the given event) to a Excel compatible file.
714
-     *
715
-     * @access protected
716
-     * @return void
717
-     */
718
-    protected function _events_export()
719
-    {
720
-        if (isset($this->_req_data['EVT_ID'])) {
721
-            $event_ids = $this->_req_data['EVT_ID'];
722
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
723
-            $event_ids = $this->_req_data['EVT_IDs'];
724
-        } else {
725
-            $event_ids = null;
726
-        }
727
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
728
-        $new_request_args = array(
729
-            'export' => 'report',
730
-            'action' => 'all_event_data',
731
-            'EVT_ID' => $event_ids,
732
-        );
733
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
734
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
735
-            require_once(EE_CLASSES . 'EE_Export.class.php');
736
-            $EE_Export = EE_Export::instance($this->_req_data);
737
-            $EE_Export->export();
738
-        }
739
-    }
740
-
741
-
742
-
743
-    /**
744
-     * handle category exports()
745
-     *
746
-     * @return void
747
-     */
748
-    protected function _categories_export()
749
-    {
750
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
751
-        $new_request_args = array(
752
-            'export'       => 'report',
753
-            'action'       => 'categories',
754
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
755
-        );
756
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
757
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
758
-            require_once(EE_CLASSES . 'EE_Export.class.php');
759
-            $EE_Export = EE_Export::instance($this->_req_data);
760
-            $EE_Export->export();
761
-        }
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * Creates a sample CSV file for importing
768
-     */
769
-    protected function _sample_export_file()
770
-    {
771
-        //		require_once(EE_CLASSES . 'EE_Export.class.php');
772
-        EE_Export::instance()->export_sample();
773
-    }
774
-
775
-
776
-
777
-    /*************        Template Settings        *************/
778
-    protected function _template_settings()
779
-    {
780
-        $this->_template_args['values'] = $this->_yes_no_values;
781
-        /**
782
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
783
-         * from General_Settings_Admin_Page to here.
784
-         */
785
-        $this->_template_args = apply_filters(
786
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
787
-            $this->_template_args
788
-        );
789
-        $this->_set_add_edit_form_tags('update_template_settings');
790
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
791
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
792
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
793
-            $this->_template_args,
794
-            true
795
-        );
796
-        $this->display_admin_page_with_sidebar();
797
-    }
798
-
799
-
800
-
801
-    protected function _update_template_settings()
802
-    {
803
-        /**
804
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
-         * from General_Settings_Admin_Page to here.
806
-         */
807
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
808
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
809
-            EE_Registry::instance()->CFG->template_settings,
810
-            $this->_req_data
811
-        );
812
-        //update custom post type slugs and detect if we need to flush rewrite rules
813
-        $old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
814
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
815
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
816
-            : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
817
-        $what                                              = 'Template Settings';
818
-        $success                                           = $this->_update_espresso_configuration(
819
-            $what,
820
-            EE_Registry::instance()->CFG->template_settings,
821
-            __FILE__,
822
-            __FUNCTION__,
823
-            __LINE__
824
-        );
825
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
826
-            update_option('ee_flush_rewrite_rules', true);
827
-        }
828
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
829
-    }
830
-
831
-
832
-
833
-    /**
834
-     * _premium_event_editor_meta_boxes
835
-     * add all metaboxes related to the event_editor
836
-     *
837
-     * @access protected
838
-     * @return void
839
-     */
840
-    protected function _premium_event_editor_meta_boxes()
841
-    {
842
-        $this->verify_cpt_object();
843
-        add_meta_box(
844
-            'espresso_event_editor_event_options',
845
-            esc_html__('Event Registration Options', 'event_espresso'),
846
-            array($this, 'registration_options_meta_box'),
847
-            $this->page_slug,
848
-            'side',
849
-            'core'
850
-        );
851
-    }
852
-
853
-
854
-
855
-    /**
856
-     * override caf metabox
857
-     *
858
-     * @return void
859
-     */
860
-    public function registration_options_meta_box()
861
-    {
862
-        $yes_no_values = array(
863
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
864
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
865
-        );
866
-        $default_reg_status_values = EEM_Registration::reg_status_array(
867
-            array(
868
-                EEM_Registration::status_id_cancelled,
869
-                EEM_Registration::status_id_declined,
870
-                EEM_Registration::status_id_incomplete,
871
-                EEM_Registration::status_id_wait_list,
872
-            ),
873
-            true
874
-        );
875
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
876
-        $template_args['_event']                          = $this->_cpt_model_obj;
877
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
878
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
879
-            'default_reg_status',
880
-            $default_reg_status_values,
881
-            $this->_cpt_model_obj->default_registration_status()
882
-        );
883
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
884
-            'display_desc',
885
-            $yes_no_values,
886
-            $this->_cpt_model_obj->display_description()
887
-        );
888
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
889
-            'display_ticket_selector',
890
-            $yes_no_values,
891
-            $this->_cpt_model_obj->display_ticket_selector(),
892
-            '',
893
-            '',
894
-            false
895
-        );
896
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
897
-            'EVT_default_registration_status',
898
-            $default_reg_status_values,
899
-            $this->_cpt_model_obj->default_registration_status()
900
-        );
901
-        $template_args['additional_registration_options'] = apply_filters(
902
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
903
-            '',
904
-            $template_args,
905
-            $yes_no_values,
906
-            $default_reg_status_values
907
-        );
908
-        EEH_Template::display_template(
909
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
910
-            $template_args
911
-        );
912
-    }
913
-
914
-
915
-
916
-    /**
917
-     * wp_list_table_mods for caf
918
-     * ============================
919
-     */
920
-    /**
921
-     * hook into list table filters and provide filters for caffeinated list table
922
-     *
923
-     * @param  array $old_filters    any existing filters present
924
-     * @param  array $list_table_obj the list table object
925
-     * @return array                  new filters
926
-     */
927
-    public function list_table_filters($old_filters, $list_table_obj)
928
-    {
929
-        $filters = array();
930
-        //first month/year filters
931
-        $filters[] = $this->espresso_event_months_dropdown();
932
-        $status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
933
-        //active status dropdown
934
-        if ($status !== 'draft') {
935
-            $filters[] = $this->active_status_dropdown(
936
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
937
-            );
938
-        }
939
-        //category filter
940
-        $filters[] = $this->category_dropdown();
941
-        return array_merge($old_filters, $filters);
942
-    }
943
-
944
-
945
-
946
-    /**
947
-     * espresso_event_months_dropdown
948
-     *
949
-     * @access public
950
-     * @return string                dropdown listing month/year selections for events.
951
-     */
952
-    public function espresso_event_months_dropdown()
953
-    {
954
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
955
-        // Note we need to include any other filters that are set!
956
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
957
-        //categories?
958
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
959
-            ? $this->_req_data['EVT_CAT']
960
-            : null;
961
-        //active status?
962
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
963
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
964
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
965
-    }
966
-
967
-
968
-
969
-    /**
970
-     * returns a list of "active" statuses on the event
971
-     *
972
-     * @param  string $current_value whatever the current active status is
973
-     * @return string
974
-     */
975
-    public function active_status_dropdown($current_value = '')
976
-    {
977
-        $select_name = 'active_status';
978
-        $values      = array(
979
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
980
-            'active'   => esc_html__('Active', 'event_espresso'),
981
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
982
-            'expired'  => esc_html__('Expired', 'event_espresso'),
983
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
984
-        );
985
-        $id          = 'id="espresso-active-status-dropdown-filter"';
986
-        $class       = 'wide';
987
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
988
-    }
989
-
990
-
991
-
992
-    /**
993
-     * output a dropdown of the categories for the category filter on the event admin list table
994
-     *
995
-     * @access  public
996
-     * @return string html
997
-     */
998
-    public function category_dropdown()
999
-    {
1000
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1001
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1002
-    }
1003
-
1004
-
1005
-
1006
-    /**
1007
-     * get total number of events today
1008
-     *
1009
-     * @access public
1010
-     * @return int
1011
-     */
1012
-    public function total_events_today()
1013
-    {
1014
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1015
-            'DTT_EVT_start',
1016
-            date('Y-m-d') . ' 00:00:00',
1017
-            'Y-m-d H:i:s',
1018
-            'UTC'
1019
-        );
1020
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1021
-            'DTT_EVT_start',
1022
-            date('Y-m-d') . ' 23:59:59',
1023
-            'Y-m-d H:i:s',
1024
-            'UTC'
1025
-        );
1026
-        $where = array(
1027
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1028
-        );
1029
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1030
-        return $count;
1031
-    }
1032
-
1033
-
1034
-
1035
-    /**
1036
-     * get total number of events this month
1037
-     *
1038
-     * @access public
1039
-     * @return int
1040
-     */
1041
-    public function total_events_this_month()
1042
-    {
1043
-        //Dates
1044
-        $this_year_r     = date('Y');
1045
-        $this_month_r    = date('m');
1046
-        $days_this_month = date('t');
1047
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1048
-            'DTT_EVT_start',
1049
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1050
-            'Y-m-d H:i:s',
1051
-            'UTC'
1052
-        );
1053
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1054
-            'DTT_EVT_start',
1055
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1056
-            'Y-m-d H:i:s',
1057
-            'UTC'
1058
-        );
1059
-        $where = array(
1060
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1061
-        );
1062
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1063
-        return $count;
1064
-    }
1065
-
1066
-
1067
-
1068
-    /** DEFAULT TICKETS STUFF **/
1069
-    public function _tickets_overview_list_table()
1070
-    {
1071
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1072
-        $this->display_admin_list_table_page_with_no_sidebar();
1073
-    }
1074
-
1075
-
1076
-
1077
-    /**
1078
-     * @param int  $per_page
1079
-     * @param bool $count
1080
-     * @param bool $trashed
1081
-     * @return \EE_Soft_Delete_Base_Class[]|int
1082
-     */
1083
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1084
-    {
1085
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1086
-        $order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1087
-        switch ($orderby) {
1088
-            case 'TKT_name' :
1089
-                $orderby = array('TKT_name' => $order);
1090
-                break;
1091
-            case 'TKT_price' :
1092
-                $orderby = array('TKT_price' => $order);
1093
-                break;
1094
-            case 'TKT_uses' :
1095
-                $orderby = array('TKT_uses' => $order);
1096
-                break;
1097
-            case 'TKT_min' :
1098
-                $orderby = array('TKT_min' => $order);
1099
-                break;
1100
-            case 'TKT_max' :
1101
-                $orderby = array('TKT_max' => $order);
1102
-                break;
1103
-            case 'TKT_qty' :
1104
-                $orderby = array('TKT_qty' => $order);
1105
-                break;
1106
-        }
1107
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1108
-            ? $this->_req_data['paged']
1109
-            : 1;
1110
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1111
-            ? $this->_req_data['perpage']
1112
-            : $per_page;
1113
-        $_where       = array(
1114
-            'TKT_is_default' => 1,
1115
-            'TKT_deleted'    => $trashed,
1116
-        );
1117
-        $offset       = ($current_page - 1) * $per_page;
1118
-        $limit        = array($offset, $per_page);
1119
-        if (isset($this->_req_data['s'])) {
1120
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1121
-            $_where['OR'] = array(
1122
-                'TKT_name'        => array('LIKE', $sstr),
1123
-                'TKT_description' => array('LIKE', $sstr),
1124
-            );
1125
-        }
1126
-        $query_params = array(
1127
-            $_where,
1128
-            'order_by' => $orderby,
1129
-            'limit'    => $limit,
1130
-            'group_by' => 'TKT_ID',
1131
-        );
1132
-        if ($count) {
1133
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1134
-        } else {
1135
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1136
-        }
1137
-    }
1138
-
1139
-
1140
-
1141
-    /**
1142
-     * @param bool $trash
1143
-     */
1144
-    protected function _trash_or_restore_ticket($trash = false)
1145
-    {
1146
-        $success = 1;
1147
-        $TKT = EEM_Ticket::instance();
1148
-        //checkboxes?
1149
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1150
-            //if array has more than one element then success message should be plural
1151
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1152
-            //cycle thru the boxes
1153
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1154
-                if ($trash) {
1155
-                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1156
-                        $success = 0;
1157
-                    }
1158
-                } else {
1159
-                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1160
-                        $success = 0;
1161
-                    }
1162
-                }
1163
-            }
1164
-        } else {
1165
-            //grab single id and trash
1166
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1167
-            if ($trash) {
1168
-                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1169
-                    $success = 0;
1170
-                }
1171
-            } else {
1172
-                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1173
-                    $success = 0;
1174
-                }
1175
-            }
1176
-        }
1177
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1178
-        $query_args  = array(
1179
-            'action' => 'ticket_list_table',
1180
-            'status' => $trash ? '' : 'trashed',
1181
-        );
1182
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1183
-    }
1184
-
1185
-
1186
-
1187
-    protected function _delete_ticket()
1188
-    {
1189
-        $success = 1;
1190
-        //checkboxes?
1191
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1192
-            //if array has more than one element then success message should be plural
1193
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1194
-            //cycle thru the boxes
1195
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1196
-                //delete
1197
-                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1198
-                    $success = 0;
1199
-                }
1200
-            }
1201
-        } else {
1202
-            //grab single id and trash
1203
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1204
-            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1205
-                $success = 0;
1206
-            }
1207
-        }
1208
-        $action_desc = 'deleted';
1209
-        $query_args  = array(
1210
-            'action' => 'ticket_list_table',
1211
-            'status' => 'trashed',
1212
-        );
1213
-        //fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1214
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1215
-            array(array('TKT_is_default' => 1)),
1216
-            'TKT_ID',
1217
-            true
1218
-        )
1219
-        ) {
1220
-            $query_args = array();
1221
-        }
1222
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1223
-    }
1224
-
1225
-
1226
-
1227
-    /**
1228
-     * @param int $TKT_ID
1229
-     * @return bool|int
1230
-     */
1231
-    protected function _delete_the_ticket($TKT_ID)
1232
-    {
1233
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1234
-        $tkt->_remove_relations('Datetime');
1235
-        //delete all related prices first
1236
-        $tkt->delete_related_permanently('Price');
1237
-        return $tkt->delete_permanently();
1238
-    }
19
+	/**
20
+	 * Extend_Events_Admin_Page constructor.
21
+	 *
22
+	 * @param bool $routing
23
+	 */
24
+	public function __construct($routing = true)
25
+	{
26
+		parent::__construct($routing);
27
+		if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
+		}
32
+	}
33
+
34
+
35
+
36
+	protected function _extend_page_config()
37
+	{
38
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
+		//is there a evt_id in the request?
40
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
+			? $this->_req_data['EVT_ID']
42
+			: 0;
43
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
+		//tkt_id?
45
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
+			? $this->_req_data['TKT_ID']
47
+			: 0;
48
+		$new_page_routes = array(
49
+			'duplicate_event'          => array(
50
+				'func'       => '_duplicate_event',
51
+				'capability' => 'ee_edit_event',
52
+				'obj_id'     => $evt_id,
53
+				'noheader'   => true,
54
+			),
55
+			'ticket_list_table'        => array(
56
+				'func'       => '_tickets_overview_list_table',
57
+				'capability' => 'ee_read_default_tickets',
58
+			),
59
+			'trash_ticket'             => array(
60
+				'func'       => '_trash_or_restore_ticket',
61
+				'capability' => 'ee_delete_default_ticket',
62
+				'obj_id'     => $tkt_id,
63
+				'noheader'   => true,
64
+				'args'       => array('trash' => true),
65
+			),
66
+			'trash_tickets'            => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_tickets',
69
+				'noheader'   => true,
70
+				'args'       => array('trash' => true),
71
+			),
72
+			'restore_ticket'           => array(
73
+				'func'       => '_trash_or_restore_ticket',
74
+				'capability' => 'ee_delete_default_ticket',
75
+				'obj_id'     => $tkt_id,
76
+				'noheader'   => true,
77
+			),
78
+			'restore_tickets'          => array(
79
+				'func'       => '_trash_or_restore_ticket',
80
+				'capability' => 'ee_delete_default_tickets',
81
+				'noheader'   => true,
82
+			),
83
+			'delete_ticket'            => array(
84
+				'func'       => '_delete_ticket',
85
+				'capability' => 'ee_delete_default_ticket',
86
+				'obj_id'     => $tkt_id,
87
+				'noheader'   => true,
88
+			),
89
+			'delete_tickets'           => array(
90
+				'func'       => '_delete_ticket',
91
+				'capability' => 'ee_delete_default_tickets',
92
+				'noheader'   => true,
93
+			),
94
+			'import_page'              => array(
95
+				'func'       => '_import_page',
96
+				'capability' => 'import',
97
+			),
98
+			'import'                   => array(
99
+				'func'       => '_import_events',
100
+				'capability' => 'import',
101
+				'noheader'   => true,
102
+			),
103
+			'import_events'            => array(
104
+				'func'       => '_import_events',
105
+				'capability' => 'import',
106
+				'noheader'   => true,
107
+			),
108
+			'export_events'            => array(
109
+				'func'       => '_events_export',
110
+				'capability' => 'export',
111
+				'noheader'   => true,
112
+			),
113
+			'export_categories'        => array(
114
+				'func'       => '_categories_export',
115
+				'capability' => 'export',
116
+				'noheader'   => true,
117
+			),
118
+			'sample_export_file'       => array(
119
+				'func'       => '_sample_export_file',
120
+				'capability' => 'export',
121
+				'noheader'   => true,
122
+			),
123
+			'update_template_settings' => array(
124
+				'func'       => '_update_template_settings',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			),
128
+		);
129
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
+		//partial route/config override
131
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
+		$this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
+		$this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
+		$this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
+		$this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
+		//add tickets tab but only if there are more than one default ticket!
138
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
+			array(array('TKT_is_default' => 1)),
140
+			'TKT_ID',
141
+			true
142
+		);
143
+		if ($tkt_count > 1) {
144
+			$new_page_config = array(
145
+				'ticket_list_table' => array(
146
+					'nav'           => array(
147
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
148
+						'order' => 60,
149
+					),
150
+					'list_table'    => 'Tickets_List_Table',
151
+					'require_nonce' => false,
152
+				),
153
+			);
154
+		}
155
+		//template settings
156
+		$new_page_config['template_settings'] = array(
157
+			'nav'           => array(
158
+				'label' => esc_html__('Templates', 'event_espresso'),
159
+				'order' => 30,
160
+			),
161
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
+			'help_tabs'     => array(
163
+				'general_settings_templates_help_tab' => array(
164
+					'title'    => esc_html__('Templates', 'event_espresso'),
165
+					'filename' => 'general_settings_templates',
166
+				),
167
+			),
168
+			'help_tour'     => array('Templates_Help_Tour'),
169
+			'require_nonce' => false,
170
+		);
171
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
172
+		//add filters and actions
173
+		//modifying _views
174
+		add_filter(
175
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
+			array($this, 'add_additional_datetime_button'),
177
+			10,
178
+			2
179
+		);
180
+		add_filter(
181
+			'FHEE_event_datetime_metabox_clone_button_template',
182
+			array($this, 'add_datetime_clone_button'),
183
+			10,
184
+			2
185
+		);
186
+		add_filter(
187
+			'FHEE_event_datetime_metabox_timezones_template',
188
+			array($this, 'datetime_timezones_template'),
189
+			10,
190
+			2
191
+		);
192
+		//filters for event list table
193
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
+		add_filter(
195
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
+			array($this, 'extra_list_table_actions'),
197
+			10,
198
+			2
199
+		);
200
+		//legend item
201
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
+		add_action('admin_init', array($this, 'admin_init'));
203
+		//heartbeat stuff
204
+		add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
+	}
206
+
207
+
208
+
209
+	/**
210
+	 * admin_init
211
+	 */
212
+	public function admin_init()
213
+	{
214
+		EE_Registry::$i18n_js_strings = array_merge(
215
+			EE_Registry::$i18n_js_strings,
216
+			array(
217
+				'image_confirm'          => esc_html__(
218
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
219
+					'event_espresso'
220
+				),
221
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
222
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
223
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
224
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
225
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
226
+			)
227
+		);
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
234
+	 * accordingly.
235
+	 *
236
+	 * @param array $response The existing heartbeat response array.
237
+	 * @param array $data     The incoming data package.
238
+	 * @return array  possibly appended response.
239
+	 */
240
+	public function heartbeat_response($response, $data)
241
+	{
242
+		/**
243
+		 * check whether count of tickets is approaching the potential
244
+		 * limits for the server.
245
+		 */
246
+		if ( ! empty($data['input_count'])) {
247
+			$response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
248
+				$data['input_count']
249
+			);
250
+		}
251
+		return $response;
252
+	}
253
+
254
+
255
+
256
+	protected function _add_screen_options_ticket_list_table()
257
+	{
258
+		$this->_per_page_screen_option();
259
+	}
260
+
261
+
262
+
263
+	/**
264
+	 * @param string $return
265
+	 * @param int    $id
266
+	 * @param string $new_title
267
+	 * @param string $new_slug
268
+	 * @return string
269
+	 */
270
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
271
+	{
272
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
273
+		//make sure this is only when editing
274
+		if ( ! empty($id)) {
275
+			$href  = EE_Admin_Page::add_query_args_and_nonce(
276
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
277
+				$this->_admin_base_url
278
+			);
279
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
280
+			$return .= '<a href="'
281
+					   . $href
282
+					   . '" title="'
283
+					   . $title
284
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
285
+					   . $title
286
+					   . '</button>';
287
+		}
288
+		return $return;
289
+	}
290
+
291
+
292
+
293
+	public function _set_list_table_views_ticket_list_table()
294
+	{
295
+		$this->_views = array(
296
+			'all'     => array(
297
+				'slug'        => 'all',
298
+				'label'       => esc_html__('All', 'event_espresso'),
299
+				'count'       => 0,
300
+				'bulk_action' => array(
301
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
302
+				),
303
+			),
304
+			'trashed' => array(
305
+				'slug'        => 'trashed',
306
+				'label'       => esc_html__('Trash', 'event_espresso'),
307
+				'count'       => 0,
308
+				'bulk_action' => array(
309
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
310
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
311
+				),
312
+			),
313
+		);
314
+	}
315
+
316
+
317
+
318
+	public function load_scripts_styles_edit()
319
+	{
320
+		wp_register_script(
321
+			'ee-event-editor-heartbeat',
322
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
323
+			array('ee_admin_js', 'heartbeat'),
324
+			EVENT_ESPRESSO_VERSION,
325
+			true
326
+		);
327
+		wp_enqueue_script('ee-accounting');
328
+		//styles
329
+		wp_enqueue_style('espresso-ui-theme');
330
+		wp_enqueue_script('event_editor_js');
331
+		wp_enqueue_script('ee-event-editor-heartbeat');
332
+	}
333
+
334
+
335
+
336
+	/**
337
+	 * @param $template
338
+	 * @param $template_args
339
+	 * @return mixed
340
+	 */
341
+	public function add_additional_datetime_button($template, $template_args)
342
+	{
343
+		return EEH_Template::display_template(
344
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
345
+			$template_args,
346
+			true
347
+		);
348
+	}
349
+
350
+
351
+
352
+	/**
353
+	 * @param $template
354
+	 * @param $template_args
355
+	 * @return mixed
356
+	 */
357
+	public function add_datetime_clone_button($template, $template_args)
358
+	{
359
+		return EEH_Template::display_template(
360
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
361
+			$template_args,
362
+			true
363
+		);
364
+	}
365
+
366
+
367
+
368
+	/**
369
+	 * @param $template
370
+	 * @param $template_args
371
+	 * @return mixed
372
+	 */
373
+	public function datetime_timezones_template($template, $template_args)
374
+	{
375
+		return EEH_Template::display_template(
376
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
377
+			$template_args,
378
+			true
379
+		);
380
+	}
381
+
382
+
383
+
384
+	protected function _set_list_table_views_default()
385
+	{
386
+		parent::_set_list_table_views_default();
387
+		$new_views = array(
388
+			'today' => array(
389
+				'slug'        => 'today',
390
+				'label'       => esc_html__('Today', 'event_espresso'),
391
+				'count'       => $this->total_events_today(),
392
+				'bulk_action' => array(
393
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
394
+				),
395
+			),
396
+			'month' => array(
397
+				'slug'        => 'month',
398
+				'label'       => esc_html__('This Month', 'event_espresso'),
399
+				'count'       => $this->total_events_this_month(),
400
+				'bulk_action' => array(
401
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
+				),
403
+			),
404
+		);
405
+		$this->_views = array_merge($this->_views, $new_views);
406
+	}
407
+
408
+
409
+
410
+	/**
411
+	 * @param array     $action_links
412
+	 * @param \EE_Event $event
413
+	 * @return array
414
+	 */
415
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
416
+	{
417
+		if (
418
+		EE_Registry::instance()->CAP->current_user_can(
419
+			'ee_read_registrations',
420
+			'espresso_registrations_reports',
421
+			$event->ID()
422
+		)
423
+		) {
424
+			$reports_query_args = array(
425
+				'action' => 'reports',
426
+				'EVT_ID' => $event->ID(),
427
+			);
428
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
429
+			$action_links[]     = '<a href="'
430
+								  . $reports_link
431
+								  . '" title="'
432
+								  . esc_attr__('View Report', 'event_espresso')
433
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
434
+								  . "\n\t";
435
+		}
436
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
437
+			EE_Registry::instance()->load_helper('MSG_Template');
438
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
439
+				'see_notifications_for',
440
+				null,
441
+				array('EVT_ID' => $event->ID())
442
+			);
443
+		}
444
+		return $action_links;
445
+	}
446
+
447
+
448
+
449
+	/**
450
+	 * @param $items
451
+	 * @return mixed
452
+	 */
453
+	public function additional_legend_items($items)
454
+	{
455
+		if (
456
+		EE_Registry::instance()->CAP->current_user_can(
457
+			'ee_read_registrations',
458
+			'espresso_registrations_reports'
459
+		)
460
+		) {
461
+			$items['reports'] = array(
462
+				'class' => 'dashicons dashicons-chart-bar',
463
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
464
+			);
465
+		}
466
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
467
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
468
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
469
+				$items['view_related_messages'] = array(
470
+					'class' => $related_for_icon['css_class'],
471
+					'desc'  => $related_for_icon['label'],
472
+				);
473
+			}
474
+		}
475
+		return $items;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * This is the callback method for the duplicate event route
482
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
483
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
484
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
485
+	 * After duplication the redirect is to the new event edit page.
486
+	 *
487
+	 * @return void
488
+	 * @access protected
489
+	 * @throws EE_Error If EE_Event is not available with given ID
490
+	 */
491
+	protected function _duplicate_event()
492
+	{
493
+		// first make sure the ID for the event is in the request.
494
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
495
+		if ( ! isset($this->_req_data['EVT_ID'])) {
496
+			EE_Error::add_error(
497
+				esc_html__(
498
+					'In order to duplicate an event an Event ID is required.  None was given.',
499
+					'event_espresso'
500
+				),
501
+				__FILE__,
502
+				__FUNCTION__,
503
+				__LINE__
504
+			);
505
+			$this->_redirect_after_action(false, '', '', array(), true);
506
+			return;
507
+		}
508
+		//k we've got EVT_ID so let's use that to get the event we'll duplicate
509
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
510
+		if ( ! $orig_event instanceof EE_Event) {
511
+			throw new EE_Error(
512
+				sprintf(
513
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
514
+					$this->_req_data['EVT_ID']
515
+				)
516
+			);
517
+		}
518
+		//k now let's clone the $orig_event before getting relations
519
+		$new_event = clone $orig_event;
520
+		//original datetimes
521
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
522
+		//other original relations
523
+		$orig_ven = $orig_event->get_many_related('Venue');
524
+		//reset the ID and modify other details to make it clear this is a dupe
525
+		$new_event->set('EVT_ID', 0);
526
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
527
+		$new_event->set('EVT_name', $new_name);
528
+		$new_event->set(
529
+			'EVT_slug',
530
+			wp_unique_post_slug(
531
+				sanitize_title($orig_event->name()),
532
+				0,
533
+				'publish',
534
+				'espresso_events',
535
+				0
536
+			)
537
+		);
538
+		$new_event->set('status', 'draft');
539
+		//duplicate discussion settings
540
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
541
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
542
+		//save the new event
543
+		$new_event->save();
544
+		//venues
545
+		foreach ($orig_ven as $ven) {
546
+			$new_event->_add_relation_to($ven, 'Venue');
547
+		}
548
+		$new_event->save();
549
+		//now we need to get the question group relations and handle that
550
+		//first primary question groups
551
+		$orig_primary_qgs = $orig_event->get_many_related(
552
+			'Question_Group',
553
+			array(array('Event_Question_Group.EQG_primary' => 1))
554
+		);
555
+		if ( ! empty($orig_primary_qgs)) {
556
+			foreach ($orig_primary_qgs as $id => $obj) {
557
+				if ($obj instanceof EE_Question_Group) {
558
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
559
+				}
560
+			}
561
+		}
562
+		//next additional attendee question groups
563
+		$orig_additional_qgs = $orig_event->get_many_related(
564
+			'Question_Group',
565
+			array(array('Event_Question_Group.EQG_primary' => 0))
566
+		);
567
+		if ( ! empty($orig_additional_qgs)) {
568
+			foreach ($orig_additional_qgs as $id => $obj) {
569
+				if ($obj instanceof EE_Question_Group) {
570
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
571
+				}
572
+			}
573
+		}
574
+		//now save
575
+		$new_event->save();
576
+		//k now that we have the new event saved we can loop through the datetimes and start adding relations.
577
+		$cloned_tickets = array();
578
+		foreach ($orig_datetimes as $orig_dtt) {
579
+			if ( ! $orig_dtt instanceof EE_Datetime) {
580
+				continue;
581
+			}
582
+			$new_dtt   = clone $orig_dtt;
583
+			$orig_tkts = $orig_dtt->tickets();
584
+			//save new dtt then add to event
585
+			$new_dtt->set('DTT_ID', 0);
586
+			$new_dtt->set('DTT_sold', 0);
587
+			$new_dtt->save();
588
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
589
+			$new_event->save();
590
+			//now let's get the ticket relations setup.
591
+			foreach ((array)$orig_tkts as $orig_tkt) {
592
+				//it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
593
+				if ( ! $orig_tkt instanceof EE_Ticket) {
594
+					continue;
595
+				}
596
+				//is this ticket archived?  If it is then let's skip
597
+				if ($orig_tkt->get('TKT_deleted')) {
598
+					continue;
599
+				}
600
+				// does this original ticket already exist in the clone_tickets cache?
601
+				//  If so we'll just use the new ticket from it.
602
+				if (isset($cloned_tickets[$orig_tkt->ID()])) {
603
+					$new_tkt = $cloned_tickets[$orig_tkt->ID()];
604
+				} else {
605
+					$new_tkt = clone $orig_tkt;
606
+					//get relations on the $orig_tkt that we need to setup.
607
+					$orig_prices = $orig_tkt->prices();
608
+					$new_tkt->set('TKT_ID', 0);
609
+					$new_tkt->set('TKT_sold', 0);
610
+					$new_tkt->set('TKT_reserved', 0);
611
+					$new_tkt->save(); //make sure new ticket has ID.
612
+					//price relations on new ticket need to be setup.
613
+					foreach ($orig_prices as $orig_price) {
614
+						$new_price = clone $orig_price;
615
+						$new_price->set('PRC_ID', 0);
616
+						$new_price->save();
617
+						$new_tkt->_add_relation_to($new_price, 'Price');
618
+						$new_tkt->save();
619
+					}
620
+				}
621
+				// k now we can add the new ticket as a relation to the new datetime
622
+				// and make sure its added to our cached $cloned_tickets array
623
+				// for use with later datetimes that have the same ticket.
624
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
625
+				$new_dtt->save();
626
+				$cloned_tickets[$orig_tkt->ID()] = $new_tkt;
627
+			}
628
+		}
629
+		//clone taxonomy information
630
+		$taxonomies_to_clone_with = apply_filters(
631
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
632
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
633
+		);
634
+		//get terms for original event (notice)
635
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
636
+		//loop through terms and add them to new event.
637
+		foreach ($orig_terms as $term) {
638
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
639
+		}
640
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
641
+		//now let's redirect to the edit page for this duplicated event if we have a new event id.
642
+		if ($new_event->ID()) {
643
+			$redirect_args = array(
644
+				'post'   => $new_event->ID(),
645
+				'action' => 'edit',
646
+			);
647
+			EE_Error::add_success(
648
+				esc_html__(
649
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
650
+					'event_espresso'
651
+				)
652
+			);
653
+		} else {
654
+			$redirect_args = array(
655
+				'action' => 'default',
656
+			);
657
+			EE_Error::add_error(
658
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
659
+				__FILE__,
660
+				__FUNCTION__,
661
+				__LINE__
662
+			);
663
+		}
664
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
665
+	}
666
+
667
+
668
+	protected function _import_page()
669
+	{
670
+		$title                                      = esc_html__('Import', 'event_espresso');
671
+		$intro                                      = esc_html__(
672
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
673
+			'event_espresso'
674
+		);
675
+		$form_url                                   = EVENTS_ADMIN_URL;
676
+		$action                                     = 'import_events';
677
+		$type                                       = 'csv';
678
+		$this->_template_args['form']               = EE_Import::instance()->upload_form(
679
+			$title, $intro, $form_url, $action, $type
680
+		);
681
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
682
+			array('action' => 'sample_export_file'),
683
+			$this->_admin_base_url
684
+		);
685
+		$content                                    = EEH_Template::display_template(
686
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
687
+			$this->_template_args,
688
+			true
689
+		);
690
+		$this->_template_args['admin_page_content'] = $content;
691
+		$this->display_admin_page_with_sidebar();
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * _import_events
698
+	 * This handles displaying the screen and running imports for importing events.
699
+	 *
700
+	 * @return void
701
+	 */
702
+	protected function _import_events()
703
+	{
704
+		require_once(EE_CLASSES . 'EE_Import.class.php');
705
+		$success = EE_Import::instance()->import();
706
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * _events_export
713
+	 * Will export all (or just the given event) to a Excel compatible file.
714
+	 *
715
+	 * @access protected
716
+	 * @return void
717
+	 */
718
+	protected function _events_export()
719
+	{
720
+		if (isset($this->_req_data['EVT_ID'])) {
721
+			$event_ids = $this->_req_data['EVT_ID'];
722
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
723
+			$event_ids = $this->_req_data['EVT_IDs'];
724
+		} else {
725
+			$event_ids = null;
726
+		}
727
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
728
+		$new_request_args = array(
729
+			'export' => 'report',
730
+			'action' => 'all_event_data',
731
+			'EVT_ID' => $event_ids,
732
+		);
733
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
734
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
735
+			require_once(EE_CLASSES . 'EE_Export.class.php');
736
+			$EE_Export = EE_Export::instance($this->_req_data);
737
+			$EE_Export->export();
738
+		}
739
+	}
740
+
741
+
742
+
743
+	/**
744
+	 * handle category exports()
745
+	 *
746
+	 * @return void
747
+	 */
748
+	protected function _categories_export()
749
+	{
750
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
751
+		$new_request_args = array(
752
+			'export'       => 'report',
753
+			'action'       => 'categories',
754
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
755
+		);
756
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
757
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
758
+			require_once(EE_CLASSES . 'EE_Export.class.php');
759
+			$EE_Export = EE_Export::instance($this->_req_data);
760
+			$EE_Export->export();
761
+		}
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * Creates a sample CSV file for importing
768
+	 */
769
+	protected function _sample_export_file()
770
+	{
771
+		//		require_once(EE_CLASSES . 'EE_Export.class.php');
772
+		EE_Export::instance()->export_sample();
773
+	}
774
+
775
+
776
+
777
+	/*************        Template Settings        *************/
778
+	protected function _template_settings()
779
+	{
780
+		$this->_template_args['values'] = $this->_yes_no_values;
781
+		/**
782
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
783
+		 * from General_Settings_Admin_Page to here.
784
+		 */
785
+		$this->_template_args = apply_filters(
786
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
787
+			$this->_template_args
788
+		);
789
+		$this->_set_add_edit_form_tags('update_template_settings');
790
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
791
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
792
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
793
+			$this->_template_args,
794
+			true
795
+		);
796
+		$this->display_admin_page_with_sidebar();
797
+	}
798
+
799
+
800
+
801
+	protected function _update_template_settings()
802
+	{
803
+		/**
804
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
805
+		 * from General_Settings_Admin_Page to here.
806
+		 */
807
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
808
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
809
+			EE_Registry::instance()->CFG->template_settings,
810
+			$this->_req_data
811
+		);
812
+		//update custom post type slugs and detect if we need to flush rewrite rules
813
+		$old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
814
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
815
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
816
+			: sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
817
+		$what                                              = 'Template Settings';
818
+		$success                                           = $this->_update_espresso_configuration(
819
+			$what,
820
+			EE_Registry::instance()->CFG->template_settings,
821
+			__FILE__,
822
+			__FUNCTION__,
823
+			__LINE__
824
+		);
825
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
826
+			update_option('ee_flush_rewrite_rules', true);
827
+		}
828
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
829
+	}
830
+
831
+
832
+
833
+	/**
834
+	 * _premium_event_editor_meta_boxes
835
+	 * add all metaboxes related to the event_editor
836
+	 *
837
+	 * @access protected
838
+	 * @return void
839
+	 */
840
+	protected function _premium_event_editor_meta_boxes()
841
+	{
842
+		$this->verify_cpt_object();
843
+		add_meta_box(
844
+			'espresso_event_editor_event_options',
845
+			esc_html__('Event Registration Options', 'event_espresso'),
846
+			array($this, 'registration_options_meta_box'),
847
+			$this->page_slug,
848
+			'side',
849
+			'core'
850
+		);
851
+	}
852
+
853
+
854
+
855
+	/**
856
+	 * override caf metabox
857
+	 *
858
+	 * @return void
859
+	 */
860
+	public function registration_options_meta_box()
861
+	{
862
+		$yes_no_values = array(
863
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
864
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
865
+		);
866
+		$default_reg_status_values = EEM_Registration::reg_status_array(
867
+			array(
868
+				EEM_Registration::status_id_cancelled,
869
+				EEM_Registration::status_id_declined,
870
+				EEM_Registration::status_id_incomplete,
871
+				EEM_Registration::status_id_wait_list,
872
+			),
873
+			true
874
+		);
875
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
876
+		$template_args['_event']                          = $this->_cpt_model_obj;
877
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
878
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
879
+			'default_reg_status',
880
+			$default_reg_status_values,
881
+			$this->_cpt_model_obj->default_registration_status()
882
+		);
883
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
884
+			'display_desc',
885
+			$yes_no_values,
886
+			$this->_cpt_model_obj->display_description()
887
+		);
888
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
889
+			'display_ticket_selector',
890
+			$yes_no_values,
891
+			$this->_cpt_model_obj->display_ticket_selector(),
892
+			'',
893
+			'',
894
+			false
895
+		);
896
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
897
+			'EVT_default_registration_status',
898
+			$default_reg_status_values,
899
+			$this->_cpt_model_obj->default_registration_status()
900
+		);
901
+		$template_args['additional_registration_options'] = apply_filters(
902
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
903
+			'',
904
+			$template_args,
905
+			$yes_no_values,
906
+			$default_reg_status_values
907
+		);
908
+		EEH_Template::display_template(
909
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
910
+			$template_args
911
+		);
912
+	}
913
+
914
+
915
+
916
+	/**
917
+	 * wp_list_table_mods for caf
918
+	 * ============================
919
+	 */
920
+	/**
921
+	 * hook into list table filters and provide filters for caffeinated list table
922
+	 *
923
+	 * @param  array $old_filters    any existing filters present
924
+	 * @param  array $list_table_obj the list table object
925
+	 * @return array                  new filters
926
+	 */
927
+	public function list_table_filters($old_filters, $list_table_obj)
928
+	{
929
+		$filters = array();
930
+		//first month/year filters
931
+		$filters[] = $this->espresso_event_months_dropdown();
932
+		$status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
933
+		//active status dropdown
934
+		if ($status !== 'draft') {
935
+			$filters[] = $this->active_status_dropdown(
936
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
937
+			);
938
+		}
939
+		//category filter
940
+		$filters[] = $this->category_dropdown();
941
+		return array_merge($old_filters, $filters);
942
+	}
943
+
944
+
945
+
946
+	/**
947
+	 * espresso_event_months_dropdown
948
+	 *
949
+	 * @access public
950
+	 * @return string                dropdown listing month/year selections for events.
951
+	 */
952
+	public function espresso_event_months_dropdown()
953
+	{
954
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
955
+		// Note we need to include any other filters that are set!
956
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
957
+		//categories?
958
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
959
+			? $this->_req_data['EVT_CAT']
960
+			: null;
961
+		//active status?
962
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
963
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
964
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
965
+	}
966
+
967
+
968
+
969
+	/**
970
+	 * returns a list of "active" statuses on the event
971
+	 *
972
+	 * @param  string $current_value whatever the current active status is
973
+	 * @return string
974
+	 */
975
+	public function active_status_dropdown($current_value = '')
976
+	{
977
+		$select_name = 'active_status';
978
+		$values      = array(
979
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
980
+			'active'   => esc_html__('Active', 'event_espresso'),
981
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
982
+			'expired'  => esc_html__('Expired', 'event_espresso'),
983
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
984
+		);
985
+		$id          = 'id="espresso-active-status-dropdown-filter"';
986
+		$class       = 'wide';
987
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
988
+	}
989
+
990
+
991
+
992
+	/**
993
+	 * output a dropdown of the categories for the category filter on the event admin list table
994
+	 *
995
+	 * @access  public
996
+	 * @return string html
997
+	 */
998
+	public function category_dropdown()
999
+	{
1000
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1001
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1002
+	}
1003
+
1004
+
1005
+
1006
+	/**
1007
+	 * get total number of events today
1008
+	 *
1009
+	 * @access public
1010
+	 * @return int
1011
+	 */
1012
+	public function total_events_today()
1013
+	{
1014
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1015
+			'DTT_EVT_start',
1016
+			date('Y-m-d') . ' 00:00:00',
1017
+			'Y-m-d H:i:s',
1018
+			'UTC'
1019
+		);
1020
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1021
+			'DTT_EVT_start',
1022
+			date('Y-m-d') . ' 23:59:59',
1023
+			'Y-m-d H:i:s',
1024
+			'UTC'
1025
+		);
1026
+		$where = array(
1027
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1028
+		);
1029
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1030
+		return $count;
1031
+	}
1032
+
1033
+
1034
+
1035
+	/**
1036
+	 * get total number of events this month
1037
+	 *
1038
+	 * @access public
1039
+	 * @return int
1040
+	 */
1041
+	public function total_events_this_month()
1042
+	{
1043
+		//Dates
1044
+		$this_year_r     = date('Y');
1045
+		$this_month_r    = date('m');
1046
+		$days_this_month = date('t');
1047
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1048
+			'DTT_EVT_start',
1049
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1050
+			'Y-m-d H:i:s',
1051
+			'UTC'
1052
+		);
1053
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1054
+			'DTT_EVT_start',
1055
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1056
+			'Y-m-d H:i:s',
1057
+			'UTC'
1058
+		);
1059
+		$where = array(
1060
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1061
+		);
1062
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1063
+		return $count;
1064
+	}
1065
+
1066
+
1067
+
1068
+	/** DEFAULT TICKETS STUFF **/
1069
+	public function _tickets_overview_list_table()
1070
+	{
1071
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1072
+		$this->display_admin_list_table_page_with_no_sidebar();
1073
+	}
1074
+
1075
+
1076
+
1077
+	/**
1078
+	 * @param int  $per_page
1079
+	 * @param bool $count
1080
+	 * @param bool $trashed
1081
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1082
+	 */
1083
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1084
+	{
1085
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1086
+		$order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1087
+		switch ($orderby) {
1088
+			case 'TKT_name' :
1089
+				$orderby = array('TKT_name' => $order);
1090
+				break;
1091
+			case 'TKT_price' :
1092
+				$orderby = array('TKT_price' => $order);
1093
+				break;
1094
+			case 'TKT_uses' :
1095
+				$orderby = array('TKT_uses' => $order);
1096
+				break;
1097
+			case 'TKT_min' :
1098
+				$orderby = array('TKT_min' => $order);
1099
+				break;
1100
+			case 'TKT_max' :
1101
+				$orderby = array('TKT_max' => $order);
1102
+				break;
1103
+			case 'TKT_qty' :
1104
+				$orderby = array('TKT_qty' => $order);
1105
+				break;
1106
+		}
1107
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1108
+			? $this->_req_data['paged']
1109
+			: 1;
1110
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1111
+			? $this->_req_data['perpage']
1112
+			: $per_page;
1113
+		$_where       = array(
1114
+			'TKT_is_default' => 1,
1115
+			'TKT_deleted'    => $trashed,
1116
+		);
1117
+		$offset       = ($current_page - 1) * $per_page;
1118
+		$limit        = array($offset, $per_page);
1119
+		if (isset($this->_req_data['s'])) {
1120
+			$sstr         = '%' . $this->_req_data['s'] . '%';
1121
+			$_where['OR'] = array(
1122
+				'TKT_name'        => array('LIKE', $sstr),
1123
+				'TKT_description' => array('LIKE', $sstr),
1124
+			);
1125
+		}
1126
+		$query_params = array(
1127
+			$_where,
1128
+			'order_by' => $orderby,
1129
+			'limit'    => $limit,
1130
+			'group_by' => 'TKT_ID',
1131
+		);
1132
+		if ($count) {
1133
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1134
+		} else {
1135
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1136
+		}
1137
+	}
1138
+
1139
+
1140
+
1141
+	/**
1142
+	 * @param bool $trash
1143
+	 */
1144
+	protected function _trash_or_restore_ticket($trash = false)
1145
+	{
1146
+		$success = 1;
1147
+		$TKT = EEM_Ticket::instance();
1148
+		//checkboxes?
1149
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1150
+			//if array has more than one element then success message should be plural
1151
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1152
+			//cycle thru the boxes
1153
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1154
+				if ($trash) {
1155
+					if ( ! $TKT->delete_by_ID($TKT_ID)) {
1156
+						$success = 0;
1157
+					}
1158
+				} else {
1159
+					if ( ! $TKT->restore_by_ID($TKT_ID)) {
1160
+						$success = 0;
1161
+					}
1162
+				}
1163
+			}
1164
+		} else {
1165
+			//grab single id and trash
1166
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1167
+			if ($trash) {
1168
+				if ( ! $TKT->delete_by_ID($TKT_ID)) {
1169
+					$success = 0;
1170
+				}
1171
+			} else {
1172
+				if ( ! $TKT->restore_by_ID($TKT_ID)) {
1173
+					$success = 0;
1174
+				}
1175
+			}
1176
+		}
1177
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1178
+		$query_args  = array(
1179
+			'action' => 'ticket_list_table',
1180
+			'status' => $trash ? '' : 'trashed',
1181
+		);
1182
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1183
+	}
1184
+
1185
+
1186
+
1187
+	protected function _delete_ticket()
1188
+	{
1189
+		$success = 1;
1190
+		//checkboxes?
1191
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1192
+			//if array has more than one element then success message should be plural
1193
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1194
+			//cycle thru the boxes
1195
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1196
+				//delete
1197
+				if ( ! $this->_delete_the_ticket($TKT_ID)) {
1198
+					$success = 0;
1199
+				}
1200
+			}
1201
+		} else {
1202
+			//grab single id and trash
1203
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1204
+			if ( ! $this->_delete_the_ticket($TKT_ID)) {
1205
+				$success = 0;
1206
+			}
1207
+		}
1208
+		$action_desc = 'deleted';
1209
+		$query_args  = array(
1210
+			'action' => 'ticket_list_table',
1211
+			'status' => 'trashed',
1212
+		);
1213
+		//fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1214
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1215
+			array(array('TKT_is_default' => 1)),
1216
+			'TKT_ID',
1217
+			true
1218
+		)
1219
+		) {
1220
+			$query_args = array();
1221
+		}
1222
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1223
+	}
1224
+
1225
+
1226
+
1227
+	/**
1228
+	 * @param int $TKT_ID
1229
+	 * @return bool|int
1230
+	 */
1231
+	protected function _delete_the_ticket($TKT_ID)
1232
+	{
1233
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1234
+		$tkt->_remove_relations('Datetime');
1235
+		//delete all related prices first
1236
+		$tkt->delete_related_permanently('Price');
1237
+		return $tkt->delete_permanently();
1238
+	}
1239 1239
 
1240 1240
 
1241 1241
 
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Payment_List_Shortcodes.lib.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Event Espresso
7 7
  * @subpackage messages
8 8
  */
9
-if (!defined('EVENT_ESPRESSO_VERSION') )
9
+if ( ! defined('EVENT_ESPRESSO_VERSION'))
10 10
 	exit('NO direct script access allowed');
11 11
 
12 12
 /**
@@ -32,18 +32,18 @@  discard block
 block discarded – undo
32 32
 		$this->label = __('Payment List Shortcodes', 'event_espresso');
33 33
 		$this->description = __('All shortcodes specific to payment lists', 'event_espresso');
34 34
 		$this->_shortcodes = array(
35
-			'[PAYMENT_LIST_*]' => __('Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:', 'event_espresso') . '<p><ul>' .
36
-				'<li><strong>no_payments</strong>:' . sprintf( __('Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"', 'event_espresso'),  htmlspecialchars('<td class="aln-cntr" colspan="6">'), htmlspecialchars('</td>') ) . '</li>' .
35
+			'[PAYMENT_LIST_*]' => __('Outputs a list of payment items. Note, this is a dynamic shortcode in that it accepts some attributes for setting certain defaults.  Attributes that are available are:', 'event_espresso').'<p><ul>'.
36
+				'<li><strong>no_payments</strong>:'.sprintf(__('Indicate with this attribute what will be used if there are no payments present.  Default is: "%sNo approved payments have been received.%s"', 'event_espresso'), htmlspecialchars('<td class="aln-cntr" colspan="6">'), htmlspecialchars('</td>')).'</li>'.
37 37
 				'</ul></p>'
38 38
 			);
39 39
 	}
40 40
 
41 41
 
42 42
 
43
-	protected function _parser( $shortcode ) {
43
+	protected function _parser($shortcode) {
44 44
 
45
-		if ( strpos( $shortcode, '[PAYMENT_LIST_*' ) !== FALSE ) {
46
-			return $this->_get_payment_list( $shortcode );
45
+		if (strpos($shortcode, '[PAYMENT_LIST_*') !== FALSE) {
46
+			return $this->_get_payment_list($shortcode);
47 47
 		}
48 48
 		return '';
49 49
 	}
@@ -60,32 +60,32 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @return string parsed ticket line item list.
62 62
 	 */
63
-	private function _get_payment_list( $shortcode ) {
63
+	private function _get_payment_list($shortcode) {
64 64
 		$this->_validate_list_requirements();
65 65
 
66 66
 
67
-		if ( ! $this->_data['data'] instanceof EE_Messages_Addressee ) {
67
+		if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) {
68 68
 			return '';
69 69
 		}
70 70
 
71
-		$valid_shortcodes = array( 'payment' );
71
+		$valid_shortcodes = array('payment');
72 72
 
73 73
 		$addressee_obj = $this->_data['data'];
74 74
 		$templates = $this->_extra_data['template'];
75
-		$payments = apply_filters( 'FHEE__Payment_List_Shortcodes___get_payments_list__payments', $addressee_obj->payments );
75
+		$payments = apply_filters('FHEE__Payment_List_Shortcodes___get_payments_list__payments', $addressee_obj->payments);
76 76
 
77 77
 		//let's get any attributes that may be present and set the defaults.
78
-		$atts = $this->_get_shortcode_attrs( $shortcode );
78
+		$atts = $this->_get_shortcode_attrs($shortcode);
79 79
 
80
-		$no_payments_msg = empty( $atts['no_payments'] ) ?  __('No approved payments have been received.','event_espresso') : $atts['no_payments'];
80
+		$no_payments_msg = empty($atts['no_payments']) ? __('No approved payments have been received.', 'event_espresso') : $atts['no_payments'];
81 81
 
82 82
 		//made it here so we have an array of paymnets, so we should have what we need.
83
-		$payment_content = empty( $payments ) ? $no_payments_msg : '';
83
+		$payment_content = empty($payments) ? $no_payments_msg : '';
84 84
 
85 85
 		$payments = (array) $payments;
86 86
 
87
-		foreach ( $payments as $payment ) {
88
-			$payment_content .= $this->_shortcode_helper->parse_payment_list_template( $templates['payment_list'], $payment, $valid_shortcodes, $this->_extra_data );
87
+		foreach ($payments as $payment) {
88
+			$payment_content .= $this->_shortcode_helper->parse_payment_list_template($templates['payment_list'], $payment, $valid_shortcodes, $this->_extra_data);
89 89
 		}
90 90
 
91 91
 		return $payment_content;
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,8 +6,9 @@
 block discarded – undo
6 6
  * @package Event Espresso
7 7
  * @subpackage messages
8 8
  */
9
-if (!defined('EVENT_ESPRESSO_VERSION') )
9
+if (!defined('EVENT_ESPRESSO_VERSION') ) {
10 10
 	exit('NO direct script access allowed');
11
+}
11 12
 
12 13
 /**
13 14
  *
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -9,164 +9,164 @@
 block discarded – undo
9 9
 abstract class EE_Table_Base
10 10
 {
11 11
 
12
-    /**
13
-     * This holds the table_name without the table prefix.
14
-     *
15
-     * @var string
16
-     */
17
-    var $_table_name;
18
-
19
-
20
-    /**
21
-     * This holds what is used as the alias for the table in queries.
22
-     *
23
-     * @var string
24
-     */
25
-    var $_table_alias;
26
-
27
-
28
-    /**
29
-     * Table's private key column
30
-     *
31
-     * @var string
32
-     */
33
-    protected $_pk_column;
34
-
35
-
36
-    /**
37
-     * Whether this table is a global table (in multisite) or specific to site.
38
-     *
39
-     * @var bool
40
-     */
41
-    protected $_global;
42
-
43
-
44
-
45
-    /**
46
-     * @global wpdb   $wpdb
47
-     * @param string  $table_name with or without wpdb prefix
48
-     * @param string  $pk_column
49
-     * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
-     *                            install, or whether each site on a multisite install has a copy of this table
51
-     */
52
-    function __construct($table_name, $pk_column, $global = false)
53
-    {
54
-        $this->_global = $global;
55
-        $prefix = $this->get_table_prefix();
56
-        //if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
-        if (strpos($table_name, $prefix) === 0) {
58
-            $table_name = ltrim($table_name, $prefix);
59
-        }
60
-        $this->_table_name = $table_name;
61
-        $this->_pk_column = $pk_column;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * This returns the table prefix for the current model state.
68
-     *
69
-     * @global wpdb $wpdb
70
-     * @return string
71
-     */
72
-    public function get_table_prefix()
73
-    {
74
-        global $wpdb;
75
-        if ($this->_global) {
76
-            $prefix = $wpdb->base_prefix;
77
-        } else {
78
-            $prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
-        }
80
-        return $prefix;
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Used to set the table_alias property
87
-     *
88
-     * @param string $table_alias
89
-     */
90
-    function _construct_finalize_with_alias($table_alias)
91
-    {
92
-        $this->_table_alias = $table_alias;
93
-    }
94
-
95
-
96
-
97
-    /**
98
-     * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
-     *
100
-     * @return string
101
-     */
102
-    function get_table_name()
103
-    {
104
-        return $this->get_table_prefix() . $this->_table_name;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * Provides what is currently set as the alias for the table to be used in queries.
111
-     *
112
-     * @return string
113
-     * @throws EE_Error
114
-     */
115
-    function get_table_alias()
116
-    {
117
-        if ( ! $this->_table_alias) {
118
-            throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
-        }
120
-        return $this->_table_alias;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @return string name of column of PK
127
-     */
128
-    function get_pk_column()
129
-    {
130
-        return $this->_pk_column;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * returns a string with the table alias, a period, and the private key's column.
137
-     *
138
-     * @return string
139
-     */
140
-    function get_fully_qualified_pk_column()
141
-    {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
-        return $sql;
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * returns the special sql for a inner select with a limit.
150
-     *
151
-     * @return string    SQL select
152
-     */
153
-    public function get_select_join_limit($limit)
154
-    {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
-        return $SQL;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Returns whether or not htis is a global table (ie, on multisite there's
164
-     * only one of these tables, on the main blog)
165
-     *
166
-     * @return boolean
167
-     */
168
-    public function is_global()
169
-    {
170
-        return $this->_global;
171
-    }
12
+	/**
13
+	 * This holds the table_name without the table prefix.
14
+	 *
15
+	 * @var string
16
+	 */
17
+	var $_table_name;
18
+
19
+
20
+	/**
21
+	 * This holds what is used as the alias for the table in queries.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	var $_table_alias;
26
+
27
+
28
+	/**
29
+	 * Table's private key column
30
+	 *
31
+	 * @var string
32
+	 */
33
+	protected $_pk_column;
34
+
35
+
36
+	/**
37
+	 * Whether this table is a global table (in multisite) or specific to site.
38
+	 *
39
+	 * @var bool
40
+	 */
41
+	protected $_global;
42
+
43
+
44
+
45
+	/**
46
+	 * @global wpdb   $wpdb
47
+	 * @param string  $table_name with or without wpdb prefix
48
+	 * @param string  $pk_column
49
+	 * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
+	 *                            install, or whether each site on a multisite install has a copy of this table
51
+	 */
52
+	function __construct($table_name, $pk_column, $global = false)
53
+	{
54
+		$this->_global = $global;
55
+		$prefix = $this->get_table_prefix();
56
+		//if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
+		if (strpos($table_name, $prefix) === 0) {
58
+			$table_name = ltrim($table_name, $prefix);
59
+		}
60
+		$this->_table_name = $table_name;
61
+		$this->_pk_column = $pk_column;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * This returns the table prefix for the current model state.
68
+	 *
69
+	 * @global wpdb $wpdb
70
+	 * @return string
71
+	 */
72
+	public function get_table_prefix()
73
+	{
74
+		global $wpdb;
75
+		if ($this->_global) {
76
+			$prefix = $wpdb->base_prefix;
77
+		} else {
78
+			$prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
+		}
80
+		return $prefix;
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Used to set the table_alias property
87
+	 *
88
+	 * @param string $table_alias
89
+	 */
90
+	function _construct_finalize_with_alias($table_alias)
91
+	{
92
+		$this->_table_alias = $table_alias;
93
+	}
94
+
95
+
96
+
97
+	/**
98
+	 * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
+	 *
100
+	 * @return string
101
+	 */
102
+	function get_table_name()
103
+	{
104
+		return $this->get_table_prefix() . $this->_table_name;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * Provides what is currently set as the alias for the table to be used in queries.
111
+	 *
112
+	 * @return string
113
+	 * @throws EE_Error
114
+	 */
115
+	function get_table_alias()
116
+	{
117
+		if ( ! $this->_table_alias) {
118
+			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
+		}
120
+		return $this->_table_alias;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @return string name of column of PK
127
+	 */
128
+	function get_pk_column()
129
+	{
130
+		return $this->_pk_column;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * returns a string with the table alias, a period, and the private key's column.
137
+	 *
138
+	 * @return string
139
+	 */
140
+	function get_fully_qualified_pk_column()
141
+	{
142
+		$sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
+		return $sql;
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * returns the special sql for a inner select with a limit.
150
+	 *
151
+	 * @return string    SQL select
152
+	 */
153
+	public function get_select_join_limit($limit)
154
+	{
155
+		$limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
+		$SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
+		return $SQL;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Returns whether or not htis is a global table (ie, on multisite there's
164
+	 * only one of these tables, on the main blog)
165
+	 *
166
+	 * @return boolean
167
+	 */
168
+	public function is_global()
169
+	{
170
+		return $this->_global;
171
+	}
172 172
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     function get_table_name()
103 103
     {
104
-        return $this->get_table_prefix() . $this->_table_name;
104
+        return $this->get_table_prefix().$this->_table_name;
105 105
     }
106 106
 
107 107
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     function get_fully_qualified_pk_column()
141 141
     {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
142
+        $sql = $this->get_table_alias().".".$this->get_pk_column();
143 143
         return $sql;
144 144
     }
145 145
 
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function get_select_join_limit($limit)
154 154
     {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int)$limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
155
+        $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit;
156
+        $SQL = SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias;
157 157
         return $SQL;
158 158
     }
159 159
 
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1247,7 +1247,7 @@
 block discarded – undo
1247 1247
     /**
1248 1248
      * Sets up the limit for the registrations query.
1249 1249
      *
1250
-     * @param $per_page
1250
+     * @param integer $per_page
1251 1251
      * @return array
1252 1252
      */
1253 1253
     protected function _get_limit($per_page)
Please login to merge, or discard this patch.
Indentation   +2955 added lines, -2955 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -23,1844 +23,1844 @@  discard block
 block discarded – undo
23 23
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registration
28
-     */
29
-    private $_registration;
30
-
31
-    /**
32
-     * @var EE_Event
33
-     */
34
-    private $_reg_event;
35
-
36
-    /**
37
-     * @var EE_Session
38
-     */
39
-    private $_session;
40
-
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-
52
-    /**
53
-     *        constructor
54
-     *
55
-     * @Constructor
56
-     * @access public
57
-     * @param bool $routing
58
-     * @return Registrations_Admin_Page
59
-     */
60
-    public function __construct($routing = true)
61
-    {
62
-        parent::__construct($routing);
63
-        add_action('wp_loaded', array($this, 'wp_loaded'));
64
-    }
65
-
66
-
67
-    public function wp_loaded()
68
-    {
69
-        // when adding a new registration...
70
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
-            EE_System::do_not_cache();
72
-            if ( ! isset($this->_req_data['processing_registration'])
73
-                 || absint($this->_req_data['processing_registration']) !== 1
74
-            ) {
75
-                // and it's NOT the attendee information reg step
76
-                // force cookie expiration by setting time to last week
77
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
-                // and update the global
79
-                $_COOKIE['ee_registration_added'] = 0;
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-    protected function _init_page_props()
86
-    {
87
-        $this->page_slug        = REG_PG_SLUG;
88
-        $this->_admin_base_url  = REG_ADMIN_URL;
89
-        $this->_admin_base_path = REG_ADMIN;
90
-        $this->page_label       = __('Registrations', 'event_espresso');
91
-        $this->_cpt_routes      = array(
92
-            'add_new_attendee' => 'espresso_attendees',
93
-            'edit_attendee'    => 'espresso_attendees',
94
-            'insert_attendee'  => 'espresso_attendees',
95
-            'update_attendee'  => 'espresso_attendees',
96
-        );
97
-        $this->_cpt_model_names = array(
98
-            'add_new_attendee' => 'EEM_Attendee',
99
-            'edit_attendee'    => 'EEM_Attendee',
100
-        );
101
-        $this->_cpt_edit_routes = array(
102
-            'espresso_attendees' => 'edit_attendee',
103
-        );
104
-        $this->_pagenow_map     = array(
105
-            'add_new_attendee' => 'post-new.php',
106
-            'edit_attendee'    => 'post.php',
107
-            'trash'            => 'post.php',
108
-        );
109
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
-        //add filters so that the comment urls don't take users to a confusing 404 page
111
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
-    }
113
-
114
-
115
-    public function clear_comment_link($link, $comment, $args)
116
-    {
117
-        //gotta make sure this only happens on this route
118
-        $post_type = get_post_type($comment->comment_post_ID);
119
-        if ($post_type === 'espresso_attendees') {
120
-            return '#commentsdiv';
121
-        }
122
-        return $link;
123
-    }
124
-
125
-
126
-    protected function _ajax_hooks()
127
-    {
128
-        //todo: all hooks for registrations ajax goes in here
129
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
-    }
131
-
132
-
133
-    protected function _define_page_props()
134
-    {
135
-        $this->_admin_page_title = $this->page_label;
136
-        $this->_labels           = array(
137
-            'buttons'                      => array(
138
-                'add-registrant'      => __('Add New Registration', 'event_espresso'),
139
-                'add-attendee'        => __('Add Contact', 'event_espresso'),
140
-                'edit'                => __('Edit Contact', 'event_espresso'),
141
-                'report'              => __("Event Registrations CSV Report", "event_espresso"),
142
-                'report_all'          => __('All Registrations CSV Report', 'event_espresso'),
143
-                'report_filtered'     => __('Filtered CSV Report', 'event_espresso'),
144
-                'contact_list_report' => __('Contact List Report', 'event_espresso'),
145
-                'contact_list_export' => __("Export Data", "event_espresso"),
146
-            ),
147
-            'publishbox'                   => array(
148
-                'add_new_attendee' => __("Add Contact Record", 'event_espresso'),
149
-                'edit_attendee'    => __("Update Contact Record", 'event_espresso'),
150
-            ),
151
-            'hide_add_button_on_cpt_route' => array(
152
-                'edit_attendee' => true,
153
-            ),
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *        grab url requests and route them
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    public function _set_page_routes()
165
-    {
166
-        $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
-            ? $this->_req_data['_REG_ID'] : 0;
169
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
-            ? $this->_req_data['ATT_ID'] : 0;
171
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post']
172
-            : $att_id;
173
-        $this->_page_routes = array(
174
-            'default'                            => array(
175
-                'func'       => '_registrations_overview_list_table',
176
-                'capability' => 'ee_read_registrations',
177
-            ),
178
-            'view_registration'                  => array(
179
-                'func'       => '_registration_details',
180
-                'capability' => 'ee_read_registration',
181
-                'obj_id'     => $reg_id,
182
-            ),
183
-            'edit_registration'                  => array(
184
-                'func'               => '_update_attendee_registration_form',
185
-                'noheader'           => true,
186
-                'headers_sent_route' => 'view_registration',
187
-                'capability'         => 'ee_edit_registration',
188
-                'obj_id'             => $reg_id,
189
-                '_REG_ID'            => $reg_id,
190
-            ),
191
-            'trash_registrations'                => array(
192
-                'func'       => '_trash_or_restore_registrations',
193
-                'args'       => array('trash' => true),
194
-                'noheader'   => true,
195
-                'capability' => 'ee_delete_registrations',
196
-            ),
197
-            'restore_registrations'              => array(
198
-                'func'       => '_trash_or_restore_registrations',
199
-                'args'       => array('trash' => false),
200
-                'noheader'   => true,
201
-                'capability' => 'ee_delete_registrations',
202
-            ),
203
-            'delete_registrations'               => array(
204
-                'func'       => '_delete_registrations',
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'new_registration'                   => array(
209
-                'func'       => 'new_registration',
210
-                'capability' => 'ee_edit_registrations',
211
-            ),
212
-            'process_reg_step'                   => array(
213
-                'func'       => 'process_reg_step',
214
-                'noheader'   => true,
215
-                'capability' => 'ee_edit_registrations',
216
-            ),
217
-            'redirect_to_txn'                    => array(
218
-                'func'       => 'redirect_to_txn',
219
-                'noheader'   => true,
220
-                'capability' => 'ee_edit_registrations',
221
-            ),
222
-            'change_reg_status'                  => array(
223
-                'func'       => '_change_reg_status',
224
-                'noheader'   => true,
225
-                'capability' => 'ee_edit_registration',
226
-                'obj_id'     => $reg_id,
227
-            ),
228
-            'approve_registration'               => array(
229
-                'func'       => 'approve_registration',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registration',
232
-                'obj_id'     => $reg_id,
233
-            ),
234
-            'approve_and_notify_registration'    => array(
235
-                'func'       => 'approve_registration',
236
-                'noheader'   => true,
237
-                'args'       => array(true),
238
-                'capability' => 'ee_edit_registration',
239
-                'obj_id'     => $reg_id,
240
-            ),
241
-            'decline_registration'               => array(
242
-                'func'       => 'decline_registration',
243
-                'noheader'   => true,
244
-                'capability' => 'ee_edit_registration',
245
-                'obj_id'     => $reg_id,
246
-            ),
247
-            'decline_and_notify_registration'    => array(
248
-                'func'       => 'decline_registration',
249
-                'noheader'   => true,
250
-                'args'       => array(true),
251
-                'capability' => 'ee_edit_registration',
252
-                'obj_id'     => $reg_id,
253
-            ),
254
-            'pending_registration'               => array(
255
-                'func'       => 'pending_registration',
256
-                'noheader'   => true,
257
-                'capability' => 'ee_edit_registration',
258
-                'obj_id'     => $reg_id,
259
-            ),
260
-            'pending_and_notify_registration'    => array(
261
-                'func'       => 'pending_registration',
262
-                'noheader'   => true,
263
-                'args'       => array(true),
264
-                'capability' => 'ee_edit_registration',
265
-                'obj_id'     => $reg_id,
266
-            ),
267
-            'no_approve_registration'            => array(
268
-                'func'       => 'not_approve_registration',
269
-                'noheader'   => true,
270
-                'capability' => 'ee_edit_registration',
271
-                'obj_id'     => $reg_id,
272
-            ),
273
-            'no_approve_and_notify_registration' => array(
274
-                'func'       => 'not_approve_registration',
275
-                'noheader'   => true,
276
-                'args'       => array(true),
277
-                'capability' => 'ee_edit_registration',
278
-                'obj_id'     => $reg_id,
279
-            ),
280
-            'cancel_registration'                => array(
281
-                'func'       => 'cancel_registration',
282
-                'noheader'   => true,
283
-                'capability' => 'ee_edit_registration',
284
-                'obj_id'     => $reg_id,
285
-            ),
286
-            'cancel_and_notify_registration'     => array(
287
-                'func'       => 'cancel_registration',
288
-                'noheader'   => true,
289
-                'args'       => array(true),
290
-                'capability' => 'ee_edit_registration',
291
-                'obj_id'     => $reg_id,
292
-            ),
293
-            'contact_list'                       => array(
294
-                'func'       => '_attendee_contact_list_table',
295
-                'capability' => 'ee_read_contacts',
296
-            ),
297
-            'add_new_attendee'                   => array(
298
-                'func' => '_create_new_cpt_item',
299
-                'args' => array(
300
-                    'new_attendee' => true,
301
-                    'capability'   => 'ee_edit_contacts',
302
-                ),
303
-            ),
304
-            'edit_attendee'                      => array(
305
-                'func'       => '_edit_cpt_item',
306
-                'capability' => 'ee_edit_contacts',
307
-                'obj_id'     => $att_id,
308
-            ),
309
-            'duplicate_attendee'                 => array(
310
-                'func'       => '_duplicate_attendee',
311
-                'noheader'   => true,
312
-                'capability' => 'ee_edit_contacts',
313
-                'obj_id'     => $att_id,
314
-            ),
315
-            'insert_attendee'                    => array(
316
-                'func'       => '_insert_or_update_attendee',
317
-                'args'       => array(
318
-                    'new_attendee' => true,
319
-                ),
320
-                'noheader'   => true,
321
-                'capability' => 'ee_edit_contacts',
322
-            ),
323
-            'update_attendee'                    => array(
324
-                'func'       => '_insert_or_update_attendee',
325
-                'args'       => array(
326
-                    'new_attendee' => false,
327
-                ),
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_contacts',
330
-                'obj_id'     => $att_id,
331
-            ),
332
-            'trash_attendees'                    => array(
333
-                'func'       => '_trash_or_restore_attendees',
334
-                'args'       => array(
335
-                    'trash' => true,
336
-                ),
337
-                'noheader'   => true,
338
-                'capability' => 'ee_delete_contacts',
339
-                'obj_id'     => $att_id,
340
-            ),
341
-            'restore_attendees'                  => array(
342
-                'func'       => '_trash_or_restore_attendees',
343
-                'args'       => array(
344
-                    'trash' => false,
345
-                ),
346
-                'noheader'   => true,
347
-                'capability' => 'ee_delete_contacts',
348
-                'obj_id'     => $att_id,
349
-            ),
350
-            'resend_registration'                => array(
351
-                'func'       => '_resend_registration',
352
-                'noheader'   => true,
353
-                'capability' => 'ee_send_message',
354
-            ),
355
-            'registrations_report'               => array(
356
-                'func'       => '_registrations_report',
357
-                'noheader'   => true,
358
-                'capability' => 'ee_read_registrations',
359
-            ),
360
-            'contact_list_export'                => array(
361
-                'func'       => '_contact_list_export',
362
-                'noheader'   => true,
363
-                'capability' => 'export',
364
-            ),
365
-            'contact_list_report'                => array(
366
-                'func'       => '_contact_list_report',
367
-                'noheader'   => true,
368
-                'capability' => 'ee_read_contacts',
369
-            ),
370
-        );
371
-    }
372
-
373
-
374
-    protected function _set_page_config()
375
-    {
376
-        $this->_page_config = array(
377
-            'default'           => array(
378
-                'nav'           => array(
379
-                    'label' => __('Overview', 'event_espresso'),
380
-                    'order' => 5,
381
-                ),
382
-                'help_tabs'     => array(
383
-                    'registrations_overview_help_tab'                       => array(
384
-                        'title'    => __('Registrations Overview', 'event_espresso'),
385
-                        'filename' => 'registrations_overview',
386
-                    ),
387
-                    'registrations_overview_table_column_headings_help_tab' => array(
388
-                        'title'    => __('Registrations Table Column Headings', 'event_espresso'),
389
-                        'filename' => 'registrations_overview_table_column_headings',
390
-                    ),
391
-                    'registrations_overview_filters_help_tab'               => array(
392
-                        'title'    => __('Registration Filters', 'event_espresso'),
393
-                        'filename' => 'registrations_overview_filters',
394
-                    ),
395
-                    'registrations_overview_views_help_tab'                 => array(
396
-                        'title'    => __('Registration Views', 'event_espresso'),
397
-                        'filename' => 'registrations_overview_views',
398
-                    ),
399
-                    'registrations_regoverview_other_help_tab'              => array(
400
-                        'title'    => __('Registrations Other', 'event_espresso'),
401
-                        'filename' => 'registrations_overview_other',
402
-                    ),
403
-                ),
404
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
405
-                'qtips'         => array('Registration_List_Table_Tips'),
406
-                'list_table'    => 'EE_Registrations_List_Table',
407
-                'require_nonce' => false,
408
-            ),
409
-            'view_registration' => array(
410
-                'nav'           => array(
411
-                    'label'      => __('REG Details', 'event_espresso'),
412
-                    'order'      => 15,
413
-                    'url'        => isset($this->_req_data['_REG_ID'])
414
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
415
-                        : $this->_admin_base_url,
416
-                    'persistent' => false,
417
-                ),
418
-                'help_tabs'     => array(
419
-                    'registrations_details_help_tab'                    => array(
420
-                        'title'    => __('Registration Details', 'event_espresso'),
421
-                        'filename' => 'registrations_details',
422
-                    ),
423
-                    'registrations_details_table_help_tab'              => array(
424
-                        'title'    => __('Registration Details Table', 'event_espresso'),
425
-                        'filename' => 'registrations_details_table',
426
-                    ),
427
-                    'registrations_details_form_answers_help_tab'       => array(
428
-                        'title'    => __('Registration Form Answers', 'event_espresso'),
429
-                        'filename' => 'registrations_details_form_answers',
430
-                    ),
431
-                    'registrations_details_registrant_details_help_tab' => array(
432
-                        'title'    => __('Contact Details', 'event_espresso'),
433
-                        'filename' => 'registrations_details_registrant_details',
434
-                    ),
435
-                ),
436
-                'help_tour'     => array('Registration_Details_Help_Tour'),
437
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
438
-                    array('_registration_details_metaboxes')),
439
-                'require_nonce' => false,
440
-            ),
441
-            'new_registration'  => array(
442
-                'nav'           => array(
443
-                    'label'      => __('Add New Registration', 'event_espresso'),
444
-                    'url'        => '#',
445
-                    'order'      => 15,
446
-                    'persistent' => false,
447
-                ),
448
-                'metaboxes'     => $this->_default_espresso_metaboxes,
449
-                'labels'        => array(
450
-                    'publishbox' => __('Save Registration', 'event_espresso'),
451
-                ),
452
-                'require_nonce' => false,
453
-            ),
454
-            'add_new_attendee'  => array(
455
-                'nav'           => array(
456
-                    'label'      => __('Add Contact', 'event_espresso'),
457
-                    'order'      => 15,
458
-                    'persistent' => false,
459
-                ),
460
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
461
-                    array('_publish_post_box', 'attendee_editor_metaboxes')),
462
-                'require_nonce' => false,
463
-            ),
464
-            'edit_attendee'     => array(
465
-                'nav'           => array(
466
-                    'label'      => __('Edit Contact', 'event_espresso'),
467
-                    'order'      => 15,
468
-                    'persistent' => false,
469
-                    'url'        => isset($this->_req_data['ATT_ID'])
470
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
471
-                        : $this->_admin_base_url,
472
-                ),
473
-                'metaboxes'     => array('attendee_editor_metaboxes'),
474
-                'require_nonce' => false,
475
-            ),
476
-            'contact_list'      => array(
477
-                'nav'           => array(
478
-                    'label' => __('Contact List', 'event_espresso'),
479
-                    'order' => 20,
480
-                ),
481
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
482
-                'help_tabs'     => array(
483
-                    'registrations_contact_list_help_tab'                       => array(
484
-                        'title'    => __('Registrations Contact List', 'event_espresso'),
485
-                        'filename' => 'registrations_contact_list',
486
-                    ),
487
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
488
-                        'title'    => __('Contact List Table Column Headings', 'event_espresso'),
489
-                        'filename' => 'registrations_contact_list_table_column_headings',
490
-                    ),
491
-                    'registrations_contact_list_views_help_tab'                 => array(
492
-                        'title'    => __('Contact List Views', 'event_espresso'),
493
-                        'filename' => 'registrations_contact_list_views',
494
-                    ),
495
-                    'registrations_contact_list_other_help_tab'                 => array(
496
-                        'title'    => __('Contact List Other', 'event_espresso'),
497
-                        'filename' => 'registrations_contact_list_other',
498
-                    ),
499
-                ),
500
-                'help_tour'     => array('Contact_List_Help_Tour'),
501
-                'metaboxes'     => array(),
502
-                'require_nonce' => false,
503
-            ),
504
-            //override default cpt routes
505
-            'create_new'        => '',
506
-            'edit'              => '',
507
-        );
508
-    }
509
-
510
-
511
-    /**
512
-     * The below methods aren't used by this class currently
513
-     */
514
-    protected function _add_screen_options()
515
-    {
516
-    }
517
-
518
-
519
-    protected function _add_feature_pointers()
520
-    {
521
-    }
522
-
523
-
524
-    public function admin_init()
525
-    {
526
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes',
527
-            'event_espresso');
528
-    }
529
-
530
-
531
-    public function admin_notices()
532
-    {
533
-    }
534
-
535
-
536
-    public function admin_footer_scripts()
537
-    {
538
-    }
539
-
540
-
541
-    /**
542
-     *        get list of registration statuses
543
-     *
544
-     * @access private
545
-     * @return void
546
-     */
547
-    private function _get_registration_status_array()
548
-    {
549
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
550
-    }
551
-
552
-
553
-    protected function _add_screen_options_default()
554
-    {
555
-        $this->_per_page_screen_option();
556
-    }
557
-
558
-
559
-    protected function _add_screen_options_contact_list()
560
-    {
561
-        $page_title              = $this->_admin_page_title;
562
-        $this->_admin_page_title = __("Contacts", 'event_espresso');
563
-        $this->_per_page_screen_option();
564
-        $this->_admin_page_title = $page_title;
565
-    }
566
-
567
-
568
-    public function load_scripts_styles()
569
-    {
570
-        //style
571
-        //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
572
-        wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'),
573
-            EVENT_ESPRESSO_VERSION);
574
-        wp_enqueue_style('espresso_reg');
575
-        //script
576
-        wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js',
577
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true);
578
-        wp_enqueue_script('espresso_reg');
579
-    }
580
-
581
-
582
-    public function load_scripts_styles_edit_attendee()
583
-    {
584
-        //stuff to only show up on our attendee edit details page.
585
-        $attendee_details_translations = array(
586
-            'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'),
587
-                $this->_cpt_model_obj->get_datetime('ATT_created')),
588
-        );
589
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
590
-        wp_enqueue_script('jquery-validate');
591
-    }
592
-
593
-
594
-    public function load_scripts_styles_view_registration()
595
-    {
596
-        //styles
597
-        wp_enqueue_style('espresso-ui-theme');
598
-        //scripts
599
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
600
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
601
-    }
602
-
603
-
604
-    public function load_scripts_styles_contact_list()
605
-    {
606
-        wp_deregister_style('espresso_reg');
607
-        wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'),
608
-            EVENT_ESPRESSO_VERSION);
609
-        wp_enqueue_style('espresso_att');
610
-    }
611
-
612
-
613
-    public function load_scripts_styles_new_registration()
614
-    {
615
-        wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'),
616
-            EVENT_ESPRESSO_VERSION, true);
617
-        wp_enqueue_script('ee-spco-for-admin');
618
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
619
-        EE_Form_Section_Proper::wp_enqueue_scripts();
620
-        EED_Ticket_Selector::load_tckt_slctr_assets();
621
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
622
-    }
623
-
624
-
625
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
626
-    {
627
-        add_filter('FHEE_load_EE_messages', '__return_true');
628
-    }
629
-
630
-
631
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
632
-    {
633
-        add_filter('FHEE_load_EE_messages', '__return_true');
634
-    }
635
-
636
-
637
-    protected function _set_list_table_views_default()
638
-    {
639
-        //for notification related bulk actions we need to make sure only active messengers have an option.
640
-        EED_Messages::set_autoloaders();
641
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
642
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
643
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
644
-        //key= bulk_action_slug, value= message type.
645
-        $match_array = array(
646
-            'approve_registration'    => 'registration',
647
-            'decline_registration'    => 'declined_registration',
648
-            'pending_registration'    => 'pending_approval',
649
-            'no_approve_registration' => 'not_approved_registration',
650
-            'cancel_registration'     => 'cancelled_registration',
651
-        );
652
-        /** setup reg status bulk actions **/
653
-        $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
654
-        if (in_array($match_array['approve_registration'], $active_mts)
655
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
656
-        ) {
657
-            $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
658
-                'event_espresso');
659
-        }
660
-        $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
661
-        if (in_array($match_array['decline_registration'], $active_mts)
662
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
663
-        ) {
664
-            $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
665
-                'event_espresso');
666
-        }
667
-        $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
668
-        if (in_array($match_array['pending_registration'], $active_mts)
669
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
670
-        ) {
671
-            $def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify',
672
-                'event_espresso');
673
-        }
674
-        $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
675
-        if (in_array($match_array['no_approve_registration'], $active_mts)
676
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
677
-        ) {
678
-            $def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify',
679
-                'event_espresso');
680
-        }
681
-        $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
682
-        if (in_array($match_array['cancel_registration'], $active_mts)
683
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
684
-        ) {
685
-            $def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify',
686
-                'event_espresso');
687
-        }
688
-        $this->_views = array(
689
-            'all'   => array(
690
-                'slug'        => 'all',
691
-                'label'       => __('View All Registrations', 'event_espresso'),
692
-                'count'       => 0,
693
-                'bulk_action' => array_merge($def_reg_status_actions, array(
694
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
695
-                )),
696
-            ),
697
-            'month' => array(
698
-                'slug'        => 'month',
699
-                'label'       => __('This Month', 'event_espresso'),
700
-                'count'       => 0,
701
-                'bulk_action' => array_merge($def_reg_status_actions, array(
702
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
703
-                )),
704
-            ),
705
-            'today' => array(
706
-                'slug'        => 'today',
707
-                'label'       => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))),
708
-                'count'       => 0,
709
-                'bulk_action' => array_merge($def_reg_status_actions, array(
710
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
711
-                )),
712
-            ),
713
-        );
714
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations',
715
-            'espresso_registrations_delete_registration')
716
-        ) {
717
-            $this->_views['incomplete'] = array(
718
-                'slug'        => 'incomplete',
719
-                'label'       => __('Incomplete', 'event_espresso'),
720
-                'count'       => 0,
721
-                'bulk_action' => array(
722
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
723
-                ),
724
-            );
725
-            $this->_views['trash']      = array(
726
-                'slug'        => 'trash',
727
-                'label'       => __('Trash', 'event_espresso'),
728
-                'count'       => 0,
729
-                'bulk_action' => array(
730
-                    'restore_registrations' => __('Restore Registrations', 'event_espresso'),
731
-                    'delete_registrations'  => __('Delete Registrations Permanently', 'event_espresso'),
732
-                ),
733
-            );
734
-        }
735
-    }
736
-
737
-
738
-    protected function _set_list_table_views_contact_list()
739
-    {
740
-        $this->_views = array(
741
-            'in_use' => array(
742
-                'slug'        => 'in_use',
743
-                'label'       => __('In Use', 'event_espresso'),
744
-                'count'       => 0,
745
-                'bulk_action' => array(
746
-                    'trash_attendees' => __('Move to Trash', 'event_espresso'),
747
-                ),
748
-            ),
749
-        );
750
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
751
-            'espresso_registrations_trash_attendees')
752
-        ) {
753
-            $this->_views['trash'] = array(
754
-                'slug'        => 'trash',
755
-                'label'       => __('Trash', 'event_espresso'),
756
-                'count'       => 0,
757
-                'bulk_action' => array(
758
-                    'restore_attendees' => __('Restore from Trash', 'event_espresso'),
759
-                ),
760
-            );
761
-        }
762
-    }
763
-
764
-
765
-    protected function _registration_legend_items()
766
-    {
767
-        $fc_items = array(
768
-            'star-icon'        => array(
769
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
770
-                'desc'  => __('This is the Primary Registrant', 'event_espresso'),
771
-            ),
772
-            'view_details'     => array(
773
-                'class' => 'dashicons dashicons-clipboard',
774
-                'desc'  => __('View Registration Details', 'event_espresso'),
775
-            ),
776
-            'edit_attendee'    => array(
777
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
778
-                'desc'  => __('Edit Contact Details', 'event_espresso'),
779
-            ),
780
-            'view_transaction' => array(
781
-                'class' => 'dashicons dashicons-cart',
782
-                'desc'  => __('View Transaction Details', 'event_espresso'),
783
-            ),
784
-            'view_invoice'     => array(
785
-                'class' => 'dashicons dashicons-media-spreadsheet',
786
-                'desc'  => __('View Transaction Invoice', 'event_espresso'),
787
-            ),
788
-        );
789
-        if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
790
-            'espresso_registrations_resend_registration')
791
-        ) {
792
-            $fc_items['resend_registration'] = array(
793
-                'class' => 'dashicons dashicons-email-alt',
794
-                'desc'  => __('Resend Registration Details', 'event_espresso'),
795
-            );
796
-        } else {
797
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
798
-        }
799
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
800
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
801
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
802
-                $fc_items['view_related_messages'] = array(
803
-                    'class' => $related_for_icon['css_class'],
804
-                    'desc'  => $related_for_icon['label'],
805
-                );
806
-            }
807
-        }
808
-        $sc_items = array(
809
-            'approved_status'   => array(
810
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
811
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
812
-            ),
813
-            'pending_status'    => array(
814
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
815
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
816
-            ),
817
-            'wait_list'         => array(
818
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
819
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
820
-            ),
821
-            'incomplete_status' => array(
822
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
823
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'),
824
-            ),
825
-            'not_approved'      => array(
826
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
827
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
828
-            ),
829
-            'declined_status'   => array(
830
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
831
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
832
-            ),
833
-            'cancelled_status'  => array(
834
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
835
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
836
-            ),
837
-        );
838
-        return array_merge($fc_items, $sc_items);
839
-    }
840
-
841
-
842
-
843
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
844
-    /**
845
-     * @throws \EE_Error
846
-     */
847
-    protected function _registrations_overview_list_table()
848
-    {
849
-        $this->_template_args['admin_page_header'] = '';
850
-        $EVT_ID                                    = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0;
851
-        if ($EVT_ID) {
852
-            if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations',
853
-                'espresso_registrations_new_registration', $EVT_ID)
854
-            ) {
855
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant',
856
-                        array('event_id' => $EVT_ID), 'add-new-h2');
857
-            }
858
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
859
-            if ($event instanceof EE_Event) {
860
-                $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s',
861
-                    'event_espresso'), '<h3 style="line-height:1.5em;">',
862
-                    '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array(
863
-                        'action' => 'edit',
864
-                        'post'   => $event->ID(),
865
-                    ), EVENTS_ADMIN_URL) . '">&nbsp;' . $event->get('EVT_name') . '&nbsp;</a>&nbsp;', '</h3>');
866
-            }
867
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
868
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
869
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
870
-                $this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5);
871
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
872
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
873
-                $this->_template_args['admin_page_header'] .= $datetime->name();
874
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
875
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
876
-            }
877
-        }
878
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
879
-        $this->display_admin_list_table_page_with_no_sidebar();
880
-    }
881
-
882
-
883
-    /**
884
-     * This sets the _registration property for the registration details screen
885
-     *
886
-     * @access private
887
-     * @return bool
888
-     */
889
-    private function _set_registration_object()
890
-    {
891
-        //get out if we've already set the object
892
-        if (is_object($this->_registration)) {
893
-            return true;
894
-        }
895
-        $REG    = EEM_Registration::instance();
896
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
897
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
898
-            return true;
899
-        } else {
900
-            $error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.',
901
-                'event_espresso'), $REG_ID);
902
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
903
-            $this->_registration = null;
904
-            return false;
905
-        }
906
-    }
907
-
908
-
909
-    /**
910
-     * Used to retrieve registrations for the list table.
911
-     *
912
-     * @param int    $per_page
913
-     * @param bool   $count
914
-     * @param bool   $this_month
915
-     * @param bool   $today
916
-     * @return \EE_Registration[]|int
917
-     */
918
-    public function get_registrations(
919
-        $per_page = 10,
920
-        $count = false,
921
-        $this_month = false,
922
-        $today = false
923
-    ) {
924
-        if( $this_month ) {
925
-            $this->_req_data['status'] = 'month';
926
-        }
927
-        if( $today ) {
928
-            $this->_req_data['status'] = 'today';
929
-        }
930
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
931
-        /**
932
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
933
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
934
-         * @see EEM_Base::get_all()
935
-         */
936
-        $query_params['group_by'] = '';
937
-
938
-        return $count
939
-            ? EEM_Registration::instance()->count($query_params)
940
-            /** @type EE_Registration[] */
941
-            : EEM_Registration::instance()->get_all($query_params);
942
-    }
943
-
944
-
945
-
946
-    /**
947
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
948
-     * Note: this listens to values on the request for some of the query parameters.
949
-     *
950
-     * @param array $request
951
-     * @param int    $per_page
952
-     * @param bool   $count
953
-     * @return array
954
-     */
955
-    protected function _get_registration_query_parameters(
956
-        $request = array(),
957
-        $per_page = 10,
958
-        $count = false
959
-    ) {
960
-
961
-        $query_params = array(
962
-            0                          => $this->_get_where_conditions_for_registrations_query(
963
-                $request
964
-            ),
965
-            'caps'                     => EEM_Registration::caps_read_admin,
966
-            'default_where_conditions' => 'this_model_only',
967
-        );
968
-        if ( ! $count) {
969
-            $query_params = array_merge(
970
-                $query_params,
971
-                $this->_get_orderby_for_registrations_query(),
972
-                $this->_get_limit($per_page)
973
-            );
974
-        }
975
-
976
-        return $query_params;
977
-    }
978
-
979
-
980
-    /**
981
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
982
-     *
983
-     * @param array $request usually the same as $this->_req_data but not necessarily
984
-     * @return array
985
-     */
986
-    protected function _add_event_id_to_where_conditions(array $request)
987
-    {
988
-        $where = array();
989
-        if ( ! empty($request['event_id'])) {
990
-            $where['EVT_ID'] = absint($request['event_id']);
991
-        }
992
-        return $where;
993
-    }
994
-
995
-
996
-    /**
997
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
998
-     *
999
-     * @param array $request usually the same as $this->_req_data but not necessarily
1000
-     * @return array
1001
-     */
1002
-    protected function _add_category_id_to_where_conditions(array $request)
1003
-    {
1004
-        $where = array();
1005
-        if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1006
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1007
-        }
1008
-        return $where;
1009
-    }
1010
-
1011
-
1012
-    /**
1013
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1014
-     *
1015
-     * @param array $request usually the same as $this->_req_data but not necessarily
1016
-     * @return array
1017
-     */
1018
-    protected function _add_datetime_id_to_where_conditions(array $request)
1019
-    {
1020
-        $where = array();
1021
-        if ( ! empty($request['datetime_id'])) {
1022
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1023
-        }
1024
-        if( ! empty($request['DTT_ID'])){
1025
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1026
-        }
1027
-        return $where;
1028
-    }
1029
-
1030
-
1031
-    /**
1032
-     * Adds the correct registration status to the where conditions for the registrations query.
1033
-     *
1034
-     * @param array $request usually the same as $this->_req_data but not necessarily
1035
-     * @return array
1036
-     */
1037
-    protected function _add_registration_status_to_where_conditions(array $request)
1038
-    {
1039
-        $where = array();
1040
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1041
-        $registration_status = ! empty($request['_reg_status'])
1042
-            ? sanitize_text_field($request['_reg_status'])
1043
-            : '';
1044
-
1045
-        /*
26
+	/**
27
+	 * @var EE_Registration
28
+	 */
29
+	private $_registration;
30
+
31
+	/**
32
+	 * @var EE_Event
33
+	 */
34
+	private $_reg_event;
35
+
36
+	/**
37
+	 * @var EE_Session
38
+	 */
39
+	private $_session;
40
+
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+
52
+	/**
53
+	 *        constructor
54
+	 *
55
+	 * @Constructor
56
+	 * @access public
57
+	 * @param bool $routing
58
+	 * @return Registrations_Admin_Page
59
+	 */
60
+	public function __construct($routing = true)
61
+	{
62
+		parent::__construct($routing);
63
+		add_action('wp_loaded', array($this, 'wp_loaded'));
64
+	}
65
+
66
+
67
+	public function wp_loaded()
68
+	{
69
+		// when adding a new registration...
70
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
+			EE_System::do_not_cache();
72
+			if ( ! isset($this->_req_data['processing_registration'])
73
+				 || absint($this->_req_data['processing_registration']) !== 1
74
+			) {
75
+				// and it's NOT the attendee information reg step
76
+				// force cookie expiration by setting time to last week
77
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
+				// and update the global
79
+				$_COOKIE['ee_registration_added'] = 0;
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+	protected function _init_page_props()
86
+	{
87
+		$this->page_slug        = REG_PG_SLUG;
88
+		$this->_admin_base_url  = REG_ADMIN_URL;
89
+		$this->_admin_base_path = REG_ADMIN;
90
+		$this->page_label       = __('Registrations', 'event_espresso');
91
+		$this->_cpt_routes      = array(
92
+			'add_new_attendee' => 'espresso_attendees',
93
+			'edit_attendee'    => 'espresso_attendees',
94
+			'insert_attendee'  => 'espresso_attendees',
95
+			'update_attendee'  => 'espresso_attendees',
96
+		);
97
+		$this->_cpt_model_names = array(
98
+			'add_new_attendee' => 'EEM_Attendee',
99
+			'edit_attendee'    => 'EEM_Attendee',
100
+		);
101
+		$this->_cpt_edit_routes = array(
102
+			'espresso_attendees' => 'edit_attendee',
103
+		);
104
+		$this->_pagenow_map     = array(
105
+			'add_new_attendee' => 'post-new.php',
106
+			'edit_attendee'    => 'post.php',
107
+			'trash'            => 'post.php',
108
+		);
109
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
+		//add filters so that the comment urls don't take users to a confusing 404 page
111
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
+	}
113
+
114
+
115
+	public function clear_comment_link($link, $comment, $args)
116
+	{
117
+		//gotta make sure this only happens on this route
118
+		$post_type = get_post_type($comment->comment_post_ID);
119
+		if ($post_type === 'espresso_attendees') {
120
+			return '#commentsdiv';
121
+		}
122
+		return $link;
123
+	}
124
+
125
+
126
+	protected function _ajax_hooks()
127
+	{
128
+		//todo: all hooks for registrations ajax goes in here
129
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
+	}
131
+
132
+
133
+	protected function _define_page_props()
134
+	{
135
+		$this->_admin_page_title = $this->page_label;
136
+		$this->_labels           = array(
137
+			'buttons'                      => array(
138
+				'add-registrant'      => __('Add New Registration', 'event_espresso'),
139
+				'add-attendee'        => __('Add Contact', 'event_espresso'),
140
+				'edit'                => __('Edit Contact', 'event_espresso'),
141
+				'report'              => __("Event Registrations CSV Report", "event_espresso"),
142
+				'report_all'          => __('All Registrations CSV Report', 'event_espresso'),
143
+				'report_filtered'     => __('Filtered CSV Report', 'event_espresso'),
144
+				'contact_list_report' => __('Contact List Report', 'event_espresso'),
145
+				'contact_list_export' => __("Export Data", "event_espresso"),
146
+			),
147
+			'publishbox'                   => array(
148
+				'add_new_attendee' => __("Add Contact Record", 'event_espresso'),
149
+				'edit_attendee'    => __("Update Contact Record", 'event_espresso'),
150
+			),
151
+			'hide_add_button_on_cpt_route' => array(
152
+				'edit_attendee' => true,
153
+			),
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *        grab url requests and route them
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	public function _set_page_routes()
165
+	{
166
+		$this->_get_registration_status_array();
167
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
+			? $this->_req_data['_REG_ID'] : 0;
169
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
+			? $this->_req_data['ATT_ID'] : 0;
171
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post']
172
+			: $att_id;
173
+		$this->_page_routes = array(
174
+			'default'                            => array(
175
+				'func'       => '_registrations_overview_list_table',
176
+				'capability' => 'ee_read_registrations',
177
+			),
178
+			'view_registration'                  => array(
179
+				'func'       => '_registration_details',
180
+				'capability' => 'ee_read_registration',
181
+				'obj_id'     => $reg_id,
182
+			),
183
+			'edit_registration'                  => array(
184
+				'func'               => '_update_attendee_registration_form',
185
+				'noheader'           => true,
186
+				'headers_sent_route' => 'view_registration',
187
+				'capability'         => 'ee_edit_registration',
188
+				'obj_id'             => $reg_id,
189
+				'_REG_ID'            => $reg_id,
190
+			),
191
+			'trash_registrations'                => array(
192
+				'func'       => '_trash_or_restore_registrations',
193
+				'args'       => array('trash' => true),
194
+				'noheader'   => true,
195
+				'capability' => 'ee_delete_registrations',
196
+			),
197
+			'restore_registrations'              => array(
198
+				'func'       => '_trash_or_restore_registrations',
199
+				'args'       => array('trash' => false),
200
+				'noheader'   => true,
201
+				'capability' => 'ee_delete_registrations',
202
+			),
203
+			'delete_registrations'               => array(
204
+				'func'       => '_delete_registrations',
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'new_registration'                   => array(
209
+				'func'       => 'new_registration',
210
+				'capability' => 'ee_edit_registrations',
211
+			),
212
+			'process_reg_step'                   => array(
213
+				'func'       => 'process_reg_step',
214
+				'noheader'   => true,
215
+				'capability' => 'ee_edit_registrations',
216
+			),
217
+			'redirect_to_txn'                    => array(
218
+				'func'       => 'redirect_to_txn',
219
+				'noheader'   => true,
220
+				'capability' => 'ee_edit_registrations',
221
+			),
222
+			'change_reg_status'                  => array(
223
+				'func'       => '_change_reg_status',
224
+				'noheader'   => true,
225
+				'capability' => 'ee_edit_registration',
226
+				'obj_id'     => $reg_id,
227
+			),
228
+			'approve_registration'               => array(
229
+				'func'       => 'approve_registration',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registration',
232
+				'obj_id'     => $reg_id,
233
+			),
234
+			'approve_and_notify_registration'    => array(
235
+				'func'       => 'approve_registration',
236
+				'noheader'   => true,
237
+				'args'       => array(true),
238
+				'capability' => 'ee_edit_registration',
239
+				'obj_id'     => $reg_id,
240
+			),
241
+			'decline_registration'               => array(
242
+				'func'       => 'decline_registration',
243
+				'noheader'   => true,
244
+				'capability' => 'ee_edit_registration',
245
+				'obj_id'     => $reg_id,
246
+			),
247
+			'decline_and_notify_registration'    => array(
248
+				'func'       => 'decline_registration',
249
+				'noheader'   => true,
250
+				'args'       => array(true),
251
+				'capability' => 'ee_edit_registration',
252
+				'obj_id'     => $reg_id,
253
+			),
254
+			'pending_registration'               => array(
255
+				'func'       => 'pending_registration',
256
+				'noheader'   => true,
257
+				'capability' => 'ee_edit_registration',
258
+				'obj_id'     => $reg_id,
259
+			),
260
+			'pending_and_notify_registration'    => array(
261
+				'func'       => 'pending_registration',
262
+				'noheader'   => true,
263
+				'args'       => array(true),
264
+				'capability' => 'ee_edit_registration',
265
+				'obj_id'     => $reg_id,
266
+			),
267
+			'no_approve_registration'            => array(
268
+				'func'       => 'not_approve_registration',
269
+				'noheader'   => true,
270
+				'capability' => 'ee_edit_registration',
271
+				'obj_id'     => $reg_id,
272
+			),
273
+			'no_approve_and_notify_registration' => array(
274
+				'func'       => 'not_approve_registration',
275
+				'noheader'   => true,
276
+				'args'       => array(true),
277
+				'capability' => 'ee_edit_registration',
278
+				'obj_id'     => $reg_id,
279
+			),
280
+			'cancel_registration'                => array(
281
+				'func'       => 'cancel_registration',
282
+				'noheader'   => true,
283
+				'capability' => 'ee_edit_registration',
284
+				'obj_id'     => $reg_id,
285
+			),
286
+			'cancel_and_notify_registration'     => array(
287
+				'func'       => 'cancel_registration',
288
+				'noheader'   => true,
289
+				'args'       => array(true),
290
+				'capability' => 'ee_edit_registration',
291
+				'obj_id'     => $reg_id,
292
+			),
293
+			'contact_list'                       => array(
294
+				'func'       => '_attendee_contact_list_table',
295
+				'capability' => 'ee_read_contacts',
296
+			),
297
+			'add_new_attendee'                   => array(
298
+				'func' => '_create_new_cpt_item',
299
+				'args' => array(
300
+					'new_attendee' => true,
301
+					'capability'   => 'ee_edit_contacts',
302
+				),
303
+			),
304
+			'edit_attendee'                      => array(
305
+				'func'       => '_edit_cpt_item',
306
+				'capability' => 'ee_edit_contacts',
307
+				'obj_id'     => $att_id,
308
+			),
309
+			'duplicate_attendee'                 => array(
310
+				'func'       => '_duplicate_attendee',
311
+				'noheader'   => true,
312
+				'capability' => 'ee_edit_contacts',
313
+				'obj_id'     => $att_id,
314
+			),
315
+			'insert_attendee'                    => array(
316
+				'func'       => '_insert_or_update_attendee',
317
+				'args'       => array(
318
+					'new_attendee' => true,
319
+				),
320
+				'noheader'   => true,
321
+				'capability' => 'ee_edit_contacts',
322
+			),
323
+			'update_attendee'                    => array(
324
+				'func'       => '_insert_or_update_attendee',
325
+				'args'       => array(
326
+					'new_attendee' => false,
327
+				),
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_contacts',
330
+				'obj_id'     => $att_id,
331
+			),
332
+			'trash_attendees'                    => array(
333
+				'func'       => '_trash_or_restore_attendees',
334
+				'args'       => array(
335
+					'trash' => true,
336
+				),
337
+				'noheader'   => true,
338
+				'capability' => 'ee_delete_contacts',
339
+				'obj_id'     => $att_id,
340
+			),
341
+			'restore_attendees'                  => array(
342
+				'func'       => '_trash_or_restore_attendees',
343
+				'args'       => array(
344
+					'trash' => false,
345
+				),
346
+				'noheader'   => true,
347
+				'capability' => 'ee_delete_contacts',
348
+				'obj_id'     => $att_id,
349
+			),
350
+			'resend_registration'                => array(
351
+				'func'       => '_resend_registration',
352
+				'noheader'   => true,
353
+				'capability' => 'ee_send_message',
354
+			),
355
+			'registrations_report'               => array(
356
+				'func'       => '_registrations_report',
357
+				'noheader'   => true,
358
+				'capability' => 'ee_read_registrations',
359
+			),
360
+			'contact_list_export'                => array(
361
+				'func'       => '_contact_list_export',
362
+				'noheader'   => true,
363
+				'capability' => 'export',
364
+			),
365
+			'contact_list_report'                => array(
366
+				'func'       => '_contact_list_report',
367
+				'noheader'   => true,
368
+				'capability' => 'ee_read_contacts',
369
+			),
370
+		);
371
+	}
372
+
373
+
374
+	protected function _set_page_config()
375
+	{
376
+		$this->_page_config = array(
377
+			'default'           => array(
378
+				'nav'           => array(
379
+					'label' => __('Overview', 'event_espresso'),
380
+					'order' => 5,
381
+				),
382
+				'help_tabs'     => array(
383
+					'registrations_overview_help_tab'                       => array(
384
+						'title'    => __('Registrations Overview', 'event_espresso'),
385
+						'filename' => 'registrations_overview',
386
+					),
387
+					'registrations_overview_table_column_headings_help_tab' => array(
388
+						'title'    => __('Registrations Table Column Headings', 'event_espresso'),
389
+						'filename' => 'registrations_overview_table_column_headings',
390
+					),
391
+					'registrations_overview_filters_help_tab'               => array(
392
+						'title'    => __('Registration Filters', 'event_espresso'),
393
+						'filename' => 'registrations_overview_filters',
394
+					),
395
+					'registrations_overview_views_help_tab'                 => array(
396
+						'title'    => __('Registration Views', 'event_espresso'),
397
+						'filename' => 'registrations_overview_views',
398
+					),
399
+					'registrations_regoverview_other_help_tab'              => array(
400
+						'title'    => __('Registrations Other', 'event_espresso'),
401
+						'filename' => 'registrations_overview_other',
402
+					),
403
+				),
404
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
405
+				'qtips'         => array('Registration_List_Table_Tips'),
406
+				'list_table'    => 'EE_Registrations_List_Table',
407
+				'require_nonce' => false,
408
+			),
409
+			'view_registration' => array(
410
+				'nav'           => array(
411
+					'label'      => __('REG Details', 'event_espresso'),
412
+					'order'      => 15,
413
+					'url'        => isset($this->_req_data['_REG_ID'])
414
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
415
+						: $this->_admin_base_url,
416
+					'persistent' => false,
417
+				),
418
+				'help_tabs'     => array(
419
+					'registrations_details_help_tab'                    => array(
420
+						'title'    => __('Registration Details', 'event_espresso'),
421
+						'filename' => 'registrations_details',
422
+					),
423
+					'registrations_details_table_help_tab'              => array(
424
+						'title'    => __('Registration Details Table', 'event_espresso'),
425
+						'filename' => 'registrations_details_table',
426
+					),
427
+					'registrations_details_form_answers_help_tab'       => array(
428
+						'title'    => __('Registration Form Answers', 'event_espresso'),
429
+						'filename' => 'registrations_details_form_answers',
430
+					),
431
+					'registrations_details_registrant_details_help_tab' => array(
432
+						'title'    => __('Contact Details', 'event_espresso'),
433
+						'filename' => 'registrations_details_registrant_details',
434
+					),
435
+				),
436
+				'help_tour'     => array('Registration_Details_Help_Tour'),
437
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
438
+					array('_registration_details_metaboxes')),
439
+				'require_nonce' => false,
440
+			),
441
+			'new_registration'  => array(
442
+				'nav'           => array(
443
+					'label'      => __('Add New Registration', 'event_espresso'),
444
+					'url'        => '#',
445
+					'order'      => 15,
446
+					'persistent' => false,
447
+				),
448
+				'metaboxes'     => $this->_default_espresso_metaboxes,
449
+				'labels'        => array(
450
+					'publishbox' => __('Save Registration', 'event_espresso'),
451
+				),
452
+				'require_nonce' => false,
453
+			),
454
+			'add_new_attendee'  => array(
455
+				'nav'           => array(
456
+					'label'      => __('Add Contact', 'event_espresso'),
457
+					'order'      => 15,
458
+					'persistent' => false,
459
+				),
460
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
461
+					array('_publish_post_box', 'attendee_editor_metaboxes')),
462
+				'require_nonce' => false,
463
+			),
464
+			'edit_attendee'     => array(
465
+				'nav'           => array(
466
+					'label'      => __('Edit Contact', 'event_espresso'),
467
+					'order'      => 15,
468
+					'persistent' => false,
469
+					'url'        => isset($this->_req_data['ATT_ID'])
470
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
471
+						: $this->_admin_base_url,
472
+				),
473
+				'metaboxes'     => array('attendee_editor_metaboxes'),
474
+				'require_nonce' => false,
475
+			),
476
+			'contact_list'      => array(
477
+				'nav'           => array(
478
+					'label' => __('Contact List', 'event_espresso'),
479
+					'order' => 20,
480
+				),
481
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
482
+				'help_tabs'     => array(
483
+					'registrations_contact_list_help_tab'                       => array(
484
+						'title'    => __('Registrations Contact List', 'event_espresso'),
485
+						'filename' => 'registrations_contact_list',
486
+					),
487
+					'registrations_contact-list_table_column_headings_help_tab' => array(
488
+						'title'    => __('Contact List Table Column Headings', 'event_espresso'),
489
+						'filename' => 'registrations_contact_list_table_column_headings',
490
+					),
491
+					'registrations_contact_list_views_help_tab'                 => array(
492
+						'title'    => __('Contact List Views', 'event_espresso'),
493
+						'filename' => 'registrations_contact_list_views',
494
+					),
495
+					'registrations_contact_list_other_help_tab'                 => array(
496
+						'title'    => __('Contact List Other', 'event_espresso'),
497
+						'filename' => 'registrations_contact_list_other',
498
+					),
499
+				),
500
+				'help_tour'     => array('Contact_List_Help_Tour'),
501
+				'metaboxes'     => array(),
502
+				'require_nonce' => false,
503
+			),
504
+			//override default cpt routes
505
+			'create_new'        => '',
506
+			'edit'              => '',
507
+		);
508
+	}
509
+
510
+
511
+	/**
512
+	 * The below methods aren't used by this class currently
513
+	 */
514
+	protected function _add_screen_options()
515
+	{
516
+	}
517
+
518
+
519
+	protected function _add_feature_pointers()
520
+	{
521
+	}
522
+
523
+
524
+	public function admin_init()
525
+	{
526
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes',
527
+			'event_espresso');
528
+	}
529
+
530
+
531
+	public function admin_notices()
532
+	{
533
+	}
534
+
535
+
536
+	public function admin_footer_scripts()
537
+	{
538
+	}
539
+
540
+
541
+	/**
542
+	 *        get list of registration statuses
543
+	 *
544
+	 * @access private
545
+	 * @return void
546
+	 */
547
+	private function _get_registration_status_array()
548
+	{
549
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
550
+	}
551
+
552
+
553
+	protected function _add_screen_options_default()
554
+	{
555
+		$this->_per_page_screen_option();
556
+	}
557
+
558
+
559
+	protected function _add_screen_options_contact_list()
560
+	{
561
+		$page_title              = $this->_admin_page_title;
562
+		$this->_admin_page_title = __("Contacts", 'event_espresso');
563
+		$this->_per_page_screen_option();
564
+		$this->_admin_page_title = $page_title;
565
+	}
566
+
567
+
568
+	public function load_scripts_styles()
569
+	{
570
+		//style
571
+		//wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
572
+		wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'),
573
+			EVENT_ESPRESSO_VERSION);
574
+		wp_enqueue_style('espresso_reg');
575
+		//script
576
+		wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js',
577
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true);
578
+		wp_enqueue_script('espresso_reg');
579
+	}
580
+
581
+
582
+	public function load_scripts_styles_edit_attendee()
583
+	{
584
+		//stuff to only show up on our attendee edit details page.
585
+		$attendee_details_translations = array(
586
+			'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'),
587
+				$this->_cpt_model_obj->get_datetime('ATT_created')),
588
+		);
589
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
590
+		wp_enqueue_script('jquery-validate');
591
+	}
592
+
593
+
594
+	public function load_scripts_styles_view_registration()
595
+	{
596
+		//styles
597
+		wp_enqueue_style('espresso-ui-theme');
598
+		//scripts
599
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
600
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
601
+	}
602
+
603
+
604
+	public function load_scripts_styles_contact_list()
605
+	{
606
+		wp_deregister_style('espresso_reg');
607
+		wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'),
608
+			EVENT_ESPRESSO_VERSION);
609
+		wp_enqueue_style('espresso_att');
610
+	}
611
+
612
+
613
+	public function load_scripts_styles_new_registration()
614
+	{
615
+		wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'),
616
+			EVENT_ESPRESSO_VERSION, true);
617
+		wp_enqueue_script('ee-spco-for-admin');
618
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
619
+		EE_Form_Section_Proper::wp_enqueue_scripts();
620
+		EED_Ticket_Selector::load_tckt_slctr_assets();
621
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
622
+	}
623
+
624
+
625
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
626
+	{
627
+		add_filter('FHEE_load_EE_messages', '__return_true');
628
+	}
629
+
630
+
631
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
632
+	{
633
+		add_filter('FHEE_load_EE_messages', '__return_true');
634
+	}
635
+
636
+
637
+	protected function _set_list_table_views_default()
638
+	{
639
+		//for notification related bulk actions we need to make sure only active messengers have an option.
640
+		EED_Messages::set_autoloaders();
641
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
642
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
643
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
644
+		//key= bulk_action_slug, value= message type.
645
+		$match_array = array(
646
+			'approve_registration'    => 'registration',
647
+			'decline_registration'    => 'declined_registration',
648
+			'pending_registration'    => 'pending_approval',
649
+			'no_approve_registration' => 'not_approved_registration',
650
+			'cancel_registration'     => 'cancelled_registration',
651
+		);
652
+		/** setup reg status bulk actions **/
653
+		$def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
654
+		if (in_array($match_array['approve_registration'], $active_mts)
655
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
656
+		) {
657
+			$def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
658
+				'event_espresso');
659
+		}
660
+		$def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
661
+		if (in_array($match_array['decline_registration'], $active_mts)
662
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
663
+		) {
664
+			$def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
665
+				'event_espresso');
666
+		}
667
+		$def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
668
+		if (in_array($match_array['pending_registration'], $active_mts)
669
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
670
+		) {
671
+			$def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify',
672
+				'event_espresso');
673
+		}
674
+		$def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
675
+		if (in_array($match_array['no_approve_registration'], $active_mts)
676
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
677
+		) {
678
+			$def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify',
679
+				'event_espresso');
680
+		}
681
+		$def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
682
+		if (in_array($match_array['cancel_registration'], $active_mts)
683
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
684
+		) {
685
+			$def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify',
686
+				'event_espresso');
687
+		}
688
+		$this->_views = array(
689
+			'all'   => array(
690
+				'slug'        => 'all',
691
+				'label'       => __('View All Registrations', 'event_espresso'),
692
+				'count'       => 0,
693
+				'bulk_action' => array_merge($def_reg_status_actions, array(
694
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
695
+				)),
696
+			),
697
+			'month' => array(
698
+				'slug'        => 'month',
699
+				'label'       => __('This Month', 'event_espresso'),
700
+				'count'       => 0,
701
+				'bulk_action' => array_merge($def_reg_status_actions, array(
702
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
703
+				)),
704
+			),
705
+			'today' => array(
706
+				'slug'        => 'today',
707
+				'label'       => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))),
708
+				'count'       => 0,
709
+				'bulk_action' => array_merge($def_reg_status_actions, array(
710
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
711
+				)),
712
+			),
713
+		);
714
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations',
715
+			'espresso_registrations_delete_registration')
716
+		) {
717
+			$this->_views['incomplete'] = array(
718
+				'slug'        => 'incomplete',
719
+				'label'       => __('Incomplete', 'event_espresso'),
720
+				'count'       => 0,
721
+				'bulk_action' => array(
722
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
723
+				),
724
+			);
725
+			$this->_views['trash']      = array(
726
+				'slug'        => 'trash',
727
+				'label'       => __('Trash', 'event_espresso'),
728
+				'count'       => 0,
729
+				'bulk_action' => array(
730
+					'restore_registrations' => __('Restore Registrations', 'event_espresso'),
731
+					'delete_registrations'  => __('Delete Registrations Permanently', 'event_espresso'),
732
+				),
733
+			);
734
+		}
735
+	}
736
+
737
+
738
+	protected function _set_list_table_views_contact_list()
739
+	{
740
+		$this->_views = array(
741
+			'in_use' => array(
742
+				'slug'        => 'in_use',
743
+				'label'       => __('In Use', 'event_espresso'),
744
+				'count'       => 0,
745
+				'bulk_action' => array(
746
+					'trash_attendees' => __('Move to Trash', 'event_espresso'),
747
+				),
748
+			),
749
+		);
750
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
751
+			'espresso_registrations_trash_attendees')
752
+		) {
753
+			$this->_views['trash'] = array(
754
+				'slug'        => 'trash',
755
+				'label'       => __('Trash', 'event_espresso'),
756
+				'count'       => 0,
757
+				'bulk_action' => array(
758
+					'restore_attendees' => __('Restore from Trash', 'event_espresso'),
759
+				),
760
+			);
761
+		}
762
+	}
763
+
764
+
765
+	protected function _registration_legend_items()
766
+	{
767
+		$fc_items = array(
768
+			'star-icon'        => array(
769
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
770
+				'desc'  => __('This is the Primary Registrant', 'event_espresso'),
771
+			),
772
+			'view_details'     => array(
773
+				'class' => 'dashicons dashicons-clipboard',
774
+				'desc'  => __('View Registration Details', 'event_espresso'),
775
+			),
776
+			'edit_attendee'    => array(
777
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
778
+				'desc'  => __('Edit Contact Details', 'event_espresso'),
779
+			),
780
+			'view_transaction' => array(
781
+				'class' => 'dashicons dashicons-cart',
782
+				'desc'  => __('View Transaction Details', 'event_espresso'),
783
+			),
784
+			'view_invoice'     => array(
785
+				'class' => 'dashicons dashicons-media-spreadsheet',
786
+				'desc'  => __('View Transaction Invoice', 'event_espresso'),
787
+			),
788
+		);
789
+		if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
790
+			'espresso_registrations_resend_registration')
791
+		) {
792
+			$fc_items['resend_registration'] = array(
793
+				'class' => 'dashicons dashicons-email-alt',
794
+				'desc'  => __('Resend Registration Details', 'event_espresso'),
795
+			);
796
+		} else {
797
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
798
+		}
799
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
800
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
801
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
802
+				$fc_items['view_related_messages'] = array(
803
+					'class' => $related_for_icon['css_class'],
804
+					'desc'  => $related_for_icon['label'],
805
+				);
806
+			}
807
+		}
808
+		$sc_items = array(
809
+			'approved_status'   => array(
810
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
811
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
812
+			),
813
+			'pending_status'    => array(
814
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
815
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
816
+			),
817
+			'wait_list'         => array(
818
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
819
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
820
+			),
821
+			'incomplete_status' => array(
822
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
823
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'),
824
+			),
825
+			'not_approved'      => array(
826
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
827
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
828
+			),
829
+			'declined_status'   => array(
830
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
831
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
832
+			),
833
+			'cancelled_status'  => array(
834
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
835
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
836
+			),
837
+		);
838
+		return array_merge($fc_items, $sc_items);
839
+	}
840
+
841
+
842
+
843
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
844
+	/**
845
+	 * @throws \EE_Error
846
+	 */
847
+	protected function _registrations_overview_list_table()
848
+	{
849
+		$this->_template_args['admin_page_header'] = '';
850
+		$EVT_ID                                    = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0;
851
+		if ($EVT_ID) {
852
+			if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations',
853
+				'espresso_registrations_new_registration', $EVT_ID)
854
+			) {
855
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant',
856
+						array('event_id' => $EVT_ID), 'add-new-h2');
857
+			}
858
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
859
+			if ($event instanceof EE_Event) {
860
+				$this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s',
861
+					'event_espresso'), '<h3 style="line-height:1.5em;">',
862
+					'<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array(
863
+						'action' => 'edit',
864
+						'post'   => $event->ID(),
865
+					), EVENTS_ADMIN_URL) . '">&nbsp;' . $event->get('EVT_name') . '&nbsp;</a>&nbsp;', '</h3>');
866
+			}
867
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
868
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
869
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
870
+				$this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5);
871
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
872
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
873
+				$this->_template_args['admin_page_header'] .= $datetime->name();
874
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
875
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
876
+			}
877
+		}
878
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
879
+		$this->display_admin_list_table_page_with_no_sidebar();
880
+	}
881
+
882
+
883
+	/**
884
+	 * This sets the _registration property for the registration details screen
885
+	 *
886
+	 * @access private
887
+	 * @return bool
888
+	 */
889
+	private function _set_registration_object()
890
+	{
891
+		//get out if we've already set the object
892
+		if (is_object($this->_registration)) {
893
+			return true;
894
+		}
895
+		$REG    = EEM_Registration::instance();
896
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
897
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
898
+			return true;
899
+		} else {
900
+			$error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.',
901
+				'event_espresso'), $REG_ID);
902
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
903
+			$this->_registration = null;
904
+			return false;
905
+		}
906
+	}
907
+
908
+
909
+	/**
910
+	 * Used to retrieve registrations for the list table.
911
+	 *
912
+	 * @param int    $per_page
913
+	 * @param bool   $count
914
+	 * @param bool   $this_month
915
+	 * @param bool   $today
916
+	 * @return \EE_Registration[]|int
917
+	 */
918
+	public function get_registrations(
919
+		$per_page = 10,
920
+		$count = false,
921
+		$this_month = false,
922
+		$today = false
923
+	) {
924
+		if( $this_month ) {
925
+			$this->_req_data['status'] = 'month';
926
+		}
927
+		if( $today ) {
928
+			$this->_req_data['status'] = 'today';
929
+		}
930
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
931
+		/**
932
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
933
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
934
+		 * @see EEM_Base::get_all()
935
+		 */
936
+		$query_params['group_by'] = '';
937
+
938
+		return $count
939
+			? EEM_Registration::instance()->count($query_params)
940
+			/** @type EE_Registration[] */
941
+			: EEM_Registration::instance()->get_all($query_params);
942
+	}
943
+
944
+
945
+
946
+	/**
947
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
948
+	 * Note: this listens to values on the request for some of the query parameters.
949
+	 *
950
+	 * @param array $request
951
+	 * @param int    $per_page
952
+	 * @param bool   $count
953
+	 * @return array
954
+	 */
955
+	protected function _get_registration_query_parameters(
956
+		$request = array(),
957
+		$per_page = 10,
958
+		$count = false
959
+	) {
960
+
961
+		$query_params = array(
962
+			0                          => $this->_get_where_conditions_for_registrations_query(
963
+				$request
964
+			),
965
+			'caps'                     => EEM_Registration::caps_read_admin,
966
+			'default_where_conditions' => 'this_model_only',
967
+		);
968
+		if ( ! $count) {
969
+			$query_params = array_merge(
970
+				$query_params,
971
+				$this->_get_orderby_for_registrations_query(),
972
+				$this->_get_limit($per_page)
973
+			);
974
+		}
975
+
976
+		return $query_params;
977
+	}
978
+
979
+
980
+	/**
981
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
982
+	 *
983
+	 * @param array $request usually the same as $this->_req_data but not necessarily
984
+	 * @return array
985
+	 */
986
+	protected function _add_event_id_to_where_conditions(array $request)
987
+	{
988
+		$where = array();
989
+		if ( ! empty($request['event_id'])) {
990
+			$where['EVT_ID'] = absint($request['event_id']);
991
+		}
992
+		return $where;
993
+	}
994
+
995
+
996
+	/**
997
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
998
+	 *
999
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1000
+	 * @return array
1001
+	 */
1002
+	protected function _add_category_id_to_where_conditions(array $request)
1003
+	{
1004
+		$where = array();
1005
+		if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1006
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1007
+		}
1008
+		return $where;
1009
+	}
1010
+
1011
+
1012
+	/**
1013
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1014
+	 *
1015
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1016
+	 * @return array
1017
+	 */
1018
+	protected function _add_datetime_id_to_where_conditions(array $request)
1019
+	{
1020
+		$where = array();
1021
+		if ( ! empty($request['datetime_id'])) {
1022
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1023
+		}
1024
+		if( ! empty($request['DTT_ID'])){
1025
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1026
+		}
1027
+		return $where;
1028
+	}
1029
+
1030
+
1031
+	/**
1032
+	 * Adds the correct registration status to the where conditions for the registrations query.
1033
+	 *
1034
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1035
+	 * @return array
1036
+	 */
1037
+	protected function _add_registration_status_to_where_conditions(array $request)
1038
+	{
1039
+		$where = array();
1040
+		$view  = EEH_Array::is_set( $request, 'status', '' );
1041
+		$registration_status = ! empty($request['_reg_status'])
1042
+			? sanitize_text_field($request['_reg_status'])
1043
+			: '';
1044
+
1045
+		/*
1046 1046
          * If filtering by registration status, then we show registrations matching that status.
1047 1047
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations UNLESS
1048 1048
          * viewing trashed registrations.
1049 1049
          */
1050
-        if ( ! empty($registration_status)) {
1051
-            $where['STS_ID'] = $registration_status;
1052
-        } else {
1053
-            //make sure we exclude incomplete registrations, but only if not trashed.
1054
-            if ($view === 'trash') {
1055
-                $where['REG_deleted'] = true;
1056
-            } else if ($view === 'incomplete') {
1057
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1058
-            } else {
1059
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1060
-            }
1061
-        }
1062
-        return $where;
1063
-    }
1064
-
1065
-
1066
-    /**
1067
-     * Adds any provided date restraints to the where conditions for the registrations query.
1068
-     *
1069
-     * @param array $request usually the same as $this->_req_data but not necessarily
1070
-     * @return array
1071
-     */
1072
-    protected function _add_date_to_where_conditions(array $request)
1073
-    {
1074
-        $where = array();
1075
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1076
-        $month_range             = ! empty($request['month_range'])
1077
-            ? sanitize_text_field($request['month_range'])
1078
-            : '';
1079
-        $retrieve_for_today      = $view === 'today';
1080
-        $retrieve_for_this_month = $view === 'month';
1081
-
1082
-        if ($retrieve_for_today) {
1083
-            $now               = date('Y-m-d', current_time('timestamp'));
1084
-            $where['REG_date'] = array(
1085
-                'BETWEEN',
1086
-                array(
1087
-                    EEM_Registration::instance()->convert_datetime_for_query(
1088
-                        'REG_date',
1089
-                        $now . ' 00:00:00',
1090
-                        'Y-m-d H:i:s'
1091
-                    ),
1092
-                    EEM_Registration::instance()->convert_datetime_for_query(
1093
-                        'REG_date',
1094
-                        $now . ' 23:59:59',
1095
-                        'Y-m-d H:i:s'
1096
-                    ),
1097
-                ),
1098
-            );
1099
-        } elseif ($retrieve_for_this_month) {
1100
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1101
-            $days_this_month        = date('t', current_time('timestamp'));
1102
-            $where['REG_date']      = array(
1103
-                'BETWEEN',
1104
-                array(
1105
-                    EEM_Registration::instance()->convert_datetime_for_query(
1106
-                        'REG_date',
1107
-                        $current_year_and_month . '-01 00:00:00',
1108
-                        'Y-m-d H:i:s'
1109
-                    ),
1110
-                    EEM_Registration::instance()->convert_datetime_for_query(
1111
-                        'REG_date',
1112
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1113
-                        'Y-m-d H:i:s'
1114
-                    ),
1115
-                ),
1116
-            );
1117
-        } elseif ($month_range) {
1118
-            $pieces          = explode(' ', $month_range, 3);
1119
-            $month_requested = ! empty($pieces[0])
1120
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1121
-                : '';
1122
-            $year_requested  = ! empty($pieces[1])
1123
-                ? $pieces[1]
1124
-                : '';
1125
-            //if there is not a month or year then we can't go further
1126
-            if ($month_requested && $year_requested) {
1127
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1128
-                $where['REG_date'] = array(
1129
-                    'BETWEEN',
1130
-                    array(
1131
-                        EEM_Registration::instance()->convert_datetime_for_query(
1132
-                            'REG_date',
1133
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1134
-                            'Y-m-d H:i:s'
1135
-                        ),
1136
-                        EEM_Registration::instance()->convert_datetime_for_query(
1137
-                            'REG_date',
1138
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1139
-                            'Y-m-d H:i:s'
1140
-                        ),
1141
-                    ),
1142
-                );
1143
-            }
1144
-        }
1145
-        return $where;
1146
-    }
1147
-
1148
-
1149
-    /**
1150
-     * Adds any provided search restraints to the where conditions for the registrations query
1151
-     *
1152
-     * @param array $request usually the same as $this->_req_data but not necessarily
1153
-     * @return array
1154
-     */
1155
-    protected function _add_search_to_where_conditions(array $request)
1156
-    {
1157
-        $where = array();
1158
-        if ( ! empty($request['s'])) {
1159
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1160
-            $where['OR'] = array(
1161
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1162
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1163
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1164
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1165
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1166
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1167
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1168
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1169
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1170
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1171
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1172
-                'REG_final_price'                         => array('LIKE', $search_string),
1173
-                'REG_code'                                => array('LIKE', $search_string),
1174
-                'REG_count'                               => array('LIKE', $search_string),
1175
-                'REG_group_size'                          => array('LIKE', $search_string),
1176
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1177
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1178
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1179
-            );
1180
-        }
1181
-        return $where;
1182
-    }
1183
-
1184
-
1185
-    /**
1186
-     * Sets up the where conditions for the registrations query.
1187
-     *
1188
-     * @param array $request
1189
-     * @return array
1190
-     */
1191
-    protected function _get_where_conditions_for_registrations_query($request)
1192
-    {
1193
-        return array_merge(
1194
-            $this->_add_event_id_to_where_conditions($request),
1195
-            $this->_add_category_id_to_where_conditions($request),
1196
-            $this->_add_datetime_id_to_where_conditions($request),
1197
-            $this->_add_registration_status_to_where_conditions($request),
1198
-            $this->_add_date_to_where_conditions($request),
1199
-            $this->_add_search_to_where_conditions($request)
1200
-        );
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * Sets up the orderby for the registrations query.
1206
-     *
1207
-     * @return array
1208
-     */
1209
-    protected function _get_orderby_for_registrations_query()
1210
-    {
1211
-        $orderby_field = ! empty($this->_req_data['orderby'])
1212
-            ? sanitize_text_field($this->_req_data['orderby'])
1213
-            : '';
1214
-        switch ($orderby_field) {
1215
-            case '_REG_ID':
1216
-                $orderby_field = 'REG_ID';
1217
-                break;
1218
-            case '_Reg_status':
1219
-                $orderby_field = 'STS_ID';
1220
-                break;
1221
-            case 'ATT_fname':
1222
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1223
-                break;
1224
-            case 'ATT_lname' :
1225
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1226
-                break;
1227
-            case 'event_name':
1228
-                $orderby_field = 'Event.EVT_name';
1229
-                break;
1230
-            case 'DTT_EVT_start':
1231
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1232
-                break;
1233
-            default: //'REG_date'
1234
-                $orderby_field = 'REG_date';
1235
-        }
1236
-
1237
-        //order
1238
-        $order = ! empty($this->_req_data['order'])
1239
-            ? sanitize_text_field($this->_req_data['order'])
1240
-            : 'DESC';
1241
-
1242
-        //mutate orderby_field
1243
-        $orderby_field = array_combine(
1244
-                (array) $orderby_field,
1245
-                array_fill(0, count($orderby_field), $order)
1246
-            );
1247
-        return array('order_by' => $orderby_field);
1248
-    }
1249
-
1250
-
1251
-    /**
1252
-     * Sets up the limit for the registrations query.
1253
-     *
1254
-     * @param $per_page
1255
-     * @return array
1256
-     */
1257
-    protected function _get_limit($per_page)
1258
-    {
1259
-        $current_page = ! empty($this->_req_data['paged'])
1260
-            ? absint($this->_req_data['paged'])
1261
-            : 1;
1262
-        $per_page     = ! empty($this->_req_data['perpage'])
1263
-            ? $this->_req_data['perpage']
1264
-            : $per_page;
1265
-
1266
-        //-1 means return all results so get out if that's set.
1267
-        if ((int)$per_page === -1) {
1268
-            return array();
1269
-        }
1270
-        $per_page = absint($per_page);
1271
-        $offset   = ($current_page - 1) * $per_page;
1272
-        return array('limit' => array($offset, $per_page));
1273
-    }
1274
-
1275
-
1276
-    public function get_registration_status_array()
1277
-    {
1278
-        return self::$_reg_status;
1279
-    }
1280
-
1281
-
1282
-
1283
-
1284
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1285
-    /**
1286
-     *        generates HTML for the View Registration Details Admin page
1287
-     *
1288
-     * @access protected
1289
-     * @return void
1290
-     */
1291
-    protected function _registration_details()
1292
-    {
1293
-        $this->_template_args = array();
1294
-        $this->_set_registration_object();
1295
-        if (is_object($this->_registration)) {
1296
-            $transaction                                   = $this->_registration->transaction() ? $this->_registration->transaction()
1297
-                : EE_Transaction::new_instance();
1298
-            $this->_session                                = $transaction->session_data();
1299
-            $event_id                                      = $this->_registration->event_ID();
1300
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1301
-            $this->_template_args['reg_nmbr']['label']     = __('Registration Number', 'event_espresso');
1302
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1303
-            $this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso');
1304
-            $this->_template_args['grand_total']           = $transaction->total();
1305
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1306
-            // link back to overview
1307
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1308
-            $this->_template_args['registration']                = $this->_registration;
1309
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1310
-                'action'   => 'default',
1311
-                'event_id' => $event_id,
1312
-            ), REG_ADMIN_URL);
1313
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
1314
-                'action' => 'default',
1315
-                'EVT_ID' => $event_id,
1316
-                'page'   => 'espresso_transactions',
1317
-            ), admin_url('admin.php'));
1318
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(array(
1319
-                'page'   => 'espresso_events',
1320
-                'action' => 'edit',
1321
-                'post'   => $event_id,
1322
-            ), admin_url('admin.php'));
1323
-            //next and previous links
1324
-            $next_reg                                      = $this->_registration->next(null, array(), 'REG_ID');
1325
-            $this->_template_args['next_registration']     = $next_reg
1326
-                ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array(
1327
-                    'action'  => 'view_registration',
1328
-                    '_REG_ID' => $next_reg['REG_ID'],
1329
-                ), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
1330
-            $previous_reg                                  = $this->_registration->previous(null, array(), 'REG_ID');
1331
-            $this->_template_args['previous_registration'] = $previous_reg
1332
-                ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array(
1333
-                    'action'  => 'view_registration',
1334
-                    '_REG_ID' => $previous_reg['REG_ID'],
1335
-                ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
1336
-            // grab header
1337
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1338
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1339
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
1340
-                $this->_template_args, true);
1341
-        } else {
1342
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1343
-        }
1344
-        // the details template wrapper
1345
-        $this->display_admin_page_with_sidebar();
1346
-    }
1347
-
1348
-
1349
-    protected function _registration_details_metaboxes()
1350
-    {
1351
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1352
-        $this->_set_registration_object();
1353
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1354
-        add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'),
1355
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1356
-        add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'),
1357
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1358
-        if ($attendee instanceof EE_Attendee
1359
-            && EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox')
1360
-        ) {
1361
-            add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'),
1362
-                array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high');
1363
-        }
1364
-        add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'),
1365
-            array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high');
1366
-        if ($this->_registration->group_size() > 1) {
1367
-            add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'),
1368
-                array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high');
1369
-        }
1370
-    }
1371
-
1372
-
1373
-    /**
1374
-     * set_reg_status_buttons_metabox
1375
-     *
1376
-     * @access protected
1377
-     * @return string
1378
-     * @throws \EE_Error
1379
-     */
1380
-    public function set_reg_status_buttons_metabox()
1381
-    {
1382
-        $this->_set_registration_object();
1383
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1384
-        echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array(
1385
-            'action' => 'change_reg_status',
1386
-        ), REG_ADMIN_URL));
1387
-        echo $change_reg_status_form->get_html();
1388
-        echo $change_reg_status_form->form_close();
1389
-    }
1390
-
1391
-
1392
-    /**
1393
-     * @return EE_Form_Section_Proper
1394
-     */
1395
-    protected function _generate_reg_status_change_form()
1396
-    {
1397
-        return new EE_Form_Section_Proper(array(
1398
-            'name'            => 'reg_status_change_form',
1399
-            'html_id'         => 'reg-status-change-form',
1400
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1401
-            'subsections'     => array(
1402
-                'return'             => new EE_Hidden_Input(array(
1403
-                    'name'    => 'return',
1404
-                    'default' => 'view_registration',
1405
-                )),
1406
-                'REG_ID'             => new EE_Hidden_Input(array(
1407
-                    'name'    => 'REG_ID',
1408
-                    'default' => $this->_registration->ID(),
1409
-                )),
1410
-                'current_status'     => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status',
1411
-                        'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1412
-                        '', 'status-' . $this->_registration->status_ID(),
1413
-                        'line-height: 1em; font-size: 1.5em; font-weight: bold;')))),
1414
-                'reg_status'         => new EE_Select_Input($this->_get_reg_statuses(), array(
1415
-                    'html_label_text' => __('Change Registration Status to', 'event_espresso'),
1416
-                    'default'         => $this->_registration->status_ID(),
1417
-                )),
1418
-                'send_notifications' => new EE_Yes_No_Input(array(
1419
-                    'html_label_text' => __('Send Related Messages', 'event_espresso'),
1420
-                    'default'         => false,
1421
-                    'html_help_text'  => __('If set to "Yes", then the related messages will be sent to the registrant.',
1422
-                        'event_espresso'),
1423
-                )),
1424
-                'submit'             => new EE_Submit_Input(array(
1425
-                    'html_class'      => 'button-primary',
1426
-                    'html_label_text' => '&nbsp;',
1427
-                    'default'         => __('Update Registration Status', 'event_espresso'),
1428
-                )),
1429
-            ),
1430
-        ));
1431
-    }
1432
-
1433
-
1434
-
1435
-    /**
1436
-     * Returns an array of all the buttons for the various statuses and switch status actions
1437
-     *
1438
-     * @return array
1439
-     */
1440
-    protected function _get_reg_statuses()
1441
-    {
1442
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1443
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1444
-        // get current reg status
1445
-        $current_status = $this->_registration->status_ID();
1446
-        // is registration for free event? This will determine whether to display the pending payment option
1447
-        if ($current_status != EEM_Registration::status_id_pending_payment
1448
-            && $this->_registration->transaction()
1449
-                                   ->is_free()
1450
-        ) {
1451
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1452
-        }
1453
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1454
-    }
1455
-
1456
-
1457
-    /**
1458
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1459
-     *
1460
-     * @param bool $status REG status given for changing registrations to.
1461
-     * @param bool $notify Whether to send messages notifications or not.
1462
-     * @return array  (array with reg_id(s) updated and whether update was successful.
1463
-     */
1464
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1465
-    {
1466
-        if (isset($this->_req_data['reg_status_change_form'])) {
1467
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1468
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1469
-        } else {
1470
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1471
-        }
1472
-        $success = $this->_set_registration_status($REG_IDs, $status);
1473
-        //notify?
1474
-        if ($success
1475
-            && $notify
1476
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1477
-                'espresso_registrations_resend_registration')
1478
-        ) {
1479
-            $this->_process_resend_registration();
1480
-        }
1481
-        return $success;
1482
-    }
1483
-
1484
-
1485
-    /**
1486
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1487
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1488
-     *
1489
-     * @param array $REG_IDs
1490
-     * @param bool  $status
1491
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1492
-     *               the array of updated registrations).
1493
-     */
1494
-    protected function _set_registration_status($REG_IDs = array(), $status = false)
1495
-    {
1496
-        $success = false;
1497
-        // typecast $REG_IDs
1498
-        $REG_IDs = (array)$REG_IDs;
1499
-        if ( ! empty($REG_IDs)) {
1500
-            $success = true;
1501
-            // set default status if none is passed
1502
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1503
-            // sanitize $REG_IDs
1504
-            $REG_IDs = array_filter($REG_IDs, 'absint');
1505
-            //loop through REG_ID's and change status
1506
-            foreach ($REG_IDs as $REG_ID) {
1507
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1508
-                if ($registration instanceof EE_Registration) {
1509
-                    $registration->set_status($status);
1510
-                    $result = $registration->save();
1511
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1512
-                    $success = $result !== false ? $success : false;
1513
-                }
1514
-            }
1515
-        }
1516
-        //reset _req_data['_REG_ID'] for any potential future messages notifications
1517
-        $this->_req_data['_REG_ID'] = $REG_IDs;
1518
-        //return $success and processed registrations
1519
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1520
-    }
1521
-
1522
-
1523
-    /**
1524
-     * Common logic for setting up success message and redirecting to appropriate route
1525
-     *
1526
-     * @param  string $STS_ID status id for the registration changed to
1527
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1528
-     * @return void
1529
-     */
1530
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1531
-    {
1532
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1533
-            : array('success' => false);
1534
-        $success = isset($result['success']) && $result['success'];
1535
-        //setup success message
1536
-        if ($success) {
1537
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1538
-                $msg = sprintf(__('Registration status has been set to %s', 'event_espresso'),
1539
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1540
-            } else {
1541
-                $msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'),
1542
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1543
-            }
1544
-            EE_Error::add_success($msg);
1545
-        } else {
1546
-            EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__,
1547
-                __LINE__, __FUNCTION__);
1548
-        }
1549
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1550
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1551
-        } else {
1552
-            $route = array('action' => 'default');
1553
-        }
1554
-        //unset nonces
1555
-        foreach ($this->_req_data as $ref => $value) {
1556
-            if (strpos($ref, 'nonce') !== false) {
1557
-                unset($this->_req_data[$ref]);
1558
-                continue;
1559
-            }
1560
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1561
-            $this->_req_data[$ref] = $value;
1562
-        }
1563
-        //merge request vars so that the reloaded list table contains any existing filter query params
1564
-        $route = array_merge($this->_req_data, $route);
1565
-        $this->_redirect_after_action($success, '', '', $route, true);
1566
-    }
1567
-
1568
-
1569
-    /**
1570
-     * incoming reg status change from reg details page.
1571
-     *
1572
-     * @return void
1573
-     */
1574
-    protected function _change_reg_status()
1575
-    {
1576
-        $this->_req_data['return'] = 'view_registration';
1577
-        //set notify based on whether the send notifications toggle is set or not
1578
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1579
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1580
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1581
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1582
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1583
-            case EEM_Registration::status_id_approved :
1584
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1585
-                $this->approve_registration($notify);
1586
-                break;
1587
-            case EEM_Registration::status_id_pending_payment :
1588
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1589
-                $this->pending_registration($notify);
1590
-                break;
1591
-            case EEM_Registration::status_id_not_approved :
1592
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1593
-                $this->not_approve_registration($notify);
1594
-                break;
1595
-            case EEM_Registration::status_id_declined :
1596
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1597
-                $this->decline_registration($notify);
1598
-                break;
1599
-            case EEM_Registration::status_id_cancelled :
1600
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1601
-                $this->cancel_registration($notify);
1602
-                break;
1603
-            case EEM_Registration::status_id_wait_list :
1604
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1605
-                $this->waitlist_registration($notify);
1606
-                break;
1607
-            case EEM_Registration::status_id_incomplete :
1608
-            default :
1609
-                $result['success'] = false;
1610
-                unset($this->_req_data['return']);
1611
-                $this->_reg_status_change_return('', false);
1612
-                break;
1613
-        }
1614
-    }
1615
-
1616
-
1617
-    /**
1618
-     * approve_registration
1619
-     *
1620
-     * @access protected
1621
-     * @param bool $notify whether or not to notify the registrant about their approval.
1622
-     * @return void
1623
-     */
1624
-    protected function approve_registration($notify = false)
1625
-    {
1626
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1627
-    }
1628
-
1629
-
1630
-    /**
1631
-     *        decline_registration
1632
-     *
1633
-     * @access protected
1634
-     * @param bool $notify whether or not to notify the registrant about their status change.
1635
-     * @return void
1636
-     */
1637
-    protected function decline_registration($notify = false)
1638
-    {
1639
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1640
-    }
1641
-
1642
-
1643
-    /**
1644
-     *        cancel_registration
1645
-     *
1646
-     * @access protected
1647
-     * @param bool $notify whether or not to notify the registrant about their status change.
1648
-     * @return void
1649
-     */
1650
-    protected function cancel_registration($notify = false)
1651
-    {
1652
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1653
-    }
1654
-
1655
-
1656
-    /**
1657
-     *        not_approve_registration
1658
-     *
1659
-     * @access protected
1660
-     * @param bool $notify whether or not to notify the registrant about their status change.
1661
-     * @return void
1662
-     */
1663
-    protected function not_approve_registration($notify = false)
1664
-    {
1665
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1666
-    }
1667
-
1668
-
1669
-    /**
1670
-     *        decline_registration
1671
-     *
1672
-     * @access protected
1673
-     * @param bool $notify whether or not to notify the registrant about their status change.
1674
-     * @return void
1675
-     */
1676
-    protected function pending_registration($notify = false)
1677
-    {
1678
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     * waitlist_registration
1684
-     *
1685
-     * @access protected
1686
-     * @param bool $notify whether or not to notify the registrant about their status change.
1687
-     * @return void
1688
-     */
1689
-    protected function waitlist_registration($notify = false)
1690
-    {
1691
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1692
-    }
1693
-
1694
-
1695
-    /**
1696
-     *        generates HTML for the Registration main meta box
1697
-     *
1698
-     * @access public
1699
-     * @return void
1700
-     */
1701
-    public function _reg_details_meta_box()
1702
-    {
1703
-        EEH_Autoloader::register_line_item_display_autoloaders();
1704
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1705
-        EE_Registry::instance()->load_helper('Line_Item');
1706
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1707
-            : EE_Transaction::new_instance();
1708
-        $this->_session = $transaction->session_data();
1709
-        $filters        = new EE_Line_Item_Filter_Collection();
1710
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1711
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1712
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1713
-            $transaction->total_line_item());
1714
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
1715
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1716
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1717
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree,
1718
-            array('EE_Registration' => $this->_registration));
1719
-        $attendee                                = $this->_registration->attendee();
1720
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
1721
-            'espresso_transactions_view_transaction')
1722
-        ) {
1723
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1724
-                'action' => 'view_transaction',
1725
-                'TXN_ID' => $transaction->ID(),
1726
-            ), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right',
1727
-                'dashicons dashicons-cart');
1728
-        } else {
1729
-            $this->_template_args['view_transaction_button'] = '';
1730
-        }
1731
-        if ($attendee instanceof EE_Attendee
1732
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1733
-                'espresso_registrations_resend_registration')
1734
-        ) {
1735
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1736
-                'action'      => 'resend_registration',
1737
-                '_REG_ID'     => $this->_registration->ID(),
1738
-                'redirect_to' => 'view_registration',
1739
-            ), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right',
1740
-                'dashicons dashicons-email-alt');
1741
-        } else {
1742
-            $this->_template_args['resend_registration_button'] = '';
1743
-        }
1744
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1745
-        $payment                               = $transaction->get_first_related('Payment');
1746
-        $payment                               = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
1747
-        $payment_method                        = $payment->get_first_related('Payment_Method');
1748
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance()
1749
-            : $payment_method;
1750
-        $reg_details                           = array(
1751
-            'payment_method'       => $payment_method->name(),
1752
-            'response_msg'         => $payment->gateway_response(),
1753
-            'registration_id'      => $this->_registration->get('REG_code'),
1754
-            'registration_session' => $this->_registration->session_ID(),
1755
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1756
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1757
-        );
1758
-        if (isset($reg_details['registration_id'])) {
1759
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1760
-            $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
1761
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
1762
-        }
1763
-        if (isset($reg_details['payment_method'])) {
1764
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
1765
-            $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method',
1766
-                'event_espresso');
1767
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
1768
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
1769
-            $this->_template_args['reg_details']['response_msg']['label']   = __('Payment method response',
1770
-                'event_espresso');
1771
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
1772
-        }
1773
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
1774
-        $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session',
1775
-            'event_espresso');
1776
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
1777
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
1778
-        $this->_template_args['reg_details']['ip_address']['label']           = __('Registration placed from IP',
1779
-            'event_espresso');
1780
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
1781
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
1782
-        $this->_template_args['reg_details']['user_agent']['label']           = __('Registrant User Agent',
1783
-            'event_espresso');
1784
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
1785
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(array(
1786
-            'action'   => 'default',
1787
-            'event_id' => $this->_registration->event_ID(),
1788
-        ), REG_ADMIN_URL);
1789
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
1790
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
1791
-        $template_path                                                        = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1792
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1793
-    }
1794
-
1795
-
1796
-    /**
1797
-     * generates HTML for the Registration Questions meta box.
1798
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
1799
-     * otherwise uses new forms system
1800
-     *
1801
-     * @access public
1802
-     * @return void
1803
-     */
1804
-    public function _reg_questions_meta_box()
1805
-    {
1806
-        //allow someone to override this method entirely
1807
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
1808
-            $this->_registration)) {
1809
-            $form                                              = $this->_get_reg_custom_questions_form($this->_registration->ID());
1810
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0 ? $form->get_html_and_js() : '';
1811
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
1812
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
1813
-            $template_path                                     = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1814
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
1815
-        }
1816
-    }
1817
-
1818
-
1819
-    /**
1820
-     * form_before_question_group
1821
-     *
1822
-     * @deprecated    as of 4.8.32.rc.000
1823
-     * @access        public
1824
-     * @param        string $output
1825
-     * @return        string
1826
-     */
1827
-    public function form_before_question_group($output)
1828
-    {
1829
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1830
-            __('This method would have been protected but was used on a filter callback'
1831
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1832
-            '4.8.32.rc.000');
1833
-        return '
1050
+		if ( ! empty($registration_status)) {
1051
+			$where['STS_ID'] = $registration_status;
1052
+		} else {
1053
+			//make sure we exclude incomplete registrations, but only if not trashed.
1054
+			if ($view === 'trash') {
1055
+				$where['REG_deleted'] = true;
1056
+			} else if ($view === 'incomplete') {
1057
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1058
+			} else {
1059
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1060
+			}
1061
+		}
1062
+		return $where;
1063
+	}
1064
+
1065
+
1066
+	/**
1067
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1068
+	 *
1069
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1070
+	 * @return array
1071
+	 */
1072
+	protected function _add_date_to_where_conditions(array $request)
1073
+	{
1074
+		$where = array();
1075
+		$view  = EEH_Array::is_set( $request, 'status', '' );
1076
+		$month_range             = ! empty($request['month_range'])
1077
+			? sanitize_text_field($request['month_range'])
1078
+			: '';
1079
+		$retrieve_for_today      = $view === 'today';
1080
+		$retrieve_for_this_month = $view === 'month';
1081
+
1082
+		if ($retrieve_for_today) {
1083
+			$now               = date('Y-m-d', current_time('timestamp'));
1084
+			$where['REG_date'] = array(
1085
+				'BETWEEN',
1086
+				array(
1087
+					EEM_Registration::instance()->convert_datetime_for_query(
1088
+						'REG_date',
1089
+						$now . ' 00:00:00',
1090
+						'Y-m-d H:i:s'
1091
+					),
1092
+					EEM_Registration::instance()->convert_datetime_for_query(
1093
+						'REG_date',
1094
+						$now . ' 23:59:59',
1095
+						'Y-m-d H:i:s'
1096
+					),
1097
+				),
1098
+			);
1099
+		} elseif ($retrieve_for_this_month) {
1100
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1101
+			$days_this_month        = date('t', current_time('timestamp'));
1102
+			$where['REG_date']      = array(
1103
+				'BETWEEN',
1104
+				array(
1105
+					EEM_Registration::instance()->convert_datetime_for_query(
1106
+						'REG_date',
1107
+						$current_year_and_month . '-01 00:00:00',
1108
+						'Y-m-d H:i:s'
1109
+					),
1110
+					EEM_Registration::instance()->convert_datetime_for_query(
1111
+						'REG_date',
1112
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1113
+						'Y-m-d H:i:s'
1114
+					),
1115
+				),
1116
+			);
1117
+		} elseif ($month_range) {
1118
+			$pieces          = explode(' ', $month_range, 3);
1119
+			$month_requested = ! empty($pieces[0])
1120
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1121
+				: '';
1122
+			$year_requested  = ! empty($pieces[1])
1123
+				? $pieces[1]
1124
+				: '';
1125
+			//if there is not a month or year then we can't go further
1126
+			if ($month_requested && $year_requested) {
1127
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1128
+				$where['REG_date'] = array(
1129
+					'BETWEEN',
1130
+					array(
1131
+						EEM_Registration::instance()->convert_datetime_for_query(
1132
+							'REG_date',
1133
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1134
+							'Y-m-d H:i:s'
1135
+						),
1136
+						EEM_Registration::instance()->convert_datetime_for_query(
1137
+							'REG_date',
1138
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1139
+							'Y-m-d H:i:s'
1140
+						),
1141
+					),
1142
+				);
1143
+			}
1144
+		}
1145
+		return $where;
1146
+	}
1147
+
1148
+
1149
+	/**
1150
+	 * Adds any provided search restraints to the where conditions for the registrations query
1151
+	 *
1152
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1153
+	 * @return array
1154
+	 */
1155
+	protected function _add_search_to_where_conditions(array $request)
1156
+	{
1157
+		$where = array();
1158
+		if ( ! empty($request['s'])) {
1159
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1160
+			$where['OR'] = array(
1161
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1162
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1163
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1164
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1165
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1166
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1167
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1168
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1169
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1170
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1171
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1172
+				'REG_final_price'                         => array('LIKE', $search_string),
1173
+				'REG_code'                                => array('LIKE', $search_string),
1174
+				'REG_count'                               => array('LIKE', $search_string),
1175
+				'REG_group_size'                          => array('LIKE', $search_string),
1176
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1177
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1178
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1179
+			);
1180
+		}
1181
+		return $where;
1182
+	}
1183
+
1184
+
1185
+	/**
1186
+	 * Sets up the where conditions for the registrations query.
1187
+	 *
1188
+	 * @param array $request
1189
+	 * @return array
1190
+	 */
1191
+	protected function _get_where_conditions_for_registrations_query($request)
1192
+	{
1193
+		return array_merge(
1194
+			$this->_add_event_id_to_where_conditions($request),
1195
+			$this->_add_category_id_to_where_conditions($request),
1196
+			$this->_add_datetime_id_to_where_conditions($request),
1197
+			$this->_add_registration_status_to_where_conditions($request),
1198
+			$this->_add_date_to_where_conditions($request),
1199
+			$this->_add_search_to_where_conditions($request)
1200
+		);
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * Sets up the orderby for the registrations query.
1206
+	 *
1207
+	 * @return array
1208
+	 */
1209
+	protected function _get_orderby_for_registrations_query()
1210
+	{
1211
+		$orderby_field = ! empty($this->_req_data['orderby'])
1212
+			? sanitize_text_field($this->_req_data['orderby'])
1213
+			: '';
1214
+		switch ($orderby_field) {
1215
+			case '_REG_ID':
1216
+				$orderby_field = 'REG_ID';
1217
+				break;
1218
+			case '_Reg_status':
1219
+				$orderby_field = 'STS_ID';
1220
+				break;
1221
+			case 'ATT_fname':
1222
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1223
+				break;
1224
+			case 'ATT_lname' :
1225
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1226
+				break;
1227
+			case 'event_name':
1228
+				$orderby_field = 'Event.EVT_name';
1229
+				break;
1230
+			case 'DTT_EVT_start':
1231
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1232
+				break;
1233
+			default: //'REG_date'
1234
+				$orderby_field = 'REG_date';
1235
+		}
1236
+
1237
+		//order
1238
+		$order = ! empty($this->_req_data['order'])
1239
+			? sanitize_text_field($this->_req_data['order'])
1240
+			: 'DESC';
1241
+
1242
+		//mutate orderby_field
1243
+		$orderby_field = array_combine(
1244
+				(array) $orderby_field,
1245
+				array_fill(0, count($orderby_field), $order)
1246
+			);
1247
+		return array('order_by' => $orderby_field);
1248
+	}
1249
+
1250
+
1251
+	/**
1252
+	 * Sets up the limit for the registrations query.
1253
+	 *
1254
+	 * @param $per_page
1255
+	 * @return array
1256
+	 */
1257
+	protected function _get_limit($per_page)
1258
+	{
1259
+		$current_page = ! empty($this->_req_data['paged'])
1260
+			? absint($this->_req_data['paged'])
1261
+			: 1;
1262
+		$per_page     = ! empty($this->_req_data['perpage'])
1263
+			? $this->_req_data['perpage']
1264
+			: $per_page;
1265
+
1266
+		//-1 means return all results so get out if that's set.
1267
+		if ((int)$per_page === -1) {
1268
+			return array();
1269
+		}
1270
+		$per_page = absint($per_page);
1271
+		$offset   = ($current_page - 1) * $per_page;
1272
+		return array('limit' => array($offset, $per_page));
1273
+	}
1274
+
1275
+
1276
+	public function get_registration_status_array()
1277
+	{
1278
+		return self::$_reg_status;
1279
+	}
1280
+
1281
+
1282
+
1283
+
1284
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1285
+	/**
1286
+	 *        generates HTML for the View Registration Details Admin page
1287
+	 *
1288
+	 * @access protected
1289
+	 * @return void
1290
+	 */
1291
+	protected function _registration_details()
1292
+	{
1293
+		$this->_template_args = array();
1294
+		$this->_set_registration_object();
1295
+		if (is_object($this->_registration)) {
1296
+			$transaction                                   = $this->_registration->transaction() ? $this->_registration->transaction()
1297
+				: EE_Transaction::new_instance();
1298
+			$this->_session                                = $transaction->session_data();
1299
+			$event_id                                      = $this->_registration->event_ID();
1300
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1301
+			$this->_template_args['reg_nmbr']['label']     = __('Registration Number', 'event_espresso');
1302
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1303
+			$this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso');
1304
+			$this->_template_args['grand_total']           = $transaction->total();
1305
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1306
+			// link back to overview
1307
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1308
+			$this->_template_args['registration']                = $this->_registration;
1309
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1310
+				'action'   => 'default',
1311
+				'event_id' => $event_id,
1312
+			), REG_ADMIN_URL);
1313
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
1314
+				'action' => 'default',
1315
+				'EVT_ID' => $event_id,
1316
+				'page'   => 'espresso_transactions',
1317
+			), admin_url('admin.php'));
1318
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(array(
1319
+				'page'   => 'espresso_events',
1320
+				'action' => 'edit',
1321
+				'post'   => $event_id,
1322
+			), admin_url('admin.php'));
1323
+			//next and previous links
1324
+			$next_reg                                      = $this->_registration->next(null, array(), 'REG_ID');
1325
+			$this->_template_args['next_registration']     = $next_reg
1326
+				? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array(
1327
+					'action'  => 'view_registration',
1328
+					'_REG_ID' => $next_reg['REG_ID'],
1329
+				), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
1330
+			$previous_reg                                  = $this->_registration->previous(null, array(), 'REG_ID');
1331
+			$this->_template_args['previous_registration'] = $previous_reg
1332
+				? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array(
1333
+					'action'  => 'view_registration',
1334
+					'_REG_ID' => $previous_reg['REG_ID'],
1335
+				), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
1336
+			// grab header
1337
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1338
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1339
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
1340
+				$this->_template_args, true);
1341
+		} else {
1342
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1343
+		}
1344
+		// the details template wrapper
1345
+		$this->display_admin_page_with_sidebar();
1346
+	}
1347
+
1348
+
1349
+	protected function _registration_details_metaboxes()
1350
+	{
1351
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1352
+		$this->_set_registration_object();
1353
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1354
+		add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'),
1355
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1356
+		add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'),
1357
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1358
+		if ($attendee instanceof EE_Attendee
1359
+			&& EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox')
1360
+		) {
1361
+			add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'),
1362
+				array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high');
1363
+		}
1364
+		add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'),
1365
+			array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high');
1366
+		if ($this->_registration->group_size() > 1) {
1367
+			add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'),
1368
+				array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high');
1369
+		}
1370
+	}
1371
+
1372
+
1373
+	/**
1374
+	 * set_reg_status_buttons_metabox
1375
+	 *
1376
+	 * @access protected
1377
+	 * @return string
1378
+	 * @throws \EE_Error
1379
+	 */
1380
+	public function set_reg_status_buttons_metabox()
1381
+	{
1382
+		$this->_set_registration_object();
1383
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1384
+		echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array(
1385
+			'action' => 'change_reg_status',
1386
+		), REG_ADMIN_URL));
1387
+		echo $change_reg_status_form->get_html();
1388
+		echo $change_reg_status_form->form_close();
1389
+	}
1390
+
1391
+
1392
+	/**
1393
+	 * @return EE_Form_Section_Proper
1394
+	 */
1395
+	protected function _generate_reg_status_change_form()
1396
+	{
1397
+		return new EE_Form_Section_Proper(array(
1398
+			'name'            => 'reg_status_change_form',
1399
+			'html_id'         => 'reg-status-change-form',
1400
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1401
+			'subsections'     => array(
1402
+				'return'             => new EE_Hidden_Input(array(
1403
+					'name'    => 'return',
1404
+					'default' => 'view_registration',
1405
+				)),
1406
+				'REG_ID'             => new EE_Hidden_Input(array(
1407
+					'name'    => 'REG_ID',
1408
+					'default' => $this->_registration->ID(),
1409
+				)),
1410
+				'current_status'     => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status',
1411
+						'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1412
+						'', 'status-' . $this->_registration->status_ID(),
1413
+						'line-height: 1em; font-size: 1.5em; font-weight: bold;')))),
1414
+				'reg_status'         => new EE_Select_Input($this->_get_reg_statuses(), array(
1415
+					'html_label_text' => __('Change Registration Status to', 'event_espresso'),
1416
+					'default'         => $this->_registration->status_ID(),
1417
+				)),
1418
+				'send_notifications' => new EE_Yes_No_Input(array(
1419
+					'html_label_text' => __('Send Related Messages', 'event_espresso'),
1420
+					'default'         => false,
1421
+					'html_help_text'  => __('If set to "Yes", then the related messages will be sent to the registrant.',
1422
+						'event_espresso'),
1423
+				)),
1424
+				'submit'             => new EE_Submit_Input(array(
1425
+					'html_class'      => 'button-primary',
1426
+					'html_label_text' => '&nbsp;',
1427
+					'default'         => __('Update Registration Status', 'event_espresso'),
1428
+				)),
1429
+			),
1430
+		));
1431
+	}
1432
+
1433
+
1434
+
1435
+	/**
1436
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1437
+	 *
1438
+	 * @return array
1439
+	 */
1440
+	protected function _get_reg_statuses()
1441
+	{
1442
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1443
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1444
+		// get current reg status
1445
+		$current_status = $this->_registration->status_ID();
1446
+		// is registration for free event? This will determine whether to display the pending payment option
1447
+		if ($current_status != EEM_Registration::status_id_pending_payment
1448
+			&& $this->_registration->transaction()
1449
+								   ->is_free()
1450
+		) {
1451
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1452
+		}
1453
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1454
+	}
1455
+
1456
+
1457
+	/**
1458
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1459
+	 *
1460
+	 * @param bool $status REG status given for changing registrations to.
1461
+	 * @param bool $notify Whether to send messages notifications or not.
1462
+	 * @return array  (array with reg_id(s) updated and whether update was successful.
1463
+	 */
1464
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1465
+	{
1466
+		if (isset($this->_req_data['reg_status_change_form'])) {
1467
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1468
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1469
+		} else {
1470
+			$REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1471
+		}
1472
+		$success = $this->_set_registration_status($REG_IDs, $status);
1473
+		//notify?
1474
+		if ($success
1475
+			&& $notify
1476
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1477
+				'espresso_registrations_resend_registration')
1478
+		) {
1479
+			$this->_process_resend_registration();
1480
+		}
1481
+		return $success;
1482
+	}
1483
+
1484
+
1485
+	/**
1486
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1487
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1488
+	 *
1489
+	 * @param array $REG_IDs
1490
+	 * @param bool  $status
1491
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1492
+	 *               the array of updated registrations).
1493
+	 */
1494
+	protected function _set_registration_status($REG_IDs = array(), $status = false)
1495
+	{
1496
+		$success = false;
1497
+		// typecast $REG_IDs
1498
+		$REG_IDs = (array)$REG_IDs;
1499
+		if ( ! empty($REG_IDs)) {
1500
+			$success = true;
1501
+			// set default status if none is passed
1502
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1503
+			// sanitize $REG_IDs
1504
+			$REG_IDs = array_filter($REG_IDs, 'absint');
1505
+			//loop through REG_ID's and change status
1506
+			foreach ($REG_IDs as $REG_ID) {
1507
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1508
+				if ($registration instanceof EE_Registration) {
1509
+					$registration->set_status($status);
1510
+					$result = $registration->save();
1511
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1512
+					$success = $result !== false ? $success : false;
1513
+				}
1514
+			}
1515
+		}
1516
+		//reset _req_data['_REG_ID'] for any potential future messages notifications
1517
+		$this->_req_data['_REG_ID'] = $REG_IDs;
1518
+		//return $success and processed registrations
1519
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1520
+	}
1521
+
1522
+
1523
+	/**
1524
+	 * Common logic for setting up success message and redirecting to appropriate route
1525
+	 *
1526
+	 * @param  string $STS_ID status id for the registration changed to
1527
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1528
+	 * @return void
1529
+	 */
1530
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1531
+	{
1532
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1533
+			: array('success' => false);
1534
+		$success = isset($result['success']) && $result['success'];
1535
+		//setup success message
1536
+		if ($success) {
1537
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1538
+				$msg = sprintf(__('Registration status has been set to %s', 'event_espresso'),
1539
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1540
+			} else {
1541
+				$msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'),
1542
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1543
+			}
1544
+			EE_Error::add_success($msg);
1545
+		} else {
1546
+			EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__,
1547
+				__LINE__, __FUNCTION__);
1548
+		}
1549
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1550
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1551
+		} else {
1552
+			$route = array('action' => 'default');
1553
+		}
1554
+		//unset nonces
1555
+		foreach ($this->_req_data as $ref => $value) {
1556
+			if (strpos($ref, 'nonce') !== false) {
1557
+				unset($this->_req_data[$ref]);
1558
+				continue;
1559
+			}
1560
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1561
+			$this->_req_data[$ref] = $value;
1562
+		}
1563
+		//merge request vars so that the reloaded list table contains any existing filter query params
1564
+		$route = array_merge($this->_req_data, $route);
1565
+		$this->_redirect_after_action($success, '', '', $route, true);
1566
+	}
1567
+
1568
+
1569
+	/**
1570
+	 * incoming reg status change from reg details page.
1571
+	 *
1572
+	 * @return void
1573
+	 */
1574
+	protected function _change_reg_status()
1575
+	{
1576
+		$this->_req_data['return'] = 'view_registration';
1577
+		//set notify based on whether the send notifications toggle is set or not
1578
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1579
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1580
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1581
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1582
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1583
+			case EEM_Registration::status_id_approved :
1584
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1585
+				$this->approve_registration($notify);
1586
+				break;
1587
+			case EEM_Registration::status_id_pending_payment :
1588
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1589
+				$this->pending_registration($notify);
1590
+				break;
1591
+			case EEM_Registration::status_id_not_approved :
1592
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1593
+				$this->not_approve_registration($notify);
1594
+				break;
1595
+			case EEM_Registration::status_id_declined :
1596
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1597
+				$this->decline_registration($notify);
1598
+				break;
1599
+			case EEM_Registration::status_id_cancelled :
1600
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1601
+				$this->cancel_registration($notify);
1602
+				break;
1603
+			case EEM_Registration::status_id_wait_list :
1604
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1605
+				$this->waitlist_registration($notify);
1606
+				break;
1607
+			case EEM_Registration::status_id_incomplete :
1608
+			default :
1609
+				$result['success'] = false;
1610
+				unset($this->_req_data['return']);
1611
+				$this->_reg_status_change_return('', false);
1612
+				break;
1613
+		}
1614
+	}
1615
+
1616
+
1617
+	/**
1618
+	 * approve_registration
1619
+	 *
1620
+	 * @access protected
1621
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1622
+	 * @return void
1623
+	 */
1624
+	protected function approve_registration($notify = false)
1625
+	{
1626
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1627
+	}
1628
+
1629
+
1630
+	/**
1631
+	 *        decline_registration
1632
+	 *
1633
+	 * @access protected
1634
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1635
+	 * @return void
1636
+	 */
1637
+	protected function decline_registration($notify = false)
1638
+	{
1639
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1640
+	}
1641
+
1642
+
1643
+	/**
1644
+	 *        cancel_registration
1645
+	 *
1646
+	 * @access protected
1647
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1648
+	 * @return void
1649
+	 */
1650
+	protected function cancel_registration($notify = false)
1651
+	{
1652
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1653
+	}
1654
+
1655
+
1656
+	/**
1657
+	 *        not_approve_registration
1658
+	 *
1659
+	 * @access protected
1660
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1661
+	 * @return void
1662
+	 */
1663
+	protected function not_approve_registration($notify = false)
1664
+	{
1665
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1666
+	}
1667
+
1668
+
1669
+	/**
1670
+	 *        decline_registration
1671
+	 *
1672
+	 * @access protected
1673
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1674
+	 * @return void
1675
+	 */
1676
+	protected function pending_registration($notify = false)
1677
+	{
1678
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 * waitlist_registration
1684
+	 *
1685
+	 * @access protected
1686
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1687
+	 * @return void
1688
+	 */
1689
+	protected function waitlist_registration($notify = false)
1690
+	{
1691
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1692
+	}
1693
+
1694
+
1695
+	/**
1696
+	 *        generates HTML for the Registration main meta box
1697
+	 *
1698
+	 * @access public
1699
+	 * @return void
1700
+	 */
1701
+	public function _reg_details_meta_box()
1702
+	{
1703
+		EEH_Autoloader::register_line_item_display_autoloaders();
1704
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1705
+		EE_Registry::instance()->load_helper('Line_Item');
1706
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1707
+			: EE_Transaction::new_instance();
1708
+		$this->_session = $transaction->session_data();
1709
+		$filters        = new EE_Line_Item_Filter_Collection();
1710
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1711
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1712
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1713
+			$transaction->total_line_item());
1714
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
1715
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1716
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1717
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree,
1718
+			array('EE_Registration' => $this->_registration));
1719
+		$attendee                                = $this->_registration->attendee();
1720
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
1721
+			'espresso_transactions_view_transaction')
1722
+		) {
1723
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1724
+				'action' => 'view_transaction',
1725
+				'TXN_ID' => $transaction->ID(),
1726
+			), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right',
1727
+				'dashicons dashicons-cart');
1728
+		} else {
1729
+			$this->_template_args['view_transaction_button'] = '';
1730
+		}
1731
+		if ($attendee instanceof EE_Attendee
1732
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1733
+				'espresso_registrations_resend_registration')
1734
+		) {
1735
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1736
+				'action'      => 'resend_registration',
1737
+				'_REG_ID'     => $this->_registration->ID(),
1738
+				'redirect_to' => 'view_registration',
1739
+			), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right',
1740
+				'dashicons dashicons-email-alt');
1741
+		} else {
1742
+			$this->_template_args['resend_registration_button'] = '';
1743
+		}
1744
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1745
+		$payment                               = $transaction->get_first_related('Payment');
1746
+		$payment                               = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
1747
+		$payment_method                        = $payment->get_first_related('Payment_Method');
1748
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance()
1749
+			: $payment_method;
1750
+		$reg_details                           = array(
1751
+			'payment_method'       => $payment_method->name(),
1752
+			'response_msg'         => $payment->gateway_response(),
1753
+			'registration_id'      => $this->_registration->get('REG_code'),
1754
+			'registration_session' => $this->_registration->session_ID(),
1755
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1756
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1757
+		);
1758
+		if (isset($reg_details['registration_id'])) {
1759
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1760
+			$this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
1761
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
1762
+		}
1763
+		if (isset($reg_details['payment_method'])) {
1764
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
1765
+			$this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method',
1766
+				'event_espresso');
1767
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
1768
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
1769
+			$this->_template_args['reg_details']['response_msg']['label']   = __('Payment method response',
1770
+				'event_espresso');
1771
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
1772
+		}
1773
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
1774
+		$this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session',
1775
+			'event_espresso');
1776
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
1777
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
1778
+		$this->_template_args['reg_details']['ip_address']['label']           = __('Registration placed from IP',
1779
+			'event_espresso');
1780
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
1781
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
1782
+		$this->_template_args['reg_details']['user_agent']['label']           = __('Registrant User Agent',
1783
+			'event_espresso');
1784
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
1785
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(array(
1786
+			'action'   => 'default',
1787
+			'event_id' => $this->_registration->event_ID(),
1788
+		), REG_ADMIN_URL);
1789
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
1790
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
1791
+		$template_path                                                        = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1792
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1793
+	}
1794
+
1795
+
1796
+	/**
1797
+	 * generates HTML for the Registration Questions meta box.
1798
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
1799
+	 * otherwise uses new forms system
1800
+	 *
1801
+	 * @access public
1802
+	 * @return void
1803
+	 */
1804
+	public function _reg_questions_meta_box()
1805
+	{
1806
+		//allow someone to override this method entirely
1807
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
1808
+			$this->_registration)) {
1809
+			$form                                              = $this->_get_reg_custom_questions_form($this->_registration->ID());
1810
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0 ? $form->get_html_and_js() : '';
1811
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
1812
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
1813
+			$template_path                                     = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1814
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
1815
+		}
1816
+	}
1817
+
1818
+
1819
+	/**
1820
+	 * form_before_question_group
1821
+	 *
1822
+	 * @deprecated    as of 4.8.32.rc.000
1823
+	 * @access        public
1824
+	 * @param        string $output
1825
+	 * @return        string
1826
+	 */
1827
+	public function form_before_question_group($output)
1828
+	{
1829
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1830
+			__('This method would have been protected but was used on a filter callback'
1831
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1832
+			'4.8.32.rc.000');
1833
+		return '
1834 1834
 	<table class="form-table ee-width-100">
1835 1835
 		<tbody>
1836 1836
 			';
1837
-    }
1838
-
1839
-
1840
-    /**
1841
-     * form_after_question_group
1842
-     *
1843
-     * @deprecated    as of 4.8.32.rc.000
1844
-     * @access        public
1845
-     * @param        string $output
1846
-     * @return        string
1847
-     */
1848
-    public function form_after_question_group($output)
1849
-    {
1850
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1851
-            __('This method would have been protected but was used on a filter callback'
1852
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1853
-            '4.8.32.rc.000');
1854
-        return '
1837
+	}
1838
+
1839
+
1840
+	/**
1841
+	 * form_after_question_group
1842
+	 *
1843
+	 * @deprecated    as of 4.8.32.rc.000
1844
+	 * @access        public
1845
+	 * @param        string $output
1846
+	 * @return        string
1847
+	 */
1848
+	public function form_after_question_group($output)
1849
+	{
1850
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1851
+			__('This method would have been protected but was used on a filter callback'
1852
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1853
+			'4.8.32.rc.000');
1854
+		return '
1855 1855
 			<tr class="hide-if-no-js">
1856 1856
 				<th> </th>
1857 1857
 				<td class="reg-admin-edit-attendee-question-td">
1858 1858
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
1859
-               . esc_attr__('click to edit question', 'event_espresso')
1860
-               . '">
1859
+			   . esc_attr__('click to edit question', 'event_espresso')
1860
+			   . '">
1861 1861
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
1862
-               . __('edit the above question group', 'event_espresso')
1863
-               . '</span>
1862
+			   . __('edit the above question group', 'event_espresso')
1863
+			   . '</span>
1864 1864
 						<div class="dashicons dashicons-edit"></div>
1865 1865
 					</a>
1866 1866
 				</td>
@@ -1868,490 +1868,490 @@  discard block
 block discarded – undo
1868 1868
 		</tbody>
1869 1869
 	</table>
1870 1870
 ';
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     * form_form_field_label_wrap
1876
-     *
1877
-     * @deprecated    as of 4.8.32.rc.000
1878
-     * @access        public
1879
-     * @param        string $label
1880
-     * @return        string
1881
-     */
1882
-    public function form_form_field_label_wrap($label)
1883
-    {
1884
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1885
-            __('This method would have been protected but was used on a filter callback'
1886
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1887
-            '4.8.32.rc.000');
1888
-        return '
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 * form_form_field_label_wrap
1876
+	 *
1877
+	 * @deprecated    as of 4.8.32.rc.000
1878
+	 * @access        public
1879
+	 * @param        string $label
1880
+	 * @return        string
1881
+	 */
1882
+	public function form_form_field_label_wrap($label)
1883
+	{
1884
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1885
+			__('This method would have been protected but was used on a filter callback'
1886
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1887
+			'4.8.32.rc.000');
1888
+		return '
1889 1889
 			<tr>
1890 1890
 				<th>
1891 1891
 					' . $label . '
1892 1892
 				</th>';
1893
-    }
1894
-
1895
-
1896
-    /**
1897
-     * form_form_field_input__wrap
1898
-     *
1899
-     * @deprecated    as of 4.8.32.rc.000
1900
-     * @access        public
1901
-     * @param        string $input
1902
-     * @return        string
1903
-     */
1904
-    public function form_form_field_input__wrap($input)
1905
-    {
1906
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1907
-            __('This method would have been protected but was used on a filter callback'
1908
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1909
-            '4.8.32.rc.000');
1910
-        return '
1893
+	}
1894
+
1895
+
1896
+	/**
1897
+	 * form_form_field_input__wrap
1898
+	 *
1899
+	 * @deprecated    as of 4.8.32.rc.000
1900
+	 * @access        public
1901
+	 * @param        string $input
1902
+	 * @return        string
1903
+	 */
1904
+	public function form_form_field_input__wrap($input)
1905
+	{
1906
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1907
+			__('This method would have been protected but was used on a filter callback'
1908
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1909
+			'4.8.32.rc.000');
1910
+		return '
1911 1911
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
1912 1912
 					' . $input . '
1913 1913
 				</td>
1914 1914
 			</tr>';
1915
-    }
1916
-
1917
-
1918
-    /**
1919
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
1920
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
1921
-     * to display the page
1922
-     *
1923
-     * @access protected
1924
-     * @return void
1925
-     */
1926
-    protected function _update_attendee_registration_form()
1927
-    {
1928
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
1929
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1930
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
1931
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
1932
-            if ($success) {
1933
-                $what  = __('Registration Form', 'event_espresso');
1934
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
1935
-                    : array('action' => 'default');
1936
-                $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
1937
-            }
1938
-        }
1939
-    }
1940
-
1941
-
1942
-    /**
1943
-     * Gets the form for saving registrations custom questions (if done
1944
-     * previously retrieves the cached form object, which may have validation errors in it)
1945
-     *
1946
-     * @param int $REG_ID
1947
-     * @return EE_Registration_Custom_Questions_Form
1948
-     */
1949
-    protected function _get_reg_custom_questions_form($REG_ID)
1950
-    {
1951
-        if ( ! $this->_reg_custom_questions_form) {
1952
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
1953
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
1954
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
1955
-            );
1956
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
1957
-        }
1958
-        return $this->_reg_custom_questions_form;
1959
-    }
1960
-
1961
-
1962
-    /**
1963
-     * Saves
1964
-     *
1965
-     * @access private
1966
-     * @param bool $REG_ID
1967
-     * @return bool
1968
-     */
1969
-    private function _save_reg_custom_questions_form($REG_ID = false)
1970
-    {
1971
-        if ( ! $REG_ID) {
1972
-            EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__,
1973
-                __FUNCTION__, __LINE__);
1974
-        }
1975
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
1976
-        $form->receive_form_submission($this->_req_data);
1977
-        $success = false;
1978
-        if ($form->is_valid()) {
1979
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
1980
-                foreach ($question_group_form->inputs() as $question_id => $input) {
1981
-                    $where_conditions    = array(
1982
-                        'QST_ID' => $question_id,
1983
-                        'REG_ID' => $REG_ID,
1984
-                    );
1985
-                    $possibly_new_values = array(
1986
-                        'ANS_value' => $input->normalized_value(),
1987
-                    );
1988
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
1989
-                    if ($answer instanceof EE_Answer) {
1990
-                        $success = $answer->save($possibly_new_values);
1991
-                    } else {
1992
-                        //insert it then
1993
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
1994
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
1995
-                        $success     = $answer->save();
1996
-                    }
1997
-                }
1998
-            }
1999
-        } else {
2000
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2001
-        }
2002
-        return $success;
2003
-    }
2004
-
2005
-
2006
-    /**
2007
-     *        generates HTML for the Registration main meta box
2008
-     *
2009
-     * @access public
2010
-     * @return void
2011
-     */
2012
-    public function _reg_attendees_meta_box()
2013
-    {
2014
-        $REG = EEM_Registration::instance();
2015
-        //get all other registrations on this transaction, and cache
2016
-        //the attendees for them so we don't have to run another query using force_join
2017
-        $registrations                           = $REG->get_all(array(
2018
-            array(
2019
-                'TXN_ID' => $this->_registration->transaction_ID(),
2020
-                'REG_ID' => array('!=', $this->_registration->ID()),
2021
-            ),
2022
-            'force_join' => array('Attendee'),
2023
-        ));
2024
-        $this->_template_args['attendees']       = array();
2025
-        $this->_template_args['attendee_notice'] = '';
2026
-        if (empty($registrations)
2027
-            || (is_array($registrations)
2028
-                && ! EEH_Array::get_one_item_from_array($registrations))
2029
-        ) {
2030
-            EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration',
2031
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2032
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2033
-        } else {
2034
-            $att_nmbr = 1;
2035
-            foreach ($registrations as $registration) {
2036
-                /* @var $registration EE_Registration */
2037
-                $attendee                                                    = $registration->attendee()
2038
-                    ? $registration->attendee()
2039
-                    : EEM_Attendee::instance()
2040
-                                  ->create_default_object();
2041
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2042
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2043
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2044
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2045
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2046
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(', ',
2047
-                    $attendee->full_address_as_array());
2048
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(array(
2049
-                    'action' => 'edit_attendee',
2050
-                    'post'   => $attendee->ID(),
2051
-                ), REG_ADMIN_URL);
2052
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2053
-                $att_nmbr++;
2054
-            }
2055
-            //EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
2056
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2057
-            //			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
2058
-        }
2059
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2060
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2061
-    }
2062
-
2063
-
2064
-    /**
2065
-     *        generates HTML for the Edit Registration side meta box
2066
-     *
2067
-     * @access public
2068
-     * @return void
2069
-     */
2070
-    public function _reg_registrant_side_meta_box()
2071
-    {
2072
-        /*@var $attendee EE_Attendee */
2073
-        $att_check = $this->_registration->attendee();
2074
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2075
-        //now let's determine if this is not the primary registration.  If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not)
2076
-        if ( ! $this->_registration->is_primary_registrant()) {
2077
-            $primary_registration = $this->_registration->get_primary_registration();
2078
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2079
-                : null;
2080
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2081
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg.
2082
-                $primary_registration = null;
2083
-            }
2084
-        } else {
2085
-            $primary_registration = null;
2086
-        }
2087
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2088
-        $this->_template_args['fname']             = $attendee->fname();//$this->_registration->ATT_fname;
2089
-        $this->_template_args['lname']             = $attendee->lname();//$this->_registration->ATT_lname;
2090
-        $this->_template_args['email']             = $attendee->email();//$this->_registration->ATT_email;
2091
-        $this->_template_args['phone']             = $attendee->phone();
2092
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2093
-        //edit link
2094
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2095
-            'action' => 'edit_attendee',
2096
-            'post'   => $attendee->ID(),
2097
-        ), REG_ADMIN_URL);
2098
-        $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso');
2099
-        //create link
2100
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2101
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2102
-                'action'  => 'duplicate_attendee',
2103
-                '_REG_ID' => $this->_registration->ID(),
2104
-            ), REG_ADMIN_URL) : '';
2105
-        $this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
2106
-        $this->_template_args['att_check']    = $att_check;
2107
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2108
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2109
-    }
2110
-
2111
-
2112
-
2113
-    /**
2114
-     * trash or restore registrations
2115
-     *
2116
-     * @param  boolean $trash whether to archive or restore
2117
-     * @access protected
2118
-     * @return void
2119
-     * @throws \EE_Error
2120
-     */
2121
-    protected function _trash_or_restore_registrations($trash = true)
2122
-    {
2123
-        //if empty _REG_ID then get out because there's nothing to do
2124
-        if (empty($this->_req_data['_REG_ID'])) {
2125
-            EE_Error::add_error(
2126
-                sprintf(
2127
-                    esc_html__(
2128
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2129
-                        'event_espresso'
2130
-                    ),
2131
-                    $trash ? 'trash' : 'restore'
2132
-                ),
2133
-                __FILE__, __LINE__, __FUNCTION__
2134
-            );
2135
-            $this->_redirect_after_action(false, '', '', array(), true);
2136
-        }
2137
-        $success = 0;
2138
-        $overwrite_msgs = false;
2139
-        //Checkboxes
2140
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2141
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2142
-        }
2143
-        $reg_count = count($this->_req_data['_REG_ID']);
2144
-        // cycle thru checkboxes
2145
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2146
-            /** @var EE_Registration $REG */
2147
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2148
-            $payments = $REG->registration_payments();
2149
-            if (! empty($payments)) {
2150
-                $name = $REG->attendee() instanceof EE_Attendee
2151
-                    ? $REG->attendee()->full_name()
2152
-                    : __('Unknown Attendee', 'event_espresso');
2153
-                $overwrite_msgs = true;
2154
-                EE_Error::add_error(
2155
-                    sprintf(
2156
-                        __(
2157
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2158
-                            'event_espresso'
2159
-                        ),
2160
-                        $name
2161
-                    ),
2162
-                    __FILE__, __FUNCTION__, __LINE__
2163
-                );
2164
-                //can't trash this registration because it has payments.
2165
-                continue;
2166
-            }
2167
-            $updated = $trash ? $REG->delete() : $REG->restore();
2168
-            if ($updated) {
2169
-                $success++;
2170
-            }
2171
-        }
2172
-        $this->_redirect_after_action(
2173
-            $success === $reg_count, // were ALL registrations affected?
2174
-            $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'),
2175
-            $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'),
2176
-            array('action' => 'default'),
2177
-            $overwrite_msgs
2178
-        );
2179
-    }
2180
-
2181
-
2182
-    /**
2183
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2184
-     * registration but also.
2185
-     * 1. Removing relations to EE_Attendee
2186
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2187
-     * ALSO trashed.
2188
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2189
-     * 4. Removing relationships between all tickets and the related registrations
2190
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2191
-     * 6. Deleting permanently any related Checkins.
2192
-     *
2193
-     * @return void
2194
-     */
2195
-    protected function _delete_registrations()
2196
-    {
2197
-        $REG_MDL = EEM_Registration::instance();
2198
-        $success = 1;
2199
-        //Checkboxes
2200
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2201
-            // if array has more than one element than success message should be plural
2202
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2203
-            // cycle thru checkboxes
2204
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2205
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2206
-                if ( ! $REG instanceof EE_Registration) {
2207
-                    continue;
2208
-                }
2209
-                $deleted = $this->_delete_registration($REG);
2210
-                if ( ! $deleted) {
2211
-                    $success = 0;
2212
-                }
2213
-            }
2214
-        } else {
2215
-            // grab single id and delete
2216
-            $REG_ID  = $this->_req_data['_REG_ID'];
2217
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2218
-            $deleted = $this->_delete_registration($REG);
2219
-            if ( ! $deleted) {
2220
-                $success = 0;
2221
-            }
2222
-        }
2223
-        $what        = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2224
-        $action_desc = __('permanently deleted.', 'event_espresso');
2225
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true);
2226
-    }
2227
-
2228
-
2229
-    /**
2230
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2231
-     * models get affected.
2232
-     *
2233
-     * @param  EE_Registration $REG registration to be deleted permenantly
2234
-     * @return boolean              true = successful deletion, false = fail.
2235
-     */
2236
-    protected function _delete_registration(EE_Registration $REG)
2237
-    {
2238
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed.
2239
-        $TXN         = $REG->get_first_related('Transaction');
2240
-        $REGS        = $TXN->get_many_related('Registration');
2241
-        $all_trashed = true;
2242
-        foreach ($REGS as $registration) {
2243
-            if ( ! $registration->get('REG_deleted')) {
2244
-                $all_trashed = false;
2245
-            }
2246
-        }
2247
-        if ( ! $all_trashed) {
2248
-            EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2249
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2250
-            return false;
2251
-        }
2252
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one).
2253
-        foreach ($REGS as $registration) {
2254
-            //delete related answers
2255
-            $registration->delete_related_permanently('Answer');
2256
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2257
-            $attendee = $registration->get_first_related('Attendee');
2258
-            if ($attendee instanceof EE_Attendee) {
2259
-                $registration->_remove_relation_to($attendee, 'Attendee');
2260
-            }
2261
-            //now remove relationships to tickets on this registration.
2262
-            $registration->_remove_relations('Ticket');
2263
-            //now delete permanently the checkins related to this registration.
2264
-            $registration->delete_related_permanently('Checkin');
2265
-            if ($registration->ID() === $REG->ID()) {
2266
-                continue;
2267
-            } //we don't want to delete permanently the existing registration just yet.
2268
-            //remove relation to transaction for these registrations if NOT the existing registrations
2269
-            $registration->_remove_relations('Transaction');
2270
-            //delete permanently any related messages.
2271
-            $registration->delete_related_permanently('Message');
2272
-            //now delete this registration permanently
2273
-            $registration->delete_permanently();
2274
-        }
2275
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself (the transaction and line items should be all that's left).
2276
-        //delete the line items related to the transaction for this registration.
2277
-        $TXN->delete_related_permanently('Line_Item');
2278
-        //we need to remove all the relationships on the transaction
2279
-        $TXN->delete_related_permanently('Payment');
2280
-        $TXN->delete_related_permanently('Extra_Meta');
2281
-        $TXN->delete_related_permanently('Message');
2282
-        //now we can delete this REG permanently (and the transaction of course)
2283
-        $REG->delete_related_permanently('Transaction');
2284
-        return $REG->delete_permanently();
2285
-    }
2286
-
2287
-
2288
-    /**
2289
-     *    generates HTML for the Register New Attendee Admin page
2290
-     *
2291
-     * @access private
2292
-     * @throws \EE_Error
2293
-     * @return void
2294
-     */
2295
-    public function new_registration()
2296
-    {
2297
-        if ( ! $this->_set_reg_event()) {
2298
-            throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request',
2299
-                'event_espresso'));
2300
-        }
2301
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2302
-        // gotta start with a clean slate if we're not coming here via ajax
2303
-        if ( ! defined('DOING_AJAX')
2304
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2305
-        ) {
2306
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2307
-        }
2308
-        $this->_template_args['event_name'] = '';
2309
-        // event name
2310
-        if ($this->_reg_event) {
2311
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2312
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2313
-                'action' => 'edit',
2314
-                'post'   => $this->_reg_event->ID(),
2315
-            ), EVENTS_ADMIN_URL);
2316
-            $edit_event_lnk                     = '<a href="'
2317
-                                                  . $edit_event_url
2318
-                                                  . '" title="'
2319
-                                                  . esc_attr__('Edit ', 'event_espresso')
2320
-                                                  . $this->_reg_event->name()
2321
-                                                  . '">'
2322
-                                                  . __('Edit Event', 'event_espresso')
2323
-                                                  . '</a>';
2324
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2325
-                                                   . $edit_event_lnk
2326
-                                                   . '</span>';
2327
-        }
2328
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2329
-        if (defined('DOING_AJAX')) {
2330
-            $this->_return_json();
2331
-        }
2332
-        // grab header
2333
-        $template_path                              = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2334
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2335
-            $this->_template_args, true);
2336
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2337
-        // the details template wrapper
2338
-        $this->display_admin_page_with_sidebar();
2339
-    }
2340
-
2341
-
2342
-    /**
2343
-     * This returns the content for a registration step
2344
-     *
2345
-     * @access protected
2346
-     * @return string html
2347
-     */
2348
-    protected function _get_registration_step_content()
2349
-    {
2350
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2351
-            $warning_msg = sprintf(__('%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2352
-                'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">',
2353
-                '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>');
2354
-            return '
1915
+	}
1916
+
1917
+
1918
+	/**
1919
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
1920
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
1921
+	 * to display the page
1922
+	 *
1923
+	 * @access protected
1924
+	 * @return void
1925
+	 */
1926
+	protected function _update_attendee_registration_form()
1927
+	{
1928
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
1929
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1930
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
1931
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
1932
+			if ($success) {
1933
+				$what  = __('Registration Form', 'event_espresso');
1934
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
1935
+					: array('action' => 'default');
1936
+				$this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
1937
+			}
1938
+		}
1939
+	}
1940
+
1941
+
1942
+	/**
1943
+	 * Gets the form for saving registrations custom questions (if done
1944
+	 * previously retrieves the cached form object, which may have validation errors in it)
1945
+	 *
1946
+	 * @param int $REG_ID
1947
+	 * @return EE_Registration_Custom_Questions_Form
1948
+	 */
1949
+	protected function _get_reg_custom_questions_form($REG_ID)
1950
+	{
1951
+		if ( ! $this->_reg_custom_questions_form) {
1952
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
1953
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
1954
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
1955
+			);
1956
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
1957
+		}
1958
+		return $this->_reg_custom_questions_form;
1959
+	}
1960
+
1961
+
1962
+	/**
1963
+	 * Saves
1964
+	 *
1965
+	 * @access private
1966
+	 * @param bool $REG_ID
1967
+	 * @return bool
1968
+	 */
1969
+	private function _save_reg_custom_questions_form($REG_ID = false)
1970
+	{
1971
+		if ( ! $REG_ID) {
1972
+			EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__,
1973
+				__FUNCTION__, __LINE__);
1974
+		}
1975
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
1976
+		$form->receive_form_submission($this->_req_data);
1977
+		$success = false;
1978
+		if ($form->is_valid()) {
1979
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
1980
+				foreach ($question_group_form->inputs() as $question_id => $input) {
1981
+					$where_conditions    = array(
1982
+						'QST_ID' => $question_id,
1983
+						'REG_ID' => $REG_ID,
1984
+					);
1985
+					$possibly_new_values = array(
1986
+						'ANS_value' => $input->normalized_value(),
1987
+					);
1988
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
1989
+					if ($answer instanceof EE_Answer) {
1990
+						$success = $answer->save($possibly_new_values);
1991
+					} else {
1992
+						//insert it then
1993
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
1994
+						$answer      = EE_Answer::new_instance($cols_n_vals);
1995
+						$success     = $answer->save();
1996
+					}
1997
+				}
1998
+			}
1999
+		} else {
2000
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2001
+		}
2002
+		return $success;
2003
+	}
2004
+
2005
+
2006
+	/**
2007
+	 *        generates HTML for the Registration main meta box
2008
+	 *
2009
+	 * @access public
2010
+	 * @return void
2011
+	 */
2012
+	public function _reg_attendees_meta_box()
2013
+	{
2014
+		$REG = EEM_Registration::instance();
2015
+		//get all other registrations on this transaction, and cache
2016
+		//the attendees for them so we don't have to run another query using force_join
2017
+		$registrations                           = $REG->get_all(array(
2018
+			array(
2019
+				'TXN_ID' => $this->_registration->transaction_ID(),
2020
+				'REG_ID' => array('!=', $this->_registration->ID()),
2021
+			),
2022
+			'force_join' => array('Attendee'),
2023
+		));
2024
+		$this->_template_args['attendees']       = array();
2025
+		$this->_template_args['attendee_notice'] = '';
2026
+		if (empty($registrations)
2027
+			|| (is_array($registrations)
2028
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2029
+		) {
2030
+			EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration',
2031
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2032
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2033
+		} else {
2034
+			$att_nmbr = 1;
2035
+			foreach ($registrations as $registration) {
2036
+				/* @var $registration EE_Registration */
2037
+				$attendee                                                    = $registration->attendee()
2038
+					? $registration->attendee()
2039
+					: EEM_Attendee::instance()
2040
+								  ->create_default_object();
2041
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2042
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2043
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2044
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2045
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2046
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(', ',
2047
+					$attendee->full_address_as_array());
2048
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(array(
2049
+					'action' => 'edit_attendee',
2050
+					'post'   => $attendee->ID(),
2051
+				), REG_ADMIN_URL);
2052
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2053
+				$att_nmbr++;
2054
+			}
2055
+			//EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
2056
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2057
+			//			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
2058
+		}
2059
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2060
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2061
+	}
2062
+
2063
+
2064
+	/**
2065
+	 *        generates HTML for the Edit Registration side meta box
2066
+	 *
2067
+	 * @access public
2068
+	 * @return void
2069
+	 */
2070
+	public function _reg_registrant_side_meta_box()
2071
+	{
2072
+		/*@var $attendee EE_Attendee */
2073
+		$att_check = $this->_registration->attendee();
2074
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2075
+		//now let's determine if this is not the primary registration.  If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not)
2076
+		if ( ! $this->_registration->is_primary_registrant()) {
2077
+			$primary_registration = $this->_registration->get_primary_registration();
2078
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2079
+				: null;
2080
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2081
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg.
2082
+				$primary_registration = null;
2083
+			}
2084
+		} else {
2085
+			$primary_registration = null;
2086
+		}
2087
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2088
+		$this->_template_args['fname']             = $attendee->fname();//$this->_registration->ATT_fname;
2089
+		$this->_template_args['lname']             = $attendee->lname();//$this->_registration->ATT_lname;
2090
+		$this->_template_args['email']             = $attendee->email();//$this->_registration->ATT_email;
2091
+		$this->_template_args['phone']             = $attendee->phone();
2092
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2093
+		//edit link
2094
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2095
+			'action' => 'edit_attendee',
2096
+			'post'   => $attendee->ID(),
2097
+		), REG_ADMIN_URL);
2098
+		$this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso');
2099
+		//create link
2100
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2101
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2102
+				'action'  => 'duplicate_attendee',
2103
+				'_REG_ID' => $this->_registration->ID(),
2104
+			), REG_ADMIN_URL) : '';
2105
+		$this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
2106
+		$this->_template_args['att_check']    = $att_check;
2107
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2108
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2109
+	}
2110
+
2111
+
2112
+
2113
+	/**
2114
+	 * trash or restore registrations
2115
+	 *
2116
+	 * @param  boolean $trash whether to archive or restore
2117
+	 * @access protected
2118
+	 * @return void
2119
+	 * @throws \EE_Error
2120
+	 */
2121
+	protected function _trash_or_restore_registrations($trash = true)
2122
+	{
2123
+		//if empty _REG_ID then get out because there's nothing to do
2124
+		if (empty($this->_req_data['_REG_ID'])) {
2125
+			EE_Error::add_error(
2126
+				sprintf(
2127
+					esc_html__(
2128
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2129
+						'event_espresso'
2130
+					),
2131
+					$trash ? 'trash' : 'restore'
2132
+				),
2133
+				__FILE__, __LINE__, __FUNCTION__
2134
+			);
2135
+			$this->_redirect_after_action(false, '', '', array(), true);
2136
+		}
2137
+		$success = 0;
2138
+		$overwrite_msgs = false;
2139
+		//Checkboxes
2140
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2141
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2142
+		}
2143
+		$reg_count = count($this->_req_data['_REG_ID']);
2144
+		// cycle thru checkboxes
2145
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2146
+			/** @var EE_Registration $REG */
2147
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2148
+			$payments = $REG->registration_payments();
2149
+			if (! empty($payments)) {
2150
+				$name = $REG->attendee() instanceof EE_Attendee
2151
+					? $REG->attendee()->full_name()
2152
+					: __('Unknown Attendee', 'event_espresso');
2153
+				$overwrite_msgs = true;
2154
+				EE_Error::add_error(
2155
+					sprintf(
2156
+						__(
2157
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2158
+							'event_espresso'
2159
+						),
2160
+						$name
2161
+					),
2162
+					__FILE__, __FUNCTION__, __LINE__
2163
+				);
2164
+				//can't trash this registration because it has payments.
2165
+				continue;
2166
+			}
2167
+			$updated = $trash ? $REG->delete() : $REG->restore();
2168
+			if ($updated) {
2169
+				$success++;
2170
+			}
2171
+		}
2172
+		$this->_redirect_after_action(
2173
+			$success === $reg_count, // were ALL registrations affected?
2174
+			$success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso'),
2175
+			$trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso'),
2176
+			array('action' => 'default'),
2177
+			$overwrite_msgs
2178
+		);
2179
+	}
2180
+
2181
+
2182
+	/**
2183
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2184
+	 * registration but also.
2185
+	 * 1. Removing relations to EE_Attendee
2186
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2187
+	 * ALSO trashed.
2188
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2189
+	 * 4. Removing relationships between all tickets and the related registrations
2190
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2191
+	 * 6. Deleting permanently any related Checkins.
2192
+	 *
2193
+	 * @return void
2194
+	 */
2195
+	protected function _delete_registrations()
2196
+	{
2197
+		$REG_MDL = EEM_Registration::instance();
2198
+		$success = 1;
2199
+		//Checkboxes
2200
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2201
+			// if array has more than one element than success message should be plural
2202
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2203
+			// cycle thru checkboxes
2204
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2205
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2206
+				if ( ! $REG instanceof EE_Registration) {
2207
+					continue;
2208
+				}
2209
+				$deleted = $this->_delete_registration($REG);
2210
+				if ( ! $deleted) {
2211
+					$success = 0;
2212
+				}
2213
+			}
2214
+		} else {
2215
+			// grab single id and delete
2216
+			$REG_ID  = $this->_req_data['_REG_ID'];
2217
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2218
+			$deleted = $this->_delete_registration($REG);
2219
+			if ( ! $deleted) {
2220
+				$success = 0;
2221
+			}
2222
+		}
2223
+		$what        = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2224
+		$action_desc = __('permanently deleted.', 'event_espresso');
2225
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true);
2226
+	}
2227
+
2228
+
2229
+	/**
2230
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2231
+	 * models get affected.
2232
+	 *
2233
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2234
+	 * @return boolean              true = successful deletion, false = fail.
2235
+	 */
2236
+	protected function _delete_registration(EE_Registration $REG)
2237
+	{
2238
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed.
2239
+		$TXN         = $REG->get_first_related('Transaction');
2240
+		$REGS        = $TXN->get_many_related('Registration');
2241
+		$all_trashed = true;
2242
+		foreach ($REGS as $registration) {
2243
+			if ( ! $registration->get('REG_deleted')) {
2244
+				$all_trashed = false;
2245
+			}
2246
+		}
2247
+		if ( ! $all_trashed) {
2248
+			EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2249
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2250
+			return false;
2251
+		}
2252
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one).
2253
+		foreach ($REGS as $registration) {
2254
+			//delete related answers
2255
+			$registration->delete_related_permanently('Answer');
2256
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2257
+			$attendee = $registration->get_first_related('Attendee');
2258
+			if ($attendee instanceof EE_Attendee) {
2259
+				$registration->_remove_relation_to($attendee, 'Attendee');
2260
+			}
2261
+			//now remove relationships to tickets on this registration.
2262
+			$registration->_remove_relations('Ticket');
2263
+			//now delete permanently the checkins related to this registration.
2264
+			$registration->delete_related_permanently('Checkin');
2265
+			if ($registration->ID() === $REG->ID()) {
2266
+				continue;
2267
+			} //we don't want to delete permanently the existing registration just yet.
2268
+			//remove relation to transaction for these registrations if NOT the existing registrations
2269
+			$registration->_remove_relations('Transaction');
2270
+			//delete permanently any related messages.
2271
+			$registration->delete_related_permanently('Message');
2272
+			//now delete this registration permanently
2273
+			$registration->delete_permanently();
2274
+		}
2275
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself (the transaction and line items should be all that's left).
2276
+		//delete the line items related to the transaction for this registration.
2277
+		$TXN->delete_related_permanently('Line_Item');
2278
+		//we need to remove all the relationships on the transaction
2279
+		$TXN->delete_related_permanently('Payment');
2280
+		$TXN->delete_related_permanently('Extra_Meta');
2281
+		$TXN->delete_related_permanently('Message');
2282
+		//now we can delete this REG permanently (and the transaction of course)
2283
+		$REG->delete_related_permanently('Transaction');
2284
+		return $REG->delete_permanently();
2285
+	}
2286
+
2287
+
2288
+	/**
2289
+	 *    generates HTML for the Register New Attendee Admin page
2290
+	 *
2291
+	 * @access private
2292
+	 * @throws \EE_Error
2293
+	 * @return void
2294
+	 */
2295
+	public function new_registration()
2296
+	{
2297
+		if ( ! $this->_set_reg_event()) {
2298
+			throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request',
2299
+				'event_espresso'));
2300
+		}
2301
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2302
+		// gotta start with a clean slate if we're not coming here via ajax
2303
+		if ( ! defined('DOING_AJAX')
2304
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2305
+		) {
2306
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2307
+		}
2308
+		$this->_template_args['event_name'] = '';
2309
+		// event name
2310
+		if ($this->_reg_event) {
2311
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2312
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2313
+				'action' => 'edit',
2314
+				'post'   => $this->_reg_event->ID(),
2315
+			), EVENTS_ADMIN_URL);
2316
+			$edit_event_lnk                     = '<a href="'
2317
+												  . $edit_event_url
2318
+												  . '" title="'
2319
+												  . esc_attr__('Edit ', 'event_espresso')
2320
+												  . $this->_reg_event->name()
2321
+												  . '">'
2322
+												  . __('Edit Event', 'event_espresso')
2323
+												  . '</a>';
2324
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2325
+												   . $edit_event_lnk
2326
+												   . '</span>';
2327
+		}
2328
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2329
+		if (defined('DOING_AJAX')) {
2330
+			$this->_return_json();
2331
+		}
2332
+		// grab header
2333
+		$template_path                              = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2334
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2335
+			$this->_template_args, true);
2336
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2337
+		// the details template wrapper
2338
+		$this->display_admin_page_with_sidebar();
2339
+	}
2340
+
2341
+
2342
+	/**
2343
+	 * This returns the content for a registration step
2344
+	 *
2345
+	 * @access protected
2346
+	 * @return string html
2347
+	 */
2348
+	protected function _get_registration_step_content()
2349
+	{
2350
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2351
+			$warning_msg = sprintf(__('%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2352
+				'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">',
2353
+				'<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>');
2354
+			return '
2355 2355
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2356 2356
 	<script >
2357 2357
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2364,658 +2364,658 @@  discard block
 block discarded – undo
2364 2364
 	        }
2365 2365
 	    }, 800 );
2366 2366
 	</script >';
2367
-        }
2368
-        $template_args = array(
2369
-            'title'                    => '',
2370
-            'content'                  => '',
2371
-            'step_button_text'         => '',
2372
-            'show_notification_toggle' => false,
2373
-        );
2374
-        //to indicate we're processing a new registration
2375
-        $hidden_fields = array(
2376
-            'processing_registration' => array(
2377
-                'type'  => 'hidden',
2378
-                'value' => 0,
2379
-            ),
2380
-            'event_id'                => array(
2381
-                'type'  => 'hidden',
2382
-                'value' => $this->_reg_event->ID(),
2383
-            ),
2384
-        );
2385
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2386
-        $cart = EE_Registry::instance()->SSN->cart();
2387
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2388
-        switch ($step) {
2389
-            case 'ticket' :
2390
-                $hidden_fields['processing_registration']['value'] = 1;
2391
-                $template_args['title']                            = __('Step One: Select the Ticket for this registration',
2392
-                    'event_espresso');
2393
-                $template_args['content']                          = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2394
-                $template_args['step_button_text']                 = __('Add Tickets and Continue to Registrant Details',
2395
-                    'event_espresso');
2396
-                $template_args['show_notification_toggle']         = false;
2397
-                break;
2398
-            case 'questions' :
2399
-                $hidden_fields['processing_registration']['value'] = 2;
2400
-                $template_args['title']                            = __('Step Two: Add Registrant Details for this Registration',
2401
-                    'event_espresso');
2402
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run.
2403
-                $template_args['content']                  = EED_Single_Page_Checkout::registration_checkout_for_admin();
2404
-                $template_args['step_button_text']         = __('Save Registration and Continue to Details',
2405
-                    'event_espresso');
2406
-                $template_args['show_notification_toggle'] = true;
2407
-                break;
2408
-        }
2409
-        $this->_set_add_edit_form_tags('process_reg_step',
2410
-            $hidden_fields); //we come back to the process_registration_step route.
2411
-        return EEH_Template::display_template(REG_TEMPLATE_PATH
2412
-                                              . 'reg_admin_register_new_attendee_step_content.template.php',
2413
-            $template_args, true);
2414
-    }
2415
-
2416
-
2417
-    /**
2418
-     *        set_reg_event
2419
-     *
2420
-     * @access private
2421
-     * @return boolean
2422
-     */
2423
-    private function _set_reg_event()
2424
-    {
2425
-        if (is_object($this->_reg_event)) {
2426
-            return true;
2427
-        }
2428
-        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2429
-        if ( ! $EVT_ID) {
2430
-            return false;
2431
-        }
2432
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2433
-        return true;
2434
-    }
2435
-
2436
-
2437
-    /**
2438
-     * process_reg_step
2439
-     *
2440
-     * @access        public
2441
-     * @return        string
2442
-     * @throws \RuntimeException
2443
-     * @throws \EE_Error
2444
-     */
2445
-    public function process_reg_step()
2446
-    {
2447
-        EE_System::do_not_cache();
2448
-        $this->_set_reg_event();
2449
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2450
-        EE_Registry::instance()->REQ->set('uts', time());
2451
-        //what step are we on?
2452
-        $cart = EE_Registry::instance()->SSN->cart();
2453
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2454
-        //if doing ajax then we need to verify the nonce
2455
-        if (defined('DOING_AJAX')) {
2456
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2457
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2458
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2459
-        }
2460
-        switch ($step) {
2461
-            case 'ticket' :
2462
-                //process ticket selection
2463
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2464
-                if ($success) {
2465
-                    EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.',
2466
-                        'event_espresso'));
2467
-                } else {
2468
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2469
-                }
2470
-                if (defined('DOING_AJAX')) {
2471
-                    $this->new_registration(); //display next step
2472
-                } else {
2473
-                    $query_args = array(
2474
-                        'action'                  => 'new_registration',
2475
-                        'processing_registration' => 1,
2476
-                        'event_id'                => $this->_reg_event->ID(),
2477
-                        'uts'                     => time(),
2478
-                    );
2479
-                    $this->_redirect_after_action(false, '', '', $query_args, true);
2480
-                }
2481
-                break;
2482
-            case 'questions' :
2483
-                if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) {
2484
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2485
-                }
2486
-                //process registration
2487
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2488
-                if ($cart instanceof EE_Cart) {
2489
-                    $grand_total = $cart->get_cart_grand_total();
2490
-                    if ($grand_total instanceof EE_Line_Item) {
2491
-                        $grand_total->save_this_and_descendants_to_txn();
2492
-                    }
2493
-                }
2494
-                if ( ! $transaction instanceof EE_Transaction) {
2495
-                    $query_args = array(
2496
-                        'action'                  => 'new_registration',
2497
-                        'processing_registration' => 2,
2498
-                        'event_id'                => $this->_reg_event->ID(),
2499
-                        'uts'                     => time(),
2500
-                    );
2501
-                    if (defined('DOING_AJAX')) {
2502
-                        //display registration form again because there are errors (maybe validation?)
2503
-                        $this->new_registration();
2504
-                        return;
2505
-                    } else {
2506
-                        $this->_redirect_after_action(false, '', '', $query_args, true);
2507
-                        return;
2508
-                    }
2509
-                }
2510
-                // maybe update status, and make sure to save transaction if not done already
2511
-                if ( ! $transaction->update_status_based_on_total_paid()) {
2512
-                    $transaction->save();
2513
-                }
2514
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2515
-                $this->_req_data = array();
2516
-                $query_args      = array(
2517
-                    'action'        => 'redirect_to_txn',
2518
-                    'TXN_ID'        => $transaction->ID(),
2519
-                    'EVT_ID'        => $this->_reg_event->ID(),
2520
-                    'event_name'    => urlencode($this->_reg_event->name()),
2521
-                    'redirect_from' => 'new_registration',
2522
-                );
2523
-                $this->_redirect_after_action(false, '', '', $query_args, true);
2524
-                break;
2525
-        }
2526
-        //what are you looking here for?  Should be nothing to do at this point.
2527
-    }
2528
-
2529
-
2530
-    /**
2531
-     * redirect_to_txn
2532
-     *
2533
-     * @access public
2534
-     * @return void
2535
-     */
2536
-    public function redirect_to_txn()
2537
-    {
2538
-        EE_System::do_not_cache();
2539
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2540
-        $query_args = array(
2541
-            'action' => 'view_transaction',
2542
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2543
-            'page'   => 'espresso_transactions',
2544
-        );
2545
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2546
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2547
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
2548
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
2549
-        }
2550
-        EE_Error::add_success(__('Registration Created.  Please review the transaction and add any payments as necessary',
2551
-            'event_espresso'));
2552
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2553
-    }
2554
-
2555
-
2556
-    /**
2557
-     *        generates HTML for the Attendee Contact List
2558
-     *
2559
-     * @access protected
2560
-     * @return void
2561
-     */
2562
-    protected function _attendee_contact_list_table()
2563
-    {
2564
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2565
-        $this->_search_btn_label = __('Contacts', 'event_espresso');
2566
-        $this->display_admin_list_table_page_with_no_sidebar();
2567
-    }
2568
-
2569
-
2570
-    /**
2571
-     *        get_attendees
2572
-     *
2573
-     * @param bool $count whether to return count or data.
2574
-     * @access public
2575
-     * @return array
2576
-     */
2577
-    public function get_attendees($per_page, $count = false, $trash = false)
2578
-    {
2579
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2580
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2581
-        $ATT_MDL                    = EEM_Attendee::instance();
2582
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2583
-        switch ($this->_req_data['orderby']) {
2584
-            case 'ATT_ID':
2585
-                $orderby = 'ATT_ID';
2586
-                break;
2587
-            case 'ATT_fname':
2588
-                $orderby = 'ATT_fname';
2589
-                break;
2590
-            case 'ATT_email':
2591
-                $orderby = 'ATT_email';
2592
-                break;
2593
-            case 'ATT_city':
2594
-                $orderby = 'ATT_city';
2595
-                break;
2596
-            case 'STA_ID':
2597
-                $orderby = 'STA_ID';
2598
-                break;
2599
-            case 'CNT_ID':
2600
-                $orderby = 'CNT_ID';
2601
-                break;
2602
-            default:
2603
-                $orderby = 'ATT_lname';
2604
-        }
2605
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
2606
-            : 'ASC';
2607
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2608
-            ? $this->_req_data['paged'] : 1;
2609
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2610
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2611
-            ? $this->_req_data['perpage'] : $per_page;
2612
-        $_where       = array();
2613
-        if ( ! empty($this->_req_data['s'])) {
2614
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2615
-            $_where['OR'] = array(
2616
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2617
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
2618
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
2619
-                'ATT_fname'                         => array('LIKE', $sstr),
2620
-                'ATT_lname'                         => array('LIKE', $sstr),
2621
-                'ATT_short_bio'                     => array('LIKE', $sstr),
2622
-                'ATT_email'                         => array('LIKE', $sstr),
2623
-                'ATT_address'                       => array('LIKE', $sstr),
2624
-                'ATT_address2'                      => array('LIKE', $sstr),
2625
-                'ATT_city'                          => array('LIKE', $sstr),
2626
-                'Country.CNT_name'                  => array('LIKE', $sstr),
2627
-                'State.STA_name'                    => array('LIKE', $sstr),
2628
-                'ATT_phone'                         => array('LIKE', $sstr),
2629
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
2630
-                'Registration.REG_code'             => array('LIKE', $sstr),
2631
-                'Registration.REG_count'            => array('LIKE', $sstr),
2632
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
2633
-            );
2634
-        }
2635
-        $offset = ($current_page - 1) * $per_page;
2636
-        $limit  = $count ? null : array($offset, $per_page);
2637
-        if ($trash) {
2638
-            $_where['status'] = array('!=', 'publish');
2639
-            $all_attendees    = $count
2640
-                ? $ATT_MDL->count(array(
2641
-                    $_where,
2642
-                    'order_by' => array($orderby => $sort),
2643
-                    'limit'    => $limit,
2644
-                ), 'ATT_ID', true)
2645
-                : $ATT_MDL->get_all(array(
2646
-                    $_where,
2647
-                    'order_by' => array($orderby => $sort),
2648
-                    'limit'    => $limit,
2649
-                ));
2650
-        } else {
2651
-            $_where['status'] = array('IN', array('publish'));
2652
-            $all_attendees    = $count
2653
-                ? $ATT_MDL->count(array(
2654
-                    $_where,
2655
-                    'order_by' => array($orderby => $sort),
2656
-                    'limit'    => $limit,
2657
-                ), 'ATT_ID', true)
2658
-                : $ATT_MDL->get_all(array(
2659
-                    $_where,
2660
-                    'order_by' => array($orderby => $sort),
2661
-                    'limit'    => $limit,
2662
-                ));
2663
-        }
2664
-        return $all_attendees;
2665
-    }
2666
-
2667
-
2668
-    /**
2669
-     * This is just taking care of resending the registration confirmation
2670
-     *
2671
-     * @access protected
2672
-     * @return void
2673
-     */
2674
-    protected function _resend_registration()
2675
-    {
2676
-        $this->_process_resend_registration();
2677
-        $query_args = isset($this->_req_data['redirect_to'])
2678
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
2679
-            : array(
2680
-                'action' => 'default',
2681
-            );
2682
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2683
-    }
2684
-
2685
-    /**
2686
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
2687
-     * to use when selecting registrations
2688
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
2689
-     *                                                     the query parameters from the request
2690
-     * @return void ends the request with a redirect or download
2691
-     */
2692
-    public function _registrations_report_base( $method_name_for_getting_query_params )
2693
-    {
2694
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2695
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2696
-                'page'        => 'espresso_batch',
2697
-                'batch'       => 'file',
2698
-                'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2699
-                'filters'     => urlencode(
2700
-                    serialize(
2701
-                        call_user_func(
2702
-                            array( $this, $method_name_for_getting_query_params ),
2703
-                            EEH_Array::is_set(
2704
-                                $this->_req_data,
2705
-                                'filters',
2706
-                                array()
2707
-                            )
2708
-                        )
2709
-                    )
2710
-                ),
2711
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
2712
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
2713
-                'return_url'  => urlencode($this->_req_data['return_url']),
2714
-            )));
2715
-        } else {
2716
-            $new_request_args = array(
2717
-                'export' => 'report',
2718
-                'action' => 'registrations_report_for_event',
2719
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2720
-            );
2721
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
2722
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2723
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2724
-                $EE_Export = EE_Export::instance($this->_req_data);
2725
-                $EE_Export->export();
2726
-            }
2727
-        }
2728
-    }
2729
-
2730
-
2731
-
2732
-    /**
2733
-     * Creates a registration report using only query parameters in the request
2734
-     * @return void
2735
-     */
2736
-    public function _registrations_report()
2737
-    {
2738
-        $this->_registrations_report_base( '_get_registration_query_parameters' );
2739
-    }
2740
-
2741
-
2742
-    public function _contact_list_export()
2743
-    {
2744
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2745
-            require_once(EE_CLASSES . 'EE_Export.class.php');
2746
-            $EE_Export = EE_Export::instance($this->_req_data);
2747
-            $EE_Export->export_attendees();
2748
-        }
2749
-    }
2750
-
2751
-
2752
-    public function _contact_list_report()
2753
-    {
2754
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2755
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2756
-                'page'        => 'espresso_batch',
2757
-                'batch'       => 'file',
2758
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
2759
-                'return_url'  => urlencode($this->_req_data['return_url']),
2760
-            )));
2761
-        } else {
2762
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2763
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2764
-                $EE_Export = EE_Export::instance($this->_req_data);
2765
-                $EE_Export->report_attendees();
2766
-            }
2767
-        }
2768
-    }
2769
-
2770
-
2771
-
2772
-
2773
-
2774
-    /***************************************        ATTENDEE DETAILS        ***************************************/
2775
-    /**
2776
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
2777
-     *
2778
-     * @return void
2779
-     */
2780
-    protected function _duplicate_attendee()
2781
-    {
2782
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
2783
-        //verify we have necessary info
2784
-        if (empty($this->_req_data['_REG_ID'])) {
2785
-            EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
2786
-                'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
2787
-            $query_args = array('action' => $action);
2788
-            $this->_redirect_after_action('', '', '', $query_args, true);
2789
-        }
2790
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
2791
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
2792
-        $attendee     = $registration->attendee();
2793
-        //remove relation of existing attendee on registration
2794
-        $registration->_remove_relation_to($attendee, 'Attendee');
2795
-        //new attendee
2796
-        $new_attendee = clone $attendee;
2797
-        $new_attendee->set('ATT_ID', 0);
2798
-        $new_attendee->save();
2799
-        //add new attendee to reg
2800
-        $registration->_add_relation_to($new_attendee, 'Attendee');
2801
-        EE_Error::add_success(__('New Contact record created.  Now make any edits you wish to make for this contact.',
2802
-            'event_espresso'));
2803
-        //redirect to edit page for attendee
2804
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
2805
-        $this->_redirect_after_action('', '', '', $query_args, true);
2806
-    }
2807
-
2808
-
2809
-    //related to cpt routes
2810
-    protected function _insert_update_cpt_item($post_id, $post)
2811
-    {
2812
-        $success  = true;
2813
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
2814
-        //for attendee updates
2815
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
2816
-            //note we should only be UPDATING attendees at this point.
2817
-            $updated_fields = array(
2818
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
2819
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
2820
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2821
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2822
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2823
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
2824
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
2825
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
2826
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
2827
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
2828
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
2829
-            );
2830
-            foreach ($updated_fields as $field => $value) {
2831
-                $attendee->set($field, $value);
2832
-            }
2833
-            $success                   = $attendee->save();
2834
-            $attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
2835
-                array());
2836
-            foreach ($attendee_update_callbacks as $a_callback) {
2837
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
2838
-                    throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
2839
-                        'event_espresso'), $a_callback));
2840
-                }
2841
-            }
2842
-        }
2843
-        if ($success === false) {
2844
-            EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.',
2845
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2846
-        }
2847
-    }
2848
-
2849
-
2850
-    public function trash_cpt_item($post_id)
2851
-    {
2852
-    }
2853
-
2854
-
2855
-    public function delete_cpt_item($post_id)
2856
-    {
2857
-    }
2858
-
2859
-
2860
-    public function restore_cpt_item($post_id)
2861
-    {
2862
-    }
2863
-
2864
-
2865
-    protected function _restore_cpt_item($post_id, $revision_id)
2866
-    {
2867
-    }
2868
-
2869
-
2870
-    public function attendee_editor_metaboxes()
2871
-    {
2872
-        $this->verify_cpt_object();
2873
-        remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action],
2874
-            'normal', 'core');
2875
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2876
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
2877
-            add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box',
2878
-                $this->_cpt_routes[$this->_req_action], 'normal');
2879
-        }
2880
-        if (post_type_supports('espresso_attendees', 'comments')) {
2881
-            add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box',
2882
-                $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2883
-        }
2884
-        add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'),
2885
-            array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core');
2886
-        add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'),
2887
-            array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2888
-        add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'),
2889
-            array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high');
2890
-    }
2891
-
2892
-
2893
-    /**
2894
-     * Metabox for attendee contact info
2895
-     *
2896
-     * @param  WP_Post $post wp post object
2897
-     * @return string        attendee contact info ( and form )
2898
-     */
2899
-    public function attendee_contact_info($post)
2900
-    {
2901
-        //get attendee object ( should already have it )
2902
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
2903
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2904
-        EEH_Template::display_template($template, $this->_template_args);
2905
-    }
2906
-
2907
-
2908
-    /**
2909
-     * Metabox for attendee details
2910
-     *
2911
-     * @param  WP_Post $post wp post object
2912
-     * @return string        attendee address details (and form)
2913
-     */
2914
-    public function attendee_address_details($post)
2915
-    {
2916
-        //get attendee object (should already have it)
2917
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
2918
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2919
-            'QST_ID'           => 0,
2920
-            'QST_display_text' => __('State/Province', 'event_espresso'),
2921
-            'QST_system'       => 'admin-state',
2922
-        )), EE_Answer::new_instance(array(
2923
-            'ANS_ID'    => 0,
2924
-            'ANS_value' => $this->_cpt_model_obj->state_ID(),
2925
-        )), array(
2926
-            'input_id'       => 'STA_ID',
2927
-            'input_name'     => 'STA_ID',
2928
-            'input_prefix'   => '',
2929
-            'append_qstn_id' => false,
2930
-        )));
2931
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2932
-            'QST_ID'           => 0,
2933
-            'QST_display_text' => __('Country', 'event_espresso'),
2934
-            'QST_system'       => 'admin-country',
2935
-        )), EE_Answer::new_instance(array(
2936
-            'ANS_ID'    => 0,
2937
-            'ANS_value' => $this->_cpt_model_obj->country_ID(),
2938
-        )), array(
2939
-            'input_id'       => 'CNT_ISO',
2940
-            'input_name'     => 'CNT_ISO',
2941
-            'input_prefix'   => '',
2942
-            'append_qstn_id' => false,
2943
-        )));
2944
-        $template                             = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2945
-        EEH_Template::display_template($template, $this->_template_args);
2946
-    }
2947
-
2948
-
2949
-    /**
2950
-     *        _attendee_details
2951
-     *
2952
-     * @access protected
2953
-     * @return void
2954
-     */
2955
-    public function attendee_registrations_meta_box($post)
2956
-    {
2957
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
2958
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2959
-        $template                              = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2960
-        EEH_Template::display_template($template, $this->_template_args);
2961
-    }
2962
-
2963
-
2964
-    /**
2965
-     * add in the form fields for the attendee edit
2966
-     *
2967
-     * @param  WP_Post $post wp post object
2968
-     * @return string        html for new form.
2969
-     */
2970
-    public function after_title_form_fields($post)
2971
-    {
2972
-        if ($post->post_type == 'espresso_attendees') {
2973
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2974
-            $template_args['attendee'] = $this->_cpt_model_obj;
2975
-            EEH_Template::display_template($template, $template_args);
2976
-        }
2977
-    }
2978
-
2979
-
2980
-    /**
2981
-     *        _trash_or_restore_attendee
2982
-     *
2983
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
2984
-     * @access protected
2985
-     * @return void
2986
-     */
2987
-    protected function _trash_or_restore_attendees($trash = true)
2988
-    {
2989
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2990
-        $ATT_MDL = EEM_Attendee::instance();
2991
-        $success = 1;
2992
-        //Checkboxes
2993
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2994
-            // if array has more than one element than success message should be plural
2995
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2996
-            // cycle thru checkboxes
2997
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
2998
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
2999
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3000
-                if ( ! $updated) {
3001
-                    $success = 0;
3002
-                }
3003
-            }
3004
-        } else {
3005
-            // grab single id and delete
3006
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3007
-            //get attendee
3008
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3009
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3010
-            $updated = $att->save();
3011
-            if ( ! $updated) {
3012
-                $success = 0;
3013
-            }
3014
-        }
3015
-        $what        = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso');
3016
-        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
3017
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3018
-    }
2367
+		}
2368
+		$template_args = array(
2369
+			'title'                    => '',
2370
+			'content'                  => '',
2371
+			'step_button_text'         => '',
2372
+			'show_notification_toggle' => false,
2373
+		);
2374
+		//to indicate we're processing a new registration
2375
+		$hidden_fields = array(
2376
+			'processing_registration' => array(
2377
+				'type'  => 'hidden',
2378
+				'value' => 0,
2379
+			),
2380
+			'event_id'                => array(
2381
+				'type'  => 'hidden',
2382
+				'value' => $this->_reg_event->ID(),
2383
+			),
2384
+		);
2385
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2386
+		$cart = EE_Registry::instance()->SSN->cart();
2387
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2388
+		switch ($step) {
2389
+			case 'ticket' :
2390
+				$hidden_fields['processing_registration']['value'] = 1;
2391
+				$template_args['title']                            = __('Step One: Select the Ticket for this registration',
2392
+					'event_espresso');
2393
+				$template_args['content']                          = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2394
+				$template_args['step_button_text']                 = __('Add Tickets and Continue to Registrant Details',
2395
+					'event_espresso');
2396
+				$template_args['show_notification_toggle']         = false;
2397
+				break;
2398
+			case 'questions' :
2399
+				$hidden_fields['processing_registration']['value'] = 2;
2400
+				$template_args['title']                            = __('Step Two: Add Registrant Details for this Registration',
2401
+					'event_espresso');
2402
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run.
2403
+				$template_args['content']                  = EED_Single_Page_Checkout::registration_checkout_for_admin();
2404
+				$template_args['step_button_text']         = __('Save Registration and Continue to Details',
2405
+					'event_espresso');
2406
+				$template_args['show_notification_toggle'] = true;
2407
+				break;
2408
+		}
2409
+		$this->_set_add_edit_form_tags('process_reg_step',
2410
+			$hidden_fields); //we come back to the process_registration_step route.
2411
+		return EEH_Template::display_template(REG_TEMPLATE_PATH
2412
+											  . 'reg_admin_register_new_attendee_step_content.template.php',
2413
+			$template_args, true);
2414
+	}
2415
+
2416
+
2417
+	/**
2418
+	 *        set_reg_event
2419
+	 *
2420
+	 * @access private
2421
+	 * @return boolean
2422
+	 */
2423
+	private function _set_reg_event()
2424
+	{
2425
+		if (is_object($this->_reg_event)) {
2426
+			return true;
2427
+		}
2428
+		$EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2429
+		if ( ! $EVT_ID) {
2430
+			return false;
2431
+		}
2432
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2433
+		return true;
2434
+	}
2435
+
2436
+
2437
+	/**
2438
+	 * process_reg_step
2439
+	 *
2440
+	 * @access        public
2441
+	 * @return        string
2442
+	 * @throws \RuntimeException
2443
+	 * @throws \EE_Error
2444
+	 */
2445
+	public function process_reg_step()
2446
+	{
2447
+		EE_System::do_not_cache();
2448
+		$this->_set_reg_event();
2449
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2450
+		EE_Registry::instance()->REQ->set('uts', time());
2451
+		//what step are we on?
2452
+		$cart = EE_Registry::instance()->SSN->cart();
2453
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2454
+		//if doing ajax then we need to verify the nonce
2455
+		if (defined('DOING_AJAX')) {
2456
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2457
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2458
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2459
+		}
2460
+		switch ($step) {
2461
+			case 'ticket' :
2462
+				//process ticket selection
2463
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2464
+				if ($success) {
2465
+					EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.',
2466
+						'event_espresso'));
2467
+				} else {
2468
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2469
+				}
2470
+				if (defined('DOING_AJAX')) {
2471
+					$this->new_registration(); //display next step
2472
+				} else {
2473
+					$query_args = array(
2474
+						'action'                  => 'new_registration',
2475
+						'processing_registration' => 1,
2476
+						'event_id'                => $this->_reg_event->ID(),
2477
+						'uts'                     => time(),
2478
+					);
2479
+					$this->_redirect_after_action(false, '', '', $query_args, true);
2480
+				}
2481
+				break;
2482
+			case 'questions' :
2483
+				if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) {
2484
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2485
+				}
2486
+				//process registration
2487
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2488
+				if ($cart instanceof EE_Cart) {
2489
+					$grand_total = $cart->get_cart_grand_total();
2490
+					if ($grand_total instanceof EE_Line_Item) {
2491
+						$grand_total->save_this_and_descendants_to_txn();
2492
+					}
2493
+				}
2494
+				if ( ! $transaction instanceof EE_Transaction) {
2495
+					$query_args = array(
2496
+						'action'                  => 'new_registration',
2497
+						'processing_registration' => 2,
2498
+						'event_id'                => $this->_reg_event->ID(),
2499
+						'uts'                     => time(),
2500
+					);
2501
+					if (defined('DOING_AJAX')) {
2502
+						//display registration form again because there are errors (maybe validation?)
2503
+						$this->new_registration();
2504
+						return;
2505
+					} else {
2506
+						$this->_redirect_after_action(false, '', '', $query_args, true);
2507
+						return;
2508
+					}
2509
+				}
2510
+				// maybe update status, and make sure to save transaction if not done already
2511
+				if ( ! $transaction->update_status_based_on_total_paid()) {
2512
+					$transaction->save();
2513
+				}
2514
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2515
+				$this->_req_data = array();
2516
+				$query_args      = array(
2517
+					'action'        => 'redirect_to_txn',
2518
+					'TXN_ID'        => $transaction->ID(),
2519
+					'EVT_ID'        => $this->_reg_event->ID(),
2520
+					'event_name'    => urlencode($this->_reg_event->name()),
2521
+					'redirect_from' => 'new_registration',
2522
+				);
2523
+				$this->_redirect_after_action(false, '', '', $query_args, true);
2524
+				break;
2525
+		}
2526
+		//what are you looking here for?  Should be nothing to do at this point.
2527
+	}
2528
+
2529
+
2530
+	/**
2531
+	 * redirect_to_txn
2532
+	 *
2533
+	 * @access public
2534
+	 * @return void
2535
+	 */
2536
+	public function redirect_to_txn()
2537
+	{
2538
+		EE_System::do_not_cache();
2539
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2540
+		$query_args = array(
2541
+			'action' => 'view_transaction',
2542
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2543
+			'page'   => 'espresso_transactions',
2544
+		);
2545
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2546
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2547
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
2548
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
2549
+		}
2550
+		EE_Error::add_success(__('Registration Created.  Please review the transaction and add any payments as necessary',
2551
+			'event_espresso'));
2552
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2553
+	}
2554
+
2555
+
2556
+	/**
2557
+	 *        generates HTML for the Attendee Contact List
2558
+	 *
2559
+	 * @access protected
2560
+	 * @return void
2561
+	 */
2562
+	protected function _attendee_contact_list_table()
2563
+	{
2564
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2565
+		$this->_search_btn_label = __('Contacts', 'event_espresso');
2566
+		$this->display_admin_list_table_page_with_no_sidebar();
2567
+	}
2568
+
2569
+
2570
+	/**
2571
+	 *        get_attendees
2572
+	 *
2573
+	 * @param bool $count whether to return count or data.
2574
+	 * @access public
2575
+	 * @return array
2576
+	 */
2577
+	public function get_attendees($per_page, $count = false, $trash = false)
2578
+	{
2579
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2580
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2581
+		$ATT_MDL                    = EEM_Attendee::instance();
2582
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2583
+		switch ($this->_req_data['orderby']) {
2584
+			case 'ATT_ID':
2585
+				$orderby = 'ATT_ID';
2586
+				break;
2587
+			case 'ATT_fname':
2588
+				$orderby = 'ATT_fname';
2589
+				break;
2590
+			case 'ATT_email':
2591
+				$orderby = 'ATT_email';
2592
+				break;
2593
+			case 'ATT_city':
2594
+				$orderby = 'ATT_city';
2595
+				break;
2596
+			case 'STA_ID':
2597
+				$orderby = 'STA_ID';
2598
+				break;
2599
+			case 'CNT_ID':
2600
+				$orderby = 'CNT_ID';
2601
+				break;
2602
+			default:
2603
+				$orderby = 'ATT_lname';
2604
+		}
2605
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
2606
+			: 'ASC';
2607
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2608
+			? $this->_req_data['paged'] : 1;
2609
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2610
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2611
+			? $this->_req_data['perpage'] : $per_page;
2612
+		$_where       = array();
2613
+		if ( ! empty($this->_req_data['s'])) {
2614
+			$sstr         = '%' . $this->_req_data['s'] . '%';
2615
+			$_where['OR'] = array(
2616
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2617
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
2618
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
2619
+				'ATT_fname'                         => array('LIKE', $sstr),
2620
+				'ATT_lname'                         => array('LIKE', $sstr),
2621
+				'ATT_short_bio'                     => array('LIKE', $sstr),
2622
+				'ATT_email'                         => array('LIKE', $sstr),
2623
+				'ATT_address'                       => array('LIKE', $sstr),
2624
+				'ATT_address2'                      => array('LIKE', $sstr),
2625
+				'ATT_city'                          => array('LIKE', $sstr),
2626
+				'Country.CNT_name'                  => array('LIKE', $sstr),
2627
+				'State.STA_name'                    => array('LIKE', $sstr),
2628
+				'ATT_phone'                         => array('LIKE', $sstr),
2629
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
2630
+				'Registration.REG_code'             => array('LIKE', $sstr),
2631
+				'Registration.REG_count'            => array('LIKE', $sstr),
2632
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
2633
+			);
2634
+		}
2635
+		$offset = ($current_page - 1) * $per_page;
2636
+		$limit  = $count ? null : array($offset, $per_page);
2637
+		if ($trash) {
2638
+			$_where['status'] = array('!=', 'publish');
2639
+			$all_attendees    = $count
2640
+				? $ATT_MDL->count(array(
2641
+					$_where,
2642
+					'order_by' => array($orderby => $sort),
2643
+					'limit'    => $limit,
2644
+				), 'ATT_ID', true)
2645
+				: $ATT_MDL->get_all(array(
2646
+					$_where,
2647
+					'order_by' => array($orderby => $sort),
2648
+					'limit'    => $limit,
2649
+				));
2650
+		} else {
2651
+			$_where['status'] = array('IN', array('publish'));
2652
+			$all_attendees    = $count
2653
+				? $ATT_MDL->count(array(
2654
+					$_where,
2655
+					'order_by' => array($orderby => $sort),
2656
+					'limit'    => $limit,
2657
+				), 'ATT_ID', true)
2658
+				: $ATT_MDL->get_all(array(
2659
+					$_where,
2660
+					'order_by' => array($orderby => $sort),
2661
+					'limit'    => $limit,
2662
+				));
2663
+		}
2664
+		return $all_attendees;
2665
+	}
2666
+
2667
+
2668
+	/**
2669
+	 * This is just taking care of resending the registration confirmation
2670
+	 *
2671
+	 * @access protected
2672
+	 * @return void
2673
+	 */
2674
+	protected function _resend_registration()
2675
+	{
2676
+		$this->_process_resend_registration();
2677
+		$query_args = isset($this->_req_data['redirect_to'])
2678
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
2679
+			: array(
2680
+				'action' => 'default',
2681
+			);
2682
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2683
+	}
2684
+
2685
+	/**
2686
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
2687
+	 * to use when selecting registrations
2688
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
2689
+	 *                                                     the query parameters from the request
2690
+	 * @return void ends the request with a redirect or download
2691
+	 */
2692
+	public function _registrations_report_base( $method_name_for_getting_query_params )
2693
+	{
2694
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2695
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2696
+				'page'        => 'espresso_batch',
2697
+				'batch'       => 'file',
2698
+				'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2699
+				'filters'     => urlencode(
2700
+					serialize(
2701
+						call_user_func(
2702
+							array( $this, $method_name_for_getting_query_params ),
2703
+							EEH_Array::is_set(
2704
+								$this->_req_data,
2705
+								'filters',
2706
+								array()
2707
+							)
2708
+						)
2709
+					)
2710
+				),
2711
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
2712
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
2713
+				'return_url'  => urlencode($this->_req_data['return_url']),
2714
+			)));
2715
+		} else {
2716
+			$new_request_args = array(
2717
+				'export' => 'report',
2718
+				'action' => 'registrations_report_for_event',
2719
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2720
+			);
2721
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
2722
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2723
+				require_once(EE_CLASSES . 'EE_Export.class.php');
2724
+				$EE_Export = EE_Export::instance($this->_req_data);
2725
+				$EE_Export->export();
2726
+			}
2727
+		}
2728
+	}
2729
+
2730
+
2731
+
2732
+	/**
2733
+	 * Creates a registration report using only query parameters in the request
2734
+	 * @return void
2735
+	 */
2736
+	public function _registrations_report()
2737
+	{
2738
+		$this->_registrations_report_base( '_get_registration_query_parameters' );
2739
+	}
2740
+
2741
+
2742
+	public function _contact_list_export()
2743
+	{
2744
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2745
+			require_once(EE_CLASSES . 'EE_Export.class.php');
2746
+			$EE_Export = EE_Export::instance($this->_req_data);
2747
+			$EE_Export->export_attendees();
2748
+		}
2749
+	}
2750
+
2751
+
2752
+	public function _contact_list_report()
2753
+	{
2754
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2755
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2756
+				'page'        => 'espresso_batch',
2757
+				'batch'       => 'file',
2758
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
2759
+				'return_url'  => urlencode($this->_req_data['return_url']),
2760
+			)));
2761
+		} else {
2762
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2763
+				require_once(EE_CLASSES . 'EE_Export.class.php');
2764
+				$EE_Export = EE_Export::instance($this->_req_data);
2765
+				$EE_Export->report_attendees();
2766
+			}
2767
+		}
2768
+	}
2769
+
2770
+
2771
+
2772
+
2773
+
2774
+	/***************************************        ATTENDEE DETAILS        ***************************************/
2775
+	/**
2776
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
2777
+	 *
2778
+	 * @return void
2779
+	 */
2780
+	protected function _duplicate_attendee()
2781
+	{
2782
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
2783
+		//verify we have necessary info
2784
+		if (empty($this->_req_data['_REG_ID'])) {
2785
+			EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
2786
+				'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
2787
+			$query_args = array('action' => $action);
2788
+			$this->_redirect_after_action('', '', '', $query_args, true);
2789
+		}
2790
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
2791
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
2792
+		$attendee     = $registration->attendee();
2793
+		//remove relation of existing attendee on registration
2794
+		$registration->_remove_relation_to($attendee, 'Attendee');
2795
+		//new attendee
2796
+		$new_attendee = clone $attendee;
2797
+		$new_attendee->set('ATT_ID', 0);
2798
+		$new_attendee->save();
2799
+		//add new attendee to reg
2800
+		$registration->_add_relation_to($new_attendee, 'Attendee');
2801
+		EE_Error::add_success(__('New Contact record created.  Now make any edits you wish to make for this contact.',
2802
+			'event_espresso'));
2803
+		//redirect to edit page for attendee
2804
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
2805
+		$this->_redirect_after_action('', '', '', $query_args, true);
2806
+	}
2807
+
2808
+
2809
+	//related to cpt routes
2810
+	protected function _insert_update_cpt_item($post_id, $post)
2811
+	{
2812
+		$success  = true;
2813
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
2814
+		//for attendee updates
2815
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
2816
+			//note we should only be UPDATING attendees at this point.
2817
+			$updated_fields = array(
2818
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
2819
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
2820
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2821
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2822
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2823
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
2824
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
2825
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
2826
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
2827
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
2828
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
2829
+			);
2830
+			foreach ($updated_fields as $field => $value) {
2831
+				$attendee->set($field, $value);
2832
+			}
2833
+			$success                   = $attendee->save();
2834
+			$attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
2835
+				array());
2836
+			foreach ($attendee_update_callbacks as $a_callback) {
2837
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
2838
+					throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
2839
+						'event_espresso'), $a_callback));
2840
+				}
2841
+			}
2842
+		}
2843
+		if ($success === false) {
2844
+			EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.',
2845
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2846
+		}
2847
+	}
2848
+
2849
+
2850
+	public function trash_cpt_item($post_id)
2851
+	{
2852
+	}
2853
+
2854
+
2855
+	public function delete_cpt_item($post_id)
2856
+	{
2857
+	}
2858
+
2859
+
2860
+	public function restore_cpt_item($post_id)
2861
+	{
2862
+	}
2863
+
2864
+
2865
+	protected function _restore_cpt_item($post_id, $revision_id)
2866
+	{
2867
+	}
2868
+
2869
+
2870
+	public function attendee_editor_metaboxes()
2871
+	{
2872
+		$this->verify_cpt_object();
2873
+		remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action],
2874
+			'normal', 'core');
2875
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2876
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
2877
+			add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box',
2878
+				$this->_cpt_routes[$this->_req_action], 'normal');
2879
+		}
2880
+		if (post_type_supports('espresso_attendees', 'comments')) {
2881
+			add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box',
2882
+				$this->_cpt_routes[$this->_req_action], 'normal', 'core');
2883
+		}
2884
+		add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'),
2885
+			array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core');
2886
+		add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'),
2887
+			array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2888
+		add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'),
2889
+			array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high');
2890
+	}
2891
+
2892
+
2893
+	/**
2894
+	 * Metabox for attendee contact info
2895
+	 *
2896
+	 * @param  WP_Post $post wp post object
2897
+	 * @return string        attendee contact info ( and form )
2898
+	 */
2899
+	public function attendee_contact_info($post)
2900
+	{
2901
+		//get attendee object ( should already have it )
2902
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
2903
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2904
+		EEH_Template::display_template($template, $this->_template_args);
2905
+	}
2906
+
2907
+
2908
+	/**
2909
+	 * Metabox for attendee details
2910
+	 *
2911
+	 * @param  WP_Post $post wp post object
2912
+	 * @return string        attendee address details (and form)
2913
+	 */
2914
+	public function attendee_address_details($post)
2915
+	{
2916
+		//get attendee object (should already have it)
2917
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
2918
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2919
+			'QST_ID'           => 0,
2920
+			'QST_display_text' => __('State/Province', 'event_espresso'),
2921
+			'QST_system'       => 'admin-state',
2922
+		)), EE_Answer::new_instance(array(
2923
+			'ANS_ID'    => 0,
2924
+			'ANS_value' => $this->_cpt_model_obj->state_ID(),
2925
+		)), array(
2926
+			'input_id'       => 'STA_ID',
2927
+			'input_name'     => 'STA_ID',
2928
+			'input_prefix'   => '',
2929
+			'append_qstn_id' => false,
2930
+		)));
2931
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2932
+			'QST_ID'           => 0,
2933
+			'QST_display_text' => __('Country', 'event_espresso'),
2934
+			'QST_system'       => 'admin-country',
2935
+		)), EE_Answer::new_instance(array(
2936
+			'ANS_ID'    => 0,
2937
+			'ANS_value' => $this->_cpt_model_obj->country_ID(),
2938
+		)), array(
2939
+			'input_id'       => 'CNT_ISO',
2940
+			'input_name'     => 'CNT_ISO',
2941
+			'input_prefix'   => '',
2942
+			'append_qstn_id' => false,
2943
+		)));
2944
+		$template                             = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2945
+		EEH_Template::display_template($template, $this->_template_args);
2946
+	}
2947
+
2948
+
2949
+	/**
2950
+	 *        _attendee_details
2951
+	 *
2952
+	 * @access protected
2953
+	 * @return void
2954
+	 */
2955
+	public function attendee_registrations_meta_box($post)
2956
+	{
2957
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
2958
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2959
+		$template                              = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2960
+		EEH_Template::display_template($template, $this->_template_args);
2961
+	}
2962
+
2963
+
2964
+	/**
2965
+	 * add in the form fields for the attendee edit
2966
+	 *
2967
+	 * @param  WP_Post $post wp post object
2968
+	 * @return string        html for new form.
2969
+	 */
2970
+	public function after_title_form_fields($post)
2971
+	{
2972
+		if ($post->post_type == 'espresso_attendees') {
2973
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2974
+			$template_args['attendee'] = $this->_cpt_model_obj;
2975
+			EEH_Template::display_template($template, $template_args);
2976
+		}
2977
+	}
2978
+
2979
+
2980
+	/**
2981
+	 *        _trash_or_restore_attendee
2982
+	 *
2983
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
2984
+	 * @access protected
2985
+	 * @return void
2986
+	 */
2987
+	protected function _trash_or_restore_attendees($trash = true)
2988
+	{
2989
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2990
+		$ATT_MDL = EEM_Attendee::instance();
2991
+		$success = 1;
2992
+		//Checkboxes
2993
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2994
+			// if array has more than one element than success message should be plural
2995
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2996
+			// cycle thru checkboxes
2997
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
2998
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
2999
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3000
+				if ( ! $updated) {
3001
+					$success = 0;
3002
+				}
3003
+			}
3004
+		} else {
3005
+			// grab single id and delete
3006
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3007
+			//get attendee
3008
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3009
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3010
+			$updated = $att->save();
3011
+			if ( ! $updated) {
3012
+				$success = 0;
3013
+			}
3014
+		}
3015
+		$what        = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso');
3016
+		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
3017
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3018
+	}
3019 3019
 
3020 3020
 }
3021 3021
 
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -569,11 +569,11 @@  discard block
 block discarded – undo
569 569
     {
570 570
         //style
571 571
         //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
572
-        wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'),
572
+        wp_register_style('espresso_reg', REG_ASSETS_URL.'espresso_registrations_admin.css', array('ee-admin-css'),
573 573
             EVENT_ESPRESSO_VERSION);
574 574
         wp_enqueue_style('espresso_reg');
575 575
         //script
576
-        wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js',
576
+        wp_register_script('espresso_reg', REG_ASSETS_URL.'espresso_registrations_admin.js',
577 577
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true);
578 578
         wp_enqueue_script('espresso_reg');
579 579
     }
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
     public function load_scripts_styles_contact_list()
605 605
     {
606 606
         wp_deregister_style('espresso_reg');
607
-        wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'),
607
+        wp_register_style('espresso_att', REG_ASSETS_URL.'espresso_attendees_admin.css', array('ee-admin-css'),
608 608
             EVENT_ESPRESSO_VERSION);
609 609
         wp_enqueue_style('espresso_att');
610 610
     }
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 
613 613
     public function load_scripts_styles_new_registration()
614 614
     {
615
-        wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'),
615
+        wp_register_script('ee-spco-for-admin', REG_ASSETS_URL.'spco_for_admin.js', array('underscore', 'jquery'),
616 616
             EVENT_ESPRESSO_VERSION, true);
617 617
         wp_enqueue_script('ee-spco-for-admin');
618 618
         add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
                     'trash_registrations' => __('Trash Registrations', 'event_espresso'),
723 723
                 ),
724 724
             );
725
-            $this->_views['trash']      = array(
725
+            $this->_views['trash'] = array(
726 726
                 'slug'        => 'trash',
727 727
                 'label'       => __('Trash', 'event_espresso'),
728 728
                 'count'       => 0,
@@ -807,31 +807,31 @@  discard block
 block discarded – undo
807 807
         }
808 808
         $sc_items = array(
809 809
             'approved_status'   => array(
810
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
810
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
811 811
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
812 812
             ),
813 813
             'pending_status'    => array(
814
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
814
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
815 815
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
816 816
             ),
817 817
             'wait_list'         => array(
818
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
818
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
819 819
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
820 820
             ),
821 821
             'incomplete_status' => array(
822
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
822
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
823 823
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'),
824 824
             ),
825 825
             'not_approved'      => array(
826
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
826
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
827 827
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
828 828
             ),
829 829
             'declined_status'   => array(
830
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
830
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
831 831
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
832 832
             ),
833 833
             'cancelled_status'  => array(
834
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
834
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
835 835
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
836 836
             ),
837 837
         );
@@ -852,17 +852,17 @@  discard block
 block discarded – undo
852 852
             if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations',
853 853
                 'espresso_registrations_new_registration', $EVT_ID)
854 854
             ) {
855
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant',
855
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button('new_registration', 'add-registrant',
856 856
                         array('event_id' => $EVT_ID), 'add-new-h2');
857 857
             }
858 858
             $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
859 859
             if ($event instanceof EE_Event) {
860 860
                 $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s',
861 861
                     'event_espresso'), '<h3 style="line-height:1.5em;">',
862
-                    '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array(
862
+                    '<br /><a href="'.EE_Admin_Page::add_query_args_and_nonce(array(
863 863
                         'action' => 'edit',
864 864
                         'post'   => $event->ID(),
865
-                    ), EVENTS_ADMIN_URL) . '">&nbsp;' . $event->get('EVT_name') . '&nbsp;</a>&nbsp;', '</h3>');
865
+                    ), EVENTS_ADMIN_URL).'">&nbsp;'.$event->get('EVT_name').'&nbsp;</a>&nbsp;', '</h3>');
866 866
             }
867 867
             $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
868 868
             $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
872 872
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
873 873
                 $this->_template_args['admin_page_header'] .= $datetime->name();
874
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
874
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
875 875
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
876 876
             }
877 877
         }
@@ -921,10 +921,10 @@  discard block
 block discarded – undo
921 921
         $this_month = false,
922 922
         $today = false
923 923
     ) {
924
-        if( $this_month ) {
924
+        if ($this_month) {
925 925
             $this->_req_data['status'] = 'month';
926 926
         }
927
-        if( $today ) {
927
+        if ($today) {
928 928
             $this->_req_data['status'] = 'today';
929 929
         }
930 930
         $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
@@ -1002,7 +1002,7 @@  discard block
 block discarded – undo
1002 1002
     protected function _add_category_id_to_where_conditions(array $request)
1003 1003
     {
1004 1004
         $where = array();
1005
-        if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1005
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1006 1006
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1007 1007
         }
1008 1008
         return $where;
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
         if ( ! empty($request['datetime_id'])) {
1022 1022
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1023 1023
         }
1024
-        if( ! empty($request['DTT_ID'])){
1024
+        if ( ! empty($request['DTT_ID'])) {
1025 1025
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1026 1026
         }
1027 1027
         return $where;
@@ -1037,7 +1037,7 @@  discard block
 block discarded – undo
1037 1037
     protected function _add_registration_status_to_where_conditions(array $request)
1038 1038
     {
1039 1039
         $where = array();
1040
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1040
+        $view  = EEH_Array::is_set($request, 'status', '');
1041 1041
         $registration_status = ! empty($request['_reg_status'])
1042 1042
             ? sanitize_text_field($request['_reg_status'])
1043 1043
             : '';
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
     protected function _add_date_to_where_conditions(array $request)
1073 1073
     {
1074 1074
         $where = array();
1075
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1075
+        $view  = EEH_Array::is_set($request, 'status', '');
1076 1076
         $month_range             = ! empty($request['month_range'])
1077 1077
             ? sanitize_text_field($request['month_range'])
1078 1078
             : '';
@@ -1086,12 +1086,12 @@  discard block
 block discarded – undo
1086 1086
                 array(
1087 1087
                     EEM_Registration::instance()->convert_datetime_for_query(
1088 1088
                         'REG_date',
1089
-                        $now . ' 00:00:00',
1089
+                        $now.' 00:00:00',
1090 1090
                         'Y-m-d H:i:s'
1091 1091
                     ),
1092 1092
                     EEM_Registration::instance()->convert_datetime_for_query(
1093 1093
                         'REG_date',
1094
-                        $now . ' 23:59:59',
1094
+                        $now.' 23:59:59',
1095 1095
                         'Y-m-d H:i:s'
1096 1096
                     ),
1097 1097
                 ),
@@ -1104,12 +1104,12 @@  discard block
 block discarded – undo
1104 1104
                 array(
1105 1105
                     EEM_Registration::instance()->convert_datetime_for_query(
1106 1106
                         'REG_date',
1107
-                        $current_year_and_month . '-01 00:00:00',
1107
+                        $current_year_and_month.'-01 00:00:00',
1108 1108
                         'Y-m-d H:i:s'
1109 1109
                     ),
1110 1110
                     EEM_Registration::instance()->convert_datetime_for_query(
1111 1111
                         'REG_date',
1112
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1112
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1113 1113
                         'Y-m-d H:i:s'
1114 1114
                     ),
1115 1115
                 ),
@@ -1124,18 +1124,18 @@  discard block
 block discarded – undo
1124 1124
                 : '';
1125 1125
             //if there is not a month or year then we can't go further
1126 1126
             if ($month_requested && $year_requested) {
1127
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1127
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1128 1128
                 $where['REG_date'] = array(
1129 1129
                     'BETWEEN',
1130 1130
                     array(
1131 1131
                         EEM_Registration::instance()->convert_datetime_for_query(
1132 1132
                             'REG_date',
1133
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1133
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1134 1134
                             'Y-m-d H:i:s'
1135 1135
                         ),
1136 1136
                         EEM_Registration::instance()->convert_datetime_for_query(
1137 1137
                             'REG_date',
1138
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1138
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1139 1139
                             'Y-m-d H:i:s'
1140 1140
                         ),
1141 1141
                     ),
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
     {
1157 1157
         $where = array();
1158 1158
         if ( ! empty($request['s'])) {
1159
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1159
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1160 1160
             $where['OR'] = array(
1161 1161
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1162 1162
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
             : $per_page;
1265 1265
 
1266 1266
         //-1 means return all results so get out if that's set.
1267
-        if ((int)$per_page === -1) {
1267
+        if ((int) $per_page === -1) {
1268 1268
             return array();
1269 1269
         }
1270 1270
         $per_page = absint($per_page);
@@ -1310,12 +1310,12 @@  discard block
 block discarded – undo
1310 1310
                 'action'   => 'default',
1311 1311
                 'event_id' => $event_id,
1312 1312
             ), REG_ADMIN_URL);
1313
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
1313
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1314 1314
                 'action' => 'default',
1315 1315
                 'EVT_ID' => $event_id,
1316 1316
                 'page'   => 'espresso_transactions',
1317 1317
             ), admin_url('admin.php'));
1318
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(array(
1318
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1319 1319
                 'page'   => 'espresso_events',
1320 1320
                 'action' => 'edit',
1321 1321
                 'post'   => $event_id,
@@ -1334,7 +1334,7 @@  discard block
 block discarded – undo
1334 1334
                     '_REG_ID' => $previous_reg['REG_ID'],
1335 1335
                 ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
1336 1336
             // grab header
1337
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1337
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1338 1338
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1339 1339
             $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
1340 1340
                 $this->_template_args, true);
@@ -1408,8 +1408,8 @@  discard block
 block discarded – undo
1408 1408
                     'default' => $this->_registration->ID(),
1409 1409
                 )),
1410 1410
                 'current_status'     => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status',
1411
-                        'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1412
-                        '', 'status-' . $this->_registration->status_ID(),
1411
+                        'event_espresso')))).EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1412
+                        '', 'status-'.$this->_registration->status_ID(),
1413 1413
                         'line-height: 1em; font-size: 1.5em; font-weight: bold;')))),
1414 1414
                 'reg_status'         => new EE_Select_Input($this->_get_reg_statuses(), array(
1415 1415
                     'html_label_text' => __('Change Registration Status to', 'event_espresso'),
@@ -1465,9 +1465,9 @@  discard block
 block discarded – undo
1465 1465
     {
1466 1466
         if (isset($this->_req_data['reg_status_change_form'])) {
1467 1467
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1468
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1468
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] : array();
1469 1469
         } else {
1470
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1470
+            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array) $this->_req_data['_REG_ID'] : array();
1471 1471
         }
1472 1472
         $success = $this->_set_registration_status($REG_IDs, $status);
1473 1473
         //notify?
@@ -1495,7 +1495,7 @@  discard block
 block discarded – undo
1495 1495
     {
1496 1496
         $success = false;
1497 1497
         // typecast $REG_IDs
1498
-        $REG_IDs = (array)$REG_IDs;
1498
+        $REG_IDs = (array) $REG_IDs;
1499 1499
         if ( ! empty($REG_IDs)) {
1500 1500
             $success = true;
1501 1501
             // set default status if none is passed
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
         ), REG_ADMIN_URL);
1789 1789
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
1790 1790
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
1791
-        $template_path                                                        = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1791
+        $template_path                                                        = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
1792 1792
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1793 1793
     }
1794 1794
 
@@ -1810,7 +1810,7 @@  discard block
 block discarded – undo
1810 1810
             $this->_template_args['att_questions']             = count($form->subforms()) > 0 ? $form->get_html_and_js() : '';
1811 1811
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
1812 1812
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
1813
-            $template_path                                     = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1813
+            $template_path                                     = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
1814 1814
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
1815 1815
         }
1816 1816
     }
@@ -1826,7 +1826,7 @@  discard block
 block discarded – undo
1826 1826
      */
1827 1827
     public function form_before_question_group($output)
1828 1828
     {
1829
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1829
+        EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__,
1830 1830
             __('This method would have been protected but was used on a filter callback'
1831 1831
                . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1832 1832
             '4.8.32.rc.000');
@@ -1847,7 +1847,7 @@  discard block
 block discarded – undo
1847 1847
      */
1848 1848
     public function form_after_question_group($output)
1849 1849
     {
1850
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1850
+        EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__,
1851 1851
             __('This method would have been protected but was used on a filter callback'
1852 1852
                . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1853 1853
             '4.8.32.rc.000');
@@ -1881,14 +1881,14 @@  discard block
 block discarded – undo
1881 1881
      */
1882 1882
     public function form_form_field_label_wrap($label)
1883 1883
     {
1884
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1884
+        EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__,
1885 1885
             __('This method would have been protected but was used on a filter callback'
1886 1886
                . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1887 1887
             '4.8.32.rc.000');
1888 1888
         return '
1889 1889
 			<tr>
1890 1890
 				<th>
1891
-					' . $label . '
1891
+					' . $label.'
1892 1892
 				</th>';
1893 1893
     }
1894 1894
 
@@ -1903,13 +1903,13 @@  discard block
 block discarded – undo
1903 1903
      */
1904 1904
     public function form_form_field_input__wrap($input)
1905 1905
     {
1906
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1906
+        EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__,
1907 1907
             __('This method would have been protected but was used on a filter callback'
1908 1908
                . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1909 1909
             '4.8.32.rc.000');
1910 1910
         return '
1911 1911
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
1912
-					' . $input . '
1912
+					' . $input.'
1913 1913
 				</td>
1914 1914
 			</tr>';
1915 1915
     }
@@ -1949,7 +1949,7 @@  discard block
 block discarded – undo
1949 1949
     protected function _get_reg_custom_questions_form($REG_ID)
1950 1950
     {
1951 1951
         if ( ! $this->_reg_custom_questions_form) {
1952
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
1952
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
1953 1953
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
1954 1954
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
1955 1955
             );
@@ -1978,7 +1978,7 @@  discard block
 block discarded – undo
1978 1978
         if ($form->is_valid()) {
1979 1979
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
1980 1980
                 foreach ($question_group_form->inputs() as $question_id => $input) {
1981
-                    $where_conditions    = array(
1981
+                    $where_conditions = array(
1982 1982
                         'QST_ID' => $question_id,
1983 1983
                         'REG_ID' => $REG_ID,
1984 1984
                     );
@@ -2014,7 +2014,7 @@  discard block
 block discarded – undo
2014 2014
         $REG = EEM_Registration::instance();
2015 2015
         //get all other registrations on this transaction, and cache
2016 2016
         //the attendees for them so we don't have to run another query using force_join
2017
-        $registrations                           = $REG->get_all(array(
2017
+        $registrations = $REG->get_all(array(
2018 2018
             array(
2019 2019
                 'TXN_ID' => $this->_registration->transaction_ID(),
2020 2020
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2034,29 +2034,29 @@  discard block
 block discarded – undo
2034 2034
             $att_nmbr = 1;
2035 2035
             foreach ($registrations as $registration) {
2036 2036
                 /* @var $registration EE_Registration */
2037
-                $attendee                                                    = $registration->attendee()
2037
+                $attendee = $registration->attendee()
2038 2038
                     ? $registration->attendee()
2039 2039
                     : EEM_Attendee::instance()
2040 2040
                                   ->create_default_object();
2041 2041
                 $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2042
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2043
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2044
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2045
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2042
+                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname(); //( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2043
+                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname(); //( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2044
+                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email(); //( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2045
+                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price(); //( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2046 2046
                 $this->_template_args['attendees'][$att_nmbr]['address']     = implode(', ',
2047 2047
                     $attendee->full_address_as_array());
2048 2048
                 $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(array(
2049 2049
                     'action' => 'edit_attendee',
2050 2050
                     'post'   => $attendee->ID(),
2051 2051
                 ), REG_ADMIN_URL);
2052
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2052
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2053 2053
                 $att_nmbr++;
2054 2054
             }
2055 2055
             //EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
2056 2056
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2057 2057
             //			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
2058 2058
         }
2059
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2059
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2060 2060
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2061 2061
     }
2062 2062
 
@@ -2085,26 +2085,26 @@  discard block
 block discarded – undo
2085 2085
             $primary_registration = null;
2086 2086
         }
2087 2087
         $this->_template_args['ATT_ID']            = $attendee->ID();
2088
-        $this->_template_args['fname']             = $attendee->fname();//$this->_registration->ATT_fname;
2089
-        $this->_template_args['lname']             = $attendee->lname();//$this->_registration->ATT_lname;
2090
-        $this->_template_args['email']             = $attendee->email();//$this->_registration->ATT_email;
2088
+        $this->_template_args['fname']             = $attendee->fname(); //$this->_registration->ATT_fname;
2089
+        $this->_template_args['lname']             = $attendee->lname(); //$this->_registration->ATT_lname;
2090
+        $this->_template_args['email']             = $attendee->email(); //$this->_registration->ATT_email;
2091 2091
         $this->_template_args['phone']             = $attendee->phone();
2092 2092
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2093 2093
         //edit link
2094
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2094
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2095 2095
             'action' => 'edit_attendee',
2096 2096
             'post'   => $attendee->ID(),
2097 2097
         ), REG_ADMIN_URL);
2098 2098
         $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso');
2099 2099
         //create link
2100
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2100
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2101 2101
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2102 2102
                 'action'  => 'duplicate_attendee',
2103 2103
                 '_REG_ID' => $this->_registration->ID(),
2104 2104
             ), REG_ADMIN_URL) : '';
2105 2105
         $this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
2106 2106
         $this->_template_args['att_check']    = $att_check;
2107
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2107
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2108 2108
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2109 2109
     }
2110 2110
 
@@ -2146,7 +2146,7 @@  discard block
 block discarded – undo
2146 2146
             /** @var EE_Registration $REG */
2147 2147
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2148 2148
             $payments = $REG->registration_payments();
2149
-            if (! empty($payments)) {
2149
+            if ( ! empty($payments)) {
2150 2150
                 $name = $REG->attendee() instanceof EE_Attendee
2151 2151
                     ? $REG->attendee()->full_name()
2152 2152
                     : __('Unknown Attendee', 'event_espresso');
@@ -2313,7 +2313,7 @@  discard block
 block discarded – undo
2313 2313
                 'action' => 'edit',
2314 2314
                 'post'   => $this->_reg_event->ID(),
2315 2315
             ), EVENTS_ADMIN_URL);
2316
-            $edit_event_lnk                     = '<a href="'
2316
+            $edit_event_lnk = '<a href="'
2317 2317
                                                   . $edit_event_url
2318 2318
                                                   . '" title="'
2319 2319
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2330,7 +2330,7 @@  discard block
 block discarded – undo
2330 2330
             $this->_return_json();
2331 2331
         }
2332 2332
         // grab header
2333
-        $template_path                              = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2333
+        $template_path                              = REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2334 2334
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2335 2335
             $this->_template_args, true);
2336 2336
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2352,7 +2352,7 @@  discard block
 block discarded – undo
2352 2352
                 'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">',
2353 2353
                 '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>');
2354 2354
             return '
2355
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2355
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2356 2356
 	<script >
2357 2357
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2358 2358
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2577,7 +2577,7 @@  discard block
 block discarded – undo
2577 2577
     public function get_attendees($per_page, $count = false, $trash = false)
2578 2578
     {
2579 2579
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2580
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2580
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
2581 2581
         $ATT_MDL                    = EEM_Attendee::instance();
2582 2582
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2583 2583
         switch ($this->_req_data['orderby']) {
@@ -2611,7 +2611,7 @@  discard block
 block discarded – undo
2611 2611
             ? $this->_req_data['perpage'] : $per_page;
2612 2612
         $_where       = array();
2613 2613
         if ( ! empty($this->_req_data['s'])) {
2614
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2614
+            $sstr         = '%'.$this->_req_data['s'].'%';
2615 2615
             $_where['OR'] = array(
2616 2616
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2617 2617
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -2689,7 +2689,7 @@  discard block
 block discarded – undo
2689 2689
      *                                                     the query parameters from the request
2690 2690
      * @return void ends the request with a redirect or download
2691 2691
      */
2692
-    public function _registrations_report_base( $method_name_for_getting_query_params )
2692
+    public function _registrations_report_base($method_name_for_getting_query_params)
2693 2693
     {
2694 2694
         if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2695 2695
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
@@ -2699,7 +2699,7 @@  discard block
 block discarded – undo
2699 2699
                 'filters'     => urlencode(
2700 2700
                     serialize(
2701 2701
                         call_user_func(
2702
-                            array( $this, $method_name_for_getting_query_params ),
2702
+                            array($this, $method_name_for_getting_query_params),
2703 2703
                             EEH_Array::is_set(
2704 2704
                                 $this->_req_data,
2705 2705
                                 'filters',
@@ -2719,8 +2719,8 @@  discard block
 block discarded – undo
2719 2719
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2720 2720
             );
2721 2721
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
2722
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2723
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2722
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
2723
+                require_once(EE_CLASSES.'EE_Export.class.php');
2724 2724
                 $EE_Export = EE_Export::instance($this->_req_data);
2725 2725
                 $EE_Export->export();
2726 2726
             }
@@ -2735,14 +2735,14 @@  discard block
 block discarded – undo
2735 2735
      */
2736 2736
     public function _registrations_report()
2737 2737
     {
2738
-        $this->_registrations_report_base( '_get_registration_query_parameters' );
2738
+        $this->_registrations_report_base('_get_registration_query_parameters');
2739 2739
     }
2740 2740
 
2741 2741
 
2742 2742
     public function _contact_list_export()
2743 2743
     {
2744
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2745
-            require_once(EE_CLASSES . 'EE_Export.class.php');
2744
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
2745
+            require_once(EE_CLASSES.'EE_Export.class.php');
2746 2746
             $EE_Export = EE_Export::instance($this->_req_data);
2747 2747
             $EE_Export->export_attendees();
2748 2748
         }
@@ -2759,8 +2759,8 @@  discard block
 block discarded – undo
2759 2759
                 'return_url'  => urlencode($this->_req_data['return_url']),
2760 2760
             )));
2761 2761
         } else {
2762
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2763
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2762
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
2763
+                require_once(EE_CLASSES.'EE_Export.class.php');
2764 2764
                 $EE_Export = EE_Export::instance($this->_req_data);
2765 2765
                 $EE_Export->report_attendees();
2766 2766
             }
@@ -2817,7 +2817,7 @@  discard block
 block discarded – undo
2817 2817
             $updated_fields = array(
2818 2818
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
2819 2819
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
2820
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2820
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
2821 2821
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2822 2822
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2823 2823
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -2900,7 +2900,7 @@  discard block
 block discarded – undo
2900 2900
     {
2901 2901
         //get attendee object ( should already have it )
2902 2902
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
2903
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2903
+        $template                         = REG_TEMPLATE_PATH.'attendee_contact_info_metabox_content.template.php';
2904 2904
         EEH_Template::display_template($template, $this->_template_args);
2905 2905
     }
2906 2906
 
@@ -2941,7 +2941,7 @@  discard block
 block discarded – undo
2941 2941
             'input_prefix'   => '',
2942 2942
             'append_qstn_id' => false,
2943 2943
         )));
2944
-        $template                             = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2944
+        $template = REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
2945 2945
         EEH_Template::display_template($template, $this->_template_args);
2946 2946
     }
2947 2947
 
@@ -2956,7 +2956,7 @@  discard block
 block discarded – undo
2956 2956
     {
2957 2957
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
2958 2958
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2959
-        $template                              = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2959
+        $template                              = REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
2960 2960
         EEH_Template::display_template($template, $this->_template_args);
2961 2961
     }
2962 2962
 
@@ -2970,7 +2970,7 @@  discard block
 block discarded – undo
2970 2970
     public function after_title_form_fields($post)
2971 2971
     {
2972 2972
         if ($post->post_type == 'espresso_attendees') {
2973
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2973
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
2974 2974
             $template_args['attendee'] = $this->_cpt_model_obj;
2975 2975
             EEH_Template::display_template($template, $template_args);
2976 2976
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Attendee.model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -242,7 +242,7 @@
 block discarded – undo
242 242
      *
243 243
      * @access        public
244 244
      * @param        $ATT_ID
245
-     * @return        mixed        array on success, FALSE on fail
245
+     * @return        EE_Base_Class|null        array on success, FALSE on fail
246 246
      * @deprecated
247 247
      */
248 248
     public function get_attendee_by_ID($ATT_ID = false)
Please login to merge, or discard this patch.
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 require_once(EE_MODELS . 'EEM_Base.model.php');
5 5
 
@@ -15,329 +15,329 @@  discard block
 block discarded – undo
15 15
 class EEM_Attendee extends EEM_CPT_Base
16 16
 {
17 17
 
18
-    // private instance of the Attendee object
19
-    protected static $_instance = null;
18
+	// private instance of the Attendee object
19
+	protected static $_instance = null;
20 20
 
21
-    /**
22
-     * QST_system for questions are strings not ints now,
23
-     * so these constants are deprecated.
24
-     * Please instead use the EEM_Attendee::system_question_* constants
25
-     *
26
-     * @deprecated
27
-     */
28
-    const fname_question_id = 1;
21
+	/**
22
+	 * QST_system for questions are strings not ints now,
23
+	 * so these constants are deprecated.
24
+	 * Please instead use the EEM_Attendee::system_question_* constants
25
+	 *
26
+	 * @deprecated
27
+	 */
28
+	const fname_question_id = 1;
29 29
 
30
-    /**
31
-     * @deprecated
32
-     */
33
-    const lname_question_id = 2;
30
+	/**
31
+	 * @deprecated
32
+	 */
33
+	const lname_question_id = 2;
34 34
 
35 35
 
36
-    /**
37
-     * @deprecated
38
-     */
39
-    const email_question_id = 3;
36
+	/**
37
+	 * @deprecated
38
+	 */
39
+	const email_question_id = 3;
40 40
 
41 41
 
42
-    /**
43
-     * @deprecated
44
-     */
45
-    const address_question_id = 4;
42
+	/**
43
+	 * @deprecated
44
+	 */
45
+	const address_question_id = 4;
46 46
 
47 47
 
48
-    /**
49
-     * @deprecated
50
-     */
51
-    const address2_question_id = 5;
52
-
53
-
54
-    /**
55
-     * @deprecated
56
-     */
57
-    const city_question_id = 6;
58
-
59
-
60
-    /**
61
-     * @deprecated
62
-     */
63
-    const state_question_id = 7;
64
-
65
-
66
-    /**
67
-     * @deprecated
68
-     */
69
-    const country_question_id = 8;
70
-
71
-
72
-    /**
73
-     * @deprecated
74
-     */
75
-    const zip_question_id = 9;
76
-
77
-
78
-    /**
79
-     * @deprecated
80
-     */
81
-    const phone_question_id = 10;
82
-
83
-    /**
84
-     * When looking for questions that correspond to attendee fields,
85
-     * look for the question with this QST_system value.
86
-     * These replace the old constants like EEM_Attendee::*_question_id
87
-     */
88
-    const system_question_fname    = 'fname';
89
-
90
-    const system_question_lname    = 'lname';
91
-
92
-    const system_question_email    = 'email';
93
-
94
-    const system_question_address  = 'address';
95
-
96
-    const system_question_address2 = 'address2';
97
-
98
-    const system_question_city     = 'city';
99
-
100
-    const system_question_state    = 'state';
101
-
102
-    const system_question_country  = 'country';
103
-
104
-    const system_question_zip      = 'zip';
105
-
106
-    const system_question_phone    = 'phone';
107
-
108
-    /**
109
-     * Keys are all the EEM_Attendee::system_question_* constants, which are
110
-     * also all the values of QST_system in the questions table, and values
111
-     * are their corresponding Attendee field names
112
-     *
113
-     * @var array
114
-     */
115
-    protected $_system_question_to_attendee_field_name = array(
116
-        EEM_Attendee::system_question_fname    => 'ATT_fname',
117
-        EEM_Attendee::system_question_lname    => 'ATT_lname',
118
-        EEM_Attendee::system_question_email    => 'ATT_email',
119
-        EEM_Attendee::system_question_address  => 'ATT_address',
120
-        EEM_Attendee::system_question_address2 => 'ATT_address2',
121
-        EEM_Attendee::system_question_city     => 'ATT_city',
122
-        EEM_Attendee::system_question_state    => 'STA_ID',
123
-        EEM_Attendee::system_question_country  => 'CNT_ISO',
124
-        EEM_Attendee::system_question_zip      => 'ATT_zip',
125
-        EEM_Attendee::system_question_phone    => 'ATT_phone',
126
-    );
127
-
128
-
129
-
130
-    /**
131
-     *        private constructor to prevent direct creation
132
-     *
133
-     * @Constructor
134
-     * @access protected
135
-     * @param null $timezone
136
-     */
137
-    protected function __construct($timezone = null)
138
-    {
139
-        $this->singular_item = __('Attendee', 'event_espresso');
140
-        $this->plural_item = __('Attendees', 'event_espresso');
141
-        $this->_tables = array(
142
-            'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
143
-            'Attendee_Meta' => new EE_Secondary_Table('esp_attendee_meta', 'ATTM_ID', 'ATT_ID'),
144
-        );
145
-        $this->_fields = array(
146
-            'Attendee_CPT'  => array(
147
-                'ATT_ID'        => new EE_Primary_Key_Int_Field('ID', __("Attendee ID", "event_espresso")),
148
-                'ATT_full_name' => new EE_Plain_Text_Field('post_title', __("Attendee Full Name", "event_espresso"),
149
-                    false, __("Unknown", "event_espresso")),
150
-                'ATT_bio'       => new EE_Post_Content_Field('post_content', __("Attendee Biography", "event_espresso"),
151
-                    false, __("No Biography Provided", "event_espresso")),
152
-                'ATT_slug'      => new EE_Slug_Field('post_name', __("Attendee URL Slug", "event_espresso"), false),
153
-                'ATT_created'   => new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"),
154
-                    false, EE_Datetime_Field::now),
155
-                'ATT_short_bio' => new EE_Simple_HTML_Field('post_excerpt',
156
-                    __("Attendee Short Biography", "event_espresso"), true,
157
-                    __("No Biography Provided", "event_espresso")),
158
-                'ATT_modified'  => new EE_Datetime_Field('post_modified',
159
-                    __("Time Attendee Last Modified", "event_espresso"), false, EE_Datetime_Field::now),
160
-                'ATT_author'    => new EE_WP_User_Field('post_author',
161
-                    __("Creator ID of the first Event attended", "event_espresso"), false),
162
-                'ATT_parent'    => new EE_DB_Only_Int_Field('post_parent',
163
-                    __("Parent Attendee (unused)", "event_espresso"), false, 0),
164
-                'post_type'     => new EE_WP_Post_Type_Field('espresso_attendees'),
165
-                // EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'),
166
-                'status'        => new EE_WP_Post_Status_Field('post_status', __('Attendee Status', 'event_espresso'),
167
-                    false, 'publish'),
168
-            ),
169
-            'Attendee_Meta' => array(
170
-                'ATTM_ID'      => new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID', 'event_espresso'),
171
-                    false),
172
-                'ATT_ID_fk'    => new EE_DB_Only_Int_Field('ATT_ID',
173
-                    __("Foreign Key to Attendee in Post Table", "event_espresso"), false),
174
-                'ATT_fname'    => new EE_Plain_Text_Field('ATT_fname', __('First Name', 'event_espresso'), true, ''),
175
-                'ATT_lname'    => new EE_Plain_Text_Field('ATT_lname', __('Last Name', 'event_espresso'), true, ''),
176
-                'ATT_address'  => new EE_Plain_Text_Field('ATT_address', __('Address Part 1', 'event_espresso'), true,
177
-                    ''),
178
-                'ATT_address2' => new EE_Plain_Text_Field('ATT_address2', __('Address Part 2', 'event_espresso'), true,
179
-                    ''),
180
-                'ATT_city'     => new EE_Plain_Text_Field('ATT_city', __('City', 'event_espresso'), true, ''),
181
-                'STA_ID'       => new EE_Foreign_Key_Int_Field('STA_ID', __('State', 'event_espresso'), true, 0,
182
-                    'State'),
183
-                'CNT_ISO'      => new EE_Foreign_Key_String_Field('CNT_ISO', __('Country', 'event_espresso'), true, '',
184
-                    'Country'),
185
-                'ATT_zip'      => new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code', 'event_espresso'), true, ''),
186
-                'ATT_email'    => new EE_Email_Field('ATT_email', __('Email Address', 'event_espresso'), true, ''),
187
-                'ATT_phone'    => new EE_Plain_Text_Field('ATT_phone', __('Phone', 'event_espresso'), true, ''),
188
-            ),
189
-        );
190
-        $this->_model_relations = array(
191
-            'Registration'      => new EE_Has_Many_Relation(),
192
-            'State'             => new EE_Belongs_To_Relation(),
193
-            'Country'           => new EE_Belongs_To_Relation(),
194
-            'Event'             => new EE_HABTM_Relation('Registration', false),
195
-            'WP_User'           => new EE_Belongs_To_Relation(),
196
-            'Message'           => new EE_Has_Many_Any_Relation(false),
197
-            //allow deletion of attendees even if they have messages in the queue for them.
198
-            'Term_Relationship' => new EE_Has_Many_Relation(),
199
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
200
-        );
201
-        $this->_caps_slug = 'contacts';
202
-        parent::__construct($timezone);
203
-    }
204
-
205
-
206
-
207
-    /**
208
-     * Gets the name of the field on the attendee model corresponding to the system question string
209
-     * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
210
-     *
211
-     * @param string $system_question_string
212
-     * @return string|null if not found
213
-     */
214
-    public function get_attendee_field_for_system_question($system_question_string)
215
-    {
216
-        return isset($this->_system_question_to_attendee_field_name[$system_question_string])
217
-            ? $this->_system_question_to_attendee_field_name[$system_question_string] : null;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
224
-     * @return array
225
-     */
226
-    public function system_question_to_attendee_field_mapping(){
227
-        return $this->_system_question_to_attendee_field_name;
228
-    }
229
-
230
-
231
-
232
-    /**
233
-     * Gets all the attendees for a transaction (by using the esp_registration as a join table)
234
-     *
235
-     * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
236
-     * @return EE_Attendee[]
237
-     */
238
-    public function get_attendees_for_transaction($transaction_id_or_obj)
239
-    {
240
-        return $this->get_all(array(
241
-            array(
242
-                'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
243
-                    ? $transaction_id_or_obj->ID() : $transaction_id_or_obj,
244
-            ),
245
-        ));
246
-    }
247
-
248
-
249
-
250
-    /**
251
-     *        retrieve  a single attendee from db via their ID
252
-     *
253
-     * @access        public
254
-     * @param        $ATT_ID
255
-     * @return        mixed        array on success, FALSE on fail
256
-     * @deprecated
257
-     */
258
-    public function get_attendee_by_ID($ATT_ID = false)
259
-    {
260
-        // retrieve a particular EE_Attendee
261
-        return $this->get_one_by_ID($ATT_ID);
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     *        retrieve  a single attendee from db via their ID
268
-     *
269
-     * @access        public
270
-     * @param        array $where_cols_n_values
271
-     * @return        mixed        array on success, FALSE on fail
272
-     */
273
-    public function get_attendee($where_cols_n_values = array())
274
-    {
275
-        if (empty($where_cols_n_values)) {
276
-            return false;
277
-        }
278
-        $attendee = $this->get_all(array($where_cols_n_values));
279
-        if ( ! empty($attendee)) {
280
-            return array_shift($attendee);
281
-        } else {
282
-            return false;
283
-        }
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     *        Search for an existing Attendee record in the DB
290
-     *
291
-     * @access        public
292
-     * @param array $where_cols_n_values
293
-     * @return bool|mixed
294
-     */
295
-    public function find_existing_attendee($where_cols_n_values = null)
296
-    {
297
-        // search by combo of first and last names plus the email address
298
-        $attendee_data_keys = array(
299
-            'ATT_fname' => $this->_ATT_fname,
300
-            'ATT_lname' => $this->_ATT_lname,
301
-            'ATT_email' => $this->_ATT_email,
302
-        );
303
-        // no search params means attendee object already exists.
304
-        $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) ? $where_cols_n_values
305
-            : $attendee_data_keys;
306
-        $valid_data = true;
307
-        // check for required values
308
-        $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
309
-            ? $valid_data : false;
310
-        $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
311
-            ? $valid_data : false;
312
-        $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
313
-            ? $valid_data : false;
314
-        if ($valid_data) {
315
-            $attendee = $this->get_attendee($where_cols_n_values);
316
-            if ($attendee instanceof EE_Attendee) {
317
-                return $attendee;
318
-            }
319
-        }
320
-        return false;
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * Takes an incoming array of EE_Registration ids and sends back a list of corresponding non duplicate
327
-     * EE_Attendee objects.
328
-     *
329
-     * @since    4.3.0
330
-     * @param  array $ids array of EE_Registration ids
331
-     * @return  EE_Attendee[]
332
-     */
333
-    public function get_array_of_contacts_from_reg_ids($ids)
334
-    {
335
-        $ids = (array)$ids;
336
-        $_where = array(
337
-            'Registration.REG_ID' => array('in', $ids),
338
-        );
339
-        return $this->get_all(array($_where));
340
-    }
48
+	/**
49
+	 * @deprecated
50
+	 */
51
+	const address2_question_id = 5;
52
+
53
+
54
+	/**
55
+	 * @deprecated
56
+	 */
57
+	const city_question_id = 6;
58
+
59
+
60
+	/**
61
+	 * @deprecated
62
+	 */
63
+	const state_question_id = 7;
64
+
65
+
66
+	/**
67
+	 * @deprecated
68
+	 */
69
+	const country_question_id = 8;
70
+
71
+
72
+	/**
73
+	 * @deprecated
74
+	 */
75
+	const zip_question_id = 9;
76
+
77
+
78
+	/**
79
+	 * @deprecated
80
+	 */
81
+	const phone_question_id = 10;
82
+
83
+	/**
84
+	 * When looking for questions that correspond to attendee fields,
85
+	 * look for the question with this QST_system value.
86
+	 * These replace the old constants like EEM_Attendee::*_question_id
87
+	 */
88
+	const system_question_fname    = 'fname';
89
+
90
+	const system_question_lname    = 'lname';
91
+
92
+	const system_question_email    = 'email';
93
+
94
+	const system_question_address  = 'address';
95
+
96
+	const system_question_address2 = 'address2';
97
+
98
+	const system_question_city     = 'city';
99
+
100
+	const system_question_state    = 'state';
101
+
102
+	const system_question_country  = 'country';
103
+
104
+	const system_question_zip      = 'zip';
105
+
106
+	const system_question_phone    = 'phone';
107
+
108
+	/**
109
+	 * Keys are all the EEM_Attendee::system_question_* constants, which are
110
+	 * also all the values of QST_system in the questions table, and values
111
+	 * are their corresponding Attendee field names
112
+	 *
113
+	 * @var array
114
+	 */
115
+	protected $_system_question_to_attendee_field_name = array(
116
+		EEM_Attendee::system_question_fname    => 'ATT_fname',
117
+		EEM_Attendee::system_question_lname    => 'ATT_lname',
118
+		EEM_Attendee::system_question_email    => 'ATT_email',
119
+		EEM_Attendee::system_question_address  => 'ATT_address',
120
+		EEM_Attendee::system_question_address2 => 'ATT_address2',
121
+		EEM_Attendee::system_question_city     => 'ATT_city',
122
+		EEM_Attendee::system_question_state    => 'STA_ID',
123
+		EEM_Attendee::system_question_country  => 'CNT_ISO',
124
+		EEM_Attendee::system_question_zip      => 'ATT_zip',
125
+		EEM_Attendee::system_question_phone    => 'ATT_phone',
126
+	);
127
+
128
+
129
+
130
+	/**
131
+	 *        private constructor to prevent direct creation
132
+	 *
133
+	 * @Constructor
134
+	 * @access protected
135
+	 * @param null $timezone
136
+	 */
137
+	protected function __construct($timezone = null)
138
+	{
139
+		$this->singular_item = __('Attendee', 'event_espresso');
140
+		$this->plural_item = __('Attendees', 'event_espresso');
141
+		$this->_tables = array(
142
+			'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
143
+			'Attendee_Meta' => new EE_Secondary_Table('esp_attendee_meta', 'ATTM_ID', 'ATT_ID'),
144
+		);
145
+		$this->_fields = array(
146
+			'Attendee_CPT'  => array(
147
+				'ATT_ID'        => new EE_Primary_Key_Int_Field('ID', __("Attendee ID", "event_espresso")),
148
+				'ATT_full_name' => new EE_Plain_Text_Field('post_title', __("Attendee Full Name", "event_espresso"),
149
+					false, __("Unknown", "event_espresso")),
150
+				'ATT_bio'       => new EE_Post_Content_Field('post_content', __("Attendee Biography", "event_espresso"),
151
+					false, __("No Biography Provided", "event_espresso")),
152
+				'ATT_slug'      => new EE_Slug_Field('post_name', __("Attendee URL Slug", "event_espresso"), false),
153
+				'ATT_created'   => new EE_Datetime_Field('post_date', __("Time Attendee Created", "event_espresso"),
154
+					false, EE_Datetime_Field::now),
155
+				'ATT_short_bio' => new EE_Simple_HTML_Field('post_excerpt',
156
+					__("Attendee Short Biography", "event_espresso"), true,
157
+					__("No Biography Provided", "event_espresso")),
158
+				'ATT_modified'  => new EE_Datetime_Field('post_modified',
159
+					__("Time Attendee Last Modified", "event_espresso"), false, EE_Datetime_Field::now),
160
+				'ATT_author'    => new EE_WP_User_Field('post_author',
161
+					__("Creator ID of the first Event attended", "event_espresso"), false),
162
+				'ATT_parent'    => new EE_DB_Only_Int_Field('post_parent',
163
+					__("Parent Attendee (unused)", "event_espresso"), false, 0),
164
+				'post_type'     => new EE_WP_Post_Type_Field('espresso_attendees'),
165
+				// EE_DB_Only_Text_Field('post_type', __("Post Type of Attendee", "event_espresso"), false,'espresso_attendees'),
166
+				'status'        => new EE_WP_Post_Status_Field('post_status', __('Attendee Status', 'event_espresso'),
167
+					false, 'publish'),
168
+			),
169
+			'Attendee_Meta' => array(
170
+				'ATTM_ID'      => new EE_DB_Only_Int_Field('ATTM_ID', __('Attendee Meta Row ID', 'event_espresso'),
171
+					false),
172
+				'ATT_ID_fk'    => new EE_DB_Only_Int_Field('ATT_ID',
173
+					__("Foreign Key to Attendee in Post Table", "event_espresso"), false),
174
+				'ATT_fname'    => new EE_Plain_Text_Field('ATT_fname', __('First Name', 'event_espresso'), true, ''),
175
+				'ATT_lname'    => new EE_Plain_Text_Field('ATT_lname', __('Last Name', 'event_espresso'), true, ''),
176
+				'ATT_address'  => new EE_Plain_Text_Field('ATT_address', __('Address Part 1', 'event_espresso'), true,
177
+					''),
178
+				'ATT_address2' => new EE_Plain_Text_Field('ATT_address2', __('Address Part 2', 'event_espresso'), true,
179
+					''),
180
+				'ATT_city'     => new EE_Plain_Text_Field('ATT_city', __('City', 'event_espresso'), true, ''),
181
+				'STA_ID'       => new EE_Foreign_Key_Int_Field('STA_ID', __('State', 'event_espresso'), true, 0,
182
+					'State'),
183
+				'CNT_ISO'      => new EE_Foreign_Key_String_Field('CNT_ISO', __('Country', 'event_espresso'), true, '',
184
+					'Country'),
185
+				'ATT_zip'      => new EE_Plain_Text_Field('ATT_zip', __('ZIP/Postal Code', 'event_espresso'), true, ''),
186
+				'ATT_email'    => new EE_Email_Field('ATT_email', __('Email Address', 'event_espresso'), true, ''),
187
+				'ATT_phone'    => new EE_Plain_Text_Field('ATT_phone', __('Phone', 'event_espresso'), true, ''),
188
+			),
189
+		);
190
+		$this->_model_relations = array(
191
+			'Registration'      => new EE_Has_Many_Relation(),
192
+			'State'             => new EE_Belongs_To_Relation(),
193
+			'Country'           => new EE_Belongs_To_Relation(),
194
+			'Event'             => new EE_HABTM_Relation('Registration', false),
195
+			'WP_User'           => new EE_Belongs_To_Relation(),
196
+			'Message'           => new EE_Has_Many_Any_Relation(false),
197
+			//allow deletion of attendees even if they have messages in the queue for them.
198
+			'Term_Relationship' => new EE_Has_Many_Relation(),
199
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
200
+		);
201
+		$this->_caps_slug = 'contacts';
202
+		parent::__construct($timezone);
203
+	}
204
+
205
+
206
+
207
+	/**
208
+	 * Gets the name of the field on the attendee model corresponding to the system question string
209
+	 * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
210
+	 *
211
+	 * @param string $system_question_string
212
+	 * @return string|null if not found
213
+	 */
214
+	public function get_attendee_field_for_system_question($system_question_string)
215
+	{
216
+		return isset($this->_system_question_to_attendee_field_name[$system_question_string])
217
+			? $this->_system_question_to_attendee_field_name[$system_question_string] : null;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
224
+	 * @return array
225
+	 */
226
+	public function system_question_to_attendee_field_mapping(){
227
+		return $this->_system_question_to_attendee_field_name;
228
+	}
229
+
230
+
231
+
232
+	/**
233
+	 * Gets all the attendees for a transaction (by using the esp_registration as a join table)
234
+	 *
235
+	 * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
236
+	 * @return EE_Attendee[]
237
+	 */
238
+	public function get_attendees_for_transaction($transaction_id_or_obj)
239
+	{
240
+		return $this->get_all(array(
241
+			array(
242
+				'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
243
+					? $transaction_id_or_obj->ID() : $transaction_id_or_obj,
244
+			),
245
+		));
246
+	}
247
+
248
+
249
+
250
+	/**
251
+	 *        retrieve  a single attendee from db via their ID
252
+	 *
253
+	 * @access        public
254
+	 * @param        $ATT_ID
255
+	 * @return        mixed        array on success, FALSE on fail
256
+	 * @deprecated
257
+	 */
258
+	public function get_attendee_by_ID($ATT_ID = false)
259
+	{
260
+		// retrieve a particular EE_Attendee
261
+		return $this->get_one_by_ID($ATT_ID);
262
+	}
263
+
264
+
265
+
266
+	/**
267
+	 *        retrieve  a single attendee from db via their ID
268
+	 *
269
+	 * @access        public
270
+	 * @param        array $where_cols_n_values
271
+	 * @return        mixed        array on success, FALSE on fail
272
+	 */
273
+	public function get_attendee($where_cols_n_values = array())
274
+	{
275
+		if (empty($where_cols_n_values)) {
276
+			return false;
277
+		}
278
+		$attendee = $this->get_all(array($where_cols_n_values));
279
+		if ( ! empty($attendee)) {
280
+			return array_shift($attendee);
281
+		} else {
282
+			return false;
283
+		}
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 *        Search for an existing Attendee record in the DB
290
+	 *
291
+	 * @access        public
292
+	 * @param array $where_cols_n_values
293
+	 * @return bool|mixed
294
+	 */
295
+	public function find_existing_attendee($where_cols_n_values = null)
296
+	{
297
+		// search by combo of first and last names plus the email address
298
+		$attendee_data_keys = array(
299
+			'ATT_fname' => $this->_ATT_fname,
300
+			'ATT_lname' => $this->_ATT_lname,
301
+			'ATT_email' => $this->_ATT_email,
302
+		);
303
+		// no search params means attendee object already exists.
304
+		$where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) ? $where_cols_n_values
305
+			: $attendee_data_keys;
306
+		$valid_data = true;
307
+		// check for required values
308
+		$valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
309
+			? $valid_data : false;
310
+		$valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
311
+			? $valid_data : false;
312
+		$valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
313
+			? $valid_data : false;
314
+		if ($valid_data) {
315
+			$attendee = $this->get_attendee($where_cols_n_values);
316
+			if ($attendee instanceof EE_Attendee) {
317
+				return $attendee;
318
+			}
319
+		}
320
+		return false;
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * Takes an incoming array of EE_Registration ids and sends back a list of corresponding non duplicate
327
+	 * EE_Attendee objects.
328
+	 *
329
+	 * @since    4.3.0
330
+	 * @param  array $ids array of EE_Registration ids
331
+	 * @return  EE_Attendee[]
332
+	 */
333
+	public function get_array_of_contacts_from_reg_ids($ids)
334
+	{
335
+		$ids = (array)$ids;
336
+		$_where = array(
337
+			'Registration.REG_ID' => array('in', $ids),
338
+		);
339
+		return $this->get_all(array($_where));
340
+	}
341 341
 
342 342
 
343 343
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4
-require_once(EE_MODELS . 'EEM_Base.model.php');
4
+require_once(EE_MODELS.'EEM_Base.model.php');
5 5
 
6 6
 
7 7
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
224 224
      * @return array
225 225
      */
226
-    public function system_question_to_attendee_field_mapping(){
226
+    public function system_question_to_attendee_field_mapping() {
227 227
         return $this->_system_question_to_attendee_field_name;
228 228
     }
229 229
 
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
      */
333 333
     public function get_array_of_contacts_from_reg_ids($ids)
334 334
     {
335
-        $ids = (array)$ids;
335
+        $ids = (array) $ids;
336 336
         $_where = array(
337 337
             'Registration.REG_ID' => array('in', $ids),
338 338
         );
Please login to merge, or discard this patch.
core/db_models/EEM_CPT_Base.model.php 2 patches
Indentation   +514 added lines, -514 removed lines patch added patch discarded remove patch
@@ -18,519 +18,519 @@
 block discarded – undo
18 18
 abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base
19 19
 {
20 20
 
21
-    /**
22
-     * @var string post_status_publish - the wp post status for published cpts
23
-     */
24
-    const post_status_publish = 'publish';
25
-
26
-    /**
27
-     * @var string post_status_future - the wp post status for scheduled cpts
28
-     */
29
-    const post_status_future = 'future';
30
-
31
-    /**
32
-     * @var string post_status_draft - the wp post status for draft cpts
33
-     */
34
-    const post_status_draft = 'draft';
35
-
36
-    /**
37
-     * @var string post_status_pending - the wp post status for pending cpts
38
-     */
39
-    const post_status_pending = 'pending';
40
-
41
-    /**
42
-     * @var string post_status_private - the wp post status for private cpts
43
-     */
44
-    const post_status_private = 'private';
45
-
46
-    /**
47
-     * @var string post_status_trashed - the wp post status for trashed cpts
48
-     */
49
-    const post_status_trashed = 'trash';
50
-
51
-    /**
52
-     * This is an array of custom statuses for the given CPT model (modified by children)
53
-     * format:
54
-     * array(
55
-     *        'status_name' => array(
56
-     *            'label' => __('Status Name', 'event_espresso'),
57
-     *            'public' => TRUE //whether a public status or not.
58
-     *        )
59
-     * )
60
-     *
61
-     * @var array
62
-     */
63
-    protected $_custom_stati = array();
64
-
65
-
66
-
67
-    /**
68
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
69
-     *
70
-     * @param string $timezone
71
-     * @throws \EE_Error
72
-     */
73
-    protected function __construct($timezone = null)
74
-    {
75
-        //adds a relationship to Term_Taxonomy for all these models. For this to work
76
-        //Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
77
-        //eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
78
-        //with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
79
-        //must also be new EE_HABTM_Relation('Term_Relationship');
80
-        $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
81
-        $primary_table_name = null;
82
-        //add  the common _status field to all CPT primary tables.
83
-        foreach ($this->_tables as $alias => $table_obj) {
84
-            if ($table_obj instanceof EE_Primary_Table) {
85
-                $primary_table_name = $alias;
86
-            }
87
-        }
88
-        //set default wp post statuses if child has not already set.
89
-        if ( ! isset($this->_fields[$primary_table_name]['status'])) {
90
-            $this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status',
91
-                __("Event Status", "event_espresso"), false, 'draft');
92
-        }
93
-        if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
94
-            $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping',
95
-                __('To Ping', 'event_espresso'), false, '');
96
-        }
97
-        if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
98
-            $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged',
99
-                __('Pinged', 'event_espresso'), false, '');
100
-        }
101
-        if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
102
-            $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status',
103
-                __('Comment Status', 'event_espresso'), false, 'open');
104
-        }
105
-        if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
106
-            $this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status',
107
-                __('Ping Status', 'event_espresso'), false, 'open');
108
-        }
109
-        if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
110
-            $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered',
111
-                __('Post Content Filtered', 'event_espresso'), false, '');
112
-        }
113
-        if ( ! isset($this->_model_relations['Post_Meta'])) {
114
-            //don't block deletes though because we want to maintain the current behaviour
115
-            $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
116
-        }
117
-        if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
118
-            //nothing was set during child constructor, so set default
119
-            $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
120
-        }
121
-        if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
122
-            //nothing was set during child constructor, so set default
123
-            //it's ok for child classes to specify this, but generally this is more DRY
124
-            $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
125
-        }
126
-        parent::__construct($timezone);
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * @return array
133
-     */
134
-    public function public_event_stati()
135
-    {
136
-        // @see wp-includes/post.php
137
-        return get_post_stati(array('public' => true));
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * Searches for field on this model of type 'deleted_flag'. if it is found,
144
-     * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
145
-     *
146
-     * @return string
147
-     * @throws EE_Error
148
-     */
149
-    public function deleted_field_name()
150
-    {
151
-        throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
152
-            "event_espresso")));
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Gets the field's name that sets the post status
159
-     *
160
-     * @return string
161
-     * @throws EE_Error
162
-     */
163
-    public function post_status_field_name()
164
-    {
165
-        $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
166
-        if ($field) {
167
-            return $field->get_name();
168
-        } else {
169
-            throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
170
-                'event_espresso'), get_class($this), get_class($this)));
171
-        }
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * Alters the query params so that only trashed/soft-deleted items are considered
178
-     *
179
-     * @param array $query_params like EEM_Base::get_all's $query_params
180
-     * @return array like EEM_Base::get_all's $query_params
181
-     */
182
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
183
-    {
184
-        $post_status_field_name = $this->post_status_field_name();
185
-        $query_params[0][$post_status_field_name] = self::post_status_trashed;
186
-        return $query_params;
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * Alters the query params so each item's deleted status is ignored.
193
-     *
194
-     * @param array $query_params
195
-     * @return array
196
-     */
197
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
198
-    {
199
-        $query_params['default_where_conditions'] = 'minimum';
200
-        return $query_params;
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
207
-     *
208
-     * @param boolean $delete       true to indicate deletion, false to indicate restoration
209
-     * @param array   $query_params like EEM_Base::get_all
210
-     * @return boolean success
211
-     */
212
-    function delete_or_restore($delete = true, $query_params = array())
213
-    {
214
-        $post_status_field_name = $this->post_status_field_name();
215
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
216
-        $new_status = $delete ? self::post_status_trashed : 'draft';
217
-        if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
218
-            return true;
219
-        } else {
220
-            return false;
221
-        }
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * meta_table
228
-     * returns first EE_Secondary_Table table name
229
-     *
230
-     * @access public
231
-     * @return string
232
-     */
233
-    public function meta_table()
234
-    {
235
-        $meta_table = $this->_get_other_tables();
236
-        $meta_table = reset($meta_table);
237
-        return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
244
-     *
245
-     * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
246
-     *                   db only fields)
247
-     * @return array
248
-     */
249
-    public function get_meta_table_fields($all = false)
250
-    {
251
-        $all_fields = $fields_to_return = array();
252
-        foreach ($this->_tables as $alias => $table_obj) {
253
-            if ($table_obj instanceof EE_Secondary_Table) {
254
-                $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
255
-            }
256
-        }
257
-        if ( ! $all) {
258
-            foreach ($all_fields as $name => $obj) {
259
-                if ($obj instanceof EE_DB_Only_Field_Base) {
260
-                    continue;
261
-                }
262
-                $fields_to_return[] = $name;
263
-            }
264
-        } else {
265
-            $fields_to_return = array_keys($all_fields);
266
-        }
267
-        return $fields_to_return;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Adds an event category with the specified name and description to the specified
274
-     * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
275
-     * and adds an entry in the term_relationship if necessary.
276
-     *
277
-     * @param EE_CPT_Base $cpt_model_object
278
-     * @param string      $category_name (used to derive the term slug too)
279
-     * @param string      $category_description
280
-     * @param int         $parent_term_taxonomy_id
281
-     * @return EE_Term_Taxonomy
282
-     */
283
-    function add_event_category(
284
-        EE_CPT_Base $cpt_model_object,
285
-        $category_name,
286
-        $category_description = '',
287
-        $parent_term_taxonomy_id = null
288
-    ) {
289
-        //create term
290
-        require_once(EE_MODELS . 'EEM_Term.model.php');
291
-        //first, check for a term by the same name or slug
292
-        $category_slug = sanitize_title($category_name);
293
-        $term = EEM_Term::instance()->get_one(array(
294
-            array(
295
-                'OR' => array(
296
-                    'name' => $category_name,
297
-                    'slug' => $category_slug,
298
-                ),
299
-            ),
300
-        ));
301
-        if ( ! $term) {
302
-            $term = EE_Term::new_instance(array(
303
-                'name' => $category_name,
304
-                'slug' => $category_slug,
305
-            ));
306
-            $term->save();
307
-        }
308
-        //make sure there's a term-taxonomy entry too
309
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
310
-        $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(
311
-            array(
312
-                'term_id'  => $term->ID(),
313
-                'taxonomy' => EE_Event_Category_Taxonomy,
314
-            ),
315
-        ));
316
-        /** @var $term_taxonomy EE_Term_Taxonomy */
317
-        if ( ! $term_taxonomy) {
318
-            $term_taxonomy = EE_Term_Taxonomy::new_instance(array(
319
-                'term_id'     => $term->ID(),
320
-                'taxonomy'    => EE_Event_Category_Taxonomy,
321
-                'description' => $category_description,
322
-                'count'       => 1,
323
-                'parent'      => $parent_term_taxonomy_id,
324
-            ));
325
-            $term_taxonomy->save();
326
-        } else {
327
-            $term_taxonomy->set_count($term_taxonomy->count() + 1);
328
-            $term_taxonomy->save();
329
-        }
330
-        return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * Removed the category specified by name as having a relation to this event.
337
-     * Does not remove the term or term_taxonomy.
338
-     *
339
-     * @param EE_CPT_Base $cpt_model_object_event
340
-     * @param string      $category_name name of the event category (term)
341
-     * @return bool
342
-     */
343
-    function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
344
-    {
345
-        //find the term_taxonomy by that name
346
-        $term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy',
347
-            array(array('Term.name' => $category_name, 'taxonomy' => EE_Event_Category_Taxonomy)));
348
-        /** @var $term_taxonomy EE_Term_Taxonomy */
349
-        if ($term_taxonomy) {
350
-            $term_taxonomy->set_count($term_taxonomy->count() - 1);
351
-            $term_taxonomy->save();
352
-        }
353
-        return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
360
-     * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
361
-     *
362
-     * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
363
-     * @access public
364
-     * @param int          $id   the ID for the cpt we want the feature image for
365
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
366
-     *                           representing width and height in pixels (i.e. array(32,32) ).
367
-     * @param string|array $attr Optional. Query string or array of attributes.
368
-     * @return string HTML image element
369
-     */
370
-    public function get_feature_image($id, $size = 'thumbnail', $attr = '')
371
-    {
372
-        return get_the_post_thumbnail($id, $size, $attr);
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * Just a handy way to get the list of post statuses currently registered with WP.
379
-     *
380
-     * @global array $wp_post_statuses set in wp core for storing all the post stati
381
-     * @return array
382
-     */
383
-    public function get_post_statuses()
384
-    {
385
-        global $wp_post_statuses;
386
-        $statuses = array();
387
-        foreach ($wp_post_statuses as $post_status => $args_object) {
388
-            $statuses[$post_status] = $args_object->label;
389
-        }
390
-        return $statuses;
391
-    }
392
-
393
-
394
-
395
-    /**
396
-     * public method that can be used to retrieve the protected status array on the instantiated cpt model
397
-     *
398
-     * @return array array of statuses.
399
-     */
400
-    public function get_status_array()
401
-    {
402
-        $statuses = $this->get_post_statuses();
403
-        //first the global filter
404
-        $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
405
-        //now the class specific filter
406
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
407
-        return $statuses;
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * this returns the post statuses that are NOT the default wordpress status
414
-     *
415
-     * @return array
416
-     */
417
-    public function get_custom_post_statuses()
418
-    {
419
-        $new_stati = array();
420
-        foreach ($this->_custom_stati as $status => $props) {
421
-            $new_stati[$status] = $props['label'];
422
-        }
423
-        return $new_stati;
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
430
-     * are a row from the posts table. If we're missing any fields required for the model,
431
-     * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
432
-     * make sure you are attaching all the model's fields onto the post)
433
-     *
434
-     * @param WP_Post|array $post
435
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
436
-     */
437
-    public function instantiate_class_from_post_object_orig($post)
438
-    {
439
-        $post = (array)$post;
440
-        $has_all_necessary_fields_for_table = true;
441
-        //check if the post has fields on the meta table already
442
-        foreach ($this->_get_other_tables() as $table_obj) {
443
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
444
-            foreach ($fields_for_that_table as $field_obj) {
445
-                if ( ! isset($post[$field_obj->get_table_column()])
446
-                     && ! isset($post[$field_obj->get_qualified_column()])
447
-                ) {
448
-                    $has_all_necessary_fields_for_table = false;
449
-                }
450
-            }
451
-        }
452
-        //if we don't have all the fields we need, then just fetch the proper model from the DB
453
-        if ( ! $has_all_necessary_fields_for_table) {
454
-            return $this->get_one_by_ID($post['ID']);
455
-        } else {
456
-            return $this->instantiate_class_from_array_or_object($post);
457
-        }
458
-    }
459
-
460
-
461
-
462
-    /**
463
-     * @param null $post
464
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
465
-     */
466
-    public function instantiate_class_from_post_object($post = null)
467
-    {
468
-        if (empty($post)) {
469
-            global $post;
470
-        }
471
-        $post = (array)$post;
472
-        $tables_needing_to_be_queried = array();
473
-        //check if the post has fields on the meta table already
474
-        foreach ($this->get_tables() as $table_obj) {
475
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
476
-            foreach ($fields_for_that_table as $field_obj) {
477
-                if ( ! isset($post[$field_obj->get_table_column()])
478
-                     && ! isset($post[$field_obj->get_qualified_column()])
479
-                ) {
480
-                    $tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
481
-                }
482
-            }
483
-        }
484
-        //if we don't have all the fields we need, then just fetch the proper model from the DB
485
-        if ($tables_needing_to_be_queried) {
486
-            if (count($tables_needing_to_be_queried) == 1
487
-                && reset($tables_needing_to_be_queried)
488
-                   instanceof
489
-                   EE_Secondary_Table
490
-            ) {
491
-                //so we're only missing data from a secondary table. Well that's not too hard to query for
492
-                $table_to_query = reset($tables_needing_to_be_queried);
493
-                $missing_data = $this->_do_wpdb_query('get_row', array(
494
-                    'SELECT * FROM '
495
-                    . $table_to_query->get_table_name()
496
-                    . ' WHERE '
497
-                    . $table_to_query->get_fk_on_table()
498
-                    . ' = '
499
-                    . $post['ID'],
500
-                    ARRAY_A,
501
-                ));
502
-                if ( ! empty($missing_data)) {
503
-                    $post = array_merge($post, $missing_data);
504
-                }
505
-            } else {
506
-                return $this->get_one_by_ID($post['ID']);
507
-            }
508
-        }
509
-        return $this->instantiate_class_from_array_or_object($post);
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * Gets the post type associated with this
516
-     *
517
-     * @throws EE_Error
518
-     * @return string
519
-     */
520
-    public function post_type()
521
-    {
522
-        $post_type_field = null;
523
-        foreach ($this->field_settings(true) as $field_obj) {
524
-            if ($field_obj instanceof EE_WP_Post_Type_Field) {
525
-                $post_type_field = $field_obj;
526
-                break;
527
-            }
528
-        }
529
-        if ($post_type_field == null) {
530
-            throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
531
-                "event_espresso"), get_class($this)));
532
-        }
533
-        return $post_type_field->get_default_value();
534
-    }
21
+	/**
22
+	 * @var string post_status_publish - the wp post status for published cpts
23
+	 */
24
+	const post_status_publish = 'publish';
25
+
26
+	/**
27
+	 * @var string post_status_future - the wp post status for scheduled cpts
28
+	 */
29
+	const post_status_future = 'future';
30
+
31
+	/**
32
+	 * @var string post_status_draft - the wp post status for draft cpts
33
+	 */
34
+	const post_status_draft = 'draft';
35
+
36
+	/**
37
+	 * @var string post_status_pending - the wp post status for pending cpts
38
+	 */
39
+	const post_status_pending = 'pending';
40
+
41
+	/**
42
+	 * @var string post_status_private - the wp post status for private cpts
43
+	 */
44
+	const post_status_private = 'private';
45
+
46
+	/**
47
+	 * @var string post_status_trashed - the wp post status for trashed cpts
48
+	 */
49
+	const post_status_trashed = 'trash';
50
+
51
+	/**
52
+	 * This is an array of custom statuses for the given CPT model (modified by children)
53
+	 * format:
54
+	 * array(
55
+	 *        'status_name' => array(
56
+	 *            'label' => __('Status Name', 'event_espresso'),
57
+	 *            'public' => TRUE //whether a public status or not.
58
+	 *        )
59
+	 * )
60
+	 *
61
+	 * @var array
62
+	 */
63
+	protected $_custom_stati = array();
64
+
65
+
66
+
67
+	/**
68
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
69
+	 *
70
+	 * @param string $timezone
71
+	 * @throws \EE_Error
72
+	 */
73
+	protected function __construct($timezone = null)
74
+	{
75
+		//adds a relationship to Term_Taxonomy for all these models. For this to work
76
+		//Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
77
+		//eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
78
+		//with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
79
+		//must also be new EE_HABTM_Relation('Term_Relationship');
80
+		$this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
81
+		$primary_table_name = null;
82
+		//add  the common _status field to all CPT primary tables.
83
+		foreach ($this->_tables as $alias => $table_obj) {
84
+			if ($table_obj instanceof EE_Primary_Table) {
85
+				$primary_table_name = $alias;
86
+			}
87
+		}
88
+		//set default wp post statuses if child has not already set.
89
+		if ( ! isset($this->_fields[$primary_table_name]['status'])) {
90
+			$this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status',
91
+				__("Event Status", "event_espresso"), false, 'draft');
92
+		}
93
+		if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
94
+			$this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping',
95
+				__('To Ping', 'event_espresso'), false, '');
96
+		}
97
+		if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
98
+			$this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged',
99
+				__('Pinged', 'event_espresso'), false, '');
100
+		}
101
+		if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
102
+			$this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status',
103
+				__('Comment Status', 'event_espresso'), false, 'open');
104
+		}
105
+		if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
106
+			$this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status',
107
+				__('Ping Status', 'event_espresso'), false, 'open');
108
+		}
109
+		if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
110
+			$this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered',
111
+				__('Post Content Filtered', 'event_espresso'), false, '');
112
+		}
113
+		if ( ! isset($this->_model_relations['Post_Meta'])) {
114
+			//don't block deletes though because we want to maintain the current behaviour
115
+			$this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
116
+		}
117
+		if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
118
+			//nothing was set during child constructor, so set default
119
+			$this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
120
+		}
121
+		if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
122
+			//nothing was set during child constructor, so set default
123
+			//it's ok for child classes to specify this, but generally this is more DRY
124
+			$this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
125
+		}
126
+		parent::__construct($timezone);
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * @return array
133
+	 */
134
+	public function public_event_stati()
135
+	{
136
+		// @see wp-includes/post.php
137
+		return get_post_stati(array('public' => true));
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * Searches for field on this model of type 'deleted_flag'. if it is found,
144
+	 * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
145
+	 *
146
+	 * @return string
147
+	 * @throws EE_Error
148
+	 */
149
+	public function deleted_field_name()
150
+	{
151
+		throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
152
+			"event_espresso")));
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Gets the field's name that sets the post status
159
+	 *
160
+	 * @return string
161
+	 * @throws EE_Error
162
+	 */
163
+	public function post_status_field_name()
164
+	{
165
+		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
166
+		if ($field) {
167
+			return $field->get_name();
168
+		} else {
169
+			throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
170
+				'event_espresso'), get_class($this), get_class($this)));
171
+		}
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * Alters the query params so that only trashed/soft-deleted items are considered
178
+	 *
179
+	 * @param array $query_params like EEM_Base::get_all's $query_params
180
+	 * @return array like EEM_Base::get_all's $query_params
181
+	 */
182
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
183
+	{
184
+		$post_status_field_name = $this->post_status_field_name();
185
+		$query_params[0][$post_status_field_name] = self::post_status_trashed;
186
+		return $query_params;
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * Alters the query params so each item's deleted status is ignored.
193
+	 *
194
+	 * @param array $query_params
195
+	 * @return array
196
+	 */
197
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
198
+	{
199
+		$query_params['default_where_conditions'] = 'minimum';
200
+		return $query_params;
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
207
+	 *
208
+	 * @param boolean $delete       true to indicate deletion, false to indicate restoration
209
+	 * @param array   $query_params like EEM_Base::get_all
210
+	 * @return boolean success
211
+	 */
212
+	function delete_or_restore($delete = true, $query_params = array())
213
+	{
214
+		$post_status_field_name = $this->post_status_field_name();
215
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
216
+		$new_status = $delete ? self::post_status_trashed : 'draft';
217
+		if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
218
+			return true;
219
+		} else {
220
+			return false;
221
+		}
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * meta_table
228
+	 * returns first EE_Secondary_Table table name
229
+	 *
230
+	 * @access public
231
+	 * @return string
232
+	 */
233
+	public function meta_table()
234
+	{
235
+		$meta_table = $this->_get_other_tables();
236
+		$meta_table = reset($meta_table);
237
+		return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
244
+	 *
245
+	 * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
246
+	 *                   db only fields)
247
+	 * @return array
248
+	 */
249
+	public function get_meta_table_fields($all = false)
250
+	{
251
+		$all_fields = $fields_to_return = array();
252
+		foreach ($this->_tables as $alias => $table_obj) {
253
+			if ($table_obj instanceof EE_Secondary_Table) {
254
+				$all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
255
+			}
256
+		}
257
+		if ( ! $all) {
258
+			foreach ($all_fields as $name => $obj) {
259
+				if ($obj instanceof EE_DB_Only_Field_Base) {
260
+					continue;
261
+				}
262
+				$fields_to_return[] = $name;
263
+			}
264
+		} else {
265
+			$fields_to_return = array_keys($all_fields);
266
+		}
267
+		return $fields_to_return;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Adds an event category with the specified name and description to the specified
274
+	 * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
275
+	 * and adds an entry in the term_relationship if necessary.
276
+	 *
277
+	 * @param EE_CPT_Base $cpt_model_object
278
+	 * @param string      $category_name (used to derive the term slug too)
279
+	 * @param string      $category_description
280
+	 * @param int         $parent_term_taxonomy_id
281
+	 * @return EE_Term_Taxonomy
282
+	 */
283
+	function add_event_category(
284
+		EE_CPT_Base $cpt_model_object,
285
+		$category_name,
286
+		$category_description = '',
287
+		$parent_term_taxonomy_id = null
288
+	) {
289
+		//create term
290
+		require_once(EE_MODELS . 'EEM_Term.model.php');
291
+		//first, check for a term by the same name or slug
292
+		$category_slug = sanitize_title($category_name);
293
+		$term = EEM_Term::instance()->get_one(array(
294
+			array(
295
+				'OR' => array(
296
+					'name' => $category_name,
297
+					'slug' => $category_slug,
298
+				),
299
+			),
300
+		));
301
+		if ( ! $term) {
302
+			$term = EE_Term::new_instance(array(
303
+				'name' => $category_name,
304
+				'slug' => $category_slug,
305
+			));
306
+			$term->save();
307
+		}
308
+		//make sure there's a term-taxonomy entry too
309
+		require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
310
+		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(
311
+			array(
312
+				'term_id'  => $term->ID(),
313
+				'taxonomy' => EE_Event_Category_Taxonomy,
314
+			),
315
+		));
316
+		/** @var $term_taxonomy EE_Term_Taxonomy */
317
+		if ( ! $term_taxonomy) {
318
+			$term_taxonomy = EE_Term_Taxonomy::new_instance(array(
319
+				'term_id'     => $term->ID(),
320
+				'taxonomy'    => EE_Event_Category_Taxonomy,
321
+				'description' => $category_description,
322
+				'count'       => 1,
323
+				'parent'      => $parent_term_taxonomy_id,
324
+			));
325
+			$term_taxonomy->save();
326
+		} else {
327
+			$term_taxonomy->set_count($term_taxonomy->count() + 1);
328
+			$term_taxonomy->save();
329
+		}
330
+		return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * Removed the category specified by name as having a relation to this event.
337
+	 * Does not remove the term or term_taxonomy.
338
+	 *
339
+	 * @param EE_CPT_Base $cpt_model_object_event
340
+	 * @param string      $category_name name of the event category (term)
341
+	 * @return bool
342
+	 */
343
+	function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
344
+	{
345
+		//find the term_taxonomy by that name
346
+		$term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy',
347
+			array(array('Term.name' => $category_name, 'taxonomy' => EE_Event_Category_Taxonomy)));
348
+		/** @var $term_taxonomy EE_Term_Taxonomy */
349
+		if ($term_taxonomy) {
350
+			$term_taxonomy->set_count($term_taxonomy->count() - 1);
351
+			$term_taxonomy->save();
352
+		}
353
+		return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
360
+	 * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
361
+	 *
362
+	 * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
363
+	 * @access public
364
+	 * @param int          $id   the ID for the cpt we want the feature image for
365
+	 * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
366
+	 *                           representing width and height in pixels (i.e. array(32,32) ).
367
+	 * @param string|array $attr Optional. Query string or array of attributes.
368
+	 * @return string HTML image element
369
+	 */
370
+	public function get_feature_image($id, $size = 'thumbnail', $attr = '')
371
+	{
372
+		return get_the_post_thumbnail($id, $size, $attr);
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * Just a handy way to get the list of post statuses currently registered with WP.
379
+	 *
380
+	 * @global array $wp_post_statuses set in wp core for storing all the post stati
381
+	 * @return array
382
+	 */
383
+	public function get_post_statuses()
384
+	{
385
+		global $wp_post_statuses;
386
+		$statuses = array();
387
+		foreach ($wp_post_statuses as $post_status => $args_object) {
388
+			$statuses[$post_status] = $args_object->label;
389
+		}
390
+		return $statuses;
391
+	}
392
+
393
+
394
+
395
+	/**
396
+	 * public method that can be used to retrieve the protected status array on the instantiated cpt model
397
+	 *
398
+	 * @return array array of statuses.
399
+	 */
400
+	public function get_status_array()
401
+	{
402
+		$statuses = $this->get_post_statuses();
403
+		//first the global filter
404
+		$statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
405
+		//now the class specific filter
406
+		$statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
407
+		return $statuses;
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * this returns the post statuses that are NOT the default wordpress status
414
+	 *
415
+	 * @return array
416
+	 */
417
+	public function get_custom_post_statuses()
418
+	{
419
+		$new_stati = array();
420
+		foreach ($this->_custom_stati as $status => $props) {
421
+			$new_stati[$status] = $props['label'];
422
+		}
423
+		return $new_stati;
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
430
+	 * are a row from the posts table. If we're missing any fields required for the model,
431
+	 * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
432
+	 * make sure you are attaching all the model's fields onto the post)
433
+	 *
434
+	 * @param WP_Post|array $post
435
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
436
+	 */
437
+	public function instantiate_class_from_post_object_orig($post)
438
+	{
439
+		$post = (array)$post;
440
+		$has_all_necessary_fields_for_table = true;
441
+		//check if the post has fields on the meta table already
442
+		foreach ($this->_get_other_tables() as $table_obj) {
443
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
444
+			foreach ($fields_for_that_table as $field_obj) {
445
+				if ( ! isset($post[$field_obj->get_table_column()])
446
+					 && ! isset($post[$field_obj->get_qualified_column()])
447
+				) {
448
+					$has_all_necessary_fields_for_table = false;
449
+				}
450
+			}
451
+		}
452
+		//if we don't have all the fields we need, then just fetch the proper model from the DB
453
+		if ( ! $has_all_necessary_fields_for_table) {
454
+			return $this->get_one_by_ID($post['ID']);
455
+		} else {
456
+			return $this->instantiate_class_from_array_or_object($post);
457
+		}
458
+	}
459
+
460
+
461
+
462
+	/**
463
+	 * @param null $post
464
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
465
+	 */
466
+	public function instantiate_class_from_post_object($post = null)
467
+	{
468
+		if (empty($post)) {
469
+			global $post;
470
+		}
471
+		$post = (array)$post;
472
+		$tables_needing_to_be_queried = array();
473
+		//check if the post has fields on the meta table already
474
+		foreach ($this->get_tables() as $table_obj) {
475
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
476
+			foreach ($fields_for_that_table as $field_obj) {
477
+				if ( ! isset($post[$field_obj->get_table_column()])
478
+					 && ! isset($post[$field_obj->get_qualified_column()])
479
+				) {
480
+					$tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
481
+				}
482
+			}
483
+		}
484
+		//if we don't have all the fields we need, then just fetch the proper model from the DB
485
+		if ($tables_needing_to_be_queried) {
486
+			if (count($tables_needing_to_be_queried) == 1
487
+				&& reset($tables_needing_to_be_queried)
488
+				   instanceof
489
+				   EE_Secondary_Table
490
+			) {
491
+				//so we're only missing data from a secondary table. Well that's not too hard to query for
492
+				$table_to_query = reset($tables_needing_to_be_queried);
493
+				$missing_data = $this->_do_wpdb_query('get_row', array(
494
+					'SELECT * FROM '
495
+					. $table_to_query->get_table_name()
496
+					. ' WHERE '
497
+					. $table_to_query->get_fk_on_table()
498
+					. ' = '
499
+					. $post['ID'],
500
+					ARRAY_A,
501
+				));
502
+				if ( ! empty($missing_data)) {
503
+					$post = array_merge($post, $missing_data);
504
+				}
505
+			} else {
506
+				return $this->get_one_by_ID($post['ID']);
507
+			}
508
+		}
509
+		return $this->instantiate_class_from_array_or_object($post);
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * Gets the post type associated with this
516
+	 *
517
+	 * @throws EE_Error
518
+	 * @return string
519
+	 */
520
+	public function post_type()
521
+	{
522
+		$post_type_field = null;
523
+		foreach ($this->field_settings(true) as $field_obj) {
524
+			if ($field_obj instanceof EE_WP_Post_Type_Field) {
525
+				$post_type_field = $field_obj;
526
+				break;
527
+			}
528
+		}
529
+		if ($post_type_field == null) {
530
+			throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
531
+				"event_espresso"), get_class($this)));
532
+		}
533
+		return $post_type_field->get_default_value();
534
+	}
535 535
 
536 536
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
         $parent_term_taxonomy_id = null
288 288
     ) {
289 289
         //create term
290
-        require_once(EE_MODELS . 'EEM_Term.model.php');
290
+        require_once(EE_MODELS.'EEM_Term.model.php');
291 291
         //first, check for a term by the same name or slug
292 292
         $category_slug = sanitize_title($category_name);
293 293
         $term = EEM_Term::instance()->get_one(array(
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
             $term->save();
307 307
         }
308 308
         //make sure there's a term-taxonomy entry too
309
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
309
+        require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php');
310 310
         $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(
311 311
             array(
312 312
                 'term_id'  => $term->ID(),
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
         //first the global filter
404 404
         $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
405 405
         //now the class specific filter
406
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
406
+        $statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses);
407 407
         return $statuses;
408 408
     }
409 409
 
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
      */
437 437
     public function instantiate_class_from_post_object_orig($post)
438 438
     {
439
-        $post = (array)$post;
439
+        $post = (array) $post;
440 440
         $has_all_necessary_fields_for_table = true;
441 441
         //check if the post has fields on the meta table already
442 442
         foreach ($this->_get_other_tables() as $table_obj) {
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
         if (empty($post)) {
469 469
             global $post;
470 470
         }
471
-        $post = (array)$post;
471
+        $post = (array) $post;
472 472
         $tables_needing_to_be_queried = array();
473 473
         //check if the post has fields on the meta table already
474 474
         foreach ($this->get_tables() as $table_obj) {
Please login to merge, or discard this patch.
core/db_models/EEM_Venue.model.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -25,87 +25,87 @@  discard block
 block discarded – undo
25 25
 class EEM_Venue extends EEM_CPT_Base
26 26
 {
27 27
 
28
-    // private instance of the Attendee object
29
-    protected static $_instance = null;
28
+	// private instance of the Attendee object
29
+	protected static $_instance = null;
30 30
 
31 31
 
32 32
 
33
-    protected function __construct($timezone = null)
34
-    {
35
-        $this->singular_item = __('Venue', 'event_espresso');
36
-        $this->plural_item = __('Venues', 'event_espresso');
37
-        $this->_tables = array(
38
-            'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
39
-            'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
40
-        );
41
-        $this->_fields = array(
42
-            'Venue_CPT'  => array(
43
-                'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
44
-                'VNU_name'       => new EE_Plain_Text_Field('post_title', __("Venue Name", "event_espresso"), false,
45
-                    ''),
46
-                'VNU_desc'       => new EE_Post_Content_Field('post_content', __("Venue Description", "event_espresso"),
47
-                    false, ''),
48
-                'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
49
-                'VNU_created'    => new EE_Datetime_Field('post_date', __("Date Venue Created", "event_espresso"),
50
-                    false, EE_Datetime_Field::now),
51
-                'VNU_short_desc' => new EE_Plain_Text_Field('post_excerpt',
52
-                    __("Short Description of Venue", "event_espresso"), true, ''),
53
-                'VNU_modified'   => new EE_Datetime_Field('post_modified', __("Venue Modified Date", "event_espresso"),
54
-                    false, EE_Datetime_Field::now),
55
-                'VNU_wp_user'    => new EE_WP_User_Field('post_author', __("Venue Creator ID", "event_espresso"),
56
-                    false),
57
-                'parent'         => new EE_Integer_Field('post_parent', __("Venue Parent ID", "event_espresso"), false,
58
-                    0),
59
-                'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
60
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
61
-                // EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'),
62
-            ),
63
-            'Venue_Meta' => array(
64
-                'VNUM_ID'             => new EE_DB_Only_Int_Field('VNUM_ID',
65
-                    __("ID of Venue Meta Row", "event_espresso"), false),
66
-                'VNU_ID_fk'           => new EE_DB_Only_Int_Field('VNU_ID',
67
-                    __("Foreign Key to Venue Post ", "event_espresso"), false),
68
-                'VNU_address'         => new EE_Plain_Text_Field('VNU_address',
69
-                    __("Venue Address line 1", "event_espresso"), true, ''),
70
-                'VNU_address2'        => new EE_Plain_Text_Field('VNU_address2',
71
-                    __("Venue Address line 2", "event_espresso"), true, ''),
72
-                'VNU_city'            => new EE_Plain_Text_Field('VNU_city', __("Venue City", "event_espresso"), true,
73
-                    ''),
74
-                'STA_ID'              => new EE_Foreign_Key_Int_Field('STA_ID', __("State ID", "event_espresso"), true,
75
-                    null, 'State'),
76
-                'CNT_ISO'             => new EE_Foreign_Key_String_Field('CNT_ISO',
77
-                    __("Country Code", "event_espresso"), true, null, 'Country'),
78
-                'VNU_zip'             => new EE_Plain_Text_Field('VNU_zip',
79
-                    __("Venue Zip/Postal Code", "event_espresso"), true),
80
-                'VNU_phone'           => new EE_Plain_Text_Field('VNU_phone', __("Venue Phone", "event_espresso"),
81
-                    true),
82
-                'VNU_capacity'        => new EE_Infinite_Integer_Field('VNU_capacity',
83
-                    __("Venue Capacity", "event_espresso"), true, EE_INF),
84
-                'VNU_url'             => new EE_Plain_Text_Field('VNU_url', __('Venue Website', 'event_espresso'),
85
-                    true),
86
-                'VNU_virtual_phone'   => new EE_Plain_Text_Field('VNU_virtual_phone',
87
-                    __('Call in Number', 'event_espresso'), true),
88
-                'VNU_virtual_url'     => new EE_Plain_Text_Field('VNU_virtual_url', __('Virtual URL', 'event_espresso'),
89
-                    true),
90
-                'VNU_google_map_link' => new EE_Plain_Text_Field('VNU_google_map_link',
91
-                    __('Google Map Link', 'event_espresso'), true),
92
-                'VNU_enable_for_gmap' => new EE_Boolean_Field('VNU_enable_for_gmap',
93
-                    __('Show Google Map?', 'event_espresso'), false, false),
94
-            ),
95
-        );
96
-        $this->_model_relations = array(
97
-            'Event'             => new EE_HABTM_Relation('Event_Venue'),
98
-            'State'             => new EE_Belongs_To_Relation(),
99
-            'Country'           => new EE_Belongs_To_Relation(),
100
-            'Event_Venue'       => new EE_Has_Many_Relation(),
101
-            'WP_User'           => new EE_Belongs_To_Relation(),
102
-            'Term_Relationship' => new EE_Has_Many_Relation(),
103
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
104
-        );
105
-        //this model is generally available for reading
106
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
107
-        parent::__construct($timezone);
108
-    }
33
+	protected function __construct($timezone = null)
34
+	{
35
+		$this->singular_item = __('Venue', 'event_espresso');
36
+		$this->plural_item = __('Venues', 'event_espresso');
37
+		$this->_tables = array(
38
+			'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
39
+			'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
40
+		);
41
+		$this->_fields = array(
42
+			'Venue_CPT'  => array(
43
+				'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
44
+				'VNU_name'       => new EE_Plain_Text_Field('post_title', __("Venue Name", "event_espresso"), false,
45
+					''),
46
+				'VNU_desc'       => new EE_Post_Content_Field('post_content', __("Venue Description", "event_espresso"),
47
+					false, ''),
48
+				'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
49
+				'VNU_created'    => new EE_Datetime_Field('post_date', __("Date Venue Created", "event_espresso"),
50
+					false, EE_Datetime_Field::now),
51
+				'VNU_short_desc' => new EE_Plain_Text_Field('post_excerpt',
52
+					__("Short Description of Venue", "event_espresso"), true, ''),
53
+				'VNU_modified'   => new EE_Datetime_Field('post_modified', __("Venue Modified Date", "event_espresso"),
54
+					false, EE_Datetime_Field::now),
55
+				'VNU_wp_user'    => new EE_WP_User_Field('post_author', __("Venue Creator ID", "event_espresso"),
56
+					false),
57
+				'parent'         => new EE_Integer_Field('post_parent', __("Venue Parent ID", "event_espresso"), false,
58
+					0),
59
+				'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
60
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
61
+				// EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'),
62
+			),
63
+			'Venue_Meta' => array(
64
+				'VNUM_ID'             => new EE_DB_Only_Int_Field('VNUM_ID',
65
+					__("ID of Venue Meta Row", "event_espresso"), false),
66
+				'VNU_ID_fk'           => new EE_DB_Only_Int_Field('VNU_ID',
67
+					__("Foreign Key to Venue Post ", "event_espresso"), false),
68
+				'VNU_address'         => new EE_Plain_Text_Field('VNU_address',
69
+					__("Venue Address line 1", "event_espresso"), true, ''),
70
+				'VNU_address2'        => new EE_Plain_Text_Field('VNU_address2',
71
+					__("Venue Address line 2", "event_espresso"), true, ''),
72
+				'VNU_city'            => new EE_Plain_Text_Field('VNU_city', __("Venue City", "event_espresso"), true,
73
+					''),
74
+				'STA_ID'              => new EE_Foreign_Key_Int_Field('STA_ID', __("State ID", "event_espresso"), true,
75
+					null, 'State'),
76
+				'CNT_ISO'             => new EE_Foreign_Key_String_Field('CNT_ISO',
77
+					__("Country Code", "event_espresso"), true, null, 'Country'),
78
+				'VNU_zip'             => new EE_Plain_Text_Field('VNU_zip',
79
+					__("Venue Zip/Postal Code", "event_espresso"), true),
80
+				'VNU_phone'           => new EE_Plain_Text_Field('VNU_phone', __("Venue Phone", "event_espresso"),
81
+					true),
82
+				'VNU_capacity'        => new EE_Infinite_Integer_Field('VNU_capacity',
83
+					__("Venue Capacity", "event_espresso"), true, EE_INF),
84
+				'VNU_url'             => new EE_Plain_Text_Field('VNU_url', __('Venue Website', 'event_espresso'),
85
+					true),
86
+				'VNU_virtual_phone'   => new EE_Plain_Text_Field('VNU_virtual_phone',
87
+					__('Call in Number', 'event_espresso'), true),
88
+				'VNU_virtual_url'     => new EE_Plain_Text_Field('VNU_virtual_url', __('Virtual URL', 'event_espresso'),
89
+					true),
90
+				'VNU_google_map_link' => new EE_Plain_Text_Field('VNU_google_map_link',
91
+					__('Google Map Link', 'event_espresso'), true),
92
+				'VNU_enable_for_gmap' => new EE_Boolean_Field('VNU_enable_for_gmap',
93
+					__('Show Google Map?', 'event_espresso'), false, false),
94
+			),
95
+		);
96
+		$this->_model_relations = array(
97
+			'Event'             => new EE_HABTM_Relation('Event_Venue'),
98
+			'State'             => new EE_Belongs_To_Relation(),
99
+			'Country'           => new EE_Belongs_To_Relation(),
100
+			'Event_Venue'       => new EE_Has_Many_Relation(),
101
+			'WP_User'           => new EE_Belongs_To_Relation(),
102
+			'Term_Relationship' => new EE_Has_Many_Relation(),
103
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
104
+		);
105
+		//this model is generally available for reading
106
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
107
+		parent::__construct($timezone);
108
+	}
109 109
 
110 110
 }
111 111
 // End of file EEM_Venue.model.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
  * @author                Michael Nelson
19 19
  *                        ------------------------------------------------------------------------
20 20
  */
21
-require_once(EE_MODELS . 'EEM_Base.model.php');
21
+require_once(EE_MODELS.'EEM_Base.model.php');
22 22
 
23 23
 
24 24
 
Please login to merge, or discard this patch.
core/db_classes/EE_Event.class.php 3 patches
Indentation   +1276 added lines, -1276 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,1368 +14,1368 @@  discard block
 block discarded – undo
14 14
 class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event
15 15
 {
16 16
 
17
-    /**
18
-     * cached value for the the logical active status for the event
19
-     *
20
-     * @see get_active_status()
21
-     * @var string
22
-     */
23
-    protected $_active_status = '';
24
-
25
-    /**
26
-     * This is just used for caching the Primary Datetime for the Event on initial retrieval
27
-     *
28
-     * @var EE_Datetime
29
-     */
30
-    protected $_Primary_Datetime;
31
-
32
-
33
-
34
-    /**
35
-     * @param array  $props_n_values          incoming values
36
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
37
-     *                                        used.)
38
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
39
-     *                                        date_format and the second value is the time format
40
-     * @return EE_Event
41
-     */
42
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
43
-    {
44
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
45
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
46
-    }
47
-
48
-
49
-
50
-    /**
51
-     * @param array  $props_n_values  incoming values from the database
52
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
53
-     *                                the website will be used.
54
-     * @return EE_Event
55
-     */
56
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
57
-    {
58
-        return new self($props_n_values, true, $timezone);
59
-    }
60
-
61
-
62
-
63
-    /**
64
-     * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
65
-     *
66
-     * @param string $field_name
67
-     * @param mixed  $field_value
68
-     * @param bool   $use_default
69
-     */
70
-    public function set($field_name, $field_value, $use_default = false)
71
-    {
72
-        switch ($field_name) {
73
-            case 'status' :
74
-                $this->set_status($field_value, $use_default);
75
-                break;
76
-            default :
77
-                parent::set($field_name, $field_value, $use_default);
78
-        }
79
-    }
80
-
81
-
82
-
83
-    /**
84
-     *    set_status
85
-     * Checks if event status is being changed to SOLD OUT
86
-     * and updates event meta data with previous event status
87
-     * so that we can revert things if/when the event is no longer sold out
88
-     *
89
-     * @access public
90
-     * @param string $new_status
91
-     * @param bool   $use_default
92
-     * @return bool|void
93
-     * @throws \EE_Error
94
-     */
95
-    public function set_status($new_status = null, $use_default = false)
96
-    {
97
-        // get current Event status
98
-        $old_status = $this->status();
99
-        // if status has changed
100
-        if ($old_status != $new_status) {
101
-            // TO sold_out
102
-            if ($new_status == EEM_Event::sold_out) {
103
-                // save the previous event status so that we can revert if the event is no longer sold out
104
-                $this->add_post_meta('_previous_event_status', $old_status);
105
-                do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
106
-                // OR FROM  sold_out
107
-            } else if ($old_status == EEM_Event::sold_out) {
108
-                $this->delete_post_meta('_previous_event_status');
109
-                do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
110
-            }
111
-            // update status
112
-            parent::set('status', $new_status, $use_default);
113
-            do_action('AHEE__EE_Event__set_status__after_update', $this);
114
-            return true;
115
-        } else {
116
-            // even though the old value matches the new value, it's still good to
117
-            // allow the parent set method to have a say
118
-            parent::set('status', $new_status, $use_default);
119
-            return true;
120
-        }
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * Gets all the datetimes for this event
127
-     *
128
-     * @param array $query_params like EEM_Base::get_all
129
-     * @return EE_Datetime[]
130
-     */
131
-    public function datetimes($query_params = array())
132
-    {
133
-        return $this->get_many_related('Datetime', $query_params);
134
-    }
135
-
136
-
137
-
138
-    /**
139
-     * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
140
-     *
141
-     * @return EE_Datetime[]
142
-     */
143
-    public function datetimes_in_chronological_order()
144
-    {
145
-        return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
152
-     * @darren, we should probably UNSET timezone on the EEM_Datetime model
153
-     * after running our query, so that this timezone isn't set for EVERY query
154
-     * on EEM_Datetime for the rest of the request, no?
155
-     *
156
-     * @param boolean $show_expired whether or not to include expired events
157
-     * @param boolean $show_deleted whether or not to include deleted events
158
-     * @param null    $limit
159
-     * @return \EE_Datetime[]
160
-     * @throws \EE_Error
161
-     */
162
-    public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
163
-    {
164
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
165
-            $this->ID(),
166
-            $show_expired,
167
-            $show_deleted,
168
-            $limit
169
-        );
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Returns one related datetime. Mostly only used by some legacy code.
176
-     *
177
-     * @return EE_Datetime
178
-     */
179
-    public function first_datetime()
180
-    {
181
-        return $this->get_first_related('Datetime');
182
-    }
183
-
184
-
185
-
186
-    /**
187
-     * Returns the 'primary' datetime for the event
188
-     *
189
-     * @param bool $try_to_exclude_expired
190
-     * @param bool $try_to_exclude_deleted
191
-     * @return EE_Datetime
192
-     */
193
-    public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
194
-    {
195
-        if ( ! empty ($this->_Primary_Datetime)) {
196
-            return $this->_Primary_Datetime;
197
-        }
198
-        $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)
199
-                                               ->get_primary_datetime_for_event($this->ID(), $try_to_exclude_expired,
200
-                                                   $try_to_exclude_deleted);
201
-        return $this->_Primary_Datetime;
202
-    }
203
-
204
-
205
-
206
-    /**
207
-     * Gets all the tickets available for purchase of this event
208
-     *
209
-     * @param array $query_params like EEM_Base::get_all
210
-     * @return EE_Ticket[]
211
-     */
212
-    public function tickets($query_params = array())
213
-    {
214
-        //first get all datetimes
215
-        $datetimes = $this->datetimes_ordered();
216
-        if ( ! $datetimes) {
217
-            return array();
218
-        }
219
-        $datetime_ids = array();
220
-        foreach ($datetimes as $datetime) {
221
-            $datetime_ids[] = $datetime->ID();
222
-        }
223
-        $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
224
-        //if incoming $query_params has where conditions let's merge but not override existing.
225
-        if (is_array($query_params) && isset($query_params[0])) {
226
-            $where_params = array_merge($query_params[0], $where_params);
227
-            unset($query_params[0]);
228
-        }
229
-        //now add $where_params to $query_params
230
-        $query_params[0] = $where_params;
231
-        return EEM_Ticket::instance()->get_all($query_params);
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * @return bool
238
-     */
239
-    public function additional_limit()
240
-    {
241
-        return $this->get('EVT_additional_limit');
242
-    }
243
-
244
-
245
-
246
-    /**
247
-     * @return bool
248
-     */
249
-    public function allow_overflow()
250
-    {
251
-        return $this->get('EVT_allow_overflow');
252
-    }
253
-
254
-
255
-
256
-    /**
257
-     * @return bool
258
-     */
259
-    public function created()
260
-    {
261
-        return $this->get('EVT_created');
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     * @return bool
268
-     */
269
-    public function description()
270
-    {
271
-        return $this->get('EVT_desc');
272
-    }
273
-
274
-
275
-
276
-    /**
277
-     * Runs do_shortcode and wpautop on the description
278
-     *
279
-     * @return string of html
280
-     */
281
-    public function description_filtered()
282
-    {
283
-        return $this->get_pretty('EVT_desc');
284
-    }
285
-
286
-
287
-
288
-    /**
289
-     * @return bool
290
-     */
291
-    public function display_description()
292
-    {
293
-        return $this->get('EVT_display_desc');
294
-    }
295
-
296
-
297
-
298
-    /**
299
-     * @return bool
300
-     */
301
-    public function display_ticket_selector()
302
-    {
303
-        return (bool)$this->get('EVT_display_ticket_selector');
304
-    }
305
-
17
+	/**
18
+	 * cached value for the the logical active status for the event
19
+	 *
20
+	 * @see get_active_status()
21
+	 * @var string
22
+	 */
23
+	protected $_active_status = '';
24
+
25
+	/**
26
+	 * This is just used for caching the Primary Datetime for the Event on initial retrieval
27
+	 *
28
+	 * @var EE_Datetime
29
+	 */
30
+	protected $_Primary_Datetime;
31
+
32
+
33
+
34
+	/**
35
+	 * @param array  $props_n_values          incoming values
36
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
37
+	 *                                        used.)
38
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
39
+	 *                                        date_format and the second value is the time format
40
+	 * @return EE_Event
41
+	 */
42
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
43
+	{
44
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
45
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
46
+	}
47
+
48
+
49
+
50
+	/**
51
+	 * @param array  $props_n_values  incoming values from the database
52
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
53
+	 *                                the website will be used.
54
+	 * @return EE_Event
55
+	 */
56
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
57
+	{
58
+		return new self($props_n_values, true, $timezone);
59
+	}
60
+
61
+
62
+
63
+	/**
64
+	 * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods
65
+	 *
66
+	 * @param string $field_name
67
+	 * @param mixed  $field_value
68
+	 * @param bool   $use_default
69
+	 */
70
+	public function set($field_name, $field_value, $use_default = false)
71
+	{
72
+		switch ($field_name) {
73
+			case 'status' :
74
+				$this->set_status($field_value, $use_default);
75
+				break;
76
+			default :
77
+				parent::set($field_name, $field_value, $use_default);
78
+		}
79
+	}
80
+
81
+
82
+
83
+	/**
84
+	 *    set_status
85
+	 * Checks if event status is being changed to SOLD OUT
86
+	 * and updates event meta data with previous event status
87
+	 * so that we can revert things if/when the event is no longer sold out
88
+	 *
89
+	 * @access public
90
+	 * @param string $new_status
91
+	 * @param bool   $use_default
92
+	 * @return bool|void
93
+	 * @throws \EE_Error
94
+	 */
95
+	public function set_status($new_status = null, $use_default = false)
96
+	{
97
+		// get current Event status
98
+		$old_status = $this->status();
99
+		// if status has changed
100
+		if ($old_status != $new_status) {
101
+			// TO sold_out
102
+			if ($new_status == EEM_Event::sold_out) {
103
+				// save the previous event status so that we can revert if the event is no longer sold out
104
+				$this->add_post_meta('_previous_event_status', $old_status);
105
+				do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status);
106
+				// OR FROM  sold_out
107
+			} else if ($old_status == EEM_Event::sold_out) {
108
+				$this->delete_post_meta('_previous_event_status');
109
+				do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status);
110
+			}
111
+			// update status
112
+			parent::set('status', $new_status, $use_default);
113
+			do_action('AHEE__EE_Event__set_status__after_update', $this);
114
+			return true;
115
+		} else {
116
+			// even though the old value matches the new value, it's still good to
117
+			// allow the parent set method to have a say
118
+			parent::set('status', $new_status, $use_default);
119
+			return true;
120
+		}
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * Gets all the datetimes for this event
127
+	 *
128
+	 * @param array $query_params like EEM_Base::get_all
129
+	 * @return EE_Datetime[]
130
+	 */
131
+	public function datetimes($query_params = array())
132
+	{
133
+		return $this->get_many_related('Datetime', $query_params);
134
+	}
135
+
136
+
137
+
138
+	/**
139
+	 * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order
140
+	 *
141
+	 * @return EE_Datetime[]
142
+	 */
143
+	public function datetimes_in_chronological_order()
144
+	{
145
+		return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC')));
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * Gets all the datetimes for this event, ordered by the DTT_order on the datetime.
152
+	 * @darren, we should probably UNSET timezone on the EEM_Datetime model
153
+	 * after running our query, so that this timezone isn't set for EVERY query
154
+	 * on EEM_Datetime for the rest of the request, no?
155
+	 *
156
+	 * @param boolean $show_expired whether or not to include expired events
157
+	 * @param boolean $show_deleted whether or not to include deleted events
158
+	 * @param null    $limit
159
+	 * @return \EE_Datetime[]
160
+	 * @throws \EE_Error
161
+	 */
162
+	public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null)
163
+	{
164
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order(
165
+			$this->ID(),
166
+			$show_expired,
167
+			$show_deleted,
168
+			$limit
169
+		);
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Returns one related datetime. Mostly only used by some legacy code.
176
+	 *
177
+	 * @return EE_Datetime
178
+	 */
179
+	public function first_datetime()
180
+	{
181
+		return $this->get_first_related('Datetime');
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * Returns the 'primary' datetime for the event
188
+	 *
189
+	 * @param bool $try_to_exclude_expired
190
+	 * @param bool $try_to_exclude_deleted
191
+	 * @return EE_Datetime
192
+	 */
193
+	public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true)
194
+	{
195
+		if ( ! empty ($this->_Primary_Datetime)) {
196
+			return $this->_Primary_Datetime;
197
+		}
198
+		$this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)
199
+											   ->get_primary_datetime_for_event($this->ID(), $try_to_exclude_expired,
200
+												   $try_to_exclude_deleted);
201
+		return $this->_Primary_Datetime;
202
+	}
203
+
204
+
205
+
206
+	/**
207
+	 * Gets all the tickets available for purchase of this event
208
+	 *
209
+	 * @param array $query_params like EEM_Base::get_all
210
+	 * @return EE_Ticket[]
211
+	 */
212
+	public function tickets($query_params = array())
213
+	{
214
+		//first get all datetimes
215
+		$datetimes = $this->datetimes_ordered();
216
+		if ( ! $datetimes) {
217
+			return array();
218
+		}
219
+		$datetime_ids = array();
220
+		foreach ($datetimes as $datetime) {
221
+			$datetime_ids[] = $datetime->ID();
222
+		}
223
+		$where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids));
224
+		//if incoming $query_params has where conditions let's merge but not override existing.
225
+		if (is_array($query_params) && isset($query_params[0])) {
226
+			$where_params = array_merge($query_params[0], $where_params);
227
+			unset($query_params[0]);
228
+		}
229
+		//now add $where_params to $query_params
230
+		$query_params[0] = $where_params;
231
+		return EEM_Ticket::instance()->get_all($query_params);
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * @return bool
238
+	 */
239
+	public function additional_limit()
240
+	{
241
+		return $this->get('EVT_additional_limit');
242
+	}
243
+
244
+
245
+
246
+	/**
247
+	 * @return bool
248
+	 */
249
+	public function allow_overflow()
250
+	{
251
+		return $this->get('EVT_allow_overflow');
252
+	}
253
+
254
+
255
+
256
+	/**
257
+	 * @return bool
258
+	 */
259
+	public function created()
260
+	{
261
+		return $this->get('EVT_created');
262
+	}
263
+
264
+
265
+
266
+	/**
267
+	 * @return bool
268
+	 */
269
+	public function description()
270
+	{
271
+		return $this->get('EVT_desc');
272
+	}
273
+
274
+
275
+
276
+	/**
277
+	 * Runs do_shortcode and wpautop on the description
278
+	 *
279
+	 * @return string of html
280
+	 */
281
+	public function description_filtered()
282
+	{
283
+		return $this->get_pretty('EVT_desc');
284
+	}
285
+
286
+
287
+
288
+	/**
289
+	 * @return bool
290
+	 */
291
+	public function display_description()
292
+	{
293
+		return $this->get('EVT_display_desc');
294
+	}
295
+
296
+
297
+
298
+	/**
299
+	 * @return bool
300
+	 */
301
+	public function display_ticket_selector()
302
+	{
303
+		return (bool)$this->get('EVT_display_ticket_selector');
304
+	}
305
+
306 306
 
307 307
 
308
-    /**
309
-     * @return bool
310
-     */
311
-    public function external_url()
312
-    {
313
-        return $this->get('EVT_external_URL');
314
-    }
308
+	/**
309
+	 * @return bool
310
+	 */
311
+	public function external_url()
312
+	{
313
+		return $this->get('EVT_external_URL');
314
+	}
315 315
 
316 316
 
317 317
 
318
-    /**
319
-     * @return bool
320
-     */
321
-    public function member_only()
322
-    {
323
-        return $this->get('EVT_member_only');
324
-    }
318
+	/**
319
+	 * @return bool
320
+	 */
321
+	public function member_only()
322
+	{
323
+		return $this->get('EVT_member_only');
324
+	}
325 325
 
326 326
 
327 327
 
328
-    /**
329
-     * @return bool
330
-     */
331
-    public function phone()
332
-    {
333
-        return $this->get('EVT_phone');
334
-    }
328
+	/**
329
+	 * @return bool
330
+	 */
331
+	public function phone()
332
+	{
333
+		return $this->get('EVT_phone');
334
+	}
335 335
 
336 336
 
337 337
 
338
-    /**
339
-     * @return bool
340
-     */
341
-    public function modified()
342
-    {
343
-        return $this->get('EVT_modified');
344
-    }
338
+	/**
339
+	 * @return bool
340
+	 */
341
+	public function modified()
342
+	{
343
+		return $this->get('EVT_modified');
344
+	}
345 345
 
346 346
 
347 347
 
348
-    /**
349
-     * @return bool
350
-     */
351
-    public function name()
352
-    {
353
-        return $this->get('EVT_name');
354
-    }
348
+	/**
349
+	 * @return bool
350
+	 */
351
+	public function name()
352
+	{
353
+		return $this->get('EVT_name');
354
+	}
355 355
 
356 356
 
357 357
 
358
-    /**
359
-     * @return bool
360
-     */
361
-    public function order()
362
-    {
363
-        return $this->get('EVT_order');
364
-    }
358
+	/**
359
+	 * @return bool
360
+	 */
361
+	public function order()
362
+	{
363
+		return $this->get('EVT_order');
364
+	}
365 365
 
366 366
 
367 367
 
368
-    /**
369
-     * @return bool|string
370
-     */
371
-    public function default_registration_status()
372
-    {
373
-        $event_default_registration_status = $this->get('EVT_default_registration_status');
374
-        return ! empty($event_default_registration_status) ? $event_default_registration_status
375
-            : EE_Registry::instance()->CFG->registration->default_STS_ID;
376
-    }
368
+	/**
369
+	 * @return bool|string
370
+	 */
371
+	public function default_registration_status()
372
+	{
373
+		$event_default_registration_status = $this->get('EVT_default_registration_status');
374
+		return ! empty($event_default_registration_status) ? $event_default_registration_status
375
+			: EE_Registry::instance()->CFG->registration->default_STS_ID;
376
+	}
377 377
 
378 378
 
379 379
 
380
-    /**
381
-     * @param int  $num_words
382
-     * @param null $more
383
-     * @param bool $not_full_desc
384
-     * @return bool|string
385
-     */
386
-    public function short_description($num_words = 55, $more = null, $not_full_desc = false)
387
-    {
388
-        $short_desc = $this->get('EVT_short_desc');
389
-        if ( ! empty($short_desc) || $not_full_desc) {
390
-            return $short_desc;
391
-        } else {
392
-            $full_desc = $this->get('EVT_desc');
393
-            return wp_trim_words($full_desc, $num_words, $more);
394
-        }
395
-    }
380
+	/**
381
+	 * @param int  $num_words
382
+	 * @param null $more
383
+	 * @param bool $not_full_desc
384
+	 * @return bool|string
385
+	 */
386
+	public function short_description($num_words = 55, $more = null, $not_full_desc = false)
387
+	{
388
+		$short_desc = $this->get('EVT_short_desc');
389
+		if ( ! empty($short_desc) || $not_full_desc) {
390
+			return $short_desc;
391
+		} else {
392
+			$full_desc = $this->get('EVT_desc');
393
+			return wp_trim_words($full_desc, $num_words, $more);
394
+		}
395
+	}
396 396
 
397 397
 
398 398
 
399
-    /**
400
-     * @return bool
401
-     */
402
-    public function slug()
403
-    {
404
-        return $this->get('EVT_slug');
405
-    }
399
+	/**
400
+	 * @return bool
401
+	 */
402
+	public function slug()
403
+	{
404
+		return $this->get('EVT_slug');
405
+	}
406 406
 
407 407
 
408 408
 
409
-    /**
410
-     * @return bool
411
-     */
412
-    public function timezone_string()
413
-    {
414
-        return $this->get('EVT_timezone_string');
415
-    }
409
+	/**
410
+	 * @return bool
411
+	 */
412
+	public function timezone_string()
413
+	{
414
+		return $this->get('EVT_timezone_string');
415
+	}
416 416
 
417 417
 
418 418
 
419
-    /**
420
-     * @return bool
421
-     */
422
-    public function visible_on()
423
-    {
424
-        return $this->get('EVT_visible_on');
425
-    }
419
+	/**
420
+	 * @return bool
421
+	 */
422
+	public function visible_on()
423
+	{
424
+		return $this->get('EVT_visible_on');
425
+	}
426 426
 
427 427
 
428 428
 
429
-    /**
430
-     * @return int
431
-     */
432
-    public function wp_user()
433
-    {
434
-        return $this->get('EVT_wp_user');
435
-    }
429
+	/**
430
+	 * @return int
431
+	 */
432
+	public function wp_user()
433
+	{
434
+		return $this->get('EVT_wp_user');
435
+	}
436 436
 
437 437
 
438 438
 
439
-    /**
440
-     * @return bool
441
-     */
442
-    public function donations()
443
-    {
444
-        return $this->get('EVT_donations');
445
-    }
439
+	/**
440
+	 * @return bool
441
+	 */
442
+	public function donations()
443
+	{
444
+		return $this->get('EVT_donations');
445
+	}
446 446
 
447 447
 
448 448
 
449
-    /**
450
-     * @param $limit
451
-     */
452
-    public function set_additional_limit($limit)
453
-    {
454
-        $this->set('EVT_additional_limit', $limit);
455
-    }
449
+	/**
450
+	 * @param $limit
451
+	 */
452
+	public function set_additional_limit($limit)
453
+	{
454
+		$this->set('EVT_additional_limit', $limit);
455
+	}
456 456
 
457 457
 
458 458
 
459
-    /**
460
-     * @param $created
461
-     */
462
-    public function set_created($created)
463
-    {
464
-        $this->set('EVT_created', $created);
465
-    }
459
+	/**
460
+	 * @param $created
461
+	 */
462
+	public function set_created($created)
463
+	{
464
+		$this->set('EVT_created', $created);
465
+	}
466 466
 
467 467
 
468 468
 
469
-    /**
470
-     * @param $desc
471
-     */
472
-    public function set_description($desc)
473
-    {
474
-        $this->set('EVT_desc', $desc);
475
-    }
469
+	/**
470
+	 * @param $desc
471
+	 */
472
+	public function set_description($desc)
473
+	{
474
+		$this->set('EVT_desc', $desc);
475
+	}
476 476
 
477 477
 
478 478
 
479
-    /**
480
-     * @param $display_desc
481
-     */
482
-    public function set_display_description($display_desc)
483
-    {
484
-        $this->set('EVT_display_desc', $display_desc);
485
-    }
479
+	/**
480
+	 * @param $display_desc
481
+	 */
482
+	public function set_display_description($display_desc)
483
+	{
484
+		$this->set('EVT_display_desc', $display_desc);
485
+	}
486 486
 
487 487
 
488 488
 
489
-    /**
490
-     * @param $display_ticket_selector
491
-     */
492
-    public function set_display_ticket_selector($display_ticket_selector)
493
-    {
494
-        $this->set('EVT_display_ticket_selector', $display_ticket_selector);
495
-    }
489
+	/**
490
+	 * @param $display_ticket_selector
491
+	 */
492
+	public function set_display_ticket_selector($display_ticket_selector)
493
+	{
494
+		$this->set('EVT_display_ticket_selector', $display_ticket_selector);
495
+	}
496 496
 
497 497
 
498 498
 
499
-    /**
500
-     * @param $external_url
501
-     */
502
-    public function set_external_url($external_url)
503
-    {
504
-        $this->set('EVT_external_URL', $external_url);
505
-    }
499
+	/**
500
+	 * @param $external_url
501
+	 */
502
+	public function set_external_url($external_url)
503
+	{
504
+		$this->set('EVT_external_URL', $external_url);
505
+	}
506 506
 
507 507
 
508 508
 
509
-    /**
510
-     * @param $member_only
511
-     */
512
-    public function set_member_only($member_only)
513
-    {
514
-        $this->set('EVT_member_only', $member_only);
515
-    }
509
+	/**
510
+	 * @param $member_only
511
+	 */
512
+	public function set_member_only($member_only)
513
+	{
514
+		$this->set('EVT_member_only', $member_only);
515
+	}
516 516
 
517 517
 
518 518
 
519
-    /**
520
-     * @param $event_phone
521
-     */
522
-    public function set_event_phone($event_phone)
523
-    {
524
-        $this->set('EVT_phone', $event_phone);
525
-    }
519
+	/**
520
+	 * @param $event_phone
521
+	 */
522
+	public function set_event_phone($event_phone)
523
+	{
524
+		$this->set('EVT_phone', $event_phone);
525
+	}
526 526
 
527 527
 
528 528
 
529
-    /**
530
-     * @param $modified
531
-     */
532
-    public function set_modified($modified)
533
-    {
534
-        $this->set('EVT_modified', $modified);
535
-    }
529
+	/**
530
+	 * @param $modified
531
+	 */
532
+	public function set_modified($modified)
533
+	{
534
+		$this->set('EVT_modified', $modified);
535
+	}
536 536
 
537 537
 
538 538
 
539
-    /**
540
-     * @param $name
541
-     */
542
-    public function set_name($name)
543
-    {
544
-        $this->set('EVT_name', $name);
545
-    }
539
+	/**
540
+	 * @param $name
541
+	 */
542
+	public function set_name($name)
543
+	{
544
+		$this->set('EVT_name', $name);
545
+	}
546 546
 
547 547
 
548 548
 
549
-    /**
550
-     * @param $order
551
-     */
552
-    public function set_order($order)
553
-    {
554
-        $this->set('EVT_order', $order);
555
-    }
549
+	/**
550
+	 * @param $order
551
+	 */
552
+	public function set_order($order)
553
+	{
554
+		$this->set('EVT_order', $order);
555
+	}
556 556
 
557 557
 
558 558
 
559
-    /**
560
-     * @param $short_desc
561
-     */
562
-    public function set_short_description($short_desc)
563
-    {
564
-        $this->set('EVT_short_desc', $short_desc);
565
-    }
559
+	/**
560
+	 * @param $short_desc
561
+	 */
562
+	public function set_short_description($short_desc)
563
+	{
564
+		$this->set('EVT_short_desc', $short_desc);
565
+	}
566 566
 
567 567
 
568 568
 
569
-    /**
570
-     * @param $slug
571
-     */
572
-    public function set_slug($slug)
573
-    {
574
-        $this->set('EVT_slug', $slug);
575
-    }
569
+	/**
570
+	 * @param $slug
571
+	 */
572
+	public function set_slug($slug)
573
+	{
574
+		$this->set('EVT_slug', $slug);
575
+	}
576 576
 
577 577
 
578 578
 
579
-    /**
580
-     * @param $timezone_string
581
-     */
582
-    public function set_timezone_string($timezone_string)
583
-    {
584
-        $this->set('EVT_timezone_string', $timezone_string);
585
-    }
579
+	/**
580
+	 * @param $timezone_string
581
+	 */
582
+	public function set_timezone_string($timezone_string)
583
+	{
584
+		$this->set('EVT_timezone_string', $timezone_string);
585
+	}
586 586
 
587 587
 
588 588
 
589
-    /**
590
-     * @param $visible_on
591
-     */
592
-    public function set_visible_on($visible_on)
593
-    {
594
-        $this->set('EVT_visible_on', $visible_on);
595
-    }
589
+	/**
590
+	 * @param $visible_on
591
+	 */
592
+	public function set_visible_on($visible_on)
593
+	{
594
+		$this->set('EVT_visible_on', $visible_on);
595
+	}
596 596
 
597 597
 
598 598
 
599
-    /**
600
-     * @param $wp_user
601
-     */
602
-    public function set_wp_user($wp_user)
603
-    {
604
-        $this->set('EVT_wp_user', $wp_user);
605
-    }
599
+	/**
600
+	 * @param $wp_user
601
+	 */
602
+	public function set_wp_user($wp_user)
603
+	{
604
+		$this->set('EVT_wp_user', $wp_user);
605
+	}
606 606
 
607 607
 
608
-
609
-    /**
610
-     * @param $default_registration_status
611
-     */
612
-    public function set_default_registration_status($default_registration_status)
613
-    {
614
-        $this->set('EVT_default_registration_status', $default_registration_status);
615
-    }
616
-
617
-
618
-
619
-    /**
620
-     * @param $donations
621
-     */
622
-    public function set_donations($donations)
623
-    {
624
-        $this->set('EVT_donations', $donations);
625
-    }
626
-
627
-
628
-
629
-    /**
630
-     * Adds a venue to this event
631
-     *
632
-     * @param EE_Venue /int $venue_id_or_obj
633
-     * @return EE_Venue
634
-     */
635
-    public function add_venue($venue_id_or_obj)
636
-    {
637
-        return $this->_add_relation_to($venue_id_or_obj, 'Venue');
638
-    }
639
-
640
-
641
-
642
-    /**
643
-     * Removes a venue from the event
644
-     *
645
-     * @param EE_Venue /int $venue_id_or_obj
646
-     * @return EE_Venue
647
-     */
648
-    public function remove_venue($venue_id_or_obj)
649
-    {
650
-        return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
651
-    }
652
-
653
-
654
-
655
-    /**
656
-     * Gets all the venues related ot the event. May provide additional $query_params if desired
657
-     *
658
-     * @param array $query_params like EEM_Base::get_all's $query_params
659
-     * @return EE_Venue[]
660
-     */
661
-    public function venues($query_params = array())
662
-    {
663
-        return $this->get_many_related('Venue', $query_params);
664
-    }
665
-
666
-
667
-
668
-    /**
669
-     * check if event id is present and if event is published
670
-     *
671
-     * @access public
672
-     * @return boolean true yes, false no
673
-     */
674
-    private function _has_ID_and_is_published()
675
-    {
676
-        // first check if event id is present and not NULL, then check if this event is published (or any of the equivalent "published" statuses)
677
-        return ($this->ID() && $this->ID() !== null
678
-                && ($this->status() == 'publish'
679
-                    || $this->status()
680
-                       == EEM_Event::sold_out
681
-                    || $this->status() == EEM_Event::postponed
682
-                    || $this->status() == EEM_Event::cancelled)) ? true : false;
683
-    }
684
-
685
-
686
-
687
-    /**
688
-     * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
689
-     *
690
-     * @access public
691
-     * @return boolean true yes, false no
692
-     */
693
-    public function is_upcoming()
694
-    {
695
-        // check if event id is present and if this event is published
696
-        if ($this->is_inactive()) {
697
-            return false;
698
-        }
699
-        // set initial value
700
-        $upcoming = false;
701
-        //next let's get all datetimes and loop through them
702
-        $datetimes = $this->datetimes_in_chronological_order();
703
-        foreach ($datetimes as $datetime) {
704
-            if ($datetime instanceof EE_Datetime) {
705
-                //if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
706
-                if ($datetime->is_expired()) {
707
-                    continue;
708
-                }
709
-                //if this dtt is active then we return false.
710
-                if ($datetime->is_active()) {
711
-                    return false;
712
-                }
713
-                //otherwise let's check upcoming status
714
-                $upcoming = $datetime->is_upcoming();
715
-            }
716
-        }
717
-        return $upcoming;
718
-    }
719
-
720
-
721
-
722
-    /**
723
-     * @return bool
724
-     */
725
-    public function is_active()
726
-    {
727
-        // check if event id is present and if this event is published
728
-        if ($this->is_inactive()) {
729
-            return false;
730
-        }
731
-        // set initial value
732
-        $active = false;
733
-        //next let's get all datetimes and loop through them
734
-        $datetimes = $this->datetimes_in_chronological_order();
735
-        foreach ($datetimes as $datetime) {
736
-            if ($datetime instanceof EE_Datetime) {
737
-                //if this dtt is expired then we continue cause one of the other datetimes might be active.
738
-                if ($datetime->is_expired()) {
739
-                    continue;
740
-                }
741
-                //if this dtt is upcoming then we return false.
742
-                if ($datetime->is_upcoming()) {
743
-                    return false;
744
-                }
745
-                //otherwise let's check active status
746
-                $active = $datetime->is_active();
747
-            }
748
-        }
749
-        return $active;
750
-    }
751
-
752
-
753
-
754
-    /**
755
-     * @return bool
756
-     */
757
-    public function is_expired()
758
-    {
759
-        // check if event id is present and if this event is published
760
-        if ($this->is_inactive()) {
761
-            return false;
762
-        }
763
-        // set initial value
764
-        $expired = false;
765
-        //first let's get all datetimes and loop through them
766
-        $datetimes = $this->datetimes_in_chronological_order();
767
-        foreach ($datetimes as $datetime) {
768
-            if ($datetime instanceof EE_Datetime) {
769
-                //if this dtt is upcoming or active then we return false.
770
-                if ($datetime->is_upcoming() || $datetime->is_active()) {
771
-                    return false;
772
-                }
773
-                //otherwise let's check active status
774
-                $expired = $datetime->is_expired();
775
-            }
776
-        }
777
-        return $expired;
778
-    }
779
-
780
-
781
-
782
-    /**
783
-     * @return bool
784
-     */
785
-    public function is_inactive()
786
-    {
787
-        // check if event id is present and if this event is published
788
-        if ($this->_has_ID_and_is_published()) {
789
-            return false;
790
-        }
791
-        return true;
792
-    }
793
-
794
-
795
-
796
-    /**
797
-     *    perform_sold_out_status_check
798
-     *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
799
-     *    available... if NOT, then the event status will get toggled to 'sold_out'
800
-     *
801
-     * @access public
802
-     * @return bool    return the ACTUAL sold out state.
803
-     */
804
-    public function perform_sold_out_status_check()
805
-    {
806
-        // get all unexpired untrashed tickets
807
-        $tickets = $this->tickets(array(
808
-            array(
809
-                'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
810
-                'TKT_deleted'  => false,
811
-            ),
812
-        ));
813
-        // if all the tickets are just expired, then don't update the event status to sold out
814
-        if (empty($tickets)) {
815
-            return true;
816
-        }
817
-        // set initial value
818
-        $spaces_remaining = 0;
819
-        foreach ($tickets as $ticket) {
820
-            if ($ticket instanceof EE_Ticket) {
821
-                $spaces_remaining += $ticket->qty('saleable');
822
-            }
823
-        }
824
-        if ($spaces_remaining === 0) {
825
-            $this->set_status(EEM_Event::sold_out);
826
-            if ( ! is_admin() || (is_admin() && defined('DOING_AJAX'))) {
827
-                $this->save();
828
-            }
829
-            $sold_out = true;
830
-        } else {
831
-            $sold_out = false;
832
-            // was event previously marked as sold out ?
833
-            if ($this->status() == EEM_Event::sold_out) {
834
-                // revert status to previous value, if it was set
835
-                $previous_event_status = $this->get_post_meta('_previous_event_status', true);
836
-                if ($previous_event_status) {
837
-                    $this->set_status($previous_event_status);
838
-                }
839
-            }
840
-        }
841
-        //note: I considered changing the EEM_Event status away from sold_out if this status check reveals that it's no longer sold out (yet the status is still set as sold out) but the problem is... what do we change the status BACK to?  We can't always assume that the previous event status was 'published' because this status check is always done in the admin and its entirely possible the event admin manually changes to sold_out status from some other status.  We also don't want a draft event to become a "publish event" because the sold out check reveals its NOT sold out.
842
-        // So I'll forgo the automatic switch away from sold out status for now and instead just return the $sold out status... so this check can be used to validate the TRUE sold out status regardless of what the Event status is set to.
843
-        return $sold_out;
844
-    }
845
-
846
-
847
-
848
-    /**
849
-     * This returns the total remaining spaces for sale on this event.
850
-     * ############################
851
-     * VERY IMPORTANT FOR DEVELOPERS:
852
-     * While included here, this method is still being tested internally, so its signature and behaviour COULD change.
853
-     * While this comment block is in place, usage is at your own risk and know that it may change in future builds.
854
-     * ############################
855
-     *
856
-     * @uses EE_Event::total_available_spaces()
857
-     * @return float|int  (EE_INF is returned as float)
858
-     */
859
-    public function spaces_remaining_for_sale()
860
-    {
861
-        //first get total available spaces including consideration for tickets that have already sold.
862
-        $spaces_available = $this->total_available_spaces(true);
863
-        //if total available = 0, then exit right away because that means everything is expired.
864
-        if ($spaces_available === 0) {
865
-            return 0;
866
-        }
867
-        //subtract total approved registrations from spaces available to get how many are remaining.
868
-        $spots_taken = EEM_Registration::instance()->count(array(
869
-            array(
870
-                'EVT_ID' => $this->ID(),
871
-                'STS_ID' => EEM_Registration::status_id_approved,
872
-            ),
873
-        ), 'REG_ID', true);
874
-        $spaces_remaining = $spaces_available - $spots_taken;
875
-        return $spaces_remaining > 0 ? $spaces_remaining : 0;
876
-    }
877
-
878
-
879
-
880
-    /**
881
-     * This returns the total spaces available for an event while considering all the qtys on the tickets and the reg
882
-     * limits on the datetimes attached to this event.
883
-     * ############################
884
-     * VERY IMPORTANT FOR DEVELOPERS:
885
-     * While included here, this method is still being tested internally, so its signature and behaviour COULD change.
886
-     * While this comment block is in place, usage is at your own risk and know that it may change in future builds.
887
-     * ############################
888
-     * Note: by "spaces available" we are not returning how many spaces remain.  That is a calculation involving using
889
-     * the value from this method and subtracting the approved registrations for the event.
890
-     *
891
-     * @param   bool $current_total_available       Whether to consider any tickets that have already sold in our
892
-     *                                              calculation. If this is false, then we return the most tickets that
893
-     *                                              could ever be sold for this event with the datetime and tickets
894
-     *                                              setup on the event under optimal selling conditions.  Otherwise we
895
-     *                                              return a live calculation of spaces available based on tickets
896
-     *                                              sold.  Depending on setup and stage of sales, this may appear to
897
-     *                                              equal remaining tickets.  However, the more tickets are sold out,
898
-     *                                              the more accurate the "live" total is.
899
-     * @return  int|float  (Note: if EE_INF is returned its considered a float by PHP)
900
-     */
901
-    public function total_available_spaces($current_total_available = false)
902
-    {
903
-        $spaces_available = 0;
904
-        //first get all tickets on the event and include expired tickets
905
-        $tickets = $this->tickets(array('default_where_conditions' => 'none'));
906
-        $ticket_sums = array();
907
-        $datetime_limits = array();
908
-        //loop through tickets and normalize them
909
-        foreach ($tickets as $ticket) {
910
-            $datetimes = $ticket->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC')));
911
-            if (empty($datetimes)) {
912
-                continue;
913
-            }
914
-            //first datetime should be the lowest datetime
915
-            $least_datetime = reset($datetimes);
916
-            //lets reset the ticket quantity to be the lower of either the lowest datetime reg limit or the ticket quantity
917
-            //IF datetimes sold (and we're not doing current live total available, then use spaces remaining for datetime, not reg_limit.
918
-            if ($current_total_available) {
919
-                if ($ticket->is_remaining()) {
920
-                    $remaining = $ticket->remaining();
921
-                } else {
922
-                    $spaces_available += $ticket->sold();
923
-                    //and we don't cache this ticket to our list because its sold out.
924
-                    continue;
925
-                }
926
-            } else {
927
-                $remaining = min($ticket->qty(), $least_datetime->reg_limit());
928
-            }
929
-            //if $ticket_limit == infinity then let's drop out right away and just return that because any infinity amount trumps all other "available" amounts.
930
-            if ($remaining === EE_INF) {
931
-                return EE_INF;
932
-            }
933
-            //multiply normalized $tkt quantity by the number of datetimes on the ticket as the "sum"
934
-            //also include the sum of all the datetime reg limits on the ticket for breaking ties.
935
-            $ticket_sums[$ticket->ID()]['sum'] = $remaining * count($datetimes);
936
-            $ticket_sums[$ticket->ID()]['datetime_sums'] = 0;
937
-            foreach ($datetimes as $datetime) {
938
-                if ($datetime->reg_limit() === EE_INF) {
939
-                    $ticket_sums[$ticket->ID()]['datetime_sums'] = EE_INF;
940
-                } else {
941
-                    $ticket_sums[$ticket->ID()]['datetime_sums'] += $current_total_available
942
-                        ? $datetime->spaces_remaining() : $datetime->reg_limit();
943
-                }
944
-                $datetime_limits[$datetime->ID()] = $current_total_available ? $datetime->spaces_remaining()
945
-                    : $datetime->reg_limit();
946
-            }
947
-            $ticket_sums[$ticket->ID()]['ticket'] = $ticket;
948
-        }
949
-        //The order is sorted by lowest available first (which is calculated for each ticket by multiplying the normalized
950
-        //ticket quantity by the number of datetimes on the ticket).  For tie-breakers, then the next sort is based on the
951
-        //ticket with the greatest sum of all remaining datetime->spaces_remaining() ( or $datetime->reg_limit() if not
952
-        //$current_total_available ) for the datetimes on the ticket.
953
-        usort($ticket_sums, function ($a, $b) {
954
-            if ($a['sum'] == $b['sum']) {
955
-                if ($a['datetime_sums'] == $b['datetime_sums']) {
956
-                    return 0;
957
-                }
958
-                return $a['datetime_sums'] < $b['datetime_sums'] ? 1 : -1;
959
-            }
960
-            return ($a['sum'] < $b['sum']) ? -1 : 1;
961
-        });
962
-        //now let's loop through the sorted tickets and simulate sellouts
963
-        foreach ($ticket_sums as $ticket_info) {
964
-            if ($ticket_info['ticket'] instanceof EE_Ticket) {
965
-                $datetimes = $ticket_info['ticket']->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC')));
966
-                //need to sort these $datetimes by remaining (only if $current_total_available)
967
-                //setup datetimes for simulation
968
-                $ticket_datetimes_remaining = array();
969
-                foreach ($datetimes as $datetime) {
970
-                    $ticket_datetimes_remaining[$datetime->ID()]['rem'] = $datetime_limits[$datetime->ID()];
971
-                    $ticket_datetimes_remaining[$datetime->ID()]['datetime'] = $datetime;
972
-                }
973
-                usort($ticket_datetimes_remaining, function ($a, $b) {
974
-                    if ($a['rem'] == $b['rem']) {
975
-                        return 0;
976
-                    }
977
-                    return ($a['rem'] < $b['rem']) ? -1 : 1;
978
-                });
979
-                //get the remaining on the first datetime (which should be the one with the least remaining) and that is
980
-                //what we add to the spaces_available running total.  Then we need to decrease the remaining on our datetime tracker.
981
-                $lowest_datetime = reset($ticket_datetimes_remaining);
982
-                //need to get the lower of; what the remaining is on the lowest datetime, and the remaining on the ticket.
983
-                // If this ends up being 0 (because of previous tickets in our simulation selling out), then it has already
984
-                // been tracked on $spaces available and this ticket is now sold out for the simulation, so we can continue
985
-                // to the next ticket.
986
-                if ($current_total_available) {
987
-                    $remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->remaining());
988
-                } else {
989
-                    $remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->qty());
990
-                }
991
-                //if $remaining is infinite that means that all datetimes on this ticket are infinite but we've made it here because all
992
-                //tickets have a quantity.  So we don't have to track datetimes, we can just use ticket quantities for total
993
-                //available.
994
-                if ($remaining === EE_INF) {
995
-                    $spaces_available += $ticket_info['ticket']->qty();
996
-                    continue;
997
-                }
998
-                //if ticket has sold amounts then we also need to add that (but only if doing live counts)
999
-                if ($current_total_available) {
1000
-                    $spaces_available += $ticket_info['ticket']->sold();
1001
-                }
1002
-                if ($remaining <= 0) {
1003
-                    continue;
1004
-                } else {
1005
-                    $spaces_available += $remaining;
1006
-                }
1007
-                //loop through the datetimes and sell them out!
1008
-                foreach ($ticket_datetimes_remaining as $datetime_info) {
1009
-                    if ($datetime_info['datetime'] instanceof EE_Datetime) {
1010
-                        $datetime_limits[$datetime_info['datetime']->ID()] += -$remaining;
1011
-                    }
1012
-                }
1013
-            }
1014
-        }
1015
-        return $spaces_available;
1016
-    }
1017
-
1018
-
1019
-
1020
-    /**
1021
-     * Checks if the event is set to sold out
1022
-     *
1023
-     * @param  bool $actual whether or not to perform calculations to not only figure the actual status but also to
1024
-     *                      flip the status if necessary to sold out If false, we just check the existing status of the
1025
-     *                      event
1026
-     * @return boolean
1027
-     */
1028
-    public function is_sold_out($actual = false)
1029
-    {
1030
-        if ( ! $actual) {
1031
-            return $this->status() == EEM_Event::sold_out;
1032
-        } else {
1033
-            return $this->perform_sold_out_status_check();
1034
-        }
1035
-    }
1036
-
1037
-
1038
-
1039
-    /**
1040
-     * Checks if the event is marked as postponed
1041
-     *
1042
-     * @return boolean
1043
-     */
1044
-    public function is_postponed()
1045
-    {
1046
-        return $this->status() == EEM_Event::postponed;
1047
-    }
1048
-
1049
-
1050
-
1051
-    /**
1052
-     * Checks if the event is marked as cancelled
1053
-     *
1054
-     * @return boolean
1055
-     */
1056
-    public function is_cancelled()
1057
-    {
1058
-        return $this->status() == EEM_Event::cancelled;
1059
-    }
1060
-
1061
-
1062
-
1063
-    /**
1064
-     * Get the logical active status in a hierarchical order for all the datetimes.  Note
1065
-     * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1066
-     * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1067
-     * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1068
-     * the event is considered expired.
1069
-     * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1070
-     * status set on the EVENT when it is not published and thus is done
1071
-     *
1072
-     * @param bool $reset
1073
-     * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1074
-     */
1075
-    public function get_active_status($reset = false)
1076
-    {
1077
-        // if the active status has already been set, then just use that value (unless we are resetting it)
1078
-        if ( ! empty($this->_active_status) && ! $reset) {
1079
-            return $this->_active_status;
1080
-        }
1081
-        //first check if event id is present on this object
1082
-        if ( ! $this->ID()) {
1083
-            return false;
1084
-        }
1085
-        $where_params_for_event = array(array('EVT_ID' => $this->ID()));
1086
-        //if event is published:
1087
-        if ($this->status() === 'publish') {
1088
-            //active?
1089
-            if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event)
1090
-                > 0
1091
-            ) {
1092
-                $this->_active_status = EE_Datetime::active;
1093
-            } else {
1094
-                //upcoming?
1095
-                if (EEM_Datetime::instance()
1096
-                                ->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0
1097
-                ) {
1098
-                    $this->_active_status = EE_Datetime::upcoming;
1099
-                } else {
1100
-                    //expired?
1101
-                    if (EEM_Datetime::instance()
1102
-                                    ->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0
1103
-                    ) {
1104
-                        $this->_active_status = EE_Datetime::expired;
1105
-                    } else {
1106
-                        //it would be odd if things make it this far because it basically means there are no datetime's
1107
-                        //attached to the event.  So in this case it will just be considered inactive.
1108
-                        $this->_active_status = EE_Datetime::inactive;
1109
-                    }
1110
-                }
1111
-            }
1112
-        } else {
1113
-            //the event is not published, so let's just set it's active status according to its' post status
1114
-            switch ($this->status()) {
1115
-                case EEM_Event::sold_out :
1116
-                    $this->_active_status = EE_Datetime::sold_out;
1117
-                    break;
1118
-                case EEM_Event::cancelled :
1119
-                    $this->_active_status = EE_Datetime::cancelled;
1120
-                    break;
1121
-                case EEM_Event::postponed :
1122
-                    $this->_active_status = EE_Datetime::postponed;
1123
-                    break;
1124
-                default :
1125
-                    $this->_active_status = EE_Datetime::inactive;
1126
-            }
1127
-        }
1128
-        return $this->_active_status;
1129
-    }
1130
-
1131
-
1132
-
1133
-    /**
1134
-     *    pretty_active_status
1135
-     *
1136
-     * @access public
1137
-     * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1138
-     * @return mixed void|string
1139
-     */
1140
-    public function pretty_active_status($echo = true)
1141
-    {
1142
-        $active_status = $this->get_active_status();
1143
-        $status = '<span class="ee-status event-active-status-'
1144
-                  . $active_status
1145
-                  . '">'
1146
-                  . EEH_Template::pretty_status($active_status, false, 'sentence')
1147
-                  . '</span>';
1148
-        if ($echo) {
1149
-            echo $status;
1150
-            return '';
1151
-        }
1152
-        return $status;
1153
-    }
1154
-
1155
-
1156
-
1157
-    /**
1158
-     * @return bool|int
1159
-     */
1160
-    public function get_number_of_tickets_sold()
1161
-    {
1162
-        $tkt_sold = 0;
1163
-        if ( ! $this->ID()) {
1164
-            return 0;
1165
-        }
1166
-        $datetimes = $this->datetimes();
1167
-        foreach ($datetimes as $datetime) {
1168
-            if ($datetime instanceof EE_Datetime) {
1169
-                $tkt_sold += $datetime->sold();
1170
-            }
1171
-        }
1172
-        return $tkt_sold;
1173
-    }
1174
-
1175
-
1176
-
1177
-    /**
1178
-     * This just returns a count of all the registrations for this event
1179
-     *
1180
-     * @access  public
1181
-     * @return int
1182
-     */
1183
-    public function get_count_of_all_registrations()
1184
-    {
1185
-        return EEM_Event::instance()->count_related($this, 'Registration');
1186
-    }
1187
-
1188
-
1189
-
1190
-    /**
1191
-     * This returns the ticket with the earliest start time that is available for this event (across all datetimes
1192
-     * attached to the event)
1193
-     *
1194
-     * @return EE_Ticket
1195
-     */
1196
-    public function get_ticket_with_earliest_start_time()
1197
-    {
1198
-        $where['Datetime.EVT_ID'] = $this->ID();
1199
-        $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1200
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1201
-    }
1202
-
1203
-
1204
-
1205
-    /**
1206
-     * This returns the ticket with the latest end time that is available for this event (across all datetimes attached
1207
-     * to the event)
1208
-     *
1209
-     * @return EE_Ticket
1210
-     */
1211
-    public function get_ticket_with_latest_end_time()
1212
-    {
1213
-        $where['Datetime.EVT_ID'] = $this->ID();
1214
-        $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1215
-        return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1216
-    }
1217
-
1218
-
1219
-
1220
-    /**
1221
-     * This returns whether there are any tickets on sale for this event.
1222
-     *
1223
-     * @return bool true = YES tickets on sale.
1224
-     */
1225
-    public function tickets_on_sale()
1226
-    {
1227
-        $earliest_ticket = $this->get_ticket_with_earliest_start_time();
1228
-        $latest_ticket = $this->get_ticket_with_latest_end_time();
1229
-        if ( ! $latest_ticket instanceof EE_Ticket && ! $earliest_ticket instanceof EE_Ticket) {
1230
-            return false;
1231
-        }
1232
-        //check on sale for these two tickets.
1233
-        if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) {
1234
-            return true;
1235
-        }
1236
-        return false;
1237
-    }
1238
-
1239
-
1240
-
1241
-    /**
1242
-     * Gets the URL for viewing this event on the front-end. Overrides parent
1243
-     * to check for an external URL first
1244
-     *
1245
-     * @return string
1246
-     */
1247
-    public function get_permalink()
1248
-    {
1249
-        if ($this->external_url()) {
1250
-            return $this->external_url();
1251
-        } else {
1252
-            return parent::get_permalink();
1253
-        }
1254
-    }
1255
-
1256
-
1257
-
1258
-    /**
1259
-     * Gets the first term for 'espresso_event_categories' we can find
1260
-     *
1261
-     * @param array $query_params like EEM_Base::get_all
1262
-     * @return EE_Term
1263
-     */
1264
-    public function first_event_category($query_params = array())
1265
-    {
1266
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1267
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1268
-        return EEM_Term::instance()->get_one($query_params);
1269
-    }
1270
-
1271
-
1272
-
1273
-    /**
1274
-     * Gets all terms for 'espresso_event_categories' we can find
1275
-     *
1276
-     * @param array $query_params
1277
-     * @return EE_Term[]
1278
-     */
1279
-    public function get_all_event_categories($query_params = array())
1280
-    {
1281
-        $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1282
-        $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1283
-        return EEM_Term::instance()->get_all($query_params);
1284
-    }
1285
-
1286
-
1287
-
1288
-    /**
1289
-     * Gets all the question groups, ordering them by QSG_order ascending
1290
-     *
1291
-     * @param array $query_params @see EEM_Base::get_all
1292
-     * @return EE_Question_Group[]
1293
-     */
1294
-    public function question_groups($query_params = array())
1295
-    {
1296
-        $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1297
-        return $this->get_many_related('Question_Group', $query_params);
1298
-    }
1299
-
1300
-
1301
-
1302
-    /**
1303
-     * Implementation for EEI_Has_Icon interface method.
1304
-     *
1305
-     * @see EEI_Visual_Representation for comments
1306
-     * @return string
1307
-     */
1308
-    public function get_icon()
1309
-    {
1310
-        return '<span class="dashicons dashicons-flag"></span>';
1311
-    }
1312
-
1313
-
1314
-
1315
-    /**
1316
-     * Implementation for EEI_Admin_Links interface method.
1317
-     *
1318
-     * @see EEI_Admin_Links for comments
1319
-     * @return string
1320
-     */
1321
-    public function get_admin_details_link()
1322
-    {
1323
-        return $this->get_admin_edit_link();
1324
-    }
1325
-
1326
-
1327
-
1328
-    /**
1329
-     * Implementation for EEI_Admin_Links interface method.
1330
-     *
1331
-     * @see EEI_Admin_Links for comments
1332
-     * @return string
1333
-     */
1334
-    public function get_admin_edit_link()
1335
-    {
1336
-        return EEH_URL::add_query_args_and_nonce(array(
1337
-            'page'   => 'espresso_events',
1338
-            'action' => 'edit',
1339
-            'post'   => $this->ID(),
1340
-        ),
1341
-            admin_url('admin.php')
1342
-        );
1343
-    }
1344
-
1345
-
1346
-
1347
-    /**
1348
-     * Implementation for EEI_Admin_Links interface method.
1349
-     *
1350
-     * @see EEI_Admin_Links for comments
1351
-     * @return string
1352
-     */
1353
-    public function get_admin_settings_link()
1354
-    {
1355
-        return EEH_URL::add_query_args_and_nonce(array(
1356
-            'page'   => 'espresso_events',
1357
-            'action' => 'default_event_settings',
1358
-        ),
1359
-            admin_url('admin.php')
1360
-        );
1361
-    }
1362
-
1363
-
1364
-
1365
-    /**
1366
-     * Implementation for EEI_Admin_Links interface method.
1367
-     *
1368
-     * @see EEI_Admin_Links for comments
1369
-     * @return string
1370
-     */
1371
-    public function get_admin_overview_link()
1372
-    {
1373
-        return EEH_URL::add_query_args_and_nonce(array(
1374
-            'page'   => 'espresso_events',
1375
-            'action' => 'default'
1376
-        ),
1377
-            admin_url('admin.php')
1378
-        );
1379
-    }
608
+
609
+	/**
610
+	 * @param $default_registration_status
611
+	 */
612
+	public function set_default_registration_status($default_registration_status)
613
+	{
614
+		$this->set('EVT_default_registration_status', $default_registration_status);
615
+	}
616
+
617
+
618
+
619
+	/**
620
+	 * @param $donations
621
+	 */
622
+	public function set_donations($donations)
623
+	{
624
+		$this->set('EVT_donations', $donations);
625
+	}
626
+
627
+
628
+
629
+	/**
630
+	 * Adds a venue to this event
631
+	 *
632
+	 * @param EE_Venue /int $venue_id_or_obj
633
+	 * @return EE_Venue
634
+	 */
635
+	public function add_venue($venue_id_or_obj)
636
+	{
637
+		return $this->_add_relation_to($venue_id_or_obj, 'Venue');
638
+	}
639
+
640
+
641
+
642
+	/**
643
+	 * Removes a venue from the event
644
+	 *
645
+	 * @param EE_Venue /int $venue_id_or_obj
646
+	 * @return EE_Venue
647
+	 */
648
+	public function remove_venue($venue_id_or_obj)
649
+	{
650
+		return $this->_remove_relation_to($venue_id_or_obj, 'Venue');
651
+	}
652
+
653
+
654
+
655
+	/**
656
+	 * Gets all the venues related ot the event. May provide additional $query_params if desired
657
+	 *
658
+	 * @param array $query_params like EEM_Base::get_all's $query_params
659
+	 * @return EE_Venue[]
660
+	 */
661
+	public function venues($query_params = array())
662
+	{
663
+		return $this->get_many_related('Venue', $query_params);
664
+	}
665
+
666
+
667
+
668
+	/**
669
+	 * check if event id is present and if event is published
670
+	 *
671
+	 * @access public
672
+	 * @return boolean true yes, false no
673
+	 */
674
+	private function _has_ID_and_is_published()
675
+	{
676
+		// first check if event id is present and not NULL, then check if this event is published (or any of the equivalent "published" statuses)
677
+		return ($this->ID() && $this->ID() !== null
678
+				&& ($this->status() == 'publish'
679
+					|| $this->status()
680
+					   == EEM_Event::sold_out
681
+					|| $this->status() == EEM_Event::postponed
682
+					|| $this->status() == EEM_Event::cancelled)) ? true : false;
683
+	}
684
+
685
+
686
+
687
+	/**
688
+	 * This simply compares the internal dates with NOW and determines if the event is upcoming or not.
689
+	 *
690
+	 * @access public
691
+	 * @return boolean true yes, false no
692
+	 */
693
+	public function is_upcoming()
694
+	{
695
+		// check if event id is present and if this event is published
696
+		if ($this->is_inactive()) {
697
+			return false;
698
+		}
699
+		// set initial value
700
+		$upcoming = false;
701
+		//next let's get all datetimes and loop through them
702
+		$datetimes = $this->datetimes_in_chronological_order();
703
+		foreach ($datetimes as $datetime) {
704
+			if ($datetime instanceof EE_Datetime) {
705
+				//if this dtt is expired then we continue cause one of the other datetimes might be upcoming.
706
+				if ($datetime->is_expired()) {
707
+					continue;
708
+				}
709
+				//if this dtt is active then we return false.
710
+				if ($datetime->is_active()) {
711
+					return false;
712
+				}
713
+				//otherwise let's check upcoming status
714
+				$upcoming = $datetime->is_upcoming();
715
+			}
716
+		}
717
+		return $upcoming;
718
+	}
719
+
720
+
721
+
722
+	/**
723
+	 * @return bool
724
+	 */
725
+	public function is_active()
726
+	{
727
+		// check if event id is present and if this event is published
728
+		if ($this->is_inactive()) {
729
+			return false;
730
+		}
731
+		// set initial value
732
+		$active = false;
733
+		//next let's get all datetimes and loop through them
734
+		$datetimes = $this->datetimes_in_chronological_order();
735
+		foreach ($datetimes as $datetime) {
736
+			if ($datetime instanceof EE_Datetime) {
737
+				//if this dtt is expired then we continue cause one of the other datetimes might be active.
738
+				if ($datetime->is_expired()) {
739
+					continue;
740
+				}
741
+				//if this dtt is upcoming then we return false.
742
+				if ($datetime->is_upcoming()) {
743
+					return false;
744
+				}
745
+				//otherwise let's check active status
746
+				$active = $datetime->is_active();
747
+			}
748
+		}
749
+		return $active;
750
+	}
751
+
752
+
753
+
754
+	/**
755
+	 * @return bool
756
+	 */
757
+	public function is_expired()
758
+	{
759
+		// check if event id is present and if this event is published
760
+		if ($this->is_inactive()) {
761
+			return false;
762
+		}
763
+		// set initial value
764
+		$expired = false;
765
+		//first let's get all datetimes and loop through them
766
+		$datetimes = $this->datetimes_in_chronological_order();
767
+		foreach ($datetimes as $datetime) {
768
+			if ($datetime instanceof EE_Datetime) {
769
+				//if this dtt is upcoming or active then we return false.
770
+				if ($datetime->is_upcoming() || $datetime->is_active()) {
771
+					return false;
772
+				}
773
+				//otherwise let's check active status
774
+				$expired = $datetime->is_expired();
775
+			}
776
+		}
777
+		return $expired;
778
+	}
779
+
780
+
781
+
782
+	/**
783
+	 * @return bool
784
+	 */
785
+	public function is_inactive()
786
+	{
787
+		// check if event id is present and if this event is published
788
+		if ($this->_has_ID_and_is_published()) {
789
+			return false;
790
+		}
791
+		return true;
792
+	}
793
+
794
+
795
+
796
+	/**
797
+	 *    perform_sold_out_status_check
798
+	 *    checks all of this events's datetime  reg_limit - sold values to determine if ANY datetimes have spaces
799
+	 *    available... if NOT, then the event status will get toggled to 'sold_out'
800
+	 *
801
+	 * @access public
802
+	 * @return bool    return the ACTUAL sold out state.
803
+	 */
804
+	public function perform_sold_out_status_check()
805
+	{
806
+		// get all unexpired untrashed tickets
807
+		$tickets = $this->tickets(array(
808
+			array(
809
+				'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')),
810
+				'TKT_deleted'  => false,
811
+			),
812
+		));
813
+		// if all the tickets are just expired, then don't update the event status to sold out
814
+		if (empty($tickets)) {
815
+			return true;
816
+		}
817
+		// set initial value
818
+		$spaces_remaining = 0;
819
+		foreach ($tickets as $ticket) {
820
+			if ($ticket instanceof EE_Ticket) {
821
+				$spaces_remaining += $ticket->qty('saleable');
822
+			}
823
+		}
824
+		if ($spaces_remaining === 0) {
825
+			$this->set_status(EEM_Event::sold_out);
826
+			if ( ! is_admin() || (is_admin() && defined('DOING_AJAX'))) {
827
+				$this->save();
828
+			}
829
+			$sold_out = true;
830
+		} else {
831
+			$sold_out = false;
832
+			// was event previously marked as sold out ?
833
+			if ($this->status() == EEM_Event::sold_out) {
834
+				// revert status to previous value, if it was set
835
+				$previous_event_status = $this->get_post_meta('_previous_event_status', true);
836
+				if ($previous_event_status) {
837
+					$this->set_status($previous_event_status);
838
+				}
839
+			}
840
+		}
841
+		//note: I considered changing the EEM_Event status away from sold_out if this status check reveals that it's no longer sold out (yet the status is still set as sold out) but the problem is... what do we change the status BACK to?  We can't always assume that the previous event status was 'published' because this status check is always done in the admin and its entirely possible the event admin manually changes to sold_out status from some other status.  We also don't want a draft event to become a "publish event" because the sold out check reveals its NOT sold out.
842
+		// So I'll forgo the automatic switch away from sold out status for now and instead just return the $sold out status... so this check can be used to validate the TRUE sold out status regardless of what the Event status is set to.
843
+		return $sold_out;
844
+	}
845
+
846
+
847
+
848
+	/**
849
+	 * This returns the total remaining spaces for sale on this event.
850
+	 * ############################
851
+	 * VERY IMPORTANT FOR DEVELOPERS:
852
+	 * While included here, this method is still being tested internally, so its signature and behaviour COULD change.
853
+	 * While this comment block is in place, usage is at your own risk and know that it may change in future builds.
854
+	 * ############################
855
+	 *
856
+	 * @uses EE_Event::total_available_spaces()
857
+	 * @return float|int  (EE_INF is returned as float)
858
+	 */
859
+	public function spaces_remaining_for_sale()
860
+	{
861
+		//first get total available spaces including consideration for tickets that have already sold.
862
+		$spaces_available = $this->total_available_spaces(true);
863
+		//if total available = 0, then exit right away because that means everything is expired.
864
+		if ($spaces_available === 0) {
865
+			return 0;
866
+		}
867
+		//subtract total approved registrations from spaces available to get how many are remaining.
868
+		$spots_taken = EEM_Registration::instance()->count(array(
869
+			array(
870
+				'EVT_ID' => $this->ID(),
871
+				'STS_ID' => EEM_Registration::status_id_approved,
872
+			),
873
+		), 'REG_ID', true);
874
+		$spaces_remaining = $spaces_available - $spots_taken;
875
+		return $spaces_remaining > 0 ? $spaces_remaining : 0;
876
+	}
877
+
878
+
879
+
880
+	/**
881
+	 * This returns the total spaces available for an event while considering all the qtys on the tickets and the reg
882
+	 * limits on the datetimes attached to this event.
883
+	 * ############################
884
+	 * VERY IMPORTANT FOR DEVELOPERS:
885
+	 * While included here, this method is still being tested internally, so its signature and behaviour COULD change.
886
+	 * While this comment block is in place, usage is at your own risk and know that it may change in future builds.
887
+	 * ############################
888
+	 * Note: by "spaces available" we are not returning how many spaces remain.  That is a calculation involving using
889
+	 * the value from this method and subtracting the approved registrations for the event.
890
+	 *
891
+	 * @param   bool $current_total_available       Whether to consider any tickets that have already sold in our
892
+	 *                                              calculation. If this is false, then we return the most tickets that
893
+	 *                                              could ever be sold for this event with the datetime and tickets
894
+	 *                                              setup on the event under optimal selling conditions.  Otherwise we
895
+	 *                                              return a live calculation of spaces available based on tickets
896
+	 *                                              sold.  Depending on setup and stage of sales, this may appear to
897
+	 *                                              equal remaining tickets.  However, the more tickets are sold out,
898
+	 *                                              the more accurate the "live" total is.
899
+	 * @return  int|float  (Note: if EE_INF is returned its considered a float by PHP)
900
+	 */
901
+	public function total_available_spaces($current_total_available = false)
902
+	{
903
+		$spaces_available = 0;
904
+		//first get all tickets on the event and include expired tickets
905
+		$tickets = $this->tickets(array('default_where_conditions' => 'none'));
906
+		$ticket_sums = array();
907
+		$datetime_limits = array();
908
+		//loop through tickets and normalize them
909
+		foreach ($tickets as $ticket) {
910
+			$datetimes = $ticket->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC')));
911
+			if (empty($datetimes)) {
912
+				continue;
913
+			}
914
+			//first datetime should be the lowest datetime
915
+			$least_datetime = reset($datetimes);
916
+			//lets reset the ticket quantity to be the lower of either the lowest datetime reg limit or the ticket quantity
917
+			//IF datetimes sold (and we're not doing current live total available, then use spaces remaining for datetime, not reg_limit.
918
+			if ($current_total_available) {
919
+				if ($ticket->is_remaining()) {
920
+					$remaining = $ticket->remaining();
921
+				} else {
922
+					$spaces_available += $ticket->sold();
923
+					//and we don't cache this ticket to our list because its sold out.
924
+					continue;
925
+				}
926
+			} else {
927
+				$remaining = min($ticket->qty(), $least_datetime->reg_limit());
928
+			}
929
+			//if $ticket_limit == infinity then let's drop out right away and just return that because any infinity amount trumps all other "available" amounts.
930
+			if ($remaining === EE_INF) {
931
+				return EE_INF;
932
+			}
933
+			//multiply normalized $tkt quantity by the number of datetimes on the ticket as the "sum"
934
+			//also include the sum of all the datetime reg limits on the ticket for breaking ties.
935
+			$ticket_sums[$ticket->ID()]['sum'] = $remaining * count($datetimes);
936
+			$ticket_sums[$ticket->ID()]['datetime_sums'] = 0;
937
+			foreach ($datetimes as $datetime) {
938
+				if ($datetime->reg_limit() === EE_INF) {
939
+					$ticket_sums[$ticket->ID()]['datetime_sums'] = EE_INF;
940
+				} else {
941
+					$ticket_sums[$ticket->ID()]['datetime_sums'] += $current_total_available
942
+						? $datetime->spaces_remaining() : $datetime->reg_limit();
943
+				}
944
+				$datetime_limits[$datetime->ID()] = $current_total_available ? $datetime->spaces_remaining()
945
+					: $datetime->reg_limit();
946
+			}
947
+			$ticket_sums[$ticket->ID()]['ticket'] = $ticket;
948
+		}
949
+		//The order is sorted by lowest available first (which is calculated for each ticket by multiplying the normalized
950
+		//ticket quantity by the number of datetimes on the ticket).  For tie-breakers, then the next sort is based on the
951
+		//ticket with the greatest sum of all remaining datetime->spaces_remaining() ( or $datetime->reg_limit() if not
952
+		//$current_total_available ) for the datetimes on the ticket.
953
+		usort($ticket_sums, function ($a, $b) {
954
+			if ($a['sum'] == $b['sum']) {
955
+				if ($a['datetime_sums'] == $b['datetime_sums']) {
956
+					return 0;
957
+				}
958
+				return $a['datetime_sums'] < $b['datetime_sums'] ? 1 : -1;
959
+			}
960
+			return ($a['sum'] < $b['sum']) ? -1 : 1;
961
+		});
962
+		//now let's loop through the sorted tickets and simulate sellouts
963
+		foreach ($ticket_sums as $ticket_info) {
964
+			if ($ticket_info['ticket'] instanceof EE_Ticket) {
965
+				$datetimes = $ticket_info['ticket']->datetimes(array('order_by' => array('DTT_reg_limit' => 'ASC')));
966
+				//need to sort these $datetimes by remaining (only if $current_total_available)
967
+				//setup datetimes for simulation
968
+				$ticket_datetimes_remaining = array();
969
+				foreach ($datetimes as $datetime) {
970
+					$ticket_datetimes_remaining[$datetime->ID()]['rem'] = $datetime_limits[$datetime->ID()];
971
+					$ticket_datetimes_remaining[$datetime->ID()]['datetime'] = $datetime;
972
+				}
973
+				usort($ticket_datetimes_remaining, function ($a, $b) {
974
+					if ($a['rem'] == $b['rem']) {
975
+						return 0;
976
+					}
977
+					return ($a['rem'] < $b['rem']) ? -1 : 1;
978
+				});
979
+				//get the remaining on the first datetime (which should be the one with the least remaining) and that is
980
+				//what we add to the spaces_available running total.  Then we need to decrease the remaining on our datetime tracker.
981
+				$lowest_datetime = reset($ticket_datetimes_remaining);
982
+				//need to get the lower of; what the remaining is on the lowest datetime, and the remaining on the ticket.
983
+				// If this ends up being 0 (because of previous tickets in our simulation selling out), then it has already
984
+				// been tracked on $spaces available and this ticket is now sold out for the simulation, so we can continue
985
+				// to the next ticket.
986
+				if ($current_total_available) {
987
+					$remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->remaining());
988
+				} else {
989
+					$remaining = min($lowest_datetime['rem'], $ticket_info['ticket']->qty());
990
+				}
991
+				//if $remaining is infinite that means that all datetimes on this ticket are infinite but we've made it here because all
992
+				//tickets have a quantity.  So we don't have to track datetimes, we can just use ticket quantities for total
993
+				//available.
994
+				if ($remaining === EE_INF) {
995
+					$spaces_available += $ticket_info['ticket']->qty();
996
+					continue;
997
+				}
998
+				//if ticket has sold amounts then we also need to add that (but only if doing live counts)
999
+				if ($current_total_available) {
1000
+					$spaces_available += $ticket_info['ticket']->sold();
1001
+				}
1002
+				if ($remaining <= 0) {
1003
+					continue;
1004
+				} else {
1005
+					$spaces_available += $remaining;
1006
+				}
1007
+				//loop through the datetimes and sell them out!
1008
+				foreach ($ticket_datetimes_remaining as $datetime_info) {
1009
+					if ($datetime_info['datetime'] instanceof EE_Datetime) {
1010
+						$datetime_limits[$datetime_info['datetime']->ID()] += -$remaining;
1011
+					}
1012
+				}
1013
+			}
1014
+		}
1015
+		return $spaces_available;
1016
+	}
1017
+
1018
+
1019
+
1020
+	/**
1021
+	 * Checks if the event is set to sold out
1022
+	 *
1023
+	 * @param  bool $actual whether or not to perform calculations to not only figure the actual status but also to
1024
+	 *                      flip the status if necessary to sold out If false, we just check the existing status of the
1025
+	 *                      event
1026
+	 * @return boolean
1027
+	 */
1028
+	public function is_sold_out($actual = false)
1029
+	{
1030
+		if ( ! $actual) {
1031
+			return $this->status() == EEM_Event::sold_out;
1032
+		} else {
1033
+			return $this->perform_sold_out_status_check();
1034
+		}
1035
+	}
1036
+
1037
+
1038
+
1039
+	/**
1040
+	 * Checks if the event is marked as postponed
1041
+	 *
1042
+	 * @return boolean
1043
+	 */
1044
+	public function is_postponed()
1045
+	{
1046
+		return $this->status() == EEM_Event::postponed;
1047
+	}
1048
+
1049
+
1050
+
1051
+	/**
1052
+	 * Checks if the event is marked as cancelled
1053
+	 *
1054
+	 * @return boolean
1055
+	 */
1056
+	public function is_cancelled()
1057
+	{
1058
+		return $this->status() == EEM_Event::cancelled;
1059
+	}
1060
+
1061
+
1062
+
1063
+	/**
1064
+	 * Get the logical active status in a hierarchical order for all the datetimes.  Note
1065
+	 * Basically, we order the datetimes by EVT_start_date.  Then first test on whether the event is published.  If its
1066
+	 * NOT published then we test for whether its expired or not.  IF it IS published then we test first on whether an
1067
+	 * event has any active dates.  If no active dates then we check for any upcoming dates.  If no upcoming dates then
1068
+	 * the event is considered expired.
1069
+	 * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published.  Sold Out is a
1070
+	 * status set on the EVENT when it is not published and thus is done
1071
+	 *
1072
+	 * @param bool $reset
1073
+	 * @return bool | string - based on EE_Datetime active constants or FALSE if error.
1074
+	 */
1075
+	public function get_active_status($reset = false)
1076
+	{
1077
+		// if the active status has already been set, then just use that value (unless we are resetting it)
1078
+		if ( ! empty($this->_active_status) && ! $reset) {
1079
+			return $this->_active_status;
1080
+		}
1081
+		//first check if event id is present on this object
1082
+		if ( ! $this->ID()) {
1083
+			return false;
1084
+		}
1085
+		$where_params_for_event = array(array('EVT_ID' => $this->ID()));
1086
+		//if event is published:
1087
+		if ($this->status() === 'publish') {
1088
+			//active?
1089
+			if (EEM_Datetime::instance()->get_datetime_count_for_status(EE_Datetime::active, $where_params_for_event)
1090
+				> 0
1091
+			) {
1092
+				$this->_active_status = EE_Datetime::active;
1093
+			} else {
1094
+				//upcoming?
1095
+				if (EEM_Datetime::instance()
1096
+								->get_datetime_count_for_status(EE_Datetime::upcoming, $where_params_for_event) > 0
1097
+				) {
1098
+					$this->_active_status = EE_Datetime::upcoming;
1099
+				} else {
1100
+					//expired?
1101
+					if (EEM_Datetime::instance()
1102
+									->get_datetime_count_for_status(EE_Datetime::expired, $where_params_for_event) > 0
1103
+					) {
1104
+						$this->_active_status = EE_Datetime::expired;
1105
+					} else {
1106
+						//it would be odd if things make it this far because it basically means there are no datetime's
1107
+						//attached to the event.  So in this case it will just be considered inactive.
1108
+						$this->_active_status = EE_Datetime::inactive;
1109
+					}
1110
+				}
1111
+			}
1112
+		} else {
1113
+			//the event is not published, so let's just set it's active status according to its' post status
1114
+			switch ($this->status()) {
1115
+				case EEM_Event::sold_out :
1116
+					$this->_active_status = EE_Datetime::sold_out;
1117
+					break;
1118
+				case EEM_Event::cancelled :
1119
+					$this->_active_status = EE_Datetime::cancelled;
1120
+					break;
1121
+				case EEM_Event::postponed :
1122
+					$this->_active_status = EE_Datetime::postponed;
1123
+					break;
1124
+				default :
1125
+					$this->_active_status = EE_Datetime::inactive;
1126
+			}
1127
+		}
1128
+		return $this->_active_status;
1129
+	}
1130
+
1131
+
1132
+
1133
+	/**
1134
+	 *    pretty_active_status
1135
+	 *
1136
+	 * @access public
1137
+	 * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1138
+	 * @return mixed void|string
1139
+	 */
1140
+	public function pretty_active_status($echo = true)
1141
+	{
1142
+		$active_status = $this->get_active_status();
1143
+		$status = '<span class="ee-status event-active-status-'
1144
+				  . $active_status
1145
+				  . '">'
1146
+				  . EEH_Template::pretty_status($active_status, false, 'sentence')
1147
+				  . '</span>';
1148
+		if ($echo) {
1149
+			echo $status;
1150
+			return '';
1151
+		}
1152
+		return $status;
1153
+	}
1154
+
1155
+
1156
+
1157
+	/**
1158
+	 * @return bool|int
1159
+	 */
1160
+	public function get_number_of_tickets_sold()
1161
+	{
1162
+		$tkt_sold = 0;
1163
+		if ( ! $this->ID()) {
1164
+			return 0;
1165
+		}
1166
+		$datetimes = $this->datetimes();
1167
+		foreach ($datetimes as $datetime) {
1168
+			if ($datetime instanceof EE_Datetime) {
1169
+				$tkt_sold += $datetime->sold();
1170
+			}
1171
+		}
1172
+		return $tkt_sold;
1173
+	}
1174
+
1175
+
1176
+
1177
+	/**
1178
+	 * This just returns a count of all the registrations for this event
1179
+	 *
1180
+	 * @access  public
1181
+	 * @return int
1182
+	 */
1183
+	public function get_count_of_all_registrations()
1184
+	{
1185
+		return EEM_Event::instance()->count_related($this, 'Registration');
1186
+	}
1187
+
1188
+
1189
+
1190
+	/**
1191
+	 * This returns the ticket with the earliest start time that is available for this event (across all datetimes
1192
+	 * attached to the event)
1193
+	 *
1194
+	 * @return EE_Ticket
1195
+	 */
1196
+	public function get_ticket_with_earliest_start_time()
1197
+	{
1198
+		$where['Datetime.EVT_ID'] = $this->ID();
1199
+		$query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC'));
1200
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1201
+	}
1202
+
1203
+
1204
+
1205
+	/**
1206
+	 * This returns the ticket with the latest end time that is available for this event (across all datetimes attached
1207
+	 * to the event)
1208
+	 *
1209
+	 * @return EE_Ticket
1210
+	 */
1211
+	public function get_ticket_with_latest_end_time()
1212
+	{
1213
+		$where['Datetime.EVT_ID'] = $this->ID();
1214
+		$query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC'));
1215
+		return EE_Registry::instance()->load_model('Ticket')->get_one($query_params);
1216
+	}
1217
+
1218
+
1219
+
1220
+	/**
1221
+	 * This returns whether there are any tickets on sale for this event.
1222
+	 *
1223
+	 * @return bool true = YES tickets on sale.
1224
+	 */
1225
+	public function tickets_on_sale()
1226
+	{
1227
+		$earliest_ticket = $this->get_ticket_with_earliest_start_time();
1228
+		$latest_ticket = $this->get_ticket_with_latest_end_time();
1229
+		if ( ! $latest_ticket instanceof EE_Ticket && ! $earliest_ticket instanceof EE_Ticket) {
1230
+			return false;
1231
+		}
1232
+		//check on sale for these two tickets.
1233
+		if ($latest_ticket->is_on_sale() || $earliest_ticket->is_on_sale()) {
1234
+			return true;
1235
+		}
1236
+		return false;
1237
+	}
1238
+
1239
+
1240
+
1241
+	/**
1242
+	 * Gets the URL for viewing this event on the front-end. Overrides parent
1243
+	 * to check for an external URL first
1244
+	 *
1245
+	 * @return string
1246
+	 */
1247
+	public function get_permalink()
1248
+	{
1249
+		if ($this->external_url()) {
1250
+			return $this->external_url();
1251
+		} else {
1252
+			return parent::get_permalink();
1253
+		}
1254
+	}
1255
+
1256
+
1257
+
1258
+	/**
1259
+	 * Gets the first term for 'espresso_event_categories' we can find
1260
+	 *
1261
+	 * @param array $query_params like EEM_Base::get_all
1262
+	 * @return EE_Term
1263
+	 */
1264
+	public function first_event_category($query_params = array())
1265
+	{
1266
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1267
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1268
+		return EEM_Term::instance()->get_one($query_params);
1269
+	}
1270
+
1271
+
1272
+
1273
+	/**
1274
+	 * Gets all terms for 'espresso_event_categories' we can find
1275
+	 *
1276
+	 * @param array $query_params
1277
+	 * @return EE_Term[]
1278
+	 */
1279
+	public function get_all_event_categories($query_params = array())
1280
+	{
1281
+		$query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1282
+		$query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID();
1283
+		return EEM_Term::instance()->get_all($query_params);
1284
+	}
1285
+
1286
+
1287
+
1288
+	/**
1289
+	 * Gets all the question groups, ordering them by QSG_order ascending
1290
+	 *
1291
+	 * @param array $query_params @see EEM_Base::get_all
1292
+	 * @return EE_Question_Group[]
1293
+	 */
1294
+	public function question_groups($query_params = array())
1295
+	{
1296
+		$query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC'));
1297
+		return $this->get_many_related('Question_Group', $query_params);
1298
+	}
1299
+
1300
+
1301
+
1302
+	/**
1303
+	 * Implementation for EEI_Has_Icon interface method.
1304
+	 *
1305
+	 * @see EEI_Visual_Representation for comments
1306
+	 * @return string
1307
+	 */
1308
+	public function get_icon()
1309
+	{
1310
+		return '<span class="dashicons dashicons-flag"></span>';
1311
+	}
1312
+
1313
+
1314
+
1315
+	/**
1316
+	 * Implementation for EEI_Admin_Links interface method.
1317
+	 *
1318
+	 * @see EEI_Admin_Links for comments
1319
+	 * @return string
1320
+	 */
1321
+	public function get_admin_details_link()
1322
+	{
1323
+		return $this->get_admin_edit_link();
1324
+	}
1325
+
1326
+
1327
+
1328
+	/**
1329
+	 * Implementation for EEI_Admin_Links interface method.
1330
+	 *
1331
+	 * @see EEI_Admin_Links for comments
1332
+	 * @return string
1333
+	 */
1334
+	public function get_admin_edit_link()
1335
+	{
1336
+		return EEH_URL::add_query_args_and_nonce(array(
1337
+			'page'   => 'espresso_events',
1338
+			'action' => 'edit',
1339
+			'post'   => $this->ID(),
1340
+		),
1341
+			admin_url('admin.php')
1342
+		);
1343
+	}
1344
+
1345
+
1346
+
1347
+	/**
1348
+	 * Implementation for EEI_Admin_Links interface method.
1349
+	 *
1350
+	 * @see EEI_Admin_Links for comments
1351
+	 * @return string
1352
+	 */
1353
+	public function get_admin_settings_link()
1354
+	{
1355
+		return EEH_URL::add_query_args_and_nonce(array(
1356
+			'page'   => 'espresso_events',
1357
+			'action' => 'default_event_settings',
1358
+		),
1359
+			admin_url('admin.php')
1360
+		);
1361
+	}
1362
+
1363
+
1364
+
1365
+	/**
1366
+	 * Implementation for EEI_Admin_Links interface method.
1367
+	 *
1368
+	 * @see EEI_Admin_Links for comments
1369
+	 * @return string
1370
+	 */
1371
+	public function get_admin_overview_link()
1372
+	{
1373
+		return EEH_URL::add_query_args_and_nonce(array(
1374
+			'page'   => 'espresso_events',
1375
+			'action' => 'default'
1376
+		),
1377
+			admin_url('admin.php')
1378
+		);
1379
+	}
1380 1380
 
1381 1381
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      */
301 301
     public function display_ticket_selector()
302 302
     {
303
-        return (bool)$this->get('EVT_display_ticket_selector');
303
+        return (bool) $this->get('EVT_display_ticket_selector');
304 304
     }
305 305
 
306 306
 
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
         //ticket quantity by the number of datetimes on the ticket).  For tie-breakers, then the next sort is based on the
951 951
         //ticket with the greatest sum of all remaining datetime->spaces_remaining() ( or $datetime->reg_limit() if not
952 952
         //$current_total_available ) for the datetimes on the ticket.
953
-        usort($ticket_sums, function ($a, $b) {
953
+        usort($ticket_sums, function($a, $b) {
954 954
             if ($a['sum'] == $b['sum']) {
955 955
                 if ($a['datetime_sums'] == $b['datetime_sums']) {
956 956
                     return 0;
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
                     $ticket_datetimes_remaining[$datetime->ID()]['rem'] = $datetime_limits[$datetime->ID()];
971 971
                     $ticket_datetimes_remaining[$datetime->ID()]['datetime'] = $datetime;
972 972
                 }
973
-                usort($ticket_datetimes_remaining, function ($a, $b) {
973
+                usort($ticket_datetimes_remaining, function($a, $b) {
974 974
                     if ($a['rem'] == $b['rem']) {
975 975
                         return 0;
976 976
                     }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1135,7 +1135,7 @@
 block discarded – undo
1135 1135
      *
1136 1136
      * @access public
1137 1137
      * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE)
1138
-     * @return mixed void|string
1138
+     * @return string void|string
1139 1139
      */
1140 1140
     public function pretty_active_status($echo = true)
1141 1141
     {
Please login to merge, or discard this patch.
core/libraries/batch/Helpers/JobParameters.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 	 * @param array $request_data
97 97
 	 * @param array $extra_data
98 98
 	 */
99
-	function __construct( $job_id, $classname, $request_data, $extra_data = array() ) {
100
-		$this->set_job_id( $job_id );
101
-		$this->set_classname( $classname );
102
-		$this->set_request_data( $request_data );
103
-		$this->set_extra_data( $extra_data );
104
-		$this->set_status( JobParameters::status_continue );
99
+	function __construct($job_id, $classname, $request_data, $extra_data = array()) {
100
+		$this->set_job_id($job_id);
101
+		$this->set_classname($classname);
102
+		$this->set_request_data($request_data);
103
+		$this->set_extra_data($extra_data);
104
+		$this->set_status(JobParameters::status_continue);
105 105
 	}
106 106
 
107 107
 
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 	 * @param boolean $first
127 127
 	 * @return boolean success
128 128
 	 */
129
-	function save( $first = false ) {
130
-		$object_vars = get_object_vars( $this );
131
-		if( $first ) {
132
-			return add_option( $this->option_name(), $object_vars, null, 'no' );
133
-		} else{
134
-			return update_option( $this->option_name(), $object_vars );
129
+	function save($first = false) {
130
+		$object_vars = get_object_vars($this);
131
+		if ($first) {
132
+			return add_option($this->option_name(), $object_vars, null, 'no');
133
+		} else {
134
+			return update_option($this->option_name(), $object_vars);
135 135
 		}
136 136
 	}
137 137
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * @return boolean
144 144
 	 */
145 145
 	function delete() {
146
-		return delete_option( $this->option_name() );
146
+		return delete_option($this->option_name());
147 147
 	}
148 148
 
149 149
 
@@ -154,26 +154,26 @@  discard block
 block discarded – undo
154 154
 	 * @return JobParameters
155 155
 	 * @throws BatchRequestException
156 156
 	 */
157
-	static function load( $job_id ) {
158
-		$job_parameter_vars = get_option( JobParameters::wp_option_prefix . $job_id );
159
-		if(
160
-			! is_array( $job_parameter_vars ) ||
161
-			! isset( $job_parameter_vars[ '_classname' ] ) ||
162
-			! isset( $job_parameter_vars[ '_request_data' ] )
157
+	static function load($job_id) {
158
+		$job_parameter_vars = get_option(JobParameters::wp_option_prefix.$job_id);
159
+		if (
160
+			! is_array($job_parameter_vars) ||
161
+			! isset($job_parameter_vars['_classname']) ||
162
+			! isset($job_parameter_vars['_request_data'])
163 163
 		) {
164 164
 			throw new BatchRequestException(
165 165
 				sprintf(
166 166
 					__('Could not retrieve job %1$s from the Wordpress options table, and so the job could not continue. The wordpress option was %2$s', 'event_espresso'),
167 167
 					$job_id,
168
-					get_option( JobParameters::wp_option_prefix . $job_id )
168
+					get_option(JobParameters::wp_option_prefix.$job_id)
169 169
 				)
170 170
 			);
171 171
 		}
172 172
 		$job_parameters = new JobParameters(
173 173
 				$job_id,
174
-				$job_parameter_vars[ '_classname' ],
175
-				$job_parameter_vars[ '_request_data'] );
176
-		foreach( $job_parameter_vars as $key => $value ) {
174
+				$job_parameter_vars['_classname'],
175
+				$job_parameter_vars['_request_data'] );
176
+		foreach ($job_parameter_vars as $key => $value) {
177 177
 			$job_parameters->{$key} = $value;
178 178
 		}
179 179
 		return $job_parameters;
@@ -217,9 +217,9 @@  discard block
 block discarded – undo
217 217
 	 * @param string|array $default
218 218
 	 * @return string|array
219 219
 	 */
220
-	function request_datum( $key, $default = '' ) {
221
-		if( isset( $this->_request_data[ $key ] ) ) {
222
-			return $this->_request_data[ $key ];
220
+	function request_datum($key, $default = '') {
221
+		if (isset($this->_request_data[$key])) {
222
+			return $this->_request_data[$key];
223 223
 		} else {
224 224
 			return $default;
225 225
 		}
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	 * @param string|array $default
234 234
 	 * @return string|array
235 235
 	 */
236
-	function extra_datum( $key, $default = '' ) {
237
-		if( isset( $this->_extra_data[ $key ] ) ) {
238
-			return $this->_extra_data[ $key ];
236
+	function extra_datum($key, $default = '') {
237
+		if (isset($this->_extra_data[$key])) {
238
+			return $this->_extra_data[$key];
239 239
 		} else {
240 240
 			return $default;
241 241
 		}
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 * @param string $key
249 249
 	 * @param string|int|array|null $value almost any extra data you want to store
250 250
 	 */
251
-	function add_extra_data( $key, $value ) {
252
-		$this->_extra_data[ $key ] = $value;
251
+	function add_extra_data($key, $value) {
252
+		$this->_extra_data[$key] = $value;
253 253
 	}
254 254
 
255 255
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * Sets the job size. You decide what units to use
279 279
 	 * @param int $size
280 280
 	 */
281
-	function set_job_size( $size ) {
281
+	function set_job_size($size) {
282 282
 		$this->_job_size = $size;
283 283
 	}
284 284
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 * @param int $newly_processed
300 300
 	 * @return int updated units processed
301 301
 	 */
302
-	function mark_processed( $newly_processed ) {
302
+	function mark_processed($newly_processed) {
303 303
 		$this->_units_processed += $newly_processed;
304 304
 		return $this->_units_processed;
305 305
 	}
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	 * Sets the total count of units processed. You might prefer to use mark_processed
311 311
 	 * @param int $total_units_processed
312 312
 	 */
313
-	function set_units_processed( $total_units_processed ) {
313
+	function set_units_processed($total_units_processed) {
314 314
 		$this->_units_processed = $total_units_processed;
315 315
 	}
316 316
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	 * Sets the job's ID
321 321
 	 * @param string $job_id
322 322
 	 */
323
-	function set_job_id( $job_id ) {
323
+	function set_job_id($job_id) {
324 324
 		$this->_job_id = $job_id;
325 325
 	}
326 326
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	 * sets the classname
331 331
 	 * @param string $classname
332 332
 	 */
333
-	function set_classname( $classname ) {
333
+	function set_classname($classname) {
334 334
 		$this->_classname = $classname;
335 335
 	}
336 336
 
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 	 * Sets the request data
341 341
 	 * @param array $request_data
342 342
 	 */
343
-	function set_request_data( $request_data ) {
343
+	function set_request_data($request_data) {
344 344
 		$this->_request_data = $request_data;
345 345
 	}
346 346
 
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 	 * Sets the array of extra data we want to store on this request
351 351
 	 * @param array $extra_data
352 352
 	 */
353
-	function set_extra_data( $extra_data ) {
353
+	function set_extra_data($extra_data) {
354 354
 		$this->_extra_data = $extra_data;
355 355
 	}
356 356
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 	 * @return string
362 362
 	 */
363 363
 	function option_name() {
364
-		return JobParameters::wp_option_prefix . $this->job_id();
364
+		return JobParameters::wp_option_prefix.$this->job_id();
365 365
 	}
366 366
 
367 367
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 	 *
381 381
 	 * @param string $status on eof JobParameters::valid_stati()
382 382
 	 */
383
-	public function set_status( $status ) {
383
+	public function set_status($status) {
384 384
 		$this->_status = $status;
385 385
 	}
386 386
 
Please login to merge, or discard this patch.