Completed
Branch CASC/initial-ui (c5e0e6)
by
unknown
32:13 queued 24:29
created

Events_Admin_Page::confirmDeletion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Events_Admin_Page
5
 * This contains the logic for setting up the Events related pages.
6
 * Any methods without phpdoc comments have inline docs with parent class.
7
 *
8
 * @package         Events_Admin_Page
9
 * @subpackage      includes/core/admin/Events_Admin_Page.core.php
10
 * @author          Darren Ethier
11
 */
12
class Events_Admin_Page extends EE_Admin_Page_CPT
13
{
14
15
    /**
16
     * This will hold the event object for event_details screen.
17
     *
18
     * @access protected
19
     * @var EE_Event $_event
20
     */
21
    protected $_event;
22
23
24
    /**
25
     * This will hold the category object for category_details screen.
26
     *
27
     * @var stdClass $_category
28
     */
29
    protected $_category;
30
31
32
    /**
33
     * This will hold the event model instance
34
     *
35
     * @var EEM_Event $_event_model
36
     */
37
    protected $_event_model;
38
39
40
    /**
41
     * @var EE_Event
42
     */
43
    protected $_cpt_model_obj = false;
44
45
46
    /**
47
     * Initialize page props for this admin page group.
48
     */
49
    protected function _init_page_props()
50
    {
51
        $this->page_slug = EVENTS_PG_SLUG;
52
        $this->page_label = EVENTS_LABEL;
53
        $this->_admin_base_url = EVENTS_ADMIN_URL;
54
        $this->_admin_base_path = EVENTS_ADMIN;
55
        $this->_cpt_model_names = array(
56
            'create_new' => 'EEM_Event',
57
            'edit'       => 'EEM_Event',
58
        );
59
        $this->_cpt_edit_routes = array(
60
            'espresso_events' => 'edit',
61
        );
62
        add_action(
63
            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
64
            array($this, 'verify_event_edit'),
65
            10,
66
            2
67
        );
68
    }
69
70
71
    /**
72
     * Sets the ajax hooks used for this admin page group.
73
     */
74
    protected function _ajax_hooks()
75
    {
76
        add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting'));
77
    }
78
79
80
    /**
81
     * Sets the page properties for this admin page group.
82
     */
83 View Code Duplication
    protected function _define_page_props()
84
    {
85
        $this->_admin_page_title = EVENTS_LABEL;
86
        $this->_labels = array(
87
            'buttons'      => array(
88
                'add'             => esc_html__('Add New Event', 'event_espresso'),
89
                'edit'            => esc_html__('Edit Event', 'event_espresso'),
90
                'delete'          => esc_html__('Delete Event', 'event_espresso'),
91
                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
92
                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
93
                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
94
            ),
95
            'editor_title' => array(
96
                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
97
            ),
98
            'publishbox'   => array(
99
                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
100
                'edit'              => esc_html__('Update Event', 'event_espresso'),
101
                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
102
                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
103
                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
104
            ),
105
        );
106
    }
107
108
109
    /**
110
     * Sets the page routes property for this admin page group.
111
     */
112
    protected function _set_page_routes()
113
    {
114
        // load formatter helper
115
        // load field generator helper
116
        // is there a evt_id in the request?
117
        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
118
            ? $this->_req_data['EVT_ID']
119
            : 0;
120
        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
121
        $this->_page_routes = array(
122
            'default'                       => array(
123
                'func'       => '_events_overview_list_table',
124
                'capability' => 'ee_read_events',
125
            ),
126
            'create_new'                    => array(
127
                'func'       => '_create_new_cpt_item',
128
                'capability' => 'ee_edit_events',
129
            ),
130
            'edit'                          => array(
131
                'func'       => '_edit_cpt_item',
132
                'capability' => 'ee_edit_event',
133
                'obj_id'     => $evt_id,
134
            ),
135
            'copy_event'                    => array(
136
                'func'       => '_copy_events',
137
                'capability' => 'ee_edit_event',
138
                'obj_id'     => $evt_id,
139
                'noheader'   => true,
140
            ),
141
            'trash_event'                   => array(
142
                'func'       => '_trash_or_restore_event',
143
                'args'       => array('event_status' => 'trash'),
144
                'capability' => 'ee_delete_event',
145
                'obj_id'     => $evt_id,
146
                'noheader'   => true,
147
            ),
148
            'trash_events'                  => array(
149
                'func'       => '_trash_or_restore_events',
150
                'args'       => array('event_status' => 'trash'),
151
                'capability' => 'ee_delete_events',
152
                'noheader'   => true,
153
            ),
154
            'restore_event'                 => array(
155
                'func'       => '_trash_or_restore_event',
156
                'args'       => array('event_status' => 'draft'),
157
                'capability' => 'ee_delete_event',
158
                'obj_id'     => $evt_id,
159
                'noheader'   => true,
160
            ),
161
            'restore_events'                => array(
162
                'func'       => '_trash_or_restore_events',
163
                'args'       => array('event_status' => 'draft'),
164
                'capability' => 'ee_delete_events',
165
                'noheader'   => true,
166
            ),
167
            'delete_event'                  => array(
168
                'func'       => '_delete_event',
169
                'capability' => 'ee_delete_event',
170
                'obj_id'     => $evt_id,
171
                'noheader'   => true,
172
            ),
173
            'delete_events'                 => array(
174
                'func'       => '_delete_events',
175
                'capability' => 'ee_delete_events',
176
                'noheader'   => true,
177
            ),
178
            'view_report'                   => array(
179
                'func'      => '_view_report',
180
                'capablity' => 'ee_edit_events',
181
            ),
182
            'default_event_settings'        => array(
183
                'func'       => '_default_event_settings',
184
                'capability' => 'manage_options',
185
            ),
186
            'update_default_event_settings' => array(
187
                'func'       => '_update_default_event_settings',
188
                'capability' => 'manage_options',
189
                'noheader'   => true,
190
            ),
191
            'template_settings'             => array(
192
                'func'       => '_template_settings',
193
                'capability' => 'manage_options',
194
            ),
195
            // event category tab related
196
            'add_category'                  => array(
197
                'func'       => '_category_details',
198
                'capability' => 'ee_edit_event_category',
199
                'args'       => array('add'),
200
            ),
201
            'edit_category'                 => array(
202
                'func'       => '_category_details',
203
                'capability' => 'ee_edit_event_category',
204
                'args'       => array('edit'),
205
            ),
206
            'delete_categories'             => array(
207
                'func'       => '_delete_categories',
208
                'capability' => 'ee_delete_event_category',
209
                'noheader'   => true,
210
            ),
211
            'delete_category'               => array(
212
                'func'       => '_delete_categories',
213
                'capability' => 'ee_delete_event_category',
214
                'noheader'   => true,
215
            ),
216
            'insert_category'               => array(
217
                'func'       => '_insert_or_update_category',
218
                'args'       => array('new_category' => true),
219
                'capability' => 'ee_edit_event_category',
220
                'noheader'   => true,
221
            ),
222
            'update_category'               => array(
223
                'func'       => '_insert_or_update_category',
224
                'args'       => array('new_category' => false),
225
                'capability' => 'ee_edit_event_category',
226
                'noheader'   => true,
227
            ),
228
            'category_list'                 => array(
229
                'func'       => '_category_list_table',
230
                'capability' => 'ee_manage_event_categories',
231
            ),
232
            'preview_deletion' => [
233
                'func' => 'previewDeletion',
234
                'capability' => 'ee_delete_events'
235
            ],
236
            'confirm_deletion' => [
237
                'func' => 'confirmDeletion',
238
                'capability' => 'ee_delete_events',
239
                'noheader' => true
240
            ]
241
        );
242
    }
243
244
245
    /**
246
     * Set the _page_config property for this admin page group.
247
     */
248
    protected function _set_page_config()
249
    {
250
        $this->_page_config = array(
251
            'default'                => array(
252
                'nav'           => array(
253
                    'label' => esc_html__('Overview', 'event_espresso'),
254
                    'order' => 10,
255
                ),
256
                'list_table'    => 'Events_Admin_List_Table',
257
                'help_tabs'     => array(
258
                    'events_overview_help_tab'                       => array(
259
                        'title'    => esc_html__('Events Overview', 'event_espresso'),
260
                        'filename' => 'events_overview',
261
                    ),
262
                    'events_overview_table_column_headings_help_tab' => array(
263
                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
264
                        'filename' => 'events_overview_table_column_headings',
265
                    ),
266
                    'events_overview_filters_help_tab'               => array(
267
                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
268
                        'filename' => 'events_overview_filters',
269
                    ),
270
                    'events_overview_view_help_tab'                  => array(
271
                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
272
                        'filename' => 'events_overview_views',
273
                    ),
274
                    'events_overview_other_help_tab'                 => array(
275
                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
276
                        'filename' => 'events_overview_other',
277
                    ),
278
                ),
279
                'help_tour'     => array(
280
                    'Event_Overview_Help_Tour',
281
                    // 'New_Features_Test_Help_Tour' for testing multiple help tour
282
                ),
283
                'qtips'         => array(
284
                    'EE_Event_List_Table_Tips',
285
                ),
286
                'require_nonce' => false,
287
            ),
288
            'create_new'             => array(
289
                'nav'           => array(
290
                    'label'      => esc_html__('Add Event', 'event_espresso'),
291
                    'order'      => 5,
292
                    'persistent' => false,
293
                ),
294
                'metaboxes'     => array('_register_event_editor_meta_boxes'),
295
                'help_tabs'     => array(
296
                    'event_editor_help_tab'                            => array(
297
                        'title'    => esc_html__('Event Editor', 'event_espresso'),
298
                        'filename' => 'event_editor',
299
                    ),
300
                    'event_editor_title_richtexteditor_help_tab'       => array(
301
                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
302
                        'filename' => 'event_editor_title_richtexteditor',
303
                    ),
304
                    'event_editor_venue_details_help_tab'              => array(
305
                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
306
                        'filename' => 'event_editor_venue_details',
307
                    ),
308
                    'event_editor_event_datetimes_help_tab'            => array(
309
                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
310
                        'filename' => 'event_editor_event_datetimes',
311
                    ),
312
                    'event_editor_event_tickets_help_tab'              => array(
313
                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
314
                        'filename' => 'event_editor_event_tickets',
315
                    ),
316
                    'event_editor_event_registration_options_help_tab' => array(
317
                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
318
                        'filename' => 'event_editor_event_registration_options',
319
                    ),
320
                    'event_editor_tags_categories_help_tab'            => array(
321
                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
322
                        'filename' => 'event_editor_tags_categories',
323
                    ),
324
                    'event_editor_questions_registrants_help_tab'      => array(
325
                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
326
                        'filename' => 'event_editor_questions_registrants',
327
                    ),
328
                    'event_editor_save_new_event_help_tab'             => array(
329
                        'title'    => esc_html__('Save New Event', 'event_espresso'),
330
                        'filename' => 'event_editor_save_new_event',
331
                    ),
332
                    'event_editor_other_help_tab'                      => array(
333
                        'title'    => esc_html__('Event Other', 'event_espresso'),
334
                        'filename' => 'event_editor_other',
335
                    ),
336
                ),
337
                'help_tour'     => array(
338
                    'Event_Editor_Help_Tour',
339
                ),
340
                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
341
                'require_nonce' => false,
342
            ),
343
            'edit'                   => array(
344
                'nav'           => array(
345
                    'label'      => esc_html__('Edit Event', 'event_espresso'),
346
                    'order'      => 5,
347
                    'persistent' => false,
348
                    'url'        => isset($this->_req_data['post'])
349
                        ? EE_Admin_Page::add_query_args_and_nonce(
350
                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
351
                            $this->_current_page_view_url
352
                        )
353
                        : $this->_admin_base_url,
354
                ),
355
                'metaboxes'     => array('_register_event_editor_meta_boxes'),
356
                'help_tabs'     => array(
357
                    'event_editor_help_tab'                            => array(
358
                        'title'    => esc_html__('Event Editor', 'event_espresso'),
359
                        'filename' => 'event_editor',
360
                    ),
361
                    'event_editor_title_richtexteditor_help_tab'       => array(
362
                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
363
                        'filename' => 'event_editor_title_richtexteditor',
364
                    ),
365
                    'event_editor_venue_details_help_tab'              => array(
366
                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
367
                        'filename' => 'event_editor_venue_details',
368
                    ),
369
                    'event_editor_event_datetimes_help_tab'            => array(
370
                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
371
                        'filename' => 'event_editor_event_datetimes',
372
                    ),
373
                    'event_editor_event_tickets_help_tab'              => array(
374
                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
375
                        'filename' => 'event_editor_event_tickets',
376
                    ),
377
                    'event_editor_event_registration_options_help_tab' => array(
378
                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
379
                        'filename' => 'event_editor_event_registration_options',
380
                    ),
381
                    'event_editor_tags_categories_help_tab'            => array(
382
                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
383
                        'filename' => 'event_editor_tags_categories',
384
                    ),
385
                    'event_editor_questions_registrants_help_tab'      => array(
386
                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
387
                        'filename' => 'event_editor_questions_registrants',
388
                    ),
389
                    'event_editor_save_new_event_help_tab'             => array(
390
                        'title'    => esc_html__('Save New Event', 'event_espresso'),
391
                        'filename' => 'event_editor_save_new_event',
392
                    ),
393
                    'event_editor_other_help_tab'                      => array(
394
                        'title'    => esc_html__('Event Other', 'event_espresso'),
395
                        'filename' => 'event_editor_other',
396
                    ),
397
                ),
398
                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
399
                'require_nonce' => false,
400
            ),
401
            'default_event_settings' => array(
402
                'nav'           => array(
403
                    'label' => esc_html__('Default Settings', 'event_espresso'),
404
                    'order' => 40,
405
                ),
406
                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
407
                'labels'        => array(
408
                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
409
                ),
410
                'help_tabs'     => array(
411
                    'default_settings_help_tab'        => array(
412
                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
413
                        'filename' => 'events_default_settings',
414
                    ),
415
                    'default_settings_status_help_tab' => array(
416
                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
417
                        'filename' => 'events_default_settings_status',
418
                    ),
419
                    'default_maximum_tickets_help_tab' => array(
420
                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
421
                        'filename' => 'events_default_settings_max_tickets',
422
                    ),
423
                ),
424
                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
425
                'require_nonce' => false,
426
            ),
427
            // template settings
428
            'template_settings'      => array(
429
                'nav'           => array(
430
                    'label' => esc_html__('Templates', 'event_espresso'),
431
                    'order' => 30,
432
                ),
433
                'metaboxes'     => $this->_default_espresso_metaboxes,
434
                'help_tabs'     => array(
435
                    'general_settings_templates_help_tab' => array(
436
                        'title'    => esc_html__('Templates', 'event_espresso'),
437
                        'filename' => 'general_settings_templates',
438
                    ),
439
                ),
440
                'help_tour'     => array('Templates_Help_Tour'),
441
                'require_nonce' => false,
442
            ),
443
            // event category stuff
444
            'add_category'           => array(
445
                'nav'           => array(
446
                    'label'      => esc_html__('Add Category', 'event_espresso'),
447
                    'order'      => 15,
448
                    'persistent' => false,
449
                ),
450
                'help_tabs'     => array(
451
                    'add_category_help_tab' => array(
452
                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
453
                        'filename' => 'events_add_category',
454
                    ),
455
                ),
456
                'help_tour'     => array('Event_Add_Category_Help_Tour'),
457
                'metaboxes'     => array('_publish_post_box'),
458
                'require_nonce' => false,
459
            ),
460
            'edit_category'          => array(
461
                'nav'           => array(
462
                    'label'      => esc_html__('Edit Category', 'event_espresso'),
463
                    'order'      => 15,
464
                    'persistent' => false,
465
                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
466
                        ? add_query_arg(
467
                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
468
                            $this->_current_page_view_url
469
                        )
470
                        : $this->_admin_base_url,
471
                ),
472
                'help_tabs'     => array(
473
                    'edit_category_help_tab' => array(
474
                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
475
                        'filename' => 'events_edit_category',
476
                    ),
477
                ),
478
                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
479
                'metaboxes'     => array('_publish_post_box'),
480
                'require_nonce' => false,
481
            ),
482
            'category_list'          => array(
483
                'nav'           => array(
484
                    'label' => esc_html__('Categories', 'event_espresso'),
485
                    'order' => 20,
486
                ),
487
                'list_table'    => 'Event_Categories_Admin_List_Table',
488
                'help_tabs'     => array(
489
                    'events_categories_help_tab'                       => array(
490
                        'title'    => esc_html__('Event Categories', 'event_espresso'),
491
                        'filename' => 'events_categories',
492
                    ),
493
                    'events_categories_table_column_headings_help_tab' => array(
494
                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
495
                        'filename' => 'events_categories_table_column_headings',
496
                    ),
497
                    'events_categories_view_help_tab'                  => array(
498
                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
499
                        'filename' => 'events_categories_views',
500
                    ),
501
                    'events_categories_other_help_tab'                 => array(
502
                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
503
                        'filename' => 'events_categories_other',
504
                    ),
505
                ),
506
                'help_tour'     => array(
507
                    'Event_Categories_Help_Tour',
508
                ),
509
                'metaboxes'     => $this->_default_espresso_metaboxes,
510
                'require_nonce' => false,
511
            ),
512
            'preview_deletion'           => array(
513
                'nav'           => array(
514
                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
515
                    'order'      => 15,
516
                    'persistent' => false,
517
                ),
518
//                'help_tabs'     => array(
519
//                    'add_category_help_tab' => array(
520
//                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
521
//                        'filename' => 'events_add_category',
522
//                    ),
523
//                ),
524
//                'help_tour'     => array('Event_Add_Category_Help_Tour'),
525
//                'metaboxes'     => array('_publish_post_box'),
526
//                'require_nonce' => false,
527
            )
528
        );
529
    }
530
531
532
    /**
533
     * Used to register any global screen options if necessary for every route in this admin page group.
534
     */
535
    protected function _add_screen_options()
536
    {
537
    }
538
539
540
    /**
541
     * Implementing the screen options for the 'default' route.
542
     */
543
    protected function _add_screen_options_default()
544
    {
545
        $this->_per_page_screen_option();
546
    }
547
548
549
    /**
550
     * Implementing screen options for the category list route.
551
     */
552 View Code Duplication
    protected function _add_screen_options_category_list()
553
    {
554
        $page_title = $this->_admin_page_title;
555
        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
556
        $this->_per_page_screen_option();
557
        $this->_admin_page_title = $page_title;
558
    }
559
560
561
    /**
562
     * Used to register any global feature pointers for the admin page group.
563
     */
564
    protected function _add_feature_pointers()
565
    {
566
    }
567
568
569
    /**
570
     * Registers and enqueues any global scripts and styles for the entire admin page group.
571
     */
572 View Code Duplication
    public function load_scripts_styles()
573
    {
574
        wp_register_style(
575
            'events-admin-css',
576
            EVENTS_ASSETS_URL . 'events-admin-page.css',
577
            array(),
578
            EVENT_ESPRESSO_VERSION
579
        );
580
        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
581
        wp_enqueue_style('events-admin-css');
582
        wp_enqueue_style('ee-cat-admin');
583
        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
584
        // registers for all views
585
        // scripts
586
        wp_register_script(
587
            'event_editor_js',
588
            EVENTS_ASSETS_URL . 'event_editor.js',
589
            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
590
            EVENT_ESPRESSO_VERSION,
591
            true
592
        );
593
    }
594
595
596
    /**
597
     * Enqueuing scripts and styles specific to this view
598
     */
599
    public function load_scripts_styles_create_new()
600
    {
601
        $this->load_scripts_styles_edit();
602
    }
603
604
605
    /**
606
     * Enqueuing scripts and styles specific to this view
607
     */
608 View Code Duplication
    public function load_scripts_styles_edit()
609
    {
610
        // styles
611
        wp_enqueue_style('espresso-ui-theme');
612
        wp_register_style(
613
            'event-editor-css',
614
            EVENTS_ASSETS_URL . 'event-editor.css',
615
            array('ee-admin-css'),
616
            EVENT_ESPRESSO_VERSION
617
        );
618
        wp_enqueue_style('event-editor-css');
619
        // scripts
620
        wp_register_script(
621
            'event-datetime-metabox',
622
            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
623
            array('event_editor_js', 'ee-datepicker'),
624
            EVENT_ESPRESSO_VERSION
625
        );
626
        wp_enqueue_script('event-datetime-metabox');
627
    }
628
629
630
    /**
631
     * Populating the _views property for the category list table view.
632
     */
633 View Code Duplication
    protected function _set_list_table_views_category_list()
634
    {
635
        $this->_views = array(
636
            'all' => array(
637
                'slug'        => 'all',
638
                'label'       => esc_html__('All', 'event_espresso'),
639
                'count'       => 0,
640
                'bulk_action' => array(
641
                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
642
                ),
643
            ),
644
        );
645
    }
646
647
648
    /**
649
     * For adding anything that fires on the admin_init hook for any route within this admin page group.
650
     */
651
    public function admin_init()
652
    {
653
        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
654
            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
655
            'event_espresso'
656
        );
657
    }
