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