Completed
Branch EDTR/refactor-master (7fdaf0)
by
unknown
17:48 queued 09:57
created

Extend_Events_Admin_Page::venuesDropdown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
use EventEspresso\core\exceptions\InvalidDataTypeException;
4
use EventEspresso\core\exceptions\InvalidInterfaceException;
5
use EventEspresso\core\services\loaders\LoaderFactory;
6
7
/**
8
 * Extend_Events_Admin_Page
9
 * This is the Events Caffeinated admin page.
10
 *
11
 * @package         Extend_Events_Admin_Page
12
 * @subpackage      includes/core/admin/Extend_Events_Admin_Page.core.php
13
 * @author          Darren Ethier
14
 */
15
class Extend_Events_Admin_Page extends Events_Admin_Page
16
{
17
18
    /**
19
     * @var EE_Admin_Config
20
     */
21
    protected $admin_config;
22
23
24
    /**
25
     * Extend_Events_Admin_Page constructor.
26
     *
27
     * @param bool $routing
28
     */
29 View Code Duplication
    public function __construct($routing = true)
30
    {
31
        parent::__construct($routing);
32
        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
33
            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
34
            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
35
            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
36
        }
37
    }
38
39
40
    /**
41
     * Sets routes.
42
     */
43
    protected function _extend_page_config()
44
    {
45
        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
46
        // is there a evt_id in the request?
47
        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
48
            ? $this->_req_data['EVT_ID']
49
            : 0;
50
        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
51
        // tkt_id?
52
        $tkt_id = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
53
            ? $this->_req_data['TKT_ID']
54
            : 0;
55
        $new_page_routes = array(
56
            'duplicate_event'          => array(
57
                'func'       => '_duplicate_event',
58
                'capability' => 'ee_edit_event',
59
                'obj_id'     => $evt_id,
60
                'noheader'   => true,
61
            ),
62
            'ticket_list_table'        => array(
63
                'func'       => '_tickets_overview_list_table',
64
                'capability' => 'ee_read_default_tickets',
65
            ),
66
            'trash_ticket'             => array(
67
                'func'       => '_trash_or_restore_ticket',
68
                'capability' => 'ee_delete_default_ticket',
69
                'obj_id'     => $tkt_id,
70
                'noheader'   => true,
71
                'args'       => array('trash' => true),
72
            ),
73
            'trash_tickets'            => array(
74
                'func'       => '_trash_or_restore_ticket',
75
                'capability' => 'ee_delete_default_tickets',
76
                'noheader'   => true,
77
                'args'       => array('trash' => true),
78
            ),
79
            'restore_ticket'           => array(
80
                'func'       => '_trash_or_restore_ticket',
81
                'capability' => 'ee_delete_default_ticket',
82
                'obj_id'     => $tkt_id,
83
                'noheader'   => true,
84
            ),
85
            'restore_tickets'          => array(
86
                'func'       => '_trash_or_restore_ticket',
87
                'capability' => 'ee_delete_default_tickets',
88
                'noheader'   => true,
89
            ),
90
            'delete_ticket'            => array(
91
                'func'       => '_delete_ticket',
92
                'capability' => 'ee_delete_default_ticket',
93
                'obj_id'     => $tkt_id,
94
                'noheader'   => true,
95
            ),
96
            'delete_tickets'           => array(
97
                'func'       => '_delete_ticket',
98
                'capability' => 'ee_delete_default_tickets',
99
                'noheader'   => true,
100
            ),
101
            'import_page'              => array(
102
                'func'       => '_import_page',
103
                'capability' => 'import',
104
            ),
105
            'import'                   => array(
106
                'func'       => '_import_events',
107
                'capability' => 'import',
108
                'noheader'   => true,
109
            ),
110
            'import_events'            => array(
111
                'func'       => '_import_events',
112
                'capability' => 'import',
113
                'noheader'   => true,
114
            ),
115
            'export_events'            => array(
116
                'func'       => '_events_export',
117
                'capability' => 'export',
118
                'noheader'   => true,
119
            ),
120
            'export_categories'        => array(
121
                'func'       => '_categories_export',
122
                'capability' => 'export',
123
                'noheader'   => true,
124
            ),
125
            'sample_export_file'       => array(
126
                'func'       => '_sample_export_file',
127
                'capability' => 'export',
128
                'noheader'   => true,
129
            ),
130
            'update_template_settings' => array(
131
                'func'       => '_update_template_settings',
132
                'capability' => 'manage_options',
133
                'noheader'   => true,
134
            ),
135
        );
136
        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
137
        // partial route/config override
138
        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
139
        $this->_page_config['create_new']['metaboxes'][] = '_premium_event_editor_meta_boxes';
140
        $this->_page_config['create_new']['qtips'][] = 'EE_Event_Editor_Tips';
141
        $this->_page_config['edit']['qtips'][] = 'EE_Event_Editor_Tips';
142
        $this->_page_config['edit']['metaboxes'][] = '_premium_event_editor_meta_boxes';
143
        $this->_page_config['default']['list_table'] = 'Extend_Events_Admin_List_Table';
144
        // add tickets tab but only if there are more than one default ticket!
145
        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
146
            array(array('TKT_is_default' => 1)),
147
            'TKT_ID',
148
            true
149
        );