658
659
660
    /**
661
     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
662
     * group.
663
     */
664
    public function admin_notices()
665
    {
666
    }
667
668
669
    /**
670
     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
671
     * this admin page group.
672
     */
673
    public function admin_footer_scripts()
674
    {
675
    }
676
677
678
    /**
679
     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
680
     * warning (via EE_Error::add_error());
681
     *
682
     * @param  EE_Event $event Event object
683
     * @param string    $req_type
684
     * @return void
685
     * @throws EE_Error
686
     * @access public
687
     */
688
    public function verify_event_edit($event = null, $req_type = '')
689
    {
690
        // don't need to do this when processing
691
        if (! empty($req_type)) {
692
            return;
693
        }
694
        // no event?
695
        if (empty($event)) {
696
            // set event
697
            $event = $this->_cpt_model_obj;
698
        }
699
        // STILL no event?
700
        if (! $event instanceof EE_Event) {
701
            return;
702
        }
703
        $orig_status = $event->status();
704
        // first check if event is active.
705
        if ($orig_status === EEM_Event::cancelled
706
            || $orig_status === EEM_Event::postponed
707
            || $event->is_expired()
708
            || $event->is_inactive()
709
        ) {
710
            return;
711
        }
712
        // made it here so it IS active... next check that any of the tickets are sold.
713
        if ($event->is_sold_out(true)) {
714
            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
715
                EE_Error::add_attention(
716
                    sprintf(
717
                        esc_html__(
718
                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
719
                            'event_espresso'
720
                        ),
721
                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
722
                    )
723
                );
724
            }
725
            return;
726
        } elseif ($orig_status === EEM_Event::sold_out) {
727
            EE_Error::add_attention(
728
                sprintf(
729
                    esc_html__(
730
                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
731
                        'event_espresso'
732
                    ),
733
                    EEH_Template::pretty_status($event->status(), false, 'sentence')
734
                )
735
            );
736
        }
