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