150
        if ($tkt_count > 1) {
151
            $new_page_config = array(
152
                'ticket_list_table' => array(
153
                    'nav'           => array(
154
                        'label' => esc_html__('Default Tickets', 'event_espresso'),
155
                        'order' => 60,
156
                    ),
157
                    'list_table'    => 'Tickets_List_Table',
158
                    'require_nonce' => false,
159
                ),
160
            );
161
        }
162
        // template settings
163
        $new_page_config['template_settings'] = array(
164
            'nav'           => array(
165
                'label' => esc_html__('Templates', 'event_espresso'),
166
                'order' => 30,
167
            ),
168
            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
169
            'help_tabs'     => array(
170
                'general_settings_templates_help_tab' => array(
171
                    'title'    => esc_html__('Templates', 'event_espresso'),
172
                    'filename' => 'general_settings_templates',
173
                ),
174
            ),
175
            'help_tour'     => array('Templates_Help_Tour'),
176
            'require_nonce' => false,
177
        );
178
        $this->_page_config = array_merge($this->_page_config, $new_page_config);
179
        // add filters and actions
180
        // modifying _views
181
        add_filter(
182
            'FHEE_event_datetime_metabox_add_additional_date_time_template',
183
            array($this, 'add_additional_datetime_button'),
184
            10,
185
            2
186
        );
187
        add_filter(
188
            'FHEE_event_datetime_metabox_clone_button_template',
189
            array($this, 'add_datetime_clone_button'),
190
            10,
191
            2
192
        );
193
        add_filter(
194
            'FHEE_event_datetime_metabox_timezones_template',
195
            array($this, 'datetime_timezones_template'),
196
            10,
197
            2
198
        );
199
        // filters for event list table
200
        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
201
        add_filter(
202
            'FHEE__Events_Admin_List_Table__column_actions__action_links',
203
            array($this, 'extra_list_table_actions'),
204
            10,
205
            2
206
        );
207
        // legend item
208
        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
209
        add_action('admin_init', array($this, 'admin_init'));
210
        $this->admin_config = EE_Registry::instance()->CFG->admin;
211
        add_filter(
212
            'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
213
            [$this, 'advancedEditorAdminFormSection']
214
        );
215
        add_action(
216
            'AHEE__Events_Admin_Page___update_default_event_settings',
217
            [$this, 'updateAdvancedEditorAdminFormSettings'],
218
            10,
219
            2
220
        );
221
    }
222
223
224
    /**
225
     * admin_init
226
     */
227
    public function admin_init()
228
    {
229
        EE_Registry::$i18n_js_strings = array_merge(
230
            EE_Registry::$i18n_js_strings,
231
            array(
232
                'image_confirm'          => esc_html__(
233
                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
234
                    'event_espresso'
235
                ),
236
                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
237
                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
238
                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
239
                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
240
                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
241
            )
242
        );
243
    }
244
245
246
    /**
247
     * Add per page screen options to the default ticket list table view.
248
     */
249
    protected function _add_screen_options_ticket_list_table()
250
    {
251
        $this->_per_page_screen_option();
252
    }
253
254
255
    /**
256
     * @param string $return
257
     * @param int    $id
258
     * @param string $new_title
259
     * @param string $new_slug
260
     * @return string
261
     */
262
    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
263
    {
264
        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
265
        // make sure this is only when editing
266
        if (! empty($id)) {
267
            $href = EE_Admin_Page::add_query_args_and_nonce(
268
                array('action' => 'duplicate_event', 'EVT_ID' => $id),
269
                $this->_admin_base_url
270
            );
271
            $title = esc_attr__('Duplicate Event', 'event_espresso');
272
            $return .= '<a href="'
273
                       . $href
274
                       . '" title="'
275
                       . $title
276
                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
277
                       . $title
278
                       . '</a>';
279
        }
280
        return $return;
281
    }
282
283
284
    /**
285
     * Set the list table views for the default ticket list table view.
286
     */
287 View Code Duplication
    public function _set_list_table_views_ticket_list_table()
288
    {
289
        $this->_views = array(
290
            'all'     => array(
291
                'slug'        => 'all',
292
                'label'       => esc_html__('All', 'event_espresso'),
293
                'count'       => 0,
294
                'bulk_action' => array(
295
                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
296
                ),
297
            ),
298
            'trashed' => array(
299
                'slug'        => 'trashed',
300
                'label'       => esc_html__('Trash', 'event_espresso'),
301
                'count'       => 0,
302
                'bulk_action' => array(
303
                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
304
                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
305
                ),
306
            ),
307
        );
308
    }
309
310
311
    /**
312
     * Enqueue scripts and styles for the event editor.
313
     */
314
    public function load_scripts_styles_edit()
315
    {
316
        wp_register_script(
317
            'ee-event-editor-heartbeat',
318
            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
319
            array('ee_admin_js', 'heartbeat'),
320
            EVENT_ESPRESSO_VERSION,
321
            true
322
        );
323
        wp_enqueue_script('ee-accounting');
324
        // styles
325
        wp_enqueue_style('espresso-ui-theme');
326
        wp_enqueue_script('event_editor_js');
327
        wp_enqueue_script('ee-event-editor-heartbeat');
328
        if ($this->admin_config->useAdvancedEditor()) {
329
            add_action(
330
                'admin_footer',
331
                function () {
332
                    $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
333
                    if ($eventId) {
334
                        echo '
335
        <script type="text/javascript">
336
            /* <![CDATA[ */ var eeEditorEventId = ' . $eventId . '; /* ]]> */
337
        </script>';
338
                    }
339
                }
340
            );
341
        }
342
    }