737
        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
738
        if (! $event->tickets_on_sale()) {
739
            return;
740
        }
741
        // made it here so show warning
742
        $this->_edit_event_warning();
743
    }
744
745
746
    /**
747
     * This is the text used for when an event is being edited that is public and has tickets for sale.
748
     * When needed, hook this into a EE_Error::add_error() notice.
749
     *
750
     * @access protected
751
     * @return void
752
     */
753
    protected function _edit_event_warning()
754
    {
755
        // we don't want to add warnings during these requests
756
        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
757
            return;
758
        }
759
        EE_Error::add_attention(
760
            sprintf(
761
                esc_html__(
762
                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
763
                    'event_espresso'
764
                ),
765
                '<a class="espresso-help-tab-lnk">',
766
                '</a>'
767
            )
768
        );
769
    }
770
771
772
    /**
773
     * When a user is creating a new event, notify them if they haven't set their timezone.
774
     * Otherwise, do the normal logic
775
     *
776
     * @return string
777
     * @throws \EE_Error
778
     */
779
    protected function _create_new_cpt_item()
780
    {
781
        $has_timezone_string = get_option('timezone_string');
782
        // only nag them about setting their timezone if it's their first event, and they haven't already done it
783
        if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) {
784
            EE_Error::add_attention(
785
                sprintf(
786
                    __(
787
                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
788
                        'event_espresso'
789
                    ),
790
                    '<br>',
791
                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
792
                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
793
                    . '</select>',
794
                    '<button class="button button-secondary timezone-submit">',
795
                    '</button><span class="spinner"></span>'
796
                ),
797
                __FILE__,
798
                __FUNCTION__,
799
                __LINE__
800
            );
801
        }
802
        return parent::_create_new_cpt_item();
803
    }
804
805
806
    /**
807
     * Sets the _views property for the default route in this admin page group.
808
     */
809
    protected function _set_list_table_views_default()
810
    {
811
        $this->_views = array(
812
            'all'   => array(
813
                'slug'        => 'all',
814
                'label'       => esc_html__('View All Events', 'event_espresso'),
815
                'count'       => 0,
816
                'bulk_action' => array(
817
                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
818
                ),
819
            ),
820
            'draft' => array(
821
                'slug'        => 'draft',
822
                'label'       => esc_html__('Draft', 'event_espresso'),
823
                'count'       => 0,
824
                'bulk_action' => array(
825
                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
826
                ),
827
            ),
828
        );
829
        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
830
            $this->_views['trash'] = array(
831
                'slug'        => 'trash',
832
                'label'       => esc_html__('Trash', 'event_espresso'),
833
                'count'       => 0,
834
                'bulk_action' => array(
835
                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
836
                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
837
                ),
838
            );
839
        }
840
    }
841
842
843
    /**
844
     * Provides the legend item array for the default list table view.
845
     *
846
     * @return array
847
     */
848
    protected function _event_legend_items()
849
    {
850
        $items = array(
851
            'view_details'   => array(
852
                'class' => 'dashicons dashicons-search',
853
                'desc'  => esc_html__('View Event', 'event_espresso'),
854
            ),
855
            'edit_event'     => array(
856
                'class' => 'ee-icon ee-icon-calendar-edit',
857
                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
858
            ),
859
            'view_attendees' => array(
860
                'class' => 'dashicons dashicons-groups',
861
                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
862
            ),
863
        );
864
        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
865
        $statuses = array(
866
            'sold_out_status'  => array(
867
                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
868
                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
869
            ),
870
            'active_status'    => array(
871
                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
872
                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
873
            ),
874
            'upcoming_status'  => array(
875
                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
876
                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
877
            ),
878
            'postponed_status' => array(
879
                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
880
                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
881
            ),
882
            'cancelled_status' => array(
883
                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
884
                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
885
            ),
886
            'expired_status'   => array(
887
                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
888
                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
889
            ),
890
            'inactive_status'  => array(
891
                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
892
                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
893
            ),
894
        );
895
        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
896
        return array_merge($items, $statuses);
897
    }
898
899
900
    /**
901
     * @return EEM_Event
902
     */
903
    private function _event_model()
904
    {
905
        if (! $this->_event_model instanceof EEM_Event) {
906
            $this->_event_model = EE_Registry::instance()->load_model('Event');
907
        }
908
        return $this->_event_model;
909
    }
910
911
912
    /**
913
     * Adds extra buttons to the WP CPT permalink field row.
914
     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
915
     *
916
     * @param  string $return    the current html
917
     * @param  int    $id        the post id for the page
918
     * @param  string $new_title What the title is
919
     * @param  string $new_slug  what the slug is
920
     * @return string            The new html string for the permalink area
921
     */
922
    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
923
    {
924
        // make sure this is only when editing
925
        if (! empty($id)) {
926
            $post = get_post($id);
927
            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
928
                       . esc_html__('Shortcode', 'event_espresso')
929
                       . '</a> ';
930
            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
931
                       . $post->ID
932
                       . ']">';
933
        }
934
        return $return;
935
    }
936
937
938
    /**
939
     * _events_overview_list_table
940
     * This contains the logic for showing the events_overview list
941
     *
942
     * @access protected
943
     * @return void
944
     * @throws \EE_Error
945
     */
946
    protected function _events_overview_list_table()
947
    {
948
        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
949
        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
950
            ? (array) $this->_template_args['after_list_table']
951
            : array();
952
        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
953
                . EEH_Template::get_button_or_link(
954
                    get_post_type_archive_link('espresso_events'),
955
                    esc_html__("View Event Archive Page", "event_espresso"),
956
                    'button'
957
                );
958
        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
959
        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
960
            'create_new',
961
            'add',
962
            array(),
963
            'add-new-h2'
964
        );
965
        $this->display_admin_list_table_page_with_no_sidebar();
966
    }
967
968
969
    /**
970
     * this allows for extra misc actions in the default WP publish box
971
     *
972
     * @return void
973
     */
974
    public function extra_misc_actions_publish_box()
975
    {
976
        $this->_generate_publish_box_extra_content();
977
    }
978
979
980
    /**
981
     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
982
     * saved.
983
     * Typically you would use this to save any additional data.
984
     * Keep in mind also that "save_post" runs on EVERY post update to the database.
985
     * ALSO very important.  When a post transitions from scheduled to published,
986
     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
987
     * other meta saves. So MAKE sure that you handle this accordingly.
988
     *
989
     * @access protected
990
     * @abstract
991
     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
992
     * @param  object $post    The post object of the cpt that was saved.
993
     * @return void
994
     * @throws \EE_Error
995
     */
996
    protected function _insert_update_cpt_item($post_id, $post)
997
    {
998
        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
999
            // get out we're not processing an event save.
1000
            return;
1001
        }
1002
        $event_values = array(
1003
            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
1004
            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
1005
            'EVT_additional_limit'            => min(
1006
                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1007
                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
1008
            ),
1009
            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
1010
                ? $this->_req_data['EVT_default_registration_status']
1011
                : EE_Registry::instance()->CFG->registration->default_STS_ID,
1012
            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
1013
            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1014
            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
1015
                ? $this->_req_data['timezone_string'] : null,
1016
            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
1017
                ? $this->_req_data['externalURL'] : null,
1018
            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
1019
                ? $this->_req_data['event_phone'] : null,
1020
        );
1021
        // update event
1022
        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1023
        // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
1024
        $get_one_where = array(
1025
            $this->_event_model()->primary_key_name() => $post_id,
1026
            'OR'                                      => array(
1027
                'status'   => $post->post_status,
1028
                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1029
                // but the returned object here has a status of "publish", so use the original post status as well
1030
                'status*1' => $this->_req_data['original_post_status'],
1031
            ),
1032
        );
1033
        $event = $this->_event_model()->get_one(array($get_one_where));
