Completed
Branch EDTR/admin-options-and-conditi... (0549e8)
by
unknown
17:49 queued 09:13
created
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 1 patch
Indentation   +1335 added lines, -1335 removed lines patch added patch discarded remove patch
@@ -15,1342 +15,1342 @@
 block discarded – undo
15 15
 class Extend_Events_Admin_Page extends Events_Admin_Page
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Admin_Config
20
-     */
21
-    protected $admin_config;
22
-
23
-
24
-    /**
25
-     * Extend_Events_Admin_Page constructor.
26
-     *
27
-     * @param bool $routing
28
-     */
29
-    public function __construct($routing = true)
30
-    {
31
-        parent::__construct($routing);
32
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
34
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
35
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
36
-        }
37
-    }
38
-
39
-
40
-    /**
41
-     * Sets routes.
42
-     */
43
-    protected function _extend_page_config()
44
-    {
45
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
46
-        // is there a evt_id in the request?
47
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
48
-            ? $this->_req_data['EVT_ID']
49
-            : 0;
50
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
51
-        // tkt_id?
52
-        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
53
-            ? $this->_req_data['TKT_ID']
54
-            : 0;
55
-        $new_page_routes = array(
56
-            'duplicate_event'          => array(
57
-                'func'       => '_duplicate_event',
58
-                'capability' => 'ee_edit_event',
59
-                'obj_id'     => $evt_id,
60
-                'noheader'   => true,
61
-            ),
62
-            'ticket_list_table'        => array(
63
-                'func'       => '_tickets_overview_list_table',
64
-                'capability' => 'ee_read_default_tickets',
65
-            ),
66
-            'trash_ticket'             => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_ticket',
69
-                'obj_id'     => $tkt_id,
70
-                'noheader'   => true,
71
-                'args'       => array('trash' => true),
72
-            ),
73
-            'trash_tickets'            => array(
74
-                'func'       => '_trash_or_restore_ticket',
75
-                'capability' => 'ee_delete_default_tickets',
76
-                'noheader'   => true,
77
-                'args'       => array('trash' => true),
78
-            ),
79
-            'restore_ticket'           => array(
80
-                'func'       => '_trash_or_restore_ticket',
81
-                'capability' => 'ee_delete_default_ticket',
82
-                'obj_id'     => $tkt_id,
83
-                'noheader'   => true,
84
-            ),
85
-            'restore_tickets'          => array(
86
-                'func'       => '_trash_or_restore_ticket',
87
-                'capability' => 'ee_delete_default_tickets',
88
-                'noheader'   => true,
89
-            ),
90
-            'delete_ticket'            => array(
91
-                'func'       => '_delete_ticket',
92
-                'capability' => 'ee_delete_default_ticket',
93
-                'obj_id'     => $tkt_id,
94
-                'noheader'   => true,
95
-            ),
96
-            'delete_tickets'           => array(
97
-                'func'       => '_delete_ticket',
98
-                'capability' => 'ee_delete_default_tickets',
99
-                'noheader'   => true,
100
-            ),
101
-            'import_page'              => array(
102
-                'func'       => '_import_page',
103
-                'capability' => 'import',
104
-            ),
105
-            'import'                   => array(
106
-                'func'       => '_import_events',
107
-                'capability' => 'import',
108
-                'noheader'   => true,
109
-            ),
110
-            'import_events'            => array(
111
-                'func'       => '_import_events',
112
-                'capability' => 'import',
113
-                'noheader'   => true,
114
-            ),
115
-            'export_events'            => array(
116
-                'func'       => '_events_export',
117
-                'capability' => 'export',
118
-                'noheader'   => true,
119
-            ),
120
-            'export_categories'        => array(
121
-                'func'       => '_categories_export',
122
-                'capability' => 'export',
123
-                'noheader'   => true,
124
-            ),
125
-            'sample_export_file'       => array(
126
-                'func'       => '_sample_export_file',
127
-                'capability' => 'export',
128
-                'noheader'   => true,
129
-            ),
130
-            'update_template_settings' => array(
131
-                'func'       => '_update_template_settings',
132
-                'capability' => 'manage_options',
133
-                'noheader'   => true,
134
-            ),
135
-        );
136
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
137
-        // partial route/config override
138
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
139
-        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
140
-        $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
141
-        $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
142
-        $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
143
-        $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
144
-        // add tickets tab but only if there are more than one default ticket!
145
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
146
-            array(array('TKT_is_default' => 1)),
147
-            'TKT_ID',
148
-            true
149
-        );
150
-        if ($tkt_count > 1) {
151
-            $new_page_config = array(
152
-                'ticket_list_table' => array(
153
-                    'nav'           => array(
154
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
155
-                        'order' => 60,
156
-                    ),
157
-                    'list_table'    => 'Tickets_List_Table',
158
-                    'require_nonce' => false,
159
-                ),
160
-            );
161
-        }
162
-        // template settings
163
-        $new_page_config['template_settings'] = array(
164
-            'nav'           => array(
165
-                'label' => esc_html__('Templates', 'event_espresso'),
166
-                'order' => 30,
167
-            ),
168
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
169
-            'help_tabs'     => array(
170
-                'general_settings_templates_help_tab' => array(
171
-                    'title'    => esc_html__('Templates', 'event_espresso'),
172
-                    'filename' => 'general_settings_templates',
173
-                ),
174
-            ),
175
-            'help_tour'     => array('Templates_Help_Tour'),
176
-            'require_nonce' => false,
177
-        );
178
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
179
-        // add filters and actions
180
-        // modifying _views
181
-        add_filter(
182
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
183
-            array($this, 'add_additional_datetime_button'),
184
-            10,
185
-            2
186
-        );
187
-        add_filter(
188
-            'FHEE_event_datetime_metabox_clone_button_template',
189
-            array($this, 'add_datetime_clone_button'),
190
-            10,
191
-            2
192
-        );
193
-        add_filter(
194
-            'FHEE_event_datetime_metabox_timezones_template',
195
-            array($this, 'datetime_timezones_template'),
196
-            10,
197
-            2
198
-        );
199
-        // filters for event list table
200
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
201
-        add_filter(
202
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
203
-            array($this, 'extra_list_table_actions'),
204
-            10,
205
-            2
206
-        );
207
-        // legend item
208
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
209
-        add_action('admin_init', array($this, 'admin_init'));
210
-        $this->admin_config = EE_Registry::instance()->CFG->admin;
211
-        add_filter(
212
-            'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
213
-            [$this, 'advancedEditorAdminFormSection']
214
-        );
215
-        add_action(
216
-            'AHEE__Events_Admin_Page___update_default_event_settings',
217
-            [$this, 'updateAdvancedEditorAdminFormSettings'],
218
-            10,
219
-            2
220
-        );
221
-    }
222
-
223
-
224
-    /**
225
-     * admin_init
226
-     */
227
-    public function admin_init()
228
-    {
229
-        EE_Registry::$i18n_js_strings = array_merge(
230
-            EE_Registry::$i18n_js_strings,
231
-            array(
232
-                'image_confirm'          => esc_html__(
233
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
234
-                    'event_espresso'
235
-                ),
236
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
237
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
238
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
239
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
240
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
241
-            )
242
-        );
243
-    }
244
-
245
-
246
-    /**
247
-     * Add per page screen options to the default ticket list table view.
248
-     */
249
-    protected function _add_screen_options_ticket_list_table()
250
-    {
251
-        $this->_per_page_screen_option();
252
-    }
253
-
254
-
255
-    /**
256
-     * @param string $return
257
-     * @param int    $id
258
-     * @param string $new_title
259
-     * @param string $new_slug
260
-     * @return string
261
-     */
262
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
263
-    {
264
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
265
-        // make sure this is only when editing
266
-        if (! empty($id)) {
267
-            $href = EE_Admin_Page::add_query_args_and_nonce(
268
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
269
-                $this->_admin_base_url
270
-            );
271
-            $title = esc_attr__('Duplicate Event', 'event_espresso');
272
-            $return .= '<a href="'
273
-                       . $href
274
-                       . '" title="'
275
-                       . $title
276
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
277
-                       . $title
278
-                       . '</a>';
279
-        }
280
-        return $return;
281
-    }
282
-
283
-
284
-    /**
285
-     * Set the list table views for the default ticket list table view.
286
-     */
287
-    public function _set_list_table_views_ticket_list_table()
288
-    {
289
-        $this->_views = array(
290
-            'all'     => array(
291
-                'slug'        => 'all',
292
-                'label'       => esc_html__('All', 'event_espresso'),
293
-                'count'       => 0,
294
-                'bulk_action' => array(
295
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
296
-                ),
297
-            ),
298
-            'trashed' => array(
299
-                'slug'        => 'trashed',
300
-                'label'       => esc_html__('Trash', 'event_espresso'),
301
-                'count'       => 0,
302
-                'bulk_action' => array(
303
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
304
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
305
-                ),
306
-            ),
307
-        );
308
-    }
309
-
310
-
311
-    /**
312
-     * Enqueue scripts and styles for the event editor.
313
-     */
314
-    public function load_scripts_styles_edit()
315
-    {
316
-        wp_register_script(
317
-            'ee-event-editor-heartbeat',
318
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
319
-            array('ee_admin_js', 'heartbeat'),
320
-            EVENT_ESPRESSO_VERSION,
321
-            true
322
-        );
323
-        wp_enqueue_script('ee-accounting');
324
-        // styles
325
-        wp_enqueue_style('espresso-ui-theme');
326
-        wp_enqueue_script('event_editor_js');
327
-        wp_enqueue_script('ee-event-editor-heartbeat');
328
-        if ($this->admin_config->useAdvancedEditor()) {
329
-            add_action(
330
-                'admin_footer',
331
-                function () {
332
-                    $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
333
-                    if ($eventId) {
334
-                        echo '
18
+	/**
19
+	 * @var EE_Admin_Config
20
+	 */
21
+	protected $admin_config;
22
+
23
+
24
+	/**
25
+	 * Extend_Events_Admin_Page constructor.
26
+	 *
27
+	 * @param bool $routing
28
+	 */
29
+	public function __construct($routing = true)
30
+	{
31
+		parent::__construct($routing);
32
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
34
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
35
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
36
+		}
37
+	}
38
+
39
+
40
+	/**
41
+	 * Sets routes.
42
+	 */
43
+	protected function _extend_page_config()
44
+	{
45
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
46
+		// is there a evt_id in the request?
47
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
48
+			? $this->_req_data['EVT_ID']
49
+			: 0;
50
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
51
+		// tkt_id?
52
+		$tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
53
+			? $this->_req_data['TKT_ID']
54
+			: 0;
55
+		$new_page_routes = array(
56
+			'duplicate_event'          => array(
57
+				'func'       => '_duplicate_event',
58
+				'capability' => 'ee_edit_event',
59
+				'obj_id'     => $evt_id,
60
+				'noheader'   => true,
61
+			),
62
+			'ticket_list_table'        => array(
63
+				'func'       => '_tickets_overview_list_table',
64
+				'capability' => 'ee_read_default_tickets',
65
+			),
66
+			'trash_ticket'             => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_ticket',
69
+				'obj_id'     => $tkt_id,
70
+				'noheader'   => true,
71
+				'args'       => array('trash' => true),
72
+			),
73
+			'trash_tickets'            => array(
74
+				'func'       => '_trash_or_restore_ticket',
75
+				'capability' => 'ee_delete_default_tickets',
76
+				'noheader'   => true,
77
+				'args'       => array('trash' => true),
78
+			),
79
+			'restore_ticket'           => array(
80
+				'func'       => '_trash_or_restore_ticket',
81
+				'capability' => 'ee_delete_default_ticket',
82
+				'obj_id'     => $tkt_id,
83
+				'noheader'   => true,
84
+			),
85
+			'restore_tickets'          => array(
86
+				'func'       => '_trash_or_restore_ticket',
87
+				'capability' => 'ee_delete_default_tickets',
88
+				'noheader'   => true,
89
+			),
90
+			'delete_ticket'            => array(
91
+				'func'       => '_delete_ticket',
92
+				'capability' => 'ee_delete_default_ticket',
93
+				'obj_id'     => $tkt_id,
94
+				'noheader'   => true,
95
+			),
96
+			'delete_tickets'           => array(
97
+				'func'       => '_delete_ticket',
98
+				'capability' => 'ee_delete_default_tickets',
99
+				'noheader'   => true,
100
+			),
101
+			'import_page'              => array(
102
+				'func'       => '_import_page',
103
+				'capability' => 'import',
104
+			),
105
+			'import'                   => array(
106
+				'func'       => '_import_events',
107
+				'capability' => 'import',
108
+				'noheader'   => true,
109
+			),
110
+			'import_events'            => array(
111
+				'func'       => '_import_events',
112
+				'capability' => 'import',
113
+				'noheader'   => true,
114
+			),
115
+			'export_events'            => array(
116
+				'func'       => '_events_export',
117
+				'capability' => 'export',
118
+				'noheader'   => true,
119
+			),
120
+			'export_categories'        => array(
121
+				'func'       => '_categories_export',
122
+				'capability' => 'export',
123
+				'noheader'   => true,
124
+			),
125
+			'sample_export_file'       => array(
126
+				'func'       => '_sample_export_file',
127
+				'capability' => 'export',
128
+				'noheader'   => true,
129
+			),
130
+			'update_template_settings' => array(
131
+				'func'       => '_update_template_settings',
132
+				'capability' => 'manage_options',
133
+				'noheader'   => true,
134
+			),
135
+		);
136
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
137
+		// partial route/config override
138
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
139
+		$this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
140
+		$this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
141
+		$this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
142
+		$this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
143
+		$this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
144
+		// add tickets tab but only if there are more than one default ticket!
145
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
146
+			array(array('TKT_is_default' => 1)),
147
+			'TKT_ID',
148
+			true
149
+		);
150
+		if ($tkt_count > 1) {
151
+			$new_page_config = array(
152
+				'ticket_list_table' => array(
153
+					'nav'           => array(
154
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
155
+						'order' => 60,
156
+					),
157
+					'list_table'    => 'Tickets_List_Table',
158
+					'require_nonce' => false,
159
+				),
160
+			);
161
+		}
162
+		// template settings
163
+		$new_page_config['template_settings'] = array(
164
+			'nav'           => array(
165
+				'label' => esc_html__('Templates', 'event_espresso'),
166
+				'order' => 30,
167
+			),
168
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
169
+			'help_tabs'     => array(
170
+				'general_settings_templates_help_tab' => array(
171
+					'title'    => esc_html__('Templates', 'event_espresso'),
172
+					'filename' => 'general_settings_templates',
173
+				),
174
+			),
175
+			'help_tour'     => array('Templates_Help_Tour'),
176
+			'require_nonce' => false,
177
+		);
178
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
179
+		// add filters and actions
180
+		// modifying _views
181
+		add_filter(
182
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
183
+			array($this, 'add_additional_datetime_button'),
184
+			10,
185
+			2
186
+		);
187
+		add_filter(
188
+			'FHEE_event_datetime_metabox_clone_button_template',
189
+			array($this, 'add_datetime_clone_button'),
190
+			10,
191
+			2
192
+		);
193
+		add_filter(
194
+			'FHEE_event_datetime_metabox_timezones_template',
195
+			array($this, 'datetime_timezones_template'),
196
+			10,
197
+			2
198
+		);
199
+		// filters for event list table
200
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
201
+		add_filter(
202
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
203
+			array($this, 'extra_list_table_actions'),
204
+			10,
205
+			2
206
+		);
207
+		// legend item
208
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
209
+		add_action('admin_init', array($this, 'admin_init'));
210
+		$this->admin_config = EE_Registry::instance()->CFG->admin;
211
+		add_filter(
212
+			'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
213
+			[$this, 'advancedEditorAdminFormSection']
214
+		);
215
+		add_action(
216
+			'AHEE__Events_Admin_Page___update_default_event_settings',
217
+			[$this, 'updateAdvancedEditorAdminFormSettings'],
218
+			10,
219
+			2
220
+		);
221
+	}
222
+
223
+
224
+	/**
225
+	 * admin_init
226
+	 */
227
+	public function admin_init()
228
+	{
229
+		EE_Registry::$i18n_js_strings = array_merge(
230
+			EE_Registry::$i18n_js_strings,
231
+			array(
232
+				'image_confirm'          => esc_html__(
233
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
234
+					'event_espresso'
235
+				),
236
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
237
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
238
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
239
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
240
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
241
+			)
242
+		);
243
+	}
244
+
245
+
246
+	/**
247
+	 * Add per page screen options to the default ticket list table view.
248
+	 */
249
+	protected function _add_screen_options_ticket_list_table()
250
+	{
251
+		$this->_per_page_screen_option();
252
+	}
253
+
254
+
255
+	/**
256
+	 * @param string $return
257
+	 * @param int    $id
258
+	 * @param string $new_title
259
+	 * @param string $new_slug
260
+	 * @return string
261
+	 */
262
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
263
+	{
264
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
265
+		// make sure this is only when editing
266
+		if (! empty($id)) {
267
+			$href = EE_Admin_Page::add_query_args_and_nonce(
268
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
269
+				$this->_admin_base_url
270
+			);
271
+			$title = esc_attr__('Duplicate Event', 'event_espresso');
272
+			$return .= '<a href="'
273
+					   . $href
274
+					   . '" title="'
275
+					   . $title
276
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
277
+					   . $title
278
+					   . '</a>';
279
+		}
280
+		return $return;
281
+	}
282
+
283
+
284
+	/**
285
+	 * Set the list table views for the default ticket list table view.
286
+	 */
287
+	public function _set_list_table_views_ticket_list_table()
288
+	{
289
+		$this->_views = array(
290
+			'all'     => array(
291
+				'slug'        => 'all',
292
+				'label'       => esc_html__('All', 'event_espresso'),
293
+				'count'       => 0,
294
+				'bulk_action' => array(
295
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
296
+				),
297
+			),
298
+			'trashed' => array(
299
+				'slug'        => 'trashed',
300
+				'label'       => esc_html__('Trash', 'event_espresso'),
301
+				'count'       => 0,
302
+				'bulk_action' => array(
303
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
304
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
305
+				),
306
+			),
307
+		);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Enqueue scripts and styles for the event editor.
313
+	 */
314
+	public function load_scripts_styles_edit()
315
+	{
316
+		wp_register_script(
317
+			'ee-event-editor-heartbeat',
318
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
319
+			array('ee_admin_js', 'heartbeat'),
320
+			EVENT_ESPRESSO_VERSION,
321
+			true
322
+		);
323
+		wp_enqueue_script('ee-accounting');
324
+		// styles
325
+		wp_enqueue_style('espresso-ui-theme');
326
+		wp_enqueue_script('event_editor_js');
327
+		wp_enqueue_script('ee-event-editor-heartbeat');
328
+		if ($this->admin_config->useAdvancedEditor()) {
329
+			add_action(
330
+				'admin_footer',
331
+				function () {
332
+					$eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
333
+					if ($eventId) {
334
+						echo '
335 335
         <script type="text/javascript">
336 336
             /* <![CDATA[ */ var eeEditorEventId = ' . $eventId . '; /* ]]> */
337 337
         </script>';
338
-                    }
339
-                }
340
-            );
341
-        }
342
-    }
343
-
344
-
345
-    /**
346
-     * Returns template for the additional datetime.
347
-     *
348
-     * @param $template
349
-     * @param $template_args
350
-     * @return mixed
351
-     * @throws DomainException
352
-     */
353
-    public function add_additional_datetime_button($template, $template_args)
354
-    {
355
-        return EEH_Template::display_template(
356
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
357
-            $template_args,
358
-            true
359
-        );
360
-    }
361
-
362
-
363
-    /**
364
-     * Returns the template for cloning a datetime.
365
-     *
366
-     * @param $template
367
-     * @param $template_args
368
-     * @return mixed
369
-     * @throws DomainException
370
-     */
371
-    public function add_datetime_clone_button($template, $template_args)
372
-    {
373
-        return EEH_Template::display_template(
374
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
375
-            $template_args,
376
-            true
377
-        );
378
-    }
379
-
380
-
381
-    /**
382
-     * Returns the template for datetime timezones.
383
-     *
384
-     * @param $template
385
-     * @param $template_args
386
-     * @return mixed
387
-     * @throws DomainException
388
-     */
389
-    public function datetime_timezones_template($template, $template_args)
390
-    {
391
-        return EEH_Template::display_template(
392
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
393
-            $template_args,
394
-            true
395
-        );
396
-    }
397
-
398
-
399
-    /**
400
-     * Sets the views for the default list table view.
401
-     */
402
-    protected function _set_list_table_views_default()
403
-    {
404
-        parent::_set_list_table_views_default();
405
-        $new_views = array(
406
-            'today' => array(
407
-                'slug'        => 'today',
408
-                'label'       => esc_html__('Today', 'event_espresso'),
409
-                'count'       => $this->total_events_today(),
410
-                'bulk_action' => array(
411
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
412
-                ),
413
-            ),
414
-            'month' => array(
415
-                'slug'        => 'month',
416
-                'label'       => esc_html__('This Month', 'event_espresso'),
417
-                'count'       => $this->total_events_this_month(),
418
-                'bulk_action' => array(
419
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
420
-                ),
421
-            ),
422
-        );
423
-        $this->_views = array_merge($this->_views, $new_views);
424
-    }
425
-
426
-
427
-    /**
428
-     * Returns the extra action links for the default list table view.
429
-     *
430
-     * @param array     $action_links
431
-     * @param \EE_Event $event
432
-     * @return array
433
-     * @throws EE_Error
434
-     */
435
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
436
-    {
437
-        if (EE_Registry::instance()->CAP->current_user_can(
438
-            'ee_read_registrations',
439
-            'espresso_registrations_reports',
440
-            $event->ID()
441
-        )
442
-        ) {
443
-            $reports_query_args = array(
444
-                'action' => 'reports',
445
-                'EVT_ID' => $event->ID(),
446
-            );
447
-            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
448
-            $action_links[] = '<a href="'
449
-                              . $reports_link
450
-                              . '" title="'
451
-                              . esc_attr__('View Report', 'event_espresso')
452
-                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
453
-                              . "\n\t";
454
-        }
455
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
456
-            EE_Registry::instance()->load_helper('MSG_Template');
457
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
458
-                'see_notifications_for',
459
-                null,
460
-                array('EVT_ID' => $event->ID())
461
-            );
462
-        }
463
-        return $action_links;
464
-    }
465
-
466
-
467
-    /**
468
-     * @param $items
469
-     * @return mixed
470
-     */
471
-    public function additional_legend_items($items)
472
-    {
473
-        if (EE_Registry::instance()->CAP->current_user_can(
474
-            'ee_read_registrations',
475
-            'espresso_registrations_reports'
476
-        )
477
-        ) {
478
-            $items['reports'] = array(
479
-                'class' => 'dashicons dashicons-chart-bar',
480
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
481
-            );
482
-        }
483
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
484
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
485
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
486
-                $items['view_related_messages'] = array(
487
-                    'class' => $related_for_icon['css_class'],
488
-                    'desc'  => $related_for_icon['label'],
489
-                );
490
-            }
491
-        }
492
-        return $items;
493
-    }
494
-
495
-
496
-    /**
497
-     * This is the callback method for the duplicate event route
498
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
499
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
500
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
501
-     * After duplication the redirect is to the new event edit page.
502
-     *
503
-     * @return void
504
-     * @access protected
505
-     * @throws EE_Error If EE_Event is not available with given ID
506
-     */
507
-    protected function _duplicate_event()
508
-    {
509
-        // first make sure the ID for the event is in the request.
510
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
511
-        if (! isset($this->_req_data['EVT_ID'])) {
512
-            EE_Error::add_error(
513
-                esc_html__(
514
-                    'In order to duplicate an event an Event ID is required.  None was given.',
515
-                    'event_espresso'
516
-                ),
517
-                __FILE__,
518
-                __FUNCTION__,
519
-                __LINE__
520
-            );
521
-            $this->_redirect_after_action(false, '', '', array(), true);
522
-            return;
523
-        }
524
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
525
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
526
-        if (! $orig_event instanceof EE_Event) {
527
-            throw new EE_Error(
528
-                sprintf(
529
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
530
-                    $this->_req_data['EVT_ID']
531
-                )
532
-            );
533
-        }
534
-        // k now let's clone the $orig_event before getting relations
535
-        $new_event = clone $orig_event;
536
-        // original datetimes
537
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
538
-        // other original relations
539
-        $orig_ven = $orig_event->get_many_related('Venue');
540
-        // reset the ID and modify other details to make it clear this is a dupe
541
-        $new_event->set('EVT_ID', 0);
542
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
543
-        $new_event->set('EVT_name', $new_name);
544
-        $new_event->set(
545
-            'EVT_slug',
546
-            wp_unique_post_slug(
547
-                sanitize_title($orig_event->name()),
548
-                0,
549
-                'publish',
550
-                'espresso_events',
551
-                0
552
-            )
553
-        );
554
-        $new_event->set('status', 'draft');
555
-        // duplicate discussion settings
556
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
557
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
558
-        // save the new event
559
-        $new_event->save();
560
-        // venues
561
-        foreach ($orig_ven as $ven) {
562
-            $new_event->_add_relation_to($ven, 'Venue');
563
-        }
564
-        $new_event->save();
565
-        // now we need to get the question group relations and handle that
566
-        // first primary question groups
567
-        $orig_primary_qgs = $orig_event->get_many_related(
568
-            'Question_Group',
569
-            array(array('Event_Question_Group.EQG_primary' => 1))
570
-        );
571
-        if (! empty($orig_primary_qgs)) {
572
-            foreach ($orig_primary_qgs as $id => $obj) {
573
-                if ($obj instanceof EE_Question_Group) {
574
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
575
-                }
576
-            }
577
-        }
578
-        // next additional attendee question groups
579
-        $orig_additional_qgs = $orig_event->get_many_related(
580
-            'Question_Group',
581
-            array(array('Event_Question_Group.EQG_primary' => 0))
582
-        );
583
-        if (! empty($orig_additional_qgs)) {
584
-            foreach ($orig_additional_qgs as $id => $obj) {
585
-                if ($obj instanceof EE_Question_Group) {
586
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
587
-                }
588
-            }
589
-        }
590
-
591
-        $new_event->save();
592
-
593
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
594
-        $cloned_tickets = array();
595
-        foreach ($orig_datetimes as $orig_dtt) {
596
-            if (! $orig_dtt instanceof EE_Datetime) {
597
-                continue;
598
-            }
599
-            $new_dtt = clone $orig_dtt;
600
-            $orig_tkts = $orig_dtt->tickets();
601
-            // save new dtt then add to event
602
-            $new_dtt->set('DTT_ID', 0);
603
-            $new_dtt->set('DTT_sold', 0);
604
-            $new_dtt->set_reserved(0);
605
-            $new_dtt->save();
606
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
607
-            $new_event->save();
608
-            // now let's get the ticket relations setup.
609
-            foreach ((array) $orig_tkts as $orig_tkt) {
610
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
611
-                if (! $orig_tkt instanceof EE_Ticket) {
612
-                    continue;
613
-                }
614
-                // is this ticket archived?  If it is then let's skip
615
-                if ($orig_tkt->get('TKT_deleted')) {
616
-                    continue;
617
-                }
618
-                // does this original ticket already exist in the clone_tickets cache?
619
-                //  If so we'll just use the new ticket from it.
620
-                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
621
-                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
622
-                } else {
623
-                    $new_tkt = clone $orig_tkt;
624
-                    // get relations on the $orig_tkt that we need to setup.
625
-                    $orig_prices = $orig_tkt->prices();
626
-                    $new_tkt->set('TKT_ID', 0);
627
-                    $new_tkt->set('TKT_sold', 0);
628
-                    $new_tkt->set('TKT_reserved', 0);
629
-                    $new_tkt->save(); // make sure new ticket has ID.
630
-                    // price relations on new ticket need to be setup.
631
-                    foreach ($orig_prices as $orig_price) {
632
-                        $new_price = clone $orig_price;
633
-                        $new_price->set('PRC_ID', 0);
634
-                        $new_price->save();
635
-                        $new_tkt->_add_relation_to($new_price, 'Price');
636
-                        $new_tkt->save();
637
-                    }
638
-
639
-                    do_action(
640
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
641
-                        $orig_tkt,
642
-                        $new_tkt,
643
-                        $orig_prices,
644
-                        $orig_event,
645
-                        $orig_dtt,
646
-                        $new_dtt
647
-                    );
648
-                }
649
-                // k now we can add the new ticket as a relation to the new datetime
650
-                // and make sure its added to our cached $cloned_tickets array
651
-                // for use with later datetimes that have the same ticket.
652
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
653
-                $new_dtt->save();
654
-                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
655
-            }
656
-        }
657
-        // clone taxonomy information
658
-        $taxonomies_to_clone_with = apply_filters(
659
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
660
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
661
-        );
662
-        // get terms for original event (notice)
663
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
664
-        // loop through terms and add them to new event.
665
-        foreach ($orig_terms as $term) {
666
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
667
-        }
668
-
669
-        // duplicate other core WP_Post items for this event.
670
-        // post thumbnail (feature image).
671
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
672
-        if ($feature_image_id) {
673
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
674
-        }
675
-
676
-        // duplicate page_template setting
677
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
678
-        if ($page_template) {
679
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
680
-        }
681
-
682
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
683
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
684
-        if ($new_event->ID()) {
685
-            $redirect_args = array(
686
-                'post'   => $new_event->ID(),
687
-                'action' => 'edit',
688
-            );
689
-            EE_Error::add_success(
690
-                esc_html__(
691
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
692
-                    'event_espresso'
693
-                )
694
-            );
695
-        } else {
696
-            $redirect_args = array(
697
-                'action' => 'default',
698
-            );
699
-            EE_Error::add_error(
700
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
701
-                __FILE__,
702
-                __FUNCTION__,
703
-                __LINE__
704
-            );
705
-        }
706
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
707
-    }
708
-
709
-
710
-    /**
711
-     * Generates output for the import page.
712
-     *
713
-     * @throws DomainException
714
-     */
715
-    protected function _import_page()
716
-    {
717
-        $title = esc_html__('Import', 'event_espresso');
718
-        $intro = esc_html__(
719
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
720
-            'event_espresso'
721
-        );
722
-        $form_url = EVENTS_ADMIN_URL;
723
-        $action = 'import_events';
724
-        $type = 'csv';
725
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
726
-            $title,
727
-            $intro,
728
-            $form_url,
729
-            $action,
730
-            $type
731
-        );
732
-        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
733
-            array('action' => 'sample_export_file'),
734
-            $this->_admin_base_url
735
-        );
736
-        $content = EEH_Template::display_template(
737
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
738
-            $this->_template_args,
739
-            true
740
-        );
741
-        $this->_template_args['admin_page_content'] = $content;
742
-        $this->display_admin_page_with_sidebar();
743
-    }
744
-
745
-
746
-    /**
747
-     * _import_events
748
-     * This handles displaying the screen and running imports for importing events.
749
-     *
750
-     * @return void
751
-     */
752
-    protected function _import_events()
753
-    {
754
-        require_once(EE_CLASSES . 'EE_Import.class.php');
755
-        $success = EE_Import::instance()->import();
756
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
757
-    }
758
-
759
-
760
-    /**
761
-     * _events_export
762
-     * Will export all (or just the given event) to a Excel compatible file.
763
-     *
764
-     * @access protected
765
-     * @return void
766
-     */
767
-    protected function _events_export()
768
-    {
769
-        if (isset($this->_req_data['EVT_ID'])) {
770
-            $event_ids = $this->_req_data['EVT_ID'];
771
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
772
-            $event_ids = $this->_req_data['EVT_IDs'];
773
-        } else {
774
-            $event_ids = null;
775
-        }
776
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
777
-        $new_request_args = array(
778
-            'export' => 'report',
779
-            'action' => 'all_event_data',
780
-            'EVT_ID' => $event_ids,
781
-        );
782
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
783
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
784
-            require_once(EE_CLASSES . 'EE_Export.class.php');
785
-            $EE_Export = EE_Export::instance($this->_req_data);
786
-            $EE_Export->export();
787
-        }
788
-    }
789
-
790
-
791
-    /**
792
-     * handle category exports()
793
-     *
794
-     * @return void
795
-     */
796
-    protected function _categories_export()
797
-    {
798
-        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
799
-        $new_request_args = array(
800
-            'export'       => 'report',
801
-            'action'       => 'categories',
802
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
803
-        );
804
-        $this->_req_data = array_merge($this->_req_data, $new_request_args);
805
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
806
-            require_once(EE_CLASSES . 'EE_Export.class.php');
807
-            $EE_Export = EE_Export::instance($this->_req_data);
808
-            $EE_Export->export();
809
-        }
810
-    }
811
-
812
-
813
-    /**
814
-     * Creates a sample CSV file for importing
815
-     */
816
-    protected function _sample_export_file()
817
-    {
818
-        // require_once(EE_CLASSES . 'EE_Export.class.php');
819
-        EE_Export::instance()->export_sample();
820
-    }
821
-
822
-
823
-    /*************        Template Settings        *************/
824
-    /**
825
-     * Generates template settings page output
826
-     *
827
-     * @throws DomainException
828
-     * @throws EE_Error
829
-     */
830
-    protected function _template_settings()
831
-    {
832
-        $this->_template_args['values'] = $this->_yes_no_values;
833
-        /**
834
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
835
-         * from General_Settings_Admin_Page to here.
836
-         */
837
-        $this->_template_args = apply_filters(
838
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
839
-            $this->_template_args
840
-        );
841
-        $this->_set_add_edit_form_tags('update_template_settings');
842
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
843
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
844
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
845
-            $this->_template_args,
846
-            true
847
-        );
848
-        $this->display_admin_page_with_sidebar();
849
-    }
850
-
851
-
852
-    /**
853
-     * Handler for updating template settings.
854
-     *
855
-     * @throws InvalidInterfaceException
856
-     * @throws InvalidDataTypeException
857
-     * @throws InvalidArgumentException
858
-     */
859
-    protected function _update_template_settings()
860
-    {
861
-        /**
862
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
863
-         * from General_Settings_Admin_Page to here.
864
-         */
865
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
866
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
867
-            EE_Registry::instance()->CFG->template_settings,
868
-            $this->_req_data
869
-        );
870
-        // update custom post type slugs and detect if we need to flush rewrite rules
871
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
872
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
873
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
874
-            : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
875
-        $what = 'Template Settings';
876
-        $success = $this->_update_espresso_configuration(
877
-            $what,
878
-            EE_Registry::instance()->CFG->template_settings,
879
-            __FILE__,
880
-            __FUNCTION__,
881
-            __LINE__
882
-        );
883
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
884
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
885
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
886
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
887
-            );
888
-            $rewrite_rules->flush();
889
-        }
890
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
891
-    }
892
-
893
-
894
-    /**
895
-     * _premium_event_editor_meta_boxes
896
-     * add all metaboxes related to the event_editor
897
-     *
898
-     * @access protected
899
-     * @return void
900
-     * @throws EE_Error
901
-     */
902
-    protected function _premium_event_editor_meta_boxes()
903
-    {
904
-        $this->verify_cpt_object();
905
-        add_meta_box(
906
-            'espresso_event_editor_event_options',
907
-            esc_html__('Event Registration Options', 'event_espresso'),
908
-            array($this, 'registration_options_meta_box'),
909
-            $this->page_slug,
910
-            'side',
911
-            'core'
912
-        );
913
-    }
914
-
915
-
916
-    /**
917
-     * override caf metabox
918
-     *
919
-     * @return void
920
-     * @throws DomainException
921
-     */
922
-    public function registration_options_meta_box()
923
-    {
924
-        $yes_no_values = array(
925
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
926
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
927
-        );
928
-        $default_reg_status_values = EEM_Registration::reg_status_array(
929
-            array(
930
-                EEM_Registration::status_id_cancelled,
931
-                EEM_Registration::status_id_declined,
932
-                EEM_Registration::status_id_incomplete,
933
-                EEM_Registration::status_id_wait_list,
934
-            ),
935
-            true
936
-        );
937
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
938
-        $template_args['_event'] = $this->_cpt_model_obj;
939
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
940
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
941
-            'default_reg_status',
942
-            $default_reg_status_values,
943
-            $this->_cpt_model_obj->default_registration_status()
944
-        );
945
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
946
-            'display_desc',
947
-            $yes_no_values,
948
-            $this->_cpt_model_obj->display_description()
949
-        );
950
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
951
-            'display_ticket_selector',
952
-            $yes_no_values,
953
-            $this->_cpt_model_obj->display_ticket_selector(),
954
-            '',
955
-            '',
956
-            false
957
-        );
958
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
959
-            'EVT_default_registration_status',
960
-            $default_reg_status_values,
961
-            $this->_cpt_model_obj->default_registration_status()
962
-        );
963
-        $template_args['additional_registration_options'] = apply_filters(
964
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
965
-            '',
966
-            $template_args,
967
-            $yes_no_values,
968
-            $default_reg_status_values
969
-        );
970
-        EEH_Template::display_template(
971
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
972
-            $template_args
973
-        );
974
-    }
975
-
976
-
977
-
978
-    /**
979
-     * wp_list_table_mods for caf
980
-     * ============================
981
-     */
982
-    /**
983
-     * hook into list table filters and provide filters for caffeinated list table
984
-     *
985
-     * @param  array $old_filters    any existing filters present
986
-     * @param  array $list_table_obj the list table object
987
-     * @return array                  new filters
988
-     */
989
-    public function list_table_filters($old_filters, $list_table_obj)
990
-    {
991
-        $filters = array();
992
-        // first month/year filters
993
-        $filters[] = $this->espresso_event_months_dropdown();
994
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
995
-        // active status dropdown
996
-        if ($status !== 'draft') {
997
-            $filters[] = $this->active_status_dropdown(
998
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
999
-            );
1000
-        }
1001
-        // category filter
1002
-        $filters[] = $this->category_dropdown();
1003
-        return array_merge($old_filters, $filters);
1004
-    }
1005
-
1006
-
1007
-    /**
1008
-     * espresso_event_months_dropdown
1009
-     *
1010
-     * @access public
1011
-     * @return string                dropdown listing month/year selections for events.
1012
-     */
1013
-    public function espresso_event_months_dropdown()
1014
-    {
1015
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1016
-        // Note we need to include any other filters that are set!
1017
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1018
-        // categories?
1019
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1020
-            ? $this->_req_data['EVT_CAT']
1021
-            : null;
1022
-        // active status?
1023
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1024
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1025
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1026
-    }
1027
-
1028
-
1029
-    /**
1030
-     * returns a list of "active" statuses on the event
1031
-     *
1032
-     * @param  string $current_value whatever the current active status is
1033
-     * @return string
1034
-     */
1035
-    public function active_status_dropdown($current_value = '')
1036
-    {
1037
-        $select_name = 'active_status';
1038
-        $values = array(
1039
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1040
-            'active'   => esc_html__('Active', 'event_espresso'),
1041
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1042
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1043
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1044
-        );
1045
-        $id = 'id="espresso-active-status-dropdown-filter"';
1046
-        $class = 'wide';
1047
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1048
-    }
1049
-
1050
-
1051
-    /**
1052
-     * output a dropdown of the categories for the category filter on the event admin list table
1053
-     *
1054
-     * @access  public
1055
-     * @return string html
1056
-     */
1057
-    public function category_dropdown()
1058
-    {
1059
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1060
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1061
-    }
1062
-
1063
-
1064
-    /**
1065
-     * get total number of events today
1066
-     *
1067
-     * @access public
1068
-     * @return int
1069
-     * @throws EE_Error
1070
-     */
1071
-    public function total_events_today()
1072
-    {
1073
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1074
-            'DTT_EVT_start',
1075
-            date('Y-m-d') . ' 00:00:00',
1076
-            'Y-m-d H:i:s',
1077
-            'UTC'
1078
-        );
1079
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1080
-            'DTT_EVT_start',
1081
-            date('Y-m-d') . ' 23:59:59',
1082
-            'Y-m-d H:i:s',
1083
-            'UTC'
1084
-        );
1085
-        $where = array(
1086
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1087
-        );
1088
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1089
-        return $count;
1090
-    }
1091
-
1092
-
1093
-    /**
1094
-     * get total number of events this month
1095
-     *
1096
-     * @access public
1097
-     * @return int
1098
-     * @throws EE_Error
1099
-     */
1100
-    public function total_events_this_month()
1101
-    {
1102
-        // Dates
1103
-        $this_year_r = date('Y');
1104
-        $this_month_r = date('m');
1105
-        $days_this_month = date('t');
1106
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1107
-            'DTT_EVT_start',
1108
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1109
-            'Y-m-d H:i:s',
1110
-            'UTC'
1111
-        );
1112
-        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1113
-            'DTT_EVT_start',
1114
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1115
-            'Y-m-d H:i:s',
1116
-            'UTC'
1117
-        );
1118
-        $where = array(
1119
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1120
-        );
1121
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1122
-        return $count;
1123
-    }
1124
-
1125
-
1126
-    /** DEFAULT TICKETS STUFF **/
1127
-
1128
-    /**
1129
-     * Output default tickets list table view.
1130
-     */
1131
-    public function _tickets_overview_list_table()
1132
-    {
1133
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1134
-        $this->display_admin_list_table_page_with_no_sidebar();
1135
-    }
1136
-
1137
-
1138
-    /**
1139
-     * @param int  $per_page
1140
-     * @param bool $count
1141
-     * @param bool $trashed
1142
-     * @return \EE_Soft_Delete_Base_Class[]|int
1143
-     */
1144
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1145
-    {
1146
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1147
-        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1148
-        switch ($orderby) {
1149
-            case 'TKT_name':
1150
-                $orderby = array('TKT_name' => $order);
1151
-                break;
1152
-            case 'TKT_price':
1153
-                $orderby = array('TKT_price' => $order);
1154
-                break;
1155
-            case 'TKT_uses':
1156
-                $orderby = array('TKT_uses' => $order);
1157
-                break;
1158
-            case 'TKT_min':
1159
-                $orderby = array('TKT_min' => $order);
1160
-                break;
1161
-            case 'TKT_max':
1162
-                $orderby = array('TKT_max' => $order);
1163
-                break;
1164
-            case 'TKT_qty':
1165
-                $orderby = array('TKT_qty' => $order);
1166
-                break;
1167
-        }
1168
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1169
-            ? $this->_req_data['paged']
1170
-            : 1;
1171
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1172
-            ? $this->_req_data['perpage']
1173
-            : $per_page;
1174
-        $_where = array(
1175
-            'TKT_is_default' => 1,
1176
-            'TKT_deleted'    => $trashed,
1177
-        );
1178
-        $offset = ($current_page - 1) * $per_page;
1179
-        $limit = array($offset, $per_page);
1180
-        if (isset($this->_req_data['s'])) {
1181
-            $sstr = '%' . $this->_req_data['s'] . '%';
1182
-            $_where['OR'] = array(
1183
-                'TKT_name'        => array('LIKE', $sstr),
1184
-                'TKT_description' => array('LIKE', $sstr),
1185
-            );
1186
-        }
1187
-        $query_params = array(
1188
-            $_where,
1189
-            'order_by' => $orderby,
1190
-            'limit'    => $limit,
1191
-            'group_by' => 'TKT_ID',
1192
-        );
1193
-        if ($count) {
1194
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1195
-        } else {
1196
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1197
-        }
1198
-    }
1199
-
1200
-
1201
-    /**
1202
-     * @param bool $trash
1203
-     * @throws EE_Error
1204
-     */
1205
-    protected function _trash_or_restore_ticket($trash = false)
1206
-    {
1207
-        $success = 1;
1208
-        $TKT = EEM_Ticket::instance();
1209
-        // checkboxes?
1210
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1211
-            // if array has more than one element then success message should be plural
1212
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1213
-            // cycle thru the boxes
1214
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1215
-                if ($trash) {
1216
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1217
-                        $success = 0;
1218
-                    }
1219
-                } else {
1220
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1221
-                        $success = 0;
1222
-                    }
1223
-                }
1224
-            }
1225
-        } else {
1226
-            // grab single id and trash
1227
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1228
-            if ($trash) {
1229
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1230
-                    $success = 0;
1231
-                }
1232
-            } else {
1233
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1234
-                    $success = 0;
1235
-                }
1236
-            }
1237
-        }
1238
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1239
-        $query_args = array(
1240
-            'action' => 'ticket_list_table',
1241
-            'status' => $trash ? '' : 'trashed',
1242
-        );
1243
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1244
-    }
1245
-
1246
-
1247
-    /**
1248
-     * Handles trashing default ticket.
1249
-     */
1250
-    protected function _delete_ticket()
1251
-    {
1252
-        $success = 1;
1253
-        // checkboxes?
1254
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1255
-            // if array has more than one element then success message should be plural
1256
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1257
-            // cycle thru the boxes
1258
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1259
-                // delete
1260
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1261
-                    $success = 0;
1262
-                }
1263
-            }
1264
-        } else {
1265
-            // grab single id and trash
1266
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1267
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1268
-                $success = 0;
1269
-            }
1270
-        }
1271
-        $action_desc = 'deleted';
1272
-        $query_args = array(
1273
-            'action' => 'ticket_list_table',
1274
-            'status' => 'trashed',
1275
-        );
1276
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1277
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1278
-            array(array('TKT_is_default' => 1)),
1279
-            'TKT_ID',
1280
-            true
1281
-        )
1282
-        ) {
1283
-            $query_args = array();
1284
-        }
1285
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1286
-    }
1287
-
1288
-
1289
-    /**
1290
-     * @param int $TKT_ID
1291
-     * @return bool|int
1292
-     * @throws EE_Error
1293
-     */
1294
-    protected function _delete_the_ticket($TKT_ID)
1295
-    {
1296
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1297
-        $tkt->_remove_relations('Datetime');
1298
-        // delete all related prices first
1299
-        $tkt->delete_related_permanently('Price');
1300
-        return $tkt->delete_permanently();
1301
-    }
1302
-
1303
-
1304
-    /**
1305
-     * @param array $default_event_settings_form_subsections
1306
-     * @return array
1307
-     * @since $VID:$
1308
-     */
1309
-    public function advancedEditorAdminFormSection(array $default_event_settings_form_subsections)
1310
-    {
1311
-        return [
1312
-            'use_advanced_editor'         => new EE_Select_Input(
1313
-                apply_filters(
1314
-                    'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_options',
1315
-                    [
1316
-                        esc_html__('Legacy Editor', 'event_espresso'),
1317
-                        esc_html__('Advanced Editor', 'event_espresso'),
1318
-                    ]
1319
-                ),
1320
-                [
1321
-                    'default'         => $this->admin_config->useAdvancedEditor(),
1322
-                    'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
1323
-                    'html_help_text'  => sprintf(
1324
-                        esc_html__(
1325
-                            'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
1326
-                            'event_espresso'
1327
-                        ),
1328
-                        '<br />'
1329
-                    ),
1330
-                ]
1331
-            ),
1332
-            'defaults_section_header' => new EE_Form_Section_HTML(
1333
-                EEH_HTML::h2(
1334
-                    esc_html__('Default Settings', 'event_espresso'),
1335
-                    '',
1336
-                    'ee-admin-settings-hdr'
1337
-                )
1338
-            ),
1339
-        ] + $default_event_settings_form_subsections;
1340
-    }
1341
-
1342
-
1343
-    /**
1344
-     * @param array     $valid_data
1345
-     * @param EE_Config $config
1346
-     * @since $VID:$
1347
-     */
1348
-    public function updateAdvancedEditorAdminFormSettings(array $valid_data, EE_Config $config)
1349
-    {
1350
-        $config->admin->setUseAdvancedEditor(
1351
-            isset($valid_data['use_advanced_editor'])
1352
-                ? $valid_data['use_advanced_editor']
1353
-                : false
1354
-        );
1355
-    }
338
+					}
339
+				}
340
+			);
341
+		}
342
+	}
343
+
344
+
345
+	/**
346
+	 * Returns template for the additional datetime.
347
+	 *
348
+	 * @param $template
349
+	 * @param $template_args
350
+	 * @return mixed
351
+	 * @throws DomainException
352
+	 */
353
+	public function add_additional_datetime_button($template, $template_args)
354
+	{
355
+		return EEH_Template::display_template(
356
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
357
+			$template_args,
358
+			true
359
+		);
360
+	}
361
+
362
+
363
+	/**
364
+	 * Returns the template for cloning a datetime.
365
+	 *
366
+	 * @param $template
367
+	 * @param $template_args
368
+	 * @return mixed
369
+	 * @throws DomainException
370
+	 */
371
+	public function add_datetime_clone_button($template, $template_args)
372
+	{
373
+		return EEH_Template::display_template(
374
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
375
+			$template_args,
376
+			true
377
+		);
378
+	}
379
+
380
+
381
+	/**
382
+	 * Returns the template for datetime timezones.
383
+	 *
384
+	 * @param $template
385
+	 * @param $template_args
386
+	 * @return mixed
387
+	 * @throws DomainException
388
+	 */
389
+	public function datetime_timezones_template($template, $template_args)
390
+	{
391
+		return EEH_Template::display_template(
392
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
393
+			$template_args,
394
+			true
395
+		);
396
+	}
397
+
398
+
399
+	/**
400
+	 * Sets the views for the default list table view.
401
+	 */
402
+	protected function _set_list_table_views_default()
403
+	{
404
+		parent::_set_list_table_views_default();
405
+		$new_views = array(
406
+			'today' => array(
407
+				'slug'        => 'today',
408
+				'label'       => esc_html__('Today', 'event_espresso'),
409
+				'count'       => $this->total_events_today(),
410
+				'bulk_action' => array(
411
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
412
+				),
413
+			),
414
+			'month' => array(
415
+				'slug'        => 'month',
416
+				'label'       => esc_html__('This Month', 'event_espresso'),
417
+				'count'       => $this->total_events_this_month(),
418
+				'bulk_action' => array(
419
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
420
+				),
421
+			),
422
+		);
423
+		$this->_views = array_merge($this->_views, $new_views);
424
+	}
425
+
426
+
427
+	/**
428
+	 * Returns the extra action links for the default list table view.
429
+	 *
430
+	 * @param array     $action_links
431
+	 * @param \EE_Event $event
432
+	 * @return array
433
+	 * @throws EE_Error
434
+	 */
435
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
436
+	{
437
+		if (EE_Registry::instance()->CAP->current_user_can(
438
+			'ee_read_registrations',
439
+			'espresso_registrations_reports',
440
+			$event->ID()
441
+		)
442
+		) {
443
+			$reports_query_args = array(
444
+				'action' => 'reports',
445
+				'EVT_ID' => $event->ID(),
446
+			);
447
+			$reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
448
+			$action_links[] = '<a href="'
449
+							  . $reports_link
450
+							  . '" title="'
451
+							  . esc_attr__('View Report', 'event_espresso')
452
+							  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
453
+							  . "\n\t";
454
+		}
455
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
456
+			EE_Registry::instance()->load_helper('MSG_Template');
457
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
458
+				'see_notifications_for',
459
+				null,
460
+				array('EVT_ID' => $event->ID())
461
+			);
462
+		}
463
+		return $action_links;
464
+	}
465
+
466
+
467
+	/**
468
+	 * @param $items
469
+	 * @return mixed
470
+	 */
471
+	public function additional_legend_items($items)
472
+	{
473
+		if (EE_Registry::instance()->CAP->current_user_can(
474
+			'ee_read_registrations',
475
+			'espresso_registrations_reports'
476
+		)
477
+		) {
478
+			$items['reports'] = array(
479
+				'class' => 'dashicons dashicons-chart-bar',
480
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
481
+			);
482
+		}
483
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
484
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
485
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
486
+				$items['view_related_messages'] = array(
487
+					'class' => $related_for_icon['css_class'],
488
+					'desc'  => $related_for_icon['label'],
489
+				);
490
+			}
491
+		}
492
+		return $items;
493
+	}
494
+
495
+
496
+	/**
497
+	 * This is the callback method for the duplicate event route
498
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
499
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
500
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
501
+	 * After duplication the redirect is to the new event edit page.
502
+	 *
503
+	 * @return void
504
+	 * @access protected
505
+	 * @throws EE_Error If EE_Event is not available with given ID
506
+	 */
507
+	protected function _duplicate_event()
508
+	{
509
+		// first make sure the ID for the event is in the request.
510
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
511
+		if (! isset($this->_req_data['EVT_ID'])) {
512
+			EE_Error::add_error(
513
+				esc_html__(
514
+					'In order to duplicate an event an Event ID is required.  None was given.',
515
+					'event_espresso'
516
+				),
517
+				__FILE__,
518
+				__FUNCTION__,
519
+				__LINE__
520
+			);
521
+			$this->_redirect_after_action(false, '', '', array(), true);
522
+			return;
523
+		}
524
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
525
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
526
+		if (! $orig_event instanceof EE_Event) {
527
+			throw new EE_Error(
528
+				sprintf(
529
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
530
+					$this->_req_data['EVT_ID']
531
+				)
532
+			);
533
+		}
534
+		// k now let's clone the $orig_event before getting relations
535
+		$new_event = clone $orig_event;
536
+		// original datetimes
537
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
538
+		// other original relations
539
+		$orig_ven = $orig_event->get_many_related('Venue');
540
+		// reset the ID and modify other details to make it clear this is a dupe
541
+		$new_event->set('EVT_ID', 0);
542
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
543
+		$new_event->set('EVT_name', $new_name);
544
+		$new_event->set(
545
+			'EVT_slug',
546
+			wp_unique_post_slug(
547
+				sanitize_title($orig_event->name()),
548
+				0,
549
+				'publish',
550
+				'espresso_events',
551
+				0
552
+			)
553
+		);
554
+		$new_event->set('status', 'draft');
555
+		// duplicate discussion settings
556
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
557
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
558
+		// save the new event
559
+		$new_event->save();
560
+		// venues
561
+		foreach ($orig_ven as $ven) {
562
+			$new_event->_add_relation_to($ven, 'Venue');
563
+		}
564
+		$new_event->save();
565
+		// now we need to get the question group relations and handle that
566
+		// first primary question groups
567
+		$orig_primary_qgs = $orig_event->get_many_related(
568
+			'Question_Group',
569
+			array(array('Event_Question_Group.EQG_primary' => 1))
570
+		);
571
+		if (! empty($orig_primary_qgs)) {
572
+			foreach ($orig_primary_qgs as $id => $obj) {
573
+				if ($obj instanceof EE_Question_Group) {
574
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
575
+				}
576
+			}
577
+		}
578
+		// next additional attendee question groups
579
+		$orig_additional_qgs = $orig_event->get_many_related(
580
+			'Question_Group',
581
+			array(array('Event_Question_Group.EQG_primary' => 0))
582
+		);
583
+		if (! empty($orig_additional_qgs)) {
584
+			foreach ($orig_additional_qgs as $id => $obj) {
585
+				if ($obj instanceof EE_Question_Group) {
586
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
587
+				}
588
+			}
589
+		}
590
+
591
+		$new_event->save();
592
+
593
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
594
+		$cloned_tickets = array();
595
+		foreach ($orig_datetimes as $orig_dtt) {
596
+			if (! $orig_dtt instanceof EE_Datetime) {
597
+				continue;
598
+			}
599
+			$new_dtt = clone $orig_dtt;
600
+			$orig_tkts = $orig_dtt->tickets();
601
+			// save new dtt then add to event
602
+			$new_dtt->set('DTT_ID', 0);
603
+			$new_dtt->set('DTT_sold', 0);
604
+			$new_dtt->set_reserved(0);
605
+			$new_dtt->save();
606
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
607
+			$new_event->save();
608
+			// now let's get the ticket relations setup.
609
+			foreach ((array) $orig_tkts as $orig_tkt) {
610
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
611
+				if (! $orig_tkt instanceof EE_Ticket) {
612
+					continue;
613
+				}
614
+				// is this ticket archived?  If it is then let's skip
615
+				if ($orig_tkt->get('TKT_deleted')) {
616
+					continue;
617
+				}
618
+				// does this original ticket already exist in the clone_tickets cache?
619
+				//  If so we'll just use the new ticket from it.
620
+				if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
621
+					$new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
622
+				} else {
623
+					$new_tkt = clone $orig_tkt;
624
+					// get relations on the $orig_tkt that we need to setup.
625
+					$orig_prices = $orig_tkt->prices();
626
+					$new_tkt->set('TKT_ID', 0);
627
+					$new_tkt->set('TKT_sold', 0);
628
+					$new_tkt->set('TKT_reserved', 0);
629
+					$new_tkt->save(); // make sure new ticket has ID.
630
+					// price relations on new ticket need to be setup.
631
+					foreach ($orig_prices as $orig_price) {
632
+						$new_price = clone $orig_price;
633
+						$new_price->set('PRC_ID', 0);
634
+						$new_price->save();
635
+						$new_tkt->_add_relation_to($new_price, 'Price');
636
+						$new_tkt->save();
637
+					}
638
+
639
+					do_action(
640
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
641
+						$orig_tkt,
642
+						$new_tkt,
643
+						$orig_prices,
644
+						$orig_event,
645
+						$orig_dtt,
646
+						$new_dtt
647
+					);
648
+				}
649
+				// k now we can add the new ticket as a relation to the new datetime
650
+				// and make sure its added to our cached $cloned_tickets array
651
+				// for use with later datetimes that have the same ticket.
652
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
653
+				$new_dtt->save();
654
+				$cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
655
+			}
656
+		}
657
+		// clone taxonomy information
658
+		$taxonomies_to_clone_with = apply_filters(
659
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
660
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
661
+		);
662
+		// get terms for original event (notice)
663
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
664
+		// loop through terms and add them to new event.
665
+		foreach ($orig_terms as $term) {
666
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
667
+		}
668
+
669
+		// duplicate other core WP_Post items for this event.
670
+		// post thumbnail (feature image).
671
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
672
+		if ($feature_image_id) {
673
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
674
+		}
675
+
676
+		// duplicate page_template setting
677
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
678
+		if ($page_template) {
679
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
680
+		}
681
+
682
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
683
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
684
+		if ($new_event->ID()) {
685
+			$redirect_args = array(
686
+				'post'   => $new_event->ID(),
687
+				'action' => 'edit',
688
+			);
689
+			EE_Error::add_success(
690
+				esc_html__(
691
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
692
+					'event_espresso'
693
+				)
694
+			);
695
+		} else {
696
+			$redirect_args = array(
697
+				'action' => 'default',
698
+			);
699
+			EE_Error::add_error(
700
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
701
+				__FILE__,
702
+				__FUNCTION__,
703
+				__LINE__
704
+			);
705
+		}
706
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
707
+	}
708
+
709
+
710
+	/**
711
+	 * Generates output for the import page.
712
+	 *
713
+	 * @throws DomainException
714
+	 */
715
+	protected function _import_page()
716
+	{
717
+		$title = esc_html__('Import', 'event_espresso');
718
+		$intro = esc_html__(
719
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
720
+			'event_espresso'
721
+		);
722
+		$form_url = EVENTS_ADMIN_URL;
723
+		$action = 'import_events';
724
+		$type = 'csv';
725
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
726
+			$title,
727
+			$intro,
728
+			$form_url,
729
+			$action,
730
+			$type
731
+		);
732
+		$this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
733
+			array('action' => 'sample_export_file'),
734
+			$this->_admin_base_url
735
+		);
736
+		$content = EEH_Template::display_template(
737
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
738
+			$this->_template_args,
739
+			true
740
+		);
741
+		$this->_template_args['admin_page_content'] = $content;
742
+		$this->display_admin_page_with_sidebar();
743
+	}
744
+
745
+
746
+	/**
747
+	 * _import_events
748
+	 * This handles displaying the screen and running imports for importing events.
749
+	 *
750
+	 * @return void
751
+	 */
752
+	protected function _import_events()
753
+	{
754
+		require_once(EE_CLASSES . 'EE_Import.class.php');
755
+		$success = EE_Import::instance()->import();
756
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
757
+	}
758
+
759
+
760
+	/**
761
+	 * _events_export
762
+	 * Will export all (or just the given event) to a Excel compatible file.
763
+	 *
764
+	 * @access protected
765
+	 * @return void
766
+	 */
767
+	protected function _events_export()
768
+	{
769
+		if (isset($this->_req_data['EVT_ID'])) {
770
+			$event_ids = $this->_req_data['EVT_ID'];
771
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
772
+			$event_ids = $this->_req_data['EVT_IDs'];
773
+		} else {
774
+			$event_ids = null;
775
+		}
776
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
777
+		$new_request_args = array(
778
+			'export' => 'report',
779
+			'action' => 'all_event_data',
780
+			'EVT_ID' => $event_ids,
781
+		);
782
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
783
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
784
+			require_once(EE_CLASSES . 'EE_Export.class.php');
785
+			$EE_Export = EE_Export::instance($this->_req_data);
786
+			$EE_Export->export();
787
+		}
788
+	}
789
+
790
+
791
+	/**
792
+	 * handle category exports()
793
+	 *
794
+	 * @return void
795
+	 */
796
+	protected function _categories_export()
797
+	{
798
+		// todo: I don't like doing this but it'll do until we modify EE_Export Class.
799
+		$new_request_args = array(
800
+			'export'       => 'report',
801
+			'action'       => 'categories',
802
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
803
+		);
804
+		$this->_req_data = array_merge($this->_req_data, $new_request_args);
805
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
806
+			require_once(EE_CLASSES . 'EE_Export.class.php');
807
+			$EE_Export = EE_Export::instance($this->_req_data);
808
+			$EE_Export->export();
809
+		}
810
+	}
811
+
812
+
813
+	/**
814
+	 * Creates a sample CSV file for importing
815
+	 */
816
+	protected function _sample_export_file()
817
+	{
818
+		// require_once(EE_CLASSES . 'EE_Export.class.php');
819
+		EE_Export::instance()->export_sample();
820
+	}
821
+
822
+
823
+	/*************        Template Settings        *************/
824
+	/**
825
+	 * Generates template settings page output
826
+	 *
827
+	 * @throws DomainException
828
+	 * @throws EE_Error
829
+	 */
830
+	protected function _template_settings()
831
+	{
832
+		$this->_template_args['values'] = $this->_yes_no_values;
833
+		/**
834
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
835
+		 * from General_Settings_Admin_Page to here.
836
+		 */
837
+		$this->_template_args = apply_filters(
838
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
839
+			$this->_template_args
840
+		);
841
+		$this->_set_add_edit_form_tags('update_template_settings');
842
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
843
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
844
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
845
+			$this->_template_args,
846
+			true
847
+		);
848
+		$this->display_admin_page_with_sidebar();
849
+	}
850
+
851
+
852
+	/**
853
+	 * Handler for updating template settings.
854
+	 *
855
+	 * @throws InvalidInterfaceException
856
+	 * @throws InvalidDataTypeException
857
+	 * @throws InvalidArgumentException
858
+	 */
859
+	protected function _update_template_settings()
860
+	{
861
+		/**
862
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
863
+		 * from General_Settings_Admin_Page to here.
864
+		 */
865
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
866
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
867
+			EE_Registry::instance()->CFG->template_settings,
868
+			$this->_req_data
869
+		);
870
+		// update custom post type slugs and detect if we need to flush rewrite rules
871
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
872
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
873
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
874
+			: EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
875
+		$what = 'Template Settings';
876
+		$success = $this->_update_espresso_configuration(
877
+			$what,
878
+			EE_Registry::instance()->CFG->template_settings,
879
+			__FILE__,
880
+			__FUNCTION__,
881
+			__LINE__
882
+		);
883
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
884
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
885
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
886
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
887
+			);
888
+			$rewrite_rules->flush();
889
+		}
890
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
891
+	}
892
+
893
+
894
+	/**
895
+	 * _premium_event_editor_meta_boxes
896
+	 * add all metaboxes related to the event_editor
897
+	 *
898
+	 * @access protected
899
+	 * @return void
900
+	 * @throws EE_Error
901
+	 */
902
+	protected function _premium_event_editor_meta_boxes()
903
+	{
904
+		$this->verify_cpt_object();
905
+		add_meta_box(
906
+			'espresso_event_editor_event_options',
907
+			esc_html__('Event Registration Options', 'event_espresso'),
908
+			array($this, 'registration_options_meta_box'),
909
+			$this->page_slug,
910
+			'side',
911
+			'core'
912
+		);
913
+	}
914
+
915
+
916
+	/**
917
+	 * override caf metabox
918
+	 *
919
+	 * @return void
920
+	 * @throws DomainException
921
+	 */
922
+	public function registration_options_meta_box()
923
+	{
924
+		$yes_no_values = array(
925
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
926
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
927
+		);
928
+		$default_reg_status_values = EEM_Registration::reg_status_array(
929
+			array(
930
+				EEM_Registration::status_id_cancelled,
931
+				EEM_Registration::status_id_declined,
932
+				EEM_Registration::status_id_incomplete,
933
+				EEM_Registration::status_id_wait_list,
934
+			),
935
+			true
936
+		);
937
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
938
+		$template_args['_event'] = $this->_cpt_model_obj;
939
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
940
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
941
+			'default_reg_status',
942
+			$default_reg_status_values,
943
+			$this->_cpt_model_obj->default_registration_status()
944
+		);
945
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
946
+			'display_desc',
947
+			$yes_no_values,
948
+			$this->_cpt_model_obj->display_description()
949
+		);
950
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
951
+			'display_ticket_selector',
952
+			$yes_no_values,
953
+			$this->_cpt_model_obj->display_ticket_selector(),
954
+			'',
955
+			'',
956
+			false
957
+		);
958
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
959
+			'EVT_default_registration_status',
960
+			$default_reg_status_values,
961
+			$this->_cpt_model_obj->default_registration_status()
962
+		);
963
+		$template_args['additional_registration_options'] = apply_filters(
964
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
965
+			'',
966
+			$template_args,
967
+			$yes_no_values,
968
+			$default_reg_status_values
969
+		);
970
+		EEH_Template::display_template(
971
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
972
+			$template_args
973
+		);
974
+	}
975
+
976
+
977
+
978
+	/**
979
+	 * wp_list_table_mods for caf
980
+	 * ============================
981
+	 */
982
+	/**
983
+	 * hook into list table filters and provide filters for caffeinated list table
984
+	 *
985
+	 * @param  array $old_filters    any existing filters present
986
+	 * @param  array $list_table_obj the list table object
987
+	 * @return array                  new filters
988
+	 */
989
+	public function list_table_filters($old_filters, $list_table_obj)
990
+	{
991
+		$filters = array();
992
+		// first month/year filters
993
+		$filters[] = $this->espresso_event_months_dropdown();
994
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
995
+		// active status dropdown
996
+		if ($status !== 'draft') {
997
+			$filters[] = $this->active_status_dropdown(
998
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
999
+			);
1000
+		}
1001
+		// category filter
1002
+		$filters[] = $this->category_dropdown();
1003
+		return array_merge($old_filters, $filters);
1004
+	}
1005
+
1006
+
1007
+	/**
1008
+	 * espresso_event_months_dropdown
1009
+	 *
1010
+	 * @access public
1011
+	 * @return string                dropdown listing month/year selections for events.
1012
+	 */
1013
+	public function espresso_event_months_dropdown()
1014
+	{
1015
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1016
+		// Note we need to include any other filters that are set!
1017
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1018
+		// categories?
1019
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1020
+			? $this->_req_data['EVT_CAT']
1021
+			: null;
1022
+		// active status?
1023
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1024
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1025
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1026
+	}
1027
+
1028
+
1029
+	/**
1030
+	 * returns a list of "active" statuses on the event
1031
+	 *
1032
+	 * @param  string $current_value whatever the current active status is
1033
+	 * @return string
1034
+	 */
1035
+	public function active_status_dropdown($current_value = '')
1036
+	{
1037
+		$select_name = 'active_status';
1038
+		$values = array(
1039
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1040
+			'active'   => esc_html__('Active', 'event_espresso'),
1041
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1042
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1043
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1044
+		);
1045
+		$id = 'id="espresso-active-status-dropdown-filter"';
1046
+		$class = 'wide';
1047
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
1048
+	}
1049
+
1050
+
1051
+	/**
1052
+	 * output a dropdown of the categories for the category filter on the event admin list table
1053
+	 *
1054
+	 * @access  public
1055
+	 * @return string html
1056
+	 */
1057
+	public function category_dropdown()
1058
+	{
1059
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1060
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1061
+	}
1062
+
1063
+
1064
+	/**
1065
+	 * get total number of events today
1066
+	 *
1067
+	 * @access public
1068
+	 * @return int
1069
+	 * @throws EE_Error
1070
+	 */
1071
+	public function total_events_today()
1072
+	{
1073
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1074
+			'DTT_EVT_start',
1075
+			date('Y-m-d') . ' 00:00:00',
1076
+			'Y-m-d H:i:s',
1077
+			'UTC'
1078
+		);
1079
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1080
+			'DTT_EVT_start',
1081
+			date('Y-m-d') . ' 23:59:59',
1082
+			'Y-m-d H:i:s',
1083
+			'UTC'
1084
+		);
1085
+		$where = array(
1086
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1087
+		);
1088
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1089
+		return $count;
1090
+	}
1091
+
1092
+
1093
+	/**
1094
+	 * get total number of events this month
1095
+	 *
1096
+	 * @access public
1097
+	 * @return int
1098
+	 * @throws EE_Error
1099
+	 */
1100
+	public function total_events_this_month()
1101
+	{
1102
+		// Dates
1103
+		$this_year_r = date('Y');
1104
+		$this_month_r = date('m');
1105
+		$days_this_month = date('t');
1106
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1107
+			'DTT_EVT_start',
1108
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1109
+			'Y-m-d H:i:s',
1110
+			'UTC'
1111
+		);
1112
+		$end = EEM_Datetime::instance()->convert_datetime_for_query(
1113
+			'DTT_EVT_start',
1114
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1115
+			'Y-m-d H:i:s',
1116
+			'UTC'
1117
+		);
1118
+		$where = array(
1119
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1120
+		);
1121
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1122
+		return $count;
1123
+	}
1124
+
1125
+
1126
+	/** DEFAULT TICKETS STUFF **/
1127
+
1128
+	/**
1129
+	 * Output default tickets list table view.
1130
+	 */
1131
+	public function _tickets_overview_list_table()
1132
+	{
1133
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1134
+		$this->display_admin_list_table_page_with_no_sidebar();
1135
+	}
1136
+
1137
+
1138
+	/**
1139
+	 * @param int  $per_page
1140
+	 * @param bool $count
1141
+	 * @param bool $trashed
1142
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1143
+	 */
1144
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1145
+	{
1146
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1147
+		$order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1148
+		switch ($orderby) {
1149
+			case 'TKT_name':
1150
+				$orderby = array('TKT_name' => $order);
1151
+				break;
1152
+			case 'TKT_price':
1153
+				$orderby = array('TKT_price' => $order);
1154
+				break;
1155
+			case 'TKT_uses':
1156
+				$orderby = array('TKT_uses' => $order);
1157
+				break;
1158
+			case 'TKT_min':
1159
+				$orderby = array('TKT_min' => $order);
1160
+				break;
1161
+			case 'TKT_max':
1162
+				$orderby = array('TKT_max' => $order);
1163
+				break;
1164
+			case 'TKT_qty':
1165
+				$orderby = array('TKT_qty' => $order);
1166
+				break;
1167
+		}
1168
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1169
+			? $this->_req_data['paged']
1170
+			: 1;
1171
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1172
+			? $this->_req_data['perpage']
1173
+			: $per_page;
1174
+		$_where = array(
1175
+			'TKT_is_default' => 1,
1176
+			'TKT_deleted'    => $trashed,
1177
+		);
1178
+		$offset = ($current_page - 1) * $per_page;
1179
+		$limit = array($offset, $per_page);
1180
+		if (isset($this->_req_data['s'])) {
1181
+			$sstr = '%' . $this->_req_data['s'] . '%';
1182
+			$_where['OR'] = array(
1183
+				'TKT_name'        => array('LIKE', $sstr),
1184
+				'TKT_description' => array('LIKE', $sstr),
1185
+			);
1186
+		}
1187
+		$query_params = array(
1188
+			$_where,
1189
+			'order_by' => $orderby,
1190
+			'limit'    => $limit,
1191
+			'group_by' => 'TKT_ID',
1192
+		);
1193
+		if ($count) {
1194
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1195
+		} else {
1196
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1197
+		}
1198
+	}
1199
+
1200
+
1201
+	/**
1202
+	 * @param bool $trash
1203
+	 * @throws EE_Error
1204
+	 */
1205
+	protected function _trash_or_restore_ticket($trash = false)
1206
+	{
1207
+		$success = 1;
1208
+		$TKT = EEM_Ticket::instance();
1209
+		// checkboxes?
1210
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1211
+			// if array has more than one element then success message should be plural
1212
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1213
+			// cycle thru the boxes
1214
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1215
+				if ($trash) {
1216
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1217
+						$success = 0;
1218
+					}
1219
+				} else {
1220
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1221
+						$success = 0;
1222
+					}
1223
+				}
1224
+			}
1225
+		} else {
1226
+			// grab single id and trash
1227
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1228
+			if ($trash) {
1229
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1230
+					$success = 0;
1231
+				}
1232
+			} else {
1233
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1234
+					$success = 0;
1235
+				}
1236
+			}
1237
+		}
1238
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1239
+		$query_args = array(
1240
+			'action' => 'ticket_list_table',
1241
+			'status' => $trash ? '' : 'trashed',
1242
+		);
1243
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1244
+	}
1245
+
1246
+
1247
+	/**
1248
+	 * Handles trashing default ticket.
1249
+	 */
1250
+	protected function _delete_ticket()
1251
+	{
1252
+		$success = 1;
1253
+		// checkboxes?
1254
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1255
+			// if array has more than one element then success message should be plural
1256
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1257
+			// cycle thru the boxes
1258
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1259
+				// delete
1260
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1261
+					$success = 0;
1262
+				}
1263
+			}
1264
+		} else {
1265
+			// grab single id and trash
1266
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1267
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1268
+				$success = 0;
1269
+			}
1270
+		}
1271
+		$action_desc = 'deleted';
1272
+		$query_args = array(
1273
+			'action' => 'ticket_list_table',
1274
+			'status' => 'trashed',
1275
+		);
1276
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1277
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1278
+			array(array('TKT_is_default' => 1)),
1279
+			'TKT_ID',
1280
+			true
1281
+		)
1282
+		) {
1283
+			$query_args = array();
1284
+		}
1285
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1286
+	}
1287
+
1288
+
1289
+	/**
1290
+	 * @param int $TKT_ID
1291
+	 * @return bool|int
1292
+	 * @throws EE_Error
1293
+	 */
1294
+	protected function _delete_the_ticket($TKT_ID)
1295
+	{
1296
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1297
+		$tkt->_remove_relations('Datetime');
1298
+		// delete all related prices first
1299
+		$tkt->delete_related_permanently('Price');
1300
+		return $tkt->delete_permanently();
1301
+	}
1302
+
1303
+
1304
+	/**
1305
+	 * @param array $default_event_settings_form_subsections
1306
+	 * @return array
1307
+	 * @since $VID:$
1308
+	 */
1309
+	public function advancedEditorAdminFormSection(array $default_event_settings_form_subsections)
1310
+	{
1311
+		return [
1312
+			'use_advanced_editor'         => new EE_Select_Input(
1313
+				apply_filters(
1314
+					'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_options',
1315
+					[
1316
+						esc_html__('Legacy Editor', 'event_espresso'),
1317
+						esc_html__('Advanced Editor', 'event_espresso'),
1318
+					]
1319
+				),
1320
+				[
1321
+					'default'         => $this->admin_config->useAdvancedEditor(),
1322
+					'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
1323
+					'html_help_text'  => sprintf(
1324
+						esc_html__(
1325
+							'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
1326
+							'event_espresso'
1327
+						),
1328
+						'<br />'
1329
+					),
1330
+				]
1331
+			),
1332
+			'defaults_section_header' => new EE_Form_Section_HTML(
1333
+				EEH_HTML::h2(
1334
+					esc_html__('Default Settings', 'event_espresso'),
1335
+					'',
1336
+					'ee-admin-settings-hdr'
1337
+				)
1338
+			),
1339
+		] + $default_event_settings_form_subsections;
1340
+	}
1341
+
1342
+
1343
+	/**
1344
+	 * @param array     $valid_data
1345
+	 * @param EE_Config $config
1346
+	 * @since $VID:$
1347
+	 */
1348
+	public function updateAdvancedEditorAdminFormSettings(array $valid_data, EE_Config $config)
1349
+	{
1350
+		$config->admin->setUseAdvancedEditor(
1351
+			isset($valid_data['use_advanced_editor'])
1352
+				? $valid_data['use_advanced_editor']
1353
+				: false
1354
+		);
1355
+	}
1356 1356
 }
Please login to merge, or discard this patch.