343
344
345
    /**
346
     * Returns template for the additional datetime.
347
     *
348
     * @param $template
349
     * @param $template_args
350
     * @return mixed
351
     * @throws DomainException
352
     */
353
    public function add_additional_datetime_button($template, $template_args)
354
    {
355
        return EEH_Template::display_template(
356
            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
357
            $template_args,
358
            true
359
        );
360
    }
361
362
363
    /**
364
     * Returns the template for cloning a datetime.
365
     *
366
     * @param $template
367
     * @param $template_args
368
     * @return mixed
369
     * @throws DomainException
370
     */
371
    public function add_datetime_clone_button($template, $template_args)
372
    {
373
        return EEH_Template::display_template(
374
            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
375
            $template_args,
376
            true
377
        );
378
    }
379
380
381
    /**
382
     * Returns the template for datetime timezones.
383
     *
384
     * @param $template
385
     * @param $template_args
386
     * @return mixed
387
     * @throws DomainException
388
     */
389
    public function datetime_timezones_template($template, $template_args)
390
    {
391
        return EEH_Template::display_template(
392
            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
393
            $template_args,
394
            true
395
        );
396
    }
397
398
399
    /**
400
     * Sets the views for the default list table view.
401
     */
402
    protected function _set_list_table_views_default()
403
    {
404
        parent::_set_list_table_views_default();
405
        $new_views = array(
406
            'today' => array(
407
                'slug'        => 'today',
408
                'label'       => esc_html__('Today', 'event_espresso'),
409
                'count'       => $this->total_events_today(),
410
                'bulk_action' => array(
411
                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
412
                ),
413
            ),
414
            'month' => array(
415
                'slug'        => 'month',
416
                'label'       => esc_html__('This Month', 'event_espresso'),
417
                'count'       => $this->total_events_this_month(),
418
                'bulk_action' => array(
419
                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
420
                ),
421
            ),
422
        );
423
        $this->_views = array_merge($this->_views, $new_views);
424
    }
425
426
427
    /**
428
     * Returns the extra action links for the default list table view.
429
     *
430
     * @param array     $action_links
431
     * @param \EE_Event $event
432
     * @return array
433
     * @throws EE_Error
434
     */
435
    public function extra_list_table_actions(array $action_links, \EE_Event $event)
436
    {
437
        if (EE_Registry::instance()->CAP->current_user_can(
438
            'ee_read_registrations',
439
            'espresso_registrations_reports',
440
            $event->ID()
441
        )
442
        ) {
443
            $reports_query_args = array(
444
                'action' => 'reports',
445
                'EVT_ID' => $event->ID(),
446
            );
447
            $reports_link = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
448
            $action_links[] = '<a href="'
449
                              . $reports_link
450
                              . '" title="'
451
                              . esc_attr__('View Report', 'event_espresso')
452
                              . '"><div class="dashicons dashicons-chart-bar"></div></a>'
453
                              . "\n\t";
454
        }
455
        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
456
            EE_Registry::instance()->load_helper('MSG_Template');
457
            $action_links[] = EEH_MSG_Template::get_message_action_link(
458
                'see_notifications_for',
459
                null,
460
                array('EVT_ID' => $event->ID())
461
            );
462
        }
463
        return $action_links;
464
    }
465
466
467
    /**
468
     * @param $items
469
     * @return mixed
470
     */
471
    public function additional_legend_items($items)
472
    {
473
        if (EE_Registry::instance()->CAP->current_user_can(
474
            'ee_read_registrations',
475
            'espresso_registrations_reports'
476
        )
477
        ) {
478
            $items['reports'] = array(
479
                'class' => 'dashicons dashicons-chart-bar',
480
                'desc'  => esc_html__('Event Reports', 'event_espresso'),
481
            );
482
        }
483 View Code Duplication
        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
484
            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
485
            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
486
                $items['view_related_messages'] = array(
487
                    'class' => $related_for_icon['css_class'],
488
                    'desc'  => $related_for_icon['label'],
489
                );
490
            }
491
        }
492
        return $items;
493
    }
494
495
496
    /**
497
     * This is the callback method for the duplicate event route
498
     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
499
     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
500
     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
501
     * After duplication the redirect is to the new event edit page.
502
     *
503
     * @return void
504
     * @access protected
505
     * @throws EE_Error If EE_Event is not available with given ID
506
     */
507
    protected function _duplicate_event()