1034
        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1035
        $event_update_callbacks = apply_filters(
1036
            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1037
            array(
1038
                array($this, '_default_venue_update'),
1039
                array($this, '_default_tickets_update'),
1040
            )
1041
        );
1042
        $att_success = true;
1043
        foreach ($event_update_callbacks as $e_callback) {
1044
            $_success = is_callable($e_callback)
1045
                ? call_user_func($e_callback, $event, $this->_req_data)
1046
                : false;
1047
            // if ANY of these updates fail then we want the appropriate global error message
1048
            $att_success = ! $att_success ? $att_success : $_success;
1049
        }
1050
        // any errors?
1051 View Code Duplication
        if ($success && false === $att_success) {
1052
            EE_Error::add_error(
1053
                esc_html__(
1054
                    'Event Details saved successfully but something went wrong with saving attachments.',
1055
                    'event_espresso'
1056
                ),
1057
                __FILE__,
1058
                __FUNCTION__,
1059
                __LINE__
1060
            );
1061
        } elseif ($success === false) {
1062
            EE_Error::add_error(
1063
                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1064
                __FILE__,
1065
                __FUNCTION__,
1066
                __LINE__
1067
            );
1068
        }
1069
    }
1070
1071
1072
    /**
1073
     * @see parent::restore_item()
1074
     * @param int $post_id
1075
     * @param int $revision_id
1076
     */
1077
    protected function _restore_cpt_item($post_id, $revision_id)
1078
    {
1079
        // copy existing event meta to new post
1080
        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1081
        if ($post_evt instanceof EE_Event) {
1082
            // meta revision restore
1083
            $post_evt->restore_revision($revision_id);
1084
            // related objs restore
1085
            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1086
        }
1087
    }
1088
1089
1090
    /**
1091
     * Attach the venue to the Event
1092
     *
1093
     * @param  \EE_Event $evtobj Event Object to add the venue to
1094
     * @param  array     $data   The request data from the form
1095
     * @return bool           Success or fail.
1096
     */
1097
    protected function _default_venue_update(\EE_Event $evtobj, $data)
1098
    {
1099
        require_once(EE_MODELS . 'EEM_Venue.model.php');
1100
        $venue_model = EE_Registry::instance()->load_model('Venue');
1101
        $rows_affected = null;
0 ignored issues
show
Unused Code introduced by
$rows_affected is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1102
        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1103
        // very important.  If we don't have a venue name...
1104
        // then we'll get out because not necessary to create empty venue
1105
        if (empty($data['venue_title'])) {
1106
            return false;
1107
        }
1108
        $venue_array = array(
1109
            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1110
            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1111
            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1112
            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1113
            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1114
                : null,
1115
            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1116
            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1117
            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1118
            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1119
            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1120
            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1121
            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1122
            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1123
            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1124
            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1125
            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1126
            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1127
            'status'              => 'publish',
1128
        );
1129
        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1130
        if (! empty($venue_id)) {
1131
            $update_where = array($venue_model->primary_key_name() => $venue_id);
1132
            $rows_affected = $venue_model->update($venue_array, array($update_where));
1133
            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1134
            $evtobj->_add_relation_to($venue_id, 'Venue');
1135
            return $rows_affected > 0 ? true : false;
1136
        } else {
1137
            // we insert the venue
1138
            $venue_id = $venue_model->insert($venue_array);
1139
            $evtobj->_add_relation_to($venue_id, 'Venue');
1140
            return ! empty($venue_id) ? true : false;
1141
        }
1142
        // when we have the ancestor come in it's already been handled by the revision save.
1143
    }
1144
1145
1146
    /**
1147
     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1148
     *
1149
     * @param  EE_Event $evtobj The Event object we're attaching data to
1150
     * @param  array    $data   The request data from the form
1151
     * @return array
1152
     */
1153
    protected function _default_tickets_update(EE_Event $evtobj, $data)
1154
    {
1155
        $success = true;
1156
        $saved_dtt = null;
1157
        $saved_tickets = array();
1158
        $incoming_date_formats = array('Y-m-d', 'h:i a');
1159
        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1160
            // trim all values to ensure any excess whitespace is removed.
1161
            $dtt = array_map('trim', $dtt);
1162
            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1163
                : $dtt['DTT_EVT_start'];
1164
            $datetime_values = array(
1165
                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1166
                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1167
                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1168
                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1169
                'DTT_order'     => $row,
1170
            );
1171
            // if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1172
            if (! empty($dtt['DTT_ID'])) {
1173
                $DTM = EE_Registry::instance()
1174
                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1175
                                  ->get_one_by_ID($dtt['DTT_ID']);
1176
                $DTM->set_date_format($incoming_date_formats[0]);
1177
                $DTM->set_time_format($incoming_date_formats[1]);
1178
                foreach ($datetime_values as $field => $value) {
1179
                    $DTM->set($field, $value);
1180
                }
1181
                // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1182
                $saved_dtts[ $DTM->ID() ] = $DTM;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$saved_dtts was never initialized. Although not strictly required by PHP, it is generally a good practice to add $saved_dtts = 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...
1183
            } else {
1184
                $DTM = EE_Registry::instance()->load_class(
1185
                    'Datetime',
1186
                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1187
                    false,
1188
                    false
1189
                );
1190
                foreach ($datetime_values as $field => $value) {
1191
                    $DTM->set($field, $value);
1192
                }
1193
            }
1194
            $DTM->save();
1195
            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1196
            // load DTT helper
1197
            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1198 View Code Duplication
            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1199
                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1200
                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1201
                $DTT->save();
1202
            }
1203
            // now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1204
            $saved_dtt = $DTT;
1205
            $success = ! $success ? $success : $DTT;
1206
            // if ANY of these updates fail then we want the appropriate global error message.
1207
            // //todo this is actually sucky we need a better error message but this is what it is for now.
1208
        }
1209
        // no dtts get deleted so we don't do any of that logic here.
1210
        // update tickets next
1211
        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1212
        foreach ($data['edit_tickets'] as $row => $tkt) {
1213
            $incoming_date_formats = array('Y-m-d', 'h:i a');
1214
            $update_prices = false;
1215
            $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1216
                ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0;
1217
            // trim inputs to ensure any excess whitespace is removed.
1218
            $tkt = array_map('trim', $tkt);
1219
            if (empty($tkt['TKT_start_date'])) {
1220
                // let's use now in the set timezone.
1221
                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1222
                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1223
            }
1224
            if (empty($tkt['TKT_end_date'])) {
1225
                // use the start date of the first datetime
1226
                $dtt = $evtobj->first_datetime();
1227
                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1228
                    $incoming_date_formats[0],
1229
                    $incoming_date_formats[1]
1230
                );
1231
            }
1232
            $TKT_values = array(
1233
                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1234
                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1235
                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1236
                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1237
                'TKT_start_date'  => $tkt['TKT_start_date'],
1238
                'TKT_end_date'    => $tkt['TKT_end_date'],
1239
                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1240
                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1241
                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1242
                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1243
                'TKT_row'         => $row,
1244
                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1245
                'TKT_price'       => $ticket_price,
1246
            );
1247
            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1248 View Code Duplication
            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1249
                $TKT_values['TKT_ID'] = 0;
1250
                $TKT_values['TKT_is_default'] = 0;
1251
                $TKT_values['TKT_price'] = $ticket_price;
1252
                $update_prices = true;
1253
            }
1254
            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1255
            // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1256
            // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1257
            if (! empty($tkt['TKT_ID'])) {
1258
                $TKT = EE_Registry::instance()
1259
                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1260
                                  ->get_one_by_ID($tkt['TKT_ID']);
1261
                if ($TKT instanceof EE_Ticket) {
1262
                    $ticket_sold = $TKT->count_related(
1263
                        'Registration',
1264
                        array(
1265
                            array(
1266
                                'STS_ID' => array(
1267
                                    'NOT IN',
1268
                                    array(EEM_Registration::status_id_incomplete),
1269
                                ),
1270
                            ),
1271
                        )
1272
                    ) > 0 ? true : false;
1273
                    // let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1274
                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1275
                                      && ! $TKT->get('TKT_deleted');
1276
                    $TKT->set_date_format($incoming_date_formats[0]);
1277
                    $TKT->set_time_format($incoming_date_formats[1]);
1278
                    // set new values
1279 View Code Duplication
                    foreach ($TKT_values as $field => $value) {
1280
                        if ($field == 'TKT_qty') {
1281
                            $TKT->set_qty($value);
1282
                        } else {
1283
                            $TKT->set($field, $value);
1284
                        }
1285
                    }
1286
                    // if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1287
                    if ($create_new_TKT) {
1288
                        // archive the old ticket first
1289
                        $TKT->set('TKT_deleted', 1);
1290
                        $TKT->save();
1291
                        // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1292
                        $saved_tickets[ $TKT->ID() ] = $TKT;
1293
                        // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1294
                        $TKT = clone $TKT;
1295
                        $TKT->set('TKT_ID', 0);
1296
                        $TKT->set('TKT_deleted', 0);
1297
                        $TKT->set('TKT_price', $ticket_price);
1298
                        $TKT->set('TKT_sold', 0);
1299
                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1300
                        $update_prices = true;
1301
                    }
1302
                    // make sure price is set if it hasn't been already
1303
                    $TKT->set('TKT_price', $ticket_price);
1304
                }
1305
            } else {
1306
                // no TKT_id so a new TKT
1307
                $TKT_values['TKT_price'] = $ticket_price;
1308
                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1309
                if ($TKT instanceof EE_Ticket) {
1310
                    // need to reset values to properly account for the date formats
1311
                    $TKT->set_date_format($incoming_date_formats[0]);
1312
                    $TKT->set_time_format($incoming_date_formats[1]);
1313
                    $TKT->set_timezone($evtobj->get_timezone());
1314
                    // set new values
1315 View Code Duplication
                    foreach ($TKT_values as $field => $value) {
1316
                        if ($field == 'TKT_qty') {
1317
                            $TKT->set_qty($value);
1318
                        } else {
1319
                            $TKT->set($field, $value);
1320
                        }
1321
                    }
1322
                    $update_prices = true;
1323
                }
1324
            }
1325
            // cap ticket qty by datetime reg limits
1326
            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1327
            // update ticket.
1328
            $TKT->save();
1329
            // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1330 View Code Duplication
            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1331
                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1332
                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1333
                $TKT->save();
1334
            }
1335
            // initially let's add the ticket to the dtt
1336
            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1337
            $saved_tickets[ $TKT->ID() ] = $TKT;
1338
            // add prices to ticket
1339
            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1340
        }
1341
        // however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1342
        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1343
        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1344 View Code Duplication
        foreach ($tickets_removed as $id) {
1345
            $id = absint($id);
1346
            // get the ticket for this id
1347
            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1348
            // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1349
            $dtts = $tkt_to_remove->get_many_related('Datetime');
1350
            foreach ($dtts as $dtt) {
1351
                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1352
            }
1353
            // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1354
            $tkt_to_remove->delete_related_permanently('Price');
1355
            // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1356
            $tkt_to_remove->delete_permanently();
1357
        }
1358
        return array($saved_dtt, $saved_tickets);
1359
    }
1360
1361
1362
    /**
1363
     * This attaches a list of given prices to a ticket.
1364
     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1365
     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1366
     * price info and prices are automatically "archived" via the ticket.
1367
     *
1368
     * @access  private
1369
     * @param array     $prices     Array of prices from the form.
1370
     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1371
     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1372
     * @return  void
1373
     */
1374
    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1375
    {
1376
        foreach ($prices as $row => $prc) {
1377
            $PRC_values = array(
1378
                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1379
                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1380
                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1381
                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1382
                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1383
                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1384
                'PRC_order'      => $row,
1385
            );
1386 View Code Duplication
            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1387
                $PRC_values['PRC_ID'] = 0;
1388
                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1389
            } else {
1390
                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1391
                // update this price with new values
1392
                foreach ($PRC_values as $field => $newprc) {
1393
                    $PRC->set($field, $newprc);
1394
                }
1395
                $PRC->save();
1396
            }
1397
            $ticket->_add_relation_to($PRC, 'Price');
1398
        }
1399
    }
1400
1401
1402
    /**
1403
     * Add in our autosave ajax handlers
1404
     *
1405
     */
1406
    protected function _ee_autosave_create_new()
1407
    {
1408
    }
1409
1410
1411
    /**
1412
     * More autosave handlers.
1413
     */
1414
    protected function _ee_autosave_edit()
1415
    {
1416
        return; // TEMPORARILY EXITING CAUSE THIS IS A TODO
1417
    }
1418
1419
1420
    /**
1421
     *    _generate_publish_box_extra_content
1422
     */
1423
    private function _generate_publish_box_extra_content()
1424
    {
1425
        // load formatter helper
1426
        // args for getting related registrations
1427
        $approved_query_args = array(
1428
            array(
1429
                'REG_deleted' => 0,
1430
                'STS_ID'      => EEM_Registration::status_id_approved,
1431
            ),
1432
        );
1433
        $not_approved_query_args = array(
1434
            array(
1435
                'REG_deleted' => 0,
1436
                'STS_ID'      => EEM_Registration::status_id_not_approved,
1437
            ),
1438
        );
1439
        $pending_payment_query_args = array(
1440
            array(
1441
                'REG_deleted' => 0,
1442
                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1443
            ),
1444
        );
1445
        // publish box
1446
        $publish_box_extra_args = array(
1447
            'view_approved_reg_url'        => add_query_arg(
1448
                array(
1449
                    'action'      => 'default',
1450
                    'event_id'    => $this->_cpt_model_obj->ID(),
1451
                    '_reg_status' => EEM_Registration::status_id_approved,
1452
                ),
1453
                REG_ADMIN_URL
1454
            ),
1455
            'view_not_approved_reg_url'    => add_query_arg(
1456
                array(
1457
                    'action'      => 'default',
1458
                    'event_id'    => $this->_cpt_model_obj->ID(),
1459
                    '_reg_status' => EEM_Registration::status_id_not_approved,
1460
                ),
1461
                REG_ADMIN_URL
1462
            ),
1463
            'view_pending_payment_reg_url' => add_query_arg(
1464
                array(
1465
                    'action'      => 'default',
1466
                    'event_id'    => $this->_cpt_model_obj->ID(),
1467
                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1468
                ),
1469
                REG_ADMIN_URL
1470
            ),
1471
            'approved_regs'                => $this->_cpt_model_obj->count_related(
1472
                'Registration',
1473
                $approved_query_args
1474
            ),
1475
            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1476
                'Registration',
1477
                $not_approved_query_args
1478
            ),
1479
            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1480
                'Registration',
1481
                $pending_payment_query_args
1482
            ),
1483
            'misc_pub_section_class'       => apply_filters(
1484
                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1485
                'misc-pub-section'
1486
            ),
1487
        );
1488
        ob_start();
1489
        do_action(
1490
            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1491
            $this->_cpt_model_obj
1492
        );
1493
        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1494
        // load template
1495
        EEH_Template::display_template(
1496
            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1497
            $publish_box_extra_args
1498
        );
1499
    }
1500
1501
1502
    /**
1503
     * @return EE_Event
1504
     */
1505
    public function get_event_object()
1506
    {
1507
        return $this->_cpt_model_obj;
1508
    }
1509
1510
1511
1512
1513
    /** METABOXES * */
1514
    /**
1515
     * _register_event_editor_meta_boxes
1516
     * add all metaboxes related to the event_editor
1517
     *
1518
     * @return void
1519
     */
1520
    protected function _register_event_editor_meta_boxes()
1521
    {
1522
        $this->verify_cpt_object();
1523
        add_meta_box(
1524
            'espresso_event_editor_tickets',
1525
            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1526
            array($this, 'ticket_metabox'),
1527
            $this->page_slug,
1528
            'normal',
1529
            'high'
1530
        );
1531
        add_meta_box(
1532
            'espresso_event_editor_event_options',
1533
            esc_html__('Event Registration Options', 'event_espresso'),
1534
            array($this, 'registration_options_meta_box'),
1535
            $this->page_slug,
1536
            'side',
1537
            'default'
1538
        );
1539
        // NOTE: if you're looking for other metaboxes in here,
1540
        // where a metabox has a related management page in the admin
1541
        // you will find it setup in the related management page's "_Hooks" file.
1542
        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1543
    }
1544
1545
1546
    /**
1547
     * @throws DomainException
1548
     * @throws EE_Error
1549
     */
1550
    public function ticket_metabox()
1551
    {
1552
        $existing_datetime_ids = $existing_ticket_ids = array();
1553
        // defaults for template args
1554
        $template_args = array(
1555
            'existing_datetime_ids'    => '',
1556
            'event_datetime_help_link' => '',
1557
            'ticket_options_help_link' => '',
1558
            'time'                     => null,
1559
            'ticket_rows'              => '',
1560
            'existing_ticket_ids'      => '',
1561
            'total_ticket_rows'        => 1,
1562
            'ticket_js_structure'      => '',
1563
            'trash_icon'               => 'ee-lock-icon',
1564
            'disabled'                 => '',
1565
        );
1566
        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1567
        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1568
        /**
1569
         * 1. Start with retrieving Datetimes
1570
         * 2. Fore each datetime get related tickets
1571
         * 3. For each ticket get related prices
1572
         */
1573
        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1574
        /** @type EE_Datetime $first_datetime */
1575
        $first_datetime = reset($times);
1576
        // do we get related tickets?
1577
        if ($first_datetime instanceof EE_Datetime
1578
            && $first_datetime->ID() !== 0
1579
        ) {
1580
            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1581
            $template_args['time'] = $first_datetime;
1582
            $related_tickets = $first_datetime->tickets(
1583
                array(
1584
                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1585
                    'default_where_conditions' => 'none',
1586
                )
1587
            );
1588
            if (! empty($related_tickets)) {
1589
                $template_args['total_ticket_rows'] = count($related_tickets);
1590
                $row = 0;
1591
                foreach ($related_tickets as $ticket) {
1592
                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1593
                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1594
                    $row++;
1595
                }
1596 View Code Duplication
            } else {
1597
                $template_args['total_ticket_rows'] = 1;
1598
                /** @type EE_Ticket $ticket */
1599
                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1600
                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1601
            }
1602 View Code Duplication
        } else {
1603
            $template_args['time'] = $times[0];
1604
            /** @type EE_Ticket $ticket */
1605
            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1606
            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1607
            // NOTE: we're just sending the first default row
1608
            // (decaf can't manage default tickets so this should be sufficient);
1609
        }
1610
        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1611
            'event_editor_event_datetimes_help_tab'
1612
        );
1613
        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1614
        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1615
        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1616
        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1617
            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1618
            true
1619
        );
1620
        $template = apply_filters(
1621
            'FHEE__Events_Admin_Page__ticket_metabox__template',
1622
            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1623
        );
1624
        EEH_Template::display_template($template, $template_args);
1625
    }
1626
1627
1628
    /**
1629
     * Setup an individual ticket form for the decaf event editor page
1630
     *
1631
     * @access private
1632
     * @param  EE_Ticket $ticket   the ticket object
1633
     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1634
     * @param int        $row
1635
     * @return string generated html for the ticket row.
1636
     */
1637
    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1638
    {
1639
        $template_args = array(
1640
            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1641
            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1642
                : '',
1643
            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1644
            'TKT_ID'              => $ticket->get('TKT_ID'),
1645
            'TKT_name'            => $ticket->get('TKT_name'),
1646
            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1647
            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1648
            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1649
            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1650
            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1651
            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1652
            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1653
                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1654
                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1655
            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1656
                : ' disabled=disabled',
1657
        );
1658
        $price = $ticket->ID() !== 0
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison !== seems to always evaluate to true as the types of $ticket->ID() (string) and 0 (integer) can never be identical. Maybe you want to use a loose comparison != instead?
Loading history...
1659
            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1660
            : EE_Registry::instance()->load_model('Price')->create_default_object();
1661
        $price_args = array(
1662
            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1663
            'PRC_amount'            => $price->get('PRC_amount'),
1664
            'PRT_ID'                => $price->get('PRT_ID'),
1665
            'PRC_ID'                => $price->get('PRC_ID'),
1666
            'PRC_is_default'        => $price->get('PRC_is_default'),
1667
        );
1668
        // make sure we have default start and end dates if skeleton
1669
        // handle rows that should NOT be empty
1670
        if (empty($template_args['TKT_start_date'])) {
1671
            // if empty then the start date will be now.
1672
            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1673
        }
1674
        if (empty($template_args['TKT_end_date'])) {
1675
            // get the earliest datetime (if present);
1676
            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1677
                ? $this->_cpt_model_obj->get_first_related(
1678
                    'Datetime',
1679
                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1680
                )
1681
                : null;
1682
            if (! empty($earliest_dtt)) {
1683
                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1684 View Code Duplication
            } else {
1685
                $template_args['TKT_end_date'] = date(
1686
                    'Y-m-d h:i a',
1687
                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1688
                );
1689
            }
1690
        }
1691
        $template_args = array_merge($template_args, $price_args);
1692
        $template = apply_filters(
1693
            'FHEE__Events_Admin_Page__get_ticket_row__template',
1694
            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1695
            $ticket
1696
        );
1697
        return EEH_Template::display_template($template, $template_args, true);
1698
    }