508
    {
509
        // first make sure the ID for the event is in the request.
510
        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
511 View Code Duplication
        if (! isset($this->_req_data['EVT_ID'])) {
512
            EE_Error::add_error(
513
                esc_html__(
514
                    'In order to duplicate an event an Event ID is required.  None was given.',
515
                    'event_espresso'
516
                ),
517
                __FILE__,
518
                __FUNCTION__,
519
                __LINE__
520
            );
521
            $this->_redirect_after_action(false, '', '', array(), true);
522
            return;
523
        }
524
        // k we've got EVT_ID so let's use that to get the event we'll duplicate
525
        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
526
        if (! $orig_event instanceof EE_Event) {
527
            throw new EE_Error(
528
                sprintf(
529
                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
530
                    $this->_req_data['EVT_ID']
531
                )
532
            );
533
        }
534
        // k now let's clone the $orig_event before getting relations
535
        $new_event = clone $orig_event;
536
        // original datetimes
537
        $orig_datetimes = $orig_event->get_many_related('Datetime');
538
        // other original relations
539
        $orig_ven = $orig_event->get_many_related('Venue');
540
        // reset the ID and modify other details to make it clear this is a dupe
541
        $new_event->set('EVT_ID', 0);
542
        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
543
        $new_event->set('EVT_name', $new_name);
544
        $new_event->set(
545
            'EVT_slug',
546
            wp_unique_post_slug(
547
                sanitize_title($orig_event->name()),
548
                0,
549
                'publish',
550
                'espresso_events',
551
                0
552
            )
553
        );
554
        $new_event->set('status', 'draft');
555
        // duplicate discussion settings
556
        $new_event->set('comment_status', $orig_event->get('comment_status'));
557
        $new_event->set('ping_status', $orig_event->get('ping_status'));
558
        // save the new event
559
        $new_event->save();
560
        // venues
561
        foreach ($orig_ven as $ven) {
562
            $new_event->_add_relation_to($ven, 'Venue');
563
        }
564
        $new_event->save();
565
        // now we need to get the question group relations and handle that
566
        // first primary question groups
567
        $orig_primary_qgs = $orig_event->get_many_related(
568
            'Question_Group',
569
            [['Event_Question_Group.EQG_primary' => true]]
570
        );
571 View Code Duplication
        if (! empty($orig_primary_qgs)) {
572
            foreach ($orig_primary_qgs as $id => $obj) {
573
                if ($obj instanceof EE_Question_Group) {
574
                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
575
                }
576
            }
577
        }
578
        // next additional attendee question groups
579
        $orig_additional_qgs = $orig_event->get_many_related(
580
            'Question_Group',
581
            [['Event_Question_Group.EQG_additional' => true]]
582
        );
583 View Code Duplication
        if (! empty($orig_additional_qgs)) {
584
            foreach ($orig_additional_qgs as $id => $obj) {
585
                if ($obj instanceof EE_Question_Group) {
586
                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
587
                }
588
            }
589
        }
590
591
        $new_event->save();
592
593
        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
594
        $cloned_tickets = array();
595
        foreach ($orig_datetimes as $orig_dtt) {
596
            if (! $orig_dtt instanceof EE_Datetime) {
597
                continue;
598
            }
599
            $new_dtt = clone $orig_dtt;
600
            $orig_tkts = $orig_dtt->tickets();
601
            // save new dtt then add to event
602
            $new_dtt->set('DTT_ID', 0);
603
            $new_dtt->set('DTT_sold', 0);
604
            $new_dtt->set_reserved(0);
605
            $new_dtt->save();
606
            $new_event->_add_relation_to($new_dtt, 'Datetime');
607
            $new_event->save();
608
            // now let's get the ticket relations setup.
609
            foreach ((array) $orig_tkts as $orig_tkt) {
610
                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
611
                if (! $orig_tkt instanceof EE_Ticket) {
612
                    continue;
613
                }
614
                // is this ticket archived?  If it is then let's skip
615
                if ($orig_tkt->get('TKT_deleted')) {
616
                    continue;
617
                }
618
                // does this original ticket already exist in the clone_tickets cache?
619
                //  If so we'll just use the new ticket from it.
620
                if (isset($cloned_tickets[ $orig_tkt->ID() ])) {
621
                    $new_tkt = $cloned_tickets[ $orig_tkt->ID() ];
622
                } else {
623
                    $new_tkt = clone $orig_tkt;
624
                    // get relations on the $orig_tkt that we need to setup.
625
                    $orig_prices = $orig_tkt->prices();
626
                    $new_tkt->set('TKT_ID', 0);
627
                    $new_tkt->set('TKT_sold', 0);
628
                    $new_tkt->set('TKT_reserved', 0);
629
                    $new_tkt->save(); // make sure new ticket has ID.
630
                    // price relations on new ticket need to be setup.
631
                    foreach ($orig_prices as $orig_price) {
632
                        $new_price = clone $orig_price;
633
                        $new_price->set('PRC_ID', 0);
634
                        $new_price->save();
635
                        $new_tkt->_add_relation_to($new_price, 'Price');
636
                        $new_tkt->save();
637
                    }
638
639
                    do_action(
640
                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
641
                        $orig_tkt,
642
                        $new_tkt,
643
                        $orig_prices,
644
                        $orig_event,
645
                        $orig_dtt,
646
                        $new_dtt
647
                    );
648
                }
649
                // k now we can add the new ticket as a relation to the new datetime
650
                // and make sure its added to our cached $cloned_tickets array
651
                // for use with later datetimes that have the same ticket.
652
                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
653
                $new_dtt->save();
654
                $cloned_tickets[ $orig_tkt->ID() ] = $new_tkt;
655
            }
656
        }
657
        // clone taxonomy information
658
        $taxonomies_to_clone_with = apply_filters(
659
            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
660
            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
661
        );
662
        // get terms for original event (notice)
663
        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
664
        // loop through terms and add them to new event.
665
        foreach ($orig_terms as $term) {
666
            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
667
        }
668
669
        // duplicate other core WP_Post items for this event.
670
        // post thumbnail (feature image).
671
        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
672
        if ($feature_image_id) {
673
            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
674
        }
675
676
        // duplicate page_template setting
677
        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
678
        if ($page_template) {
679
            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
680
        }
681
682
        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
683
        // now let's redirect to the edit page for this duplicated event if we have a new event id.
684
        if ($new_event->ID()) {
685
            $redirect_args = array(
686
                'post'   => $new_event->ID(),
687
                'action' => 'edit',
688
            );
689
            EE_Error::add_success(
690
                esc_html__(
691
                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
692
                    'event_espresso'
693
                )
694
            );
695
        } else {
696
            $redirect_args = array(
697
                'action' => 'default',
698
            );
699
            EE_Error::add_error(
700
                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
701
                __FILE__,
702
                __FUNCTION__,
703
                __LINE__
704
            );
705
        }
706
        $this->_redirect_after_action(false, '', '', $redirect_args, true);
707
    }