1699
1700
1701
    /**
1702
     * @throws DomainException
1703
     */
1704
    public function registration_options_meta_box()
1705
    {
1706
        $yes_no_values = array(
1707
            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1708
            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1709
        );
1710
        $default_reg_status_values = EEM_Registration::reg_status_array(
1711
            array(
1712
                EEM_Registration::status_id_cancelled,
1713
                EEM_Registration::status_id_declined,
1714
                EEM_Registration::status_id_incomplete,
1715
            ),
1716
            true
1717
        );
1718
        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1719
        $template_args['_event'] = $this->_cpt_model_obj;
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...
1720
        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1721
        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1722
        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1723
            'default_reg_status',
1724
            $default_reg_status_values,
1725
            $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...
1726
        );
1727
        $template_args['display_description'] = EEH_Form_Fields::select_input(
1728
            'display_desc',
1729
            $yes_no_values,
1730
            $this->_cpt_model_obj->display_description()
1731
        );
1732
        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1733
            'display_ticket_selector',
1734
            $yes_no_values,
1735
            $this->_cpt_model_obj->display_ticket_selector(),
1736
            '',
1737
            '',
1738
            false
1739
        );
1740
        $template_args['additional_registration_options'] = apply_filters(
1741
            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1742
            '',
1743
            $template_args,
1744
            $yes_no_values,
1745
            $default_reg_status_values
1746
        );
1747
        EEH_Template::display_template(
1748
            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1749
            $template_args
1750
        );
1751
    }
1752
1753
1754
    /**
1755
     * _get_events()
1756
     * This method simply returns all the events (for the given _view and paging)
1757
     *
1758
     * @access public
1759
     * @param int  $per_page     count of items per page (20 default);
1760
     * @param int  $current_page what is the current page being viewed.
1761
     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1762
     *                           If FALSE then we return an array of event objects
1763
     *                           that match the given _view and paging parameters.
1764
     * @return array an array of event objects.
1765
     */
1766
    public function get_events($per_page = 10, $current_page = 1, $count = false)
1767
    {
1768
        $EEME = $this->_event_model();
1769
        $offset = ($current_page - 1) * $per_page;
1770
        $limit = $count ? null : $offset . ',' . $per_page;
1771
        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1772
        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1773
        if (isset($this->_req_data['month_range'])) {
1774
            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1775
            // simulate the FIRST day of the month, that fixes issues for months like February
1776
            // where PHP doesn't know what to assume for date.
1777
            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1778
            $month_r = ! empty($pieces[0]) ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1779
            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1780
        }
1781
        $where = array();
1782
        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1783
        // determine what post_status our condition will have for the query.
1784
        switch ($status) {
1785
            case 'month':
1786
            case 'today':
1787
            case null:
1788
            case 'all':
1789
                break;
1790
            case 'draft':
1791
                $where['status'] = array('IN', array('draft', 'auto-draft'));
1792
                break;
1793
            default:
1794
                $where['status'] = $status;
1795
        }
1796
        // categories?
1797
        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1798
            ? $this->_req_data['EVT_CAT'] : null;
1799
        if (! empty($category)) {
1800
            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1801
            $where['Term_Taxonomy.term_id'] = $category;
1802
        }
1803
        // date where conditions
1804
        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1805
        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1806
            $DateTime = new DateTime(
1807
                $year_r . '-' . $month_r . '-01 00:00:00',
1808
                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1809
            );
1810
            $start = $DateTime->format(implode(' ', $start_formats));
1811
            $end = $DateTime->setDate(
1812
                $year_r,
1813
                $month_r,
1814
                $DateTime
1815
                    ->format('t')
1816
            )->setTime(23, 59, 59)
1817
                            ->format(implode(' ', $start_formats));
1818
            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1819
        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1820
            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1821
            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1822
            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1823
            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1824
        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1825
            $now = date('Y-m-01');
1826
            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1827
            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1828
            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1829
                            ->setTime(23, 59, 59)
1830
                            ->format(implode(' ', $start_formats));
1831
            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1832
        }
1833 View Code Duplication
        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1834
            $where['EVT_wp_user'] = get_current_user_id();
1835
        } else {
1836
            if (! isset($where['status'])) {
1837
                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1838
                    $where['OR'] = array(
1839
                        'status*restrict_private' => array('!=', 'private'),
1840
                        'AND'                     => array(
1841
                            'status*inclusive' => array('=', 'private'),
1842
                            'EVT_wp_user'      => get_current_user_id(),
1843
                        ),
1844
                    );
1845
                }
1846
            }
1847
        }
1848
        if (isset($this->_req_data['EVT_wp_user'])) {
1849
            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1850
                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1851
            ) {
1852
                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1853
            }
1854
        }
1855
        // search query handling
1856
        if (isset($this->_req_data['s'])) {
1857
            $search_string = '%' . $this->_req_data['s'] . '%';
1858
            $where['OR'] = array(
1859
                'EVT_name'       => array('LIKE', $search_string),
1860
                'EVT_desc'       => array('LIKE', $search_string),
1861
                'EVT_short_desc' => array('LIKE', $search_string),
1862
            );
1863
        }
1864
        // filter events by venue.
1865
        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
1866
            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
1867
        }
1868
        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1869
        $query_params = apply_filters(
1870
            'FHEE__Events_Admin_Page__get_events__query_params',
1871
            array(
1872
                $where,
1873
                'limit'    => $limit,
1874
                'order_by' => $orderby,
1875
                'order'    => $order,
1876
                'group_by' => 'EVT_ID',
1877
            ),
1878
            $this->_req_data
1879
        );
1880
        // let's first check if we have special requests coming in.
1881
        if (isset($this->_req_data['active_status'])) {
1882
            switch ($this->_req_data['active_status']) {
1883
                case 'upcoming':
1884
                    return $EEME->get_upcoming_events($query_params, $count);
1885
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1886
                case 'expired':
1887
                    return $EEME->get_expired_events($query_params, $count);
1888
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1889
                case 'active':
1890
                    return $EEME->get_active_events($query_params, $count);
1891
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1892
                case 'inactive':
1893
                    return $EEME->get_inactive_events($query_params, $count);
1894
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1895
            }
1896
        }
1897
1898
        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1899
        return $events;
1900
    }
1901
1902
1903
    /**
1904
     * handling for WordPress CPT actions (trash, restore, delete)
1905
     *
1906
     * @param string $post_id
1907
     */
1908
    public function trash_cpt_item($post_id)
1909
    {
1910
        $this->_req_data['EVT_ID'] = $post_id;
1911
        $this->_trash_or_restore_event('trash', false);
1912
    }
1913
1914
1915
    /**
1916
     * @param string $post_id
1917
     */
1918
    public function restore_cpt_item($post_id)
1919
    {
1920
        $this->_req_data['EVT_ID'] = $post_id;
1921
        $this->_trash_or_restore_event('draft', false);
1922
    }
1923
1924
1925
    /**
1926
     * @param string $post_id
1927
     */
1928
    public function delete_cpt_item($post_id)
1929
    {
1930
        throw new EE_Error(esc_html__('Please contact Event Espresso support with the details of what you did to produce this error.', 'event_espresso'));
1931
        $this->_req_data['EVT_ID'] = $post_id;
1932
        $this->_delete_event();
1933
    }
1934
1935
1936
    /**
1937
     * _trash_or_restore_event
1938
     *
1939
     * @access protected
1940
     * @param  string $event_status
1941
     * @param bool    $redirect_after
1942
     */
1943 View Code Duplication
    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1944
    {
1945
        // determine the event id and set to array.
1946
        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1947
        // loop thru events
1948
        if ($EVT_ID) {
1949
            // clean status
1950
            $event_status = sanitize_key($event_status);
1951
            // grab status
1952
            if (! empty($event_status)) {
1953
                $success = $this->_change_event_status($EVT_ID, $event_status);
1954
            } else {
1955
                $success = false;
1956
                $msg = esc_html__(
1957
                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1958
                    'event_espresso'
1959
                );
1960
                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1961
            }
1962
        } else {
1963
            $success = false;
1964
            $msg = esc_html__(
1965
                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1966
                'event_espresso'
1967
            );
1968
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1969
        }
1970
        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1971
        if ($redirect_after) {
1972
            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1973
        }
1974
    }
1975
1976
1977
    /**
1978
     * _trash_or_restore_events
1979
     *
1980
     * @access protected
1981
     * @param  string $event_status
1982
     * @return void
1983
     */
1984 View Code Duplication
    protected function _trash_or_restore_events($event_status = 'trash')
1985
    {
1986
        // clean status
1987
        $event_status = sanitize_key($event_status);
1988
        // grab status
1989
        if (! empty($event_status)) {
1990
            $success = true;
1991
            // determine the event id and set to array.
1992
            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array();
1993
            // loop thru events
1994
            foreach ($EVT_IDs as $EVT_ID) {
1995
                if ($EVT_ID = absint($EVT_ID)) {
1996
                    $results = $this->_change_event_status($EVT_ID, $event_status);
1997
                    $success = $results !== false ? $success : false;
1998
                } else {
1999
                    $msg = sprintf(
2000
                        esc_html__(
2001
                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2002
                            'event_espresso'
2003
                        ),
2004
                        $EVT_ID
2005
                    );
2006
                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2007
                    $success = false;
2008
                }
2009
            }
2010
        } else {
2011
            $success = false;
2012
            $msg = esc_html__(
2013
                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2014
                'event_espresso'
2015
            );
2016
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2017
        }
2018
        // in order to force a pluralized result message we need to send back a success status greater than 1
2019
        $success = $success ? 2 : false;
2020
        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2021
        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
2022
    }