708
709
710
    /**
711
     * Generates output for the import page.
712
     *
713
     * @throws DomainException
714
     */
715
    protected function _import_page()
716
    {
717
        $title = esc_html__('Import', 'event_espresso');
718
        $intro = esc_html__(
719
            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
720
            'event_espresso'
721
        );
722
        $form_url = EVENTS_ADMIN_URL;
723
        $action = 'import_events';
724
        $type = 'csv';
725
        $this->_template_args['form'] = EE_Import::instance()->upload_form(
726
            $title,
727
            $intro,
728
            $form_url,
729
            $action,
730
            $type
731
        );
732
        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
733
            array('action' => 'sample_export_file'),
734
            $this->_admin_base_url
735
        );
736
        $content = EEH_Template::display_template(
737
            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
738
            $this->_template_args,
739
            true
740
        );
741
        $this->_template_args['admin_page_content'] = $content;
742
        $this->display_admin_page_with_sidebar();
743
    }
744
745
746
    /**
747
     * _import_events
748
     * This handles displaying the screen and running imports for importing events.
749
     *
750
     * @return void
751
     */
752
    protected function _import_events()
753
    {
754
        require_once(EE_CLASSES . 'EE_Import.class.php');
755
        $success = EE_Import::instance()->import();
756
        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
757
    }
758
759
760
    /**
761
     * _events_export
762
     * Will export all (or just the given event) to a Excel compatible file.
763
     *
764
     * @access protected
765
     * @return void
766
     */
767
    protected function _events_export()
768
    {
769
        if (isset($this->_req_data['EVT_ID'])) {
770
            $event_ids = $this->_req_data['EVT_ID'];
771
        } elseif (isset($this->_req_data['EVT_IDs'])) {
772
            $event_ids = $this->_req_data['EVT_IDs'];
773
        } else {
774
            $event_ids = null;
775
        }
776
        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
777
        $new_request_args = array(
778
            'export' => 'report',
779
            'action' => 'all_event_data',
780
            'EVT_ID' => $event_ids,
781
        );
782
        $this->_req_data = array_merge($this->_req_data, $new_request_args);
783
        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
784
            require_once(EE_CLASSES . 'EE_Export.class.php');
785
            $EE_Export = EE_Export::instance($this->_req_data);
786
            $EE_Export->export();
787
        }
788
    }
789
790
791
    /**
792
     * handle category exports()
793
     *
794
     * @return void
795
     */
796 View Code Duplication
    protected function _categories_export()
797
    {
798
        // todo: I don't like doing this but it'll do until we modify EE_Export Class.
799
        $new_request_args = array(
800
            'export'       => 'report',
801
            'action'       => 'categories',
802
            'category_ids' => $this->_req_data['EVT_CAT_ID'],
803
        );
804
        $this->_req_data = array_merge($this->_req_data, $new_request_args);
805
        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
806
            require_once(EE_CLASSES . 'EE_Export.class.php');
807
            $EE_Export = EE_Export::instance($this->_req_data);
808
            $EE_Export->export();
809
        }
810
    }
811
812
813
    /**
814
     * Creates a sample CSV file for importing
815
     */
816
    protected function _sample_export_file()
817
    {
818
        // require_once(EE_CLASSES . 'EE_Export.class.php');
819
        EE_Export::instance()->export_sample();
820
    }
821
822
823
    /*************        Template Settings        *************/
824
    /**
825
     * Generates template settings page output
826
     *
827
     * @throws DomainException
828
     * @throws EE_Error
829
     */
830
    protected function _template_settings()
831
    {
832
        $this->_template_args['values'] = $this->_yes_no_values;
833
        /**
834
         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
835
         * from General_Settings_Admin_Page to here.
836
         */
837
        $this->_template_args = apply_filters(
838
            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
839
            $this->_template_args
840
        );
841
        $this->_set_add_edit_form_tags('update_template_settings');
842
        $this->_set_publish_post_box_vars(null, false, false, null, false);
843
        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
844
            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
845
            $this->_template_args,
846
            true
847
        );
848
        $this->display_admin_page_with_sidebar();
849
    }
850
851
852
    /**
853
     * Handler for updating template settings.
854
     *
855
     * @throws InvalidInterfaceException
856
     * @throws InvalidDataTypeException
857
     * @throws InvalidArgumentException
858
     */
859
    protected function _update_template_settings()
860
    {
861
        /**
862
         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
863
         * from General_Settings_Admin_Page to here.
864
         */
865
        EE_Registry::instance()->CFG->template_settings = apply_filters(
866
            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
867
            EE_Registry::instance()->CFG->template_settings,
868
            $this->_req_data
869
        );
870
        // update custom post type slugs and detect if we need to flush rewrite rules
871
        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
872
        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
873
            ? EE_Registry::instance()->CFG->core->event_cpt_slug
874
            : EEH_URL::slugify($this->_req_data['event_cpt_slug'], 'events');
875
        $what = 'Template Settings';
876
        $success = $this->_update_espresso_configuration(
877
            $what,
878
            EE_Registry::instance()->CFG->template_settings,
879
            __FILE__,
880
            __FUNCTION__,
881
            __LINE__
882
        );
883
        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
884
            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
885
            $rewrite_rules = LoaderFactory::getLoader()->getShared(
886
                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
887
            );
888
            $rewrite_rules->flush();
889
        }
890
        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
891
    }
892
893
894
    /**
895
     * _premium_event_editor_meta_boxes
896
     * add all metaboxes related to the event_editor
897
     *
898
     * @access protected
899
     * @return void
900
     * @throws EE_Error
901
     */
902 View Code Duplication
    protected function _premium_event_editor_meta_boxes()
903
    {
904
        $this->verify_cpt_object();
905
        add_meta_box(
906
            'espresso_event_editor_event_options',
907
            esc_html__('Event Registration Options', 'event_espresso'),
908
            array($this, 'registration_options_meta_box'),
909
            $this->page_slug,
910
            'side',
911
            'core'
912
        );
913
    }
914
915
916
    /**
917
     * override caf metabox
918
     *
919
     * @return void
920
     * @throws DomainException
921
     */
922
    public function registration_options_meta_box()
923
    {
924
        $yes_no_values = array(
925
            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
926
            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
927
        );
928
        $default_reg_status_values = EEM_Registration::reg_status_array(
929
            array(
930
                EEM_Registration::status_id_cancelled,
931
                EEM_Registration::status_id_declined,
932
                EEM_Registration::status_id_incomplete,
933
                EEM_Registration::status_id_wait_list,
934
            ),
935
            true
936
        );
937
        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$template_args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $template_args = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
938
        $template_args['_event'] = $this->_cpt_model_obj;
939
        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
940
        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
941
            'default_reg_status',
942
            $default_reg_status_values,
943
            $this->_cpt_model_obj->default_registration_status()
0 ignored issues
show
Bug introduced by
It seems like $this->_cpt_model_obj->d...t_registration_status() targeting EE_Event::default_registration_status() can also be of type boolean; however, EEH_Form_Fields::select_input() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
944
        );
945
        $template_args['display_description'] = EEH_Form_Fields::select_input(
946
            'display_desc',
947
            $yes_no_values,
948
            $this->_cpt_model_obj->display_description()
949
        );
950
        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
951
            'display_ticket_selector',
952
            $yes_no_values,
953
            $this->_cpt_model_obj->display_ticket_selector(),
954
            '',
955
            '',
956
            false
957
        );
958
        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
959
            'EVT_default_registration_status',
960
            $default_reg_status_values,
961
            $this->_cpt_model_obj->default_registration_status()
0 ignored issues
show
Bug introduced by
It seems like $this->_cpt_model_obj->d...t_registration_status() targeting EE_Event::default_registration_status() can also be of type boolean; however, EEH_Form_Fields::select_input() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
962
        );
963
        $template_args['additional_registration_options'] = apply_filters(
964
            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
965
            '',
966
            $template_args,
967
            $yes_no_values,
968
            $default_reg_status_values
969
        );
970
        EEH_Template::display_template(
971
            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
972
            $template_args
973
        );
974
    }
975
976
977
978
    /**
979
     * wp_list_table_mods for caf
980
     * ============================
981
     */
982
    /**
983
     * hook into list table filters and provide filters for caffeinated list table
984
     *
985
     * @param  array $old_filters    any existing filters present
986
     * @param  array $list_table_obj the list table object
987
     * @return array                  new filters
988
     */
989
    public function list_table_filters($old_filters, $list_table_obj)
990
    {
991
        $filters = array();
992
        // first month/year filters
993
        $filters[] = $this->espresso_event_months_dropdown();
994
        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
995
        // active status dropdown
996
        if ($status !== 'draft') {
997
            $filters[] = $this->active_status_dropdown(
998
                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
999
            );
1000
            $filters[] = $this->venuesDropdown(
1001
                isset($this->_req_data['venue']) ? $this->_req_data['venue'] : ''
1002
            );
1003
        }
1004
        // category filter
1005
        $filters[] = $this->category_dropdown();
1006
        return array_merge($old_filters, $filters);
1007
    }
1008
1009
1010
    /**
1011
     * espresso_event_months_dropdown
1012
     *
1013
     * @access public
1014
     * @return string                dropdown listing month/year selections for events.
1015
     */
1016
    public function espresso_event_months_dropdown()
1017
    {
1018
        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1019
        // Note we need to include any other filters that are set!
1020
        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1021
        // categories?
1022
        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1023
            ? $this->_req_data['EVT_CAT']
1024
            : null;
1025
        // active status?
1026
        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
1027
        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
1028
        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
1029
    }
1030
1031
1032
    /**
1033
     * returns a list of "active" statuses on the event
1034
     *
1035
     * @param  string $current_value whatever the current active status is
1036
     * @return string
1037
     */
1038
    public function active_status_dropdown($current_value = '')