2023
2024
2025
    /**
2026
     * _trash_or_restore_events
2027
     *
2028
     * @access  private
2029
     * @param  int    $EVT_ID
2030
     * @param  string $event_status
2031
     * @return bool
2032
     */
2033 View Code Duplication
    private function _change_event_status($EVT_ID = 0, $event_status = '')
2034
    {
2035
        // grab event id
2036
        if (! $EVT_ID) {
2037
            $msg = esc_html__(
2038
                'An error occurred. No Event ID or an invalid Event ID was received.',
2039
                'event_espresso'
2040
            );
2041
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2042
            return false;
2043
        }
2044
        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2045
        // clean status
2046
        $event_status = sanitize_key($event_status);
2047
        // grab status
2048
        if (empty($event_status)) {
2049
            $msg = esc_html__(
2050
                'An error occurred. No Event Status or an invalid Event Status was received.',
2051
                'event_espresso'
2052
            );
2053
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2054
            return false;
2055
        }
2056
        // was event trashed or restored ?
2057
        switch ($event_status) {
2058
            case 'draft':
2059
                $action = 'restored from the trash';
2060
                $hook = 'AHEE_event_restored_from_trash';
2061
                break;
2062
            case 'trash':
2063
                $action = 'moved to the trash';
2064
                $hook = 'AHEE_event_moved_to_trash';
2065
                break;
2066
            default:
2067
                $action = 'updated';
2068
                $hook = false;
2069
        }
2070
        // use class to change status
2071
        $this->_cpt_model_obj->set_status($event_status);
2072
        $success = $this->_cpt_model_obj->save();
2073
        if ($success === false) {
2074
            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2075
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2076
            return false;
2077
        }
2078
        if ($hook) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $hook of type string|false is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
2079
            do_action($hook);
2080
        }
2081
        return true;
2082
    }
2083
2084
2085
    /**
2086
     * _delete_event
2087
     *
2088
     * @access protected
2089
     * @param bool $redirect_after
0 ignored issues
show
Bug introduced by
There is no parameter named $redirect_after. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2090
     */
2091
    protected function _delete_event()
2092
    {
2093
        // determine the event id and set to array.
2094
        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2095
        wp_safe_redirect(
2096
            EE_Admin_Page::add_query_args_and_nonce(
2097
                [
2098
                    'action' => 'preview_deletion',
2099
                    'EVT_IDs[]' => $EVT_ID
2100
                ],
2101
                $this->_admin_base_url
2102
            )
2103
        );
2104
    }
2105
2106
2107
    /**
2108
     * _delete_events
2109
     *
2110
     * @access protected
2111
     * @return void
2112
     */
2113
    protected function _delete_events()
2114
    {
2115
        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2116
        $args = [
2117
            'action' => 'preview_deletion',
2118
        ];
2119
        foreach($EVT_IDs as $EVT_ID){
2120
            $args['EVT_IDs[]'] = (int)$EVT_ID;
2121
        }
2122
        wp_safe_redirect(
2123
            EE_Admin_Page::add_query_args_and_nonce(
2124
                $args,
2125
                $this->_admin_base_url
2126
            )
2127
        );
2128
    }
2129
2130
    /**
2131
     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2132
     * @since $VID:$
2133
     */
2134
    protected function previewDeletion()
2135
    {
2136
        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2137
        $confirm_deletion_args = [
2138
            'action' => 'confirm_deletion',
2139
        ];
2140
        foreach($EVT_IDs as $EVT_ID){
2141
            $confirm_deletion_args['EVT_ID[]'] = (int)$EVT_ID;
2142
        }
2143
        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2144
            EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php',
2145
            [
2146
                'form_url' => EE_Admin_Page::add_query_args_and_nonce(
2147
                    $confirm_deletion_args,
2148
                    $this->admin_base_url()
2149
                )
2150
            ],
2151
            true
2152
        );
2153
        $this->display_admin_page_with_no_sidebar();
2154
    }
2155
2156
    protected function confirmDeletion()
2157
    {
2158
        echo "event deleted here";
2159
2160
        // code from original _delete_event, which I assume we want to keep
2161
        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2162
        // remove this event from the list of events with no prices
2163
        if (isset($espresso_no_ticket_prices[ $EVT_ID ])) {
0 ignored issues
show
Bug introduced by
The variable $EVT_ID seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
2164
            unset($espresso_no_ticket_prices[ $EVT_ID ]);
2165
        }
2166
        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2167
    }
2168
2169
    /**
2170
     * _permanently_delete_event
2171
     *
2172
     * @access  private
2173
     * @param  int $EVT_ID
2174
     * @return bool
2175
     */
2176
    private function _permanently_delete_event($EVT_ID = 0)
2177
    {
2178
        // grab event id
2179
        if (! $EVT_ID) {
2180
            $msg = esc_html__(
2181
                'An error occurred. No Event ID or an invalid Event ID was received.',
2182
                'event_espresso'
2183
            );
2184
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2185
            return false;
2186
        }
2187
        if (! $this->_cpt_model_obj instanceof EE_Event
2188
            || $this->_cpt_model_obj->ID() !== $EVT_ID
2189
        ) {
2190
            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2191
        }
2192
        if (! $this->_cpt_model_obj instanceof EE_Event) {
2193
            return false;
2194
        }
2195
        // need to delete related tickets and prices first.
2196
        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2197
        foreach ($datetimes as $datetime) {
2198
            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2199
            $tickets = $datetime->get_many_related('Ticket');
2200
            foreach ($tickets as $ticket) {
2201
                $ticket->_remove_relation_to($datetime, 'Datetime');
2202
                $ticket->delete_related_permanently('Price');
2203
                $ticket->delete_permanently();
2204
            }
2205
            $datetime->delete();
2206
        }
2207
        // what about related venues or terms?
2208
        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2209
        foreach ($venues as $venue) {
2210
            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2211
        }
2212
        // any attached question groups?
2213
        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2214
        if (! empty($question_groups)) {
2215
            foreach ($question_groups as $question_group) {
2216
                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2217
            }
2218
        }
2219
        // Message Template Groups
2220
        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2221
        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2222
        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2223
        foreach ($term_taxonomies as $term_taxonomy) {
2224
            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2225
        }
2226
        $success = $this->_cpt_model_obj->delete_permanently();
2227
        // did it all go as planned ?
2228
        if ($success) {
2229
            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2230
            EE_Error::add_success($msg);
2231
        } else {
2232
            $msg = sprintf(
2233
                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2234
                $EVT_ID
2235
            );
2236
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2237
            return false;
2238
        }
2239
        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2240
        return true;
2241
    }
2242
2243
2244
    /**
2245
     * get total number of events
2246
     *
2247
     * @access public
2248
     * @return int
2249
     */
2250
    public function total_events()
2251
    {
2252
        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2253
        return $count;
2254
    }
2255
2256
2257
    /**
2258
     * get total number of draft events
2259
     *
2260
     * @access public
2261
     * @return int
2262
     */
2263
    public function total_events_draft()
2264
    {
2265
        $where = array(
2266
            'status' => array('IN', array('draft', 'auto-draft')),
2267
        );
2268
        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2269
        return $count;
2270
    }
2271
2272
2273
    /**
2274
     * get total number of trashed events
2275
     *
2276
     * @access public
2277
     * @return int
2278
     */
2279
    public function total_trashed_events()
2280
    {
2281
        $where = array(
2282
            'status' => 'trash',
2283
        );
2284
        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2285
        return $count;
2286
    }
2287
2288
2289
    /**
2290
     *    _default_event_settings
2291
     *    This generates the Default Settings Tab
2292
     *
2293
     * @return void
2294
     * @throws EE_Error
2295
     */
2296 View Code Duplication
    protected function _default_event_settings()
2297
    {
2298
        $this->_set_add_edit_form_tags('update_default_event_settings');
2299
        $this->_set_publish_post_box_vars(null, false, false, null, false);
2300
        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2301
        $this->display_admin_page_with_sidebar();
2302
    }
2303
2304
2305
    /**
2306
     * Return the form for event settings.
2307
     *
2308
     * @return EE_Form_Section_Proper
2309
     * @throws EE_Error
2310
     */
2311
    protected function _default_event_settings_form()
2312
    {
2313
        $registration_config = EE_Registry::instance()->CFG->registration;
2314
        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2315
            // exclude
2316
            array(
2317
                EEM_Registration::status_id_cancelled,
2318
                EEM_Registration::status_id_declined,
2319
                EEM_Registration::status_id_incomplete,
2320
                EEM_Registration::status_id_wait_list,
2321
            ),
2322
            true
2323
        );
2324
        return new EE_Form_Section_Proper(
2325
            array(
2326
                'name'            => 'update_default_event_settings',
2327
                'html_id'         => 'update_default_event_settings',
2328
                'html_class'      => 'form-table',
2329
                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2330
                'subsections'     => apply_filters(
2331
                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2332
                    array(
2333
                        'default_reg_status'  => new EE_Select_Input(
2334
                            $registration_stati_for_selection,
2335
                            array(
2336
                                'default'         => isset($registration_config->default_STS_ID)
2337
                                                     && array_key_exists(
2338
                                                         $registration_config->default_STS_ID,
2339
                                                         $registration_stati_for_selection
2340
                                                     )
2341
                                    ? sanitize_text_field($registration_config->default_STS_ID)
2342
                                    : EEM_Registration::status_id_pending_payment,
2343
                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2344
                                                     . EEH_Template::get_help_tab_link(
2345
                                                         'default_settings_status_help_tab'
2346
                                                     ),
2347
                                'html_help_text'  => esc_html__(
2348
                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2349
                                    'event_espresso'
2350
                                ),
2351
                            )
2352
                        ),
2353
                        'default_max_tickets' => new EE_Integer_Input(
2354
                            array(
2355
                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2356
                                    ? $registration_config->default_maximum_number_of_tickets
2357
                                    : EEM_Event::get_default_additional_limit(),
2358
                                'html_label_text' => esc_html__(
2359
                                    'Default Maximum Tickets Allowed Per Order:',
2360
                                    'event_espresso'
2361
                                )
2362
                                                     . EEH_Template::get_help_tab_link(
2363
                                                         'default_maximum_tickets_help_tab"'
2364
                                                     ),
2365
                                'html_help_text'  => esc_html__(
2366
                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2367
                                    'event_espresso'
2368
                                ),
2369
                            )
2370
                        ),
2371
                    )
2372
                ),
2373
            )
2374
        );