1039
    {
1040
        $select_name = 'active_status';
1041
        $values = array(
1042
            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1043
            'active'   => esc_html__('Active', 'event_espresso'),
1044
            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1045
            'expired'  => esc_html__('Expired', 'event_espresso'),
1046
            'inactive' => esc_html__('Inactive', 'event_espresso'),
1047
        );
1048
1049
        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1050
    }
1051
1052
    /**
1053
     * returns a list of "venues"
1054
     *
1055
     * @param  string $current_value whatever the current active status is
1056
     * @return string
1057
     */
1058
    protected function venuesDropdown($current_value = '')
1059
    {
1060
        $select_name = 'venue';
1061
        $values = array(
1062
            '' => esc_html__('All Venues', 'event_espresso'),
1063
        );
1064
        // populate the list of venues.
1065
        $venue_model = EE_Registry::instance()->load_model('Venue');
1066
        $venues = $venue_model->get_all(array('order_by' => array('VNU_name' => 'ASC')));
1067
1068
        foreach ($venues as $venue) {
1069
            $values[ $venue->ID() ] = $venue->name();
1070
        }
1071
1072
        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1073
    }
1074
1075
1076
    /**
1077
     * output a dropdown of the categories for the category filter on the event admin list table
1078
     *
1079
     * @access  public
1080
     * @return string html
1081
     */
1082
    public function category_dropdown()
1083
    {
1084
        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1085
        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1086
    }
1087
1088
1089
    /**
1090
     * get total number of events today
1091
     *
1092
     * @access public
1093
     * @return int
1094
     * @throws EE_Error
1095
     */
1096
    public function total_events_today()
1097
    {
1098
        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1099
            'DTT_EVT_start',
1100
            date('Y-m-d') . ' 00:00:00',
1101
            'Y-m-d H:i:s',
1102
            'UTC'
1103
        );
1104
        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1105
            'DTT_EVT_start',
1106
            date('Y-m-d') . ' 23:59:59',
1107
            'Y-m-d H:i:s',
1108
            'UTC'
1109
        );
1110
        $where = array(
1111
            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1112
        );
1113
        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1114
        return $count;
1115
    }
1116
1117
1118
    /**
1119
     * get total number of events this month
1120
     *
1121
     * @access public
1122
     * @return int
1123
     * @throws EE_Error
1124
     */
1125
    public function total_events_this_month()
1126
    {
1127
        // Dates
1128
        $this_year_r = date('Y');
1129
        $this_month_r = date('m');
1130
        $days_this_month = date('t');
1131
        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1132
            'DTT_EVT_start',
1133
            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1134
            'Y-m-d H:i:s',
1135
            'UTC'
1136
        );
1137
        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1138
            'DTT_EVT_start',
1139
            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1140
            'Y-m-d H:i:s',
1141
            'UTC'
1142
        );
1143
        $where = array(
1144
            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1145
        );
1146
        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1147
        return $count;
1148
    }
1149
1150
1151
    /** DEFAULT TICKETS STUFF **/
1152
1153
    /**
1154
     * Output default tickets list table view.
1155
     */
1156
    public function _tickets_overview_list_table()
1157
    {
1158
        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1159
        $this->display_admin_list_table_page_with_no_sidebar();
1160
    }
1161
1162
1163
    /**
1164
     * @param int  $per_page
1165
     * @param bool $count
1166
     * @param bool $trashed
1167
     * @return \EE_Soft_Delete_Base_Class[]|int
1168
     */
1169 View Code Duplication
    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1170
    {
1171
        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1172
        $order = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1173
        switch ($orderby) {
1174
            case 'TKT_name':
1175
                $orderby = array('TKT_name' => $order);
1176
                break;
1177
            case 'TKT_price':
1178
                $orderby = array('TKT_price' => $order);
1179
                break;
1180
            case 'TKT_uses':
1181
                $orderby = array('TKT_uses' => $order);
1182
                break;
1183
            case 'TKT_min':
1184
                $orderby = array('TKT_min' => $order);
1185
                break;
1186
            case 'TKT_max':
1187
                $orderby = array('TKT_max' => $order);
1188
                break;
1189
            case 'TKT_qty':
1190
                $orderby = array('TKT_qty' => $order);
1191
                break;
1192
        }
1193
        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1194
            ? $this->_req_data['paged']
1195
            : 1;
1196
        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1197
            ? $this->_req_data['perpage']
1198
            : $per_page;
1199
        $_where = array(
1200
            'TKT_is_default' => 1,
1201
            'TKT_deleted'    => $trashed,
1202
        );
1203
        $offset = ($current_page - 1) * $per_page;
1204
        $limit = array($offset, $per_page);
1205
        if (isset($this->_req_data['s'])) {
1206
            $sstr = '%' . $this->_req_data['s'] . '%';
1207
            $_where['OR'] = array(
1208
                'TKT_name'        => array('LIKE', $sstr),
1209
                'TKT_description' => array('LIKE', $sstr),
1210
            );
1211
        }
1212
        $query_params = array(
1213
            $_where,
1214
            'order_by' => $orderby,
1215
            'limit'    => $limit,
1216
            'group_by' => 'TKT_ID',
1217
        );
1218
        if ($count) {
1219
            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1220
        } else {
1221
            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1222
        }
1223
    }
1224
1225
1226
    /**
1227
     * @param bool $trash
1228
     * @throws EE_Error
1229
     */
1230
    protected function _trash_or_restore_ticket($trash = false)
1231
    {
1232
        $success = 1;
1233
        $TKT = EEM_Ticket::instance();
1234
        // checkboxes?
1235 View Code Duplication
        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1236
            // if array has more than one element then success message should be plural
1237
            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1238
            // cycle thru the boxes
1239
            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $value is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1240
                if ($trash) {
1241
                    if (! $TKT->delete_by_ID($TKT_ID)) {
1242
                        $success = 0;
1243
                    }
1244
                } else {
1245
                    if (! $TKT->restore_by_ID($TKT_ID)) {
1246
                        $success = 0;
1247
                    }
1248
                }
1249
            }
1250
        } else {
1251
            // grab single id and trash
1252
            $TKT_ID = absint($this->_req_data['TKT_ID']);
1253
            if ($trash) {
1254
                if (! $TKT->delete_by_ID($TKT_ID)) {
1255
                    $success = 0;
1256
                }
1257
            } else {
1258
                if (! $TKT->restore_by_ID($TKT_ID)) {
1259
                    $success = 0;
1260
                }
1261
            }
1262
        }
1263
        $action_desc = $trash ? 'moved to the trash' : 'restored';
1264
        $query_args = array(
1265
            'action' => 'ticket_list_table',
1266
            'status' => $trash ? '' : 'trashed',
1267
        );
1268
        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1269
    }
1270
1271
1272
    /**
1273
     * Handles trashing default ticket.
1274
     */
1275
    protected function _delete_ticket()
1276
    {
1277
        $success = 1;
1278
        // checkboxes?
1279 View Code Duplication
        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1280
            // if array has more than one element then success message should be plural
1281
            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1282
            // cycle thru the boxes
1283
            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $value is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1284
                // delete
1285
                if (! $this->_delete_the_ticket($TKT_ID)) {
1286
                    $success = 0;
1287
                }
1288
            }
1289
        } else {
1290
            // grab single id and trash
1291
            $TKT_ID = absint($this->_req_data['TKT_ID']);
1292
            if (! $this->_delete_the_ticket($TKT_ID)) {
1293
                $success = 0;
1294
            }
1295
        }
1296
        $action_desc = 'deleted';
1297
        $query_args = array(
1298
            'action' => 'ticket_list_table',
1299
            'status' => 'trashed',
1300
        );
1301
        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1302
        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1303
            array(array('TKT_is_default' => 1)),
1304
            'TKT_ID',
1305
            true
1306
        )
1307
        ) {
1308
            $query_args = array();
1309
        }
1310
        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1311
    }
1312
1313
1314
    /**
1315
     * @param int $TKT_ID
1316
     * @return bool|int
1317
     * @throws EE_Error
1318
     */
1319
    protected function _delete_the_ticket($TKT_ID)
1320
    {
1321
        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1322
        $tkt->_remove_relations('Datetime');
1323
        // delete all related prices first
1324
        $tkt->delete_related_permanently('Price');
1325
        return $tkt->delete_permanently();
1326
    }
1327
1328
1329
    /**
1330
     * @param array $default_event_settings_form_subsections
1331
     * @return array
1332
     * @since $VID:$
1333
     */
1334
    public function advancedEditorAdminFormSection(array $default_event_settings_form_subsections)
1335
    {
1336
        return [
1337
            'use_advanced_editor'         => new EE_Select_Input(
1338
                apply_filters(
1339
                    'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_answer_options',
1340
                    [
1341
                        esc_html__('Legacy Editor', 'event_espresso'),
1342
                        esc_html__('Advanced Editor', 'event_espresso'),
1343
                    ]
1344
                ),
1345
                apply_filters(
1346
                    'FHEE__Events_Admin_Page___default_event_settings_form__advanced_editor_input_settings',
1347
                    [
1348
                        'default'         => $this->admin_config->useAdvancedEditor(),
1349
                        'html_label_text' => esc_html__('Activate Advanced Editor?', 'event_espresso'),
1350
                        'html_help_text'  => sprintf(
1351
                            esc_html__(
1352
                                'Controls whether the Event Espresso Event Editor continues to use the existing legacy editor that functions like the typical older WordPress admin you are used to,%1$sor uses the new Advanced Editor with a more powerful and easier to use interface. This may be automatically turned on in order to utilize advanced features from new addons.',
1353
                                'event_espresso'
1354
                            ),
1355
                            '<br />'
1356
                        ),
1357
                    ]
1358
                )
1359
            ),
1360
            'defaults_section_header' => new EE_Form_Section_HTML(
1361
                EEH_HTML::h2(
1362
                    esc_html__('Default Settings', 'event_espresso'),
1363
                    '',
1364
                    'ee-admin-settings-hdr'
1365
                )
1366
            ),
1367
        ] + $default_event_settings_form_subsections;
1368
    }
1369
1370
1371
    /**
1372
     * @param array     $valid_data
1373
     * @param EE_Config $config
1374
     * @since $VID:$
1375
     */
1376
    public function updateAdvancedEditorAdminFormSettings(array $valid_data, EE_Config $config)
1377
    {
1378
        $config->admin->setUseAdvancedEditor(
1379
            isset($valid_data['use_advanced_editor'])
1380
                ? $valid_data['use_advanced_editor']
1381
                : false
1382
        );
1383
    }
1384
}
1385