2375
    }
2376
2377
2378
    /**
2379
     * _update_default_event_settings
2380
     *
2381
     * @access protected
2382
     * @return void
2383
     * @throws EE_Error
2384
     */
2385
    protected function _update_default_event_settings()
2386
    {
2387
        $registration_config = EE_Registry::instance()->CFG->registration;
2388
        $form = $this->_default_event_settings_form();
2389
        if ($form->was_submitted()) {
2390
            $form->receive_form_submission();
2391
            if ($form->is_valid()) {
2392
                $valid_data = $form->valid_data();
2393
                if (isset($valid_data['default_reg_status'])) {
2394
                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2395
                }
2396
                if (isset($valid_data['default_max_tickets'])) {
2397
                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2398
                }
2399
                // update because data was valid!
2400
                EE_Registry::instance()->CFG->update_espresso_config();
2401
                EE_Error::overwrite_success();
2402
                EE_Error::add_success(
2403
                    __('Default Event Settings were updated', 'event_espresso')
2404
                );
2405
            }
2406
        }
2407
        $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true);
2408
    }
2409
2410
2411
    /*************        Templates        *************/
2412 View Code Duplication
    protected function _template_settings()
2413
    {
2414
        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2415
        $this->_template_args['preview_img'] = '<img src="'
2416
                                               . EVENTS_ASSETS_URL
2417
                                               . '/images/'
2418
                                               . 'caffeinated_template_features.jpg" alt="'
2419
                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2420
                                               . '" />';
2421
        $this->_template_args['preview_text'] = '<strong>'
2422
                                                . esc_html__(
2423
                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2424
                                                    'event_espresso'
2425
                                                ) . '</strong>';
2426
        $this->display_admin_caf_preview_page('template_settings_tab');
2427
    }
2428
2429
2430
    /** Event Category Stuff **/
2431
    /**
2432
     * set the _category property with the category object for the loaded page.
2433
     *
2434
     * @access private
2435
     * @return void
2436
     */
2437
    private function _set_category_object()
2438
    {
2439
        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2440
            return;
2441
        } //already have the category object so get out.
2442
        // set default category object
2443
        $this->_set_empty_category_object();
2444
        // only set if we've got an id
2445
        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2446
            return;
2447
        }
2448
        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2449
        $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2450
        if (! empty($term)) {
2451
            $this->_category->category_name = $term->name;
2452
            $this->_category->category_identifier = $term->slug;
2453
            $this->_category->category_desc = $term->description;
2454
            $this->_category->id = $term->term_id;
2455
            $this->_category->parent = $term->parent;
2456
        }
2457
    }
2458
2459
2460
    /**
2461
     * Clears out category properties.
2462
     */
2463
    private function _set_empty_category_object()
2464
    {
2465
        $this->_category = new stdClass();
2466
        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2467
        $this->_category->id = $this->_category->parent = 0;
2468
    }
2469
2470
2471
    /**
2472
     * @throws EE_Error
2473
     */
2474 View Code Duplication
    protected function _category_list_table()
2475
    {
2476
        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2477
        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2478
        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2479
            'add_category',
2480
            'add_category',
2481
            array(),
2482
            'add-new-h2'
2483
        );
2484
        $this->display_admin_list_table_page_with_sidebar();
2485
    }
2486
2487
2488
    /**
2489
     * Output category details view.
2490
     */
2491 View Code Duplication
    protected function _category_details($view)
2492
    {
2493
        // load formatter helper
2494
        // load field generator helper
2495
        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2496
        $this->_set_add_edit_form_tags($route);
2497
        $this->_set_category_object();
2498
        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2499
        $delete_action = 'delete_category';
2500
        // custom redirect
2501
        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2502
            array('action' => 'category_list'),
2503
            $this->_admin_base_url
2504
        );
2505
        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2506
        // take care of contents
2507
        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2508
        $this->display_admin_page_with_sidebar();
2509
    }
2510
2511
2512
    /**
2513
     * Output category details content.
2514
     */
2515 View Code Duplication
    protected function _category_details_content()
2516
    {
2517
        $editor_args['category_desc'] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$editor_args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $editor_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...
2518
            'type'          => 'wp_editor',
2519
            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2520
            'class'         => 'my_editor_custom',
2521
            'wpeditor_args' => array('media_buttons' => false),
2522
        );
2523
        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2524
        $all_terms = get_terms(
2525
            array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY),
2526
            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2527
        );
2528
        // setup category select for term parents.
2529
        $category_select_values[] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$category_select_values was never initialized. Although not strictly required by PHP, it is generally a good practice to add $category_select_values = 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...
2530
            'text' => esc_html__('No Parent', 'event_espresso'),
2531
            'id'   => 0,
2532
        );
2533
        foreach ($all_terms as $term) {
2534
            $category_select_values[] = array(
2535
                'text' => $term->name,
2536
                'id'   => $term->term_id,
2537
            );
2538
        }
2539
        $category_select = EEH_Form_Fields::select_input(
2540
            'category_parent',
2541
            $category_select_values,
2542
            $this->_category->parent
2543
        );
2544
        $template_args = array(
2545
            'category'                 => $this->_category,
2546
            'category_select'          => $category_select,
2547
            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2548
            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2549
            'disable'                  => '',
2550
            'disabled_message'         => false,
2551
        );
2552
        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2553
        return EEH_Template::display_template($template, $template_args, true);
2554
    }
2555
2556
2557
    /**
2558
     * Handles deleting categories.
2559
     */
2560 View Code Duplication
    protected function _delete_categories()
2561
    {
2562
        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2563
            : (array) $this->_req_data['category_id'];
2564
        foreach ($cat_ids as $cat_id) {
2565
            $this->_delete_category($cat_id);
2566
        }
2567
        // doesn't matter what page we're coming from... we're going to the same place after delete.
2568
        $query_args = array(
2569
            'action' => 'category_list',
2570
        );
2571
        $this->_redirect_after_action(0, '', '', $query_args);
2572
    }
2573
2574
2575
    /**
2576
     * Handles deleting specific category.
2577
     *
2578
     * @param int $cat_id
2579
     */
2580
    protected function _delete_category($cat_id)
2581
    {
2582
        $cat_id = absint($cat_id);
2583
        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2584
    }
2585
2586
2587
    /**
2588
     * Handles triggering the update or insertion of a new category.
2589
     *
2590
     * @param bool $new_category true means we're triggering the insert of a new category.
2591
     */
2592 View Code Duplication
    protected function _insert_or_update_category($new_category)
2593
    {
2594
        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2595
        $success = 0; // we already have a success message so lets not send another.
2596
        if ($cat_id) {
2597
            $query_args = array(
2598
                'action'     => 'edit_category',
2599
                'EVT_CAT_ID' => $cat_id,
2600
            );
2601
        } else {
2602
            $query_args = array('action' => 'add_category');
2603
        }
2604
        $this->_redirect_after_action($success, '', '', $query_args, true);
2605
    }
2606
2607
2608
    /**
2609
     * Inserts or updates category
2610
     *
2611
     * @param bool $update (true indicates we're updating a category).
2612
     * @return bool|mixed|string
2613
     */
2614
    private function _insert_category($update = false)
2615
    {
2616
        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2617
        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2618
        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2619
        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2620
        if (empty($category_name)) {
2621
            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2622
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2623
            return false;
2624
        }
2625
        $term_args = array(
2626
            'name'        => $category_name,
2627
            'description' => $category_desc,
2628
            'parent'      => $category_parent,
2629
        );
2630
        // was the category_identifier input disabled?
2631
        if (isset($this->_req_data['category_identifier'])) {
2632
            $term_args['slug'] = $this->_req_data['category_identifier'];
2633
        }
2634
        $insert_ids = $update
2635
            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2636
            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2637
        if (! is_array($insert_ids)) {
2638
            $msg = esc_html__(
2639
                'An error occurred and the category has not been saved to the database.',
2640
                'event_espresso'
2641
            );
2642
            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2643
        } else {
2644
            $cat_id = $insert_ids['term_id'];
2645
            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2646
            EE_Error::add_success($msg);
2647
        }
2648
        return $cat_id;
2649
    }
2650
2651
2652
    /**
2653
     * Gets categories or count of categories matching the arguments in the request.
2654
     *
2655
     * @param int  $per_page
2656
     * @param int  $current_page
2657
     * @param bool $count
2658
     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2659
     */
2660 View Code Duplication
    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2661
    {
2662
        // testing term stuff
2663
        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2664
        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2665
        $limit = ($current_page - 1) * $per_page;
2666
        $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2667
        if (isset($this->_req_data['s'])) {
2668
            $sstr = '%' . $this->_req_data['s'] . '%';
2669
            $where['OR'] = array(
2670
                'Term.name'   => array('LIKE', $sstr),
2671
                'description' => array('LIKE', $sstr),
2672
            );
2673
        }
2674
        $query_params = array(
2675
            $where,
2676
            'order_by'   => array($orderby => $order),
2677
            'limit'      => $limit . ',' . $per_page,
2678
            'force_join' => array('Term'),
2679
        );
2680
        $categories = $count
2681
            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2682
            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2683
        return $categories;
2684
    }
2685
2686
    /* end category stuff */
2687
    /**************/
2688
2689
2690
    /**
2691
     * Callback for the `ee_save_timezone_setting` ajax action.
2692
     *
2693
     * @throws EE_Error
2694
     */
2695
    public function save_timezonestring_setting()
2696
    {
2697
        $timezone_string = isset($this->_req_data['timezone_selected'])
2698
            ? $this->_req_data['timezone_selected']
2699
            : '';
2700
        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2701
            EE_Error::add_error(
2702
                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2703
                __FILE__,
2704
                __FUNCTION__,
2705
                __LINE__
2706
            );
2707
            $this->_template_args['error'] = true;
2708
            $this->_return_json();
2709
        }
2710
2711
        update_option('timezone_string', $timezone_string);
2712
        EE_Error::add_success(
2713
            esc_html__('Your timezone string was updated.', 'event_espresso')
2714
        );
2715
        $this->_template_args['success'] = true;
2716
        $this->_return_json(true, array('action' => 'create_new'));
2717
    }
2718
}
2719