Completed
Branch FET-3467-waitlists (4406f2)
by
unknown
46:31 queued 34:26
created
admin_pages/registrations/Registrations_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1247,7 +1247,7 @@
 block discarded – undo
1247 1247
     /**
1248 1248
      * Sets up the limit for the registrations query.
1249 1249
      *
1250
-     * @param $per_page
1250
+     * @param integer $per_page
1251 1251
      * @return array
1252 1252
      */
1253 1253
     protected function _get_limit($per_page)
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         // when adding a new registration...
70 70
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71 71
             EE_System::do_not_cache();
72
-            if (! isset($this->_req_data['processing_registration'])
72
+            if ( ! isset($this->_req_data['processing_registration'])
73 73
                  || absint($this->_req_data['processing_registration']) !== 1
74 74
             ) {
75 75
                 // and it's NOT the attendee information reg step
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
         //style
578 578
         wp_register_style(
579 579
             'espresso_reg',
580
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
580
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
581 581
             array('ee-admin-css'),
582 582
             EVENT_ESPRESSO_VERSION
583 583
         );
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
         //script
586 586
         wp_register_script(
587 587
             'espresso_reg',
588
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
588
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
589 589
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
590 590
             EVENT_ESPRESSO_VERSION,
591 591
             true
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
         wp_deregister_style('espresso_reg');
624 624
         wp_register_style(
625 625
             'espresso_att',
626
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
626
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
627 627
             array('ee-admin-css'),
628 628
             EVENT_ESPRESSO_VERSION
629 629
         );
@@ -635,7 +635,7 @@  discard block
 block discarded – undo
635 635
     {
636 636
         wp_register_script(
637 637
             'ee-spco-for-admin',
638
-            REG_ASSETS_URL . 'spco_for_admin.js',
638
+            REG_ASSETS_URL.'spco_for_admin.js',
639 639
             array('underscore', 'jquery'),
640 640
             EVENT_ESPRESSO_VERSION,
641 641
             true
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
769 769
                 ),
770 770
             );
771
-            $this->_views['trash']      = array(
771
+            $this->_views['trash'] = array(
772 772
                 'slug'        => 'trash',
773 773
                 'label'       => esc_html__('Trash', 'event_espresso'),
774 774
                 'count'       => 0,
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
         }
858 858
         $sc_items = array(
859 859
             'approved_status'   => array(
860
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
860
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
861 861
                 'desc'  => EEH_Template::pretty_status(
862 862
                     EEM_Registration::status_id_approved,
863 863
                     false,
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
                 ),
866 866
             ),
867 867
             'pending_status'    => array(
868
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
868
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
869 869
                 'desc'  => EEH_Template::pretty_status(
870 870
                     EEM_Registration::status_id_pending_payment,
871 871
                     false,
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
                 ),
874 874
             ),
875 875
             'wait_list'         => array(
876
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
876
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
877 877
                 'desc'  => EEH_Template::pretty_status(
878 878
                     EEM_Registration::status_id_wait_list,
879 879
                     false,
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
                 ),
882 882
             ),
883 883
             'incomplete_status' => array(
884
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
884
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
885 885
                 'desc'  => EEH_Template::pretty_status(
886 886
                     EEM_Registration::status_id_incomplete,
887 887
                     false,
@@ -889,7 +889,7 @@  discard block
 block discarded – undo
889 889
                 ),
890 890
             ),
891 891
             'not_approved'      => array(
892
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
892
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
893 893
                 'desc'  => EEH_Template::pretty_status(
894 894
                     EEM_Registration::status_id_not_approved,
895 895
                     false,
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
                 ),
898 898
             ),
899 899
             'declined_status'   => array(
900
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
900
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
901 901
                 'desc'  => EEH_Template::pretty_status(
902 902
                     EEM_Registration::status_id_declined,
903 903
                     false,
@@ -905,7 +905,7 @@  discard block
 block discarded – undo
905 905
                 ),
906 906
             ),
907 907
             'cancelled_status'  => array(
908
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
908
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
909 909
                 'desc'  => EEH_Template::pretty_status(
910 910
                     EEM_Registration::status_id_cancelled,
911 911
                     false,
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
                 'espresso_registrations_new_registration',
935 935
                 $EVT_ID
936 936
             )) {
937
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
937
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
938 938
                     'new_registration',
939 939
                     'add-registrant',
940 940
                     array('event_id' => $EVT_ID),
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
975 975
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
976 976
                 $this->_template_args['admin_page_header'] .= $datetime->name();
977
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
977
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
978 978
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
979 979
             }
980 980
         }
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
             'caps'                     => EEM_Registration::caps_read_admin,
1075 1075
             'default_where_conditions' => 'this_model_only',
1076 1076
         );
1077
-        if (! $count) {
1077
+        if ( ! $count) {
1078 1078
             $query_params = array_merge(
1079 1079
                 $query_params,
1080 1080
                 $this->_get_orderby_for_registrations_query(),
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
     protected function _add_event_id_to_where_conditions(array $request)
1096 1096
     {
1097 1097
         $where = array();
1098
-        if (! empty($request['event_id'])) {
1098
+        if ( ! empty($request['event_id'])) {
1099 1099
             $where['EVT_ID'] = absint($request['event_id']);
1100 1100
         }
1101 1101
         return $where;
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
     protected function _add_category_id_to_where_conditions(array $request)
1112 1112
     {
1113 1113
         $where = array();
1114
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1114
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1115 1115
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1116 1116
         }
1117 1117
         return $where;
@@ -1127,10 +1127,10 @@  discard block
 block discarded – undo
1127 1127
     protected function _add_datetime_id_to_where_conditions(array $request)
1128 1128
     {
1129 1129
         $where = array();
1130
-        if (! empty($request['datetime_id'])) {
1130
+        if ( ! empty($request['datetime_id'])) {
1131 1131
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1132 1132
         }
1133
-        if (! empty($request['DTT_ID'])) {
1133
+        if ( ! empty($request['DTT_ID'])) {
1134 1134
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1135 1135
         }
1136 1136
         return $where;
@@ -1156,7 +1156,7 @@  discard block
 block discarded – undo
1156 1156
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1157 1157
          * UNLESS viewing trashed registrations.
1158 1158
          */
1159
-        if (! empty($registration_status)) {
1159
+        if ( ! empty($registration_status)) {
1160 1160
             $where['STS_ID'] = $registration_status;
1161 1161
         } else {
1162 1162
             //make sure we exclude incomplete registrations, but only if not trashed.
@@ -1196,12 +1196,12 @@  discard block
 block discarded – undo
1196 1196
                 array(
1197 1197
                     EEM_Registration::instance()->convert_datetime_for_query(
1198 1198
                         'REG_date',
1199
-                        $now . ' 00:00:00',
1199
+                        $now.' 00:00:00',
1200 1200
                         'Y-m-d H:i:s'
1201 1201
                     ),
1202 1202
                     EEM_Registration::instance()->convert_datetime_for_query(
1203 1203
                         'REG_date',
1204
-                        $now . ' 23:59:59',
1204
+                        $now.' 23:59:59',
1205 1205
                         'Y-m-d H:i:s'
1206 1206
                     ),
1207 1207
                 ),
@@ -1214,12 +1214,12 @@  discard block
 block discarded – undo
1214 1214
                 array(
1215 1215
                     EEM_Registration::instance()->convert_datetime_for_query(
1216 1216
                         'REG_date',
1217
-                        $current_year_and_month . '-01 00:00:00',
1217
+                        $current_year_and_month.'-01 00:00:00',
1218 1218
                         'Y-m-d H:i:s'
1219 1219
                     ),
1220 1220
                     EEM_Registration::instance()->convert_datetime_for_query(
1221 1221
                         'REG_date',
1222
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1222
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1223 1223
                         'Y-m-d H:i:s'
1224 1224
                     ),
1225 1225
                 ),
@@ -1234,18 +1234,18 @@  discard block
 block discarded – undo
1234 1234
                 : '';
1235 1235
             //if there is not a month or year then we can't go further
1236 1236
             if ($month_requested && $year_requested) {
1237
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1237
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1238 1238
                 $where['REG_date'] = array(
1239 1239
                     'BETWEEN',
1240 1240
                     array(
1241 1241
                         EEM_Registration::instance()->convert_datetime_for_query(
1242 1242
                             'REG_date',
1243
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1243
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1244 1244
                             'Y-m-d H:i:s'
1245 1245
                         ),
1246 1246
                         EEM_Registration::instance()->convert_datetime_for_query(
1247 1247
                             'REG_date',
1248
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1248
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1249 1249
                             'Y-m-d H:i:s'
1250 1250
                         ),
1251 1251
                     ),
@@ -1265,8 +1265,8 @@  discard block
 block discarded – undo
1265 1265
     protected function _add_search_to_where_conditions(array $request)
1266 1266
     {
1267 1267
         $where = array();
1268
-        if (! empty($request['s'])) {
1269
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1268
+        if ( ! empty($request['s'])) {
1269
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1270 1270
             $where['OR*search_conditions'] = array(
1271 1271
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1272 1272
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1379,7 +1379,7 @@  discard block
 block discarded – undo
1379 1379
             : $per_page;
1380 1380
 
1381 1381
         //-1 means return all results so get out if that's set.
1382
-        if ((int)$per_page === -1) {
1382
+        if ((int) $per_page === -1) {
1383 1383
             return array();
1384 1384
         }
1385 1385
         $per_page = absint($per_page);
@@ -1432,7 +1432,7 @@  discard block
 block discarded – undo
1432 1432
                 ),
1433 1433
                 REG_ADMIN_URL
1434 1434
             );
1435
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1435
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1436 1436
                 array(
1437 1437
                     'action' => 'default',
1438 1438
                     'EVT_ID' => $event_id,
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
                 ),
1441 1441
                 admin_url('admin.php')
1442 1442
             );
1443
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1443
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1444 1444
                 array(
1445 1445
                     'page'   => 'espresso_events',
1446 1446
                     'action' => 'edit',
@@ -1449,12 +1449,12 @@  discard block
 block discarded – undo
1449 1449
                 admin_url('admin.php')
1450 1450
             );
1451 1451
             //next and previous links
1452
-            $next_reg                                      = $this->_registration->next(
1452
+            $next_reg = $this->_registration->next(
1453 1453
                 null,
1454 1454
                 array(),
1455 1455
                 'REG_ID'
1456 1456
             );
1457
-            $this->_template_args['next_registration']     = $next_reg
1457
+            $this->_template_args['next_registration'] = $next_reg
1458 1458
                 ? $this->_next_link(
1459 1459
                     EE_Admin_Page::add_query_args_and_nonce(
1460 1460
                         array(
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1467 1467
                 )
1468 1468
                 : '';
1469
-            $previous_reg                                  = $this->_registration->previous(
1469
+            $previous_reg = $this->_registration->previous(
1470 1470
                 null,
1471 1471
                 array(),
1472 1472
                 'REG_ID'
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
                 )
1485 1485
                 : '';
1486 1486
             // grab header
1487
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1487
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1488 1488
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1489 1489
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1490 1490
                 $template_path,
@@ -1599,7 +1599,7 @@  discard block
 block discarded – undo
1599 1599
                             EEH_HTML::strong(
1600 1600
                                 $this->_registration->pretty_status(),
1601 1601
                                 '',
1602
-                                'status-' . $this->_registration->status_ID(),
1602
+                                'status-'.$this->_registration->status_ID(),
1603 1603
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1604 1604
                             )
1605 1605
                         )
@@ -1669,9 +1669,9 @@  discard block
 block discarded – undo
1669 1669
     {
1670 1670
         if (isset($this->_req_data['reg_status_change_form'])) {
1671 1671
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1672
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1672
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] : array();
1673 1673
         } else {
1674
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1674
+            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array) $this->_req_data['_REG_ID'] : array();
1675 1675
         }
1676 1676
         $success = $this->_set_registration_status($REG_IDs, $status);
1677 1677
         //notify?
@@ -1703,7 +1703,7 @@  discard block
 block discarded – undo
1703 1703
     {
1704 1704
         $success = false;
1705 1705
         // typecast $REG_IDs
1706
-        $REG_IDs = (array)$REG_IDs;
1706
+        $REG_IDs = (array) $REG_IDs;
1707 1707
         if ( ! empty($REG_IDs)) {
1708 1708
             $success = true;
1709 1709
             // set default status if none is passed
@@ -1933,7 +1933,7 @@  discard block
 block discarded – undo
1933 1933
             $filtered_line_item_tree,
1934 1934
             array('EE_Registration' => $this->_registration)
1935 1935
         );
1936
-        $attendee                                = $this->_registration->attendee();
1936
+        $attendee = $this->_registration->attendee();
1937 1937
         if (EE_Registry::instance()->CAP->current_user_can(
1938 1938
             'ee_read_transaction',
1939 1939
             'espresso_transactions_view_transaction'
@@ -2012,7 +2012,7 @@  discard block
 block discarded – undo
2012 2012
                 'Payment method response',
2013 2013
                 'event_espresso'
2014 2014
             );
2015
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2015
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2016 2016
         }
2017 2017
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2018 2018
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2040,7 +2040,7 @@  discard block
 block discarded – undo
2040 2040
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2041 2041
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2042 2042
         $template_path                                                        =
2043
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2043
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2044 2044
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2045 2045
     }
2046 2046
 
@@ -2069,7 +2069,7 @@  discard block
 block discarded – undo
2069 2069
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2070 2070
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
2071 2071
             $template_path                                     =
2072
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2072
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2073 2073
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2074 2074
         }
2075 2075
     }
@@ -2086,7 +2086,7 @@  discard block
 block discarded – undo
2086 2086
     public function form_before_question_group($output)
2087 2087
     {
2088 2088
         EE_Error::doing_it_wrong(
2089
-            __CLASS__ . '::' . __FUNCTION__,
2089
+            __CLASS__.'::'.__FUNCTION__,
2090 2090
             esc_html__(
2091 2091
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2092 2092
                 'event_espresso'
@@ -2111,7 +2111,7 @@  discard block
 block discarded – undo
2111 2111
     public function form_after_question_group($output)
2112 2112
     {
2113 2113
         EE_Error::doing_it_wrong(
2114
-            __CLASS__ . '::' . __FUNCTION__,
2114
+            __CLASS__.'::'.__FUNCTION__,
2115 2115
             esc_html__(
2116 2116
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2117 2117
                 'event_espresso'
@@ -2149,7 +2149,7 @@  discard block
 block discarded – undo
2149 2149
     public function form_form_field_label_wrap($label)
2150 2150
     {
2151 2151
         EE_Error::doing_it_wrong(
2152
-            __CLASS__ . '::' . __FUNCTION__,
2152
+            __CLASS__.'::'.__FUNCTION__,
2153 2153
             esc_html__(
2154 2154
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2155 2155
                 'event_espresso'
@@ -2159,7 +2159,7 @@  discard block
 block discarded – undo
2159 2159
         return '
2160 2160
 			<tr>
2161 2161
 				<th>
2162
-					' . $label . '
2162
+					' . $label.'
2163 2163
 				</th>';
2164 2164
     }
2165 2165
 
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
     public function form_form_field_input__wrap($input)
2176 2176
     {
2177 2177
         EE_Error::doing_it_wrong(
2178
-            __CLASS__ . '::' . __FUNCTION__,
2178
+            __CLASS__.'::'.__FUNCTION__,
2179 2179
             esc_html__(
2180 2180
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2181 2181
                 'event_espresso'
@@ -2184,7 +2184,7 @@  discard block
 block discarded – undo
2184 2184
         );
2185 2185
         return '
2186 2186
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2187
-					' . $input . '
2187
+					' . $input.'
2188 2188
 				</td>
2189 2189
 			</tr>';
2190 2190
     }
@@ -2226,7 +2226,7 @@  discard block
 block discarded – undo
2226 2226
     protected function _get_reg_custom_questions_form($REG_ID)
2227 2227
     {
2228 2228
         if ( ! $this->_reg_custom_questions_form) {
2229
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2229
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2230 2230
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2231 2231
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2232 2232
             );
@@ -2259,7 +2259,7 @@  discard block
 block discarded – undo
2259 2259
         if ($form->is_valid()) {
2260 2260
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
2261 2261
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2262
-                    $where_conditions    = array(
2262
+                    $where_conditions = array(
2263 2263
                         'QST_ID' => $question_id,
2264 2264
                         'REG_ID' => $REG_ID,
2265 2265
                     );
@@ -2297,7 +2297,7 @@  discard block
 block discarded – undo
2297 2297
         $REG = EEM_Registration::instance();
2298 2298
         //get all other registrations on this transaction, and cache
2299 2299
         //the attendees for them so we don't have to run another query using force_join
2300
-        $registrations                           = $REG->get_all(array(
2300
+        $registrations = $REG->get_all(array(
2301 2301
             array(
2302 2302
                 'TXN_ID' => $this->_registration->transaction_ID(),
2303 2303
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2321,7 +2321,7 @@  discard block
 block discarded – undo
2321 2321
             $att_nmbr = 1;
2322 2322
             foreach ($registrations as $registration) {
2323 2323
                 /* @var $registration EE_Registration */
2324
-                $attendee                                                    = $registration->attendee()
2324
+                $attendee = $registration->attendee()
2325 2325
                     ? $registration->attendee()
2326 2326
                     : EEM_Attendee::instance()
2327 2327
                                   ->create_default_object();
@@ -2334,19 +2334,19 @@  discard block
 block discarded – undo
2334 2334
                     ', ',
2335 2335
                     $attendee->full_address_as_array()
2336 2336
                 );
2337
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2337
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2338 2338
                     array(
2339 2339
                         'action' => 'edit_attendee',
2340 2340
                         'post'   => $attendee->ID(),
2341 2341
                     ),
2342 2342
                     REG_ADMIN_URL
2343 2343
                 );
2344
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2344
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2345 2345
                 $att_nmbr++;
2346 2346
             }
2347 2347
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2348 2348
         }
2349
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2349
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2350 2350
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2351 2351
     }
2352 2352
 
@@ -2386,20 +2386,20 @@  discard block
 block discarded – undo
2386 2386
         $this->_template_args['phone']             = $attendee->phone();
2387 2387
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2388 2388
         //edit link
2389
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2389
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2390 2390
             'action' => 'edit_attendee',
2391 2391
             'post'   => $attendee->ID(),
2392 2392
         ), REG_ADMIN_URL);
2393 2393
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2394 2394
         //create link
2395
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2395
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2396 2396
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2397 2397
                 'action'  => 'duplicate_attendee',
2398 2398
                 '_REG_ID' => $this->_registration->ID(),
2399 2399
             ), REG_ADMIN_URL) : '';
2400 2400
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2401 2401
         $this->_template_args['att_check']    = $att_check;
2402
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2402
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2403 2403
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2404 2404
     }
2405 2405
 
@@ -2441,7 +2441,7 @@  discard block
 block discarded – undo
2441 2441
             /** @var EE_Registration $REG */
2442 2442
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2443 2443
             $payments = $REG->registration_payments();
2444
-            if (! empty($payments)) {
2444
+            if ( ! empty($payments)) {
2445 2445
                 $name = $REG->attendee() instanceof EE_Attendee
2446 2446
                     ? $REG->attendee()->full_name()
2447 2447
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2634,7 +2634,7 @@  discard block
 block discarded – undo
2634 2634
                 'action' => 'edit',
2635 2635
                 'post'   => $this->_reg_event->ID(),
2636 2636
             ), EVENTS_ADMIN_URL);
2637
-            $edit_event_lnk                     = '<a href="'
2637
+            $edit_event_lnk = '<a href="'
2638 2638
                                                   . $edit_event_url
2639 2639
                                                   . '" title="'
2640 2640
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2652,7 +2652,7 @@  discard block
 block discarded – undo
2652 2652
         }
2653 2653
         // grab header
2654 2654
         $template_path                              =
2655
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2655
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2656 2656
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2657 2657
             $this->_template_args, true);
2658 2658
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2687,7 +2687,7 @@  discard block
 block discarded – undo
2687 2687
                 '</b>'
2688 2688
             );
2689 2689
             return '
2690
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2690
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2691 2691
 	<script >
2692 2692
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2693 2693
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2755,7 +2755,7 @@  discard block
 block discarded – undo
2755 2755
         //we come back to the process_registration_step route.
2756 2756
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2757 2757
         return EEH_Template::display_template(
2758
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2758
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2759 2759
             $template_args,
2760 2760
             true
2761 2761
         );
@@ -2774,7 +2774,7 @@  discard block
 block discarded – undo
2774 2774
         if (is_object($this->_reg_event)) {
2775 2775
             return true;
2776 2776
         }
2777
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2777
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2778 2778
         if ( ! $EVT_ID) {
2779 2779
             return false;
2780 2780
         }
@@ -2840,7 +2840,7 @@  discard block
 block discarded – undo
2840 2840
                 }
2841 2841
                 break;
2842 2842
             case 'questions' :
2843
-                if (! isset(
2843
+                if ( ! isset(
2844 2844
                     $this->_req_data['txn_reg_status_change'],
2845 2845
                     $this->_req_data['txn_reg_status_change']['send_notifications'])
2846 2846
                 ) {
@@ -2954,7 +2954,7 @@  discard block
 block discarded – undo
2954 2954
     public function get_attendees($per_page, $count = false, $trash = false)
2955 2955
     {
2956 2956
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2957
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2957
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
2958 2958
         $ATT_MDL                    = EEM_Attendee::instance();
2959 2959
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2960 2960
         switch ($this->_req_data['orderby']) {
@@ -2991,7 +2991,7 @@  discard block
 block discarded – undo
2991 2991
             : $per_page;
2992 2992
         $_where       = array();
2993 2993
         if ( ! empty($this->_req_data['s'])) {
2994
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2994
+            $sstr         = '%'.$this->_req_data['s'].'%';
2995 2995
             $_where['OR'] = array(
2996 2996
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2997 2997
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3067,9 +3067,9 @@  discard block
 block discarded – undo
3067 3067
      *                                                     the query parameters from the request
3068 3068
      * @return void ends the request with a redirect or download
3069 3069
      */
3070
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3070
+    public function _registrations_report_base($method_name_for_getting_query_params)
3071 3071
     {
3072
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3072
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3073 3073
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3074 3074
                 array(
3075 3075
                     'page'        => 'espresso_batch',
@@ -3078,7 +3078,7 @@  discard block
 block discarded – undo
3078 3078
                     'filters'     => urlencode(
3079 3079
                         serialize(
3080 3080
                             call_user_func(
3081
-                                array( $this, $method_name_for_getting_query_params ),
3081
+                                array($this, $method_name_for_getting_query_params),
3082 3082
                                 EEH_Array::is_set(
3083 3083
                                     $this->_req_data,
3084 3084
                                     'filters',
@@ -3098,8 +3098,8 @@  discard block
 block discarded – undo
3098 3098
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3099 3099
             );
3100 3100
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3101
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3102
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3101
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3102
+                require_once(EE_CLASSES.'EE_Export.class.php');
3103 3103
                 $EE_Export = EE_Export::instance($this->_req_data);
3104 3104
                 $EE_Export->export();
3105 3105
             }
@@ -3120,8 +3120,8 @@  discard block
 block discarded – undo
3120 3120
 
3121 3121
     public function _contact_list_export()
3122 3122
     {
3123
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3124
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3123
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3124
+            require_once(EE_CLASSES.'EE_Export.class.php');
3125 3125
             $EE_Export = EE_Export::instance($this->_req_data);
3126 3126
             $EE_Export->export_attendees();
3127 3127
         }
@@ -3138,8 +3138,8 @@  discard block
 block discarded – undo
3138 3138
                 'return_url'  => urlencode($this->_req_data['return_url']),
3139 3139
             )));
3140 3140
         } else {
3141
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3142
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3141
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3142
+                require_once(EE_CLASSES.'EE_Export.class.php');
3143 3143
                 $EE_Export = EE_Export::instance($this->_req_data);
3144 3144
                 $EE_Export->report_attendees();
3145 3145
             }
@@ -3205,7 +3205,7 @@  discard block
 block discarded – undo
3205 3205
             $updated_fields = array(
3206 3206
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3207 3207
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3208
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3208
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3209 3209
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3210 3210
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3211 3211
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3338,7 +3338,7 @@  discard block
 block discarded – undo
3338 3338
     {
3339 3339
         //get attendee object ( should already have it )
3340 3340
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3341
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3341
+        $template                         = REG_TEMPLATE_PATH.'attendee_contact_info_metabox_content.template.php';
3342 3342
         EEH_Template::display_template($template, $this->_template_args);
3343 3343
     }
3344 3344
 
@@ -3400,8 +3400,8 @@  discard block
 block discarded – undo
3400 3400
                 )
3401 3401
             )
3402 3402
         );
3403
-        $template                             =
3404
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3403
+        $template =
3404
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3405 3405
         EEH_Template::display_template($template, $this->_template_args);
3406 3406
     }
3407 3407
 
@@ -3420,7 +3420,7 @@  discard block
 block discarded – undo
3420 3420
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3421 3421
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3422 3422
         $template                              =
3423
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3423
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3424 3424
         EEH_Template::display_template($template, $this->_template_args);
3425 3425
     }
3426 3426
 
@@ -3435,7 +3435,7 @@  discard block
 block discarded – undo
3435 3435
     public function after_title_form_fields($post)
3436 3436
     {
3437 3437
         if ($post->post_type == 'espresso_attendees') {
3438
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3438
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3439 3439
             $template_args['attendee'] = $this->_cpt_model_obj;
3440 3440
             EEH_Template::display_template($template, $template_args);
3441 3441
         }
Please login to merge, or discard this patch.
Indentation   +3427 added lines, -3427 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -23,2113 +23,2113 @@  discard block
 block discarded – undo
23 23
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registration
28
-     */
29
-    private $_registration;
30
-
31
-    /**
32
-     * @var EE_Event
33
-     */
34
-    private $_reg_event;
35
-
36
-    /**
37
-     * @var EE_Session
38
-     */
39
-    private $_session;
40
-
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-
52
-    /**
53
-     *        constructor
54
-     *
55
-     * @Constructor
56
-     * @access public
57
-     * @param bool $routing
58
-     * @return Registrations_Admin_Page
59
-     */
60
-    public function __construct($routing = true)
61
-    {
62
-        parent::__construct($routing);
63
-        add_action('wp_loaded', array($this, 'wp_loaded'));
64
-    }
65
-
66
-
67
-    public function wp_loaded()
68
-    {
69
-        // when adding a new registration...
70
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
-            EE_System::do_not_cache();
72
-            if (! isset($this->_req_data['processing_registration'])
73
-                 || absint($this->_req_data['processing_registration']) !== 1
74
-            ) {
75
-                // and it's NOT the attendee information reg step
76
-                // force cookie expiration by setting time to last week
77
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
-                // and update the global
79
-                $_COOKIE['ee_registration_added'] = 0;
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-    protected function _init_page_props()
86
-    {
87
-        $this->page_slug        = REG_PG_SLUG;
88
-        $this->_admin_base_url  = REG_ADMIN_URL;
89
-        $this->_admin_base_path = REG_ADMIN;
90
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
91
-        $this->_cpt_routes      = array(
92
-            'add_new_attendee' => 'espresso_attendees',
93
-            'edit_attendee'    => 'espresso_attendees',
94
-            'insert_attendee'  => 'espresso_attendees',
95
-            'update_attendee'  => 'espresso_attendees',
96
-        );
97
-        $this->_cpt_model_names = array(
98
-            'add_new_attendee' => 'EEM_Attendee',
99
-            'edit_attendee'    => 'EEM_Attendee',
100
-        );
101
-        $this->_cpt_edit_routes = array(
102
-            'espresso_attendees' => 'edit_attendee',
103
-        );
104
-        $this->_pagenow_map     = array(
105
-            'add_new_attendee' => 'post-new.php',
106
-            'edit_attendee'    => 'post.php',
107
-            'trash'            => 'post.php',
108
-        );
109
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
-        //add filters so that the comment urls don't take users to a confusing 404 page
111
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
-    }
113
-
114
-
115
-    public function clear_comment_link($link, $comment, $args)
116
-    {
117
-        //gotta make sure this only happens on this route
118
-        $post_type = get_post_type($comment->comment_post_ID);
119
-        if ($post_type === 'espresso_attendees') {
120
-            return '#commentsdiv';
121
-        }
122
-        return $link;
123
-    }
124
-
125
-
126
-    protected function _ajax_hooks()
127
-    {
128
-        //todo: all hooks for registrations ajax goes in here
129
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
-    }
131
-
132
-
133
-    protected function _define_page_props()
134
-    {
135
-        $this->_admin_page_title = $this->page_label;
136
-        $this->_labels           = array(
137
-            'buttons'                      => array(
138
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
-            ),
147
-            'publishbox'                   => array(
148
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
-            ),
151
-            'hide_add_button_on_cpt_route' => array(
152
-                'edit_attendee' => true,
153
-            ),
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *        grab url requests and route them
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    public function _set_page_routes()
165
-    {
166
-        $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
-            ? $this->_req_data['_REG_ID'] : 0;
169
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
-            ? $this->_req_data['ATT_ID'] : 0;
171
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
172
-            ? $this->_req_data['post']
173
-            : $att_id;
174
-        $this->_page_routes = array(
175
-            'default'                            => array(
176
-                'func'       => '_registrations_overview_list_table',
177
-                'capability' => 'ee_read_registrations',
178
-            ),
179
-            'view_registration'                  => array(
180
-                'func'       => '_registration_details',
181
-                'capability' => 'ee_read_registration',
182
-                'obj_id'     => $reg_id,
183
-            ),
184
-            'edit_registration'                  => array(
185
-                'func'               => '_update_attendee_registration_form',
186
-                'noheader'           => true,
187
-                'headers_sent_route' => 'view_registration',
188
-                'capability'         => 'ee_edit_registration',
189
-                'obj_id'             => $reg_id,
190
-                '_REG_ID'            => $reg_id,
191
-            ),
192
-            'trash_registrations'                => array(
193
-                'func'       => '_trash_or_restore_registrations',
194
-                'args'       => array('trash' => true),
195
-                'noheader'   => true,
196
-                'capability' => 'ee_delete_registrations',
197
-            ),
198
-            'restore_registrations'              => array(
199
-                'func'       => '_trash_or_restore_registrations',
200
-                'args'       => array('trash' => false),
201
-                'noheader'   => true,
202
-                'capability' => 'ee_delete_registrations',
203
-            ),
204
-            'delete_registrations'               => array(
205
-                'func'       => '_delete_registrations',
206
-                'noheader'   => true,
207
-                'capability' => 'ee_delete_registrations',
208
-            ),
209
-            'new_registration'                   => array(
210
-                'func'       => 'new_registration',
211
-                'capability' => 'ee_edit_registrations',
212
-            ),
213
-            'process_reg_step'                   => array(
214
-                'func'       => 'process_reg_step',
215
-                'noheader'   => true,
216
-                'capability' => 'ee_edit_registrations',
217
-            ),
218
-            'redirect_to_txn'                    => array(
219
-                'func'       => 'redirect_to_txn',
220
-                'noheader'   => true,
221
-                'capability' => 'ee_edit_registrations',
222
-            ),
223
-            'change_reg_status'                  => array(
224
-                'func'       => '_change_reg_status',
225
-                'noheader'   => true,
226
-                'capability' => 'ee_edit_registration',
227
-                'obj_id'     => $reg_id,
228
-            ),
229
-            'approve_registration'               => array(
230
-                'func'       => 'approve_registration',
231
-                'noheader'   => true,
232
-                'capability' => 'ee_edit_registration',
233
-                'obj_id'     => $reg_id,
234
-            ),
235
-            'approve_and_notify_registration'    => array(
236
-                'func'       => 'approve_registration',
237
-                'noheader'   => true,
238
-                'args'       => array(true),
239
-                'capability' => 'ee_edit_registration',
240
-                'obj_id'     => $reg_id,
241
-            ),
242
-            'decline_registration'               => array(
243
-                'func'       => 'decline_registration',
244
-                'noheader'   => true,
245
-                'capability' => 'ee_edit_registration',
246
-                'obj_id'     => $reg_id,
247
-            ),
248
-            'decline_and_notify_registration'    => array(
249
-                'func'       => 'decline_registration',
250
-                'noheader'   => true,
251
-                'args'       => array(true),
252
-                'capability' => 'ee_edit_registration',
253
-                'obj_id'     => $reg_id,
254
-            ),
255
-            'pending_registration'               => array(
256
-                'func'       => 'pending_registration',
257
-                'noheader'   => true,
258
-                'capability' => 'ee_edit_registration',
259
-                'obj_id'     => $reg_id,
260
-            ),
261
-            'pending_and_notify_registration'    => array(
262
-                'func'       => 'pending_registration',
263
-                'noheader'   => true,
264
-                'args'       => array(true),
265
-                'capability' => 'ee_edit_registration',
266
-                'obj_id'     => $reg_id,
267
-            ),
268
-            'no_approve_registration'            => array(
269
-                'func'       => 'not_approve_registration',
270
-                'noheader'   => true,
271
-                'capability' => 'ee_edit_registration',
272
-                'obj_id'     => $reg_id,
273
-            ),
274
-            'no_approve_and_notify_registration' => array(
275
-                'func'       => 'not_approve_registration',
276
-                'noheader'   => true,
277
-                'args'       => array(true),
278
-                'capability' => 'ee_edit_registration',
279
-                'obj_id'     => $reg_id,
280
-            ),
281
-            'cancel_registration'                => array(
282
-                'func'       => 'cancel_registration',
283
-                'noheader'   => true,
284
-                'capability' => 'ee_edit_registration',
285
-                'obj_id'     => $reg_id,
286
-            ),
287
-            'cancel_and_notify_registration'     => array(
288
-                'func'       => 'cancel_registration',
289
-                'noheader'   => true,
290
-                'args'       => array(true),
291
-                'capability' => 'ee_edit_registration',
292
-                'obj_id'     => $reg_id,
293
-            ),
294
-            'wait_list_registration' => array(
295
-                'func'       => 'wait_list_registration',
296
-                'noheader'   => true,
297
-                'capability' => 'ee_edit_registration',
298
-                'obj_id'     => $reg_id,
299
-            ),
300
-            'contact_list'                       => array(
301
-                'func'       => '_attendee_contact_list_table',
302
-                'capability' => 'ee_read_contacts',
303
-            ),
304
-            'add_new_attendee'                   => array(
305
-                'func' => '_create_new_cpt_item',
306
-                'args' => array(
307
-                    'new_attendee' => true,
308
-                    'capability'   => 'ee_edit_contacts',
309
-                ),
310
-            ),
311
-            'edit_attendee'                      => array(
312
-                'func'       => '_edit_cpt_item',
313
-                'capability' => 'ee_edit_contacts',
314
-                'obj_id'     => $att_id,
315
-            ),
316
-            'duplicate_attendee'                 => array(
317
-                'func'       => '_duplicate_attendee',
318
-                'noheader'   => true,
319
-                'capability' => 'ee_edit_contacts',
320
-                'obj_id'     => $att_id,
321
-            ),
322
-            'insert_attendee'                    => array(
323
-                'func'       => '_insert_or_update_attendee',
324
-                'args'       => array(
325
-                    'new_attendee' => true,
326
-                ),
327
-                'noheader'   => true,
328
-                'capability' => 'ee_edit_contacts',
329
-            ),
330
-            'update_attendee'                    => array(
331
-                'func'       => '_insert_or_update_attendee',
332
-                'args'       => array(
333
-                    'new_attendee' => false,
334
-                ),
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_contacts',
337
-                'obj_id'     => $att_id,
338
-            ),
339
-            'trash_attendee'                    => array(
340
-                'func'       => '_trash_or_restore_attendees',
341
-                'args'       => array(
342
-                    'trash' => true,
343
-                ),
344
-                'noheader'   => true,
345
-                'capability' => 'ee_delete_contacts',
346
-                'obj_id'     => $att_id,
347
-            ),
348
-            'restore_attendees'                  => array(
349
-                'func'       => '_trash_or_restore_attendees',
350
-                'args'       => array(
351
-                    'trash' => false,
352
-                ),
353
-                'noheader'   => true,
354
-                'capability' => 'ee_delete_contacts',
355
-                'obj_id'     => $att_id,
356
-            ),
357
-            'resend_registration'                => array(
358
-                'func'       => '_resend_registration',
359
-                'noheader'   => true,
360
-                'capability' => 'ee_send_message',
361
-            ),
362
-            'registrations_report'               => array(
363
-                'func'       => '_registrations_report',
364
-                'noheader'   => true,
365
-                'capability' => 'ee_read_registrations',
366
-            ),
367
-            'contact_list_export'                => array(
368
-                'func'       => '_contact_list_export',
369
-                'noheader'   => true,
370
-                'capability' => 'export',
371
-            ),
372
-            'contact_list_report'                => array(
373
-                'func'       => '_contact_list_report',
374
-                'noheader'   => true,
375
-                'capability' => 'ee_read_contacts',
376
-            ),
377
-        );
378
-    }
379
-
380
-
381
-    protected function _set_page_config()
382
-    {
383
-        $this->_page_config = array(
384
-            'default'           => array(
385
-                'nav'           => array(
386
-                    'label' => esc_html__('Overview', 'event_espresso'),
387
-                    'order' => 5,
388
-                ),
389
-                'help_tabs'     => array(
390
-                    'registrations_overview_help_tab'                       => array(
391
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
392
-                        'filename' => 'registrations_overview',
393
-                    ),
394
-                    'registrations_overview_table_column_headings_help_tab' => array(
395
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
396
-                        'filename' => 'registrations_overview_table_column_headings',
397
-                    ),
398
-                    'registrations_overview_filters_help_tab'               => array(
399
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
400
-                        'filename' => 'registrations_overview_filters',
401
-                    ),
402
-                    'registrations_overview_views_help_tab'                 => array(
403
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
404
-                        'filename' => 'registrations_overview_views',
405
-                    ),
406
-                    'registrations_regoverview_other_help_tab'              => array(
407
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
408
-                        'filename' => 'registrations_overview_other',
409
-                    ),
410
-                ),
411
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
412
-                'qtips'         => array('Registration_List_Table_Tips'),
413
-                'list_table'    => 'EE_Registrations_List_Table',
414
-                'require_nonce' => false,
415
-            ),
416
-            'view_registration' => array(
417
-                'nav'           => array(
418
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
419
-                    'order'      => 15,
420
-                    'url'        => isset($this->_req_data['_REG_ID'])
421
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
422
-                        : $this->_admin_base_url,
423
-                    'persistent' => false,
424
-                ),
425
-                'help_tabs'     => array(
426
-                    'registrations_details_help_tab'                    => array(
427
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
428
-                        'filename' => 'registrations_details',
429
-                    ),
430
-                    'registrations_details_table_help_tab'              => array(
431
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
432
-                        'filename' => 'registrations_details_table',
433
-                    ),
434
-                    'registrations_details_form_answers_help_tab'       => array(
435
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
436
-                        'filename' => 'registrations_details_form_answers',
437
-                    ),
438
-                    'registrations_details_registrant_details_help_tab' => array(
439
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
440
-                        'filename' => 'registrations_details_registrant_details',
441
-                    ),
442
-                ),
443
-                'help_tour'     => array('Registration_Details_Help_Tour'),
444
-                'metaboxes'     => array_merge(
445
-                    $this->_default_espresso_metaboxes,
446
-                    array('_registration_details_metaboxes')
447
-                ),
448
-                'require_nonce' => false,
449
-            ),
450
-            'new_registration'  => array(
451
-                'nav'           => array(
452
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
453
-                    'url'        => '#',
454
-                    'order'      => 15,
455
-                    'persistent' => false,
456
-                ),
457
-                'metaboxes'     => $this->_default_espresso_metaboxes,
458
-                'labels'        => array(
459
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
460
-                ),
461
-                'require_nonce' => false,
462
-            ),
463
-            'add_new_attendee'  => array(
464
-                'nav'           => array(
465
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
466
-                    'order'      => 15,
467
-                    'persistent' => false,
468
-                ),
469
-                'metaboxes'     => array_merge(
470
-                    $this->_default_espresso_metaboxes,
471
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
472
-                ),
473
-                'require_nonce' => false,
474
-            ),
475
-            'edit_attendee'     => array(
476
-                'nav'           => array(
477
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
478
-                    'order'      => 15,
479
-                    'persistent' => false,
480
-                    'url'        => isset($this->_req_data['ATT_ID'])
481
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
482
-                        : $this->_admin_base_url,
483
-                ),
484
-                'metaboxes'     => array('attendee_editor_metaboxes'),
485
-                'require_nonce' => false,
486
-            ),
487
-            'contact_list'      => array(
488
-                'nav'           => array(
489
-                    'label' => esc_html__('Contact List', 'event_espresso'),
490
-                    'order' => 20,
491
-                ),
492
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
493
-                'help_tabs'     => array(
494
-                    'registrations_contact_list_help_tab'                       => array(
495
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
496
-                        'filename' => 'registrations_contact_list',
497
-                    ),
498
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
499
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
500
-                        'filename' => 'registrations_contact_list_table_column_headings',
501
-                    ),
502
-                    'registrations_contact_list_views_help_tab'                 => array(
503
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
504
-                        'filename' => 'registrations_contact_list_views',
505
-                    ),
506
-                    'registrations_contact_list_other_help_tab'                 => array(
507
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
508
-                        'filename' => 'registrations_contact_list_other',
509
-                    ),
510
-                ),
511
-                'help_tour'     => array('Contact_List_Help_Tour'),
512
-                'metaboxes'     => array(),
513
-                'require_nonce' => false,
514
-            ),
515
-            //override default cpt routes
516
-            'create_new'        => '',
517
-            'edit'              => '',
518
-        );
519
-    }
520
-
521
-
522
-    /**
523
-     * The below methods aren't used by this class currently
524
-     */
525
-    protected function _add_screen_options()
526
-    {
527
-    }
528
-
529
-
530
-    protected function _add_feature_pointers()
531
-    {
532
-    }
533
-
534
-
535
-    public function admin_init()
536
-    {
537
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
538
-            'click "Update Registration Questions" to save your changes',
539
-            'event_espresso'
540
-        );
541
-    }
542
-
543
-
544
-    public function admin_notices()
545
-    {
546
-    }
547
-
548
-
549
-    public function admin_footer_scripts()
550
-    {
551
-    }
552
-
553
-
554
-    /**
555
-     *        get list of registration statuses
556
-     *
557
-     * @access private
558
-     * @return void
559
-     */
560
-    private function _get_registration_status_array()
561
-    {
562
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
563
-    }
564
-
565
-
566
-    protected function _add_screen_options_default()
567
-    {
568
-        $this->_per_page_screen_option();
569
-    }
570
-
571
-
572
-    protected function _add_screen_options_contact_list()
573
-    {
574
-        $page_title              = $this->_admin_page_title;
575
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
576
-        $this->_per_page_screen_option();
577
-        $this->_admin_page_title = $page_title;
578
-    }
579
-
580
-
581
-    public function load_scripts_styles()
582
-    {
583
-        //style
584
-        wp_register_style(
585
-            'espresso_reg',
586
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
587
-            array('ee-admin-css'),
588
-            EVENT_ESPRESSO_VERSION
589
-        );
590
-        wp_enqueue_style('espresso_reg');
591
-        //script
592
-        wp_register_script(
593
-            'espresso_reg',
594
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
595
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
596
-            EVENT_ESPRESSO_VERSION,
597
-            true
598
-        );
599
-        wp_enqueue_script('espresso_reg');
600
-    }
601
-
602
-
603
-    public function load_scripts_styles_edit_attendee()
604
-    {
605
-        //stuff to only show up on our attendee edit details page.
606
-        $attendee_details_translations = array(
607
-            'att_publish_text' => sprintf(
608
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
609
-                $this->_cpt_model_obj->get_datetime('ATT_created')
610
-            ),
611
-        );
612
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
613
-        wp_enqueue_script('jquery-validate');
614
-    }
615
-
616
-
617
-    public function load_scripts_styles_view_registration()
618
-    {
619
-        //styles
620
-        wp_enqueue_style('espresso-ui-theme');
621
-        //scripts
622
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
623
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
624
-    }
625
-
626
-
627
-    public function load_scripts_styles_contact_list()
628
-    {
629
-        wp_deregister_style('espresso_reg');
630
-        wp_register_style(
631
-            'espresso_att',
632
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
633
-            array('ee-admin-css'),
634
-            EVENT_ESPRESSO_VERSION
635
-        );
636
-        wp_enqueue_style('espresso_att');
637
-    }
638
-
639
-
640
-    public function load_scripts_styles_new_registration()
641
-    {
642
-        wp_register_script(
643
-            'ee-spco-for-admin',
644
-            REG_ASSETS_URL . 'spco_for_admin.js',
645
-            array('underscore', 'jquery'),
646
-            EVENT_ESPRESSO_VERSION,
647
-            true
648
-        );
649
-        wp_enqueue_script('ee-spco-for-admin');
650
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
651
-        EE_Form_Section_Proper::wp_enqueue_scripts();
652
-        EED_Ticket_Selector::load_tckt_slctr_assets();
653
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
654
-    }
655
-
656
-
657
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
658
-    {
659
-        add_filter('FHEE_load_EE_messages', '__return_true');
660
-    }
661
-
662
-
663
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
664
-    {
665
-        add_filter('FHEE_load_EE_messages', '__return_true');
666
-    }
667
-
668
-
669
-    protected function _set_list_table_views_default()
670
-    {
671
-        //for notification related bulk actions we need to make sure only active messengers have an option.
672
-        EED_Messages::set_autoloaders();
673
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
674
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
675
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
676
-        //key= bulk_action_slug, value= message type.
677
-        $match_array = array(
678
-            'approve_registration'    => 'registration',
679
-            'decline_registration'    => 'declined_registration',
680
-            'pending_registration'    => 'pending_approval',
681
-            'no_approve_registration' => 'not_approved_registration',
682
-            'cancel_registration'     => 'cancelled_registration',
683
-        );
684
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
685
-            'ee_send_message',
686
-            'batch_send_messages'
687
-        );
688
-        /** setup reg status bulk actions **/
689
-        $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
690
-        if ($can_send && in_array($match_array['approve_registration'], $active_mts, true)) {
691
-                $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
692
-                    'event_espresso');
693
-        }
694
-        $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
695
-        if ($can_send && in_array($match_array['decline_registration'], $active_mts, true)) {
696
-                $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
697
-                    'event_espresso');
698
-        }
699
-        $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
700
-        if ($can_send && in_array($match_array['pending_registration'], $active_mts, true)) {
701
-                $def_reg_status_actions['pending_and_notify_registration'] = __(
702
-                    'Set Registrations to Pending Payment and Notify',
703
-                    'event_espresso'
704
-                );
705
-        }
706
-        $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
707
-        if ($can_send && in_array($match_array['no_approve_registration'], $active_mts, true)) {
708
-                $def_reg_status_actions['no_approve_and_notify_registration'] = __(
709
-                    'Set Registrations to Not Approved and Notify',
710
-                    'event_espresso'
711
-                );
712
-        }
713
-        $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
714
-        if ($can_send && in_array($match_array['cancel_registration'], $active_mts, true)) {
715
-                $def_reg_status_actions['cancel_and_notify_registration'] = __(
716
-                    'Cancel Registrations and Notify',
717
-                    'event_espresso'
718
-                );
719
-        }
720
-        $def_reg_status_actions = apply_filters(
721
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
722
-            $def_reg_status_actions,
723
-            $active_mts
724
-        );
725
-
726
-        $this->_views = array(
727
-            'all'   => array(
728
-                'slug'        => 'all',
729
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
730
-                'count'       => 0,
731
-                'bulk_action' => array_merge($def_reg_status_actions, array(
732
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
733
-                )),
734
-            ),
735
-            'month' => array(
736
-                'slug'        => 'month',
737
-                'label'       => esc_html__('This Month', 'event_espresso'),
738
-                'count'       => 0,
739
-                'bulk_action' => array_merge($def_reg_status_actions, array(
740
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
741
-                )),
742
-            ),
743
-            'today' => array(
744
-                'slug'        => 'today',
745
-                'label'       => sprintf(
746
-                    esc_html__('Today - %s', 'event_espresso'),
747
-                    date('M d, Y', current_time('timestamp'))
748
-                ),
749
-                'count'       => 0,
750
-                'bulk_action' => array_merge($def_reg_status_actions, array(
751
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
752
-                )),
753
-            ),
754
-        );
755
-        if (EE_Registry::instance()->CAP->current_user_can(
756
-            'ee_delete_registrations',
757
-            'espresso_registrations_delete_registration'
758
-        )) {
759
-            $this->_views['incomplete'] = array(
760
-                'slug'        => 'incomplete',
761
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
762
-                'count'       => 0,
763
-                'bulk_action' => array(
764
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
765
-                ),
766
-            );
767
-            $this->_views['trash']      = array(
768
-                'slug'        => 'trash',
769
-                'label'       => esc_html__('Trash', 'event_espresso'),
770
-                'count'       => 0,
771
-                'bulk_action' => array(
772
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
773
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
774
-                ),
775
-            );
776
-        }
777
-    }
778
-
779
-
780
-    protected function _set_list_table_views_contact_list()
781
-    {
782
-        $this->_views = array(
783
-            'in_use' => array(
784
-                'slug'        => 'in_use',
785
-                'label'       => esc_html__('In Use', 'event_espresso'),
786
-                'count'       => 0,
787
-                'bulk_action' => array(
788
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
789
-                ),
790
-            ),
791
-        );
792
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
793
-            'espresso_registrations_trash_attendees')
794
-        ) {
795
-            $this->_views['trash'] = array(
796
-                'slug'        => 'trash',
797
-                'label'       => esc_html__('Trash', 'event_espresso'),
798
-                'count'       => 0,
799
-                'bulk_action' => array(
800
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
801
-                ),
802
-            );
803
-        }
804
-    }
805
-
806
-
807
-    protected function _registration_legend_items()
808
-    {
809
-        $fc_items = array(
810
-            'star-icon'        => array(
811
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
812
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
813
-            ),
814
-            'view_details'     => array(
815
-                'class' => 'dashicons dashicons-clipboard',
816
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
817
-            ),
818
-            'edit_attendee'    => array(
819
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
820
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
821
-            ),
822
-            'view_transaction' => array(
823
-                'class' => 'dashicons dashicons-cart',
824
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
825
-            ),
826
-            'view_invoice'     => array(
827
-                'class' => 'dashicons dashicons-media-spreadsheet',
828
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
829
-            ),
830
-        );
831
-        if (EE_Registry::instance()->CAP->current_user_can(
832
-            'ee_send_message',
833
-            'espresso_registrations_resend_registration'
834
-        )) {
835
-            $fc_items['resend_registration'] = array(
836
-                'class' => 'dashicons dashicons-email-alt',
837
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
838
-            );
839
-        } else {
840
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
841
-        }
842
-        if (EE_Registry::instance()->CAP->current_user_can(
843
-            'ee_read_global_messages',
844
-            'view_filtered_messages'
845
-        )) {
846
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
847
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
848
-                $fc_items['view_related_messages'] = array(
849
-                    'class' => $related_for_icon['css_class'],
850
-                    'desc'  => $related_for_icon['label'],
851
-                );
852
-            }
853
-        }
854
-        $sc_items = array(
855
-            'approved_status'   => array(
856
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
857
-                'desc'  => EEH_Template::pretty_status(
858
-                    EEM_Registration::status_id_approved,
859
-                    false,
860
-                    'sentence'
861
-                ),
862
-            ),
863
-            'pending_status'    => array(
864
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
865
-                'desc'  => EEH_Template::pretty_status(
866
-                    EEM_Registration::status_id_pending_payment,
867
-                    false,
868
-                    'sentence'
869
-                ),
870
-            ),
871
-            'wait_list'         => array(
872
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
873
-                'desc'  => EEH_Template::pretty_status(
874
-                    EEM_Registration::status_id_wait_list,
875
-                    false,
876
-                    'sentence'
877
-                ),
878
-            ),
879
-            'incomplete_status' => array(
880
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
881
-                'desc'  => EEH_Template::pretty_status(
882
-                    EEM_Registration::status_id_incomplete,
883
-                    false,
884
-                    'sentence'
885
-                ),
886
-            ),
887
-            'not_approved'      => array(
888
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
889
-                'desc'  => EEH_Template::pretty_status(
890
-                    EEM_Registration::status_id_not_approved,
891
-                    false,
892
-                    'sentence'
893
-                ),
894
-            ),
895
-            'declined_status'   => array(
896
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
897
-                'desc'  => EEH_Template::pretty_status(
898
-                    EEM_Registration::status_id_declined,
899
-                    false,
900
-                    'sentence'
901
-                ),
902
-            ),
903
-            'cancelled_status'  => array(
904
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
905
-                'desc'  => EEH_Template::pretty_status(
906
-                    EEM_Registration::status_id_cancelled,
907
-                    false,
908
-                    'sentence'
909
-                ),
910
-            ),
911
-        );
912
-        return array_merge($fc_items, $sc_items);
913
-    }
914
-
915
-
916
-
917
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
918
-    /**
919
-     * @throws \EE_Error
920
-     */
921
-    protected function _registrations_overview_list_table()
922
-    {
923
-        $this->_template_args['admin_page_header'] = '';
924
-        $EVT_ID                                    = ! empty($this->_req_data['event_id'])
925
-            ? absint($this->_req_data['event_id'])
926
-            : 0;
927
-        if ($EVT_ID) {
928
-            if (EE_Registry::instance()->CAP->current_user_can(
929
-                'ee_edit_registrations',
930
-                'espresso_registrations_new_registration',
931
-                $EVT_ID
932
-            )) {
933
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
934
-                    'new_registration',
935
-                    'add-registrant',
936
-                    array('event_id' => $EVT_ID),
937
-                    'add-new-h2'
938
-                );
939
-            }
940
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
941
-            if ($event instanceof EE_Event) {
942
-                $this->_template_args['admin_page_header'] = sprintf(
943
-                    esc_html__(
944
-                        '%s Viewing registrations for the event: %s%s',
945
-                        'event_espresso'
946
-                    ),
947
-                    '<h3 style="line-height:1.5em;">',
948
-                    '<br /><a href="'
949
-                        . EE_Admin_Page::add_query_args_and_nonce(
950
-                            array(
951
-                                'action' => 'edit',
952
-                                'post'   => $event->ID(),
953
-                            ),
954
-                            EVENTS_ADMIN_URL
955
-                        )
956
-                        . '">&nbsp;'
957
-                        . $event->get('EVT_name')
958
-                        . '&nbsp;</a>&nbsp;',
959
-                    '</h3>'
960
-                );
961
-            }
962
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
963
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
964
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
965
-                $this->_template_args['admin_page_header'] = substr(
966
-                    $this->_template_args['admin_page_header'],
967
-                    0,
968
-                    -5
969
-                );
970
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
971
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
972
-                $this->_template_args['admin_page_header'] .= $datetime->name();
973
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
974
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
975
-            }
976
-        }
977
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
978
-        $this->display_admin_list_table_page_with_no_sidebar();
979
-    }
980
-
981
-
982
-    /**
983
-     * This sets the _registration property for the registration details screen
984
-     *
985
-     * @access private
986
-     * @return bool
987
-     */
988
-    private function _set_registration_object()
989
-    {
990
-        //get out if we've already set the object
991
-        if (is_object($this->_registration)) {
992
-            return true;
993
-        }
994
-        $REG    = EEM_Registration::instance();
995
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
996
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
997
-            return true;
998
-        } else {
999
-            $error_msg = sprintf(
1000
-                esc_html__(
1001
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1002
-                    'event_espresso'
1003
-                ),
1004
-                $REG_ID
1005
-            );
1006
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1007
-            $this->_registration = null;
1008
-            return false;
1009
-        }
1010
-    }
1011
-
1012
-
1013
-    /**
1014
-     * Used to retrieve registrations for the list table.
1015
-     *
1016
-     * @param int  $per_page
1017
-     * @param bool $count
1018
-     * @param bool $this_month
1019
-     * @param bool $today
1020
-     * @return EE_Registration[]|int
1021
-     * @throws EE_Error
1022
-     */
1023
-    public function get_registrations(
1024
-        $per_page = 10,
1025
-        $count = false,
1026
-        $this_month = false,
1027
-        $today = false
1028
-    ) {
1029
-        if ($this_month) {
1030
-            $this->_req_data['status'] = 'month';
1031
-        }
1032
-        if ($today) {
1033
-            $this->_req_data['status'] = 'today';
1034
-        }
1035
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1036
-        /**
1037
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1038
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1039
-         * @see EEM_Base::get_all()
1040
-         */
1041
-        $query_params['group_by'] = '';
1042
-
1043
-        return $count
1044
-            ? EEM_Registration::instance()->count($query_params)
1045
-            /** @type EE_Registration[] */
1046
-            : EEM_Registration::instance()->get_all($query_params);
1047
-    }
1048
-
1049
-
1050
-
1051
-    /**
1052
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1053
-     * Note: this listens to values on the request for some of the query parameters.
1054
-     *
1055
-     * @param array $request
1056
-     * @param int    $per_page
1057
-     * @param bool   $count
1058
-     * @return array
1059
-     */
1060
-    protected function _get_registration_query_parameters(
1061
-        $request = array(),
1062
-        $per_page = 10,
1063
-        $count = false
1064
-    ) {
1065
-
1066
-        $query_params = array(
1067
-            0                          => $this->_get_where_conditions_for_registrations_query(
1068
-                $request
1069
-            ),
1070
-            'caps'                     => EEM_Registration::caps_read_admin,
1071
-            'default_where_conditions' => 'this_model_only',
1072
-        );
1073
-        if (! $count) {
1074
-            $query_params = array_merge(
1075
-                $query_params,
1076
-                $this->_get_orderby_for_registrations_query(),
1077
-                $this->_get_limit($per_page)
1078
-            );
1079
-        }
1080
-
1081
-        return $query_params;
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1087
-     *
1088
-     * @param array $request usually the same as $this->_req_data but not necessarily
1089
-     * @return array
1090
-     */
1091
-    protected function _add_event_id_to_where_conditions(array $request)
1092
-    {
1093
-        $where = array();
1094
-        if (! empty($request['event_id'])) {
1095
-            $where['EVT_ID'] = absint($request['event_id']);
1096
-        }
1097
-        return $where;
1098
-    }
1099
-
1100
-
1101
-    /**
1102
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1103
-     *
1104
-     * @param array $request usually the same as $this->_req_data but not necessarily
1105
-     * @return array
1106
-     */
1107
-    protected function _add_category_id_to_where_conditions(array $request)
1108
-    {
1109
-        $where = array();
1110
-        if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1111
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1112
-        }
1113
-        return $where;
1114
-    }
1115
-
1116
-
1117
-    /**
1118
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1119
-     *
1120
-     * @param array $request usually the same as $this->_req_data but not necessarily
1121
-     * @return array
1122
-     */
1123
-    protected function _add_datetime_id_to_where_conditions(array $request)
1124
-    {
1125
-        $where = array();
1126
-        if (! empty($request['datetime_id'])) {
1127
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1128
-        }
1129
-        if (! empty($request['DTT_ID'])) {
1130
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1131
-        }
1132
-        return $where;
1133
-    }
1134
-
1135
-
1136
-    /**
1137
-     * Adds the correct registration status to the where conditions for the registrations query.
1138
-     *
1139
-     * @param array $request usually the same as $this->_req_data but not necessarily
1140
-     * @return array
1141
-     */
1142
-    protected function _add_registration_status_to_where_conditions(array $request)
1143
-    {
1144
-        $where = array();
1145
-        $view = EEH_Array::is_set($request, 'status', '');
1146
-        $registration_status = ! empty($request['_reg_status'])
1147
-            ? sanitize_text_field($request['_reg_status'])
1148
-            : '';
1149
-
1150
-        /*
26
+	/**
27
+	 * @var EE_Registration
28
+	 */
29
+	private $_registration;
30
+
31
+	/**
32
+	 * @var EE_Event
33
+	 */
34
+	private $_reg_event;
35
+
36
+	/**
37
+	 * @var EE_Session
38
+	 */
39
+	private $_session;
40
+
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+
52
+	/**
53
+	 *        constructor
54
+	 *
55
+	 * @Constructor
56
+	 * @access public
57
+	 * @param bool $routing
58
+	 * @return Registrations_Admin_Page
59
+	 */
60
+	public function __construct($routing = true)
61
+	{
62
+		parent::__construct($routing);
63
+		add_action('wp_loaded', array($this, 'wp_loaded'));
64
+	}
65
+
66
+
67
+	public function wp_loaded()
68
+	{
69
+		// when adding a new registration...
70
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
+			EE_System::do_not_cache();
72
+			if (! isset($this->_req_data['processing_registration'])
73
+				 || absint($this->_req_data['processing_registration']) !== 1
74
+			) {
75
+				// and it's NOT the attendee information reg step
76
+				// force cookie expiration by setting time to last week
77
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
+				// and update the global
79
+				$_COOKIE['ee_registration_added'] = 0;
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+	protected function _init_page_props()
86
+	{
87
+		$this->page_slug        = REG_PG_SLUG;
88
+		$this->_admin_base_url  = REG_ADMIN_URL;
89
+		$this->_admin_base_path = REG_ADMIN;
90
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
91
+		$this->_cpt_routes      = array(
92
+			'add_new_attendee' => 'espresso_attendees',
93
+			'edit_attendee'    => 'espresso_attendees',
94
+			'insert_attendee'  => 'espresso_attendees',
95
+			'update_attendee'  => 'espresso_attendees',
96
+		);
97
+		$this->_cpt_model_names = array(
98
+			'add_new_attendee' => 'EEM_Attendee',
99
+			'edit_attendee'    => 'EEM_Attendee',
100
+		);
101
+		$this->_cpt_edit_routes = array(
102
+			'espresso_attendees' => 'edit_attendee',
103
+		);
104
+		$this->_pagenow_map     = array(
105
+			'add_new_attendee' => 'post-new.php',
106
+			'edit_attendee'    => 'post.php',
107
+			'trash'            => 'post.php',
108
+		);
109
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
+		//add filters so that the comment urls don't take users to a confusing 404 page
111
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
+	}
113
+
114
+
115
+	public function clear_comment_link($link, $comment, $args)
116
+	{
117
+		//gotta make sure this only happens on this route
118
+		$post_type = get_post_type($comment->comment_post_ID);
119
+		if ($post_type === 'espresso_attendees') {
120
+			return '#commentsdiv';
121
+		}
122
+		return $link;
123
+	}
124
+
125
+
126
+	protected function _ajax_hooks()
127
+	{
128
+		//todo: all hooks for registrations ajax goes in here
129
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
+	}
131
+
132
+
133
+	protected function _define_page_props()
134
+	{
135
+		$this->_admin_page_title = $this->page_label;
136
+		$this->_labels           = array(
137
+			'buttons'                      => array(
138
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
139
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
140
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
141
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
142
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
143
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
144
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
145
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
146
+			),
147
+			'publishbox'                   => array(
148
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
149
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
150
+			),
151
+			'hide_add_button_on_cpt_route' => array(
152
+				'edit_attendee' => true,
153
+			),
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *        grab url requests and route them
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	public function _set_page_routes()
165
+	{
166
+		$this->_get_registration_status_array();
167
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
+			? $this->_req_data['_REG_ID'] : 0;
169
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
+			? $this->_req_data['ATT_ID'] : 0;
171
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
172
+			? $this->_req_data['post']
173
+			: $att_id;
174
+		$this->_page_routes = array(
175
+			'default'                            => array(
176
+				'func'       => '_registrations_overview_list_table',
177
+				'capability' => 'ee_read_registrations',
178
+			),
179
+			'view_registration'                  => array(
180
+				'func'       => '_registration_details',
181
+				'capability' => 'ee_read_registration',
182
+				'obj_id'     => $reg_id,
183
+			),
184
+			'edit_registration'                  => array(
185
+				'func'               => '_update_attendee_registration_form',
186
+				'noheader'           => true,
187
+				'headers_sent_route' => 'view_registration',
188
+				'capability'         => 'ee_edit_registration',
189
+				'obj_id'             => $reg_id,
190
+				'_REG_ID'            => $reg_id,
191
+			),
192
+			'trash_registrations'                => array(
193
+				'func'       => '_trash_or_restore_registrations',
194
+				'args'       => array('trash' => true),
195
+				'noheader'   => true,
196
+				'capability' => 'ee_delete_registrations',
197
+			),
198
+			'restore_registrations'              => array(
199
+				'func'       => '_trash_or_restore_registrations',
200
+				'args'       => array('trash' => false),
201
+				'noheader'   => true,
202
+				'capability' => 'ee_delete_registrations',
203
+			),
204
+			'delete_registrations'               => array(
205
+				'func'       => '_delete_registrations',
206
+				'noheader'   => true,
207
+				'capability' => 'ee_delete_registrations',
208
+			),
209
+			'new_registration'                   => array(
210
+				'func'       => 'new_registration',
211
+				'capability' => 'ee_edit_registrations',
212
+			),
213
+			'process_reg_step'                   => array(
214
+				'func'       => 'process_reg_step',
215
+				'noheader'   => true,
216
+				'capability' => 'ee_edit_registrations',
217
+			),
218
+			'redirect_to_txn'                    => array(
219
+				'func'       => 'redirect_to_txn',
220
+				'noheader'   => true,
221
+				'capability' => 'ee_edit_registrations',
222
+			),
223
+			'change_reg_status'                  => array(
224
+				'func'       => '_change_reg_status',
225
+				'noheader'   => true,
226
+				'capability' => 'ee_edit_registration',
227
+				'obj_id'     => $reg_id,
228
+			),
229
+			'approve_registration'               => array(
230
+				'func'       => 'approve_registration',
231
+				'noheader'   => true,
232
+				'capability' => 'ee_edit_registration',
233
+				'obj_id'     => $reg_id,
234
+			),
235
+			'approve_and_notify_registration'    => array(
236
+				'func'       => 'approve_registration',
237
+				'noheader'   => true,
238
+				'args'       => array(true),
239
+				'capability' => 'ee_edit_registration',
240
+				'obj_id'     => $reg_id,
241
+			),
242
+			'decline_registration'               => array(
243
+				'func'       => 'decline_registration',
244
+				'noheader'   => true,
245
+				'capability' => 'ee_edit_registration',
246
+				'obj_id'     => $reg_id,
247
+			),
248
+			'decline_and_notify_registration'    => array(
249
+				'func'       => 'decline_registration',
250
+				'noheader'   => true,
251
+				'args'       => array(true),
252
+				'capability' => 'ee_edit_registration',
253
+				'obj_id'     => $reg_id,
254
+			),
255
+			'pending_registration'               => array(
256
+				'func'       => 'pending_registration',
257
+				'noheader'   => true,
258
+				'capability' => 'ee_edit_registration',
259
+				'obj_id'     => $reg_id,
260
+			),
261
+			'pending_and_notify_registration'    => array(
262
+				'func'       => 'pending_registration',
263
+				'noheader'   => true,
264
+				'args'       => array(true),
265
+				'capability' => 'ee_edit_registration',
266
+				'obj_id'     => $reg_id,
267
+			),
268
+			'no_approve_registration'            => array(
269
+				'func'       => 'not_approve_registration',
270
+				'noheader'   => true,
271
+				'capability' => 'ee_edit_registration',
272
+				'obj_id'     => $reg_id,
273
+			),
274
+			'no_approve_and_notify_registration' => array(
275
+				'func'       => 'not_approve_registration',
276
+				'noheader'   => true,
277
+				'args'       => array(true),
278
+				'capability' => 'ee_edit_registration',
279
+				'obj_id'     => $reg_id,
280
+			),
281
+			'cancel_registration'                => array(
282
+				'func'       => 'cancel_registration',
283
+				'noheader'   => true,
284
+				'capability' => 'ee_edit_registration',
285
+				'obj_id'     => $reg_id,
286
+			),
287
+			'cancel_and_notify_registration'     => array(
288
+				'func'       => 'cancel_registration',
289
+				'noheader'   => true,
290
+				'args'       => array(true),
291
+				'capability' => 'ee_edit_registration',
292
+				'obj_id'     => $reg_id,
293
+			),
294
+			'wait_list_registration' => array(
295
+				'func'       => 'wait_list_registration',
296
+				'noheader'   => true,
297
+				'capability' => 'ee_edit_registration',
298
+				'obj_id'     => $reg_id,
299
+			),
300
+			'contact_list'                       => array(
301
+				'func'       => '_attendee_contact_list_table',
302
+				'capability' => 'ee_read_contacts',
303
+			),
304
+			'add_new_attendee'                   => array(
305
+				'func' => '_create_new_cpt_item',
306
+				'args' => array(
307
+					'new_attendee' => true,
308
+					'capability'   => 'ee_edit_contacts',
309
+				),
310
+			),
311
+			'edit_attendee'                      => array(
312
+				'func'       => '_edit_cpt_item',
313
+				'capability' => 'ee_edit_contacts',
314
+				'obj_id'     => $att_id,
315
+			),
316
+			'duplicate_attendee'                 => array(
317
+				'func'       => '_duplicate_attendee',
318
+				'noheader'   => true,
319
+				'capability' => 'ee_edit_contacts',
320
+				'obj_id'     => $att_id,
321
+			),
322
+			'insert_attendee'                    => array(
323
+				'func'       => '_insert_or_update_attendee',
324
+				'args'       => array(
325
+					'new_attendee' => true,
326
+				),
327
+				'noheader'   => true,
328
+				'capability' => 'ee_edit_contacts',
329
+			),
330
+			'update_attendee'                    => array(
331
+				'func'       => '_insert_or_update_attendee',
332
+				'args'       => array(
333
+					'new_attendee' => false,
334
+				),
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_contacts',
337
+				'obj_id'     => $att_id,
338
+			),
339
+			'trash_attendee'                    => array(
340
+				'func'       => '_trash_or_restore_attendees',
341
+				'args'       => array(
342
+					'trash' => true,
343
+				),
344
+				'noheader'   => true,
345
+				'capability' => 'ee_delete_contacts',
346
+				'obj_id'     => $att_id,
347
+			),
348
+			'restore_attendees'                  => array(
349
+				'func'       => '_trash_or_restore_attendees',
350
+				'args'       => array(
351
+					'trash' => false,
352
+				),
353
+				'noheader'   => true,
354
+				'capability' => 'ee_delete_contacts',
355
+				'obj_id'     => $att_id,
356
+			),
357
+			'resend_registration'                => array(
358
+				'func'       => '_resend_registration',
359
+				'noheader'   => true,
360
+				'capability' => 'ee_send_message',
361
+			),
362
+			'registrations_report'               => array(
363
+				'func'       => '_registrations_report',
364
+				'noheader'   => true,
365
+				'capability' => 'ee_read_registrations',
366
+			),
367
+			'contact_list_export'                => array(
368
+				'func'       => '_contact_list_export',
369
+				'noheader'   => true,
370
+				'capability' => 'export',
371
+			),
372
+			'contact_list_report'                => array(
373
+				'func'       => '_contact_list_report',
374
+				'noheader'   => true,
375
+				'capability' => 'ee_read_contacts',
376
+			),
377
+		);
378
+	}
379
+
380
+
381
+	protected function _set_page_config()
382
+	{
383
+		$this->_page_config = array(
384
+			'default'           => array(
385
+				'nav'           => array(
386
+					'label' => esc_html__('Overview', 'event_espresso'),
387
+					'order' => 5,
388
+				),
389
+				'help_tabs'     => array(
390
+					'registrations_overview_help_tab'                       => array(
391
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
392
+						'filename' => 'registrations_overview',
393
+					),
394
+					'registrations_overview_table_column_headings_help_tab' => array(
395
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
396
+						'filename' => 'registrations_overview_table_column_headings',
397
+					),
398
+					'registrations_overview_filters_help_tab'               => array(
399
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
400
+						'filename' => 'registrations_overview_filters',
401
+					),
402
+					'registrations_overview_views_help_tab'                 => array(
403
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
404
+						'filename' => 'registrations_overview_views',
405
+					),
406
+					'registrations_regoverview_other_help_tab'              => array(
407
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
408
+						'filename' => 'registrations_overview_other',
409
+					),
410
+				),
411
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
412
+				'qtips'         => array('Registration_List_Table_Tips'),
413
+				'list_table'    => 'EE_Registrations_List_Table',
414
+				'require_nonce' => false,
415
+			),
416
+			'view_registration' => array(
417
+				'nav'           => array(
418
+					'label'      => esc_html__('REG Details', 'event_espresso'),
419
+					'order'      => 15,
420
+					'url'        => isset($this->_req_data['_REG_ID'])
421
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
422
+						: $this->_admin_base_url,
423
+					'persistent' => false,
424
+				),
425
+				'help_tabs'     => array(
426
+					'registrations_details_help_tab'                    => array(
427
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
428
+						'filename' => 'registrations_details',
429
+					),
430
+					'registrations_details_table_help_tab'              => array(
431
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
432
+						'filename' => 'registrations_details_table',
433
+					),
434
+					'registrations_details_form_answers_help_tab'       => array(
435
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
436
+						'filename' => 'registrations_details_form_answers',
437
+					),
438
+					'registrations_details_registrant_details_help_tab' => array(
439
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
440
+						'filename' => 'registrations_details_registrant_details',
441
+					),
442
+				),
443
+				'help_tour'     => array('Registration_Details_Help_Tour'),
444
+				'metaboxes'     => array_merge(
445
+					$this->_default_espresso_metaboxes,
446
+					array('_registration_details_metaboxes')
447
+				),
448
+				'require_nonce' => false,
449
+			),
450
+			'new_registration'  => array(
451
+				'nav'           => array(
452
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
453
+					'url'        => '#',
454
+					'order'      => 15,
455
+					'persistent' => false,
456
+				),
457
+				'metaboxes'     => $this->_default_espresso_metaboxes,
458
+				'labels'        => array(
459
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
460
+				),
461
+				'require_nonce' => false,
462
+			),
463
+			'add_new_attendee'  => array(
464
+				'nav'           => array(
465
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
466
+					'order'      => 15,
467
+					'persistent' => false,
468
+				),
469
+				'metaboxes'     => array_merge(
470
+					$this->_default_espresso_metaboxes,
471
+					array('_publish_post_box', 'attendee_editor_metaboxes')
472
+				),
473
+				'require_nonce' => false,
474
+			),
475
+			'edit_attendee'     => array(
476
+				'nav'           => array(
477
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
478
+					'order'      => 15,
479
+					'persistent' => false,
480
+					'url'        => isset($this->_req_data['ATT_ID'])
481
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
482
+						: $this->_admin_base_url,
483
+				),
484
+				'metaboxes'     => array('attendee_editor_metaboxes'),
485
+				'require_nonce' => false,
486
+			),
487
+			'contact_list'      => array(
488
+				'nav'           => array(
489
+					'label' => esc_html__('Contact List', 'event_espresso'),
490
+					'order' => 20,
491
+				),
492
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
493
+				'help_tabs'     => array(
494
+					'registrations_contact_list_help_tab'                       => array(
495
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
496
+						'filename' => 'registrations_contact_list',
497
+					),
498
+					'registrations_contact-list_table_column_headings_help_tab' => array(
499
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
500
+						'filename' => 'registrations_contact_list_table_column_headings',
501
+					),
502
+					'registrations_contact_list_views_help_tab'                 => array(
503
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
504
+						'filename' => 'registrations_contact_list_views',
505
+					),
506
+					'registrations_contact_list_other_help_tab'                 => array(
507
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
508
+						'filename' => 'registrations_contact_list_other',
509
+					),
510
+				),
511
+				'help_tour'     => array('Contact_List_Help_Tour'),
512
+				'metaboxes'     => array(),
513
+				'require_nonce' => false,
514
+			),
515
+			//override default cpt routes
516
+			'create_new'        => '',
517
+			'edit'              => '',
518
+		);
519
+	}
520
+
521
+
522
+	/**
523
+	 * The below methods aren't used by this class currently
524
+	 */
525
+	protected function _add_screen_options()
526
+	{
527
+	}
528
+
529
+
530
+	protected function _add_feature_pointers()
531
+	{
532
+	}
533
+
534
+
535
+	public function admin_init()
536
+	{
537
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
538
+			'click "Update Registration Questions" to save your changes',
539
+			'event_espresso'
540
+		);
541
+	}
542
+
543
+
544
+	public function admin_notices()
545
+	{
546
+	}
547
+
548
+
549
+	public function admin_footer_scripts()
550
+	{
551
+	}
552
+
553
+
554
+	/**
555
+	 *        get list of registration statuses
556
+	 *
557
+	 * @access private
558
+	 * @return void
559
+	 */
560
+	private function _get_registration_status_array()
561
+	{
562
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
563
+	}
564
+
565
+
566
+	protected function _add_screen_options_default()
567
+	{
568
+		$this->_per_page_screen_option();
569
+	}
570
+
571
+
572
+	protected function _add_screen_options_contact_list()
573
+	{
574
+		$page_title              = $this->_admin_page_title;
575
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
576
+		$this->_per_page_screen_option();
577
+		$this->_admin_page_title = $page_title;
578
+	}
579
+
580
+
581
+	public function load_scripts_styles()
582
+	{
583
+		//style
584
+		wp_register_style(
585
+			'espresso_reg',
586
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
587
+			array('ee-admin-css'),
588
+			EVENT_ESPRESSO_VERSION
589
+		);
590
+		wp_enqueue_style('espresso_reg');
591
+		//script
592
+		wp_register_script(
593
+			'espresso_reg',
594
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
595
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
596
+			EVENT_ESPRESSO_VERSION,
597
+			true
598
+		);
599
+		wp_enqueue_script('espresso_reg');
600
+	}
601
+
602
+
603
+	public function load_scripts_styles_edit_attendee()
604
+	{
605
+		//stuff to only show up on our attendee edit details page.
606
+		$attendee_details_translations = array(
607
+			'att_publish_text' => sprintf(
608
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
609
+				$this->_cpt_model_obj->get_datetime('ATT_created')
610
+			),
611
+		);
612
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
613
+		wp_enqueue_script('jquery-validate');
614
+	}
615
+
616
+
617
+	public function load_scripts_styles_view_registration()
618
+	{
619
+		//styles
620
+		wp_enqueue_style('espresso-ui-theme');
621
+		//scripts
622
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
623
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
624
+	}
625
+
626
+
627
+	public function load_scripts_styles_contact_list()
628
+	{
629
+		wp_deregister_style('espresso_reg');
630
+		wp_register_style(
631
+			'espresso_att',
632
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
633
+			array('ee-admin-css'),
634
+			EVENT_ESPRESSO_VERSION
635
+		);
636
+		wp_enqueue_style('espresso_att');
637
+	}
638
+
639
+
640
+	public function load_scripts_styles_new_registration()
641
+	{
642
+		wp_register_script(
643
+			'ee-spco-for-admin',
644
+			REG_ASSETS_URL . 'spco_for_admin.js',
645
+			array('underscore', 'jquery'),
646
+			EVENT_ESPRESSO_VERSION,
647
+			true
648
+		);
649
+		wp_enqueue_script('ee-spco-for-admin');
650
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
651
+		EE_Form_Section_Proper::wp_enqueue_scripts();
652
+		EED_Ticket_Selector::load_tckt_slctr_assets();
653
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
654
+	}
655
+
656
+
657
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
658
+	{
659
+		add_filter('FHEE_load_EE_messages', '__return_true');
660
+	}
661
+
662
+
663
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
664
+	{
665
+		add_filter('FHEE_load_EE_messages', '__return_true');
666
+	}
667
+
668
+
669
+	protected function _set_list_table_views_default()
670
+	{
671
+		//for notification related bulk actions we need to make sure only active messengers have an option.
672
+		EED_Messages::set_autoloaders();
673
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
674
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
675
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
676
+		//key= bulk_action_slug, value= message type.
677
+		$match_array = array(
678
+			'approve_registration'    => 'registration',
679
+			'decline_registration'    => 'declined_registration',
680
+			'pending_registration'    => 'pending_approval',
681
+			'no_approve_registration' => 'not_approved_registration',
682
+			'cancel_registration'     => 'cancelled_registration',
683
+		);
684
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
685
+			'ee_send_message',
686
+			'batch_send_messages'
687
+		);
688
+		/** setup reg status bulk actions **/
689
+		$def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
690
+		if ($can_send && in_array($match_array['approve_registration'], $active_mts, true)) {
691
+				$def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
692
+					'event_espresso');
693
+		}
694
+		$def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
695
+		if ($can_send && in_array($match_array['decline_registration'], $active_mts, true)) {
696
+				$def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
697
+					'event_espresso');
698
+		}
699
+		$def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
700
+		if ($can_send && in_array($match_array['pending_registration'], $active_mts, true)) {
701
+				$def_reg_status_actions['pending_and_notify_registration'] = __(
702
+					'Set Registrations to Pending Payment and Notify',
703
+					'event_espresso'
704
+				);
705
+		}
706
+		$def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
707
+		if ($can_send && in_array($match_array['no_approve_registration'], $active_mts, true)) {
708
+				$def_reg_status_actions['no_approve_and_notify_registration'] = __(
709
+					'Set Registrations to Not Approved and Notify',
710
+					'event_espresso'
711
+				);
712
+		}
713
+		$def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
714
+		if ($can_send && in_array($match_array['cancel_registration'], $active_mts, true)) {
715
+				$def_reg_status_actions['cancel_and_notify_registration'] = __(
716
+					'Cancel Registrations and Notify',
717
+					'event_espresso'
718
+				);
719
+		}
720
+		$def_reg_status_actions = apply_filters(
721
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
722
+			$def_reg_status_actions,
723
+			$active_mts
724
+		);
725
+
726
+		$this->_views = array(
727
+			'all'   => array(
728
+				'slug'        => 'all',
729
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
730
+				'count'       => 0,
731
+				'bulk_action' => array_merge($def_reg_status_actions, array(
732
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
733
+				)),
734
+			),
735
+			'month' => array(
736
+				'slug'        => 'month',
737
+				'label'       => esc_html__('This Month', 'event_espresso'),
738
+				'count'       => 0,
739
+				'bulk_action' => array_merge($def_reg_status_actions, array(
740
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
741
+				)),
742
+			),
743
+			'today' => array(
744
+				'slug'        => 'today',
745
+				'label'       => sprintf(
746
+					esc_html__('Today - %s', 'event_espresso'),
747
+					date('M d, Y', current_time('timestamp'))
748
+				),
749
+				'count'       => 0,
750
+				'bulk_action' => array_merge($def_reg_status_actions, array(
751
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
752
+				)),
753
+			),
754
+		);
755
+		if (EE_Registry::instance()->CAP->current_user_can(
756
+			'ee_delete_registrations',
757
+			'espresso_registrations_delete_registration'
758
+		)) {
759
+			$this->_views['incomplete'] = array(
760
+				'slug'        => 'incomplete',
761
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
762
+				'count'       => 0,
763
+				'bulk_action' => array(
764
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
765
+				),
766
+			);
767
+			$this->_views['trash']      = array(
768
+				'slug'        => 'trash',
769
+				'label'       => esc_html__('Trash', 'event_espresso'),
770
+				'count'       => 0,
771
+				'bulk_action' => array(
772
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
773
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
774
+				),
775
+			);
776
+		}
777
+	}
778
+
779
+
780
+	protected function _set_list_table_views_contact_list()
781
+	{
782
+		$this->_views = array(
783
+			'in_use' => array(
784
+				'slug'        => 'in_use',
785
+				'label'       => esc_html__('In Use', 'event_espresso'),
786
+				'count'       => 0,
787
+				'bulk_action' => array(
788
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
789
+				),
790
+			),
791
+		);
792
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
793
+			'espresso_registrations_trash_attendees')
794
+		) {
795
+			$this->_views['trash'] = array(
796
+				'slug'        => 'trash',
797
+				'label'       => esc_html__('Trash', 'event_espresso'),
798
+				'count'       => 0,
799
+				'bulk_action' => array(
800
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
801
+				),
802
+			);
803
+		}
804
+	}
805
+
806
+
807
+	protected function _registration_legend_items()
808
+	{
809
+		$fc_items = array(
810
+			'star-icon'        => array(
811
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
812
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
813
+			),
814
+			'view_details'     => array(
815
+				'class' => 'dashicons dashicons-clipboard',
816
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
817
+			),
818
+			'edit_attendee'    => array(
819
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
820
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
821
+			),
822
+			'view_transaction' => array(
823
+				'class' => 'dashicons dashicons-cart',
824
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
825
+			),
826
+			'view_invoice'     => array(
827
+				'class' => 'dashicons dashicons-media-spreadsheet',
828
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
829
+			),
830
+		);
831
+		if (EE_Registry::instance()->CAP->current_user_can(
832
+			'ee_send_message',
833
+			'espresso_registrations_resend_registration'
834
+		)) {
835
+			$fc_items['resend_registration'] = array(
836
+				'class' => 'dashicons dashicons-email-alt',
837
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
838
+			);
839
+		} else {
840
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
841
+		}
842
+		if (EE_Registry::instance()->CAP->current_user_can(
843
+			'ee_read_global_messages',
844
+			'view_filtered_messages'
845
+		)) {
846
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
847
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
848
+				$fc_items['view_related_messages'] = array(
849
+					'class' => $related_for_icon['css_class'],
850
+					'desc'  => $related_for_icon['label'],
851
+				);
852
+			}
853
+		}
854
+		$sc_items = array(
855
+			'approved_status'   => array(
856
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
857
+				'desc'  => EEH_Template::pretty_status(
858
+					EEM_Registration::status_id_approved,
859
+					false,
860
+					'sentence'
861
+				),
862
+			),
863
+			'pending_status'    => array(
864
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
865
+				'desc'  => EEH_Template::pretty_status(
866
+					EEM_Registration::status_id_pending_payment,
867
+					false,
868
+					'sentence'
869
+				),
870
+			),
871
+			'wait_list'         => array(
872
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
873
+				'desc'  => EEH_Template::pretty_status(
874
+					EEM_Registration::status_id_wait_list,
875
+					false,
876
+					'sentence'
877
+				),
878
+			),
879
+			'incomplete_status' => array(
880
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
881
+				'desc'  => EEH_Template::pretty_status(
882
+					EEM_Registration::status_id_incomplete,
883
+					false,
884
+					'sentence'
885
+				),
886
+			),
887
+			'not_approved'      => array(
888
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
889
+				'desc'  => EEH_Template::pretty_status(
890
+					EEM_Registration::status_id_not_approved,
891
+					false,
892
+					'sentence'
893
+				),
894
+			),
895
+			'declined_status'   => array(
896
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
897
+				'desc'  => EEH_Template::pretty_status(
898
+					EEM_Registration::status_id_declined,
899
+					false,
900
+					'sentence'
901
+				),
902
+			),
903
+			'cancelled_status'  => array(
904
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
905
+				'desc'  => EEH_Template::pretty_status(
906
+					EEM_Registration::status_id_cancelled,
907
+					false,
908
+					'sentence'
909
+				),
910
+			),
911
+		);
912
+		return array_merge($fc_items, $sc_items);
913
+	}
914
+
915
+
916
+
917
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
918
+	/**
919
+	 * @throws \EE_Error
920
+	 */
921
+	protected function _registrations_overview_list_table()
922
+	{
923
+		$this->_template_args['admin_page_header'] = '';
924
+		$EVT_ID                                    = ! empty($this->_req_data['event_id'])
925
+			? absint($this->_req_data['event_id'])
926
+			: 0;
927
+		if ($EVT_ID) {
928
+			if (EE_Registry::instance()->CAP->current_user_can(
929
+				'ee_edit_registrations',
930
+				'espresso_registrations_new_registration',
931
+				$EVT_ID
932
+			)) {
933
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
934
+					'new_registration',
935
+					'add-registrant',
936
+					array('event_id' => $EVT_ID),
937
+					'add-new-h2'
938
+				);
939
+			}
940
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
941
+			if ($event instanceof EE_Event) {
942
+				$this->_template_args['admin_page_header'] = sprintf(
943
+					esc_html__(
944
+						'%s Viewing registrations for the event: %s%s',
945
+						'event_espresso'
946
+					),
947
+					'<h3 style="line-height:1.5em;">',
948
+					'<br /><a href="'
949
+						. EE_Admin_Page::add_query_args_and_nonce(
950
+							array(
951
+								'action' => 'edit',
952
+								'post'   => $event->ID(),
953
+							),
954
+							EVENTS_ADMIN_URL
955
+						)
956
+						. '">&nbsp;'
957
+						. $event->get('EVT_name')
958
+						. '&nbsp;</a>&nbsp;',
959
+					'</h3>'
960
+				);
961
+			}
962
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
963
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
964
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
965
+				$this->_template_args['admin_page_header'] = substr(
966
+					$this->_template_args['admin_page_header'],
967
+					0,
968
+					-5
969
+				);
970
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
971
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
972
+				$this->_template_args['admin_page_header'] .= $datetime->name();
973
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
974
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
975
+			}
976
+		}
977
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
978
+		$this->display_admin_list_table_page_with_no_sidebar();
979
+	}
980
+
981
+
982
+	/**
983
+	 * This sets the _registration property for the registration details screen
984
+	 *
985
+	 * @access private
986
+	 * @return bool
987
+	 */
988
+	private function _set_registration_object()
989
+	{
990
+		//get out if we've already set the object
991
+		if (is_object($this->_registration)) {
992
+			return true;
993
+		}
994
+		$REG    = EEM_Registration::instance();
995
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
996
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
997
+			return true;
998
+		} else {
999
+			$error_msg = sprintf(
1000
+				esc_html__(
1001
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1002
+					'event_espresso'
1003
+				),
1004
+				$REG_ID
1005
+			);
1006
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1007
+			$this->_registration = null;
1008
+			return false;
1009
+		}
1010
+	}
1011
+
1012
+
1013
+	/**
1014
+	 * Used to retrieve registrations for the list table.
1015
+	 *
1016
+	 * @param int  $per_page
1017
+	 * @param bool $count
1018
+	 * @param bool $this_month
1019
+	 * @param bool $today
1020
+	 * @return EE_Registration[]|int
1021
+	 * @throws EE_Error
1022
+	 */
1023
+	public function get_registrations(
1024
+		$per_page = 10,
1025
+		$count = false,
1026
+		$this_month = false,
1027
+		$today = false
1028
+	) {
1029
+		if ($this_month) {
1030
+			$this->_req_data['status'] = 'month';
1031
+		}
1032
+		if ($today) {
1033
+			$this->_req_data['status'] = 'today';
1034
+		}
1035
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1036
+		/**
1037
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1038
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1039
+		 * @see EEM_Base::get_all()
1040
+		 */
1041
+		$query_params['group_by'] = '';
1042
+
1043
+		return $count
1044
+			? EEM_Registration::instance()->count($query_params)
1045
+			/** @type EE_Registration[] */
1046
+			: EEM_Registration::instance()->get_all($query_params);
1047
+	}
1048
+
1049
+
1050
+
1051
+	/**
1052
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1053
+	 * Note: this listens to values on the request for some of the query parameters.
1054
+	 *
1055
+	 * @param array $request
1056
+	 * @param int    $per_page
1057
+	 * @param bool   $count
1058
+	 * @return array
1059
+	 */
1060
+	protected function _get_registration_query_parameters(
1061
+		$request = array(),
1062
+		$per_page = 10,
1063
+		$count = false
1064
+	) {
1065
+
1066
+		$query_params = array(
1067
+			0                          => $this->_get_where_conditions_for_registrations_query(
1068
+				$request
1069
+			),
1070
+			'caps'                     => EEM_Registration::caps_read_admin,
1071
+			'default_where_conditions' => 'this_model_only',
1072
+		);
1073
+		if (! $count) {
1074
+			$query_params = array_merge(
1075
+				$query_params,
1076
+				$this->_get_orderby_for_registrations_query(),
1077
+				$this->_get_limit($per_page)
1078
+			);
1079
+		}
1080
+
1081
+		return $query_params;
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1087
+	 *
1088
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1089
+	 * @return array
1090
+	 */
1091
+	protected function _add_event_id_to_where_conditions(array $request)
1092
+	{
1093
+		$where = array();
1094
+		if (! empty($request['event_id'])) {
1095
+			$where['EVT_ID'] = absint($request['event_id']);
1096
+		}
1097
+		return $where;
1098
+	}
1099
+
1100
+
1101
+	/**
1102
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1103
+	 *
1104
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1105
+	 * @return array
1106
+	 */
1107
+	protected function _add_category_id_to_where_conditions(array $request)
1108
+	{
1109
+		$where = array();
1110
+		if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
1111
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1112
+		}
1113
+		return $where;
1114
+	}
1115
+
1116
+
1117
+	/**
1118
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1119
+	 *
1120
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1121
+	 * @return array
1122
+	 */
1123
+	protected function _add_datetime_id_to_where_conditions(array $request)
1124
+	{
1125
+		$where = array();
1126
+		if (! empty($request['datetime_id'])) {
1127
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1128
+		}
1129
+		if (! empty($request['DTT_ID'])) {
1130
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1131
+		}
1132
+		return $where;
1133
+	}
1134
+
1135
+
1136
+	/**
1137
+	 * Adds the correct registration status to the where conditions for the registrations query.
1138
+	 *
1139
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1140
+	 * @return array
1141
+	 */
1142
+	protected function _add_registration_status_to_where_conditions(array $request)
1143
+	{
1144
+		$where = array();
1145
+		$view = EEH_Array::is_set($request, 'status', '');
1146
+		$registration_status = ! empty($request['_reg_status'])
1147
+			? sanitize_text_field($request['_reg_status'])
1148
+			: '';
1149
+
1150
+		/*
1151 1151
          * If filtering by registration status, then we show registrations matching that status.
1152 1152
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1153 1153
          * UNLESS viewing trashed registrations.
1154 1154
          */
1155
-        if (! empty($registration_status)) {
1156
-            $where['STS_ID'] = $registration_status;
1157
-        } else {
1158
-            //make sure we exclude incomplete registrations, but only if not trashed.
1159
-            if ($view === 'trash') {
1160
-                $where['REG_deleted'] = true;
1161
-            } elseif ($view === 'incomplete') {
1162
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1163
-            } else {
1164
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1165
-            }
1166
-        }
1167
-        return $where;
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     * Adds any provided date restraints to the where conditions for the registrations query.
1173
-     *
1174
-     * @param array $request usually the same as $this->_req_data but not necessarily
1175
-     * @return array
1176
-     * @throws EE_Error
1177
-     */
1178
-    protected function _add_date_to_where_conditions(array $request)
1179
-    {
1180
-        $where = array();
1181
-        $view = EEH_Array::is_set($request, 'status', '');
1182
-        $month_range             = ! empty($request['month_range'])
1183
-            ? sanitize_text_field($request['month_range'])
1184
-            : '';
1185
-        $retrieve_for_today      = $view === 'today';
1186
-        $retrieve_for_this_month = $view === 'month';
1187
-
1188
-        if ($retrieve_for_today) {
1189
-            $now               = date('Y-m-d', current_time('timestamp'));
1190
-            $where['REG_date'] = array(
1191
-                'BETWEEN',
1192
-                array(
1193
-                    EEM_Registration::instance()->convert_datetime_for_query(
1194
-                        'REG_date',
1195
-                        $now . ' 00:00:00',
1196
-                        'Y-m-d H:i:s'
1197
-                    ),
1198
-                    EEM_Registration::instance()->convert_datetime_for_query(
1199
-                        'REG_date',
1200
-                        $now . ' 23:59:59',
1201
-                        'Y-m-d H:i:s'
1202
-                    ),
1203
-                ),
1204
-            );
1205
-        } elseif ($retrieve_for_this_month) {
1206
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1207
-            $days_this_month        = date('t', current_time('timestamp'));
1208
-            $where['REG_date']      = array(
1209
-                'BETWEEN',
1210
-                array(
1211
-                    EEM_Registration::instance()->convert_datetime_for_query(
1212
-                        'REG_date',
1213
-                        $current_year_and_month . '-01 00:00:00',
1214
-                        'Y-m-d H:i:s'
1215
-                    ),
1216
-                    EEM_Registration::instance()->convert_datetime_for_query(
1217
-                        'REG_date',
1218
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1219
-                        'Y-m-d H:i:s'
1220
-                    ),
1221
-                ),
1222
-            );
1223
-        } elseif ($month_range) {
1224
-            $pieces          = explode(' ', $month_range, 3);
1225
-            $month_requested = ! empty($pieces[0])
1226
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1227
-                : '';
1228
-            $year_requested  = ! empty($pieces[1])
1229
-                ? $pieces[1]
1230
-                : '';
1231
-            //if there is not a month or year then we can't go further
1232
-            if ($month_requested && $year_requested) {
1233
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1234
-                $where['REG_date'] = array(
1235
-                    'BETWEEN',
1236
-                    array(
1237
-                        EEM_Registration::instance()->convert_datetime_for_query(
1238
-                            'REG_date',
1239
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1240
-                            'Y-m-d H:i:s'
1241
-                        ),
1242
-                        EEM_Registration::instance()->convert_datetime_for_query(
1243
-                            'REG_date',
1244
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1245
-                            'Y-m-d H:i:s'
1246
-                        ),
1247
-                    ),
1248
-                );
1249
-            }
1250
-        }
1251
-        return $where;
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     * Adds any provided search restraints to the where conditions for the registrations query
1257
-     *
1258
-     * @param array $request usually the same as $this->_req_data but not necessarily
1259
-     * @return array
1260
-     */
1261
-    protected function _add_search_to_where_conditions(array $request)
1262
-    {
1263
-        $where = array();
1264
-        if (! empty($request['s'])) {
1265
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1266
-            $where['OR*search_conditions'] = array(
1267
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1268
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1269
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1270
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1271
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1272
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1273
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1274
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1275
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1276
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1277
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1278
-                'REG_final_price'                         => array('LIKE', $search_string),
1279
-                'REG_code'                                => array('LIKE', $search_string),
1280
-                'REG_count'                               => array('LIKE', $search_string),
1281
-                'REG_group_size'                          => array('LIKE', $search_string),
1282
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1283
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1284
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1285
-            );
1286
-        }
1287
-        return $where;
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * Sets up the where conditions for the registrations query.
1293
-     *
1294
-     * @param array $request
1295
-     * @return array
1296
-     * @throws EE_Error
1297
-     */
1298
-    protected function _get_where_conditions_for_registrations_query($request)
1299
-    {
1300
-        return apply_filters(
1301
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1302
-            array_merge(
1303
-                $this->_add_event_id_to_where_conditions($request),
1304
-                $this->_add_category_id_to_where_conditions($request),
1305
-                $this->_add_datetime_id_to_where_conditions($request),
1306
-                $this->_add_registration_status_to_where_conditions($request),
1307
-                $this->_add_date_to_where_conditions($request),
1308
-                $this->_add_search_to_where_conditions($request)
1309
-            ),
1310
-            $request
1311
-        );
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * Sets up the orderby for the registrations query.
1317
-     *
1318
-     * @return array
1319
-     */
1320
-    protected function _get_orderby_for_registrations_query()
1321
-    {
1322
-        $orderby_field = ! empty($this->_req_data['orderby'])
1323
-            ? sanitize_text_field($this->_req_data['orderby'])
1324
-            : '';
1325
-        switch ($orderby_field) {
1326
-            case '_REG_ID':
1327
-                $orderby_field = 'REG_ID';
1328
-                break;
1329
-            case '_Reg_status':
1330
-                $orderby_field = 'STS_ID';
1331
-                break;
1332
-            case 'ATT_fname':
1333
-                $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1334
-                break;
1335
-            case 'ATT_lname':
1336
-                $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1337
-                break;
1338
-            case 'event_name':
1339
-                $orderby_field = 'Event.EVT_name';
1340
-                break;
1341
-            case 'DTT_EVT_start':
1342
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1343
-                break;
1344
-            default: //'REG_date'
1345
-                $orderby_field = 'REG_date';
1346
-        }
1347
-
1348
-        //order
1349
-        $order = ! empty($this->_req_data['order'])
1350
-            ? sanitize_text_field($this->_req_data['order'])
1351
-            : 'DESC';
1352
-
1353
-        //mutate orderby_field
1354
-        $orderby_field = array_combine(
1355
-            (array) $orderby_field,
1356
-            array_fill(0, count($orderby_field), $order)
1357
-        );
1358
-        return array('order_by' => $orderby_field);
1359
-    }
1360
-
1361
-
1362
-    /**
1363
-     * Sets up the limit for the registrations query.
1364
-     *
1365
-     * @param $per_page
1366
-     * @return array
1367
-     */
1368
-    protected function _get_limit($per_page)
1369
-    {
1370
-        $current_page = ! empty($this->_req_data['paged'])
1371
-            ? absint($this->_req_data['paged'])
1372
-            : 1;
1373
-        $per_page     = ! empty($this->_req_data['perpage'])
1374
-            ? $this->_req_data['perpage']
1375
-            : $per_page;
1376
-
1377
-        //-1 means return all results so get out if that's set.
1378
-        if ((int)$per_page === -1) {
1379
-            return array();
1380
-        }
1381
-        $per_page = absint($per_page);
1382
-        $offset   = ($current_page - 1) * $per_page;
1383
-        return array('limit' => array($offset, $per_page));
1384
-    }
1385
-
1386
-
1387
-    public function get_registration_status_array()
1388
-    {
1389
-        return self::$_reg_status;
1390
-    }
1391
-
1392
-
1393
-
1394
-
1395
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1396
-    /**
1397
-     *        generates HTML for the View Registration Details Admin page
1398
-     *
1399
-     * @access protected
1400
-     * @return void
1401
-     * @throws DomainException
1402
-     * @throws EE_Error
1403
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1404
-     */
1405
-    protected function _registration_details()
1406
-    {
1407
-        $this->_template_args = array();
1408
-        $this->_set_registration_object();
1409
-        if (is_object($this->_registration)) {
1410
-            $transaction                                   = $this->_registration->transaction()
1411
-                ? $this->_registration->transaction()
1412
-                : EE_Transaction::new_instance();
1413
-            $this->_session                                = $transaction->session_data();
1414
-            $event_id                                      = $this->_registration->event_ID();
1415
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1416
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1417
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1418
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1419
-            $this->_template_args['grand_total']           = $transaction->total();
1420
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1421
-            // link back to overview
1422
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1423
-            $this->_template_args['registration']                = $this->_registration;
1424
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1425
-                array(
1426
-                    'action'   => 'default',
1427
-                    'event_id' => $event_id,
1428
-                ),
1429
-                REG_ADMIN_URL
1430
-            );
1431
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1432
-                array(
1433
-                    'action' => 'default',
1434
-                    'EVT_ID' => $event_id,
1435
-                    'page'   => 'espresso_transactions',
1436
-                ),
1437
-                admin_url('admin.php')
1438
-            );
1439
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1440
-                array(
1441
-                    'page'   => 'espresso_events',
1442
-                    'action' => 'edit',
1443
-                    'post'   => $event_id,
1444
-                ),
1445
-                admin_url('admin.php')
1446
-            );
1447
-            //next and previous links
1448
-            $next_reg                                      = $this->_registration->next(
1449
-                null,
1450
-                array(),
1451
-                'REG_ID'
1452
-            );
1453
-            $this->_template_args['next_registration']     = $next_reg
1454
-                ? $this->_next_link(
1455
-                    EE_Admin_Page::add_query_args_and_nonce(
1456
-                        array(
1457
-                            'action'  => 'view_registration',
1458
-                            '_REG_ID' => $next_reg['REG_ID'],
1459
-                        ),
1460
-                        REG_ADMIN_URL
1461
-                    ),
1462
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1463
-                )
1464
-                : '';
1465
-            $previous_reg                                  = $this->_registration->previous(
1466
-                null,
1467
-                array(),
1468
-                'REG_ID'
1469
-            );
1470
-            $this->_template_args['previous_registration'] = $previous_reg
1471
-                ? $this->_previous_link(
1472
-                    EE_Admin_Page::add_query_args_and_nonce(
1473
-                        array(
1474
-                            'action'  => 'view_registration',
1475
-                            '_REG_ID' => $previous_reg['REG_ID'],
1476
-                        ),
1477
-                        REG_ADMIN_URL
1478
-                    ),
1479
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1480
-                )
1481
-                : '';
1482
-            // grab header
1483
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1484
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1485
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1486
-                $template_path,
1487
-                $this->_template_args,
1488
-                true
1489
-            );
1490
-        } else {
1491
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1492
-        }
1493
-        // the details template wrapper
1494
-        $this->display_admin_page_with_sidebar();
1495
-    }
1496
-
1497
-
1498
-    protected function _registration_details_metaboxes()
1499
-    {
1500
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1501
-        $this->_set_registration_object();
1502
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1503
-        add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1504
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1505
-        add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1506
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1507
-        if ($attendee instanceof EE_Attendee
1508
-            && EE_Registry::instance()->CAP->current_user_can(
1509
-                'ee_edit_registration',
1510
-                'edit-reg-questions-mbox'
1511
-            )
1512
-        ) {
1513
-            add_meta_box(
1514
-                'edit-reg-questions-mbox',
1515
-                esc_html__('Registration Form Answers', 'event_espresso'),
1516
-                array($this, '_reg_questions_meta_box'),
1517
-                $this->wp_page_slug,
1518
-                'normal',
1519
-                'high'
1520
-            );
1521
-        }
1522
-        add_meta_box(
1523
-            'edit-reg-registrant-mbox',
1524
-            esc_html__('Contact Details', 'event_espresso'),
1525
-            array($this, '_reg_registrant_side_meta_box'),
1526
-            $this->wp_page_slug,
1527
-            'side',
1528
-            'high'
1529
-        );
1530
-        if ($this->_registration->group_size() > 1) {
1531
-            add_meta_box(
1532
-                'edit-reg-attendees-mbox',
1533
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1534
-                array($this, '_reg_attendees_meta_box'),
1535
-                $this->wp_page_slug,
1536
-                'normal',
1537
-                'high'
1538
-            );
1539
-        }
1540
-    }
1541
-
1542
-
1543
-    /**
1544
-     * set_reg_status_buttons_metabox
1545
-     *
1546
-     * @access protected
1547
-     * @return string
1548
-     * @throws \EE_Error
1549
-     */
1550
-    public function set_reg_status_buttons_metabox()
1551
-    {
1552
-        $this->_set_registration_object();
1553
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1554
-        echo $change_reg_status_form->form_open(
1555
-            self::add_query_args_and_nonce(
1556
-                array(
1557
-                    'action' => 'change_reg_status',
1558
-                ),
1559
-                REG_ADMIN_URL
1560
-            )
1561
-        );
1562
-        echo $change_reg_status_form->get_html();
1563
-        echo $change_reg_status_form->form_close();
1564
-    }
1565
-
1566
-
1567
-
1568
-    /**
1569
-     * @return EE_Form_Section_Proper
1570
-     * @throws EE_Error
1571
-     */
1572
-    protected function _generate_reg_status_change_form()
1573
-    {
1574
-        return new EE_Form_Section_Proper(array(
1575
-            'name'            => 'reg_status_change_form',
1576
-            'html_id'         => 'reg-status-change-form',
1577
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1578
-            'subsections'     => array(
1579
-                'return'             => new EE_Hidden_Input(array(
1580
-                    'name'    => 'return',
1581
-                    'default' => 'view_registration',
1582
-                )),
1583
-                'REG_ID'             => new EE_Hidden_Input(array(
1584
-                    'name'    => 'REG_ID',
1585
-                    'default' => $this->_registration->ID(),
1586
-                )),
1587
-                'current_status'     => new EE_Form_Section_HTML(
1588
-                    EEH_HTML::tr(
1589
-                        EEH_HTML::th(
1590
-                            EEH_HTML::label(
1591
-                                EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1592
-                                )
1593
-                            )
1594
-                        )
1595
-                        . EEH_HTML::td(
1596
-                            EEH_HTML::strong(
1597
-                                $this->_registration->pretty_status(),
1598
-                                '',
1599
-                                'status-' . $this->_registration->status_ID(),
1600
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1601
-                            )
1602
-                        )
1603
-                    )
1604
-                ),
1605
-                'reg_status'         => new EE_Select_Input(
1606
-                    $this->_get_reg_statuses(),
1607
-                    array(
1608
-                        'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1609
-                        'default'         => $this->_registration->status_ID(),
1610
-                    )
1611
-                ),
1612
-                'send_notifications' => new EE_Yes_No_Input(
1613
-                    array(
1614
-                        'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1615
-                        'default'         => false,
1616
-                        'html_help_text'  => esc_html__(
1617
-                            'If set to "Yes", then the related messages will be sent to the registrant.',
1618
-                            'event_espresso'
1619
-                        ),
1620
-                    )
1621
-                ),
1622
-                'submit'             => new EE_Submit_Input(
1623
-                    array(
1624
-                        'html_class'      => 'button-primary',
1625
-                        'html_label_text' => '&nbsp;',
1626
-                        'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1627
-                    )
1628
-                ),
1629
-            ),
1630
-        ));
1631
-    }
1632
-
1633
-
1634
-    /**
1635
-     * Returns an array of all the buttons for the various statuses and switch status actions
1636
-     *
1637
-     * @return array
1638
-     * @throws EE_Error
1639
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1640
-     */
1641
-    protected function _get_reg_statuses()
1642
-    {
1643
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1644
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1645
-        // get current reg status
1646
-        $current_status = $this->_registration->status_ID();
1647
-        // is registration for free event? This will determine whether to display the pending payment option
1648
-        if (
1649
-            $current_status !== EEM_Registration::status_id_pending_payment
1650
-            && $this->_registration->transaction()->is_free()
1651
-        ) {
1652
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1653
-        }
1654
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1655
-    }
1656
-
1657
-
1658
-
1659
-    /**
1660
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1661
-     *
1662
-     * @param bool $status REG status given for changing registrations to.
1663
-     * @param bool $notify Whether to send messages notifications or not.
1664
-     * @return array  (array with reg_id(s) updated and whether update was successful.
1665
-     * @throws \EE_Error
1666
-     */
1667
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1668
-    {
1669
-        if (isset($this->_req_data['reg_status_change_form'])) {
1670
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1671
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1672
-        } else {
1673
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1674
-        }
1675
-        $success = $this->_set_registration_status($REG_IDs, $status);
1676
-        //notify?
1677
-        if ($success
1678
-            && $notify
1679
-            && EE_Registry::instance()->CAP->current_user_can(
1680
-                'ee_send_message',
1681
-                'espresso_registrations_resend_registration'
1682
-            )
1683
-        ) {
1684
-            $this->_process_resend_registration();
1685
-        }
1686
-        return $success;
1687
-    }
1688
-
1689
-
1690
-
1691
-    /**
1692
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1693
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1694
-     *
1695
-     * @param array $REG_IDs
1696
-     * @param bool  $status
1697
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
-     * @throws \RuntimeException
1699
-     * @throws \EE_Error
1700
-     *               the array of updated registrations).
1701
-     * @throws EE_Error
1702
-     * @throws RuntimeException
1703
-     */
1704
-    protected function _set_registration_status($REG_IDs = array(), $status = false)
1705
-    {
1706
-        $success = false;
1707
-        // typecast $REG_IDs
1708
-        $REG_IDs = (array)$REG_IDs;
1709
-        if ( ! empty($REG_IDs)) {
1710
-            $success = true;
1711
-            // set default status if none is passed
1712
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1713
-            // sanitize $REG_IDs
1714
-            $REG_IDs = array_filter($REG_IDs, 'absint');
1715
-            //loop through REG_ID's and change status
1716
-            foreach ($REG_IDs as $REG_ID) {
1717
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1718
-                if ($registration instanceof EE_Registration) {
1719
-                    $registration->set_status($status);
1720
-                    $result = $registration->save();
1721
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1722
-                    $success = $result !== false ? $success : false;
1723
-                }
1724
-            }
1725
-        }
1726
-        //reset _req_data['_REG_ID'] for any potential future messages notifications
1727
-        $this->_req_data['_REG_ID'] = $REG_IDs;
1728
-        //return $success and processed registrations
1729
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1730
-    }
1731
-
1732
-
1733
-    /**
1734
-     * Common logic for setting up success message and redirecting to appropriate route
1735
-     *
1736
-     * @param  string $STS_ID status id for the registration changed to
1737
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1738
-     * @return void
1739
-     */
1740
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1741
-    {
1742
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1743
-            : array('success' => false);
1744
-        $success = isset($result['success']) && $result['success'];
1745
-        //setup success message
1746
-        if ($success) {
1747
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1748
-                $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1749
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1750
-            } else {
1751
-                $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1752
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1753
-            }
1754
-            EE_Error::add_success($msg);
1755
-        } else {
1756
-            EE_Error::add_error(
1757
-                esc_html__(
1758
-                    'Something went wrong, and the status was not changed',
1759
-                    'event_espresso'
1760
-                ), __FILE__, __LINE__, __FUNCTION__
1761
-            );
1762
-        }
1763
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1764
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1765
-        } else {
1766
-            $route = array('action' => 'default');
1767
-        }
1768
-        //unset nonces
1769
-        foreach ($this->_req_data as $ref => $value) {
1770
-            if (strpos($ref, 'nonce') !== false) {
1771
-                unset($this->_req_data[$ref]);
1772
-                continue;
1773
-            }
1774
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1775
-            $this->_req_data[$ref] = $value;
1776
-        }
1777
-        //merge request vars so that the reloaded list table contains any existing filter query params
1778
-        $route = array_merge($this->_req_data, $route);
1779
-        $this->_redirect_after_action($success, '', '', $route, true);
1780
-    }
1781
-
1782
-
1783
-    /**
1784
-     * incoming reg status change from reg details page.
1785
-     *
1786
-     * @return void
1787
-     */
1788
-    protected function _change_reg_status()
1789
-    {
1790
-        $this->_req_data['return'] = 'view_registration';
1791
-        //set notify based on whether the send notifications toggle is set or not
1792
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1793
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1794
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1795
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1796
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1797
-            case EEM_Registration::status_id_approved :
1798
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1799
-                $this->approve_registration($notify);
1800
-                break;
1801
-            case EEM_Registration::status_id_pending_payment :
1802
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1803
-                $this->pending_registration($notify);
1804
-                break;
1805
-            case EEM_Registration::status_id_not_approved :
1806
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1807
-                $this->not_approve_registration($notify);
1808
-                break;
1809
-            case EEM_Registration::status_id_declined :
1810
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1811
-                $this->decline_registration($notify);
1812
-                break;
1813
-            case EEM_Registration::status_id_cancelled :
1814
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1815
-                $this->cancel_registration($notify);
1816
-                break;
1817
-            case EEM_Registration::status_id_wait_list :
1818
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1819
-                $this->wait_list_registration($notify);
1820
-                break;
1821
-            case EEM_Registration::status_id_incomplete :
1822
-            default :
1823
-                $result['success'] = false;
1824
-                unset($this->_req_data['return']);
1825
-                $this->_reg_status_change_return('', false);
1826
-                break;
1827
-        }
1828
-    }
1829
-
1830
-
1831
-    /**
1832
-     * approve_registration
1833
-     *
1834
-     * @access protected
1835
-     * @param bool $notify whether or not to notify the registrant about their approval.
1836
-     * @return void
1837
-     */
1838
-    protected function approve_registration($notify = false)
1839
-    {
1840
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1841
-    }
1842
-
1843
-
1844
-    /**
1845
-     *        decline_registration
1846
-     *
1847
-     * @access protected
1848
-     * @param bool $notify whether or not to notify the registrant about their status change.
1849
-     * @return void
1850
-     */
1851
-    protected function decline_registration($notify = false)
1852
-    {
1853
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1854
-    }
1855
-
1856
-
1857
-    /**
1858
-     *        cancel_registration
1859
-     *
1860
-     * @access protected
1861
-     * @param bool $notify whether or not to notify the registrant about their status change.
1862
-     * @return void
1863
-     */
1864
-    protected function cancel_registration($notify = false)
1865
-    {
1866
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1867
-    }
1868
-
1869
-
1870
-    /**
1871
-     *        not_approve_registration
1872
-     *
1873
-     * @access protected
1874
-     * @param bool $notify whether or not to notify the registrant about their status change.
1875
-     * @return void
1876
-     */
1877
-    protected function not_approve_registration($notify = false)
1878
-    {
1879
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1880
-    }
1881
-
1882
-
1883
-    /**
1884
-     *        decline_registration
1885
-     *
1886
-     * @access protected
1887
-     * @param bool $notify whether or not to notify the registrant about their status change.
1888
-     * @return void
1889
-     */
1890
-    protected function pending_registration($notify = false)
1891
-    {
1892
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1893
-    }
1894
-
1895
-
1896
-    /**
1897
-     * waitlist_registration
1898
-     *
1899
-     * @access protected
1900
-     * @param bool $notify whether or not to notify the registrant about their status change.
1901
-     * @return void
1902
-     */
1903
-    protected function wait_list_registration($notify = false)
1904
-    {
1905
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1906
-    }
1907
-
1908
-
1909
-    /**
1910
-     *        generates HTML for the Registration main meta box
1911
-     *
1912
-     * @access public
1913
-     * @return void
1914
-     * @throws DomainException
1915
-     * @throws EE_Error
1916
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1917
-     */
1918
-    public function _reg_details_meta_box()
1919
-    {
1920
-        EEH_Autoloader::register_line_item_display_autoloaders();
1921
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1922
-        EE_Registry::instance()->load_helper('Line_Item');
1923
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1924
-            : EE_Transaction::new_instance();
1925
-        $this->_session = $transaction->session_data();
1926
-        $filters        = new EE_Line_Item_Filter_Collection();
1927
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1928
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1929
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1930
-            $transaction->total_line_item());
1931
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
1932
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1933
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1934
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
1935
-            $filtered_line_item_tree,
1936
-            array('EE_Registration' => $this->_registration)
1937
-        );
1938
-        $attendee                                = $this->_registration->attendee();
1939
-        if (EE_Registry::instance()->CAP->current_user_can(
1940
-            'ee_read_transaction',
1941
-            'espresso_transactions_view_transaction'
1942
-        )) {
1943
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
1944
-                EE_Admin_Page::add_query_args_and_nonce(
1945
-                    array(
1946
-                        'action' => 'view_transaction',
1947
-                        'TXN_ID' => $transaction->ID(),
1948
-                    ),
1949
-                    TXN_ADMIN_URL
1950
-                ),
1951
-                esc_html__(' View Transaction', 'event_espresso'),
1952
-                'button secondary-button right',
1953
-                'dashicons dashicons-cart'
1954
-            );
1955
-        } else {
1956
-            $this->_template_args['view_transaction_button'] = '';
1957
-        }
1958
-        if ($attendee instanceof EE_Attendee
1959
-            && EE_Registry::instance()->CAP->current_user_can(
1960
-                'ee_send_message',
1961
-                'espresso_registrations_resend_registration'
1962
-            )
1963
-        ) {
1964
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
1965
-                EE_Admin_Page::add_query_args_and_nonce(
1966
-                    array(
1967
-                        'action'      => 'resend_registration',
1968
-                        '_REG_ID'     => $this->_registration->ID(),
1969
-                        'redirect_to' => 'view_registration',
1970
-                    ),
1971
-                    REG_ADMIN_URL
1972
-                ),
1973
-                esc_html__(' Resend Registration', 'event_espresso'),
1974
-                'button secondary-button right',
1975
-                'dashicons dashicons-email-alt'
1976
-            );
1977
-        } else {
1978
-            $this->_template_args['resend_registration_button'] = '';
1979
-        }
1980
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1981
-        $payment                               = $transaction->get_first_related('Payment');
1982
-        $payment                               = ! $payment instanceof EE_Payment
1983
-            ? EE_Payment::new_instance()
1984
-            : $payment;
1985
-        $payment_method                        = $payment->get_first_related('Payment_Method');
1986
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
1987
-            ? EE_Payment_Method::new_instance()
1988
-            : $payment_method;
1989
-        $reg_details                           = array(
1990
-            'payment_method'       => $payment_method->name(),
1991
-            'response_msg'         => $payment->gateway_response(),
1992
-            'registration_id'      => $this->_registration->get('REG_code'),
1993
-            'registration_session' => $this->_registration->session_ID(),
1994
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1995
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1996
-        );
1997
-        if (isset($reg_details['registration_id'])) {
1998
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1999
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2000
-                'Registration ID',
2001
-                'event_espresso'
2002
-            );
2003
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2004
-        }
2005
-        if (isset($reg_details['payment_method'])) {
2006
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2007
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2008
-                'Most Recent Payment Method',
2009
-                'event_espresso'
2010
-            );
2011
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2012
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2013
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2014
-                'Payment method response',
2015
-                'event_espresso'
2016
-            );
2017
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2018
-        }
2019
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2020
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2021
-            'Registration Session',
2022
-            'event_espresso'
2023
-        );
2024
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2025
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2026
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2027
-            'Registration placed from IP',
2028
-            'event_espresso'
2029
-        );
2030
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2031
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2032
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2033
-            'event_espresso');
2034
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2035
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2036
-            array(
2037
-                'action'   => 'default',
2038
-                'event_id' => $this->_registration->event_ID(),
2039
-            ),
2040
-            REG_ADMIN_URL
2041
-        );
2042
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
2043
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
2044
-        $template_path                                                        =
2045
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2046
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2047
-    }
2048
-
2049
-
2050
-    /**
2051
-     * generates HTML for the Registration Questions meta box.
2052
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2053
-     * otherwise uses new forms system
2054
-     *
2055
-     * @access public
2056
-     * @return void
2057
-     * @throws DomainException
2058
-     * @throws EE_Error
2059
-     */
2060
-    public function _reg_questions_meta_box()
2061
-    {
2062
-        //allow someone to override this method entirely
2063
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2064
-            $this->_registration)) {
2065
-            $form                                              = $this->_get_reg_custom_questions_form(
2066
-                $this->_registration->ID()
2067
-            );
2068
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0
2069
-                ? $form->get_html_and_js()
2070
-                : '';
2071
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2072
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
2073
-            $template_path                                     =
2074
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2075
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2076
-        }
2077
-    }
2078
-
2079
-
2080
-    /**
2081
-     * form_before_question_group
2082
-     *
2083
-     * @deprecated    as of 4.8.32.rc.000
2084
-     * @access        public
2085
-     * @param        string $output
2086
-     * @return        string
2087
-     */
2088
-    public function form_before_question_group($output)
2089
-    {
2090
-        EE_Error::doing_it_wrong(
2091
-            __CLASS__ . '::' . __FUNCTION__,
2092
-            esc_html__(
2093
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2094
-                'event_espresso'
2095
-            ),
2096
-            '4.8.32.rc.000'
2097
-        );
2098
-        return '
1155
+		if (! empty($registration_status)) {
1156
+			$where['STS_ID'] = $registration_status;
1157
+		} else {
1158
+			//make sure we exclude incomplete registrations, but only if not trashed.
1159
+			if ($view === 'trash') {
1160
+				$where['REG_deleted'] = true;
1161
+			} elseif ($view === 'incomplete') {
1162
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1163
+			} else {
1164
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1165
+			}
1166
+		}
1167
+		return $where;
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1173
+	 *
1174
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1175
+	 * @return array
1176
+	 * @throws EE_Error
1177
+	 */
1178
+	protected function _add_date_to_where_conditions(array $request)
1179
+	{
1180
+		$where = array();
1181
+		$view = EEH_Array::is_set($request, 'status', '');
1182
+		$month_range             = ! empty($request['month_range'])
1183
+			? sanitize_text_field($request['month_range'])
1184
+			: '';
1185
+		$retrieve_for_today      = $view === 'today';
1186
+		$retrieve_for_this_month = $view === 'month';
1187
+
1188
+		if ($retrieve_for_today) {
1189
+			$now               = date('Y-m-d', current_time('timestamp'));
1190
+			$where['REG_date'] = array(
1191
+				'BETWEEN',
1192
+				array(
1193
+					EEM_Registration::instance()->convert_datetime_for_query(
1194
+						'REG_date',
1195
+						$now . ' 00:00:00',
1196
+						'Y-m-d H:i:s'
1197
+					),
1198
+					EEM_Registration::instance()->convert_datetime_for_query(
1199
+						'REG_date',
1200
+						$now . ' 23:59:59',
1201
+						'Y-m-d H:i:s'
1202
+					),
1203
+				),
1204
+			);
1205
+		} elseif ($retrieve_for_this_month) {
1206
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1207
+			$days_this_month        = date('t', current_time('timestamp'));
1208
+			$where['REG_date']      = array(
1209
+				'BETWEEN',
1210
+				array(
1211
+					EEM_Registration::instance()->convert_datetime_for_query(
1212
+						'REG_date',
1213
+						$current_year_and_month . '-01 00:00:00',
1214
+						'Y-m-d H:i:s'
1215
+					),
1216
+					EEM_Registration::instance()->convert_datetime_for_query(
1217
+						'REG_date',
1218
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1219
+						'Y-m-d H:i:s'
1220
+					),
1221
+				),
1222
+			);
1223
+		} elseif ($month_range) {
1224
+			$pieces          = explode(' ', $month_range, 3);
1225
+			$month_requested = ! empty($pieces[0])
1226
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1227
+				: '';
1228
+			$year_requested  = ! empty($pieces[1])
1229
+				? $pieces[1]
1230
+				: '';
1231
+			//if there is not a month or year then we can't go further
1232
+			if ($month_requested && $year_requested) {
1233
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1234
+				$where['REG_date'] = array(
1235
+					'BETWEEN',
1236
+					array(
1237
+						EEM_Registration::instance()->convert_datetime_for_query(
1238
+							'REG_date',
1239
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1240
+							'Y-m-d H:i:s'
1241
+						),
1242
+						EEM_Registration::instance()->convert_datetime_for_query(
1243
+							'REG_date',
1244
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1245
+							'Y-m-d H:i:s'
1246
+						),
1247
+					),
1248
+				);
1249
+			}
1250
+		}
1251
+		return $where;
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 * Adds any provided search restraints to the where conditions for the registrations query
1257
+	 *
1258
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1259
+	 * @return array
1260
+	 */
1261
+	protected function _add_search_to_where_conditions(array $request)
1262
+	{
1263
+		$where = array();
1264
+		if (! empty($request['s'])) {
1265
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1266
+			$where['OR*search_conditions'] = array(
1267
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1268
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1269
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1270
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1271
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1272
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1273
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1274
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1275
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1276
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1277
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1278
+				'REG_final_price'                         => array('LIKE', $search_string),
1279
+				'REG_code'                                => array('LIKE', $search_string),
1280
+				'REG_count'                               => array('LIKE', $search_string),
1281
+				'REG_group_size'                          => array('LIKE', $search_string),
1282
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1283
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1284
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1285
+			);
1286
+		}
1287
+		return $where;
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * Sets up the where conditions for the registrations query.
1293
+	 *
1294
+	 * @param array $request
1295
+	 * @return array
1296
+	 * @throws EE_Error
1297
+	 */
1298
+	protected function _get_where_conditions_for_registrations_query($request)
1299
+	{
1300
+		return apply_filters(
1301
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1302
+			array_merge(
1303
+				$this->_add_event_id_to_where_conditions($request),
1304
+				$this->_add_category_id_to_where_conditions($request),
1305
+				$this->_add_datetime_id_to_where_conditions($request),
1306
+				$this->_add_registration_status_to_where_conditions($request),
1307
+				$this->_add_date_to_where_conditions($request),
1308
+				$this->_add_search_to_where_conditions($request)
1309
+			),
1310
+			$request
1311
+		);
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * Sets up the orderby for the registrations query.
1317
+	 *
1318
+	 * @return array
1319
+	 */
1320
+	protected function _get_orderby_for_registrations_query()
1321
+	{
1322
+		$orderby_field = ! empty($this->_req_data['orderby'])
1323
+			? sanitize_text_field($this->_req_data['orderby'])
1324
+			: '';
1325
+		switch ($orderby_field) {
1326
+			case '_REG_ID':
1327
+				$orderby_field = 'REG_ID';
1328
+				break;
1329
+			case '_Reg_status':
1330
+				$orderby_field = 'STS_ID';
1331
+				break;
1332
+			case 'ATT_fname':
1333
+				$orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1334
+				break;
1335
+			case 'ATT_lname':
1336
+				$orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1337
+				break;
1338
+			case 'event_name':
1339
+				$orderby_field = 'Event.EVT_name';
1340
+				break;
1341
+			case 'DTT_EVT_start':
1342
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1343
+				break;
1344
+			default: //'REG_date'
1345
+				$orderby_field = 'REG_date';
1346
+		}
1347
+
1348
+		//order
1349
+		$order = ! empty($this->_req_data['order'])
1350
+			? sanitize_text_field($this->_req_data['order'])
1351
+			: 'DESC';
1352
+
1353
+		//mutate orderby_field
1354
+		$orderby_field = array_combine(
1355
+			(array) $orderby_field,
1356
+			array_fill(0, count($orderby_field), $order)
1357
+		);
1358
+		return array('order_by' => $orderby_field);
1359
+	}
1360
+
1361
+
1362
+	/**
1363
+	 * Sets up the limit for the registrations query.
1364
+	 *
1365
+	 * @param $per_page
1366
+	 * @return array
1367
+	 */
1368
+	protected function _get_limit($per_page)
1369
+	{
1370
+		$current_page = ! empty($this->_req_data['paged'])
1371
+			? absint($this->_req_data['paged'])
1372
+			: 1;
1373
+		$per_page     = ! empty($this->_req_data['perpage'])
1374
+			? $this->_req_data['perpage']
1375
+			: $per_page;
1376
+
1377
+		//-1 means return all results so get out if that's set.
1378
+		if ((int)$per_page === -1) {
1379
+			return array();
1380
+		}
1381
+		$per_page = absint($per_page);
1382
+		$offset   = ($current_page - 1) * $per_page;
1383
+		return array('limit' => array($offset, $per_page));
1384
+	}
1385
+
1386
+
1387
+	public function get_registration_status_array()
1388
+	{
1389
+		return self::$_reg_status;
1390
+	}
1391
+
1392
+
1393
+
1394
+
1395
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1396
+	/**
1397
+	 *        generates HTML for the View Registration Details Admin page
1398
+	 *
1399
+	 * @access protected
1400
+	 * @return void
1401
+	 * @throws DomainException
1402
+	 * @throws EE_Error
1403
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1404
+	 */
1405
+	protected function _registration_details()
1406
+	{
1407
+		$this->_template_args = array();
1408
+		$this->_set_registration_object();
1409
+		if (is_object($this->_registration)) {
1410
+			$transaction                                   = $this->_registration->transaction()
1411
+				? $this->_registration->transaction()
1412
+				: EE_Transaction::new_instance();
1413
+			$this->_session                                = $transaction->session_data();
1414
+			$event_id                                      = $this->_registration->event_ID();
1415
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1416
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1417
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1418
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1419
+			$this->_template_args['grand_total']           = $transaction->total();
1420
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1421
+			// link back to overview
1422
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1423
+			$this->_template_args['registration']                = $this->_registration;
1424
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1425
+				array(
1426
+					'action'   => 'default',
1427
+					'event_id' => $event_id,
1428
+				),
1429
+				REG_ADMIN_URL
1430
+			);
1431
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1432
+				array(
1433
+					'action' => 'default',
1434
+					'EVT_ID' => $event_id,
1435
+					'page'   => 'espresso_transactions',
1436
+				),
1437
+				admin_url('admin.php')
1438
+			);
1439
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1440
+				array(
1441
+					'page'   => 'espresso_events',
1442
+					'action' => 'edit',
1443
+					'post'   => $event_id,
1444
+				),
1445
+				admin_url('admin.php')
1446
+			);
1447
+			//next and previous links
1448
+			$next_reg                                      = $this->_registration->next(
1449
+				null,
1450
+				array(),
1451
+				'REG_ID'
1452
+			);
1453
+			$this->_template_args['next_registration']     = $next_reg
1454
+				? $this->_next_link(
1455
+					EE_Admin_Page::add_query_args_and_nonce(
1456
+						array(
1457
+							'action'  => 'view_registration',
1458
+							'_REG_ID' => $next_reg['REG_ID'],
1459
+						),
1460
+						REG_ADMIN_URL
1461
+					),
1462
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1463
+				)
1464
+				: '';
1465
+			$previous_reg                                  = $this->_registration->previous(
1466
+				null,
1467
+				array(),
1468
+				'REG_ID'
1469
+			);
1470
+			$this->_template_args['previous_registration'] = $previous_reg
1471
+				? $this->_previous_link(
1472
+					EE_Admin_Page::add_query_args_and_nonce(
1473
+						array(
1474
+							'action'  => 'view_registration',
1475
+							'_REG_ID' => $previous_reg['REG_ID'],
1476
+						),
1477
+						REG_ADMIN_URL
1478
+					),
1479
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1480
+				)
1481
+				: '';
1482
+			// grab header
1483
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1484
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1485
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1486
+				$template_path,
1487
+				$this->_template_args,
1488
+				true
1489
+			);
1490
+		} else {
1491
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1492
+		}
1493
+		// the details template wrapper
1494
+		$this->display_admin_page_with_sidebar();
1495
+	}
1496
+
1497
+
1498
+	protected function _registration_details_metaboxes()
1499
+	{
1500
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1501
+		$this->_set_registration_object();
1502
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1503
+		add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'),
1504
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1505
+		add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'),
1506
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1507
+		if ($attendee instanceof EE_Attendee
1508
+			&& EE_Registry::instance()->CAP->current_user_can(
1509
+				'ee_edit_registration',
1510
+				'edit-reg-questions-mbox'
1511
+			)
1512
+		) {
1513
+			add_meta_box(
1514
+				'edit-reg-questions-mbox',
1515
+				esc_html__('Registration Form Answers', 'event_espresso'),
1516
+				array($this, '_reg_questions_meta_box'),
1517
+				$this->wp_page_slug,
1518
+				'normal',
1519
+				'high'
1520
+			);
1521
+		}
1522
+		add_meta_box(
1523
+			'edit-reg-registrant-mbox',
1524
+			esc_html__('Contact Details', 'event_espresso'),
1525
+			array($this, '_reg_registrant_side_meta_box'),
1526
+			$this->wp_page_slug,
1527
+			'side',
1528
+			'high'
1529
+		);
1530
+		if ($this->_registration->group_size() > 1) {
1531
+			add_meta_box(
1532
+				'edit-reg-attendees-mbox',
1533
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1534
+				array($this, '_reg_attendees_meta_box'),
1535
+				$this->wp_page_slug,
1536
+				'normal',
1537
+				'high'
1538
+			);
1539
+		}
1540
+	}
1541
+
1542
+
1543
+	/**
1544
+	 * set_reg_status_buttons_metabox
1545
+	 *
1546
+	 * @access protected
1547
+	 * @return string
1548
+	 * @throws \EE_Error
1549
+	 */
1550
+	public function set_reg_status_buttons_metabox()
1551
+	{
1552
+		$this->_set_registration_object();
1553
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1554
+		echo $change_reg_status_form->form_open(
1555
+			self::add_query_args_and_nonce(
1556
+				array(
1557
+					'action' => 'change_reg_status',
1558
+				),
1559
+				REG_ADMIN_URL
1560
+			)
1561
+		);
1562
+		echo $change_reg_status_form->get_html();
1563
+		echo $change_reg_status_form->form_close();
1564
+	}
1565
+
1566
+
1567
+
1568
+	/**
1569
+	 * @return EE_Form_Section_Proper
1570
+	 * @throws EE_Error
1571
+	 */
1572
+	protected function _generate_reg_status_change_form()
1573
+	{
1574
+		return new EE_Form_Section_Proper(array(
1575
+			'name'            => 'reg_status_change_form',
1576
+			'html_id'         => 'reg-status-change-form',
1577
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1578
+			'subsections'     => array(
1579
+				'return'             => new EE_Hidden_Input(array(
1580
+					'name'    => 'return',
1581
+					'default' => 'view_registration',
1582
+				)),
1583
+				'REG_ID'             => new EE_Hidden_Input(array(
1584
+					'name'    => 'REG_ID',
1585
+					'default' => $this->_registration->ID(),
1586
+				)),
1587
+				'current_status'     => new EE_Form_Section_HTML(
1588
+					EEH_HTML::tr(
1589
+						EEH_HTML::th(
1590
+							EEH_HTML::label(
1591
+								EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso')
1592
+								)
1593
+							)
1594
+						)
1595
+						. EEH_HTML::td(
1596
+							EEH_HTML::strong(
1597
+								$this->_registration->pretty_status(),
1598
+								'',
1599
+								'status-' . $this->_registration->status_ID(),
1600
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1601
+							)
1602
+						)
1603
+					)
1604
+				),
1605
+				'reg_status'         => new EE_Select_Input(
1606
+					$this->_get_reg_statuses(),
1607
+					array(
1608
+						'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1609
+						'default'         => $this->_registration->status_ID(),
1610
+					)
1611
+				),
1612
+				'send_notifications' => new EE_Yes_No_Input(
1613
+					array(
1614
+						'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1615
+						'default'         => false,
1616
+						'html_help_text'  => esc_html__(
1617
+							'If set to "Yes", then the related messages will be sent to the registrant.',
1618
+							'event_espresso'
1619
+						),
1620
+					)
1621
+				),
1622
+				'submit'             => new EE_Submit_Input(
1623
+					array(
1624
+						'html_class'      => 'button-primary',
1625
+						'html_label_text' => '&nbsp;',
1626
+						'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1627
+					)
1628
+				),
1629
+			),
1630
+		));
1631
+	}
1632
+
1633
+
1634
+	/**
1635
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1636
+	 *
1637
+	 * @return array
1638
+	 * @throws EE_Error
1639
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1640
+	 */
1641
+	protected function _get_reg_statuses()
1642
+	{
1643
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1644
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1645
+		// get current reg status
1646
+		$current_status = $this->_registration->status_ID();
1647
+		// is registration for free event? This will determine whether to display the pending payment option
1648
+		if (
1649
+			$current_status !== EEM_Registration::status_id_pending_payment
1650
+			&& $this->_registration->transaction()->is_free()
1651
+		) {
1652
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1653
+		}
1654
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1655
+	}
1656
+
1657
+
1658
+
1659
+	/**
1660
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1661
+	 *
1662
+	 * @param bool $status REG status given for changing registrations to.
1663
+	 * @param bool $notify Whether to send messages notifications or not.
1664
+	 * @return array  (array with reg_id(s) updated and whether update was successful.
1665
+	 * @throws \EE_Error
1666
+	 */
1667
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1668
+	{
1669
+		if (isset($this->_req_data['reg_status_change_form'])) {
1670
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1671
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1672
+		} else {
1673
+			$REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1674
+		}
1675
+		$success = $this->_set_registration_status($REG_IDs, $status);
1676
+		//notify?
1677
+		if ($success
1678
+			&& $notify
1679
+			&& EE_Registry::instance()->CAP->current_user_can(
1680
+				'ee_send_message',
1681
+				'espresso_registrations_resend_registration'
1682
+			)
1683
+		) {
1684
+			$this->_process_resend_registration();
1685
+		}
1686
+		return $success;
1687
+	}
1688
+
1689
+
1690
+
1691
+	/**
1692
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1693
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1694
+	 *
1695
+	 * @param array $REG_IDs
1696
+	 * @param bool  $status
1697
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1698
+	 * @throws \RuntimeException
1699
+	 * @throws \EE_Error
1700
+	 *               the array of updated registrations).
1701
+	 * @throws EE_Error
1702
+	 * @throws RuntimeException
1703
+	 */
1704
+	protected function _set_registration_status($REG_IDs = array(), $status = false)
1705
+	{
1706
+		$success = false;
1707
+		// typecast $REG_IDs
1708
+		$REG_IDs = (array)$REG_IDs;
1709
+		if ( ! empty($REG_IDs)) {
1710
+			$success = true;
1711
+			// set default status if none is passed
1712
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1713
+			// sanitize $REG_IDs
1714
+			$REG_IDs = array_filter($REG_IDs, 'absint');
1715
+			//loop through REG_ID's and change status
1716
+			foreach ($REG_IDs as $REG_ID) {
1717
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1718
+				if ($registration instanceof EE_Registration) {
1719
+					$registration->set_status($status);
1720
+					$result = $registration->save();
1721
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1722
+					$success = $result !== false ? $success : false;
1723
+				}
1724
+			}
1725
+		}
1726
+		//reset _req_data['_REG_ID'] for any potential future messages notifications
1727
+		$this->_req_data['_REG_ID'] = $REG_IDs;
1728
+		//return $success and processed registrations
1729
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1730
+	}
1731
+
1732
+
1733
+	/**
1734
+	 * Common logic for setting up success message and redirecting to appropriate route
1735
+	 *
1736
+	 * @param  string $STS_ID status id for the registration changed to
1737
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1738
+	 * @return void
1739
+	 */
1740
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1741
+	{
1742
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1743
+			: array('success' => false);
1744
+		$success = isset($result['success']) && $result['success'];
1745
+		//setup success message
1746
+		if ($success) {
1747
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1748
+				$msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'),
1749
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1750
+			} else {
1751
+				$msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'),
1752
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1753
+			}
1754
+			EE_Error::add_success($msg);
1755
+		} else {
1756
+			EE_Error::add_error(
1757
+				esc_html__(
1758
+					'Something went wrong, and the status was not changed',
1759
+					'event_espresso'
1760
+				), __FILE__, __LINE__, __FUNCTION__
1761
+			);
1762
+		}
1763
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1764
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1765
+		} else {
1766
+			$route = array('action' => 'default');
1767
+		}
1768
+		//unset nonces
1769
+		foreach ($this->_req_data as $ref => $value) {
1770
+			if (strpos($ref, 'nonce') !== false) {
1771
+				unset($this->_req_data[$ref]);
1772
+				continue;
1773
+			}
1774
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1775
+			$this->_req_data[$ref] = $value;
1776
+		}
1777
+		//merge request vars so that the reloaded list table contains any existing filter query params
1778
+		$route = array_merge($this->_req_data, $route);
1779
+		$this->_redirect_after_action($success, '', '', $route, true);
1780
+	}
1781
+
1782
+
1783
+	/**
1784
+	 * incoming reg status change from reg details page.
1785
+	 *
1786
+	 * @return void
1787
+	 */
1788
+	protected function _change_reg_status()
1789
+	{
1790
+		$this->_req_data['return'] = 'view_registration';
1791
+		//set notify based on whether the send notifications toggle is set or not
1792
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1793
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1794
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1795
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1796
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1797
+			case EEM_Registration::status_id_approved :
1798
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1799
+				$this->approve_registration($notify);
1800
+				break;
1801
+			case EEM_Registration::status_id_pending_payment :
1802
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1803
+				$this->pending_registration($notify);
1804
+				break;
1805
+			case EEM_Registration::status_id_not_approved :
1806
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1807
+				$this->not_approve_registration($notify);
1808
+				break;
1809
+			case EEM_Registration::status_id_declined :
1810
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1811
+				$this->decline_registration($notify);
1812
+				break;
1813
+			case EEM_Registration::status_id_cancelled :
1814
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1815
+				$this->cancel_registration($notify);
1816
+				break;
1817
+			case EEM_Registration::status_id_wait_list :
1818
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1819
+				$this->wait_list_registration($notify);
1820
+				break;
1821
+			case EEM_Registration::status_id_incomplete :
1822
+			default :
1823
+				$result['success'] = false;
1824
+				unset($this->_req_data['return']);
1825
+				$this->_reg_status_change_return('', false);
1826
+				break;
1827
+		}
1828
+	}
1829
+
1830
+
1831
+	/**
1832
+	 * approve_registration
1833
+	 *
1834
+	 * @access protected
1835
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1836
+	 * @return void
1837
+	 */
1838
+	protected function approve_registration($notify = false)
1839
+	{
1840
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1841
+	}
1842
+
1843
+
1844
+	/**
1845
+	 *        decline_registration
1846
+	 *
1847
+	 * @access protected
1848
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1849
+	 * @return void
1850
+	 */
1851
+	protected function decline_registration($notify = false)
1852
+	{
1853
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1854
+	}
1855
+
1856
+
1857
+	/**
1858
+	 *        cancel_registration
1859
+	 *
1860
+	 * @access protected
1861
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1862
+	 * @return void
1863
+	 */
1864
+	protected function cancel_registration($notify = false)
1865
+	{
1866
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1867
+	}
1868
+
1869
+
1870
+	/**
1871
+	 *        not_approve_registration
1872
+	 *
1873
+	 * @access protected
1874
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1875
+	 * @return void
1876
+	 */
1877
+	protected function not_approve_registration($notify = false)
1878
+	{
1879
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1880
+	}
1881
+
1882
+
1883
+	/**
1884
+	 *        decline_registration
1885
+	 *
1886
+	 * @access protected
1887
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1888
+	 * @return void
1889
+	 */
1890
+	protected function pending_registration($notify = false)
1891
+	{
1892
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1893
+	}
1894
+
1895
+
1896
+	/**
1897
+	 * waitlist_registration
1898
+	 *
1899
+	 * @access protected
1900
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1901
+	 * @return void
1902
+	 */
1903
+	protected function wait_list_registration($notify = false)
1904
+	{
1905
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1906
+	}
1907
+
1908
+
1909
+	/**
1910
+	 *        generates HTML for the Registration main meta box
1911
+	 *
1912
+	 * @access public
1913
+	 * @return void
1914
+	 * @throws DomainException
1915
+	 * @throws EE_Error
1916
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1917
+	 */
1918
+	public function _reg_details_meta_box()
1919
+	{
1920
+		EEH_Autoloader::register_line_item_display_autoloaders();
1921
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1922
+		EE_Registry::instance()->load_helper('Line_Item');
1923
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1924
+			: EE_Transaction::new_instance();
1925
+		$this->_session = $transaction->session_data();
1926
+		$filters        = new EE_Line_Item_Filter_Collection();
1927
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1928
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1929
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1930
+			$transaction->total_line_item());
1931
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
1932
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1933
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1934
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
1935
+			$filtered_line_item_tree,
1936
+			array('EE_Registration' => $this->_registration)
1937
+		);
1938
+		$attendee                                = $this->_registration->attendee();
1939
+		if (EE_Registry::instance()->CAP->current_user_can(
1940
+			'ee_read_transaction',
1941
+			'espresso_transactions_view_transaction'
1942
+		)) {
1943
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
1944
+				EE_Admin_Page::add_query_args_and_nonce(
1945
+					array(
1946
+						'action' => 'view_transaction',
1947
+						'TXN_ID' => $transaction->ID(),
1948
+					),
1949
+					TXN_ADMIN_URL
1950
+				),
1951
+				esc_html__(' View Transaction', 'event_espresso'),
1952
+				'button secondary-button right',
1953
+				'dashicons dashicons-cart'
1954
+			);
1955
+		} else {
1956
+			$this->_template_args['view_transaction_button'] = '';
1957
+		}
1958
+		if ($attendee instanceof EE_Attendee
1959
+			&& EE_Registry::instance()->CAP->current_user_can(
1960
+				'ee_send_message',
1961
+				'espresso_registrations_resend_registration'
1962
+			)
1963
+		) {
1964
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
1965
+				EE_Admin_Page::add_query_args_and_nonce(
1966
+					array(
1967
+						'action'      => 'resend_registration',
1968
+						'_REG_ID'     => $this->_registration->ID(),
1969
+						'redirect_to' => 'view_registration',
1970
+					),
1971
+					REG_ADMIN_URL
1972
+				),
1973
+				esc_html__(' Resend Registration', 'event_espresso'),
1974
+				'button secondary-button right',
1975
+				'dashicons dashicons-email-alt'
1976
+			);
1977
+		} else {
1978
+			$this->_template_args['resend_registration_button'] = '';
1979
+		}
1980
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1981
+		$payment                               = $transaction->get_first_related('Payment');
1982
+		$payment                               = ! $payment instanceof EE_Payment
1983
+			? EE_Payment::new_instance()
1984
+			: $payment;
1985
+		$payment_method                        = $payment->get_first_related('Payment_Method');
1986
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
1987
+			? EE_Payment_Method::new_instance()
1988
+			: $payment_method;
1989
+		$reg_details                           = array(
1990
+			'payment_method'       => $payment_method->name(),
1991
+			'response_msg'         => $payment->gateway_response(),
1992
+			'registration_id'      => $this->_registration->get('REG_code'),
1993
+			'registration_session' => $this->_registration->session_ID(),
1994
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1995
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1996
+		);
1997
+		if (isset($reg_details['registration_id'])) {
1998
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1999
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2000
+				'Registration ID',
2001
+				'event_espresso'
2002
+			);
2003
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2004
+		}
2005
+		if (isset($reg_details['payment_method'])) {
2006
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2007
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2008
+				'Most Recent Payment Method',
2009
+				'event_espresso'
2010
+			);
2011
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2012
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2013
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2014
+				'Payment method response',
2015
+				'event_espresso'
2016
+			);
2017
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2018
+		}
2019
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2020
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2021
+			'Registration Session',
2022
+			'event_espresso'
2023
+		);
2024
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2025
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2026
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2027
+			'Registration placed from IP',
2028
+			'event_espresso'
2029
+		);
2030
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2031
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2032
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__('Registrant User Agent',
2033
+			'event_espresso');
2034
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2035
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2036
+			array(
2037
+				'action'   => 'default',
2038
+				'event_id' => $this->_registration->event_ID(),
2039
+			),
2040
+			REG_ADMIN_URL
2041
+		);
2042
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
2043
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
2044
+		$template_path                                                        =
2045
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2046
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2047
+	}
2048
+
2049
+
2050
+	/**
2051
+	 * generates HTML for the Registration Questions meta box.
2052
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2053
+	 * otherwise uses new forms system
2054
+	 *
2055
+	 * @access public
2056
+	 * @return void
2057
+	 * @throws DomainException
2058
+	 * @throws EE_Error
2059
+	 */
2060
+	public function _reg_questions_meta_box()
2061
+	{
2062
+		//allow someone to override this method entirely
2063
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
2064
+			$this->_registration)) {
2065
+			$form                                              = $this->_get_reg_custom_questions_form(
2066
+				$this->_registration->ID()
2067
+			);
2068
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0
2069
+				? $form->get_html_and_js()
2070
+				: '';
2071
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2072
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
2073
+			$template_path                                     =
2074
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2075
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2076
+		}
2077
+	}
2078
+
2079
+
2080
+	/**
2081
+	 * form_before_question_group
2082
+	 *
2083
+	 * @deprecated    as of 4.8.32.rc.000
2084
+	 * @access        public
2085
+	 * @param        string $output
2086
+	 * @return        string
2087
+	 */
2088
+	public function form_before_question_group($output)
2089
+	{
2090
+		EE_Error::doing_it_wrong(
2091
+			__CLASS__ . '::' . __FUNCTION__,
2092
+			esc_html__(
2093
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2094
+				'event_espresso'
2095
+			),
2096
+			'4.8.32.rc.000'
2097
+		);
2098
+		return '
2099 2099
 	<table class="form-table ee-width-100">
2100 2100
 		<tbody>
2101 2101
 			';
2102
-    }
2103
-
2104
-
2105
-    /**
2106
-     * form_after_question_group
2107
-     *
2108
-     * @deprecated    as of 4.8.32.rc.000
2109
-     * @access        public
2110
-     * @param        string $output
2111
-     * @return        string
2112
-     */
2113
-    public function form_after_question_group($output)
2114
-    {
2115
-        EE_Error::doing_it_wrong(
2116
-            __CLASS__ . '::' . __FUNCTION__,
2117
-            esc_html__(
2118
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2119
-                'event_espresso'
2120
-            ),
2121
-            '4.8.32.rc.000'
2122
-        );
2123
-        return '
2102
+	}
2103
+
2104
+
2105
+	/**
2106
+	 * form_after_question_group
2107
+	 *
2108
+	 * @deprecated    as of 4.8.32.rc.000
2109
+	 * @access        public
2110
+	 * @param        string $output
2111
+	 * @return        string
2112
+	 */
2113
+	public function form_after_question_group($output)
2114
+	{
2115
+		EE_Error::doing_it_wrong(
2116
+			__CLASS__ . '::' . __FUNCTION__,
2117
+			esc_html__(
2118
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2119
+				'event_espresso'
2120
+			),
2121
+			'4.8.32.rc.000'
2122
+		);
2123
+		return '
2124 2124
 			<tr class="hide-if-no-js">
2125 2125
 				<th> </th>
2126 2126
 				<td class="reg-admin-edit-attendee-question-td">
2127 2127
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2128
-               . esc_attr__('click to edit question', 'event_espresso')
2129
-               . '">
2128
+			   . esc_attr__('click to edit question', 'event_espresso')
2129
+			   . '">
2130 2130
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2131
-               . esc_html__('edit the above question group', 'event_espresso')
2132
-               . '</span>
2131
+			   . esc_html__('edit the above question group', 'event_espresso')
2132
+			   . '</span>
2133 2133
 						<div class="dashicons dashicons-edit"></div>
2134 2134
 					</a>
2135 2135
 				</td>
@@ -2137,558 +2137,558 @@  discard block
 block discarded – undo
2137 2137
 		</tbody>
2138 2138
 	</table>
2139 2139
 ';
2140
-    }
2141
-
2142
-
2143
-    /**
2144
-     * form_form_field_label_wrap
2145
-     *
2146
-     * @deprecated    as of 4.8.32.rc.000
2147
-     * @access        public
2148
-     * @param        string $label
2149
-     * @return        string
2150
-     */
2151
-    public function form_form_field_label_wrap($label)
2152
-    {
2153
-        EE_Error::doing_it_wrong(
2154
-            __CLASS__ . '::' . __FUNCTION__,
2155
-            esc_html__(
2156
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2157
-                'event_espresso'
2158
-            ),
2159
-            '4.8.32.rc.000'
2160
-        );
2161
-        return '
2140
+	}
2141
+
2142
+
2143
+	/**
2144
+	 * form_form_field_label_wrap
2145
+	 *
2146
+	 * @deprecated    as of 4.8.32.rc.000
2147
+	 * @access        public
2148
+	 * @param        string $label
2149
+	 * @return        string
2150
+	 */
2151
+	public function form_form_field_label_wrap($label)
2152
+	{
2153
+		EE_Error::doing_it_wrong(
2154
+			__CLASS__ . '::' . __FUNCTION__,
2155
+			esc_html__(
2156
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2157
+				'event_espresso'
2158
+			),
2159
+			'4.8.32.rc.000'
2160
+		);
2161
+		return '
2162 2162
 			<tr>
2163 2163
 				<th>
2164 2164
 					' . $label . '
2165 2165
 				</th>';
2166
-    }
2167
-
2168
-
2169
-    /**
2170
-     * form_form_field_input__wrap
2171
-     *
2172
-     * @deprecated    as of 4.8.32.rc.000
2173
-     * @access        public
2174
-     * @param        string $input
2175
-     * @return        string
2176
-     */
2177
-    public function form_form_field_input__wrap($input)
2178
-    {
2179
-        EE_Error::doing_it_wrong(
2180
-            __CLASS__ . '::' . __FUNCTION__,
2181
-            esc_html__(
2182
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2183
-                'event_espresso'
2184
-            ),
2185
-            '4.8.32.rc.000'
2186
-        );
2187
-        return '
2166
+	}
2167
+
2168
+
2169
+	/**
2170
+	 * form_form_field_input__wrap
2171
+	 *
2172
+	 * @deprecated    as of 4.8.32.rc.000
2173
+	 * @access        public
2174
+	 * @param        string $input
2175
+	 * @return        string
2176
+	 */
2177
+	public function form_form_field_input__wrap($input)
2178
+	{
2179
+		EE_Error::doing_it_wrong(
2180
+			__CLASS__ . '::' . __FUNCTION__,
2181
+			esc_html__(
2182
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2183
+				'event_espresso'
2184
+			),
2185
+			'4.8.32.rc.000'
2186
+		);
2187
+		return '
2188 2188
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2189 2189
 					' . $input . '
2190 2190
 				</td>
2191 2191
 			</tr>';
2192
-    }
2193
-
2194
-
2195
-    /**
2196
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2197
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2198
-     * to display the page
2199
-     *
2200
-     * @access protected
2201
-     * @return void
2202
-     * @throws EE_Error
2203
-     */
2204
-    protected function _update_attendee_registration_form()
2205
-    {
2206
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2207
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2208
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2209
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2210
-            if ($success) {
2211
-                $what  = esc_html__('Registration Form', 'event_espresso');
2212
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2213
-                    : array('action' => 'default');
2214
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2215
-            }
2216
-        }
2217
-    }
2218
-
2219
-
2220
-    /**
2221
-     * Gets the form for saving registrations custom questions (if done
2222
-     * previously retrieves the cached form object, which may have validation errors in it)
2223
-     *
2224
-     * @param int $REG_ID
2225
-     * @return EE_Registration_Custom_Questions_Form
2226
-     * @throws EE_Error
2227
-     */
2228
-    protected function _get_reg_custom_questions_form($REG_ID)
2229
-    {
2230
-        if ( ! $this->_reg_custom_questions_form) {
2231
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2232
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2233
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2234
-            );
2235
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2236
-        }
2237
-        return $this->_reg_custom_questions_form;
2238
-    }
2239
-
2240
-
2241
-    /**
2242
-     * Saves
2243
-     *
2244
-     * @access private
2245
-     * @param bool $REG_ID
2246
-     * @return bool
2247
-     * @throws EE_Error
2248
-     */
2249
-    private function _save_reg_custom_questions_form($REG_ID = false)
2250
-    {
2251
-        if ( ! $REG_ID) {
2252
-            EE_Error::add_error(
2253
-                esc_html__(
2254
-                    'An error occurred. No registration ID was received.', 'event_espresso'),
2255
-                __FILE__, __FUNCTION__, __LINE__
2256
-            );
2257
-        }
2258
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2259
-        $form->receive_form_submission($this->_req_data);
2260
-        $success = false;
2261
-        if ($form->is_valid()) {
2262
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2263
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2264
-                    $where_conditions    = array(
2265
-                        'QST_ID' => $question_id,
2266
-                        'REG_ID' => $REG_ID,
2267
-                    );
2268
-                    $possibly_new_values = array(
2269
-                        'ANS_value' => $input->normalized_value(),
2270
-                    );
2271
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2272
-                    if ($answer instanceof EE_Answer) {
2273
-                        $success = $answer->save($possibly_new_values);
2274
-                    } else {
2275
-                        //insert it then
2276
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2277
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2278
-                        $success     = $answer->save();
2279
-                    }
2280
-                }
2281
-            }
2282
-        } else {
2283
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2284
-        }
2285
-        return $success;
2286
-    }
2287
-
2288
-
2289
-    /**
2290
-     *        generates HTML for the Registration main meta box
2291
-     *
2292
-     * @access public
2293
-     * @return void
2294
-     * @throws DomainException
2295
-     * @throws EE_Error
2296
-     */
2297
-    public function _reg_attendees_meta_box()
2298
-    {
2299
-        $REG = EEM_Registration::instance();
2300
-        //get all other registrations on this transaction, and cache
2301
-        //the attendees for them so we don't have to run another query using force_join
2302
-        $registrations                           = $REG->get_all(array(
2303
-            array(
2304
-                'TXN_ID' => $this->_registration->transaction_ID(),
2305
-                'REG_ID' => array('!=', $this->_registration->ID()),
2306
-            ),
2307
-            'force_join' => array('Attendee'),
2308
-        ));
2309
-        $this->_template_args['attendees']       = array();
2310
-        $this->_template_args['attendee_notice'] = '';
2311
-        if (empty($registrations)
2312
-            || (is_array($registrations)
2313
-                && ! EEH_Array::get_one_item_from_array($registrations))
2314
-        ) {
2315
-            EE_Error::add_error(
2316
-                esc_html__(
2317
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2318
-                    'event_espresso'
2319
-                ), __FILE__, __FUNCTION__, __LINE__
2320
-            );
2321
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2322
-        } else {
2323
-            $att_nmbr = 1;
2324
-            foreach ($registrations as $registration) {
2325
-                /* @var $registration EE_Registration */
2326
-                $attendee                                                    = $registration->attendee()
2327
-                    ? $registration->attendee()
2328
-                    : EEM_Attendee::instance()
2329
-                                  ->create_default_object();
2330
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2331
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2332
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2333
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2334
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2335
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2336
-                    ', ',
2337
-                    $attendee->full_address_as_array()
2338
-                );
2339
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2340
-                    array(
2341
-                        'action' => 'edit_attendee',
2342
-                        'post'   => $attendee->ID(),
2343
-                    ),
2344
-                    REG_ADMIN_URL
2345
-                );
2346
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2347
-                $att_nmbr++;
2348
-            }
2349
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2350
-        }
2351
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2352
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2353
-    }
2354
-
2355
-
2356
-    /**
2357
-     *        generates HTML for the Edit Registration side meta box
2358
-     *
2359
-     * @access public
2360
-     * @return void
2361
-     * @throws DomainException
2362
-     * @throws EE_Error
2363
-     */
2364
-    public function _reg_registrant_side_meta_box()
2365
-    {
2366
-        /*@var $attendee EE_Attendee */
2367
-        $att_check = $this->_registration->attendee();
2368
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2369
-        //now let's determine if this is not the primary registration.  If it isn't then we set the
2370
-        //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2371
-        //primary registration object (that way we know if we need to show create button or not)
2372
-        if ( ! $this->_registration->is_primary_registrant()) {
2373
-            $primary_registration = $this->_registration->get_primary_registration();
2374
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2375
-                : null;
2376
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2377
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2378
-                //custom attendee object so let's not worry about the primary reg.
2379
-                $primary_registration = null;
2380
-            }
2381
-        } else {
2382
-            $primary_registration = null;
2383
-        }
2384
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2385
-        $this->_template_args['fname']             = $attendee->fname();
2386
-        $this->_template_args['lname']             = $attendee->lname();
2387
-        $this->_template_args['email']             = $attendee->email();
2388
-        $this->_template_args['phone']             = $attendee->phone();
2389
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2390
-        //edit link
2391
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2392
-            'action' => 'edit_attendee',
2393
-            'post'   => $attendee->ID(),
2394
-        ), REG_ADMIN_URL);
2395
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2396
-        //create link
2397
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2398
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2399
-                'action'  => 'duplicate_attendee',
2400
-                '_REG_ID' => $this->_registration->ID(),
2401
-            ), REG_ADMIN_URL) : '';
2402
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2403
-        $this->_template_args['att_check']    = $att_check;
2404
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2405
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2406
-    }
2407
-
2408
-
2409
-    /**
2410
-     * trash or restore registrations
2411
-     *
2412
-     * @param  boolean $trash whether to archive or restore
2413
-     * @return void
2414
-     * @throws EE_Error
2415
-     * @throws RuntimeException
2416
-     * @access protected
2417
-     */
2418
-    protected function _trash_or_restore_registrations($trash = true)
2419
-    {
2420
-        //if empty _REG_ID then get out because there's nothing to do
2421
-        if (empty($this->_req_data['_REG_ID'])) {
2422
-            EE_Error::add_error(
2423
-                sprintf(
2424
-                    esc_html__(
2425
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2426
-                        'event_espresso'
2427
-                    ),
2428
-                    $trash ? 'trash' : 'restore'
2429
-                ),
2430
-                __FILE__, __LINE__, __FUNCTION__
2431
-            );
2432
-            $this->_redirect_after_action(false, '', '', array(), true);
2433
-        }
2434
-        $success = 0;
2435
-        $overwrite_msgs = false;
2436
-        //Checkboxes
2437
-        if ( ! is_array($this->_req_data['_REG_ID'])) {
2438
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2439
-        }
2440
-        $reg_count = count($this->_req_data['_REG_ID']);
2441
-        // cycle thru checkboxes
2442
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2443
-            /** @var EE_Registration $REG */
2444
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2445
-            $payments = $REG->registration_payments();
2446
-            if (! empty($payments)) {
2447
-                $name = $REG->attendee() instanceof EE_Attendee
2448
-                    ? $REG->attendee()->full_name()
2449
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2450
-                $overwrite_msgs = true;
2451
-                EE_Error::add_error(
2452
-                    sprintf(
2453
-                        esc_html__(
2454
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2455
-                            'event_espresso'
2456
-                        ),
2457
-                        $name
2458
-                    ),
2459
-                    __FILE__, __FUNCTION__, __LINE__
2460
-                );
2461
-                //can't trash this registration because it has payments.
2462
-                continue;
2463
-            }
2464
-            $updated = $trash ? $REG->delete() : $REG->restore();
2465
-            if ($updated) {
2466
-                $success++;
2467
-            }
2468
-        }
2469
-        $this->_redirect_after_action(
2470
-            $success === $reg_count, // were ALL registrations affected?
2471
-            $success > 1
2472
-                ? esc_html__('Registrations', 'event_espresso')
2473
-                : esc_html__('Registration', 'event_espresso'),
2474
-            $trash
2475
-                ? esc_html__('moved to the trash', 'event_espresso')
2476
-                : esc_html__('restored', 'event_espresso'),
2477
-            array('action' => 'default'),
2478
-            $overwrite_msgs
2479
-        );
2480
-    }
2481
-
2482
-
2483
-    /**
2484
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2485
-     * registration but also.
2486
-     * 1. Removing relations to EE_Attendee
2487
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2488
-     * ALSO trashed.
2489
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2490
-     * 4. Removing relationships between all tickets and the related registrations
2491
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2492
-     * 6. Deleting permanently any related Checkins.
2493
-     *
2494
-     * @return void
2495
-     * @throws EE_Error
2496
-     */
2497
-    protected function _delete_registrations()
2498
-    {
2499
-        $REG_MDL = EEM_Registration::instance();
2500
-        $success = 1;
2501
-        //Checkboxes
2502
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2503
-            // if array has more than one element than success message should be plural
2504
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2505
-            // cycle thru checkboxes
2506
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2507
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2508
-                if ( ! $REG instanceof EE_Registration) {
2509
-                    continue;
2510
-                }
2511
-                $deleted = $this->_delete_registration($REG);
2512
-                if ( ! $deleted) {
2513
-                    $success = 0;
2514
-                }
2515
-            }
2516
-        } else {
2517
-            // grab single id and delete
2518
-            $REG_ID  = $this->_req_data['_REG_ID'];
2519
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2520
-            $deleted = $this->_delete_registration($REG);
2521
-            if ( ! $deleted) {
2522
-                $success = 0;
2523
-            }
2524
-        }
2525
-        $what        = $success > 1
2526
-            ? esc_html__('Registrations', 'event_espresso')
2527
-            : esc_html__('Registration', 'event_espresso');
2528
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2529
-        $this->_redirect_after_action(
2530
-            $success,
2531
-            $what,
2532
-            $action_desc,
2533
-            array('action' => 'default'),
2534
-            true
2535
-        );
2536
-    }
2537
-
2538
-
2539
-    /**
2540
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2541
-     * models get affected.
2542
-     *
2543
-     * @param  EE_Registration $REG registration to be deleted permenantly
2544
-     * @return bool true = successful deletion, false = fail.
2545
-     * @throws EE_Error
2546
-     */
2547
-    protected function _delete_registration(EE_Registration $REG)
2548
-    {
2549
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2550
-        //registrations on the transaction that are NOT trashed.
2551
-        $TXN         = $REG->get_first_related('Transaction');
2552
-        $REGS        = $TXN->get_many_related('Registration');
2553
-        $all_trashed = true;
2554
-        foreach ($REGS as $registration) {
2555
-            if ( ! $registration->get('REG_deleted')) {
2556
-                $all_trashed = false;
2557
-            }
2558
-        }
2559
-        if ( ! $all_trashed) {
2560
-            EE_Error::add_error(
2561
-                esc_html__(
2562
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2563
-                    'event_espresso'
2564
-                ),
2565
-                __FILE__, __FUNCTION__, __LINE__
2566
-            );
2567
-            return false;
2568
-        }
2569
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them
2570
-        //separately from THIS one).
2571
-        foreach ($REGS as $registration) {
2572
-            //delete related answers
2573
-            $registration->delete_related_permanently('Answer');
2574
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2575
-            $attendee = $registration->get_first_related('Attendee');
2576
-            if ($attendee instanceof EE_Attendee) {
2577
-                $registration->_remove_relation_to($attendee, 'Attendee');
2578
-            }
2579
-            //now remove relationships to tickets on this registration.
2580
-            $registration->_remove_relations('Ticket');
2581
-            //now delete permanently the checkins related to this registration.
2582
-            $registration->delete_related_permanently('Checkin');
2583
-            if ($registration->ID() === $REG->ID()) {
2584
-                continue;
2585
-            } //we don't want to delete permanently the existing registration just yet.
2586
-            //remove relation to transaction for these registrations if NOT the existing registrations
2587
-            $registration->_remove_relations('Transaction');
2588
-            //delete permanently any related messages.
2589
-            $registration->delete_related_permanently('Message');
2590
-            //now delete this registration permanently
2591
-            $registration->delete_permanently();
2592
-        }
2593
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself
2594
-        // (the transaction and line items should be all that's left).
2595
-        // delete the line items related to the transaction for this registration.
2596
-        $TXN->delete_related_permanently('Line_Item');
2597
-        //we need to remove all the relationships on the transaction
2598
-        $TXN->delete_related_permanently('Payment');
2599
-        $TXN->delete_related_permanently('Extra_Meta');
2600
-        $TXN->delete_related_permanently('Message');
2601
-        //now we can delete this REG permanently (and the transaction of course)
2602
-        $REG->delete_related_permanently('Transaction');
2603
-        return $REG->delete_permanently();
2604
-    }
2605
-
2606
-
2607
-    /**
2608
-     *    generates HTML for the Register New Attendee Admin page
2609
-     *
2610
-     * @access private
2611
-     * @throws DomainException
2612
-     * @throws EE_Error
2613
-     */
2614
-    public function new_registration()
2615
-    {
2616
-        if ( ! $this->_set_reg_event()) {
2617
-            throw new EE_Error(
2618
-                esc_html__(
2619
-                    'Unable to continue with registering because there is no Event ID in the request',
2620
-                    'event_espresso'
2621
-                )
2622
-            );
2623
-        }
2624
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2625
-        // gotta start with a clean slate if we're not coming here via ajax
2626
-        if ( ! defined('DOING_AJAX')
2627
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2628
-        ) {
2629
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2630
-        }
2631
-        $this->_template_args['event_name'] = '';
2632
-        // event name
2633
-        if ($this->_reg_event) {
2634
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2635
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2636
-                'action' => 'edit',
2637
-                'post'   => $this->_reg_event->ID(),
2638
-            ), EVENTS_ADMIN_URL);
2639
-            $edit_event_lnk                     = '<a href="'
2640
-                                                  . $edit_event_url
2641
-                                                  . '" title="'
2642
-                                                  . esc_attr__('Edit ', 'event_espresso')
2643
-                                                  . $this->_reg_event->name()
2644
-                                                  . '">'
2645
-                                                  . esc_html__('Edit Event', 'event_espresso')
2646
-                                                  . '</a>';
2647
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2648
-                                                   . $edit_event_lnk
2649
-                                                   . '</span>';
2650
-        }
2651
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2652
-        if (defined('DOING_AJAX')) {
2653
-            $this->_return_json();
2654
-        }
2655
-        // grab header
2656
-        $template_path                              =
2657
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2658
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2659
-            $this->_template_args, true);
2660
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2661
-        // the details template wrapper
2662
-        $this->display_admin_page_with_sidebar();
2663
-    }
2664
-
2665
-
2666
-    /**
2667
-     * This returns the content for a registration step
2668
-     *
2669
-     * @access protected
2670
-     * @return string html
2671
-     * @throws DomainException
2672
-     * @throws EE_Error
2673
-     */
2674
-    protected function _get_registration_step_content()
2675
-    {
2676
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2677
-            $warning_msg = sprintf(
2678
-                esc_html__(
2679
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2680
-                    'event_espresso'
2681
-                ),
2682
-                '<br />',
2683
-                '<h3 class="important-notice">',
2684
-                '</h3>',
2685
-                '<div class="float-right">',
2686
-                '<span id="redirect_timer" class="important-notice">30</span>',
2687
-                '</div>',
2688
-                '<b>',
2689
-                '</b>'
2690
-            );
2691
-            return '
2192
+	}
2193
+
2194
+
2195
+	/**
2196
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2197
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2198
+	 * to display the page
2199
+	 *
2200
+	 * @access protected
2201
+	 * @return void
2202
+	 * @throws EE_Error
2203
+	 */
2204
+	protected function _update_attendee_registration_form()
2205
+	{
2206
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2207
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2208
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2209
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2210
+			if ($success) {
2211
+				$what  = esc_html__('Registration Form', 'event_espresso');
2212
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2213
+					: array('action' => 'default');
2214
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2215
+			}
2216
+		}
2217
+	}
2218
+
2219
+
2220
+	/**
2221
+	 * Gets the form for saving registrations custom questions (if done
2222
+	 * previously retrieves the cached form object, which may have validation errors in it)
2223
+	 *
2224
+	 * @param int $REG_ID
2225
+	 * @return EE_Registration_Custom_Questions_Form
2226
+	 * @throws EE_Error
2227
+	 */
2228
+	protected function _get_reg_custom_questions_form($REG_ID)
2229
+	{
2230
+		if ( ! $this->_reg_custom_questions_form) {
2231
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2232
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2233
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2234
+			);
2235
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2236
+		}
2237
+		return $this->_reg_custom_questions_form;
2238
+	}
2239
+
2240
+
2241
+	/**
2242
+	 * Saves
2243
+	 *
2244
+	 * @access private
2245
+	 * @param bool $REG_ID
2246
+	 * @return bool
2247
+	 * @throws EE_Error
2248
+	 */
2249
+	private function _save_reg_custom_questions_form($REG_ID = false)
2250
+	{
2251
+		if ( ! $REG_ID) {
2252
+			EE_Error::add_error(
2253
+				esc_html__(
2254
+					'An error occurred. No registration ID was received.', 'event_espresso'),
2255
+				__FILE__, __FUNCTION__, __LINE__
2256
+			);
2257
+		}
2258
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2259
+		$form->receive_form_submission($this->_req_data);
2260
+		$success = false;
2261
+		if ($form->is_valid()) {
2262
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2263
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2264
+					$where_conditions    = array(
2265
+						'QST_ID' => $question_id,
2266
+						'REG_ID' => $REG_ID,
2267
+					);
2268
+					$possibly_new_values = array(
2269
+						'ANS_value' => $input->normalized_value(),
2270
+					);
2271
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
2272
+					if ($answer instanceof EE_Answer) {
2273
+						$success = $answer->save($possibly_new_values);
2274
+					} else {
2275
+						//insert it then
2276
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2277
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2278
+						$success     = $answer->save();
2279
+					}
2280
+				}
2281
+			}
2282
+		} else {
2283
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2284
+		}
2285
+		return $success;
2286
+	}
2287
+
2288
+
2289
+	/**
2290
+	 *        generates HTML for the Registration main meta box
2291
+	 *
2292
+	 * @access public
2293
+	 * @return void
2294
+	 * @throws DomainException
2295
+	 * @throws EE_Error
2296
+	 */
2297
+	public function _reg_attendees_meta_box()
2298
+	{
2299
+		$REG = EEM_Registration::instance();
2300
+		//get all other registrations on this transaction, and cache
2301
+		//the attendees for them so we don't have to run another query using force_join
2302
+		$registrations                           = $REG->get_all(array(
2303
+			array(
2304
+				'TXN_ID' => $this->_registration->transaction_ID(),
2305
+				'REG_ID' => array('!=', $this->_registration->ID()),
2306
+			),
2307
+			'force_join' => array('Attendee'),
2308
+		));
2309
+		$this->_template_args['attendees']       = array();
2310
+		$this->_template_args['attendee_notice'] = '';
2311
+		if (empty($registrations)
2312
+			|| (is_array($registrations)
2313
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2314
+		) {
2315
+			EE_Error::add_error(
2316
+				esc_html__(
2317
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2318
+					'event_espresso'
2319
+				), __FILE__, __FUNCTION__, __LINE__
2320
+			);
2321
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2322
+		} else {
2323
+			$att_nmbr = 1;
2324
+			foreach ($registrations as $registration) {
2325
+				/* @var $registration EE_Registration */
2326
+				$attendee                                                    = $registration->attendee()
2327
+					? $registration->attendee()
2328
+					: EEM_Attendee::instance()
2329
+								  ->create_default_object();
2330
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2331
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2332
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2333
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2334
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2335
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2336
+					', ',
2337
+					$attendee->full_address_as_array()
2338
+				);
2339
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(
2340
+					array(
2341
+						'action' => 'edit_attendee',
2342
+						'post'   => $attendee->ID(),
2343
+					),
2344
+					REG_ADMIN_URL
2345
+				);
2346
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2347
+				$att_nmbr++;
2348
+			}
2349
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2350
+		}
2351
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2352
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2353
+	}
2354
+
2355
+
2356
+	/**
2357
+	 *        generates HTML for the Edit Registration side meta box
2358
+	 *
2359
+	 * @access public
2360
+	 * @return void
2361
+	 * @throws DomainException
2362
+	 * @throws EE_Error
2363
+	 */
2364
+	public function _reg_registrant_side_meta_box()
2365
+	{
2366
+		/*@var $attendee EE_Attendee */
2367
+		$att_check = $this->_registration->attendee();
2368
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2369
+		//now let's determine if this is not the primary registration.  If it isn't then we set the
2370
+		//primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2371
+		//primary registration object (that way we know if we need to show create button or not)
2372
+		if ( ! $this->_registration->is_primary_registrant()) {
2373
+			$primary_registration = $this->_registration->get_primary_registration();
2374
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2375
+				: null;
2376
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2377
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2378
+				//custom attendee object so let's not worry about the primary reg.
2379
+				$primary_registration = null;
2380
+			}
2381
+		} else {
2382
+			$primary_registration = null;
2383
+		}
2384
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2385
+		$this->_template_args['fname']             = $attendee->fname();
2386
+		$this->_template_args['lname']             = $attendee->lname();
2387
+		$this->_template_args['email']             = $attendee->email();
2388
+		$this->_template_args['phone']             = $attendee->phone();
2389
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2390
+		//edit link
2391
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2392
+			'action' => 'edit_attendee',
2393
+			'post'   => $attendee->ID(),
2394
+		), REG_ADMIN_URL);
2395
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2396
+		//create link
2397
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2398
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2399
+				'action'  => 'duplicate_attendee',
2400
+				'_REG_ID' => $this->_registration->ID(),
2401
+			), REG_ADMIN_URL) : '';
2402
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2403
+		$this->_template_args['att_check']    = $att_check;
2404
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2405
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2406
+	}
2407
+
2408
+
2409
+	/**
2410
+	 * trash or restore registrations
2411
+	 *
2412
+	 * @param  boolean $trash whether to archive or restore
2413
+	 * @return void
2414
+	 * @throws EE_Error
2415
+	 * @throws RuntimeException
2416
+	 * @access protected
2417
+	 */
2418
+	protected function _trash_or_restore_registrations($trash = true)
2419
+	{
2420
+		//if empty _REG_ID then get out because there's nothing to do
2421
+		if (empty($this->_req_data['_REG_ID'])) {
2422
+			EE_Error::add_error(
2423
+				sprintf(
2424
+					esc_html__(
2425
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2426
+						'event_espresso'
2427
+					),
2428
+					$trash ? 'trash' : 'restore'
2429
+				),
2430
+				__FILE__, __LINE__, __FUNCTION__
2431
+			);
2432
+			$this->_redirect_after_action(false, '', '', array(), true);
2433
+		}
2434
+		$success = 0;
2435
+		$overwrite_msgs = false;
2436
+		//Checkboxes
2437
+		if ( ! is_array($this->_req_data['_REG_ID'])) {
2438
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2439
+		}
2440
+		$reg_count = count($this->_req_data['_REG_ID']);
2441
+		// cycle thru checkboxes
2442
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2443
+			/** @var EE_Registration $REG */
2444
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2445
+			$payments = $REG->registration_payments();
2446
+			if (! empty($payments)) {
2447
+				$name = $REG->attendee() instanceof EE_Attendee
2448
+					? $REG->attendee()->full_name()
2449
+					: esc_html__('Unknown Attendee', 'event_espresso');
2450
+				$overwrite_msgs = true;
2451
+				EE_Error::add_error(
2452
+					sprintf(
2453
+						esc_html__(
2454
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2455
+							'event_espresso'
2456
+						),
2457
+						$name
2458
+					),
2459
+					__FILE__, __FUNCTION__, __LINE__
2460
+				);
2461
+				//can't trash this registration because it has payments.
2462
+				continue;
2463
+			}
2464
+			$updated = $trash ? $REG->delete() : $REG->restore();
2465
+			if ($updated) {
2466
+				$success++;
2467
+			}
2468
+		}
2469
+		$this->_redirect_after_action(
2470
+			$success === $reg_count, // were ALL registrations affected?
2471
+			$success > 1
2472
+				? esc_html__('Registrations', 'event_espresso')
2473
+				: esc_html__('Registration', 'event_espresso'),
2474
+			$trash
2475
+				? esc_html__('moved to the trash', 'event_espresso')
2476
+				: esc_html__('restored', 'event_espresso'),
2477
+			array('action' => 'default'),
2478
+			$overwrite_msgs
2479
+		);
2480
+	}
2481
+
2482
+
2483
+	/**
2484
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2485
+	 * registration but also.
2486
+	 * 1. Removing relations to EE_Attendee
2487
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2488
+	 * ALSO trashed.
2489
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2490
+	 * 4. Removing relationships between all tickets and the related registrations
2491
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2492
+	 * 6. Deleting permanently any related Checkins.
2493
+	 *
2494
+	 * @return void
2495
+	 * @throws EE_Error
2496
+	 */
2497
+	protected function _delete_registrations()
2498
+	{
2499
+		$REG_MDL = EEM_Registration::instance();
2500
+		$success = 1;
2501
+		//Checkboxes
2502
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2503
+			// if array has more than one element than success message should be plural
2504
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2505
+			// cycle thru checkboxes
2506
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2507
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2508
+				if ( ! $REG instanceof EE_Registration) {
2509
+					continue;
2510
+				}
2511
+				$deleted = $this->_delete_registration($REG);
2512
+				if ( ! $deleted) {
2513
+					$success = 0;
2514
+				}
2515
+			}
2516
+		} else {
2517
+			// grab single id and delete
2518
+			$REG_ID  = $this->_req_data['_REG_ID'];
2519
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2520
+			$deleted = $this->_delete_registration($REG);
2521
+			if ( ! $deleted) {
2522
+				$success = 0;
2523
+			}
2524
+		}
2525
+		$what        = $success > 1
2526
+			? esc_html__('Registrations', 'event_espresso')
2527
+			: esc_html__('Registration', 'event_espresso');
2528
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2529
+		$this->_redirect_after_action(
2530
+			$success,
2531
+			$what,
2532
+			$action_desc,
2533
+			array('action' => 'default'),
2534
+			true
2535
+		);
2536
+	}
2537
+
2538
+
2539
+	/**
2540
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2541
+	 * models get affected.
2542
+	 *
2543
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2544
+	 * @return bool true = successful deletion, false = fail.
2545
+	 * @throws EE_Error
2546
+	 */
2547
+	protected function _delete_registration(EE_Registration $REG)
2548
+	{
2549
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2550
+		//registrations on the transaction that are NOT trashed.
2551
+		$TXN         = $REG->get_first_related('Transaction');
2552
+		$REGS        = $TXN->get_many_related('Registration');
2553
+		$all_trashed = true;
2554
+		foreach ($REGS as $registration) {
2555
+			if ( ! $registration->get('REG_deleted')) {
2556
+				$all_trashed = false;
2557
+			}
2558
+		}
2559
+		if ( ! $all_trashed) {
2560
+			EE_Error::add_error(
2561
+				esc_html__(
2562
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2563
+					'event_espresso'
2564
+				),
2565
+				__FILE__, __FUNCTION__, __LINE__
2566
+			);
2567
+			return false;
2568
+		}
2569
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them
2570
+		//separately from THIS one).
2571
+		foreach ($REGS as $registration) {
2572
+			//delete related answers
2573
+			$registration->delete_related_permanently('Answer');
2574
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2575
+			$attendee = $registration->get_first_related('Attendee');
2576
+			if ($attendee instanceof EE_Attendee) {
2577
+				$registration->_remove_relation_to($attendee, 'Attendee');
2578
+			}
2579
+			//now remove relationships to tickets on this registration.
2580
+			$registration->_remove_relations('Ticket');
2581
+			//now delete permanently the checkins related to this registration.
2582
+			$registration->delete_related_permanently('Checkin');
2583
+			if ($registration->ID() === $REG->ID()) {
2584
+				continue;
2585
+			} //we don't want to delete permanently the existing registration just yet.
2586
+			//remove relation to transaction for these registrations if NOT the existing registrations
2587
+			$registration->_remove_relations('Transaction');
2588
+			//delete permanently any related messages.
2589
+			$registration->delete_related_permanently('Message');
2590
+			//now delete this registration permanently
2591
+			$registration->delete_permanently();
2592
+		}
2593
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself
2594
+		// (the transaction and line items should be all that's left).
2595
+		// delete the line items related to the transaction for this registration.
2596
+		$TXN->delete_related_permanently('Line_Item');
2597
+		//we need to remove all the relationships on the transaction
2598
+		$TXN->delete_related_permanently('Payment');
2599
+		$TXN->delete_related_permanently('Extra_Meta');
2600
+		$TXN->delete_related_permanently('Message');
2601
+		//now we can delete this REG permanently (and the transaction of course)
2602
+		$REG->delete_related_permanently('Transaction');
2603
+		return $REG->delete_permanently();
2604
+	}
2605
+
2606
+
2607
+	/**
2608
+	 *    generates HTML for the Register New Attendee Admin page
2609
+	 *
2610
+	 * @access private
2611
+	 * @throws DomainException
2612
+	 * @throws EE_Error
2613
+	 */
2614
+	public function new_registration()
2615
+	{
2616
+		if ( ! $this->_set_reg_event()) {
2617
+			throw new EE_Error(
2618
+				esc_html__(
2619
+					'Unable to continue with registering because there is no Event ID in the request',
2620
+					'event_espresso'
2621
+				)
2622
+			);
2623
+		}
2624
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2625
+		// gotta start with a clean slate if we're not coming here via ajax
2626
+		if ( ! defined('DOING_AJAX')
2627
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2628
+		) {
2629
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2630
+		}
2631
+		$this->_template_args['event_name'] = '';
2632
+		// event name
2633
+		if ($this->_reg_event) {
2634
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2635
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2636
+				'action' => 'edit',
2637
+				'post'   => $this->_reg_event->ID(),
2638
+			), EVENTS_ADMIN_URL);
2639
+			$edit_event_lnk                     = '<a href="'
2640
+												  . $edit_event_url
2641
+												  . '" title="'
2642
+												  . esc_attr__('Edit ', 'event_espresso')
2643
+												  . $this->_reg_event->name()
2644
+												  . '">'
2645
+												  . esc_html__('Edit Event', 'event_espresso')
2646
+												  . '</a>';
2647
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2648
+												   . $edit_event_lnk
2649
+												   . '</span>';
2650
+		}
2651
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2652
+		if (defined('DOING_AJAX')) {
2653
+			$this->_return_json();
2654
+		}
2655
+		// grab header
2656
+		$template_path                              =
2657
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2658
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2659
+			$this->_template_args, true);
2660
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2661
+		// the details template wrapper
2662
+		$this->display_admin_page_with_sidebar();
2663
+	}
2664
+
2665
+
2666
+	/**
2667
+	 * This returns the content for a registration step
2668
+	 *
2669
+	 * @access protected
2670
+	 * @return string html
2671
+	 * @throws DomainException
2672
+	 * @throws EE_Error
2673
+	 */
2674
+	protected function _get_registration_step_content()
2675
+	{
2676
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2677
+			$warning_msg = sprintf(
2678
+				esc_html__(
2679
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2680
+					'event_espresso'
2681
+				),
2682
+				'<br />',
2683
+				'<h3 class="important-notice">',
2684
+				'</h3>',
2685
+				'<div class="float-right">',
2686
+				'<span id="redirect_timer" class="important-notice">30</span>',
2687
+				'</div>',
2688
+				'<b>',
2689
+				'</b>'
2690
+			);
2691
+			return '
2692 2692
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2693 2693
 	<script >
2694 2694
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2701,792 +2701,792 @@  discard block
 block discarded – undo
2701 2701
 	        }
2702 2702
 	    }, 800 );
2703 2703
 	</script >';
2704
-        }
2705
-        $template_args = array(
2706
-            'title'                    => '',
2707
-            'content'                  => '',
2708
-            'step_button_text'         => '',
2709
-            'show_notification_toggle' => false,
2710
-        );
2711
-        //to indicate we're processing a new registration
2712
-        $hidden_fields = array(
2713
-            'processing_registration' => array(
2714
-                'type'  => 'hidden',
2715
-                'value' => 0,
2716
-            ),
2717
-            'event_id'                => array(
2718
-                'type'  => 'hidden',
2719
-                'value' => $this->_reg_event->ID(),
2720
-            ),
2721
-        );
2722
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2723
-        $cart = EE_Registry::instance()->SSN->cart();
2724
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2725
-        switch ($step) {
2726
-            case 'ticket' :
2727
-                $hidden_fields['processing_registration']['value'] = 1;
2728
-                $template_args['title']                            = esc_html__(
2729
-                    'Step One: Select the Ticket for this registration',
2730
-                    'event_espresso'
2731
-                );
2732
-                $template_args['content']                          =
2733
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2734
-                $template_args['step_button_text']                 = esc_html__(
2735
-                    'Add Tickets and Continue to Registrant Details',
2736
-                    'event_espresso'
2737
-                );
2738
-                $template_args['show_notification_toggle']         = false;
2739
-                break;
2740
-            case 'questions' :
2741
-                $hidden_fields['processing_registration']['value'] = 2;
2742
-                $template_args['title']                            = esc_html__(
2743
-                    'Step Two: Add Registrant Details for this Registration',
2744
-                    'event_espresso'
2745
-                );
2746
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2747
-                // properly by the first process_reg_step run.
2748
-                $template_args['content']                  =
2749
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2750
-                $template_args['step_button_text']         = esc_html__(
2751
-                    'Save Registration and Continue to Details',
2752
-                    'event_espresso'
2753
-                );
2754
-                $template_args['show_notification_toggle'] = true;
2755
-                break;
2756
-        }
2757
-        //we come back to the process_registration_step route.
2758
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2759
-        return EEH_Template::display_template(
2760
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2761
-            $template_args,
2762
-            true
2763
-        );
2764
-    }
2765
-
2766
-
2767
-    /**
2768
-     *        set_reg_event
2769
-     *
2770
-     * @access private
2771
-     * @return bool
2772
-     * @throws EE_Error
2773
-     */
2774
-    private function _set_reg_event()
2775
-    {
2776
-        if (is_object($this->_reg_event)) {
2777
-            return true;
2778
-        }
2779
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2780
-        if ( ! $EVT_ID) {
2781
-            return false;
2782
-        }
2783
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2784
-        return true;
2785
-    }
2786
-
2787
-
2788
-    /**
2789
-     * process_reg_step
2790
-     *
2791
-     * @access        public
2792
-     * @return string
2793
-     * @throws DomainException
2794
-     * @throws EE_Error
2795
-     * @throws RuntimeException
2796
-     */
2797
-    public function process_reg_step()
2798
-    {
2799
-        EE_System::do_not_cache();
2800
-        $this->_set_reg_event();
2801
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2802
-        EE_Registry::instance()->REQ->set('uts', time());
2803
-        //what step are we on?
2804
-        $cart = EE_Registry::instance()->SSN->cart();
2805
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2806
-        //if doing ajax then we need to verify the nonce
2807
-        if (defined('DOING_AJAX')) {
2808
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2809
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2810
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2811
-        }
2812
-        switch ($step) {
2813
-            case 'ticket' :
2814
-                //process ticket selection
2815
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2816
-                if ($success) {
2817
-                    EE_Error::add_success(
2818
-                        esc_html__(
2819
-                            'Tickets Selected. Now complete the registration.',
2820
-                            'event_espresso'
2821
-                        )
2822
-                    );
2823
-                } else {
2824
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2825
-                }
2826
-                if (defined('DOING_AJAX')) {
2827
-                    $this->new_registration(); //display next step
2828
-                } else {
2829
-                    $query_args = array(
2830
-                        'action'                  => 'new_registration',
2831
-                        'processing_registration' => 1,
2832
-                        'event_id'                => $this->_reg_event->ID(),
2833
-                        'uts'                     => time(),
2834
-                    );
2835
-                    $this->_redirect_after_action(
2836
-                        false,
2837
-                        '',
2838
-                        '',
2839
-                        $query_args,
2840
-                        true
2841
-                    );
2842
-                }
2843
-                break;
2844
-            case 'questions' :
2845
-                if (! isset(
2846
-                    $this->_req_data['txn_reg_status_change'],
2847
-                    $this->_req_data['txn_reg_status_change']['send_notifications'])
2848
-                ) {
2849
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2850
-                }
2851
-                //process registration
2852
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2853
-                if ($cart instanceof EE_Cart) {
2854
-                    $grand_total = $cart->get_cart_grand_total();
2855
-                    if ($grand_total instanceof EE_Line_Item) {
2856
-                        $grand_total->save_this_and_descendants_to_txn();
2857
-                    }
2858
-                }
2859
-                if ( ! $transaction instanceof EE_Transaction) {
2860
-                    $query_args = array(
2861
-                        'action'                  => 'new_registration',
2862
-                        'processing_registration' => 2,
2863
-                        'event_id'                => $this->_reg_event->ID(),
2864
-                        'uts'                     => time(),
2865
-                    );
2866
-                    if (defined('DOING_AJAX')) {
2867
-                        //display registration form again because there are errors (maybe validation?)
2868
-                        $this->new_registration();
2869
-                        return;
2870
-                    } else {
2871
-                        $this->_redirect_after_action(
2872
-                            false,
2873
-                            '',
2874
-                            '',
2875
-                            $query_args,
2876
-                            true
2877
-                        );
2878
-                        return;
2879
-                    }
2880
-                }
2881
-                // maybe update status, and make sure to save transaction if not done already
2882
-                if ( ! $transaction->update_status_based_on_total_paid()) {
2883
-                    $transaction->save();
2884
-                }
2885
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2886
-                $this->_req_data = array();
2887
-                $query_args      = array(
2888
-                    'action'        => 'redirect_to_txn',
2889
-                    'TXN_ID'        => $transaction->ID(),
2890
-                    'EVT_ID'        => $this->_reg_event->ID(),
2891
-                    'event_name'    => urlencode($this->_reg_event->name()),
2892
-                    'redirect_from' => 'new_registration',
2893
-                );
2894
-                $this->_redirect_after_action(false, '', '', $query_args, true);
2895
-                break;
2896
-        }
2897
-        //what are you looking here for?  Should be nothing to do at this point.
2898
-    }
2899
-
2900
-
2901
-    /**
2902
-     * redirect_to_txn
2903
-     *
2904
-     * @access public
2905
-     * @return void
2906
-     * @throws EE_Error
2907
-     */
2908
-    public function redirect_to_txn()
2909
-    {
2910
-        EE_System::do_not_cache();
2911
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2912
-        $query_args = array(
2913
-            'action' => 'view_transaction',
2914
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2915
-            'page'   => 'espresso_transactions',
2916
-        );
2917
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2918
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2919
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
2920
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
2921
-        }
2922
-        EE_Error::add_success(
2923
-            esc_html__(
2924
-                'Registration Created.  Please review the transaction and add any payments as necessary',
2925
-                'event_espresso'
2926
-            )
2927
-        );
2928
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2929
-    }
2930
-
2931
-
2932
-    /**
2933
-     *        generates HTML for the Attendee Contact List
2934
-     *
2935
-     * @access protected
2936
-     * @return void
2937
-     */
2938
-    protected function _attendee_contact_list_table()
2939
-    {
2940
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2941
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
2942
-        $this->display_admin_list_table_page_with_no_sidebar();
2943
-    }
2944
-
2945
-
2946
-    /**
2947
-     *        get_attendees
2948
-     *
2949
-     * @param      $per_page
2950
-     * @param bool $count whether to return count or data.
2951
-     * @param bool $trash
2952
-     * @return array
2953
-     * @throws EE_Error
2954
-     * @access public
2955
-     */
2956
-    public function get_attendees($per_page, $count = false, $trash = false)
2957
-    {
2958
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2959
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2960
-        $ATT_MDL                    = EEM_Attendee::instance();
2961
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2962
-        switch ($this->_req_data['orderby']) {
2963
-            case 'ATT_ID':
2964
-                $orderby = 'ATT_ID';
2965
-                break;
2966
-            case 'ATT_fname':
2967
-                $orderby = 'ATT_fname';
2968
-                break;
2969
-            case 'ATT_email':
2970
-                $orderby = 'ATT_email';
2971
-                break;
2972
-            case 'ATT_city':
2973
-                $orderby = 'ATT_city';
2974
-                break;
2975
-            case 'STA_ID':
2976
-                $orderby = 'STA_ID';
2977
-                break;
2978
-            case 'CNT_ID':
2979
-                $orderby = 'CNT_ID';
2980
-                break;
2981
-            default:
2982
-                $orderby = 'ATT_lname';
2983
-        }
2984
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
2985
-            ? $this->_req_data['order']
2986
-            : 'ASC';
2987
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2988
-            ? $this->_req_data['paged']
2989
-            : 1;
2990
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2991
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2992
-            ? $this->_req_data['perpage']
2993
-            : $per_page;
2994
-        $_where       = array();
2995
-        if ( ! empty($this->_req_data['s'])) {
2996
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2997
-            $_where['OR'] = array(
2998
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2999
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3000
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3001
-                'ATT_fname'                         => array('LIKE', $sstr),
3002
-                'ATT_lname'                         => array('LIKE', $sstr),
3003
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3004
-                'ATT_email'                         => array('LIKE', $sstr),
3005
-                'ATT_address'                       => array('LIKE', $sstr),
3006
-                'ATT_address2'                      => array('LIKE', $sstr),
3007
-                'ATT_city'                          => array('LIKE', $sstr),
3008
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3009
-                'State.STA_name'                    => array('LIKE', $sstr),
3010
-                'ATT_phone'                         => array('LIKE', $sstr),
3011
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3012
-                'Registration.REG_code'             => array('LIKE', $sstr),
3013
-                'Registration.REG_count'            => array('LIKE', $sstr),
3014
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3015
-            );
3016
-        }
3017
-        $offset = ($current_page - 1) * $per_page;
3018
-        $limit  = $count ? null : array($offset, $per_page);
3019
-        if ($trash) {
3020
-            $_where['status'] = array('!=', 'publish');
3021
-            $all_attendees    = $count
3022
-                ? $ATT_MDL->count(array(
3023
-                    $_where,
3024
-                    'order_by' => array($orderby => $sort),
3025
-                    'limit'    => $limit,
3026
-                ), 'ATT_ID', true)
3027
-                : $ATT_MDL->get_all(array(
3028
-                    $_where,
3029
-                    'order_by' => array($orderby => $sort),
3030
-                    'limit'    => $limit,
3031
-                ));
3032
-        } else {
3033
-            $_where['status'] = array('IN', array('publish'));
3034
-            $all_attendees    = $count
3035
-                ? $ATT_MDL->count(array(
3036
-                    $_where,
3037
-                    'order_by' => array($orderby => $sort),
3038
-                    'limit'    => $limit,
3039
-                ), 'ATT_ID', true)
3040
-                : $ATT_MDL->get_all(array(
3041
-                    $_where,
3042
-                    'order_by' => array($orderby => $sort),
3043
-                    'limit'    => $limit,
3044
-                ));
3045
-        }
3046
-        return $all_attendees;
3047
-    }
3048
-
3049
-
3050
-    /**
3051
-     * This is just taking care of resending the registration confirmation
3052
-     *
3053
-     * @access protected
3054
-     * @return void
3055
-     */
3056
-    protected function _resend_registration()
3057
-    {
3058
-        $this->_process_resend_registration();
3059
-        $query_args = isset($this->_req_data['redirect_to'])
3060
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3061
-            : array('action' => 'default');
3062
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3063
-    }
3064
-
3065
-    /**
3066
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3067
-     * to use when selecting registrations
3068
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3069
-     *                                                     the query parameters from the request
3070
-     * @return void ends the request with a redirect or download
3071
-     */
3072
-    public function _registrations_report_base( $method_name_for_getting_query_params )
3073
-    {
3074
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3075
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3076
-                array(
3077
-                    'page'        => 'espresso_batch',
3078
-                    'batch'       => 'file',
3079
-                    'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3080
-                    'filters'     => urlencode(
3081
-                        serialize(
3082
-                            call_user_func(
3083
-                                array( $this, $method_name_for_getting_query_params ),
3084
-                                EEH_Array::is_set(
3085
-                                    $this->_req_data,
3086
-                                    'filters',
3087
-                                    array()
3088
-                                )
3089
-                            )
3090
-                        )
3091
-                ),
3092
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3093
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3094
-                'return_url'  => urlencode($this->_req_data['return_url']),
3095
-            )));
3096
-        } else {
3097
-            $new_request_args = array(
3098
-                'export' => 'report',
3099
-                'action' => 'registrations_report_for_event',
3100
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3101
-            );
3102
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3103
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3104
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3105
-                $EE_Export = EE_Export::instance($this->_req_data);
3106
-                $EE_Export->export();
3107
-            }
3108
-        }
3109
-    }
3110
-
3111
-
3112
-
3113
-    /**
3114
-     * Creates a registration report using only query parameters in the request
3115
-     * @return void
3116
-     */
3117
-    public function _registrations_report()
3118
-    {
3119
-        $this->_registrations_report_base('_get_registration_query_parameters');
3120
-    }
3121
-
3122
-
3123
-    public function _contact_list_export()
3124
-    {
3125
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3126
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3127
-            $EE_Export = EE_Export::instance($this->_req_data);
3128
-            $EE_Export->export_attendees();
3129
-        }
3130
-    }
3131
-
3132
-
3133
-    public function _contact_list_report()
3134
-    {
3135
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3136
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3137
-                'page'        => 'espresso_batch',
3138
-                'batch'       => 'file',
3139
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3140
-                'return_url'  => urlencode($this->_req_data['return_url']),
3141
-            )));
3142
-        } else {
3143
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3144
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3145
-                $EE_Export = EE_Export::instance($this->_req_data);
3146
-                $EE_Export->report_attendees();
3147
-            }
3148
-        }
3149
-    }
3150
-
3151
-
3152
-
3153
-
3154
-
3155
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3156
-    /**
3157
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3158
-     *
3159
-     * @return void
3160
-     * @throws EE_Error
3161
-     */
3162
-    protected function _duplicate_attendee()
3163
-    {
3164
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3165
-        //verify we have necessary info
3166
-        if (empty($this->_req_data['_REG_ID'])) {
3167
-            EE_Error::add_error(
3168
-                esc_html__(
3169
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3170
-                    'event_espresso'
3171
-                ), __FILE__, __LINE__, __FUNCTION__
3172
-            );
3173
-            $query_args = array('action' => $action);
3174
-            $this->_redirect_after_action('', '', '', $query_args, true);
3175
-        }
3176
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3177
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3178
-        $attendee     = $registration->attendee();
3179
-        //remove relation of existing attendee on registration
3180
-        $registration->_remove_relation_to($attendee, 'Attendee');
3181
-        //new attendee
3182
-        $new_attendee = clone $attendee;
3183
-        $new_attendee->set('ATT_ID', 0);
3184
-        $new_attendee->save();
3185
-        //add new attendee to reg
3186
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3187
-        EE_Error::add_success(
3188
-            esc_html__(
3189
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3190
-                'event_espresso'
3191
-            )
3192
-        );
3193
-        //redirect to edit page for attendee
3194
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3195
-        $this->_redirect_after_action('', '', '', $query_args, true);
3196
-    }
3197
-
3198
-
3199
-    //related to cpt routes
3200
-    protected function _insert_update_cpt_item($post_id, $post)
3201
-    {
3202
-        $success  = true;
3203
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3204
-        //for attendee updates
3205
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3206
-            //note we should only be UPDATING attendees at this point.
3207
-            $updated_fields = array(
3208
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3209
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3210
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3211
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3212
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3213
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3214
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3215
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3216
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3217
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3218
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3219
-            );
3220
-            foreach ($updated_fields as $field => $value) {
3221
-                $attendee->set($field, $value);
3222
-            }
3223
-            $success                   = $attendee->save();
3224
-            $attendee_update_callbacks = apply_filters(
3225
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3226
-                array()
3227
-            );
3228
-            foreach ($attendee_update_callbacks as $a_callback) {
3229
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3230
-                    throw new EE_Error(
3231
-                        sprintf(
3232
-                            esc_html__(
3233
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3234
-                                'event_espresso'
3235
-                            ),
3236
-                            $a_callback
3237
-                        )
3238
-                    );
3239
-                }
3240
-            }
3241
-        }
3242
-        if ($success === false) {
3243
-            EE_Error::add_error(
3244
-                esc_html__(
3245
-                    'Something went wrong with updating the meta table data for the registration.',
3246
-                    'event_espresso'
3247
-                ),
3248
-                __FILE__, __FUNCTION__, __LINE__
3249
-            );
3250
-        }
3251
-    }
3252
-
3253
-
3254
-    public function trash_cpt_item($post_id)
3255
-    {
3256
-    }
3257
-
3258
-
3259
-    public function delete_cpt_item($post_id)
3260
-    {
3261
-    }
3262
-
3263
-
3264
-    public function restore_cpt_item($post_id)
3265
-    {
3266
-    }
3267
-
3268
-
3269
-    protected function _restore_cpt_item($post_id, $revision_id)
3270
-    {
3271
-    }
3272
-
3273
-
3274
-    public function attendee_editor_metaboxes()
3275
-    {
3276
-        $this->verify_cpt_object();
3277
-        remove_meta_box(
3278
-            'postexcerpt',
3279
-            esc_html__('Excerpt', 'event_espresso'),
3280
-            'post_excerpt_meta_box',
3281
-            $this->_cpt_routes[$this->_req_action],
3282
-            'normal',
3283
-            'core'
3284
-        );
3285
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3286
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3287
-            add_meta_box(
3288
-                'postexcerpt',
3289
-                esc_html__('Short Biography', 'event_espresso'),
3290
-                'post_excerpt_meta_box',
3291
-                $this->_cpt_routes[$this->_req_action],
3292
-                'normal'
3293
-            );
3294
-        }
3295
-        if (post_type_supports('espresso_attendees', 'comments')) {
3296
-            add_meta_box(
3297
-                'commentsdiv',
3298
-                esc_html__('Notes on the Contact', 'event_espresso'),
3299
-                'post_comment_meta_box',
3300
-                $this->_cpt_routes[$this->_req_action],
3301
-                'normal',
3302
-                'core'
3303
-            );
3304
-        }
3305
-        add_meta_box(
3306
-            'attendee_contact_info',
3307
-            esc_html__('Contact Info', 'event_espresso'),
3308
-            array($this, 'attendee_contact_info'),
3309
-            $this->_cpt_routes[$this->_req_action],
3310
-            'side',
3311
-            'core'
3312
-        );
3313
-        add_meta_box(
3314
-            'attendee_details_address',
3315
-            esc_html__('Address Details', 'event_espresso'),
3316
-            array($this, 'attendee_address_details'),
3317
-            $this->_cpt_routes[$this->_req_action],
3318
-            'normal',
3319
-            'core'
3320
-        );
3321
-        add_meta_box(
3322
-            'attendee_registrations',
3323
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3324
-            array($this, 'attendee_registrations_meta_box'),
3325
-            $this->_cpt_routes[$this->_req_action],
3326
-            'normal',
3327
-            'high'
3328
-        );
3329
-    }
3330
-
3331
-
3332
-    /**
3333
-     * Metabox for attendee contact info
3334
-     *
3335
-     * @param  WP_Post $post wp post object
3336
-     * @return string attendee contact info ( and form )
3337
-     * @throws DomainException
3338
-     */
3339
-    public function attendee_contact_info($post)
3340
-    {
3341
-        //get attendee object ( should already have it )
3342
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3343
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3344
-        EEH_Template::display_template($template, $this->_template_args);
3345
-    }
3346
-
3347
-
3348
-    /**
3349
-     * Metabox for attendee details
3350
-     *
3351
-     * @param  WP_Post $post wp post object
3352
-     * @return string attendee address details (and form)
3353
-     * @throws DomainException
3354
-     */
3355
-    public function attendee_address_details($post)
3356
-    {
3357
-        //get attendee object (should already have it)
3358
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3359
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3360
-            new EE_Question_Form_Input(
3361
-                EE_Question::new_instance(
3362
-                    array(
3363
-                        'QST_ID'           => 0,
3364
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3365
-                        'QST_system'       => 'admin-state',
3366
-                    )
3367
-                ),
3368
-                EE_Answer::new_instance(
3369
-                    array(
3370
-                        'ANS_ID'    => 0,
3371
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3372
-                    )
3373
-                ),
3374
-                array(
3375
-                    'input_id'       => 'STA_ID',
3376
-                    'input_name'     => 'STA_ID',
3377
-                    'input_prefix'   => '',
3378
-                    'append_qstn_id' => false,
3379
-                )
3380
-            )
3381
-        );
3382
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3383
-            new EE_Question_Form_Input(
3384
-                EE_Question::new_instance(
3385
-                    array(
3386
-                        'QST_ID'           => 0,
3387
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3388
-                        'QST_system'       => 'admin-country',
3389
-                    )
3390
-                ),
3391
-                EE_Answer::new_instance(
3392
-                    array(
3393
-                        'ANS_ID'    => 0,
3394
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3395
-                    )
3396
-                ),
3397
-                array(
3398
-                    'input_id'       => 'CNT_ISO',
3399
-                    'input_name'     => 'CNT_ISO',
3400
-                    'input_prefix'   => '',
3401
-                    'append_qstn_id' => false,
3402
-                )
3403
-            )
3404
-        );
3405
-        $template                             =
3406
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3407
-        EEH_Template::display_template($template, $this->_template_args);
3408
-    }
3409
-
3410
-
3411
-    /**
3412
-     *        _attendee_details
3413
-     *
3414
-     * @access protected
3415
-     * @param $post
3416
-     * @return void
3417
-     * @throws DomainException
3418
-     * @throws EE_Error
3419
-     */
3420
-    public function attendee_registrations_meta_box($post)
3421
-    {
3422
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3423
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3424
-        $template                              =
3425
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3426
-        EEH_Template::display_template($template, $this->_template_args);
3427
-    }
3428
-
3429
-
3430
-    /**
3431
-     * add in the form fields for the attendee edit
3432
-     *
3433
-     * @param  WP_Post $post wp post object
3434
-     * @return string html for new form.
3435
-     * @throws DomainException
3436
-     */
3437
-    public function after_title_form_fields($post)
3438
-    {
3439
-        if ($post->post_type == 'espresso_attendees') {
3440
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3441
-            $template_args['attendee'] = $this->_cpt_model_obj;
3442
-            EEH_Template::display_template($template, $template_args);
3443
-        }
3444
-    }
3445
-
3446
-
3447
-    /**
3448
-     *        _trash_or_restore_attendee
3449
-     *
3450
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3451
-     * @return void
3452
-     * @throws EE_Error
3453
-     * @access protected
3454
-     */
3455
-    protected function _trash_or_restore_attendees($trash = true)
3456
-    {
3457
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3458
-        $ATT_MDL = EEM_Attendee::instance();
3459
-        $success = 1;
3460
-        //Checkboxes
3461
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3462
-            // if array has more than one element than success message should be plural
3463
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3464
-            // cycle thru checkboxes
3465
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3466
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3467
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3468
-                if ( ! $updated) {
3469
-                    $success = 0;
3470
-                }
3471
-            }
3472
-        } else {
3473
-            // grab single id and delete
3474
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3475
-            //get attendee
3476
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3477
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3478
-            $updated = $att->save();
3479
-            if ( ! $updated) {
3480
-                $success = 0;
3481
-            }
3482
-        }
3483
-        $what        = $success > 1
3484
-            ? esc_html__('Contacts', 'event_espresso')
3485
-            : esc_html__('Contact', 'event_espresso');
3486
-        $action_desc = $trash
3487
-            ? esc_html__('moved to the trash', 'event_espresso')
3488
-            : esc_html__('restored', 'event_espresso');
3489
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3490
-    }
2704
+		}
2705
+		$template_args = array(
2706
+			'title'                    => '',
2707
+			'content'                  => '',
2708
+			'step_button_text'         => '',
2709
+			'show_notification_toggle' => false,
2710
+		);
2711
+		//to indicate we're processing a new registration
2712
+		$hidden_fields = array(
2713
+			'processing_registration' => array(
2714
+				'type'  => 'hidden',
2715
+				'value' => 0,
2716
+			),
2717
+			'event_id'                => array(
2718
+				'type'  => 'hidden',
2719
+				'value' => $this->_reg_event->ID(),
2720
+			),
2721
+		);
2722
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2723
+		$cart = EE_Registry::instance()->SSN->cart();
2724
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2725
+		switch ($step) {
2726
+			case 'ticket' :
2727
+				$hidden_fields['processing_registration']['value'] = 1;
2728
+				$template_args['title']                            = esc_html__(
2729
+					'Step One: Select the Ticket for this registration',
2730
+					'event_espresso'
2731
+				);
2732
+				$template_args['content']                          =
2733
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2734
+				$template_args['step_button_text']                 = esc_html__(
2735
+					'Add Tickets and Continue to Registrant Details',
2736
+					'event_espresso'
2737
+				);
2738
+				$template_args['show_notification_toggle']         = false;
2739
+				break;
2740
+			case 'questions' :
2741
+				$hidden_fields['processing_registration']['value'] = 2;
2742
+				$template_args['title']                            = esc_html__(
2743
+					'Step Two: Add Registrant Details for this Registration',
2744
+					'event_espresso'
2745
+				);
2746
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2747
+				// properly by the first process_reg_step run.
2748
+				$template_args['content']                  =
2749
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2750
+				$template_args['step_button_text']         = esc_html__(
2751
+					'Save Registration and Continue to Details',
2752
+					'event_espresso'
2753
+				);
2754
+				$template_args['show_notification_toggle'] = true;
2755
+				break;
2756
+		}
2757
+		//we come back to the process_registration_step route.
2758
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2759
+		return EEH_Template::display_template(
2760
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2761
+			$template_args,
2762
+			true
2763
+		);
2764
+	}
2765
+
2766
+
2767
+	/**
2768
+	 *        set_reg_event
2769
+	 *
2770
+	 * @access private
2771
+	 * @return bool
2772
+	 * @throws EE_Error
2773
+	 */
2774
+	private function _set_reg_event()
2775
+	{
2776
+		if (is_object($this->_reg_event)) {
2777
+			return true;
2778
+		}
2779
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2780
+		if ( ! $EVT_ID) {
2781
+			return false;
2782
+		}
2783
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2784
+		return true;
2785
+	}
2786
+
2787
+
2788
+	/**
2789
+	 * process_reg_step
2790
+	 *
2791
+	 * @access        public
2792
+	 * @return string
2793
+	 * @throws DomainException
2794
+	 * @throws EE_Error
2795
+	 * @throws RuntimeException
2796
+	 */
2797
+	public function process_reg_step()
2798
+	{
2799
+		EE_System::do_not_cache();
2800
+		$this->_set_reg_event();
2801
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2802
+		EE_Registry::instance()->REQ->set('uts', time());
2803
+		//what step are we on?
2804
+		$cart = EE_Registry::instance()->SSN->cart();
2805
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2806
+		//if doing ajax then we need to verify the nonce
2807
+		if (defined('DOING_AJAX')) {
2808
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2809
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2810
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2811
+		}
2812
+		switch ($step) {
2813
+			case 'ticket' :
2814
+				//process ticket selection
2815
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2816
+				if ($success) {
2817
+					EE_Error::add_success(
2818
+						esc_html__(
2819
+							'Tickets Selected. Now complete the registration.',
2820
+							'event_espresso'
2821
+						)
2822
+					);
2823
+				} else {
2824
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2825
+				}
2826
+				if (defined('DOING_AJAX')) {
2827
+					$this->new_registration(); //display next step
2828
+				} else {
2829
+					$query_args = array(
2830
+						'action'                  => 'new_registration',
2831
+						'processing_registration' => 1,
2832
+						'event_id'                => $this->_reg_event->ID(),
2833
+						'uts'                     => time(),
2834
+					);
2835
+					$this->_redirect_after_action(
2836
+						false,
2837
+						'',
2838
+						'',
2839
+						$query_args,
2840
+						true
2841
+					);
2842
+				}
2843
+				break;
2844
+			case 'questions' :
2845
+				if (! isset(
2846
+					$this->_req_data['txn_reg_status_change'],
2847
+					$this->_req_data['txn_reg_status_change']['send_notifications'])
2848
+				) {
2849
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2850
+				}
2851
+				//process registration
2852
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2853
+				if ($cart instanceof EE_Cart) {
2854
+					$grand_total = $cart->get_cart_grand_total();
2855
+					if ($grand_total instanceof EE_Line_Item) {
2856
+						$grand_total->save_this_and_descendants_to_txn();
2857
+					}
2858
+				}
2859
+				if ( ! $transaction instanceof EE_Transaction) {
2860
+					$query_args = array(
2861
+						'action'                  => 'new_registration',
2862
+						'processing_registration' => 2,
2863
+						'event_id'                => $this->_reg_event->ID(),
2864
+						'uts'                     => time(),
2865
+					);
2866
+					if (defined('DOING_AJAX')) {
2867
+						//display registration form again because there are errors (maybe validation?)
2868
+						$this->new_registration();
2869
+						return;
2870
+					} else {
2871
+						$this->_redirect_after_action(
2872
+							false,
2873
+							'',
2874
+							'',
2875
+							$query_args,
2876
+							true
2877
+						);
2878
+						return;
2879
+					}
2880
+				}
2881
+				// maybe update status, and make sure to save transaction if not done already
2882
+				if ( ! $transaction->update_status_based_on_total_paid()) {
2883
+					$transaction->save();
2884
+				}
2885
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2886
+				$this->_req_data = array();
2887
+				$query_args      = array(
2888
+					'action'        => 'redirect_to_txn',
2889
+					'TXN_ID'        => $transaction->ID(),
2890
+					'EVT_ID'        => $this->_reg_event->ID(),
2891
+					'event_name'    => urlencode($this->_reg_event->name()),
2892
+					'redirect_from' => 'new_registration',
2893
+				);
2894
+				$this->_redirect_after_action(false, '', '', $query_args, true);
2895
+				break;
2896
+		}
2897
+		//what are you looking here for?  Should be nothing to do at this point.
2898
+	}
2899
+
2900
+
2901
+	/**
2902
+	 * redirect_to_txn
2903
+	 *
2904
+	 * @access public
2905
+	 * @return void
2906
+	 * @throws EE_Error
2907
+	 */
2908
+	public function redirect_to_txn()
2909
+	{
2910
+		EE_System::do_not_cache();
2911
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2912
+		$query_args = array(
2913
+			'action' => 'view_transaction',
2914
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2915
+			'page'   => 'espresso_transactions',
2916
+		);
2917
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2918
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2919
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
2920
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
2921
+		}
2922
+		EE_Error::add_success(
2923
+			esc_html__(
2924
+				'Registration Created.  Please review the transaction and add any payments as necessary',
2925
+				'event_espresso'
2926
+			)
2927
+		);
2928
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2929
+	}
2930
+
2931
+
2932
+	/**
2933
+	 *        generates HTML for the Attendee Contact List
2934
+	 *
2935
+	 * @access protected
2936
+	 * @return void
2937
+	 */
2938
+	protected function _attendee_contact_list_table()
2939
+	{
2940
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2941
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
2942
+		$this->display_admin_list_table_page_with_no_sidebar();
2943
+	}
2944
+
2945
+
2946
+	/**
2947
+	 *        get_attendees
2948
+	 *
2949
+	 * @param      $per_page
2950
+	 * @param bool $count whether to return count or data.
2951
+	 * @param bool $trash
2952
+	 * @return array
2953
+	 * @throws EE_Error
2954
+	 * @access public
2955
+	 */
2956
+	public function get_attendees($per_page, $count = false, $trash = false)
2957
+	{
2958
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2959
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2960
+		$ATT_MDL                    = EEM_Attendee::instance();
2961
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2962
+		switch ($this->_req_data['orderby']) {
2963
+			case 'ATT_ID':
2964
+				$orderby = 'ATT_ID';
2965
+				break;
2966
+			case 'ATT_fname':
2967
+				$orderby = 'ATT_fname';
2968
+				break;
2969
+			case 'ATT_email':
2970
+				$orderby = 'ATT_email';
2971
+				break;
2972
+			case 'ATT_city':
2973
+				$orderby = 'ATT_city';
2974
+				break;
2975
+			case 'STA_ID':
2976
+				$orderby = 'STA_ID';
2977
+				break;
2978
+			case 'CNT_ID':
2979
+				$orderby = 'CNT_ID';
2980
+				break;
2981
+			default:
2982
+				$orderby = 'ATT_lname';
2983
+		}
2984
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
2985
+			? $this->_req_data['order']
2986
+			: 'ASC';
2987
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2988
+			? $this->_req_data['paged']
2989
+			: 1;
2990
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2991
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2992
+			? $this->_req_data['perpage']
2993
+			: $per_page;
2994
+		$_where       = array();
2995
+		if ( ! empty($this->_req_data['s'])) {
2996
+			$sstr         = '%' . $this->_req_data['s'] . '%';
2997
+			$_where['OR'] = array(
2998
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2999
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3000
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3001
+				'ATT_fname'                         => array('LIKE', $sstr),
3002
+				'ATT_lname'                         => array('LIKE', $sstr),
3003
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3004
+				'ATT_email'                         => array('LIKE', $sstr),
3005
+				'ATT_address'                       => array('LIKE', $sstr),
3006
+				'ATT_address2'                      => array('LIKE', $sstr),
3007
+				'ATT_city'                          => array('LIKE', $sstr),
3008
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3009
+				'State.STA_name'                    => array('LIKE', $sstr),
3010
+				'ATT_phone'                         => array('LIKE', $sstr),
3011
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3012
+				'Registration.REG_code'             => array('LIKE', $sstr),
3013
+				'Registration.REG_count'            => array('LIKE', $sstr),
3014
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3015
+			);
3016
+		}
3017
+		$offset = ($current_page - 1) * $per_page;
3018
+		$limit  = $count ? null : array($offset, $per_page);
3019
+		if ($trash) {
3020
+			$_where['status'] = array('!=', 'publish');
3021
+			$all_attendees    = $count
3022
+				? $ATT_MDL->count(array(
3023
+					$_where,
3024
+					'order_by' => array($orderby => $sort),
3025
+					'limit'    => $limit,
3026
+				), 'ATT_ID', true)
3027
+				: $ATT_MDL->get_all(array(
3028
+					$_where,
3029
+					'order_by' => array($orderby => $sort),
3030
+					'limit'    => $limit,
3031
+				));
3032
+		} else {
3033
+			$_where['status'] = array('IN', array('publish'));
3034
+			$all_attendees    = $count
3035
+				? $ATT_MDL->count(array(
3036
+					$_where,
3037
+					'order_by' => array($orderby => $sort),
3038
+					'limit'    => $limit,
3039
+				), 'ATT_ID', true)
3040
+				: $ATT_MDL->get_all(array(
3041
+					$_where,
3042
+					'order_by' => array($orderby => $sort),
3043
+					'limit'    => $limit,
3044
+				));
3045
+		}
3046
+		return $all_attendees;
3047
+	}
3048
+
3049
+
3050
+	/**
3051
+	 * This is just taking care of resending the registration confirmation
3052
+	 *
3053
+	 * @access protected
3054
+	 * @return void
3055
+	 */
3056
+	protected function _resend_registration()
3057
+	{
3058
+		$this->_process_resend_registration();
3059
+		$query_args = isset($this->_req_data['redirect_to'])
3060
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3061
+			: array('action' => 'default');
3062
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3063
+	}
3064
+
3065
+	/**
3066
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3067
+	 * to use when selecting registrations
3068
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3069
+	 *                                                     the query parameters from the request
3070
+	 * @return void ends the request with a redirect or download
3071
+	 */
3072
+	public function _registrations_report_base( $method_name_for_getting_query_params )
3073
+	{
3074
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3075
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(
3076
+				array(
3077
+					'page'        => 'espresso_batch',
3078
+					'batch'       => 'file',
3079
+					'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3080
+					'filters'     => urlencode(
3081
+						serialize(
3082
+							call_user_func(
3083
+								array( $this, $method_name_for_getting_query_params ),
3084
+								EEH_Array::is_set(
3085
+									$this->_req_data,
3086
+									'filters',
3087
+									array()
3088
+								)
3089
+							)
3090
+						)
3091
+				),
3092
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3093
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3094
+				'return_url'  => urlencode($this->_req_data['return_url']),
3095
+			)));
3096
+		} else {
3097
+			$new_request_args = array(
3098
+				'export' => 'report',
3099
+				'action' => 'registrations_report_for_event',
3100
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3101
+			);
3102
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3103
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3104
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3105
+				$EE_Export = EE_Export::instance($this->_req_data);
3106
+				$EE_Export->export();
3107
+			}
3108
+		}
3109
+	}
3110
+
3111
+
3112
+
3113
+	/**
3114
+	 * Creates a registration report using only query parameters in the request
3115
+	 * @return void
3116
+	 */
3117
+	public function _registrations_report()
3118
+	{
3119
+		$this->_registrations_report_base('_get_registration_query_parameters');
3120
+	}
3121
+
3122
+
3123
+	public function _contact_list_export()
3124
+	{
3125
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3126
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3127
+			$EE_Export = EE_Export::instance($this->_req_data);
3128
+			$EE_Export->export_attendees();
3129
+		}
3130
+	}
3131
+
3132
+
3133
+	public function _contact_list_report()
3134
+	{
3135
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3136
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
3137
+				'page'        => 'espresso_batch',
3138
+				'batch'       => 'file',
3139
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3140
+				'return_url'  => urlencode($this->_req_data['return_url']),
3141
+			)));
3142
+		} else {
3143
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3144
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3145
+				$EE_Export = EE_Export::instance($this->_req_data);
3146
+				$EE_Export->report_attendees();
3147
+			}
3148
+		}
3149
+	}
3150
+
3151
+
3152
+
3153
+
3154
+
3155
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3156
+	/**
3157
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3158
+	 *
3159
+	 * @return void
3160
+	 * @throws EE_Error
3161
+	 */
3162
+	protected function _duplicate_attendee()
3163
+	{
3164
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3165
+		//verify we have necessary info
3166
+		if (empty($this->_req_data['_REG_ID'])) {
3167
+			EE_Error::add_error(
3168
+				esc_html__(
3169
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3170
+					'event_espresso'
3171
+				), __FILE__, __LINE__, __FUNCTION__
3172
+			);
3173
+			$query_args = array('action' => $action);
3174
+			$this->_redirect_after_action('', '', '', $query_args, true);
3175
+		}
3176
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3177
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3178
+		$attendee     = $registration->attendee();
3179
+		//remove relation of existing attendee on registration
3180
+		$registration->_remove_relation_to($attendee, 'Attendee');
3181
+		//new attendee
3182
+		$new_attendee = clone $attendee;
3183
+		$new_attendee->set('ATT_ID', 0);
3184
+		$new_attendee->save();
3185
+		//add new attendee to reg
3186
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3187
+		EE_Error::add_success(
3188
+			esc_html__(
3189
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3190
+				'event_espresso'
3191
+			)
3192
+		);
3193
+		//redirect to edit page for attendee
3194
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3195
+		$this->_redirect_after_action('', '', '', $query_args, true);
3196
+	}
3197
+
3198
+
3199
+	//related to cpt routes
3200
+	protected function _insert_update_cpt_item($post_id, $post)
3201
+	{
3202
+		$success  = true;
3203
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
3204
+		//for attendee updates
3205
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
3206
+			//note we should only be UPDATING attendees at this point.
3207
+			$updated_fields = array(
3208
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3209
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3210
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3211
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3212
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3213
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3214
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3215
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3216
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3217
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
3218
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
3219
+			);
3220
+			foreach ($updated_fields as $field => $value) {
3221
+				$attendee->set($field, $value);
3222
+			}
3223
+			$success                   = $attendee->save();
3224
+			$attendee_update_callbacks = apply_filters(
3225
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3226
+				array()
3227
+			);
3228
+			foreach ($attendee_update_callbacks as $a_callback) {
3229
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3230
+					throw new EE_Error(
3231
+						sprintf(
3232
+							esc_html__(
3233
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3234
+								'event_espresso'
3235
+							),
3236
+							$a_callback
3237
+						)
3238
+					);
3239
+				}
3240
+			}
3241
+		}
3242
+		if ($success === false) {
3243
+			EE_Error::add_error(
3244
+				esc_html__(
3245
+					'Something went wrong with updating the meta table data for the registration.',
3246
+					'event_espresso'
3247
+				),
3248
+				__FILE__, __FUNCTION__, __LINE__
3249
+			);
3250
+		}
3251
+	}
3252
+
3253
+
3254
+	public function trash_cpt_item($post_id)
3255
+	{
3256
+	}
3257
+
3258
+
3259
+	public function delete_cpt_item($post_id)
3260
+	{
3261
+	}
3262
+
3263
+
3264
+	public function restore_cpt_item($post_id)
3265
+	{
3266
+	}
3267
+
3268
+
3269
+	protected function _restore_cpt_item($post_id, $revision_id)
3270
+	{
3271
+	}
3272
+
3273
+
3274
+	public function attendee_editor_metaboxes()
3275
+	{
3276
+		$this->verify_cpt_object();
3277
+		remove_meta_box(
3278
+			'postexcerpt',
3279
+			esc_html__('Excerpt', 'event_espresso'),
3280
+			'post_excerpt_meta_box',
3281
+			$this->_cpt_routes[$this->_req_action],
3282
+			'normal',
3283
+			'core'
3284
+		);
3285
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3286
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3287
+			add_meta_box(
3288
+				'postexcerpt',
3289
+				esc_html__('Short Biography', 'event_espresso'),
3290
+				'post_excerpt_meta_box',
3291
+				$this->_cpt_routes[$this->_req_action],
3292
+				'normal'
3293
+			);
3294
+		}
3295
+		if (post_type_supports('espresso_attendees', 'comments')) {
3296
+			add_meta_box(
3297
+				'commentsdiv',
3298
+				esc_html__('Notes on the Contact', 'event_espresso'),
3299
+				'post_comment_meta_box',
3300
+				$this->_cpt_routes[$this->_req_action],
3301
+				'normal',
3302
+				'core'
3303
+			);
3304
+		}
3305
+		add_meta_box(
3306
+			'attendee_contact_info',
3307
+			esc_html__('Contact Info', 'event_espresso'),
3308
+			array($this, 'attendee_contact_info'),
3309
+			$this->_cpt_routes[$this->_req_action],
3310
+			'side',
3311
+			'core'
3312
+		);
3313
+		add_meta_box(
3314
+			'attendee_details_address',
3315
+			esc_html__('Address Details', 'event_espresso'),
3316
+			array($this, 'attendee_address_details'),
3317
+			$this->_cpt_routes[$this->_req_action],
3318
+			'normal',
3319
+			'core'
3320
+		);
3321
+		add_meta_box(
3322
+			'attendee_registrations',
3323
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3324
+			array($this, 'attendee_registrations_meta_box'),
3325
+			$this->_cpt_routes[$this->_req_action],
3326
+			'normal',
3327
+			'high'
3328
+		);
3329
+	}
3330
+
3331
+
3332
+	/**
3333
+	 * Metabox for attendee contact info
3334
+	 *
3335
+	 * @param  WP_Post $post wp post object
3336
+	 * @return string attendee contact info ( and form )
3337
+	 * @throws DomainException
3338
+	 */
3339
+	public function attendee_contact_info($post)
3340
+	{
3341
+		//get attendee object ( should already have it )
3342
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3343
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
3344
+		EEH_Template::display_template($template, $this->_template_args);
3345
+	}
3346
+
3347
+
3348
+	/**
3349
+	 * Metabox for attendee details
3350
+	 *
3351
+	 * @param  WP_Post $post wp post object
3352
+	 * @return string attendee address details (and form)
3353
+	 * @throws DomainException
3354
+	 */
3355
+	public function attendee_address_details($post)
3356
+	{
3357
+		//get attendee object (should already have it)
3358
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3359
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3360
+			new EE_Question_Form_Input(
3361
+				EE_Question::new_instance(
3362
+					array(
3363
+						'QST_ID'           => 0,
3364
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3365
+						'QST_system'       => 'admin-state',
3366
+					)
3367
+				),
3368
+				EE_Answer::new_instance(
3369
+					array(
3370
+						'ANS_ID'    => 0,
3371
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3372
+					)
3373
+				),
3374
+				array(
3375
+					'input_id'       => 'STA_ID',
3376
+					'input_name'     => 'STA_ID',
3377
+					'input_prefix'   => '',
3378
+					'append_qstn_id' => false,
3379
+				)
3380
+			)
3381
+		);
3382
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3383
+			new EE_Question_Form_Input(
3384
+				EE_Question::new_instance(
3385
+					array(
3386
+						'QST_ID'           => 0,
3387
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3388
+						'QST_system'       => 'admin-country',
3389
+					)
3390
+				),
3391
+				EE_Answer::new_instance(
3392
+					array(
3393
+						'ANS_ID'    => 0,
3394
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3395
+					)
3396
+				),
3397
+				array(
3398
+					'input_id'       => 'CNT_ISO',
3399
+					'input_name'     => 'CNT_ISO',
3400
+					'input_prefix'   => '',
3401
+					'append_qstn_id' => false,
3402
+				)
3403
+			)
3404
+		);
3405
+		$template                             =
3406
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3407
+		EEH_Template::display_template($template, $this->_template_args);
3408
+	}
3409
+
3410
+
3411
+	/**
3412
+	 *        _attendee_details
3413
+	 *
3414
+	 * @access protected
3415
+	 * @param $post
3416
+	 * @return void
3417
+	 * @throws DomainException
3418
+	 * @throws EE_Error
3419
+	 */
3420
+	public function attendee_registrations_meta_box($post)
3421
+	{
3422
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3423
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3424
+		$template                              =
3425
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3426
+		EEH_Template::display_template($template, $this->_template_args);
3427
+	}
3428
+
3429
+
3430
+	/**
3431
+	 * add in the form fields for the attendee edit
3432
+	 *
3433
+	 * @param  WP_Post $post wp post object
3434
+	 * @return string html for new form.
3435
+	 * @throws DomainException
3436
+	 */
3437
+	public function after_title_form_fields($post)
3438
+	{
3439
+		if ($post->post_type == 'espresso_attendees') {
3440
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3441
+			$template_args['attendee'] = $this->_cpt_model_obj;
3442
+			EEH_Template::display_template($template, $template_args);
3443
+		}
3444
+	}
3445
+
3446
+
3447
+	/**
3448
+	 *        _trash_or_restore_attendee
3449
+	 *
3450
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3451
+	 * @return void
3452
+	 * @throws EE_Error
3453
+	 * @access protected
3454
+	 */
3455
+	protected function _trash_or_restore_attendees($trash = true)
3456
+	{
3457
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3458
+		$ATT_MDL = EEM_Attendee::instance();
3459
+		$success = 1;
3460
+		//Checkboxes
3461
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3462
+			// if array has more than one element than success message should be plural
3463
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3464
+			// cycle thru checkboxes
3465
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3466
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3467
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3468
+				if ( ! $updated) {
3469
+					$success = 0;
3470
+				}
3471
+			}
3472
+		} else {
3473
+			// grab single id and delete
3474
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3475
+			//get attendee
3476
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3477
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3478
+			$updated = $att->save();
3479
+			if ( ! $updated) {
3480
+				$success = 0;
3481
+			}
3482
+		}
3483
+		$what        = $success > 1
3484
+			? esc_html__('Contacts', 'event_espresso')
3485
+			: esc_html__('Contact', 'event_espresso');
3486
+		$action_desc = $trash
3487
+			? esc_html__('moved to the trash', 'event_espresso')
3488
+			: esc_html__('restored', 'event_espresso');
3489
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3490
+	}
3491 3491
 
3492 3492
 }
Please login to merge, or discard this patch.
core/db_models/EEM_CPT_Base.model.php 2 patches
Indentation   +514 added lines, -514 removed lines patch added patch discarded remove patch
@@ -18,519 +18,519 @@
 block discarded – undo
18 18
 abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base
19 19
 {
20 20
 
21
-    /**
22
-     * @var string post_status_publish - the wp post status for published cpts
23
-     */
24
-    const post_status_publish = 'publish';
25
-
26
-    /**
27
-     * @var string post_status_future - the wp post status for scheduled cpts
28
-     */
29
-    const post_status_future = 'future';
30
-
31
-    /**
32
-     * @var string post_status_draft - the wp post status for draft cpts
33
-     */
34
-    const post_status_draft = 'draft';
35
-
36
-    /**
37
-     * @var string post_status_pending - the wp post status for pending cpts
38
-     */
39
-    const post_status_pending = 'pending';
40
-
41
-    /**
42
-     * @var string post_status_private - the wp post status for private cpts
43
-     */
44
-    const post_status_private = 'private';
45
-
46
-    /**
47
-     * @var string post_status_trashed - the wp post status for trashed cpts
48
-     */
49
-    const post_status_trashed = 'trash';
50
-
51
-    /**
52
-     * This is an array of custom statuses for the given CPT model (modified by children)
53
-     * format:
54
-     * array(
55
-     *        'status_name' => array(
56
-     *            'label' => __('Status Name', 'event_espresso'),
57
-     *            'public' => TRUE //whether a public status or not.
58
-     *        )
59
-     * )
60
-     *
61
-     * @var array
62
-     */
63
-    protected $_custom_stati = array();
64
-
65
-
66
-
67
-    /**
68
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
69
-     *
70
-     * @param string $timezone
71
-     * @throws \EE_Error
72
-     */
73
-    protected function __construct($timezone = null)
74
-    {
75
-        //adds a relationship to Term_Taxonomy for all these models. For this to work
76
-        //Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
77
-        //eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
78
-        //with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
79
-        //must also be new EE_HABTM_Relation('Term_Relationship');
80
-        $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
81
-        $primary_table_name = null;
82
-        //add  the common _status field to all CPT primary tables.
83
-        foreach ($this->_tables as $alias => $table_obj) {
84
-            if ($table_obj instanceof EE_Primary_Table) {
85
-                $primary_table_name = $alias;
86
-            }
87
-        }
88
-        //set default wp post statuses if child has not already set.
89
-        if ( ! isset($this->_fields[$primary_table_name]['status'])) {
90
-            $this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status',
91
-                __("Event Status", "event_espresso"), false, 'draft');
92
-        }
93
-        if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
94
-            $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping',
95
-                __('To Ping', 'event_espresso'), false, '');
96
-        }
97
-        if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
98
-            $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged',
99
-                __('Pinged', 'event_espresso'), false, '');
100
-        }
101
-        if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
102
-            $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status',
103
-                __('Comment Status', 'event_espresso'), false, 'open');
104
-        }
105
-        if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
106
-            $this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status',
107
-                __('Ping Status', 'event_espresso'), false, 'open');
108
-        }
109
-        if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
110
-            $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered',
111
-                __('Post Content Filtered', 'event_espresso'), false, '');
112
-        }
113
-        if ( ! isset($this->_model_relations['Post_Meta'])) {
114
-            //don't block deletes though because we want to maintain the current behaviour
115
-            $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
116
-        }
117
-        if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
118
-            //nothing was set during child constructor, so set default
119
-            $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
120
-        }
121
-        if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
122
-            //nothing was set during child constructor, so set default
123
-            //it's ok for child classes to specify this, but generally this is more DRY
124
-            $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
125
-        }
126
-        parent::__construct($timezone);
127
-    }
128
-
129
-
130
-
131
-    /**
132
-     * @return array
133
-     */
134
-    public function public_event_stati()
135
-    {
136
-        // @see wp-includes/post.php
137
-        return get_post_stati(array('public' => true));
138
-    }
139
-
140
-
141
-
142
-    /**
143
-     * Searches for field on this model of type 'deleted_flag'. if it is found,
144
-     * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
145
-     *
146
-     * @return string
147
-     * @throws EE_Error
148
-     */
149
-    public function deleted_field_name()
150
-    {
151
-        throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
152
-            "event_espresso")));
153
-    }
154
-
155
-
156
-
157
-    /**
158
-     * Gets the field's name that sets the post status
159
-     *
160
-     * @return string
161
-     * @throws EE_Error
162
-     */
163
-    public function post_status_field_name()
164
-    {
165
-        $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
166
-        if ($field) {
167
-            return $field->get_name();
168
-        } else {
169
-            throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
170
-                'event_espresso'), get_class($this), get_class($this)));
171
-        }
172
-    }
173
-
174
-
175
-
176
-    /**
177
-     * Alters the query params so that only trashed/soft-deleted items are considered
178
-     *
179
-     * @param array $query_params like EEM_Base::get_all's $query_params
180
-     * @return array like EEM_Base::get_all's $query_params
181
-     */
182
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
183
-    {
184
-        $post_status_field_name = $this->post_status_field_name();
185
-        $query_params[0][$post_status_field_name] = self::post_status_trashed;
186
-        return $query_params;
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * Alters the query params so each item's deleted status is ignored.
193
-     *
194
-     * @param array $query_params
195
-     * @return array
196
-     */
197
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
198
-    {
199
-        $query_params['default_where_conditions'] = 'minimum';
200
-        return $query_params;
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
207
-     *
208
-     * @param boolean $delete       true to indicate deletion, false to indicate restoration
209
-     * @param array   $query_params like EEM_Base::get_all
210
-     * @return boolean success
211
-     */
212
-    function delete_or_restore($delete = true, $query_params = array())
213
-    {
214
-        $post_status_field_name = $this->post_status_field_name();
215
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
216
-        $new_status = $delete ? self::post_status_trashed : 'draft';
217
-        if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
218
-            return true;
219
-        } else {
220
-            return false;
221
-        }
222
-    }
223
-
224
-
225
-
226
-    /**
227
-     * meta_table
228
-     * returns first EE_Secondary_Table table name
229
-     *
230
-     * @access public
231
-     * @return string
232
-     */
233
-    public function meta_table()
234
-    {
235
-        $meta_table = $this->_get_other_tables();
236
-        $meta_table = reset($meta_table);
237
-        return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
238
-    }
239
-
240
-
241
-
242
-    /**
243
-     * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
244
-     *
245
-     * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
246
-     *                   db only fields)
247
-     * @return array
248
-     */
249
-    public function get_meta_table_fields($all = false)
250
-    {
251
-        $all_fields = $fields_to_return = array();
252
-        foreach ($this->_tables as $alias => $table_obj) {
253
-            if ($table_obj instanceof EE_Secondary_Table) {
254
-                $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
255
-            }
256
-        }
257
-        if ( ! $all) {
258
-            foreach ($all_fields as $name => $obj) {
259
-                if ($obj instanceof EE_DB_Only_Field_Base) {
260
-                    continue;
261
-                }
262
-                $fields_to_return[] = $name;
263
-            }
264
-        } else {
265
-            $fields_to_return = array_keys($all_fields);
266
-        }
267
-        return $fields_to_return;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Adds an event category with the specified name and description to the specified
274
-     * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
275
-     * and adds an entry in the term_relationship if necessary.
276
-     *
277
-     * @param EE_CPT_Base $cpt_model_object
278
-     * @param string      $category_name (used to derive the term slug too)
279
-     * @param string      $category_description
280
-     * @param int         $parent_term_taxonomy_id
281
-     * @return EE_Term_Taxonomy
282
-     */
283
-    function add_event_category(
284
-        EE_CPT_Base $cpt_model_object,
285
-        $category_name,
286
-        $category_description = '',
287
-        $parent_term_taxonomy_id = null
288
-    ) {
289
-        //create term
290
-        require_once(EE_MODELS . 'EEM_Term.model.php');
291
-        //first, check for a term by the same name or slug
292
-        $category_slug = sanitize_title($category_name);
293
-        $term = EEM_Term::instance()->get_one(array(
294
-            array(
295
-                'OR' => array(
296
-                    'name' => $category_name,
297
-                    'slug' => $category_slug,
298
-                ),
299
-            ),
300
-        ));
301
-        if ( ! $term) {
302
-            $term = EE_Term::new_instance(array(
303
-                'name' => $category_name,
304
-                'slug' => $category_slug,
305
-            ));
306
-            $term->save();
307
-        }
308
-        //make sure there's a term-taxonomy entry too
309
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
310
-        $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(
311
-            array(
312
-                'term_id'  => $term->ID(),
313
-                'taxonomy' => EE_Event_Category_Taxonomy,
314
-            ),
315
-        ));
316
-        /** @var $term_taxonomy EE_Term_Taxonomy */
317
-        if ( ! $term_taxonomy) {
318
-            $term_taxonomy = EE_Term_Taxonomy::new_instance(array(
319
-                'term_id'     => $term->ID(),
320
-                'taxonomy'    => EE_Event_Category_Taxonomy,
321
-                'description' => $category_description,
322
-                'count'       => 1,
323
-                'parent'      => $parent_term_taxonomy_id,
324
-            ));
325
-            $term_taxonomy->save();
326
-        } else {
327
-            $term_taxonomy->set_count($term_taxonomy->count() + 1);
328
-            $term_taxonomy->save();
329
-        }
330
-        return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
331
-    }
332
-
333
-
334
-
335
-    /**
336
-     * Removed the category specified by name as having a relation to this event.
337
-     * Does not remove the term or term_taxonomy.
338
-     *
339
-     * @param EE_CPT_Base $cpt_model_object_event
340
-     * @param string      $category_name name of the event category (term)
341
-     * @return bool
342
-     */
343
-    function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
344
-    {
345
-        //find the term_taxonomy by that name
346
-        $term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy',
347
-            array(array('Term.name' => $category_name, 'taxonomy' => EE_Event_Category_Taxonomy)));
348
-        /** @var $term_taxonomy EE_Term_Taxonomy */
349
-        if ($term_taxonomy) {
350
-            $term_taxonomy->set_count($term_taxonomy->count() - 1);
351
-            $term_taxonomy->save();
352
-        }
353
-        return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
354
-    }
355
-
356
-
357
-
358
-    /**
359
-     * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
360
-     * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
361
-     *
362
-     * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
363
-     * @access public
364
-     * @param int          $id   the ID for the cpt we want the feature image for
365
-     * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
366
-     *                           representing width and height in pixels (i.e. array(32,32) ).
367
-     * @param string|array $attr Optional. Query string or array of attributes.
368
-     * @return string HTML image element
369
-     */
370
-    public function get_feature_image($id, $size = 'thumbnail', $attr = '')
371
-    {
372
-        return get_the_post_thumbnail($id, $size, $attr);
373
-    }
374
-
375
-
376
-
377
-    /**
378
-     * Just a handy way to get the list of post statuses currently registered with WP.
379
-     *
380
-     * @global array $wp_post_statuses set in wp core for storing all the post stati
381
-     * @return array
382
-     */
383
-    public function get_post_statuses()
384
-    {
385
-        global $wp_post_statuses;
386
-        $statuses = array();
387
-        foreach ($wp_post_statuses as $post_status => $args_object) {
388
-            $statuses[$post_status] = $args_object->label;
389
-        }
390
-        return $statuses;
391
-    }
392
-
393
-
394
-
395
-    /**
396
-     * public method that can be used to retrieve the protected status array on the instantiated cpt model
397
-     *
398
-     * @return array array of statuses.
399
-     */
400
-    public function get_status_array()
401
-    {
402
-        $statuses = $this->get_post_statuses();
403
-        //first the global filter
404
-        $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
405
-        //now the class specific filter
406
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
407
-        return $statuses;
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * this returns the post statuses that are NOT the default wordpress status
414
-     *
415
-     * @return array
416
-     */
417
-    public function get_custom_post_statuses()
418
-    {
419
-        $new_stati = array();
420
-        foreach ($this->_custom_stati as $status => $props) {
421
-            $new_stati[$status] = $props['label'];
422
-        }
423
-        return $new_stati;
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
430
-     * are a row from the posts table. If we're missing any fields required for the model,
431
-     * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
432
-     * make sure you are attaching all the model's fields onto the post)
433
-     *
434
-     * @param WP_Post|array $post
435
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
436
-     */
437
-    public function instantiate_class_from_post_object_orig($post)
438
-    {
439
-        $post = (array)$post;
440
-        $has_all_necessary_fields_for_table = true;
441
-        //check if the post has fields on the meta table already
442
-        foreach ($this->_get_other_tables() as $table_obj) {
443
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
444
-            foreach ($fields_for_that_table as $field_obj) {
445
-                if ( ! isset($post[$field_obj->get_table_column()])
446
-                     && ! isset($post[$field_obj->get_qualified_column()])
447
-                ) {
448
-                    $has_all_necessary_fields_for_table = false;
449
-                }
450
-            }
451
-        }
452
-        //if we don't have all the fields we need, then just fetch the proper model from the DB
453
-        if ( ! $has_all_necessary_fields_for_table) {
454
-            return $this->get_one_by_ID($post['ID']);
455
-        } else {
456
-            return $this->instantiate_class_from_array_or_object($post);
457
-        }
458
-    }
459
-
460
-
461
-
462
-    /**
463
-     * @param null $post
464
-     * @return EE_Base_Class|EE_Soft_Delete_Base_Class
465
-     */
466
-    public function instantiate_class_from_post_object($post = null)
467
-    {
468
-        if (empty($post)) {
469
-            global $post;
470
-        }
471
-        $post = (array)$post;
472
-        $tables_needing_to_be_queried = array();
473
-        //check if the post has fields on the meta table already
474
-        foreach ($this->get_tables() as $table_obj) {
475
-            $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
476
-            foreach ($fields_for_that_table as $field_obj) {
477
-                if ( ! isset($post[$field_obj->get_table_column()])
478
-                     && ! isset($post[$field_obj->get_qualified_column()])
479
-                ) {
480
-                    $tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
481
-                }
482
-            }
483
-        }
484
-        //if we don't have all the fields we need, then just fetch the proper model from the DB
485
-        if ($tables_needing_to_be_queried) {
486
-            if (count($tables_needing_to_be_queried) == 1
487
-                && reset($tables_needing_to_be_queried)
488
-                   instanceof
489
-                   EE_Secondary_Table
490
-            ) {
491
-                //so we're only missing data from a secondary table. Well that's not too hard to query for
492
-                $table_to_query = reset($tables_needing_to_be_queried);
493
-                $missing_data = $this->_do_wpdb_query('get_row', array(
494
-                    'SELECT * FROM '
495
-                    . $table_to_query->get_table_name()
496
-                    . ' WHERE '
497
-                    . $table_to_query->get_fk_on_table()
498
-                    . ' = '
499
-                    . $post['ID'],
500
-                    ARRAY_A,
501
-                ));
502
-                if ( ! empty($missing_data)) {
503
-                    $post = array_merge($post, $missing_data);
504
-                }
505
-            } else {
506
-                return $this->get_one_by_ID($post['ID']);
507
-            }
508
-        }
509
-        return $this->instantiate_class_from_array_or_object($post);
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * Gets the post type associated with this
516
-     *
517
-     * @throws EE_Error
518
-     * @return string
519
-     */
520
-    public function post_type()
521
-    {
522
-        $post_type_field = null;
523
-        foreach ($this->field_settings(true) as $field_obj) {
524
-            if ($field_obj instanceof EE_WP_Post_Type_Field) {
525
-                $post_type_field = $field_obj;
526
-                break;
527
-            }
528
-        }
529
-        if ($post_type_field == null) {
530
-            throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
531
-                "event_espresso"), get_class($this)));
532
-        }
533
-        return $post_type_field->get_default_value();
534
-    }
21
+	/**
22
+	 * @var string post_status_publish - the wp post status for published cpts
23
+	 */
24
+	const post_status_publish = 'publish';
25
+
26
+	/**
27
+	 * @var string post_status_future - the wp post status for scheduled cpts
28
+	 */
29
+	const post_status_future = 'future';
30
+
31
+	/**
32
+	 * @var string post_status_draft - the wp post status for draft cpts
33
+	 */
34
+	const post_status_draft = 'draft';
35
+
36
+	/**
37
+	 * @var string post_status_pending - the wp post status for pending cpts
38
+	 */
39
+	const post_status_pending = 'pending';
40
+
41
+	/**
42
+	 * @var string post_status_private - the wp post status for private cpts
43
+	 */
44
+	const post_status_private = 'private';
45
+
46
+	/**
47
+	 * @var string post_status_trashed - the wp post status for trashed cpts
48
+	 */
49
+	const post_status_trashed = 'trash';
50
+
51
+	/**
52
+	 * This is an array of custom statuses for the given CPT model (modified by children)
53
+	 * format:
54
+	 * array(
55
+	 *        'status_name' => array(
56
+	 *            'label' => __('Status Name', 'event_espresso'),
57
+	 *            'public' => TRUE //whether a public status or not.
58
+	 *        )
59
+	 * )
60
+	 *
61
+	 * @var array
62
+	 */
63
+	protected $_custom_stati = array();
64
+
65
+
66
+
67
+	/**
68
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
69
+	 *
70
+	 * @param string $timezone
71
+	 * @throws \EE_Error
72
+	 */
73
+	protected function __construct($timezone = null)
74
+	{
75
+		//adds a relationship to Term_Taxonomy for all these models. For this to work
76
+		//Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly
77
+		//eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry
78
+		//with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value
79
+		//must also be new EE_HABTM_Relation('Term_Relationship');
80
+		$this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship');
81
+		$primary_table_name = null;
82
+		//add  the common _status field to all CPT primary tables.
83
+		foreach ($this->_tables as $alias => $table_obj) {
84
+			if ($table_obj instanceof EE_Primary_Table) {
85
+				$primary_table_name = $alias;
86
+			}
87
+		}
88
+		//set default wp post statuses if child has not already set.
89
+		if ( ! isset($this->_fields[$primary_table_name]['status'])) {
90
+			$this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field('post_status',
91
+				__("Event Status", "event_espresso"), false, 'draft');
92
+		}
93
+		if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) {
94
+			$this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field('to_ping',
95
+				__('To Ping', 'event_espresso'), false, '');
96
+		}
97
+		if ( ! isset($this->_fields[$primary_table_name]['pinged'])) {
98
+			$this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field('pinged',
99
+				__('Pinged', 'event_espresso'), false, '');
100
+		}
101
+		if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) {
102
+			$this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field('comment_status',
103
+				__('Comment Status', 'event_espresso'), false, 'open');
104
+		}
105
+		if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) {
106
+			$this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field('ping_status',
107
+				__('Ping Status', 'event_espresso'), false, 'open');
108
+		}
109
+		if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) {
110
+			$this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field('post_content_filtered',
111
+				__('Post Content Filtered', 'event_espresso'), false, '');
112
+		}
113
+		if ( ! isset($this->_model_relations['Post_Meta'])) {
114
+			//don't block deletes though because we want to maintain the current behaviour
115
+			$this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false);
116
+		}
117
+		if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
118
+			//nothing was set during child constructor, so set default
119
+			$this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type());
120
+		}
121
+		if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
122
+			//nothing was set during child constructor, so set default
123
+			//it's ok for child classes to specify this, but generally this is more DRY
124
+			$this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type());
125
+		}
126
+		parent::__construct($timezone);
127
+	}
128
+
129
+
130
+
131
+	/**
132
+	 * @return array
133
+	 */
134
+	public function public_event_stati()
135
+	{
136
+		// @see wp-includes/post.php
137
+		return get_post_stati(array('public' => true));
138
+	}
139
+
140
+
141
+
142
+	/**
143
+	 * Searches for field on this model of type 'deleted_flag'. if it is found,
144
+	 * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name
145
+	 *
146
+	 * @return string
147
+	 * @throws EE_Error
148
+	 */
149
+	public function deleted_field_name()
150
+	{
151
+		throw new EE_Error(sprintf(__("EEM_CPT_Base should nto call deleted_field_name! It should instead use post_status_field_name",
152
+			"event_espresso")));
153
+	}
154
+
155
+
156
+
157
+	/**
158
+	 * Gets the field's name that sets the post status
159
+	 *
160
+	 * @return string
161
+	 * @throws EE_Error
162
+	 */
163
+	public function post_status_field_name()
164
+	{
165
+		$field = $this->get_a_field_of_type('EE_WP_Post_Status_Field');
166
+		if ($field) {
167
+			return $field->get_name();
168
+		} else {
169
+			throw new EE_Error(sprintf(__('We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
170
+				'event_espresso'), get_class($this), get_class($this)));
171
+		}
172
+	}
173
+
174
+
175
+
176
+	/**
177
+	 * Alters the query params so that only trashed/soft-deleted items are considered
178
+	 *
179
+	 * @param array $query_params like EEM_Base::get_all's $query_params
180
+	 * @return array like EEM_Base::get_all's $query_params
181
+	 */
182
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
183
+	{
184
+		$post_status_field_name = $this->post_status_field_name();
185
+		$query_params[0][$post_status_field_name] = self::post_status_trashed;
186
+		return $query_params;
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * Alters the query params so each item's deleted status is ignored.
193
+	 *
194
+	 * @param array $query_params
195
+	 * @return array
196
+	 */
197
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
198
+	{
199
+		$query_params['default_where_conditions'] = 'minimum';
200
+		return $query_params;
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
207
+	 *
208
+	 * @param boolean $delete       true to indicate deletion, false to indicate restoration
209
+	 * @param array   $query_params like EEM_Base::get_all
210
+	 * @return boolean success
211
+	 */
212
+	function delete_or_restore($delete = true, $query_params = array())
213
+	{
214
+		$post_status_field_name = $this->post_status_field_name();
215
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
216
+		$new_status = $delete ? self::post_status_trashed : 'draft';
217
+		if ($this->update(array($post_status_field_name => $new_status), $query_params)) {
218
+			return true;
219
+		} else {
220
+			return false;
221
+		}
222
+	}
223
+
224
+
225
+
226
+	/**
227
+	 * meta_table
228
+	 * returns first EE_Secondary_Table table name
229
+	 *
230
+	 * @access public
231
+	 * @return string
232
+	 */
233
+	public function meta_table()
234
+	{
235
+		$meta_table = $this->_get_other_tables();
236
+		$meta_table = reset($meta_table);
237
+		return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null;
238
+	}
239
+
240
+
241
+
242
+	/**
243
+	 * This simply returns an array of the meta table fields (useful for when we just need to update those fields)
244
+	 *
245
+	 * @param  bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields.  Defaults to false (no
246
+	 *                   db only fields)
247
+	 * @return array
248
+	 */
249
+	public function get_meta_table_fields($all = false)
250
+	{
251
+		$all_fields = $fields_to_return = array();
252
+		foreach ($this->_tables as $alias => $table_obj) {
253
+			if ($table_obj instanceof EE_Secondary_Table) {
254
+				$all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields);
255
+			}
256
+		}
257
+		if ( ! $all) {
258
+			foreach ($all_fields as $name => $obj) {
259
+				if ($obj instanceof EE_DB_Only_Field_Base) {
260
+					continue;
261
+				}
262
+				$fields_to_return[] = $name;
263
+			}
264
+		} else {
265
+			$fields_to_return = array_keys($all_fields);
266
+		}
267
+		return $fields_to_return;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Adds an event category with the specified name and description to the specified
274
+	 * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary,
275
+	 * and adds an entry in the term_relationship if necessary.
276
+	 *
277
+	 * @param EE_CPT_Base $cpt_model_object
278
+	 * @param string      $category_name (used to derive the term slug too)
279
+	 * @param string      $category_description
280
+	 * @param int         $parent_term_taxonomy_id
281
+	 * @return EE_Term_Taxonomy
282
+	 */
283
+	function add_event_category(
284
+		EE_CPT_Base $cpt_model_object,
285
+		$category_name,
286
+		$category_description = '',
287
+		$parent_term_taxonomy_id = null
288
+	) {
289
+		//create term
290
+		require_once(EE_MODELS . 'EEM_Term.model.php');
291
+		//first, check for a term by the same name or slug
292
+		$category_slug = sanitize_title($category_name);
293
+		$term = EEM_Term::instance()->get_one(array(
294
+			array(
295
+				'OR' => array(
296
+					'name' => $category_name,
297
+					'slug' => $category_slug,
298
+				),
299
+			),
300
+		));
301
+		if ( ! $term) {
302
+			$term = EE_Term::new_instance(array(
303
+				'name' => $category_name,
304
+				'slug' => $category_slug,
305
+			));
306
+			$term->save();
307
+		}
308
+		//make sure there's a term-taxonomy entry too
309
+		require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
310
+		$term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(
311
+			array(
312
+				'term_id'  => $term->ID(),
313
+				'taxonomy' => EE_Event_Category_Taxonomy,
314
+			),
315
+		));
316
+		/** @var $term_taxonomy EE_Term_Taxonomy */
317
+		if ( ! $term_taxonomy) {
318
+			$term_taxonomy = EE_Term_Taxonomy::new_instance(array(
319
+				'term_id'     => $term->ID(),
320
+				'taxonomy'    => EE_Event_Category_Taxonomy,
321
+				'description' => $category_description,
322
+				'count'       => 1,
323
+				'parent'      => $parent_term_taxonomy_id,
324
+			));
325
+			$term_taxonomy->save();
326
+		} else {
327
+			$term_taxonomy->set_count($term_taxonomy->count() + 1);
328
+			$term_taxonomy->save();
329
+		}
330
+		return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy');
331
+	}
332
+
333
+
334
+
335
+	/**
336
+	 * Removed the category specified by name as having a relation to this event.
337
+	 * Does not remove the term or term_taxonomy.
338
+	 *
339
+	 * @param EE_CPT_Base $cpt_model_object_event
340
+	 * @param string      $category_name name of the event category (term)
341
+	 * @return bool
342
+	 */
343
+	function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name)
344
+	{
345
+		//find the term_taxonomy by that name
346
+		$term_taxonomy = $this->get_first_related($cpt_model_object_event, 'Term_Taxonomy',
347
+			array(array('Term.name' => $category_name, 'taxonomy' => EE_Event_Category_Taxonomy)));
348
+		/** @var $term_taxonomy EE_Term_Taxonomy */
349
+		if ($term_taxonomy) {
350
+			$term_taxonomy->set_count($term_taxonomy->count() - 1);
351
+			$term_taxonomy->save();
352
+		}
353
+		return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy');
354
+	}
355
+
356
+
357
+
358
+	/**
359
+	 * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the
360
+	 * given CPT ID.  It accepts the same params as what get_the_post_thumbnail() accepts.
361
+	 *
362
+	 * @link   http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
363
+	 * @access public
364
+	 * @param int          $id   the ID for the cpt we want the feature image for
365
+	 * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array
366
+	 *                           representing width and height in pixels (i.e. array(32,32) ).
367
+	 * @param string|array $attr Optional. Query string or array of attributes.
368
+	 * @return string HTML image element
369
+	 */
370
+	public function get_feature_image($id, $size = 'thumbnail', $attr = '')
371
+	{
372
+		return get_the_post_thumbnail($id, $size, $attr);
373
+	}
374
+
375
+
376
+
377
+	/**
378
+	 * Just a handy way to get the list of post statuses currently registered with WP.
379
+	 *
380
+	 * @global array $wp_post_statuses set in wp core for storing all the post stati
381
+	 * @return array
382
+	 */
383
+	public function get_post_statuses()
384
+	{
385
+		global $wp_post_statuses;
386
+		$statuses = array();
387
+		foreach ($wp_post_statuses as $post_status => $args_object) {
388
+			$statuses[$post_status] = $args_object->label;
389
+		}
390
+		return $statuses;
391
+	}
392
+
393
+
394
+
395
+	/**
396
+	 * public method that can be used to retrieve the protected status array on the instantiated cpt model
397
+	 *
398
+	 * @return array array of statuses.
399
+	 */
400
+	public function get_status_array()
401
+	{
402
+		$statuses = $this->get_post_statuses();
403
+		//first the global filter
404
+		$statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
405
+		//now the class specific filter
406
+		$statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
407
+		return $statuses;
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * this returns the post statuses that are NOT the default wordpress status
414
+	 *
415
+	 * @return array
416
+	 */
417
+	public function get_custom_post_statuses()
418
+	{
419
+		$new_stati = array();
420
+		foreach ($this->_custom_stati as $status => $props) {
421
+			$new_stati[$status] = $props['label'];
422
+		}
423
+		return $new_stati;
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which
430
+	 * are a row from the posts table. If we're missing any fields required for the model,
431
+	 * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries,
432
+	 * make sure you are attaching all the model's fields onto the post)
433
+	 *
434
+	 * @param WP_Post|array $post
435
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
436
+	 */
437
+	public function instantiate_class_from_post_object_orig($post)
438
+	{
439
+		$post = (array)$post;
440
+		$has_all_necessary_fields_for_table = true;
441
+		//check if the post has fields on the meta table already
442
+		foreach ($this->_get_other_tables() as $table_obj) {
443
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
444
+			foreach ($fields_for_that_table as $field_obj) {
445
+				if ( ! isset($post[$field_obj->get_table_column()])
446
+					 && ! isset($post[$field_obj->get_qualified_column()])
447
+				) {
448
+					$has_all_necessary_fields_for_table = false;
449
+				}
450
+			}
451
+		}
452
+		//if we don't have all the fields we need, then just fetch the proper model from the DB
453
+		if ( ! $has_all_necessary_fields_for_table) {
454
+			return $this->get_one_by_ID($post['ID']);
455
+		} else {
456
+			return $this->instantiate_class_from_array_or_object($post);
457
+		}
458
+	}
459
+
460
+
461
+
462
+	/**
463
+	 * @param null $post
464
+	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class
465
+	 */
466
+	public function instantiate_class_from_post_object($post = null)
467
+	{
468
+		if (empty($post)) {
469
+			global $post;
470
+		}
471
+		$post = (array)$post;
472
+		$tables_needing_to_be_queried = array();
473
+		//check if the post has fields on the meta table already
474
+		foreach ($this->get_tables() as $table_obj) {
475
+			$fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias());
476
+			foreach ($fields_for_that_table as $field_obj) {
477
+				if ( ! isset($post[$field_obj->get_table_column()])
478
+					 && ! isset($post[$field_obj->get_qualified_column()])
479
+				) {
480
+					$tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj;
481
+				}
482
+			}
483
+		}
484
+		//if we don't have all the fields we need, then just fetch the proper model from the DB
485
+		if ($tables_needing_to_be_queried) {
486
+			if (count($tables_needing_to_be_queried) == 1
487
+				&& reset($tables_needing_to_be_queried)
488
+				   instanceof
489
+				   EE_Secondary_Table
490
+			) {
491
+				//so we're only missing data from a secondary table. Well that's not too hard to query for
492
+				$table_to_query = reset($tables_needing_to_be_queried);
493
+				$missing_data = $this->_do_wpdb_query('get_row', array(
494
+					'SELECT * FROM '
495
+					. $table_to_query->get_table_name()
496
+					. ' WHERE '
497
+					. $table_to_query->get_fk_on_table()
498
+					. ' = '
499
+					. $post['ID'],
500
+					ARRAY_A,
501
+				));
502
+				if ( ! empty($missing_data)) {
503
+					$post = array_merge($post, $missing_data);
504
+				}
505
+			} else {
506
+				return $this->get_one_by_ID($post['ID']);
507
+			}
508
+		}
509
+		return $this->instantiate_class_from_array_or_object($post);
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * Gets the post type associated with this
516
+	 *
517
+	 * @throws EE_Error
518
+	 * @return string
519
+	 */
520
+	public function post_type()
521
+	{
522
+		$post_type_field = null;
523
+		foreach ($this->field_settings(true) as $field_obj) {
524
+			if ($field_obj instanceof EE_WP_Post_Type_Field) {
525
+				$post_type_field = $field_obj;
526
+				break;
527
+			}
528
+		}
529
+		if ($post_type_field == null) {
530
+			throw new EE_Error(sprintf(__("CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt",
531
+				"event_espresso"), get_class($this)));
532
+		}
533
+		return $post_type_field->get_default_value();
534
+	}
535 535
 
536 536
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
         $parent_term_taxonomy_id = null
288 288
     ) {
289 289
         //create term
290
-        require_once(EE_MODELS . 'EEM_Term.model.php');
290
+        require_once(EE_MODELS.'EEM_Term.model.php');
291 291
         //first, check for a term by the same name or slug
292 292
         $category_slug = sanitize_title($category_name);
293 293
         $term = EEM_Term::instance()->get_one(array(
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
             $term->save();
307 307
         }
308 308
         //make sure there's a term-taxonomy entry too
309
-        require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php');
309
+        require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php');
310 310
         $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one(array(
311 311
             array(
312 312
                 'term_id'  => $term->ID(),
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
         //first the global filter
404 404
         $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses);
405 405
         //now the class specific filter
406
-        $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses);
406
+        $statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses);
407 407
         return $statuses;
408 408
     }
409 409
 
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
      */
437 437
     public function instantiate_class_from_post_object_orig($post)
438 438
     {
439
-        $post = (array)$post;
439
+        $post = (array) $post;
440 440
         $has_all_necessary_fields_for_table = true;
441 441
         //check if the post has fields on the meta table already
442 442
         foreach ($this->_get_other_tables() as $table_obj) {
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
         if (empty($post)) {
469 469
             global $post;
470 470
         }
471
-        $post = (array)$post;
471
+        $post = (array) $post;
472 472
         $tables_needing_to_be_queried = array();
473 473
         //check if the post has fields on the meta table already
474 474
         foreach ($this->get_tables() as $table_obj) {
Please login to merge, or discard this patch.
core/db_models/EEM_Venue.model.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -25,87 +25,87 @@  discard block
 block discarded – undo
25 25
 class EEM_Venue extends EEM_CPT_Base
26 26
 {
27 27
 
28
-    // private instance of the Attendee object
29
-    protected static $_instance = null;
28
+	// private instance of the Attendee object
29
+	protected static $_instance = null;
30 30
 
31 31
 
32 32
 
33
-    protected function __construct($timezone = null)
34
-    {
35
-        $this->singular_item = __('Venue', 'event_espresso');
36
-        $this->plural_item = __('Venues', 'event_espresso');
37
-        $this->_tables = array(
38
-            'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
39
-            'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
40
-        );
41
-        $this->_fields = array(
42
-            'Venue_CPT'  => array(
43
-                'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
44
-                'VNU_name'       => new EE_Plain_Text_Field('post_title', __("Venue Name", "event_espresso"), false,
45
-                    ''),
46
-                'VNU_desc'       => new EE_Post_Content_Field('post_content', __("Venue Description", "event_espresso"),
47
-                    false, ''),
48
-                'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
49
-                'VNU_created'    => new EE_Datetime_Field('post_date', __("Date Venue Created", "event_espresso"),
50
-                    false, EE_Datetime_Field::now),
51
-                'VNU_short_desc' => new EE_Plain_Text_Field('post_excerpt',
52
-                    __("Short Description of Venue", "event_espresso"), true, ''),
53
-                'VNU_modified'   => new EE_Datetime_Field('post_modified', __("Venue Modified Date", "event_espresso"),
54
-                    false, EE_Datetime_Field::now),
55
-                'VNU_wp_user'    => new EE_WP_User_Field('post_author', __("Venue Creator ID", "event_espresso"),
56
-                    false),
57
-                'parent'         => new EE_Integer_Field('post_parent', __("Venue Parent ID", "event_espresso"), false,
58
-                    0),
59
-                'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
60
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
61
-                // EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'),
62
-            ),
63
-            'Venue_Meta' => array(
64
-                'VNUM_ID'             => new EE_DB_Only_Int_Field('VNUM_ID',
65
-                    __("ID of Venue Meta Row", "event_espresso"), false),
66
-                'VNU_ID_fk'           => new EE_DB_Only_Int_Field('VNU_ID',
67
-                    __("Foreign Key to Venue Post ", "event_espresso"), false),
68
-                'VNU_address'         => new EE_Plain_Text_Field('VNU_address',
69
-                    __("Venue Address line 1", "event_espresso"), true, ''),
70
-                'VNU_address2'        => new EE_Plain_Text_Field('VNU_address2',
71
-                    __("Venue Address line 2", "event_espresso"), true, ''),
72
-                'VNU_city'            => new EE_Plain_Text_Field('VNU_city', __("Venue City", "event_espresso"), true,
73
-                    ''),
74
-                'STA_ID'              => new EE_Foreign_Key_Int_Field('STA_ID', __("State ID", "event_espresso"), true,
75
-                    null, 'State'),
76
-                'CNT_ISO'             => new EE_Foreign_Key_String_Field('CNT_ISO',
77
-                    __("Country Code", "event_espresso"), true, null, 'Country'),
78
-                'VNU_zip'             => new EE_Plain_Text_Field('VNU_zip',
79
-                    __("Venue Zip/Postal Code", "event_espresso"), true),
80
-                'VNU_phone'           => new EE_Plain_Text_Field('VNU_phone', __("Venue Phone", "event_espresso"),
81
-                    true),
82
-                'VNU_capacity'        => new EE_Infinite_Integer_Field('VNU_capacity',
83
-                    __("Venue Capacity", "event_espresso"), true, EE_INF),
84
-                'VNU_url'             => new EE_Plain_Text_Field('VNU_url', __('Venue Website', 'event_espresso'),
85
-                    true),
86
-                'VNU_virtual_phone'   => new EE_Plain_Text_Field('VNU_virtual_phone',
87
-                    __('Call in Number', 'event_espresso'), true),
88
-                'VNU_virtual_url'     => new EE_Plain_Text_Field('VNU_virtual_url', __('Virtual URL', 'event_espresso'),
89
-                    true),
90
-                'VNU_google_map_link' => new EE_Plain_Text_Field('VNU_google_map_link',
91
-                    __('Google Map Link', 'event_espresso'), true),
92
-                'VNU_enable_for_gmap' => new EE_Boolean_Field('VNU_enable_for_gmap',
93
-                    __('Show Google Map?', 'event_espresso'), false, false),
94
-            ),
95
-        );
96
-        $this->_model_relations = array(
97
-            'Event'             => new EE_HABTM_Relation('Event_Venue'),
98
-            'State'             => new EE_Belongs_To_Relation(),
99
-            'Country'           => new EE_Belongs_To_Relation(),
100
-            'Event_Venue'       => new EE_Has_Many_Relation(),
101
-            'WP_User'           => new EE_Belongs_To_Relation(),
102
-            'Term_Relationship' => new EE_Has_Many_Relation(),
103
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
104
-        );
105
-        //this model is generally available for reading
106
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
107
-        parent::__construct($timezone);
108
-    }
33
+	protected function __construct($timezone = null)
34
+	{
35
+		$this->singular_item = __('Venue', 'event_espresso');
36
+		$this->plural_item = __('Venues', 'event_espresso');
37
+		$this->_tables = array(
38
+			'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
39
+			'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
40
+		);
41
+		$this->_fields = array(
42
+			'Venue_CPT'  => array(
43
+				'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
44
+				'VNU_name'       => new EE_Plain_Text_Field('post_title', __("Venue Name", "event_espresso"), false,
45
+					''),
46
+				'VNU_desc'       => new EE_Post_Content_Field('post_content', __("Venue Description", "event_espresso"),
47
+					false, ''),
48
+				'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
49
+				'VNU_created'    => new EE_Datetime_Field('post_date', __("Date Venue Created", "event_espresso"),
50
+					false, EE_Datetime_Field::now),
51
+				'VNU_short_desc' => new EE_Plain_Text_Field('post_excerpt',
52
+					__("Short Description of Venue", "event_espresso"), true, ''),
53
+				'VNU_modified'   => new EE_Datetime_Field('post_modified', __("Venue Modified Date", "event_espresso"),
54
+					false, EE_Datetime_Field::now),
55
+				'VNU_wp_user'    => new EE_WP_User_Field('post_author', __("Venue Creator ID", "event_espresso"),
56
+					false),
57
+				'parent'         => new EE_Integer_Field('post_parent', __("Venue Parent ID", "event_espresso"), false,
58
+					0),
59
+				'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
60
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
61
+				// EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'),
62
+			),
63
+			'Venue_Meta' => array(
64
+				'VNUM_ID'             => new EE_DB_Only_Int_Field('VNUM_ID',
65
+					__("ID of Venue Meta Row", "event_espresso"), false),
66
+				'VNU_ID_fk'           => new EE_DB_Only_Int_Field('VNU_ID',
67
+					__("Foreign Key to Venue Post ", "event_espresso"), false),
68
+				'VNU_address'         => new EE_Plain_Text_Field('VNU_address',
69
+					__("Venue Address line 1", "event_espresso"), true, ''),
70
+				'VNU_address2'        => new EE_Plain_Text_Field('VNU_address2',
71
+					__("Venue Address line 2", "event_espresso"), true, ''),
72
+				'VNU_city'            => new EE_Plain_Text_Field('VNU_city', __("Venue City", "event_espresso"), true,
73
+					''),
74
+				'STA_ID'              => new EE_Foreign_Key_Int_Field('STA_ID', __("State ID", "event_espresso"), true,
75
+					null, 'State'),
76
+				'CNT_ISO'             => new EE_Foreign_Key_String_Field('CNT_ISO',
77
+					__("Country Code", "event_espresso"), true, null, 'Country'),
78
+				'VNU_zip'             => new EE_Plain_Text_Field('VNU_zip',
79
+					__("Venue Zip/Postal Code", "event_espresso"), true),
80
+				'VNU_phone'           => new EE_Plain_Text_Field('VNU_phone', __("Venue Phone", "event_espresso"),
81
+					true),
82
+				'VNU_capacity'        => new EE_Infinite_Integer_Field('VNU_capacity',
83
+					__("Venue Capacity", "event_espresso"), true, EE_INF),
84
+				'VNU_url'             => new EE_Plain_Text_Field('VNU_url', __('Venue Website', 'event_espresso'),
85
+					true),
86
+				'VNU_virtual_phone'   => new EE_Plain_Text_Field('VNU_virtual_phone',
87
+					__('Call in Number', 'event_espresso'), true),
88
+				'VNU_virtual_url'     => new EE_Plain_Text_Field('VNU_virtual_url', __('Virtual URL', 'event_espresso'),
89
+					true),
90
+				'VNU_google_map_link' => new EE_Plain_Text_Field('VNU_google_map_link',
91
+					__('Google Map Link', 'event_espresso'), true),
92
+				'VNU_enable_for_gmap' => new EE_Boolean_Field('VNU_enable_for_gmap',
93
+					__('Show Google Map?', 'event_espresso'), false, false),
94
+			),
95
+		);
96
+		$this->_model_relations = array(
97
+			'Event'             => new EE_HABTM_Relation('Event_Venue'),
98
+			'State'             => new EE_Belongs_To_Relation(),
99
+			'Country'           => new EE_Belongs_To_Relation(),
100
+			'Event_Venue'       => new EE_Has_Many_Relation(),
101
+			'WP_User'           => new EE_Belongs_To_Relation(),
102
+			'Term_Relationship' => new EE_Has_Many_Relation(),
103
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
104
+		);
105
+		//this model is generally available for reading
106
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
107
+		parent::__construct($timezone);
108
+	}
109 109
 
110 110
 }
111 111
 // End of file EEM_Venue.model.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
  * @author                Michael Nelson
19 19
  *                        ------------------------------------------------------------------------
20 20
  */
21
-require_once(EE_MODELS . 'EEM_Base.model.php');
21
+require_once(EE_MODELS.'EEM_Base.model.php');
22 22
 
23 23
 
24 24
 
Please login to merge, or discard this patch.
core/libraries/batch/Helpers/JobParameters.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 	 * @param array $request_data
97 97
 	 * @param array $extra_data
98 98
 	 */
99
-	function __construct( $job_id, $classname, $request_data, $extra_data = array() ) {
100
-		$this->set_job_id( $job_id );
101
-		$this->set_classname( $classname );
102
-		$this->set_request_data( $request_data );
103
-		$this->set_extra_data( $extra_data );
104
-		$this->set_status( JobParameters::status_continue );
99
+	function __construct($job_id, $classname, $request_data, $extra_data = array()) {
100
+		$this->set_job_id($job_id);
101
+		$this->set_classname($classname);
102
+		$this->set_request_data($request_data);
103
+		$this->set_extra_data($extra_data);
104
+		$this->set_status(JobParameters::status_continue);
105 105
 	}
106 106
 
107 107
 
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 	 * @param boolean $first
127 127
 	 * @return boolean success
128 128
 	 */
129
-	function save( $first = false ) {
130
-		$object_vars = get_object_vars( $this );
131
-		if( $first ) {
132
-			return add_option( $this->option_name(), $object_vars, null, 'no' );
133
-		} else{
134
-			return update_option( $this->option_name(), $object_vars );
129
+	function save($first = false) {
130
+		$object_vars = get_object_vars($this);
131
+		if ($first) {
132
+			return add_option($this->option_name(), $object_vars, null, 'no');
133
+		} else {
134
+			return update_option($this->option_name(), $object_vars);
135 135
 		}
136 136
 	}
137 137
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 	 * @return boolean
144 144
 	 */
145 145
 	function delete() {
146
-		return delete_option( $this->option_name() );
146
+		return delete_option($this->option_name());
147 147
 	}
148 148
 
149 149
 
@@ -154,26 +154,26 @@  discard block
 block discarded – undo
154 154
 	 * @return JobParameters
155 155
 	 * @throws BatchRequestException
156 156
 	 */
157
-	static function load( $job_id ) {
158
-		$job_parameter_vars = get_option( JobParameters::wp_option_prefix . $job_id );
159
-		if(
160
-			! is_array( $job_parameter_vars ) ||
161
-			! isset( $job_parameter_vars[ '_classname' ] ) ||
162
-			! isset( $job_parameter_vars[ '_request_data' ] )
157
+	static function load($job_id) {
158
+		$job_parameter_vars = get_option(JobParameters::wp_option_prefix.$job_id);
159
+		if (
160
+			! is_array($job_parameter_vars) ||
161
+			! isset($job_parameter_vars['_classname']) ||
162
+			! isset($job_parameter_vars['_request_data'])
163 163
 		) {
164 164
 			throw new BatchRequestException(
165 165
 				sprintf(
166 166
 					__('Could not retrieve job %1$s from the Wordpress options table, and so the job could not continue. The wordpress option was %2$s', 'event_espresso'),
167 167
 					$job_id,
168
-					get_option( JobParameters::wp_option_prefix . $job_id )
168
+					get_option(JobParameters::wp_option_prefix.$job_id)
169 169
 				)
170 170
 			);
171 171
 		}
172 172
 		$job_parameters = new JobParameters(
173 173
 				$job_id,
174
-				$job_parameter_vars[ '_classname' ],
175
-				$job_parameter_vars[ '_request_data'] );
176
-		foreach( $job_parameter_vars as $key => $value ) {
174
+				$job_parameter_vars['_classname'],
175
+				$job_parameter_vars['_request_data'] );
176
+		foreach ($job_parameter_vars as $key => $value) {
177 177
 			$job_parameters->{$key} = $value;
178 178
 		}
179 179
 		return $job_parameters;
@@ -217,9 +217,9 @@  discard block
 block discarded – undo
217 217
 	 * @param string|array $default
218 218
 	 * @return string|array
219 219
 	 */
220
-	function request_datum( $key, $default = '' ) {
221
-		if( isset( $this->_request_data[ $key ] ) ) {
222
-			return $this->_request_data[ $key ];
220
+	function request_datum($key, $default = '') {
221
+		if (isset($this->_request_data[$key])) {
222
+			return $this->_request_data[$key];
223 223
 		} else {
224 224
 			return $default;
225 225
 		}
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	 * @param string|array $default
234 234
 	 * @return string|array
235 235
 	 */
236
-	function extra_datum( $key, $default = '' ) {
237
-		if( isset( $this->_extra_data[ $key ] ) ) {
238
-			return $this->_extra_data[ $key ];
236
+	function extra_datum($key, $default = '') {
237
+		if (isset($this->_extra_data[$key])) {
238
+			return $this->_extra_data[$key];
239 239
 		} else {
240 240
 			return $default;
241 241
 		}
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 * @param string $key
249 249
 	 * @param string|int|array|null $value almost any extra data you want to store
250 250
 	 */
251
-	function add_extra_data( $key, $value ) {
252
-		$this->_extra_data[ $key ] = $value;
251
+	function add_extra_data($key, $value) {
252
+		$this->_extra_data[$key] = $value;
253 253
 	}
254 254
 
255 255
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * Sets the job size. You decide what units to use
279 279
 	 * @param int $size
280 280
 	 */
281
-	function set_job_size( $size ) {
281
+	function set_job_size($size) {
282 282
 		$this->_job_size = $size;
283 283
 	}
284 284
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 * @param int $newly_processed
300 300
 	 * @return int updated units processed
301 301
 	 */
302
-	function mark_processed( $newly_processed ) {
302
+	function mark_processed($newly_processed) {
303 303
 		$this->_units_processed += $newly_processed;
304 304
 		return $this->_units_processed;
305 305
 	}
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	 * Sets the total count of units processed. You might prefer to use mark_processed
311 311
 	 * @param int $total_units_processed
312 312
 	 */
313
-	function set_units_processed( $total_units_processed ) {
313
+	function set_units_processed($total_units_processed) {
314 314
 		$this->_units_processed = $total_units_processed;
315 315
 	}
316 316
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
 	 * Sets the job's ID
321 321
 	 * @param string $job_id
322 322
 	 */
323
-	function set_job_id( $job_id ) {
323
+	function set_job_id($job_id) {
324 324
 		$this->_job_id = $job_id;
325 325
 	}
326 326
 
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	 * sets the classname
331 331
 	 * @param string $classname
332 332
 	 */
333
-	function set_classname( $classname ) {
333
+	function set_classname($classname) {
334 334
 		$this->_classname = $classname;
335 335
 	}
336 336
 
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 	 * Sets the request data
341 341
 	 * @param array $request_data
342 342
 	 */
343
-	function set_request_data( $request_data ) {
343
+	function set_request_data($request_data) {
344 344
 		$this->_request_data = $request_data;
345 345
 	}
346 346
 
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 	 * Sets the array of extra data we want to store on this request
351 351
 	 * @param array $extra_data
352 352
 	 */
353
-	function set_extra_data( $extra_data ) {
353
+	function set_extra_data($extra_data) {
354 354
 		$this->_extra_data = $extra_data;
355 355
 	}
356 356
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 	 * @return string
362 362
 	 */
363 363
 	function option_name() {
364
-		return JobParameters::wp_option_prefix . $this->job_id();
364
+		return JobParameters::wp_option_prefix.$this->job_id();
365 365
 	}
366 366
 
367 367
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 	 *
381 381
 	 * @param string $status on eof JobParameters::valid_stati()
382 382
 	 */
383
-	public function set_status( $status ) {
383
+	public function set_status($status) {
384 384
 		$this->_status = $status;
385 385
 	}
386 386
 
Please login to merge, or discard this patch.
core/domain/entities/DbSafeDateTime.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\domain\entities;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -47,20 +47,20 @@  discard block
 block discarded – undo
47 47
     {
48 48
         // if the folder path is writable, then except the path + filename, else keep empty
49 49
         $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
50
-            ?  $error_log_dir
50
+            ? $error_log_dir
51 51
             : '';
52 52
     }
53 53
 
54 54
 
55 55
 
56 56
 	public function __toString() {
57
-		return $this->format( DbSafeDateTime::db_safe_timestamp_format );
57
+		return $this->format(DbSafeDateTime::db_safe_timestamp_format);
58 58
 	}
59 59
 
60 60
 
61 61
 
62 62
 	public function __sleep() {
63
-		$this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format );
63
+		$this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format);
64 64
         $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
65 65
         if ( ! $date instanceof \DateTime) {
66 66
             try {
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
                 )
84 84
             );
85 85
         }
86
-        return array( '_datetime_string' );
86
+        return array('_datetime_string');
87 87
 	}
88 88
 
89 89
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         // but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
97 97
         // so we're no better off, but at least things won't go fatal on us.
98 98
         $this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string);
99
-		$date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string );
99
+		$date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
100 100
 		if ( ! $date instanceof \DateTime) {
101 101
             $this->writeToErrorLog(
102 102
                 sprintf(
Please login to merge, or discard this patch.
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -32,24 +32,24 @@  discard block
 block discarded – undo
32 32
 	protected $_datetime_string = '';
33 33
 
34 34
 	/**
35
-     * where to write the error log to
36
-     *
37
-     * @type string $_error_log_dir
35
+	 * where to write the error log to
36
+	 *
37
+	 * @type string $_error_log_dir
38 38
 	 */
39 39
 	protected $_error_log_dir = '';
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * @param string $error_log_dir
45
-     */
46
-    public function setErrorLogDir($error_log_dir)
47
-    {
48
-        // if the folder path is writable, then except the path + filename, else keep empty
49
-        $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
50
-            ?  $error_log_dir
51
-            : '';
52
-    }
43
+	/**
44
+	 * @param string $error_log_dir
45
+	 */
46
+	public function setErrorLogDir($error_log_dir)
47
+	{
48
+		// if the folder path is writable, then except the path + filename, else keep empty
49
+		$this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
50
+			?  $error_log_dir
51
+			: '';
52
+	}
53 53
 
54 54
 
55 55
 
@@ -61,84 +61,84 @@  discard block
 block discarded – undo
61 61
 
62 62
 	public function __sleep() {
63 63
 		$this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format );
64
-        $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
65
-        if ( ! $date instanceof \DateTime) {
66
-            try {
67
-                // we want a stack trace to determine where the malformed date came from, so...
68
-                throw new \DomainException();
69
-            } catch (\DomainException $e) {
70
-                $stack_trace = $e->getTraceAsString();
71
-            }
72
-            $this->writeToErrorLog(
73
-                sprintf(
74
-                    __(
75
-                        'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s',
76
-                        'event_espresso'
77
-                    ),
78
-                    $this->_datetime_string,
79
-                    '<br />',
80
-                    print_r(\DateTime::getLastErrors(), true),
81
-                    PHP_VERSION,
82
-                    $stack_trace
83
-                )
84
-            );
85
-        }
86
-        return array( '_datetime_string' );
64
+		$date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
65
+		if ( ! $date instanceof \DateTime) {
66
+			try {
67
+				// we want a stack trace to determine where the malformed date came from, so...
68
+				throw new \DomainException();
69
+			} catch (\DomainException $e) {
70
+				$stack_trace = $e->getTraceAsString();
71
+			}
72
+			$this->writeToErrorLog(
73
+				sprintf(
74
+					__(
75
+						'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s',
76
+						'event_espresso'
77
+					),
78
+					$this->_datetime_string,
79
+					'<br />',
80
+					print_r(\DateTime::getLastErrors(), true),
81
+					PHP_VERSION,
82
+					$stack_trace
83
+				)
84
+			);
85
+		}
86
+		return array( '_datetime_string' );
87 87
 	}
88 88
 
89 89
 
90 90
 
91 91
 	public function __wakeup() {
92
-	    // if an empty or null value got saved to the db for a datetime,
93
-        // then some servers and/or PHP itself will incorrectly convert that date string
94
-        // resulting in "-0001-11-30" for the year-month-day.
95
-        // We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created,
96
-        // but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
97
-        // so we're no better off, but at least things won't go fatal on us.
98
-        $this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string);
92
+		// if an empty or null value got saved to the db for a datetime,
93
+		// then some servers and/or PHP itself will incorrectly convert that date string
94
+		// resulting in "-0001-11-30" for the year-month-day.
95
+		// We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created,
96
+		// but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
97
+		// so we're no better off, but at least things won't go fatal on us.
98
+		$this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string);
99 99
 		$date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string );
100 100
 		if ( ! $date instanceof \DateTime) {
101
-            $this->writeToErrorLog(
102
-                sprintf(
103
-                    __(
104
-                        'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s',
105
-                        'event_espresso'
106
-                    ),
107
-                    $this->_datetime_string,
108
-                    '<br />',
109
-                    print_r(\DateTime::getLastErrors(), true),
110
-                    PHP_VERSION
111
-                )
112
-            );
113
-        } else {
114
-            $this->__construct(
115
-                $date->format(\EE_Datetime_Field::mysql_timestamp_format),
116
-                new \DateTimeZone($date->format('e'))
117
-            );
118
-        }
101
+			$this->writeToErrorLog(
102
+				sprintf(
103
+					__(
104
+						'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s',
105
+						'event_espresso'
106
+					),
107
+					$this->_datetime_string,
108
+					'<br />',
109
+					print_r(\DateTime::getLastErrors(), true),
110
+					PHP_VERSION
111
+				)
112
+			);
113
+		} else {
114
+			$this->__construct(
115
+				$date->format(\EE_Datetime_Field::mysql_timestamp_format),
116
+				new \DateTimeZone($date->format('e'))
117
+			);
118
+		}
119 119
 	}
120 120
 
121
-    /**
122
-     * Creates a DbSafeDateTime from ye old DateTime
123
-     * @param \DateTime $datetime
124
-     * @return \EventEspresso\core\domain\entities\DbSafeDateTime
125
-     */
126
-    public static function createFromDateTime(\DateTime $datetime)
127
-    {
128
-        return new DbSafeDateTime(
129
-            $datetime->format(\EE_Datetime_Field::mysql_timestamp_format),
130
-            new \DateTimeZone($datetime->format('e'))
131
-        );
132
-    }
133
-
134
-    private function writeToErrorLog($message)
135
-    {
136
-        if ( ! empty($this->_error_log_dir)) {
137
-            error_log($message, 3, $this->_error_log_dir);
138
-        } else {
139
-            error_log($message);
140
-        }
141
-    }
121
+	/**
122
+	 * Creates a DbSafeDateTime from ye old DateTime
123
+	 * @param \DateTime $datetime
124
+	 * @return \EventEspresso\core\domain\entities\DbSafeDateTime
125
+	 */
126
+	public static function createFromDateTime(\DateTime $datetime)
127
+	{
128
+		return new DbSafeDateTime(
129
+			$datetime->format(\EE_Datetime_Field::mysql_timestamp_format),
130
+			new \DateTimeZone($datetime->format('e'))
131
+		);
132
+	}
133
+
134
+	private function writeToErrorLog($message)
135
+	{
136
+		if ( ! empty($this->_error_log_dir)) {
137
+			error_log($message, 3, $this->_error_log_dir);
138
+		} else {
139
+			error_log($message);
140
+		}
141
+	}
142 142
 
143 143
 
144 144
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Message.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -697,7 +697,7 @@
 block discarded – undo
697 697
     /**
698 698
      * Gets any error message.
699 699
      *
700
-     * @return mixed|null
700
+     * @return string
701 701
      */
702 702
     public function error_message()
703 703
     {
Please login to merge, or discard this patch.
Indentation   +856 added lines, -856 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -12,865 +12,865 @@  discard block
 block discarded – undo
12 12
 class EE_Message extends EE_Base_Class implements EEI_Admin_Links
13 13
 {
14 14
 
15
-    /**
16
-     * @deprecated 4.9.0  Added for backward compat with add-on's
17
-     * @type null
18
-     */
19
-    public $template_pack;
20
-
21
-    /**
22
-     * @deprecated 4.9.0 Added for backward compat with add-on's
23
-     * @type null
24
-     */
25
-    public $template_variation;
26
-
27
-    /**
28
-     * @deprecated 4.9.0 Added for backward compat with add-on's
29
-     * @type string
30
-     */
31
-    public $content = '';
32
-
33
-
34
-    /**
35
-     * @type EE_messenger $_messenger
36
-     */
37
-    protected $_messenger = null;
38
-
39
-    /**
40
-     * @type EE_message_type $_message_type
41
-     */
42
-    protected $_message_type = null;
43
-
44
-
45
-    /**
46
-     * @param array  $props_n_values
47
-     * @param string $timezone
48
-     * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
49
-     *                             format.
50
-     * @return EE_Message
51
-     */
52
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
53
-    {
54
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
55
-        //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
56
-        if ( ! $has_object) {
57
-            EE_Registry::instance()->load_helper('URL');
58
-            $props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
59
-        }
60
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
61
-    }
62
-
63
-
64
-    /**
65
-     * @param array  $props_n_values
66
-     * @param string $timezone
67
-     * @return EE_Message
68
-     */
69
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
70
-    {
71
-        return new self($props_n_values, true, $timezone);
72
-    }
73
-
74
-
75
-    /**
76
-     * Gets MSG_token
77
-     *
78
-     * @return int
79
-     */
80
-    public function MSG_token()
81
-    {
82
-        return $this->get('MSG_token');
83
-    }
84
-
85
-
86
-    /**
87
-     * Sets MSG_token
88
-     *
89
-     * @param int $MSG_token
90
-     */
91
-    public function set_MSG_token($MSG_token)
92
-    {
93
-        $this->set('MSG_token', $MSG_token);
94
-    }
95
-
96
-
97
-    /**
98
-     * Gets GRP_ID
99
-     *
100
-     * @return int
101
-     */
102
-    public function GRP_ID()
103
-    {
104
-        return $this->get('GRP_ID');
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets GRP_ID
110
-     *
111
-     * @param int $GRP_ID
112
-     */
113
-    public function set_GRP_ID($GRP_ID)
114
-    {
115
-        $this->set('GRP_ID', $GRP_ID);
116
-    }
117
-
118
-
119
-    /**
120
-     * Gets TXN_ID
121
-     *
122
-     * @return int
123
-     */
124
-    public function TXN_ID()
125
-    {
126
-        return $this->get('TXN_ID');
127
-    }
128
-
129
-
130
-    /**
131
-     * Sets TXN_ID
132
-     *
133
-     * @param int $TXN_ID
134
-     */
135
-    public function set_TXN_ID($TXN_ID)
136
-    {
137
-        $this->set('TXN_ID', $TXN_ID);
138
-    }
139
-
140
-
141
-    /**
142
-     * Gets messenger
143
-     *
144
-     * @return string
145
-     */
146
-    public function messenger()
147
-    {
148
-        return $this->get('MSG_messenger');
149
-    }
150
-
151
-
152
-    /**
153
-     * Sets messenger
154
-     *
155
-     * @param string $messenger
156
-     */
157
-    public function set_messenger($messenger)
158
-    {
159
-        $this->set('MSG_messenger', $messenger);
160
-    }
161
-
162
-
163
-    /**
164
-     * Returns corresponding messenger object for the set messenger on this message
165
-     *
166
-     * @return EE_messenger | null
167
-     */
168
-    public function messenger_object()
169
-    {
170
-        return $this->_messenger;
171
-    }
172
-
173
-
174
-    /**
175
-     * Sets messenger
176
-     *
177
-     * @param EE_messenger $messenger
178
-     */
179
-    public function set_messenger_object(EE_messenger $messenger)
180
-    {
181
-        $this->_messenger = $messenger;
182
-    }
183
-
184
-
185
-    /**
186
-     * validates messenger
187
-     *
188
-     * @param bool $throw_exceptions
189
-     * @return bool
190
-     * @throws \EE_Error
191
-     */
192
-    public function valid_messenger($throw_exceptions = false)
193
-    {
194
-        if ($this->_messenger instanceof EE_messenger) {
195
-            return true;
196
-        }
197
-        if ($throw_exceptions) {
198
-            throw new EE_Error(
199
-                sprintf(
200
-                    __(
201
-                        'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
202
-                        'event_espresso'
203
-                    ),
204
-                    $this->messenger()
205
-                )
206
-            );
207
-        }
208
-        return false;
209
-    }
210
-
211
-
212
-    /**
213
-     * This returns the set localized label for the messenger on this message.
214
-     * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
215
-     * with this message.
216
-     *
217
-     * @param   bool $plural whether to return the plural label or not.
218
-     * @return string
219
-     */
220
-    public function messenger_label($plural = false)
221
-    {
222
-        $label_type = $plural ? 'plural' : 'singular';
223
-        $messenger  = $this->messenger_object();
224
-        return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger();
225
-    }
226
-
227
-
228
-    /**
229
-     * Gets message_type
230
-     *
231
-     * @return string
232
-     */
233
-    public function message_type()
234
-    {
235
-        return $this->get('MSG_message_type');
236
-    }
237
-
238
-
239
-    /**
240
-     * Sets message_type
241
-     *
242
-     * @param string $message_type
243
-     */
244
-    public function set_message_type($message_type)
245
-    {
246
-        $this->set('MSG_message_type', $message_type);
247
-    }
248
-
249
-
250
-    /**
251
-     * Returns the message type object for the set message type on this message
252
-     *
253
-     * @return EE_message_type | null
254
-     */
255
-    public function message_type_object()
256
-    {
257
-        return $this->_message_type;
258
-    }
259
-
260
-
261
-    /**
262
-     * Sets message_type
263
-     *
264
-     * @param EE_message_type $message_type
265
-     * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
266
-     *                                        the message type or not.
267
-     */
268
-    public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
269
-    {
270
-        $this->_message_type = $message_type;
271
-        if ($set_priority) {
272
-            $this->set_priority($this->_message_type->get_priority());
273
-        }
274
-    }
275
-
276
-
277
-    /**
278
-     * validates message_type
279
-     *
280
-     * @param bool $throw_exceptions
281
-     * @return bool
282
-     * @throws \EE_Error
283
-     */
284
-    public function valid_message_type($throw_exceptions = false)
285
-    {
286
-        if ($this->_message_type instanceof EE_message_type) {
287
-            return true;
288
-        }
289
-        if ($throw_exceptions) {
290
-            throw new EE_Error(
291
-                sprintf(
292
-                    __(
293
-                        'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
294
-                        'event_espresso'
295
-                    ),
296
-                    $this->message_type()
297
-                )
298
-            );
299
-        }
300
-        return false;
301
-    }
302
-
303
-
304
-    /**
305
-     * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
306
-     *
307
-     * @param bool $throw_exceptions
308
-     * @return bool
309
-     * @throws \EE_Error
310
-     */
311
-    public function is_valid($throw_exceptions = false)
312
-    {
313
-        if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
314
-            return true;
315
-        }
316
-        return false;
317
-    }
318
-
319
-
320
-    /**
321
-     * This validates whether the internal messenger and message type objects are valid for sending.
322
-     * Three checks are done:
323
-     * 1. There is a valid messenger object.
324
-     * 2. There is a valid message type object.
325
-     * 3. The message type object is active for the messenger.
326
-     *
327
-     * @throws EE_Error  But only if $throw_exceptions is set to true.
328
-     * @param bool $throw_exceptions
329
-     * @return bool
330
-     */
331
-    public function is_valid_for_sending_or_generation($throw_exceptions = false)
332
-    {
333
-        $valid = false;
334
-        if ($this->is_valid($throw_exceptions)) {
335
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
336
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
337
-            $valid                    = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(),
338
-                $this->message_type());
339
-            if ( ! $valid && $throw_exceptions) {
340
-                throw new EE_Error(
341
-                    sprintf(
342
-                        __('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
-                            'event_espresso'),
344
-                        $this->message_type(),
345
-                        $this->messenger()
346
-                    )
347
-                );
348
-            }
349
-        }
350
-        return $valid;
351
-    }
352
-
353
-
354
-    /**
355
-     * This returns the set localized label for the message type on this message.
356
-     * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
357
-     * with this message.
358
-     *
359
-     * @param   bool $plural whether to return the plural label or not.
360
-     * @return string
361
-     */
362
-    public function message_type_label($plural = false)
363
-    {
364
-        $label_type   = $plural ? 'plural' : 'singular';
365
-        $message_type = $this->message_type_object();
366
-        return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : $this->message_type();
367
-    }
368
-
369
-
370
-    /**
371
-     * Gets context
372
-     *
373
-     * @return string
374
-     */
375
-    public function context()
376
-    {
377
-        return $this->get('MSG_context');
378
-    }
379
-
380
-
381
-    /**
382
-     * This returns the corresponding localized label for the given context slug, if possible from installed message
383
-     * types. Otherwise, this will just return the set context slug on this object.
384
-     *
385
-     * @return string
386
-     */
387
-    public function context_label()
388
-    {
389
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
390
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
-        $contexts                 = $message_resource_manager->get_all_contexts();
392
-        return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context();
393
-    }
394
-
395
-
396
-    /**
397
-     * Sets context
398
-     *
399
-     * @param string $context
400
-     */
401
-    public function set_context($context)
402
-    {
403
-        $this->set('MSG_context', $context);
404
-    }
405
-
406
-
407
-    /**
408
-     * Gets recipient_ID
409
-     *
410
-     * @return int
411
-     */
412
-    public function recipient_ID()
413
-    {
414
-        return $this->get('MSG_recipient_ID');
415
-    }
416
-
417
-
418
-    /**
419
-     * Sets recipient_ID
420
-     *
421
-     * @param string $recipient_ID
422
-     */
423
-    public function set_recipient_ID($recipient_ID)
424
-    {
425
-        $this->set('MSG_recipient_ID', $recipient_ID);
426
-    }
427
-
428
-
429
-    /**
430
-     * Gets recipient_type
431
-     *
432
-     * @return string
433
-     */
434
-    public function recipient_type()
435
-    {
436
-        return $this->get('MSG_recipient_type');
437
-    }
438
-
439
-
440
-    /**
441
-     * Return the related object matching the recipient type and ID.
442
-     *
443
-     * @return EE_Base_Class | null
444
-     */
445
-    public function recipient_object()
446
-    {
447
-        if ( ! $this->recipient_type() || ! $this->recipient_ID()) {
448
-            return null;
449
-        }
450
-
451
-        return $this->get_first_related($this->recipient_type());
452
-    }
453
-
454
-
455
-    /**
456
-     * Sets recipient_type
457
-     *
458
-     * @param string $recipient_type
459
-     */
460
-    public function set_recipient_type($recipient_type)
461
-    {
462
-        $this->set('MSG_recipient_type', $recipient_type);
463
-    }
464
-
465
-
466
-    /**
467
-     * Gets content
468
-     *
469
-     * @return string
470
-     */
471
-    public function content()
472
-    {
473
-        return $this->get('MSG_content');
474
-    }
475
-
476
-
477
-    /**
478
-     * Sets content
479
-     *
480
-     * @param string $content
481
-     */
482
-    public function set_content($content)
483
-    {
484
-        $this->set('MSG_content', $content);
485
-    }
486
-
487
-
488
-    /**
489
-     * Gets subject
490
-     *
491
-     * @return string
492
-     */
493
-    public function subject()
494
-    {
495
-        return $this->get('MSG_subject');
496
-    }
497
-
498
-
499
-    /**
500
-     * Sets subject
501
-     *
502
-     * @param string $subject
503
-     */
504
-    public function set_subject($subject)
505
-    {
506
-        $this->set('MSG_subject', $subject);
507
-    }
508
-
509
-
510
-    /**
511
-     * Gets to
512
-     *
513
-     * @return string
514
-     */
515
-    public function to()
516
-    {
517
-        $to = $this->get('MSG_to');
518
-        return empty($to) ? __('No recipient', 'event_espresso') : $to;
519
-    }
520
-
521
-
522
-    /**
523
-     * Sets to
524
-     *
525
-     * @param string $to
526
-     */
527
-    public function set_to($to)
528
-    {
529
-        $this->set('MSG_to', $to);
530
-    }
531
-
532
-
533
-    /**
534
-     * Gets from
535
-     *
536
-     * @return string
537
-     */
538
-    public function from()
539
-    {
540
-        return $this->get('MSG_from');
541
-    }
542
-
543
-
544
-    /**
545
-     * Sets from
546
-     *
547
-     * @param string $from
548
-     */
549
-    public function set_from($from)
550
-    {
551
-        $this->set('MSG_from', $from);
552
-    }
553
-
554
-
555
-    /**
556
-     * Gets priority
557
-     *
558
-     * @return int
559
-     */
560
-    public function priority()
561
-    {
562
-        return $this->get('MSG_priority');
563
-    }
564
-
565
-
566
-    /**
567
-     * Sets priority
568
-     * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
569
-     * this method calls the send_now method to verify that.
570
-     *
571
-     * @param int $priority
572
-     */
573
-    public function set_priority($priority)
574
-    {
575
-        $priority = $this->send_now() ? EEM_Message::priority_high : $priority;
576
-        parent::set('MSG_priority', $priority);
577
-    }
578
-
579
-
580
-    /**
581
-     * Overrides parent::set method so we can capture any sets for priority.
582
-     *
583
-     * @see parent::set() for phpdocs
584
-     * @param string $field_name
585
-     * @param mixed  $field_value
586
-     * @param bool   $use_default
587
-     * @throws EE_Error
588
-     */
589
-    public function set($field_name, $field_value, $use_default = false)
590
-    {
591
-        if ($field_name === 'MSG_priority') {
592
-            $this->set_priority($field_value);
593
-        }
594
-        parent::set($field_name, $field_value, $use_default);
595
-    }
596
-
597
-
598
-    /**
599
-     * @return bool
600
-     * @throws \EE_Error
601
-     */
602
-    public function send_now()
603
-    {
604
-        $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority();
605
-        return $send_now === EEM_Message::priority_high ? true : false;
606
-    }
607
-
608
-
609
-    /**
610
-     * Gets STS_ID
611
-     *
612
-     * @return string
613
-     */
614
-    public function STS_ID()
615
-    {
616
-        return $this->get('STS_ID');
617
-    }
618
-
619
-
620
-    /**
621
-     * Sets STS_ID
622
-     *
623
-     * @param string $STS_ID
624
-     */
625
-    public function set_STS_ID($STS_ID)
626
-    {
627
-        $this->set('STS_ID', $STS_ID);
628
-    }
629
-
630
-
631
-    /**
632
-     * Gets created
633
-     *
634
-     * @return string
635
-     */
636
-    public function created()
637
-    {
638
-        return $this->get('MSG_created');
639
-    }
640
-
641
-
642
-    /**
643
-     * Sets created
644
-     *
645
-     * @param string $created
646
-     */
647
-    public function set_created($created)
648
-    {
649
-        $this->set('MSG_created', $created);
650
-    }
651
-
652
-
653
-    /**
654
-     * Gets modified
655
-     *
656
-     * @return string
657
-     */
658
-    public function modified()
659
-    {
660
-        return $this->get('MSG_modified');
661
-    }
662
-
663
-
664
-    /**
665
-     * Sets modified
666
-     *
667
-     * @param string $modified
668
-     */
669
-    public function set_modified($modified)
670
-    {
671
-        $this->set('MSG_modified', $modified);
672
-    }
673
-
674
-
675
-    /**
676
-     * Sets generation data for this message.
677
-     *
678
-     * @param mixed $data
679
-     */
680
-    public function set_generation_data($data)
681
-    {
682
-        $this->set_field_or_extra_meta('MSG_generation_data', $data);
683
-    }
684
-
685
-
686
-    /**
687
-     * Returns any set generation data for this message.
688
-     *
689
-     * @return mixed|null
690
-     */
691
-    public function get_generation_data()
692
-    {
693
-        return $this->get_field_or_extra_meta('MSG_generation_data');
694
-    }
695
-
696
-
697
-    /**
698
-     * Gets any error message.
699
-     *
700
-     * @return mixed|null
701
-     */
702
-    public function error_message()
703
-    {
704
-        return $this->get_field_or_extra_meta('MSG_error');
705
-    }
706
-
707
-
708
-    /**
709
-     * Sets an error message.
710
-     *
711
-     * @param $message
712
-     * @return bool|int
713
-     */
714
-    public function set_error_message($message)
715
-    {
716
-        return $this->set_field_or_extra_meta('MSG_error', $message);
717
-    }
718
-
719
-
720
-    /**
721
-     * This retrieves the associated template pack with this message.
722
-     *
723
-     * @return EE_Messages_Template_Pack | null
724
-     */
725
-    public function get_template_pack()
726
-    {
727
-        /**
728
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
729
-         */
730
-        if ( ! empty($this->template_pack)) {
731
-            return $this->template_pack;
732
-        }
733
-        /** @type EE_Message_Template_Group $grp */
734
-        $grp = $this->get_first_related('Message_Template_Group');
735
-        //if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
736
-        if ( ! $grp instanceof EE_Message_Template_Group) {
737
-            $grp = EEM_Message_Template_Group::instance()->get_one(
738
-                array(
739
-                    array(
740
-                        'MTP_messenger'    => $this->messenger(),
741
-                        'MTP_message_type' => $this->message_type(),
742
-                        'MTP_is_global'    => true,
743
-                    ),
744
-                )
745
-            );
746
-        }
747
-
748
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
749
-    }
750
-
751
-
752
-    /**
753
-     * Retrieves the variation used for generating this message.
754
-     *
755
-     * @return string
756
-     */
757
-    public function get_template_pack_variation()
758
-    {
759
-        /**
760
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
761
-         */
762
-        if ( ! empty($this->template_variation)) {
763
-            return $this->template_variation;
764
-        }
765
-
766
-        /** @type EE_Message_Template_Group $grp */
767
-        $grp = $this->get_first_related('Message_Template_Group');
768
-
769
-        //if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
770
-        if ( ! $grp instanceof EE_Message_Template_Group) {
771
-            $grp = EEM_Message_Template_Group::instance()->get_one(
772
-                array(
773
-                    array(
774
-                        'MTP_messenger'    => $this->messenger(),
775
-                        'MTP_message_type' => $this->message_type(),
776
-                        'MTP_is_global'    => true,
777
-                    ),
778
-                )
779
-            );
780
-        }
781
-
782
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
783
-    }
784
-
785
-    /**
786
-     * Return the link to the admin details for the object.
787
-     *
788
-     * @return string
789
-     */
790
-    public function get_admin_details_link()
791
-    {
792
-        EE_Registry::instance()->load_helper('URL');
793
-        EE_Registry::instance()->load_helper('MSG_Template');
794
-        switch ($this->STS_ID()) {
795
-            case EEM_Message::status_failed :
796
-            case EEM_Message::status_debug_only :
797
-                return EEH_MSG_Template::generate_error_display_trigger($this);
798
-                break;
799
-
800
-            case EEM_Message::status_sent :
801
-                return EEH_MSG_Template::generate_browser_trigger($this);
802
-                break;
803
-
804
-            default :
805
-                return '';
806
-        }
807
-    }
808
-
809
-    /**
810
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
811
-     *
812
-     * @return string
813
-     */
814
-    public function get_admin_edit_link()
815
-    {
816
-        return $this->get_admin_details_link();
817
-    }
818
-
819
-    /**
820
-     * Returns the link to a settings page for the object.
821
-     *
822
-     * @return string
823
-     */
824
-    public function get_admin_settings_link()
825
-    {
826
-        EE_Registry::instance()->load_helper('URL');
827
-        return EEH_URL::add_query_args_and_nonce(
828
-            array(
829
-                'page'   => 'espresso_messages',
830
-                'action' => 'settings',
831
-            ),
832
-            admin_url('admin.php')
833
-        );
834
-    }
835
-
836
-    /**
837
-     * Returns the link to the "overview" for the object (typically the "list table" view).
838
-     *
839
-     * @return string
840
-     */
841
-    public function get_admin_overview_link()
842
-    {
843
-        EE_Registry::instance()->load_helper('URL');
844
-        return EEH_URL::add_query_args_and_nonce(
845
-            array(
846
-                'page'   => 'espresso_messages',
847
-                'action' => 'default',
848
-            ),
849
-            admin_url('admin.php')
850
-        );
851
-    }
852
-
853
-
854
-    /**
855
-     * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
856
-     * it.
857
-     * Note this also SAVES the current message object to the db because it adds an error message to accompany the status.
858
-     *
859
-     */
860
-    public function set_messenger_is_executing()
861
-    {
862
-        $this->set_STS_ID( EEM_Message::status_messenger_executing );
863
-        $this->set_error_message(
864
-            esc_html__(
865
-                'A message with this status indicates that there was a problem that occurred while the message was being
15
+	/**
16
+	 * @deprecated 4.9.0  Added for backward compat with add-on's
17
+	 * @type null
18
+	 */
19
+	public $template_pack;
20
+
21
+	/**
22
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
23
+	 * @type null
24
+	 */
25
+	public $template_variation;
26
+
27
+	/**
28
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
29
+	 * @type string
30
+	 */
31
+	public $content = '';
32
+
33
+
34
+	/**
35
+	 * @type EE_messenger $_messenger
36
+	 */
37
+	protected $_messenger = null;
38
+
39
+	/**
40
+	 * @type EE_message_type $_message_type
41
+	 */
42
+	protected $_message_type = null;
43
+
44
+
45
+	/**
46
+	 * @param array  $props_n_values
47
+	 * @param string $timezone
48
+	 * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
49
+	 *                             format.
50
+	 * @return EE_Message
51
+	 */
52
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
53
+	{
54
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
55
+		//if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
56
+		if ( ! $has_object) {
57
+			EE_Registry::instance()->load_helper('URL');
58
+			$props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
59
+		}
60
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
61
+	}
62
+
63
+
64
+	/**
65
+	 * @param array  $props_n_values
66
+	 * @param string $timezone
67
+	 * @return EE_Message
68
+	 */
69
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
70
+	{
71
+		return new self($props_n_values, true, $timezone);
72
+	}
73
+
74
+
75
+	/**
76
+	 * Gets MSG_token
77
+	 *
78
+	 * @return int
79
+	 */
80
+	public function MSG_token()
81
+	{
82
+		return $this->get('MSG_token');
83
+	}
84
+
85
+
86
+	/**
87
+	 * Sets MSG_token
88
+	 *
89
+	 * @param int $MSG_token
90
+	 */
91
+	public function set_MSG_token($MSG_token)
92
+	{
93
+		$this->set('MSG_token', $MSG_token);
94
+	}
95
+
96
+
97
+	/**
98
+	 * Gets GRP_ID
99
+	 *
100
+	 * @return int
101
+	 */
102
+	public function GRP_ID()
103
+	{
104
+		return $this->get('GRP_ID');
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets GRP_ID
110
+	 *
111
+	 * @param int $GRP_ID
112
+	 */
113
+	public function set_GRP_ID($GRP_ID)
114
+	{
115
+		$this->set('GRP_ID', $GRP_ID);
116
+	}
117
+
118
+
119
+	/**
120
+	 * Gets TXN_ID
121
+	 *
122
+	 * @return int
123
+	 */
124
+	public function TXN_ID()
125
+	{
126
+		return $this->get('TXN_ID');
127
+	}
128
+
129
+
130
+	/**
131
+	 * Sets TXN_ID
132
+	 *
133
+	 * @param int $TXN_ID
134
+	 */
135
+	public function set_TXN_ID($TXN_ID)
136
+	{
137
+		$this->set('TXN_ID', $TXN_ID);
138
+	}
139
+
140
+
141
+	/**
142
+	 * Gets messenger
143
+	 *
144
+	 * @return string
145
+	 */
146
+	public function messenger()
147
+	{
148
+		return $this->get('MSG_messenger');
149
+	}
150
+
151
+
152
+	/**
153
+	 * Sets messenger
154
+	 *
155
+	 * @param string $messenger
156
+	 */
157
+	public function set_messenger($messenger)
158
+	{
159
+		$this->set('MSG_messenger', $messenger);
160
+	}
161
+
162
+
163
+	/**
164
+	 * Returns corresponding messenger object for the set messenger on this message
165
+	 *
166
+	 * @return EE_messenger | null
167
+	 */
168
+	public function messenger_object()
169
+	{
170
+		return $this->_messenger;
171
+	}
172
+
173
+
174
+	/**
175
+	 * Sets messenger
176
+	 *
177
+	 * @param EE_messenger $messenger
178
+	 */
179
+	public function set_messenger_object(EE_messenger $messenger)
180
+	{
181
+		$this->_messenger = $messenger;
182
+	}
183
+
184
+
185
+	/**
186
+	 * validates messenger
187
+	 *
188
+	 * @param bool $throw_exceptions
189
+	 * @return bool
190
+	 * @throws \EE_Error
191
+	 */
192
+	public function valid_messenger($throw_exceptions = false)
193
+	{
194
+		if ($this->_messenger instanceof EE_messenger) {
195
+			return true;
196
+		}
197
+		if ($throw_exceptions) {
198
+			throw new EE_Error(
199
+				sprintf(
200
+					__(
201
+						'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
202
+						'event_espresso'
203
+					),
204
+					$this->messenger()
205
+				)
206
+			);
207
+		}
208
+		return false;
209
+	}
210
+
211
+
212
+	/**
213
+	 * This returns the set localized label for the messenger on this message.
214
+	 * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
215
+	 * with this message.
216
+	 *
217
+	 * @param   bool $plural whether to return the plural label or not.
218
+	 * @return string
219
+	 */
220
+	public function messenger_label($plural = false)
221
+	{
222
+		$label_type = $plural ? 'plural' : 'singular';
223
+		$messenger  = $this->messenger_object();
224
+		return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger();
225
+	}
226
+
227
+
228
+	/**
229
+	 * Gets message_type
230
+	 *
231
+	 * @return string
232
+	 */
233
+	public function message_type()
234
+	{
235
+		return $this->get('MSG_message_type');
236
+	}
237
+
238
+
239
+	/**
240
+	 * Sets message_type
241
+	 *
242
+	 * @param string $message_type
243
+	 */
244
+	public function set_message_type($message_type)
245
+	{
246
+		$this->set('MSG_message_type', $message_type);
247
+	}
248
+
249
+
250
+	/**
251
+	 * Returns the message type object for the set message type on this message
252
+	 *
253
+	 * @return EE_message_type | null
254
+	 */
255
+	public function message_type_object()
256
+	{
257
+		return $this->_message_type;
258
+	}
259
+
260
+
261
+	/**
262
+	 * Sets message_type
263
+	 *
264
+	 * @param EE_message_type $message_type
265
+	 * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
266
+	 *                                        the message type or not.
267
+	 */
268
+	public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
269
+	{
270
+		$this->_message_type = $message_type;
271
+		if ($set_priority) {
272
+			$this->set_priority($this->_message_type->get_priority());
273
+		}
274
+	}
275
+
276
+
277
+	/**
278
+	 * validates message_type
279
+	 *
280
+	 * @param bool $throw_exceptions
281
+	 * @return bool
282
+	 * @throws \EE_Error
283
+	 */
284
+	public function valid_message_type($throw_exceptions = false)
285
+	{
286
+		if ($this->_message_type instanceof EE_message_type) {
287
+			return true;
288
+		}
289
+		if ($throw_exceptions) {
290
+			throw new EE_Error(
291
+				sprintf(
292
+					__(
293
+						'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
294
+						'event_espresso'
295
+					),
296
+					$this->message_type()
297
+				)
298
+			);
299
+		}
300
+		return false;
301
+	}
302
+
303
+
304
+	/**
305
+	 * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
306
+	 *
307
+	 * @param bool $throw_exceptions
308
+	 * @return bool
309
+	 * @throws \EE_Error
310
+	 */
311
+	public function is_valid($throw_exceptions = false)
312
+	{
313
+		if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
314
+			return true;
315
+		}
316
+		return false;
317
+	}
318
+
319
+
320
+	/**
321
+	 * This validates whether the internal messenger and message type objects are valid for sending.
322
+	 * Three checks are done:
323
+	 * 1. There is a valid messenger object.
324
+	 * 2. There is a valid message type object.
325
+	 * 3. The message type object is active for the messenger.
326
+	 *
327
+	 * @throws EE_Error  But only if $throw_exceptions is set to true.
328
+	 * @param bool $throw_exceptions
329
+	 * @return bool
330
+	 */
331
+	public function is_valid_for_sending_or_generation($throw_exceptions = false)
332
+	{
333
+		$valid = false;
334
+		if ($this->is_valid($throw_exceptions)) {
335
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
336
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
337
+			$valid                    = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(),
338
+				$this->message_type());
339
+			if ( ! $valid && $throw_exceptions) {
340
+				throw new EE_Error(
341
+					sprintf(
342
+						__('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
+							'event_espresso'),
344
+						$this->message_type(),
345
+						$this->messenger()
346
+					)
347
+				);
348
+			}
349
+		}
350
+		return $valid;
351
+	}
352
+
353
+
354
+	/**
355
+	 * This returns the set localized label for the message type on this message.
356
+	 * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
357
+	 * with this message.
358
+	 *
359
+	 * @param   bool $plural whether to return the plural label or not.
360
+	 * @return string
361
+	 */
362
+	public function message_type_label($plural = false)
363
+	{
364
+		$label_type   = $plural ? 'plural' : 'singular';
365
+		$message_type = $this->message_type_object();
366
+		return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : $this->message_type();
367
+	}
368
+
369
+
370
+	/**
371
+	 * Gets context
372
+	 *
373
+	 * @return string
374
+	 */
375
+	public function context()
376
+	{
377
+		return $this->get('MSG_context');
378
+	}
379
+
380
+
381
+	/**
382
+	 * This returns the corresponding localized label for the given context slug, if possible from installed message
383
+	 * types. Otherwise, this will just return the set context slug on this object.
384
+	 *
385
+	 * @return string
386
+	 */
387
+	public function context_label()
388
+	{
389
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
390
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
+		$contexts                 = $message_resource_manager->get_all_contexts();
392
+		return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context();
393
+	}
394
+
395
+
396
+	/**
397
+	 * Sets context
398
+	 *
399
+	 * @param string $context
400
+	 */
401
+	public function set_context($context)
402
+	{
403
+		$this->set('MSG_context', $context);
404
+	}
405
+
406
+
407
+	/**
408
+	 * Gets recipient_ID
409
+	 *
410
+	 * @return int
411
+	 */
412
+	public function recipient_ID()
413
+	{
414
+		return $this->get('MSG_recipient_ID');
415
+	}
416
+
417
+
418
+	/**
419
+	 * Sets recipient_ID
420
+	 *
421
+	 * @param string $recipient_ID
422
+	 */
423
+	public function set_recipient_ID($recipient_ID)
424
+	{
425
+		$this->set('MSG_recipient_ID', $recipient_ID);
426
+	}
427
+
428
+
429
+	/**
430
+	 * Gets recipient_type
431
+	 *
432
+	 * @return string
433
+	 */
434
+	public function recipient_type()
435
+	{
436
+		return $this->get('MSG_recipient_type');
437
+	}
438
+
439
+
440
+	/**
441
+	 * Return the related object matching the recipient type and ID.
442
+	 *
443
+	 * @return EE_Base_Class | null
444
+	 */
445
+	public function recipient_object()
446
+	{
447
+		if ( ! $this->recipient_type() || ! $this->recipient_ID()) {
448
+			return null;
449
+		}
450
+
451
+		return $this->get_first_related($this->recipient_type());
452
+	}
453
+
454
+
455
+	/**
456
+	 * Sets recipient_type
457
+	 *
458
+	 * @param string $recipient_type
459
+	 */
460
+	public function set_recipient_type($recipient_type)
461
+	{
462
+		$this->set('MSG_recipient_type', $recipient_type);
463
+	}
464
+
465
+
466
+	/**
467
+	 * Gets content
468
+	 *
469
+	 * @return string
470
+	 */
471
+	public function content()
472
+	{
473
+		return $this->get('MSG_content');
474
+	}
475
+
476
+
477
+	/**
478
+	 * Sets content
479
+	 *
480
+	 * @param string $content
481
+	 */
482
+	public function set_content($content)
483
+	{
484
+		$this->set('MSG_content', $content);
485
+	}
486
+
487
+
488
+	/**
489
+	 * Gets subject
490
+	 *
491
+	 * @return string
492
+	 */
493
+	public function subject()
494
+	{
495
+		return $this->get('MSG_subject');
496
+	}
497
+
498
+
499
+	/**
500
+	 * Sets subject
501
+	 *
502
+	 * @param string $subject
503
+	 */
504
+	public function set_subject($subject)
505
+	{
506
+		$this->set('MSG_subject', $subject);
507
+	}
508
+
509
+
510
+	/**
511
+	 * Gets to
512
+	 *
513
+	 * @return string
514
+	 */
515
+	public function to()
516
+	{
517
+		$to = $this->get('MSG_to');
518
+		return empty($to) ? __('No recipient', 'event_espresso') : $to;
519
+	}
520
+
521
+
522
+	/**
523
+	 * Sets to
524
+	 *
525
+	 * @param string $to
526
+	 */
527
+	public function set_to($to)
528
+	{
529
+		$this->set('MSG_to', $to);
530
+	}
531
+
532
+
533
+	/**
534
+	 * Gets from
535
+	 *
536
+	 * @return string
537
+	 */
538
+	public function from()
539
+	{
540
+		return $this->get('MSG_from');
541
+	}
542
+
543
+
544
+	/**
545
+	 * Sets from
546
+	 *
547
+	 * @param string $from
548
+	 */
549
+	public function set_from($from)
550
+	{
551
+		$this->set('MSG_from', $from);
552
+	}
553
+
554
+
555
+	/**
556
+	 * Gets priority
557
+	 *
558
+	 * @return int
559
+	 */
560
+	public function priority()
561
+	{
562
+		return $this->get('MSG_priority');
563
+	}
564
+
565
+
566
+	/**
567
+	 * Sets priority
568
+	 * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
569
+	 * this method calls the send_now method to verify that.
570
+	 *
571
+	 * @param int $priority
572
+	 */
573
+	public function set_priority($priority)
574
+	{
575
+		$priority = $this->send_now() ? EEM_Message::priority_high : $priority;
576
+		parent::set('MSG_priority', $priority);
577
+	}
578
+
579
+
580
+	/**
581
+	 * Overrides parent::set method so we can capture any sets for priority.
582
+	 *
583
+	 * @see parent::set() for phpdocs
584
+	 * @param string $field_name
585
+	 * @param mixed  $field_value
586
+	 * @param bool   $use_default
587
+	 * @throws EE_Error
588
+	 */
589
+	public function set($field_name, $field_value, $use_default = false)
590
+	{
591
+		if ($field_name === 'MSG_priority') {
592
+			$this->set_priority($field_value);
593
+		}
594
+		parent::set($field_name, $field_value, $use_default);
595
+	}
596
+
597
+
598
+	/**
599
+	 * @return bool
600
+	 * @throws \EE_Error
601
+	 */
602
+	public function send_now()
603
+	{
604
+		$send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority();
605
+		return $send_now === EEM_Message::priority_high ? true : false;
606
+	}
607
+
608
+
609
+	/**
610
+	 * Gets STS_ID
611
+	 *
612
+	 * @return string
613
+	 */
614
+	public function STS_ID()
615
+	{
616
+		return $this->get('STS_ID');
617
+	}
618
+
619
+
620
+	/**
621
+	 * Sets STS_ID
622
+	 *
623
+	 * @param string $STS_ID
624
+	 */
625
+	public function set_STS_ID($STS_ID)
626
+	{
627
+		$this->set('STS_ID', $STS_ID);
628
+	}
629
+
630
+
631
+	/**
632
+	 * Gets created
633
+	 *
634
+	 * @return string
635
+	 */
636
+	public function created()
637
+	{
638
+		return $this->get('MSG_created');
639
+	}
640
+
641
+
642
+	/**
643
+	 * Sets created
644
+	 *
645
+	 * @param string $created
646
+	 */
647
+	public function set_created($created)
648
+	{
649
+		$this->set('MSG_created', $created);
650
+	}
651
+
652
+
653
+	/**
654
+	 * Gets modified
655
+	 *
656
+	 * @return string
657
+	 */
658
+	public function modified()
659
+	{
660
+		return $this->get('MSG_modified');
661
+	}
662
+
663
+
664
+	/**
665
+	 * Sets modified
666
+	 *
667
+	 * @param string $modified
668
+	 */
669
+	public function set_modified($modified)
670
+	{
671
+		$this->set('MSG_modified', $modified);
672
+	}
673
+
674
+
675
+	/**
676
+	 * Sets generation data for this message.
677
+	 *
678
+	 * @param mixed $data
679
+	 */
680
+	public function set_generation_data($data)
681
+	{
682
+		$this->set_field_or_extra_meta('MSG_generation_data', $data);
683
+	}
684
+
685
+
686
+	/**
687
+	 * Returns any set generation data for this message.
688
+	 *
689
+	 * @return mixed|null
690
+	 */
691
+	public function get_generation_data()
692
+	{
693
+		return $this->get_field_or_extra_meta('MSG_generation_data');
694
+	}
695
+
696
+
697
+	/**
698
+	 * Gets any error message.
699
+	 *
700
+	 * @return mixed|null
701
+	 */
702
+	public function error_message()
703
+	{
704
+		return $this->get_field_or_extra_meta('MSG_error');
705
+	}
706
+
707
+
708
+	/**
709
+	 * Sets an error message.
710
+	 *
711
+	 * @param $message
712
+	 * @return bool|int
713
+	 */
714
+	public function set_error_message($message)
715
+	{
716
+		return $this->set_field_or_extra_meta('MSG_error', $message);
717
+	}
718
+
719
+
720
+	/**
721
+	 * This retrieves the associated template pack with this message.
722
+	 *
723
+	 * @return EE_Messages_Template_Pack | null
724
+	 */
725
+	public function get_template_pack()
726
+	{
727
+		/**
728
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
729
+		 */
730
+		if ( ! empty($this->template_pack)) {
731
+			return $this->template_pack;
732
+		}
733
+		/** @type EE_Message_Template_Group $grp */
734
+		$grp = $this->get_first_related('Message_Template_Group');
735
+		//if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
736
+		if ( ! $grp instanceof EE_Message_Template_Group) {
737
+			$grp = EEM_Message_Template_Group::instance()->get_one(
738
+				array(
739
+					array(
740
+						'MTP_messenger'    => $this->messenger(),
741
+						'MTP_message_type' => $this->message_type(),
742
+						'MTP_is_global'    => true,
743
+					),
744
+				)
745
+			);
746
+		}
747
+
748
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
749
+	}
750
+
751
+
752
+	/**
753
+	 * Retrieves the variation used for generating this message.
754
+	 *
755
+	 * @return string
756
+	 */
757
+	public function get_template_pack_variation()
758
+	{
759
+		/**
760
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
761
+		 */
762
+		if ( ! empty($this->template_variation)) {
763
+			return $this->template_variation;
764
+		}
765
+
766
+		/** @type EE_Message_Template_Group $grp */
767
+		$grp = $this->get_first_related('Message_Template_Group');
768
+
769
+		//if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
770
+		if ( ! $grp instanceof EE_Message_Template_Group) {
771
+			$grp = EEM_Message_Template_Group::instance()->get_one(
772
+				array(
773
+					array(
774
+						'MTP_messenger'    => $this->messenger(),
775
+						'MTP_message_type' => $this->message_type(),
776
+						'MTP_is_global'    => true,
777
+					),
778
+				)
779
+			);
780
+		}
781
+
782
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
783
+	}
784
+
785
+	/**
786
+	 * Return the link to the admin details for the object.
787
+	 *
788
+	 * @return string
789
+	 */
790
+	public function get_admin_details_link()
791
+	{
792
+		EE_Registry::instance()->load_helper('URL');
793
+		EE_Registry::instance()->load_helper('MSG_Template');
794
+		switch ($this->STS_ID()) {
795
+			case EEM_Message::status_failed :
796
+			case EEM_Message::status_debug_only :
797
+				return EEH_MSG_Template::generate_error_display_trigger($this);
798
+				break;
799
+
800
+			case EEM_Message::status_sent :
801
+				return EEH_MSG_Template::generate_browser_trigger($this);
802
+				break;
803
+
804
+			default :
805
+				return '';
806
+		}
807
+	}
808
+
809
+	/**
810
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
811
+	 *
812
+	 * @return string
813
+	 */
814
+	public function get_admin_edit_link()
815
+	{
816
+		return $this->get_admin_details_link();
817
+	}
818
+
819
+	/**
820
+	 * Returns the link to a settings page for the object.
821
+	 *
822
+	 * @return string
823
+	 */
824
+	public function get_admin_settings_link()
825
+	{
826
+		EE_Registry::instance()->load_helper('URL');
827
+		return EEH_URL::add_query_args_and_nonce(
828
+			array(
829
+				'page'   => 'espresso_messages',
830
+				'action' => 'settings',
831
+			),
832
+			admin_url('admin.php')
833
+		);
834
+	}
835
+
836
+	/**
837
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
838
+	 *
839
+	 * @return string
840
+	 */
841
+	public function get_admin_overview_link()
842
+	{
843
+		EE_Registry::instance()->load_helper('URL');
844
+		return EEH_URL::add_query_args_and_nonce(
845
+			array(
846
+				'page'   => 'espresso_messages',
847
+				'action' => 'default',
848
+			),
849
+			admin_url('admin.php')
850
+		);
851
+	}
852
+
853
+
854
+	/**
855
+	 * This sets the EEM_Message::status_messenger_executing class on the message and the appropriate error message for
856
+	 * it.
857
+	 * Note this also SAVES the current message object to the db because it adds an error message to accompany the status.
858
+	 *
859
+	 */
860
+	public function set_messenger_is_executing()
861
+	{
862
+		$this->set_STS_ID( EEM_Message::status_messenger_executing );
863
+		$this->set_error_message(
864
+			esc_html__(
865
+				'A message with this status indicates that there was a problem that occurred while the message was being
866 866
                 processed by the messenger.  It is still possible that the message was sent successfully, but at some
867 867
                 point during the processing there was a failure.  This usually is indicative of a timeout issue with PHP 
868 868
                 or memory limits being reached.  If you see this repeatedly you may want to consider upgrading the memory 
869 869
                 available to PHP on your server.',
870
-                'event_espresso'
871
-            )
872
-        );
873
-    }
870
+				'event_espresso'
871
+			)
872
+		);
873
+	}
874 874
 }
875 875
 /* End of file EE_Message.class.php */
876 876
 /* Location: /core/db_classes/EE_Message.class.php */
877 877
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
      */
860 860
     public function set_messenger_is_executing()
861 861
     {
862
-        $this->set_STS_ID( EEM_Message::status_messenger_executing );
862
+        $this->set_STS_ID(EEM_Message::status_messenger_executing);
863 863
         $this->set_error_message(
864 864
             esc_html__(
865 865
                 'A message with this status indicates that there was a problem that occurred while the message was being
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Queue.lib.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -603,7 +603,7 @@
 block discarded – undo
603 603
      * @param EE_Message      $message
604 604
      * @param EE_messenger    $messenger
605 605
      * @param EE_message_type $message_type
606
-     * @param                 $test_send
606
+     * @param                 boolean $test_send
607 607
      * @return bool   true means all went well, false means, not so much.
608 608
      */
609 609
     protected function _do_preview(
Please login to merge, or discard this patch.
Indentation   +677 added lines, -677 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use \EventEspresso\core\exceptions\SendMessageException;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 /**
@@ -18,681 +18,681 @@  discard block
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * @type    string  reference for sending action
23
-     */
24
-    const action_sending = 'sending';
25
-
26
-    /**
27
-     * @type    string  reference for generation action
28
-     */
29
-    const action_generating = 'generation';
30
-
31
-
32
-    /**
33
-     * @type EE_Message_Repository $_message_repository
34
-     */
35
-    protected $_message_repository;
36
-
37
-    /**
38
-     * Sets the limit of how many messages are generated per process.
39
-     *
40
-     * @type int
41
-     */
42
-    protected $_batch_count;
43
-
44
-    /**
45
-     * Sets the limit of how many messages can be sent per hour.
46
-     *
47
-     * @type int
48
-     */
49
-    protected $_rate_limit;
50
-
51
-    /**
52
-     * This is an array of cached queue items being stored in this object.
53
-     * The array keys will be the ID of the EE_Message in the db if saved.  If the EE_Message
54
-     * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.)
55
-     *
56
-     * @type EE_Message[]
57
-     */
58
-    protected $_cached_queue_items;
59
-
60
-    /**
61
-     * Tracks the number of unsaved queue items.
62
-     *
63
-     * @type int
64
-     */
65
-    protected $_unsaved_count = 0;
66
-
67
-    /**
68
-     * used to record if a do_messenger_hooks has already been called for a message type.  This prevents multiple
69
-     * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls.
70
-     *
71
-     * @type array
72
-     */
73
-    protected $_did_hook = array();
74
-
75
-
76
-    /**
77
-     * Constructor.
78
-     * Setup all the initial properties and load a EE_Message_Repository.
79
-     *
80
-     * @param \EE_Message_Repository $message_repository
81
-     */
82
-    public function __construct(EE_Message_Repository $message_repository)
83
-    {
84
-        $this->_batch_count        = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50);
85
-        $this->_rate_limit         = $this->get_rate_limit();
86
-        $this->_message_repository = $message_repository;
87
-    }
88
-
89
-
90
-    /**
91
-     * Add a EE_Message object to the queue
92
-     *
93
-     * @param EE_Message $message
94
-     * @param array      $data         This will be an array of data to attach to the object in the repository.  If the
95
-     *                                 object is persisted, this data will be saved on an extra_meta object related to
96
-     *                                 EE_Message.
97
-     * @param  bool      $preview      Whether this EE_Message represents a preview or not.
98
-     * @param  bool      $test_send    This indicates whether to do a test send instead of actual send. A test send will
99
-     *                                 use the messenger send method but typically is based on preview data.
100
-     * @return bool          Whether the message was successfully added to the repository or not.
101
-     */
102
-    public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false)
103
-    {
104
-        $data['preview']   = $preview;
105
-        $data['test_send'] = $test_send;
106
-        return $this->_message_repository->add($message, $data);
107
-    }
108
-
109
-
110
-    /**
111
-     * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message
112
-     *
113
-     * @param EE_Message $message The message to detach from the queue
114
-     * @param bool       $persist This flag indicates whether to attempt to delete the object from the db as well.
115
-     * @return bool
116
-     */
117
-    public function remove(EE_Message $message, $persist = false)
118
-    {
119
-        if ($persist && $this->_message_repository->current() !== $message) {
120
-            //get pointer on right message
121
-            if ($this->_message_repository->has($message)) {
122
-                $this->_message_repository->rewind();
123
-                while ($this->_message_repository->valid()) {
124
-                    if ($this->_message_repository->current() === $message) {
125
-                        break;
126
-                    }
127
-                    $this->_message_repository->next();
128
-                }
129
-            } else {
130
-                return false;
131
-            }
132
-        }
133
-        return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message);
134
-    }
135
-
136
-
137
-    /**
138
-     * Persists all queued EE_Message objects to the db.
139
-     *
140
-     * @param bool $do_hooks_only       @see EE_Message_Repository::saveAll
141
-     * @return array @see EE_Messages_Repository::saveAll() for return values.
142
-     */
143
-    public function save($do_hooks_only = false)
144
-    {
145
-        return $this->_message_repository->saveAll($do_hooks_only);
146
-    }
147
-
148
-
149
-    /**
150
-     * @return EE_Message_Repository
151
-     */
152
-    public function get_message_repository()
153
-    {
154
-        return $this->_message_repository;
155
-    }
156
-
157
-
158
-    /**
159
-     * This does the following things:
160
-     * 1. Checks if there is a lock on generation (prevents race conditions).  If there is a lock then exits (return
161
-     * false).
162
-     * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue
163
-     * 3. Returns bool.  True = batch ready.  False = no batch ready (or nothing available for generation).
164
-     * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from
165
-     * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not
166
-     * removed.
167
-     *
168
-     * @return bool  true if successfully retrieved batch, false no batch ready.
169
-     */
170
-    public function get_batch_to_generate()
171
-    {
172
-        if ($this->is_locked(EE_Messages_Queue::action_generating)) {
173
-            return false;
174
-        }
175
-
176
-        //lock batch generation to prevent race conditions.
177
-        $this->lock_queue(EE_Messages_Queue::action_generating);
178
-
179
-        $query_args = array(
180
-            // key 0 = where conditions
181
-            0          => array('STS_ID' => EEM_Message::status_incomplete),
182
-            'order_by' => $this->_get_priority_orderby(),
183
-            'limit'    => $this->_batch_count,
184
-        );
185
-        $messages   = EEM_Message::instance()->get_all($query_args);
186
-
187
-        if ( ! $messages) {
188
-            return false; //nothing to generate
189
-        }
190
-
191
-        foreach ($messages as $message) {
192
-            if ($message instanceof EE_Message) {
193
-                $data = $message->all_extra_meta_array();
194
-                $this->add($message, $data);
195
-            }
196
-        }
197
-        return true;
198
-    }
199
-
200
-
201
-    /**
202
-     * This does the following things:
203
-     * 1. Checks if there is a lock on sending (prevents race conditions).  If there is a lock then exits (return
204
-     * false).
205
-     * 2. Grabs the allowed number of messages to send for the rate_limit.  If cannot send any more messages, then
206
-     * return false.
207
-     * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution.
208
-     * 3. On success or unsuccessful send, sets status appropriately.
209
-     * 4. Saves messages via the queue
210
-     * 5. Releases lock.
211
-     *
212
-     * @return bool  true on success, false if something preventing sending (i.e. lock set).  Note: true does not
213
-     *               necessarily mean that all messages were successfully sent.  It just means that this method
214
-     *               successfully completed. On true, client may want to call $this->count_STS_in_queue(
215
-     *               EEM_Message::status_failed ) to see if any failed EE_Message objects.  Each failed message object
216
-     *               will also have a saved error message on it to assist with notifying user.
217
-     */
218
-    public function get_to_send_batch_and_send()
219
-    {
220
-        if ($this->is_locked(EE_Messages_Queue::action_sending) || $this->_rate_limit < 1) {
221
-            return false;
222
-        }
223
-
224
-        $this->lock_queue(EE_Messages_Queue::action_sending);
225
-
226
-        $batch = $this->_batch_count < $this->_rate_limit ? $this->_batch_count : $this->_rate_limit;
227
-
228
-        $query_args = array(
229
-            // key 0 = where conditions
230
-            0          => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())),
231
-            'order_by' => $this->_get_priority_orderby(),
232
-            'limit'    => $batch,
233
-        );
234
-
235
-        $messages_to_send = EEM_Message::instance()->get_all($query_args);
236
-
237
-
238
-        //any to send?
239
-        if ( ! $messages_to_send) {
240
-            $this->unlock_queue(EE_Messages_Queue::action_sending);
241
-            return false;
242
-        }
243
-
244
-        //add to queue.
245
-        foreach ($messages_to_send as $message) {
246
-            if ($message instanceof EE_Message) {
247
-                $this->add($message);
248
-            }
249
-        }
250
-
251
-        //send messages  (this also updates the rate limit)
252
-        $this->execute();
253
-
254
-        //release lock
255
-        $this->unlock_queue(EE_Messages_Queue::action_sending);
256
-        return true;
257
-    }
258
-
259
-
260
-    /**
261
-     * Locks the queue so that no other queues can call the "batch" methods.
262
-     *
263
-     * @param   string $type The type of queue being locked.
264
-     */
265
-    public function lock_queue($type = EE_Messages_Queue::action_generating)
266
-    {
267
-        set_transient($this->_get_lock_key($type), 1, $this->_get_lock_expiry($type));
268
-    }
269
-
270
-
271
-    /**
272
-     * Unlocks the queue so that batch methods can be used.
273
-     *
274
-     * @param   string $type The type of queue being unlocked.
275
-     */
276
-    public function unlock_queue($type = EE_Messages_Queue::action_generating)
277
-    {
278
-        delete_transient($this->_get_lock_key($type));
279
-    }
280
-
281
-
282
-    /**
283
-     * Retrieve the key used for the lock transient.
284
-     *
285
-     * @param string $type The type of lock.
286
-     * @return string
287
-     */
288
-    protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
289
-    {
290
-        return '_ee_lock_' . $type;
291
-    }
292
-
293
-
294
-    /**
295
-     * Retrieve the expiry time for the lock transient.
296
-     *
297
-     * @param string $type The type of lock
298
-     * @return int   time to expiry in seconds.
299
-     */
300
-    protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
301
-    {
302
-        return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
303
-    }
304
-
305
-
306
-    /**
307
-     * Returns the key used for rate limit transient.
308
-     *
309
-     * @return string
310
-     */
311
-    protected function _get_rate_limit_key()
312
-    {
313
-        return '_ee_rate_limit';
314
-    }
315
-
316
-
317
-    /**
318
-     * Returns the rate limit expiry time.
319
-     *
320
-     * @return int
321
-     */
322
-    protected function _get_rate_limit_expiry()
323
-    {
324
-        return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
325
-    }
326
-
327
-
328
-    /**
329
-     * Returns the default rate limit for sending messages.
330
-     *
331
-     * @return int
332
-     */
333
-    protected function _default_rate_limit()
334
-    {
335
-        return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
336
-    }
337
-
338
-
339
-    /**
340
-     * Return the orderby array for priority.
341
-     *
342
-     * @return array
343
-     */
344
-    protected function _get_priority_orderby()
345
-    {
346
-        return array(
347
-            'MSG_priority' => 'ASC',
348
-            'MSG_modified' => 'DESC',
349
-        );
350
-    }
351
-
352
-
353
-    /**
354
-     * Returns whether batch methods are "locked" or not.
355
-     *
356
-     * @param  string $type The type of lock being checked for.
357
-     * @return bool
358
-     */
359
-    public function is_locked($type = EE_Messages_Queue::action_generating)
360
-    {
361
-        /**
362
-         * This filters the default is_locked behaviour.
363
-         */
364
-        $is_locked = filter_var(
365
-            apply_filters(
366
-                'FHEE__EE_Messages_Queue__is_locked',
367
-                get_transient($this->_get_lock_key($type)),
368
-                $this
369
-            ),
370
-            FILTER_VALIDATE_BOOLEAN
371
-        );
372
-
373
-        /**
374
-         * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method.
375
-         *            Also implemented here because messages processed on the same request should not have any locks applied.
376
-         */
377
-        if (
378
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
379
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
380
-        ) {
381
-            $is_locked = false;
382
-        }
383
-
384
-
385
-        return $is_locked;
386
-    }
387
-
388
-
389
-    /**
390
-     * Retrieves the rate limit that may be cached as a transient.
391
-     * If the rate limit is not set, then this sets the default rate limit and expiry and returns it.
392
-     *
393
-     * @return int
394
-     */
395
-    public function get_rate_limit()
396
-    {
397
-        if ( ! $rate_limit = get_transient($this->_get_rate_limit_key())) {
398
-            $rate_limit = $this->_default_rate_limit();
399
-            set_transient($this->_get_rate_limit_key(), $rate_limit, $this->_get_rate_limit_key());
400
-        }
401
-        return $rate_limit;
402
-    }
403
-
404
-
405
-    /**
406
-     * This updates existing rate limit with the new limit which is the old minus the batch.
407
-     *
408
-     * @param int $batch_completed This sets the new rate limit based on the given batch that was completed.
409
-     */
410
-    public function set_rate_limit($batch_completed)
411
-    {
412
-        //first get the most up to date rate limit (in case its expired and reset)
413
-        $rate_limit = $this->get_rate_limit();
414
-        $new_limit  = $rate_limit - $batch_completed;
415
-        //updating the transient option directly to avoid resetting the expiry.
416
-        update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
417
-    }
418
-
419
-
420
-    /**
421
-     * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in.
422
-     * If that exists, then we immediately initiate a non-blocking request to do the requested action type.
423
-     * Note: Keep in mind that there is the possibility that the request will not execute if there is already another
424
-     * request running on a queue for the given task.
425
-     *
426
-     * @param string $task     This indicates what type of request is going to be initiated.
427
-     * @param int    $priority This indicates the priority that triggers initiating the request.
428
-     */
429
-    public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high)
430
-    {
431
-        //determine what status is matched with the priority as part of the trigger conditions.
432
-        $status = $task == 'generate'
433
-            ? EEM_Message::status_incomplete
434
-            : EEM_Message::instance()->stati_indicating_to_send();
435
-        // always make sure we save because either this will get executed immediately on a separate request
436
-        // or remains in the queue for the regularly scheduled queue batch.
437
-        $this->save();
438
-        /**
439
-         * This filter/option allows users to override processing of messages on separate requests and instead have everything
440
-         * happen on the same request.  If this is utilized remember:
441
-         * - message priorities don't matter
442
-         * - existing unprocessed messages in the queue will not get processed unless manually triggered.
443
-         * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional
444
-         *   processing happening on the same request.
445
-         * - any race condition protection (locks) are removed because they don't apply when things are processed on
446
-         *   the same request.
447
-         */
448
-        if (
449
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
450
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
451
-        ) {
452
-            $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor');
453
-            if ($messages_processor instanceof EE_Messages_Processor) {
454
-                return $messages_processor->process_immediately_from_queue($this);
455
-            }
456
-            //if we get here then that means the messages processor couldn't be loaded so messages will just remain
457
-            //queued for manual triggering by end user.
458
-        }
459
-
460
-        if ($this->_message_repository->count_by_priority_and_status($priority, $status)) {
461
-            EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task);
462
-        }
463
-    }
464
-
465
-
466
-    /**
467
-     *  Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message.
468
-     *
469
-     * @param   bool     $save                    Used to indicate whether to save the message queue after sending
470
-     *                                            (default will save).
471
-     * @param   mixed    $sending_messenger       (optional) When the sending messenger is different than
472
-     *                                            what is on the EE_Message object in the queue.
473
-     *                                            For instance, showing the browser view of an email message,
474
-     *                                            or giving a pdf generated view of an html document.
475
-     *                                            This should be an instance of EE_messenger but if you call this
476
-     *                                            method
477
-     *                                            intending it to be a sending messenger but a valid one could not be
478
-     *                                            retrieved then send in an instance of EE_Error that contains the
479
-     *                                            related error message.
480
-     * @param   bool|int $by_priority             When set, this indicates that only messages
481
-     *                                            matching the given priority should be executed.
482
-     * @return int        Number of messages sent.  Note, 0 does not mean that no messages were processed.
483
-     *                                            Also, if the messenger is an request type messenger (or a preview),
484
-     *                                            its entirely possible that the messenger will exit before
485
-     */
486
-    public function execute($save = true, $sending_messenger = null, $by_priority = false)
487
-    {
488
-        $messages_sent   = 0;
489
-        $this->_did_hook = array();
490
-        $this->_message_repository->rewind();
491
-
492
-        while ($this->_message_repository->valid()) {
493
-            $error_messages = array();
494
-            /** @type EE_Message $message */
495
-            $message = $this->_message_repository->current();
496
-            //only process things that are queued for sending
497
-            if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
498
-                $this->_message_repository->next();
499
-                continue;
500
-            }
501
-            //if $by_priority is set and does not match then continue;
502
-            if ($by_priority && $by_priority != $message->priority()) {
503
-                $this->_message_repository->next();
504
-                continue;
505
-            }
506
-            //error checking
507
-            if (! $message->valid_messenger()) {
508
-                $error_messages[] = sprintf(
509
-                    __('The %s messenger is not active at time of sending.', 'event_espresso'),
510
-                    $message->messenger()
511
-                );
512
-            }
513
-            if (! $message->valid_message_type()) {
514
-                $error_messages[] = sprintf(
515
-                    __('The %s message type is not active at the time of sending.', 'event_espresso'),
516
-                    $message->message_type()
517
-                );
518
-            }
519
-            // if there was supposed to be a sending messenger for this message, but it was invalid/inactive,
520
-            // then it will instead be an EE_Error object, so let's check for that
521
-            if ($sending_messenger instanceof EE_Error) {
522
-                $error_messages[] = $sending_messenger->getMessage();
523
-            }
524
-            // if there are no errors, then let's process the message
525
-            if (empty($error_messages)) {
526
-                if ($save) {
527
-                    $message->set_messenger_is_executing();
528
-                }
529
-                if ($this->_process_message($message, $sending_messenger)) {
530
-                    $messages_sent++;
531
-                }
532
-            }
533
-            $this->_set_error_message($message, $error_messages);
534
-            //add modified time
535
-            $message->set_modified(time());
536
-            //we save each message after its processed to make sure its status persists in case PHP times-out or runs
537
-            //out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281
538
-            if ($save) {
539
-                $message->save();
540
-            }
541
-
542
-            $this->_message_repository->next();
543
-        }
544
-        if ($save) {
545
-            $this->save(true);
546
-        }
547
-        return $messages_sent;
548
-    }
549
-
550
-
551
-    /**
552
-     * _process_message
553
-     *
554
-     * @param EE_Message $message
555
-     * @param mixed      $sending_messenger (optional)
556
-     * @return bool
557
-     */
558
-    protected function _process_message(EE_Message $message, $sending_messenger = null)
559
-    {
560
-        // these *should* have been validated in the execute() method above
561
-        $messenger    = $message->messenger_object();
562
-        $message_type = $message->message_type_object();
563
-        //do actions for sending messenger if it differs from generating messenger and swap values.
564
-        if (
565
-            $sending_messenger instanceof EE_messenger
566
-            && $messenger instanceof EE_messenger
567
-            && $sending_messenger->name != $messenger->name
568
-        ) {
569
-            $messenger->do_secondary_messenger_hooks($sending_messenger->name);
570
-            $messenger = $sending_messenger;
571
-        }
572
-        // send using messenger, but double check objects
573
-        if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) {
574
-            //set hook for message type (but only if not using another messenger to send).
575
-            if ( ! isset($this->_did_hook[$message_type->name])) {
576
-                $message_type->do_messenger_hooks($messenger);
577
-                $this->_did_hook[$message_type->name] = 1;
578
-            }
579
-            //if preview then use preview method
580
-            return $this->_message_repository->is_preview()
581
-                ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send())
582
-                : $this->_do_send($message, $messenger, $message_type);
583
-        }
584
-        return false;
585
-    }
586
-
587
-
588
-    /**
589
-     * The intention of this method is to count how many EE_Message objects
590
-     * are in the queue with a given status.
591
-     * Example usage:
592
-     * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed
593
-     * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ).
594
-     *
595
-     * @param array $status Stati to check for in queue
596
-     * @return int  Count of EE_Message's matching the given status.
597
-     */
598
-    public function count_STS_in_queue($status)
599
-    {
600
-        $count  = 0;
601
-        $status = is_array($status) ? $status : array($status);
602
-        $this->_message_repository->rewind();
603
-        foreach ($this->_message_repository as $message) {
604
-            if (in_array($message->STS_ID(), $status)) {
605
-                $count++;
606
-            }
607
-        }
608
-        return $count;
609
-    }
610
-
611
-
612
-    /**
613
-     * Executes the get_preview method on the provided messenger.
614
-     *
615
-     * @param EE_Message      $message
616
-     * @param EE_messenger    $messenger
617
-     * @param EE_message_type $message_type
618
-     * @param                 $test_send
619
-     * @return bool   true means all went well, false means, not so much.
620
-     */
621
-    protected function _do_preview(
622
-        EE_Message $message,
623
-        EE_messenger $messenger,
624
-        EE_message_type $message_type,
625
-        $test_send
626
-    ) {
627
-        if ($preview = $messenger->get_preview($message, $message_type, $test_send)) {
628
-            if ( ! $test_send) {
629
-                $message->set_content($preview);
630
-            }
631
-            $message->set_STS_ID(EEM_Message::status_sent);
632
-            return true;
633
-        } else {
634
-            $message->set_STS_ID(EEM_Message::status_failed);
635
-            return false;
636
-        }
637
-    }
638
-
639
-
640
-    /**
641
-     * Executes the send method on the provided messenger
642
-     * EE_Messengers are expected to:
643
-     * - return true if the send was successful.
644
-     * - return false if the send was unsuccessful but can be tried again.
645
-     * - throw an Exception if the send was unsuccessful and cannot be tried again.
646
-     *
647
-     * @param EE_Message      $message
648
-     * @param EE_messenger    $messenger
649
-     * @param EE_message_type $message_type
650
-     * @return bool true means all went well, false means, not so much.
651
-     */
652
-    protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type)
653
-    {
654
-        try {
655
-            if ($messenger->send_message($message, $message_type)) {
656
-                $message->set_STS_ID(EEM_Message::status_sent);
657
-                return true;
658
-            } else {
659
-                $message->set_STS_ID(EEM_Message::status_retry);
660
-                return false;
661
-            }
662
-        } catch (SendMessageException $e) {
663
-            $message->set_STS_ID(EEM_Message::status_failed);
664
-            $message->set_error_message($e->getMessage());
665
-            return false;
666
-        }
667
-    }
668
-
669
-
670
-    /**
671
-     * This sets any necessary error messages on the message object and its status to failed.
672
-     *
673
-     * @param EE_Message $message
674
-     * @param array      $error_messages the response from the messenger.
675
-     */
676
-    protected function _set_error_message(EE_Message $message, $error_messages)
677
-    {
678
-        $error_messages = (array)$error_messages;
679
-        if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
680
-            $notices          = EE_Error::has_notices();
681
-            $error_messages[] = __(
682
-                'Messenger and Message Type were valid and active, but the messenger send method failed.',
683
-                'event_espresso'
684
-            );
685
-            if ($notices === 1) {
686
-                $notices           = EE_Error::get_vanilla_notices();
687
-                $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array();
688
-                $error_messages[]  = implode("\n", $notices['errors']);
689
-            }
690
-        }
691
-        if (count($error_messages) > 0) {
692
-            $msg = __('Message was not executed successfully.', 'event_espresso');
693
-            $msg = $msg . "\n" . implode("\n", $error_messages);
694
-            $message->set_error_message($msg);
695
-        }
696
-    }
21
+	/**
22
+	 * @type    string  reference for sending action
23
+	 */
24
+	const action_sending = 'sending';
25
+
26
+	/**
27
+	 * @type    string  reference for generation action
28
+	 */
29
+	const action_generating = 'generation';
30
+
31
+
32
+	/**
33
+	 * @type EE_Message_Repository $_message_repository
34
+	 */
35
+	protected $_message_repository;
36
+
37
+	/**
38
+	 * Sets the limit of how many messages are generated per process.
39
+	 *
40
+	 * @type int
41
+	 */
42
+	protected $_batch_count;
43
+
44
+	/**
45
+	 * Sets the limit of how many messages can be sent per hour.
46
+	 *
47
+	 * @type int
48
+	 */
49
+	protected $_rate_limit;
50
+
51
+	/**
52
+	 * This is an array of cached queue items being stored in this object.
53
+	 * The array keys will be the ID of the EE_Message in the db if saved.  If the EE_Message
54
+	 * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.)
55
+	 *
56
+	 * @type EE_Message[]
57
+	 */
58
+	protected $_cached_queue_items;
59
+
60
+	/**
61
+	 * Tracks the number of unsaved queue items.
62
+	 *
63
+	 * @type int
64
+	 */
65
+	protected $_unsaved_count = 0;
66
+
67
+	/**
68
+	 * used to record if a do_messenger_hooks has already been called for a message type.  This prevents multiple
69
+	 * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls.
70
+	 *
71
+	 * @type array
72
+	 */
73
+	protected $_did_hook = array();
74
+
75
+
76
+	/**
77
+	 * Constructor.
78
+	 * Setup all the initial properties and load a EE_Message_Repository.
79
+	 *
80
+	 * @param \EE_Message_Repository $message_repository
81
+	 */
82
+	public function __construct(EE_Message_Repository $message_repository)
83
+	{
84
+		$this->_batch_count        = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50);
85
+		$this->_rate_limit         = $this->get_rate_limit();
86
+		$this->_message_repository = $message_repository;
87
+	}
88
+
89
+
90
+	/**
91
+	 * Add a EE_Message object to the queue
92
+	 *
93
+	 * @param EE_Message $message
94
+	 * @param array      $data         This will be an array of data to attach to the object in the repository.  If the
95
+	 *                                 object is persisted, this data will be saved on an extra_meta object related to
96
+	 *                                 EE_Message.
97
+	 * @param  bool      $preview      Whether this EE_Message represents a preview or not.
98
+	 * @param  bool      $test_send    This indicates whether to do a test send instead of actual send. A test send will
99
+	 *                                 use the messenger send method but typically is based on preview data.
100
+	 * @return bool          Whether the message was successfully added to the repository or not.
101
+	 */
102
+	public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false)
103
+	{
104
+		$data['preview']   = $preview;
105
+		$data['test_send'] = $test_send;
106
+		return $this->_message_repository->add($message, $data);
107
+	}
108
+
109
+
110
+	/**
111
+	 * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message
112
+	 *
113
+	 * @param EE_Message $message The message to detach from the queue
114
+	 * @param bool       $persist This flag indicates whether to attempt to delete the object from the db as well.
115
+	 * @return bool
116
+	 */
117
+	public function remove(EE_Message $message, $persist = false)
118
+	{
119
+		if ($persist && $this->_message_repository->current() !== $message) {
120
+			//get pointer on right message
121
+			if ($this->_message_repository->has($message)) {
122
+				$this->_message_repository->rewind();
123
+				while ($this->_message_repository->valid()) {
124
+					if ($this->_message_repository->current() === $message) {
125
+						break;
126
+					}
127
+					$this->_message_repository->next();
128
+				}
129
+			} else {
130
+				return false;
131
+			}
132
+		}
133
+		return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message);
134
+	}
135
+
136
+
137
+	/**
138
+	 * Persists all queued EE_Message objects to the db.
139
+	 *
140
+	 * @param bool $do_hooks_only       @see EE_Message_Repository::saveAll
141
+	 * @return array @see EE_Messages_Repository::saveAll() for return values.
142
+	 */
143
+	public function save($do_hooks_only = false)
144
+	{
145
+		return $this->_message_repository->saveAll($do_hooks_only);
146
+	}
147
+
148
+
149
+	/**
150
+	 * @return EE_Message_Repository
151
+	 */
152
+	public function get_message_repository()
153
+	{
154
+		return $this->_message_repository;
155
+	}
156
+
157
+
158
+	/**
159
+	 * This does the following things:
160
+	 * 1. Checks if there is a lock on generation (prevents race conditions).  If there is a lock then exits (return
161
+	 * false).
162
+	 * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue
163
+	 * 3. Returns bool.  True = batch ready.  False = no batch ready (or nothing available for generation).
164
+	 * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from
165
+	 * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not
166
+	 * removed.
167
+	 *
168
+	 * @return bool  true if successfully retrieved batch, false no batch ready.
169
+	 */
170
+	public function get_batch_to_generate()
171
+	{
172
+		if ($this->is_locked(EE_Messages_Queue::action_generating)) {
173
+			return false;
174
+		}
175
+
176
+		//lock batch generation to prevent race conditions.
177
+		$this->lock_queue(EE_Messages_Queue::action_generating);
178
+
179
+		$query_args = array(
180
+			// key 0 = where conditions
181
+			0          => array('STS_ID' => EEM_Message::status_incomplete),
182
+			'order_by' => $this->_get_priority_orderby(),
183
+			'limit'    => $this->_batch_count,
184
+		);
185
+		$messages   = EEM_Message::instance()->get_all($query_args);
186
+
187
+		if ( ! $messages) {
188
+			return false; //nothing to generate
189
+		}
190
+
191
+		foreach ($messages as $message) {
192
+			if ($message instanceof EE_Message) {
193
+				$data = $message->all_extra_meta_array();
194
+				$this->add($message, $data);
195
+			}
196
+		}
197
+		return true;
198
+	}
199
+
200
+
201
+	/**
202
+	 * This does the following things:
203
+	 * 1. Checks if there is a lock on sending (prevents race conditions).  If there is a lock then exits (return
204
+	 * false).
205
+	 * 2. Grabs the allowed number of messages to send for the rate_limit.  If cannot send any more messages, then
206
+	 * return false.
207
+	 * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution.
208
+	 * 3. On success or unsuccessful send, sets status appropriately.
209
+	 * 4. Saves messages via the queue
210
+	 * 5. Releases lock.
211
+	 *
212
+	 * @return bool  true on success, false if something preventing sending (i.e. lock set).  Note: true does not
213
+	 *               necessarily mean that all messages were successfully sent.  It just means that this method
214
+	 *               successfully completed. On true, client may want to call $this->count_STS_in_queue(
215
+	 *               EEM_Message::status_failed ) to see if any failed EE_Message objects.  Each failed message object
216
+	 *               will also have a saved error message on it to assist with notifying user.
217
+	 */
218
+	public function get_to_send_batch_and_send()
219
+	{
220
+		if ($this->is_locked(EE_Messages_Queue::action_sending) || $this->_rate_limit < 1) {
221
+			return false;
222
+		}
223
+
224
+		$this->lock_queue(EE_Messages_Queue::action_sending);
225
+
226
+		$batch = $this->_batch_count < $this->_rate_limit ? $this->_batch_count : $this->_rate_limit;
227
+
228
+		$query_args = array(
229
+			// key 0 = where conditions
230
+			0          => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())),
231
+			'order_by' => $this->_get_priority_orderby(),
232
+			'limit'    => $batch,
233
+		);
234
+
235
+		$messages_to_send = EEM_Message::instance()->get_all($query_args);
236
+
237
+
238
+		//any to send?
239
+		if ( ! $messages_to_send) {
240
+			$this->unlock_queue(EE_Messages_Queue::action_sending);
241
+			return false;
242
+		}
243
+
244
+		//add to queue.
245
+		foreach ($messages_to_send as $message) {
246
+			if ($message instanceof EE_Message) {
247
+				$this->add($message);
248
+			}
249
+		}
250
+
251
+		//send messages  (this also updates the rate limit)
252
+		$this->execute();
253
+
254
+		//release lock
255
+		$this->unlock_queue(EE_Messages_Queue::action_sending);
256
+		return true;
257
+	}
258
+
259
+
260
+	/**
261
+	 * Locks the queue so that no other queues can call the "batch" methods.
262
+	 *
263
+	 * @param   string $type The type of queue being locked.
264
+	 */
265
+	public function lock_queue($type = EE_Messages_Queue::action_generating)
266
+	{
267
+		set_transient($this->_get_lock_key($type), 1, $this->_get_lock_expiry($type));
268
+	}
269
+
270
+
271
+	/**
272
+	 * Unlocks the queue so that batch methods can be used.
273
+	 *
274
+	 * @param   string $type The type of queue being unlocked.
275
+	 */
276
+	public function unlock_queue($type = EE_Messages_Queue::action_generating)
277
+	{
278
+		delete_transient($this->_get_lock_key($type));
279
+	}
280
+
281
+
282
+	/**
283
+	 * Retrieve the key used for the lock transient.
284
+	 *
285
+	 * @param string $type The type of lock.
286
+	 * @return string
287
+	 */
288
+	protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
289
+	{
290
+		return '_ee_lock_' . $type;
291
+	}
292
+
293
+
294
+	/**
295
+	 * Retrieve the expiry time for the lock transient.
296
+	 *
297
+	 * @param string $type The type of lock
298
+	 * @return int   time to expiry in seconds.
299
+	 */
300
+	protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
301
+	{
302
+		return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
303
+	}
304
+
305
+
306
+	/**
307
+	 * Returns the key used for rate limit transient.
308
+	 *
309
+	 * @return string
310
+	 */
311
+	protected function _get_rate_limit_key()
312
+	{
313
+		return '_ee_rate_limit';
314
+	}
315
+
316
+
317
+	/**
318
+	 * Returns the rate limit expiry time.
319
+	 *
320
+	 * @return int
321
+	 */
322
+	protected function _get_rate_limit_expiry()
323
+	{
324
+		return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
325
+	}
326
+
327
+
328
+	/**
329
+	 * Returns the default rate limit for sending messages.
330
+	 *
331
+	 * @return int
332
+	 */
333
+	protected function _default_rate_limit()
334
+	{
335
+		return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
336
+	}
337
+
338
+
339
+	/**
340
+	 * Return the orderby array for priority.
341
+	 *
342
+	 * @return array
343
+	 */
344
+	protected function _get_priority_orderby()
345
+	{
346
+		return array(
347
+			'MSG_priority' => 'ASC',
348
+			'MSG_modified' => 'DESC',
349
+		);
350
+	}
351
+
352
+
353
+	/**
354
+	 * Returns whether batch methods are "locked" or not.
355
+	 *
356
+	 * @param  string $type The type of lock being checked for.
357
+	 * @return bool
358
+	 */
359
+	public function is_locked($type = EE_Messages_Queue::action_generating)
360
+	{
361
+		/**
362
+		 * This filters the default is_locked behaviour.
363
+		 */
364
+		$is_locked = filter_var(
365
+			apply_filters(
366
+				'FHEE__EE_Messages_Queue__is_locked',
367
+				get_transient($this->_get_lock_key($type)),
368
+				$this
369
+			),
370
+			FILTER_VALIDATE_BOOLEAN
371
+		);
372
+
373
+		/**
374
+		 * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method.
375
+		 *            Also implemented here because messages processed on the same request should not have any locks applied.
376
+		 */
377
+		if (
378
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
379
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
380
+		) {
381
+			$is_locked = false;
382
+		}
383
+
384
+
385
+		return $is_locked;
386
+	}
387
+
388
+
389
+	/**
390
+	 * Retrieves the rate limit that may be cached as a transient.
391
+	 * If the rate limit is not set, then this sets the default rate limit and expiry and returns it.
392
+	 *
393
+	 * @return int
394
+	 */
395
+	public function get_rate_limit()
396
+	{
397
+		if ( ! $rate_limit = get_transient($this->_get_rate_limit_key())) {
398
+			$rate_limit = $this->_default_rate_limit();
399
+			set_transient($this->_get_rate_limit_key(), $rate_limit, $this->_get_rate_limit_key());
400
+		}
401
+		return $rate_limit;
402
+	}
403
+
404
+
405
+	/**
406
+	 * This updates existing rate limit with the new limit which is the old minus the batch.
407
+	 *
408
+	 * @param int $batch_completed This sets the new rate limit based on the given batch that was completed.
409
+	 */
410
+	public function set_rate_limit($batch_completed)
411
+	{
412
+		//first get the most up to date rate limit (in case its expired and reset)
413
+		$rate_limit = $this->get_rate_limit();
414
+		$new_limit  = $rate_limit - $batch_completed;
415
+		//updating the transient option directly to avoid resetting the expiry.
416
+		update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
417
+	}
418
+
419
+
420
+	/**
421
+	 * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in.
422
+	 * If that exists, then we immediately initiate a non-blocking request to do the requested action type.
423
+	 * Note: Keep in mind that there is the possibility that the request will not execute if there is already another
424
+	 * request running on a queue for the given task.
425
+	 *
426
+	 * @param string $task     This indicates what type of request is going to be initiated.
427
+	 * @param int    $priority This indicates the priority that triggers initiating the request.
428
+	 */
429
+	public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high)
430
+	{
431
+		//determine what status is matched with the priority as part of the trigger conditions.
432
+		$status = $task == 'generate'
433
+			? EEM_Message::status_incomplete
434
+			: EEM_Message::instance()->stati_indicating_to_send();
435
+		// always make sure we save because either this will get executed immediately on a separate request
436
+		// or remains in the queue for the regularly scheduled queue batch.
437
+		$this->save();
438
+		/**
439
+		 * This filter/option allows users to override processing of messages on separate requests and instead have everything
440
+		 * happen on the same request.  If this is utilized remember:
441
+		 * - message priorities don't matter
442
+		 * - existing unprocessed messages in the queue will not get processed unless manually triggered.
443
+		 * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional
444
+		 *   processing happening on the same request.
445
+		 * - any race condition protection (locks) are removed because they don't apply when things are processed on
446
+		 *   the same request.
447
+		 */
448
+		if (
449
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
450
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
451
+		) {
452
+			$messages_processor = EE_Registry::instance()->load_lib('Messages_Processor');
453
+			if ($messages_processor instanceof EE_Messages_Processor) {
454
+				return $messages_processor->process_immediately_from_queue($this);
455
+			}
456
+			//if we get here then that means the messages processor couldn't be loaded so messages will just remain
457
+			//queued for manual triggering by end user.
458
+		}
459
+
460
+		if ($this->_message_repository->count_by_priority_and_status($priority, $status)) {
461
+			EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task);
462
+		}
463
+	}
464
+
465
+
466
+	/**
467
+	 *  Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message.
468
+	 *
469
+	 * @param   bool     $save                    Used to indicate whether to save the message queue after sending
470
+	 *                                            (default will save).
471
+	 * @param   mixed    $sending_messenger       (optional) When the sending messenger is different than
472
+	 *                                            what is on the EE_Message object in the queue.
473
+	 *                                            For instance, showing the browser view of an email message,
474
+	 *                                            or giving a pdf generated view of an html document.
475
+	 *                                            This should be an instance of EE_messenger but if you call this
476
+	 *                                            method
477
+	 *                                            intending it to be a sending messenger but a valid one could not be
478
+	 *                                            retrieved then send in an instance of EE_Error that contains the
479
+	 *                                            related error message.
480
+	 * @param   bool|int $by_priority             When set, this indicates that only messages
481
+	 *                                            matching the given priority should be executed.
482
+	 * @return int        Number of messages sent.  Note, 0 does not mean that no messages were processed.
483
+	 *                                            Also, if the messenger is an request type messenger (or a preview),
484
+	 *                                            its entirely possible that the messenger will exit before
485
+	 */
486
+	public function execute($save = true, $sending_messenger = null, $by_priority = false)
487
+	{
488
+		$messages_sent   = 0;
489
+		$this->_did_hook = array();
490
+		$this->_message_repository->rewind();
491
+
492
+		while ($this->_message_repository->valid()) {
493
+			$error_messages = array();
494
+			/** @type EE_Message $message */
495
+			$message = $this->_message_repository->current();
496
+			//only process things that are queued for sending
497
+			if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
498
+				$this->_message_repository->next();
499
+				continue;
500
+			}
501
+			//if $by_priority is set and does not match then continue;
502
+			if ($by_priority && $by_priority != $message->priority()) {
503
+				$this->_message_repository->next();
504
+				continue;
505
+			}
506
+			//error checking
507
+			if (! $message->valid_messenger()) {
508
+				$error_messages[] = sprintf(
509
+					__('The %s messenger is not active at time of sending.', 'event_espresso'),
510
+					$message->messenger()
511
+				);
512
+			}
513
+			if (! $message->valid_message_type()) {
514
+				$error_messages[] = sprintf(
515
+					__('The %s message type is not active at the time of sending.', 'event_espresso'),
516
+					$message->message_type()
517
+				);
518
+			}
519
+			// if there was supposed to be a sending messenger for this message, but it was invalid/inactive,
520
+			// then it will instead be an EE_Error object, so let's check for that
521
+			if ($sending_messenger instanceof EE_Error) {
522
+				$error_messages[] = $sending_messenger->getMessage();
523
+			}
524
+			// if there are no errors, then let's process the message
525
+			if (empty($error_messages)) {
526
+				if ($save) {
527
+					$message->set_messenger_is_executing();
528
+				}
529
+				if ($this->_process_message($message, $sending_messenger)) {
530
+					$messages_sent++;
531
+				}
532
+			}
533
+			$this->_set_error_message($message, $error_messages);
534
+			//add modified time
535
+			$message->set_modified(time());
536
+			//we save each message after its processed to make sure its status persists in case PHP times-out or runs
537
+			//out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281
538
+			if ($save) {
539
+				$message->save();
540
+			}
541
+
542
+			$this->_message_repository->next();
543
+		}
544
+		if ($save) {
545
+			$this->save(true);
546
+		}
547
+		return $messages_sent;
548
+	}
549
+
550
+
551
+	/**
552
+	 * _process_message
553
+	 *
554
+	 * @param EE_Message $message
555
+	 * @param mixed      $sending_messenger (optional)
556
+	 * @return bool
557
+	 */
558
+	protected function _process_message(EE_Message $message, $sending_messenger = null)
559
+	{
560
+		// these *should* have been validated in the execute() method above
561
+		$messenger    = $message->messenger_object();
562
+		$message_type = $message->message_type_object();
563
+		//do actions for sending messenger if it differs from generating messenger and swap values.
564
+		if (
565
+			$sending_messenger instanceof EE_messenger
566
+			&& $messenger instanceof EE_messenger
567
+			&& $sending_messenger->name != $messenger->name
568
+		) {
569
+			$messenger->do_secondary_messenger_hooks($sending_messenger->name);
570
+			$messenger = $sending_messenger;
571
+		}
572
+		// send using messenger, but double check objects
573
+		if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) {
574
+			//set hook for message type (but only if not using another messenger to send).
575
+			if ( ! isset($this->_did_hook[$message_type->name])) {
576
+				$message_type->do_messenger_hooks($messenger);
577
+				$this->_did_hook[$message_type->name] = 1;
578
+			}
579
+			//if preview then use preview method
580
+			return $this->_message_repository->is_preview()
581
+				? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send())
582
+				: $this->_do_send($message, $messenger, $message_type);
583
+		}
584
+		return false;
585
+	}
586
+
587
+
588
+	/**
589
+	 * The intention of this method is to count how many EE_Message objects
590
+	 * are in the queue with a given status.
591
+	 * Example usage:
592
+	 * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed
593
+	 * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ).
594
+	 *
595
+	 * @param array $status Stati to check for in queue
596
+	 * @return int  Count of EE_Message's matching the given status.
597
+	 */
598
+	public function count_STS_in_queue($status)
599
+	{
600
+		$count  = 0;
601
+		$status = is_array($status) ? $status : array($status);
602
+		$this->_message_repository->rewind();
603
+		foreach ($this->_message_repository as $message) {
604
+			if (in_array($message->STS_ID(), $status)) {
605
+				$count++;
606
+			}
607
+		}
608
+		return $count;
609
+	}
610
+
611
+
612
+	/**
613
+	 * Executes the get_preview method on the provided messenger.
614
+	 *
615
+	 * @param EE_Message      $message
616
+	 * @param EE_messenger    $messenger
617
+	 * @param EE_message_type $message_type
618
+	 * @param                 $test_send
619
+	 * @return bool   true means all went well, false means, not so much.
620
+	 */
621
+	protected function _do_preview(
622
+		EE_Message $message,
623
+		EE_messenger $messenger,
624
+		EE_message_type $message_type,
625
+		$test_send
626
+	) {
627
+		if ($preview = $messenger->get_preview($message, $message_type, $test_send)) {
628
+			if ( ! $test_send) {
629
+				$message->set_content($preview);
630
+			}
631
+			$message->set_STS_ID(EEM_Message::status_sent);
632
+			return true;
633
+		} else {
634
+			$message->set_STS_ID(EEM_Message::status_failed);
635
+			return false;
636
+		}
637
+	}
638
+
639
+
640
+	/**
641
+	 * Executes the send method on the provided messenger
642
+	 * EE_Messengers are expected to:
643
+	 * - return true if the send was successful.
644
+	 * - return false if the send was unsuccessful but can be tried again.
645
+	 * - throw an Exception if the send was unsuccessful and cannot be tried again.
646
+	 *
647
+	 * @param EE_Message      $message
648
+	 * @param EE_messenger    $messenger
649
+	 * @param EE_message_type $message_type
650
+	 * @return bool true means all went well, false means, not so much.
651
+	 */
652
+	protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type)
653
+	{
654
+		try {
655
+			if ($messenger->send_message($message, $message_type)) {
656
+				$message->set_STS_ID(EEM_Message::status_sent);
657
+				return true;
658
+			} else {
659
+				$message->set_STS_ID(EEM_Message::status_retry);
660
+				return false;
661
+			}
662
+		} catch (SendMessageException $e) {
663
+			$message->set_STS_ID(EEM_Message::status_failed);
664
+			$message->set_error_message($e->getMessage());
665
+			return false;
666
+		}
667
+	}
668
+
669
+
670
+	/**
671
+	 * This sets any necessary error messages on the message object and its status to failed.
672
+	 *
673
+	 * @param EE_Message $message
674
+	 * @param array      $error_messages the response from the messenger.
675
+	 */
676
+	protected function _set_error_message(EE_Message $message, $error_messages)
677
+	{
678
+		$error_messages = (array)$error_messages;
679
+		if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
680
+			$notices          = EE_Error::has_notices();
681
+			$error_messages[] = __(
682
+				'Messenger and Message Type were valid and active, but the messenger send method failed.',
683
+				'event_espresso'
684
+			);
685
+			if ($notices === 1) {
686
+				$notices           = EE_Error::get_vanilla_notices();
687
+				$notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array();
688
+				$error_messages[]  = implode("\n", $notices['errors']);
689
+			}
690
+		}
691
+		if (count($error_messages) > 0) {
692
+			$msg = __('Message was not executed successfully.', 'event_espresso');
693
+			$msg = $msg . "\n" . implode("\n", $error_messages);
694
+			$message->set_error_message($msg);
695
+		}
696
+	}
697 697
 
698 698
 } //end EE_Messages_Queue class
699 699
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 use \EventEspresso\core\exceptions\SendMessageException;
3 3
 
4
-if (! defined('EVENT_ESPRESSO_VERSION')) {
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5 5
     exit('No direct script access allowed');
6 6
 }
7 7
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             'order_by' => $this->_get_priority_orderby(),
183 183
             'limit'    => $this->_batch_count,
184 184
         );
185
-        $messages   = EEM_Message::instance()->get_all($query_args);
185
+        $messages = EEM_Message::instance()->get_all($query_args);
186 186
 
187 187
         if ( ! $messages) {
188 188
             return false; //nothing to generate
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
      */
288 288
     protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
289 289
     {
290
-        return '_ee_lock_' . $type;
290
+        return '_ee_lock_'.$type;
291 291
     }
292 292
 
293 293
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
      */
300 300
     protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
301 301
     {
302
-        return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
302
+        return (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
303 303
     }
304 304
 
305 305
 
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
      */
322 322
     protected function _get_rate_limit_expiry()
323 323
     {
324
-        return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
324
+        return (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
325 325
     }
326 326
 
327 327
 
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
      */
333 333
     protected function _default_rate_limit()
334 334
     {
335
-        return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
335
+        return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
336 336
     }
337 337
 
338 338
 
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
         $rate_limit = $this->get_rate_limit();
414 414
         $new_limit  = $rate_limit - $batch_completed;
415 415
         //updating the transient option directly to avoid resetting the expiry.
416
-        update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
416
+        update_option('_transient_'.$this->_get_rate_limit_key(), $new_limit);
417 417
     }
418 418
 
419 419
 
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
             /** @type EE_Message $message */
495 495
             $message = $this->_message_repository->current();
496 496
             //only process things that are queued for sending
497
-            if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
497
+            if ( ! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
498 498
                 $this->_message_repository->next();
499 499
                 continue;
500 500
             }
@@ -504,13 +504,13 @@  discard block
 block discarded – undo
504 504
                 continue;
505 505
             }
506 506
             //error checking
507
-            if (! $message->valid_messenger()) {
507
+            if ( ! $message->valid_messenger()) {
508 508
                 $error_messages[] = sprintf(
509 509
                     __('The %s messenger is not active at time of sending.', 'event_espresso'),
510 510
                     $message->messenger()
511 511
                 );
512 512
             }
513
-            if (! $message->valid_message_type()) {
513
+            if ( ! $message->valid_message_type()) {
514 514
                 $error_messages[] = sprintf(
515 515
                     __('The %s message type is not active at the time of sending.', 'event_espresso'),
516 516
                     $message->message_type()
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
      */
676 676
     protected function _set_error_message(EE_Message $message, $error_messages)
677 677
     {
678
-        $error_messages = (array)$error_messages;
678
+        $error_messages = (array) $error_messages;
679 679
         if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
680 680
             $notices          = EE_Error::has_notices();
681 681
             $error_messages[] = __(
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
         }
691 691
         if (count($error_messages) > 0) {
692 692
             $msg = __('Message was not executed successfully.', 'event_espresso');
693
-            $msg = $msg . "\n" . implode("\n", $error_messages);
693
+            $msg = $msg."\n".implode("\n", $error_messages);
694 694
             $message->set_error_message($msg);
695 695
         }
696 696
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Status.model.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 /**
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @ version            4.0
13 13
  * ------------------------------------------------------------------------
14 14
  */
15
-require_once(EE_MODELS . 'EEM_Base.model.php');
15
+require_once(EE_MODELS.'EEM_Base.model.php');
16 16
 
17 17
 /**
18 18
  * Class EEM_Status
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
                     false,
50 50
                     'event',
51 51
                     array(
52
-                        'event'        => __("Event", "event_espresso"),//deprecated
52
+                        'event'        => __("Event", "event_espresso"), //deprecated
53 53
                         'registration' => __("Registration", "event_espresso"),
54 54
                         'transaction'  => __("Transaction", "event_espresso"),
55 55
                         'payment'      => __("Payment", "event_espresso"),
Please login to merge, or discard this patch.
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -25,291 +25,291 @@  discard block
 block discarded – undo
25 25
 class EEM_Status extends EEM_Base
26 26
 {
27 27
 
28
-    // private instance of the Attendee object
29
-    protected static $_instance = null;
28
+	// private instance of the Attendee object
29
+	protected static $_instance = null;
30 30
 
31 31
 
32
-    /**
33
-     * @return EEM_Status
34
-     */
35
-    protected function __construct($timezone = null)
36
-    {
37
-        $this->singular_item    = __('Status', 'event_espresso');
38
-        $this->plural_item      = __('Stati', 'event_espresso');
39
-        $this->_tables          = array(
40
-            'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
41
-        );
42
-        $this->_fields          = array(
43
-            'StatusTable' => array(
44
-                'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
45
-                'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
46
-                'STS_type'     => new EE_Enum_Text_Field(
47
-                    'STS_type',
48
-                    __("Type", "event_espresso"),
49
-                    false,
50
-                    'event',
51
-                    array(
52
-                        'event'        => __("Event", "event_espresso"),//deprecated
53
-                        'registration' => __("Registration", "event_espresso"),
54
-                        'transaction'  => __("Transaction", "event_espresso"),
55
-                        'payment'      => __("Payment", "event_espresso"),
56
-                        'email'        => __("Email", "event_espresso"),
57
-                        'message'      => __("Message", "event_espresso"),
58
-                    )),
59
-                'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false),
60
-                'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
61
-                'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
62
-            ),
63
-        );
64
-        $this->_model_relations = array(
65
-            'Registration' => new EE_Has_Many_Relation(),
66
-            'Transaction'  => new EE_Has_Many_Relation(),
67
-            'Payment'      => new EE_Has_Many_Relation(),
68
-        );
69
-        //this model is generally available for reading
70
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
32
+	/**
33
+	 * @return EEM_Status
34
+	 */
35
+	protected function __construct($timezone = null)
36
+	{
37
+		$this->singular_item    = __('Status', 'event_espresso');
38
+		$this->plural_item      = __('Stati', 'event_espresso');
39
+		$this->_tables          = array(
40
+			'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
41
+		);
42
+		$this->_fields          = array(
43
+			'StatusTable' => array(
44
+				'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
45
+				'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
46
+				'STS_type'     => new EE_Enum_Text_Field(
47
+					'STS_type',
48
+					__("Type", "event_espresso"),
49
+					false,
50
+					'event',
51
+					array(
52
+						'event'        => __("Event", "event_espresso"),//deprecated
53
+						'registration' => __("Registration", "event_espresso"),
54
+						'transaction'  => __("Transaction", "event_espresso"),
55
+						'payment'      => __("Payment", "event_espresso"),
56
+						'email'        => __("Email", "event_espresso"),
57
+						'message'      => __("Message", "event_espresso"),
58
+					)),
59
+				'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false),
60
+				'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
61
+				'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
62
+			),
63
+		);
64
+		$this->_model_relations = array(
65
+			'Registration' => new EE_Has_Many_Relation(),
66
+			'Transaction'  => new EE_Has_Many_Relation(),
67
+			'Payment'      => new EE_Has_Many_Relation(),
68
+		);
69
+		//this model is generally available for reading
70
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
71 71
 
72
-        parent::__construct($timezone);
73
-    }
72
+		parent::__construct($timezone);
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * This method provides the localized singular or plural string for a given status id
78
-     *
79
-     * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
80
-     *                           That way if there isn't a translation in the index we'll return the default code.
81
-     * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
82
-     *                           same as the singular (in English), however, this may NOT be the case with other
83
-     *                           languages
84
-     * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
85
-     *                           the status string returned ( UPPER, lower, Sentence)
86
-     * @throws EE_Error
87
-     * @return array             an array of translated strings for the incoming status id.
88
-     */
89
-    public function localized_status($statuses, $plural = false, $schema = 'upper')
90
-    {
91
-        //note these are all in lower case because ucwords() on upper case will NOT convert.
92
-        $translation_array = array(
93
-            EEM_Registration::status_id_pending_payment => array(
94
-                __('pending payment', 'event_espresso'), //singular
95
-                __('pending payments', 'event_espresso') //plural
96
-            ),
97
-            EEM_Registration::status_id_approved        => array(
98
-                __('approved', 'event_espresso'), //singular
99
-                __('approved', 'event_espresso') //plural
100
-            ),
101
-            EEM_Registration::status_id_not_approved    => array(
102
-                __('not approved', 'event_espresso'),
103
-                __('not approved', 'event_espresso'),
104
-            ),
105
-            EEM_Registration::status_id_cancelled       => array(
106
-                __('cancelled', 'event_espresso'),
107
-                __('cancelled', 'event_espresso'),
108
-            ),
109
-            EEM_Registration::status_id_incomplete      => array(
110
-                __('incomplete', 'event_espresso'),
111
-                __('incomplete', 'event_espresso'),
112
-            ),
113
-            EEM_Registration::status_id_declined        => array(
114
-                __('declined', 'event_espresso'),
115
-                __('declined', 'event_espresso'),
116
-            ),
117
-            EEM_Registration::status_id_wait_list       => array(
118
-                __('wait list', 'event_espresso'),
119
-                __('wait list', 'event_espresso'),
120
-            ),
121
-            EEM_Transaction::overpaid_status_code       => array(
122
-                __('overpaid', 'event_espresso'),
123
-                __('overpaid', 'event_espresso'),
124
-            ),
125
-            EEM_Transaction::complete_status_code       => array(
126
-                __('complete', 'event_espresso'),
127
-                __('complete', 'event_espresso'),
128
-            ),
129
-            EEM_Transaction::incomplete_status_code     => array(
130
-                __('incomplete', 'event_espresso'),
131
-                __('incomplete', 'event_espresso'),
132
-            ),
133
-            EEM_Transaction::failed_status_code         => array(
134
-                __('failed', 'event_espresso'),
135
-                __('failed', 'event_espresso'),
136
-            ),
137
-            EEM_Transaction::abandoned_status_code      => array(
138
-                __('abandoned', 'event_espresso'),
139
-                __('abandoned', 'event_espresso'),
140
-            ),
141
-            EEM_Payment::status_id_approved             => array(
142
-                __('accepted', 'event_espresso'),
143
-                __('accepted', 'event_espresso'),
144
-            ),
145
-            EEM_Payment::status_id_pending              => array(
146
-                __('pending', 'event_espresso'),
147
-                __('pending', 'event_espresso'),
148
-            ),
149
-            EEM_Payment::status_id_cancelled            => array(
150
-                __('cancelled', 'event_espresso'),
151
-                __('cancelled', 'event_espresso'),
152
-            ),
153
-            EEM_Payment::status_id_declined             => array(
154
-                __('declined', 'event_espresso'),
155
-                __('declined', 'event_espresso'),
156
-            ),
157
-            EEM_Payment::status_id_failed               => array(
158
-                __('failed', 'event_espresso'),
159
-                __('failed', 'event_espresso'),
160
-            ),
161
-            //following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
162
-            EEM_Event::sold_out                         => array(
163
-                __('sold out', 'event_espresso'),
164
-                __('sold out', 'event_espresso'),
165
-            ),
166
-            EEM_Event::postponed                        => array(
167
-                __('postponed', 'event_espresso'),
168
-                __('Postponed', 'event_espresso'),
169
-            ),
170
-            EEM_Event::cancelled                        => array(
171
-                __('cancelled', 'event_espresso'),
172
-                __('cancelled', 'event_espresso'),
173
-            ),
174
-            EE_Ticket::archived                         => array(
175
-                __('archived', 'event_espresso'),
176
-                __('archived', 'event_espresso'),
177
-            ),
178
-            EE_Ticket::expired                          => array(
179
-                __('expired', 'event_espresso'),
180
-                __('expired', 'event_espresso'),
181
-            ),
182
-            EE_Ticket::sold_out                         => array(
183
-                __('sold out', 'event_espresso'),
184
-                __('sold out', 'event_espresso'),
185
-            ),
186
-            EE_Ticket::pending                          => array(
187
-                __('upcoming', 'event_espresso'),
188
-                __('upcoming', 'event_espresso'),
189
-            ),
190
-            EE_Ticket::onsale                           => array(
191
-                __('on sale', 'event_espresso'),
192
-                __('on sale', 'event_espresso'),
193
-            ),
194
-            EE_Datetime::cancelled                      => array(
195
-                __('cancelled', 'event_espresso'),
196
-                __('cancelled', 'event_espresso'),
197
-            ),
198
-            EE_Datetime::sold_out                       => array(
199
-                __('sold out', 'event_espresso'),
200
-                __('sold out', 'event_espresso'),
201
-            ),
202
-            EE_Datetime::expired                        => array(
203
-                __('expired', 'event_espresso'),
204
-                __('expired', 'event_espresso'),
205
-            ),
206
-            EE_Datetime::inactive                       => array(
207
-                __('inactive', 'event_espresso'),
208
-                __('inactive', 'event_espresso'),
209
-            ),
210
-            EE_Datetime::upcoming                       => array(
211
-                __('upcoming', 'event_espresso'),
212
-                __('upcoming', 'event_espresso'),
213
-            ),
214
-            EE_Datetime::active                         => array(
215
-                __('active', 'event_espresso'),
216
-                __('active', 'event_espresso'),
217
-            ),
218
-            EE_Datetime::postponed                      => array(
219
-                __('postponed', 'event_espresso'),
220
-                __('postponed', 'event_espresso'),
221
-            ),
222
-            //messages related
223
-            EEM_Message::status_sent                    => array(
224
-                __('sent', 'event_espresso'),
225
-                __('sent', 'event_espresso'),
226
-            ),
227
-            EEM_Message::status_idle                    => array(
228
-                __('queued for sending', 'event_espresso'),
229
-                __('queued for sending', 'event_espresso'),
230
-            ),
231
-            EEM_Message::status_failed                  => array(
232
-                __('failed', 'event_espresso'),
233
-                __('failed', 'event_espresso'),
234
-            ),
235
-            EEM_Message::status_debug_only              => array(
236
-                __('debug only', 'event_espresso'),
237
-                __('debug only', 'event_espresso'),
238
-            ),
239
-            EEM_Message::status_messenger_executing     => array(
240
-                __('messenger is executing', 'event_espresso'),
241
-                __('messenger is executing', 'event_espresso'),
242
-            ),
243
-            EEM_Message::status_resend                  => array(
244
-                __('queued for resending', 'event_espresso'),
245
-                __('queued for resending', 'event_espresso'),
246
-            ),
247
-            EEM_Message::status_incomplete              => array(
248
-                __('queued for generating', 'event_espresso'),
249
-                __('queued for generating', 'event_espresso'),
250
-            ),
251
-            EEM_Message::status_retry                   => array(
252
-                __('failed sending, can be retried', 'event_espresso'),
253
-                __('failed sending, can be retried', 'event_espresso'),
254
-            ),
255
-            EEM_CPT_Base::post_status_publish           => array(
256
-                __('published', 'event_espresso'),
257
-                __('published', 'event_espresso'),
258
-            ),
259
-            EEM_CPT_Base::post_status_future            => array(
260
-                __('scheduled', 'event_espresso'),
261
-                __('scheduled', 'event_espresso'),
262
-            ),
263
-            EEM_CPT_Base::post_status_draft             => array(
264
-                __('draft', 'event_espresso'),
265
-                __('draft', 'event_espresso'),
266
-            ),
267
-            EEM_CPT_Base::post_status_pending           => array(
268
-                __('pending', 'event_espresso'),
269
-                __('pending', 'event_espresso'),
270
-            ),
271
-            EEM_CPT_Base::post_status_private           => array(
272
-                __('private', 'event_espresso'),
273
-                __('private', 'event_espresso'),
274
-            ),
275
-            EEM_CPT_Base::post_status_trashed           => array(
276
-                __('trashed', 'event_espresso'),
277
-                __('trashed', 'event_espresso'),
278
-            ),
279
-        );
76
+	/**
77
+	 * This method provides the localized singular or plural string for a given status id
78
+	 *
79
+	 * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
80
+	 *                           That way if there isn't a translation in the index we'll return the default code.
81
+	 * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
82
+	 *                           same as the singular (in English), however, this may NOT be the case with other
83
+	 *                           languages
84
+	 * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
85
+	 *                           the status string returned ( UPPER, lower, Sentence)
86
+	 * @throws EE_Error
87
+	 * @return array             an array of translated strings for the incoming status id.
88
+	 */
89
+	public function localized_status($statuses, $plural = false, $schema = 'upper')
90
+	{
91
+		//note these are all in lower case because ucwords() on upper case will NOT convert.
92
+		$translation_array = array(
93
+			EEM_Registration::status_id_pending_payment => array(
94
+				__('pending payment', 'event_espresso'), //singular
95
+				__('pending payments', 'event_espresso') //plural
96
+			),
97
+			EEM_Registration::status_id_approved        => array(
98
+				__('approved', 'event_espresso'), //singular
99
+				__('approved', 'event_espresso') //plural
100
+			),
101
+			EEM_Registration::status_id_not_approved    => array(
102
+				__('not approved', 'event_espresso'),
103
+				__('not approved', 'event_espresso'),
104
+			),
105
+			EEM_Registration::status_id_cancelled       => array(
106
+				__('cancelled', 'event_espresso'),
107
+				__('cancelled', 'event_espresso'),
108
+			),
109
+			EEM_Registration::status_id_incomplete      => array(
110
+				__('incomplete', 'event_espresso'),
111
+				__('incomplete', 'event_espresso'),
112
+			),
113
+			EEM_Registration::status_id_declined        => array(
114
+				__('declined', 'event_espresso'),
115
+				__('declined', 'event_espresso'),
116
+			),
117
+			EEM_Registration::status_id_wait_list       => array(
118
+				__('wait list', 'event_espresso'),
119
+				__('wait list', 'event_espresso'),
120
+			),
121
+			EEM_Transaction::overpaid_status_code       => array(
122
+				__('overpaid', 'event_espresso'),
123
+				__('overpaid', 'event_espresso'),
124
+			),
125
+			EEM_Transaction::complete_status_code       => array(
126
+				__('complete', 'event_espresso'),
127
+				__('complete', 'event_espresso'),
128
+			),
129
+			EEM_Transaction::incomplete_status_code     => array(
130
+				__('incomplete', 'event_espresso'),
131
+				__('incomplete', 'event_espresso'),
132
+			),
133
+			EEM_Transaction::failed_status_code         => array(
134
+				__('failed', 'event_espresso'),
135
+				__('failed', 'event_espresso'),
136
+			),
137
+			EEM_Transaction::abandoned_status_code      => array(
138
+				__('abandoned', 'event_espresso'),
139
+				__('abandoned', 'event_espresso'),
140
+			),
141
+			EEM_Payment::status_id_approved             => array(
142
+				__('accepted', 'event_espresso'),
143
+				__('accepted', 'event_espresso'),
144
+			),
145
+			EEM_Payment::status_id_pending              => array(
146
+				__('pending', 'event_espresso'),
147
+				__('pending', 'event_espresso'),
148
+			),
149
+			EEM_Payment::status_id_cancelled            => array(
150
+				__('cancelled', 'event_espresso'),
151
+				__('cancelled', 'event_espresso'),
152
+			),
153
+			EEM_Payment::status_id_declined             => array(
154
+				__('declined', 'event_espresso'),
155
+				__('declined', 'event_espresso'),
156
+			),
157
+			EEM_Payment::status_id_failed               => array(
158
+				__('failed', 'event_espresso'),
159
+				__('failed', 'event_espresso'),
160
+			),
161
+			//following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
162
+			EEM_Event::sold_out                         => array(
163
+				__('sold out', 'event_espresso'),
164
+				__('sold out', 'event_espresso'),
165
+			),
166
+			EEM_Event::postponed                        => array(
167
+				__('postponed', 'event_espresso'),
168
+				__('Postponed', 'event_espresso'),
169
+			),
170
+			EEM_Event::cancelled                        => array(
171
+				__('cancelled', 'event_espresso'),
172
+				__('cancelled', 'event_espresso'),
173
+			),
174
+			EE_Ticket::archived                         => array(
175
+				__('archived', 'event_espresso'),
176
+				__('archived', 'event_espresso'),
177
+			),
178
+			EE_Ticket::expired                          => array(
179
+				__('expired', 'event_espresso'),
180
+				__('expired', 'event_espresso'),
181
+			),
182
+			EE_Ticket::sold_out                         => array(
183
+				__('sold out', 'event_espresso'),
184
+				__('sold out', 'event_espresso'),
185
+			),
186
+			EE_Ticket::pending                          => array(
187
+				__('upcoming', 'event_espresso'),
188
+				__('upcoming', 'event_espresso'),
189
+			),
190
+			EE_Ticket::onsale                           => array(
191
+				__('on sale', 'event_espresso'),
192
+				__('on sale', 'event_espresso'),
193
+			),
194
+			EE_Datetime::cancelled                      => array(
195
+				__('cancelled', 'event_espresso'),
196
+				__('cancelled', 'event_espresso'),
197
+			),
198
+			EE_Datetime::sold_out                       => array(
199
+				__('sold out', 'event_espresso'),
200
+				__('sold out', 'event_espresso'),
201
+			),
202
+			EE_Datetime::expired                        => array(
203
+				__('expired', 'event_espresso'),
204
+				__('expired', 'event_espresso'),
205
+			),
206
+			EE_Datetime::inactive                       => array(
207
+				__('inactive', 'event_espresso'),
208
+				__('inactive', 'event_espresso'),
209
+			),
210
+			EE_Datetime::upcoming                       => array(
211
+				__('upcoming', 'event_espresso'),
212
+				__('upcoming', 'event_espresso'),
213
+			),
214
+			EE_Datetime::active                         => array(
215
+				__('active', 'event_espresso'),
216
+				__('active', 'event_espresso'),
217
+			),
218
+			EE_Datetime::postponed                      => array(
219
+				__('postponed', 'event_espresso'),
220
+				__('postponed', 'event_espresso'),
221
+			),
222
+			//messages related
223
+			EEM_Message::status_sent                    => array(
224
+				__('sent', 'event_espresso'),
225
+				__('sent', 'event_espresso'),
226
+			),
227
+			EEM_Message::status_idle                    => array(
228
+				__('queued for sending', 'event_espresso'),
229
+				__('queued for sending', 'event_espresso'),
230
+			),
231
+			EEM_Message::status_failed                  => array(
232
+				__('failed', 'event_espresso'),
233
+				__('failed', 'event_espresso'),
234
+			),
235
+			EEM_Message::status_debug_only              => array(
236
+				__('debug only', 'event_espresso'),
237
+				__('debug only', 'event_espresso'),
238
+			),
239
+			EEM_Message::status_messenger_executing     => array(
240
+				__('messenger is executing', 'event_espresso'),
241
+				__('messenger is executing', 'event_espresso'),
242
+			),
243
+			EEM_Message::status_resend                  => array(
244
+				__('queued for resending', 'event_espresso'),
245
+				__('queued for resending', 'event_espresso'),
246
+			),
247
+			EEM_Message::status_incomplete              => array(
248
+				__('queued for generating', 'event_espresso'),
249
+				__('queued for generating', 'event_espresso'),
250
+			),
251
+			EEM_Message::status_retry                   => array(
252
+				__('failed sending, can be retried', 'event_espresso'),
253
+				__('failed sending, can be retried', 'event_espresso'),
254
+			),
255
+			EEM_CPT_Base::post_status_publish           => array(
256
+				__('published', 'event_espresso'),
257
+				__('published', 'event_espresso'),
258
+			),
259
+			EEM_CPT_Base::post_status_future            => array(
260
+				__('scheduled', 'event_espresso'),
261
+				__('scheduled', 'event_espresso'),
262
+			),
263
+			EEM_CPT_Base::post_status_draft             => array(
264
+				__('draft', 'event_espresso'),
265
+				__('draft', 'event_espresso'),
266
+			),
267
+			EEM_CPT_Base::post_status_pending           => array(
268
+				__('pending', 'event_espresso'),
269
+				__('pending', 'event_espresso'),
270
+			),
271
+			EEM_CPT_Base::post_status_private           => array(
272
+				__('private', 'event_espresso'),
273
+				__('private', 'event_espresso'),
274
+			),
275
+			EEM_CPT_Base::post_status_trashed           => array(
276
+				__('trashed', 'event_espresso'),
277
+				__('trashed', 'event_espresso'),
278
+			),
279
+		);
280 280
 
281
-        $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
281
+		$translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
282 282
 
283
-        if ( ! is_array($statuses)) {
284
-            throw new EE_Error(__('The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
285
-                'event_espresso'));
286
-        }
283
+		if ( ! is_array($statuses)) {
284
+			throw new EE_Error(__('The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
285
+				'event_espresso'));
286
+		}
287 287
 
288
-        $translation = array();
288
+		$translation = array();
289 289
 
290
-        foreach ($statuses as $id => $code) {
291
-            if (isset($translation_array[$id])) {
292
-                $translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0];
293
-            } else {
294
-                $translation[$id] = $code;
295
-            }
290
+		foreach ($statuses as $id => $code) {
291
+			if (isset($translation_array[$id])) {
292
+				$translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0];
293
+			} else {
294
+				$translation[$id] = $code;
295
+			}
296 296
 
297
-            //schema
298
-            switch ($schema) {
299
-                case 'lower' :
300
-                    $translation[$id] = strtolower($translation[$id]); //even though these start in lower case, this will catch any statuses added via filter.
301
-                    break;
302
-                case 'sentence' :
303
-                    $translation[$id] = ucwords($translation[$id]);
304
-                    break;
305
-                case 'upper' :
306
-                    $translation[$id] = strtoupper($translation[$id]);
307
-                    break;
308
-            }
309
-        }
297
+			//schema
298
+			switch ($schema) {
299
+				case 'lower' :
300
+					$translation[$id] = strtolower($translation[$id]); //even though these start in lower case, this will catch any statuses added via filter.
301
+					break;
302
+				case 'sentence' :
303
+					$translation[$id] = ucwords($translation[$id]);
304
+					break;
305
+				case 'upper' :
306
+					$translation[$id] = strtoupper($translation[$id]);
307
+					break;
308
+			}
309
+		}
310 310
 
311
-        return $translation;
312
-    }
311
+		return $translation;
312
+	}
313 313
 
314 314
 
315 315
 }
Please login to merge, or discard this patch.
admin_pages/messages/EE_Message_List_Table.class.php 2 patches
Indentation   +427 added lines, -427 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -15,430 +15,430 @@  discard block
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * @return Messages_Admin_Page
20
-     */
21
-    public function get_admin_page()
22
-    {
23
-        return $this->_admin_page;
24
-    }
25
-
26
-
27
-    protected function _setup_data()
28
-    {
29
-        $this->_data           = $this->_get_messages($this->_per_page, $this->_view);
30
-        $this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true);
31
-    }
32
-
33
-
34
-    protected function _set_properties()
35
-    {
36
-        $this->_wp_list_args = array(
37
-            'singular' => __('Message', 'event_espresso'),
38
-            'plural'   => __('Messages', 'event_espresso'),
39
-            'ajax'     => true,
40
-            'screen'   => $this->get_admin_page()->get_current_screen()->id,
41
-        );
42
-
43
-        $this->_columns = array(
44
-            'cb'           => '<input type="checkbox" />',
45
-            'to'           => __('To', 'event_espresso'),
46
-            'from'         => __('From', 'event_espresso'),
47
-            'messenger'    => __('Messenger', 'event_espresso'),
48
-            'message_type' => __('Message Type', 'event_espresso'),
49
-            'context'      => __('Context', 'event_espresso'),
50
-            'modified'     => __('Modified', 'event_espresso'),
51
-            'action'       => __('Actions', 'event_espresso'),
52
-            'msg_id'       => __('ID', 'event_espresso'),
53
-        );
54
-
55
-        $this->_sortable_columns = array(
56
-            'modified'     => array('MSG_modified' => true),
57
-            'message_type' => array('MSG_message_type' => false),
58
-            'messenger'    => array('MSG_messenger' => false),
59
-            'to'           => array('MSG_to' => false),
60
-            'from'         => array('MSG_from' => false),
61
-            'context'      => array('MSG_context' => false),
62
-            'msg_id'       => array('MSG_ID', false),
63
-        );
64
-
65
-        $this->_primary_column = 'to';
66
-
67
-        $this->_hidden_columns = array(
68
-            'msg_id',
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     * This simply sets up the row class for the table rows.
75
-     * Allows for easier overriding of child methods for setting up sorting.
76
-     *
77
-     * @param  object $item the current item
78
-     * @return string
79
-     */
80
-    protected function _get_row_class($item)
81
-    {
82
-        $class = parent::_get_row_class($item);
83
-        //add status class
84
-        $class .= ' ee-status-strip msg-status-' . $item->STS_ID();
85
-        if ($this->_has_checkbox_column) {
86
-            $class .= ' has-checkbox-column';
87
-        }
88
-        return $class;
89
-    }
90
-
91
-
92
-    /**
93
-     * _get_table_filters
94
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
95
-     * get's shown in the table.
96
-     *
97
-     * @abstract
98
-     * @access protected
99
-     * @return string
100
-     * @throws \EE_Error
101
-     */
102
-    protected function _get_table_filters()
103
-    {
104
-        $filters = array();
105
-
106
-        //get select_inputs
107
-        $select_inputs = array(
108
-            $this->_get_messengers_dropdown_filter(),
109
-            $this->_get_message_types_dropdown_filter(),
110
-            $this->_get_contexts_for_message_types_dropdown_filter(),
111
-        );
112
-
113
-        //set filters to select inputs if they aren't empty
114
-        foreach ($select_inputs as $select_input) {
115
-            if ($select_input) {
116
-                $filters[] = $select_input;
117
-            }
118
-        }
119
-        return $filters;
120
-    }
121
-
122
-
123
-    protected function _add_view_counts()
124
-    {
125
-        foreach ($this->_views as $view => $args) {
126
-            $this->_views[$view]['count'] = $this->_get_messages($this->_per_page, $view, true, true);
127
-        }
128
-    }
129
-
130
-
131
-    /**
132
-     * @param EE_Message $message
133
-     * @return string   checkbox
134
-     * @throws \EE_Error
135
-     */
136
-    public function column_cb($message)
137
-    {
138
-        return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID());
139
-    }
140
-
141
-
142
-    /**
143
-     * @param EE_Message $message
144
-     * @return string
145
-     * @throws \EE_Error
146
-     */
147
-    public function column_msg_id(EE_Message $message)
148
-    {
149
-        return $message->ID();
150
-    }
151
-
152
-
153
-    /**
154
-     * @param EE_Message $message
155
-     * @return string    The recipient of the message
156
-     * @throws \EE_Error
157
-     */
158
-    public function column_to(EE_Message $message)
159
-    {
160
-        EE_Registry::instance()->load_helper('URL');
161
-        $actions           = array();
162
-        $actions['delete'] = '<a href="'
163
-                             . EEH_URL::add_query_args_and_nonce(
164
-                array(
165
-                    'page'   => 'espresso_messages',
166
-                    'action' => 'delete_ee_message',
167
-                    'MSG_ID' => $message->ID(),
168
-                ),
169
-                admin_url('admin.php')
170
-            )
171
-                             . '">' . __('Delete', 'event_espresso') . '</a>';
172
-        return esc_html($message->to()) . $this->row_actions($actions);
173
-    }
174
-
175
-
176
-    /**
177
-     * @param EE_Message $message
178
-     * @return string   The sender of the message
179
-     */
180
-    public function column_from(EE_Message $message)
181
-    {
182
-        return esc_html($message->from());
183
-    }
184
-
185
-
186
-    /**
187
-     * @param EE_Message $message
188
-     * @return string  The messenger used to send the message.
189
-     */
190
-    public function column_messenger(EE_Message $message)
191
-    {
192
-        return ucwords($message->messenger_label());
193
-    }
194
-
195
-
196
-    /**
197
-     * @param EE_Message $message
198
-     * @return string  The message type used to generate the message.
199
-     */
200
-    public function column_message_type(EE_Message $message)
201
-    {
202
-        return ucwords($message->message_type_label());
203
-    }
204
-
205
-
206
-    /**
207
-     * @param EE_Message $message
208
-     * @return string  The context the message was generated for.
209
-     */
210
-    public function column_context(EE_Message $message)
211
-    {
212
-        return $message->context_label();
213
-    }
214
-
215
-
216
-    /**
217
-     * @param EE_Message $message
218
-     * @return string    The timestamp when this message was last modified.
219
-     */
220
-    public function column_modified(EE_Message $message)
221
-    {
222
-        return $message->modified();
223
-    }
224
-
225
-
226
-    /**
227
-     * @param EE_Message $message
228
-     * @return string   Actions that can be done on the current message.
229
-     */
230
-    public function column_action(EE_Message $message)
231
-    {
232
-        EE_Registry::instance()->load_helper('MSG_Template');
233
-        $action_links = array(
234
-            'view'                => EEH_MSG_Template::get_message_action_link('view', $message),
235
-            'error'               => EEH_MSG_Template::get_message_action_link('error', $message),
236
-            'generate_now'        => EEH_MSG_Template::get_message_action_link('generate_now', $message),
237
-            'send_now'            => EEH_MSG_Template::get_message_action_link('send_now', $message),
238
-            'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message),
239
-            'view_transaction'    => EEH_MSG_Template::get_message_action_link('view_transaction', $message),
240
-        );
241
-        $content      = '';
242
-        switch ($message->STS_ID()) {
243
-            case EEM_Message::status_sent :
244
-                $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
245
-                break;
246
-            case EEM_Message::status_resend :
247
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
248
-                break;
249
-            case EEM_Message::status_retry :
250
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
251
-                break;
252
-            case EEM_Message::status_failed :
253
-            case EEM_Message::status_debug_only :
254
-                $content = $action_links['error'] . $action_links['view_transaction'];
255
-                break;
256
-            case EEM_Message::status_idle :
257
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
258
-                break;
259
-            case EEM_Message::status_incomplete;
260
-                $content = $action_links['generate_now'] . $action_links['view_transaction'];
261
-                break;
262
-        }
263
-        return $content;
264
-    }
265
-
266
-
267
-    /**
268
-     * Retrieve the EE_Message objects for the list table.
269
-     *
270
-     * @param int    $perpage The number of items per page
271
-     * @param string $view    The view items are being retrieved for
272
-     * @param bool   $count   Whether to just return a count or not.
273
-     * @param bool   $all     Disregard any paging info (no limit on data returned).
274
-     * @return int|EE_Message[]
275
-     * @throws \EE_Error
276
-     */
277
-    protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false)
278
-    {
279
-
280
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
281
-            ? $this->_req_data['paged']
282
-            : 1;
283
-
284
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
285
-            ? $this->_req_data['perpage']
286
-            : $perpage;
287
-
288
-        $offset       = ($current_page - 1) * $per_page;
289
-        $limit        = $all || $count ? null : array($offset, $per_page);
290
-        $query_params = array(
291
-            'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'],
292
-            'order'    => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'],
293
-            'limit'    => $limit,
294
-        );
295
-
296
-        /**
297
-         * Any filters coming in from other routes?
298
-         */
299
-        if (isset($this->_req_data['filterby'])) {
300
-            $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params());
301
-            if ( ! $count) {
302
-                $query_params['group_by'] = 'MSG_ID';
303
-            }
304
-        }
305
-
306
-        //view conditionals
307
-        if ($view !== 'all' && $count && $all) {
308
-            $query_params[0]['AND*view_conditional'] = array(
309
-                'STS_ID' => strtoupper($view),
310
-            );
311
-        }
312
-
313
-        if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
314
-            $query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed
315
-                ? array(
316
-                    'STS_ID' => array(
317
-                        'IN',
318
-                        array(EEM_Message::status_failed, EEM_Message::status_messenger_executing)
319
-                    )
320
-                )
321
-                : array( 'STS_ID' => strtoupper($this->_req_data['status']) );
322
-        }
323
-
324
-        if (! $all && ! empty($this->_req_data['s'])) {
325
-            $search_string         = '%' . $this->_req_data['s'] . '%';
326
-            $query_params[0]['OR'] = array(
327
-                'MSG_to'      => array('LIKE', $search_string),
328
-                'MSG_from'    => array('LIKE', $search_string),
329
-                'MSG_subject' => array('LIKE', $search_string),
330
-                'MSG_content' => array('LIKE', $search_string),
331
-            );
332
-        }
333
-
334
-        //account for debug only status.  We don't show Messages with the EEM_Message::status_debug_only to clients when
335
-        //the messages system is in debug mode.
336
-        //Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only
337
-        //messages in the database.
338
-        if (! EEM_Message::debug()) {
339
-            $query_params[0]['AND*debug_only_conditional'] = array(
340
-                'STS_ID' => array('!=', EEM_Message::status_debug_only),
341
-            );
342
-        }
343
-
344
-        //account for filters
345
-        if (! $all
346
-            && isset($this->_req_data['ee_messenger_filter_by'])
347
-            && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected'
348
-        ) {
349
-            $query_params[0]['AND*messenger_filter'] = array(
350
-                'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'],
351
-            );
352
-        }
353
-        if (! $all
354
-            && ! empty($this->_req_data['ee_message_type_filter_by'])
355
-            && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected'
356
-        ) {
357
-            $query_params[0]['AND*message_type_filter'] = array(
358
-                'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'],
359
-            );
360
-        }
361
-
362
-        if (! $all
363
-            && ! empty($this->_req_data['ee_context_filter_by'])
364
-            && $this->_req_data['ee_context_filter_by'] !== 'none_selected'
365
-        ) {
366
-            $query_params[0]['AND*context_filter'] = array(
367
-                'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])),
368
-            );
369
-        }
370
-
371
-        return $count
372
-            /** @type int */
373
-            ? EEM_Message::instance()->count($query_params, null, true)
374
-            /** @type EE_Message[] */
375
-            : EEM_Message::instance()->get_all($query_params);
376
-    }
377
-
378
-
379
-    /**
380
-     * Generate dropdown filter select input for messengers.
381
-     *
382
-     * @return string
383
-     */
384
-    protected function _get_messengers_dropdown_filter()
385
-    {
386
-        $messenger_options                    = array();
387
-        $active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
388
-
389
-        //setup array of messenger options
390
-        foreach ($active_messages_grouped_by_messenger as $active_message) {
391
-            if ($active_message instanceof EE_Message) {
392
-                $messenger_options[$active_message->messenger()] = ucwords($active_message->messenger_label());
393
-            }
394
-        }
395
-        return $this->get_admin_page()->get_messengers_select_input($messenger_options);
396
-    }
397
-
398
-
399
-    /**
400
-     * Generate dropdown filter select input for message types
401
-     *
402
-     * @return string
403
-     */
404
-    protected function _get_message_types_dropdown_filter()
405
-    {
406
-        $message_type_options                    = array();
407
-        $active_messages_grouped_by_message_type = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
408
-
409
-        //setup array of message type options
410
-        foreach ($active_messages_grouped_by_message_type as $active_message) {
411
-            if ($active_message instanceof EE_Message) {
412
-                $message_type_options[$active_message->message_type()] = ucwords($active_message->message_type_label());
413
-            }
414
-        }
415
-        return $this->get_admin_page()->get_message_types_select_input($message_type_options);
416
-    }
417
-
418
-
419
-    /**
420
-     * Generate dropdown filter select input for message type contexts
421
-     *
422
-     * @return string
423
-     */
424
-    protected function _get_contexts_for_message_types_dropdown_filter()
425
-    {
426
-        $context_options                    = array();
427
-        $active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
428
-
429
-        //setup array of context options
430
-        foreach ($active_messages_grouped_by_context as $active_message) {
431
-            if ($active_message instanceof EE_Message) {
432
-                $message_type = $active_message->message_type_object();
433
-                if ($message_type instanceof EE_message_type) {
434
-                    foreach ($message_type->get_contexts() as $context => $context_details) {
435
-                        if (isset($context_details['label'])) {
436
-                            $context_options[$context] = $context_details['label'];
437
-                        }
438
-                    }
439
-                }
440
-            }
441
-        }
442
-        return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options);
443
-    }
18
+	/**
19
+	 * @return Messages_Admin_Page
20
+	 */
21
+	public function get_admin_page()
22
+	{
23
+		return $this->_admin_page;
24
+	}
25
+
26
+
27
+	protected function _setup_data()
28
+	{
29
+		$this->_data           = $this->_get_messages($this->_per_page, $this->_view);
30
+		$this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true);
31
+	}
32
+
33
+
34
+	protected function _set_properties()
35
+	{
36
+		$this->_wp_list_args = array(
37
+			'singular' => __('Message', 'event_espresso'),
38
+			'plural'   => __('Messages', 'event_espresso'),
39
+			'ajax'     => true,
40
+			'screen'   => $this->get_admin_page()->get_current_screen()->id,
41
+		);
42
+
43
+		$this->_columns = array(
44
+			'cb'           => '<input type="checkbox" />',
45
+			'to'           => __('To', 'event_espresso'),
46
+			'from'         => __('From', 'event_espresso'),
47
+			'messenger'    => __('Messenger', 'event_espresso'),
48
+			'message_type' => __('Message Type', 'event_espresso'),
49
+			'context'      => __('Context', 'event_espresso'),
50
+			'modified'     => __('Modified', 'event_espresso'),
51
+			'action'       => __('Actions', 'event_espresso'),
52
+			'msg_id'       => __('ID', 'event_espresso'),
53
+		);
54
+
55
+		$this->_sortable_columns = array(
56
+			'modified'     => array('MSG_modified' => true),
57
+			'message_type' => array('MSG_message_type' => false),
58
+			'messenger'    => array('MSG_messenger' => false),
59
+			'to'           => array('MSG_to' => false),
60
+			'from'         => array('MSG_from' => false),
61
+			'context'      => array('MSG_context' => false),
62
+			'msg_id'       => array('MSG_ID', false),
63
+		);
64
+
65
+		$this->_primary_column = 'to';
66
+
67
+		$this->_hidden_columns = array(
68
+			'msg_id',
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 * This simply sets up the row class for the table rows.
75
+	 * Allows for easier overriding of child methods for setting up sorting.
76
+	 *
77
+	 * @param  object $item the current item
78
+	 * @return string
79
+	 */
80
+	protected function _get_row_class($item)
81
+	{
82
+		$class = parent::_get_row_class($item);
83
+		//add status class
84
+		$class .= ' ee-status-strip msg-status-' . $item->STS_ID();
85
+		if ($this->_has_checkbox_column) {
86
+			$class .= ' has-checkbox-column';
87
+		}
88
+		return $class;
89
+	}
90
+
91
+
92
+	/**
93
+	 * _get_table_filters
94
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
95
+	 * get's shown in the table.
96
+	 *
97
+	 * @abstract
98
+	 * @access protected
99
+	 * @return string
100
+	 * @throws \EE_Error
101
+	 */
102
+	protected function _get_table_filters()
103
+	{
104
+		$filters = array();
105
+
106
+		//get select_inputs
107
+		$select_inputs = array(
108
+			$this->_get_messengers_dropdown_filter(),
109
+			$this->_get_message_types_dropdown_filter(),
110
+			$this->_get_contexts_for_message_types_dropdown_filter(),
111
+		);
112
+
113
+		//set filters to select inputs if they aren't empty
114
+		foreach ($select_inputs as $select_input) {
115
+			if ($select_input) {
116
+				$filters[] = $select_input;
117
+			}
118
+		}
119
+		return $filters;
120
+	}
121
+
122
+
123
+	protected function _add_view_counts()
124
+	{
125
+		foreach ($this->_views as $view => $args) {
126
+			$this->_views[$view]['count'] = $this->_get_messages($this->_per_page, $view, true, true);
127
+		}
128
+	}
129
+
130
+
131
+	/**
132
+	 * @param EE_Message $message
133
+	 * @return string   checkbox
134
+	 * @throws \EE_Error
135
+	 */
136
+	public function column_cb($message)
137
+	{
138
+		return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID());
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param EE_Message $message
144
+	 * @return string
145
+	 * @throws \EE_Error
146
+	 */
147
+	public function column_msg_id(EE_Message $message)
148
+	{
149
+		return $message->ID();
150
+	}
151
+
152
+
153
+	/**
154
+	 * @param EE_Message $message
155
+	 * @return string    The recipient of the message
156
+	 * @throws \EE_Error
157
+	 */
158
+	public function column_to(EE_Message $message)
159
+	{
160
+		EE_Registry::instance()->load_helper('URL');
161
+		$actions           = array();
162
+		$actions['delete'] = '<a href="'
163
+							 . EEH_URL::add_query_args_and_nonce(
164
+				array(
165
+					'page'   => 'espresso_messages',
166
+					'action' => 'delete_ee_message',
167
+					'MSG_ID' => $message->ID(),
168
+				),
169
+				admin_url('admin.php')
170
+			)
171
+							 . '">' . __('Delete', 'event_espresso') . '</a>';
172
+		return esc_html($message->to()) . $this->row_actions($actions);
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param EE_Message $message
178
+	 * @return string   The sender of the message
179
+	 */
180
+	public function column_from(EE_Message $message)
181
+	{
182
+		return esc_html($message->from());
183
+	}
184
+
185
+
186
+	/**
187
+	 * @param EE_Message $message
188
+	 * @return string  The messenger used to send the message.
189
+	 */
190
+	public function column_messenger(EE_Message $message)
191
+	{
192
+		return ucwords($message->messenger_label());
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param EE_Message $message
198
+	 * @return string  The message type used to generate the message.
199
+	 */
200
+	public function column_message_type(EE_Message $message)
201
+	{
202
+		return ucwords($message->message_type_label());
203
+	}
204
+
205
+
206
+	/**
207
+	 * @param EE_Message $message
208
+	 * @return string  The context the message was generated for.
209
+	 */
210
+	public function column_context(EE_Message $message)
211
+	{
212
+		return $message->context_label();
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param EE_Message $message
218
+	 * @return string    The timestamp when this message was last modified.
219
+	 */
220
+	public function column_modified(EE_Message $message)
221
+	{
222
+		return $message->modified();
223
+	}
224
+
225
+
226
+	/**
227
+	 * @param EE_Message $message
228
+	 * @return string   Actions that can be done on the current message.
229
+	 */
230
+	public function column_action(EE_Message $message)
231
+	{
232
+		EE_Registry::instance()->load_helper('MSG_Template');
233
+		$action_links = array(
234
+			'view'                => EEH_MSG_Template::get_message_action_link('view', $message),
235
+			'error'               => EEH_MSG_Template::get_message_action_link('error', $message),
236
+			'generate_now'        => EEH_MSG_Template::get_message_action_link('generate_now', $message),
237
+			'send_now'            => EEH_MSG_Template::get_message_action_link('send_now', $message),
238
+			'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message),
239
+			'view_transaction'    => EEH_MSG_Template::get_message_action_link('view_transaction', $message),
240
+		);
241
+		$content      = '';
242
+		switch ($message->STS_ID()) {
243
+			case EEM_Message::status_sent :
244
+				$content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
245
+				break;
246
+			case EEM_Message::status_resend :
247
+				$content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
248
+				break;
249
+			case EEM_Message::status_retry :
250
+				$content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
251
+				break;
252
+			case EEM_Message::status_failed :
253
+			case EEM_Message::status_debug_only :
254
+				$content = $action_links['error'] . $action_links['view_transaction'];
255
+				break;
256
+			case EEM_Message::status_idle :
257
+				$content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
258
+				break;
259
+			case EEM_Message::status_incomplete;
260
+				$content = $action_links['generate_now'] . $action_links['view_transaction'];
261
+				break;
262
+		}
263
+		return $content;
264
+	}
265
+
266
+
267
+	/**
268
+	 * Retrieve the EE_Message objects for the list table.
269
+	 *
270
+	 * @param int    $perpage The number of items per page
271
+	 * @param string $view    The view items are being retrieved for
272
+	 * @param bool   $count   Whether to just return a count or not.
273
+	 * @param bool   $all     Disregard any paging info (no limit on data returned).
274
+	 * @return int|EE_Message[]
275
+	 * @throws \EE_Error
276
+	 */
277
+	protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false)
278
+	{
279
+
280
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
281
+			? $this->_req_data['paged']
282
+			: 1;
283
+
284
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
285
+			? $this->_req_data['perpage']
286
+			: $perpage;
287
+
288
+		$offset       = ($current_page - 1) * $per_page;
289
+		$limit        = $all || $count ? null : array($offset, $per_page);
290
+		$query_params = array(
291
+			'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'],
292
+			'order'    => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'],
293
+			'limit'    => $limit,
294
+		);
295
+
296
+		/**
297
+		 * Any filters coming in from other routes?
298
+		 */
299
+		if (isset($this->_req_data['filterby'])) {
300
+			$query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params());
301
+			if ( ! $count) {
302
+				$query_params['group_by'] = 'MSG_ID';
303
+			}
304
+		}
305
+
306
+		//view conditionals
307
+		if ($view !== 'all' && $count && $all) {
308
+			$query_params[0]['AND*view_conditional'] = array(
309
+				'STS_ID' => strtoupper($view),
310
+			);
311
+		}
312
+
313
+		if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
314
+			$query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed
315
+				? array(
316
+					'STS_ID' => array(
317
+						'IN',
318
+						array(EEM_Message::status_failed, EEM_Message::status_messenger_executing)
319
+					)
320
+				)
321
+				: array( 'STS_ID' => strtoupper($this->_req_data['status']) );
322
+		}
323
+
324
+		if (! $all && ! empty($this->_req_data['s'])) {
325
+			$search_string         = '%' . $this->_req_data['s'] . '%';
326
+			$query_params[0]['OR'] = array(
327
+				'MSG_to'      => array('LIKE', $search_string),
328
+				'MSG_from'    => array('LIKE', $search_string),
329
+				'MSG_subject' => array('LIKE', $search_string),
330
+				'MSG_content' => array('LIKE', $search_string),
331
+			);
332
+		}
333
+
334
+		//account for debug only status.  We don't show Messages with the EEM_Message::status_debug_only to clients when
335
+		//the messages system is in debug mode.
336
+		//Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only
337
+		//messages in the database.
338
+		if (! EEM_Message::debug()) {
339
+			$query_params[0]['AND*debug_only_conditional'] = array(
340
+				'STS_ID' => array('!=', EEM_Message::status_debug_only),
341
+			);
342
+		}
343
+
344
+		//account for filters
345
+		if (! $all
346
+			&& isset($this->_req_data['ee_messenger_filter_by'])
347
+			&& $this->_req_data['ee_messenger_filter_by'] !== 'none_selected'
348
+		) {
349
+			$query_params[0]['AND*messenger_filter'] = array(
350
+				'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'],
351
+			);
352
+		}
353
+		if (! $all
354
+			&& ! empty($this->_req_data['ee_message_type_filter_by'])
355
+			&& $this->_req_data['ee_message_type_filter_by'] !== 'none_selected'
356
+		) {
357
+			$query_params[0]['AND*message_type_filter'] = array(
358
+				'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'],
359
+			);
360
+		}
361
+
362
+		if (! $all
363
+			&& ! empty($this->_req_data['ee_context_filter_by'])
364
+			&& $this->_req_data['ee_context_filter_by'] !== 'none_selected'
365
+		) {
366
+			$query_params[0]['AND*context_filter'] = array(
367
+				'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])),
368
+			);
369
+		}
370
+
371
+		return $count
372
+			/** @type int */
373
+			? EEM_Message::instance()->count($query_params, null, true)
374
+			/** @type EE_Message[] */
375
+			: EEM_Message::instance()->get_all($query_params);
376
+	}
377
+
378
+
379
+	/**
380
+	 * Generate dropdown filter select input for messengers.
381
+	 *
382
+	 * @return string
383
+	 */
384
+	protected function _get_messengers_dropdown_filter()
385
+	{
386
+		$messenger_options                    = array();
387
+		$active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
388
+
389
+		//setup array of messenger options
390
+		foreach ($active_messages_grouped_by_messenger as $active_message) {
391
+			if ($active_message instanceof EE_Message) {
392
+				$messenger_options[$active_message->messenger()] = ucwords($active_message->messenger_label());
393
+			}
394
+		}
395
+		return $this->get_admin_page()->get_messengers_select_input($messenger_options);
396
+	}
397
+
398
+
399
+	/**
400
+	 * Generate dropdown filter select input for message types
401
+	 *
402
+	 * @return string
403
+	 */
404
+	protected function _get_message_types_dropdown_filter()
405
+	{
406
+		$message_type_options                    = array();
407
+		$active_messages_grouped_by_message_type = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
408
+
409
+		//setup array of message type options
410
+		foreach ($active_messages_grouped_by_message_type as $active_message) {
411
+			if ($active_message instanceof EE_Message) {
412
+				$message_type_options[$active_message->message_type()] = ucwords($active_message->message_type_label());
413
+			}
414
+		}
415
+		return $this->get_admin_page()->get_message_types_select_input($message_type_options);
416
+	}
417
+
418
+
419
+	/**
420
+	 * Generate dropdown filter select input for message type contexts
421
+	 *
422
+	 * @return string
423
+	 */
424
+	protected function _get_contexts_for_message_types_dropdown_filter()
425
+	{
426
+		$context_options                    = array();
427
+		$active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
428
+
429
+		//setup array of context options
430
+		foreach ($active_messages_grouped_by_context as $active_message) {
431
+			if ($active_message instanceof EE_Message) {
432
+				$message_type = $active_message->message_type_object();
433
+				if ($message_type instanceof EE_message_type) {
434
+					foreach ($message_type->get_contexts() as $context => $context_details) {
435
+						if (isset($context_details['label'])) {
436
+							$context_options[$context] = $context_details['label'];
437
+						}
438
+					}
439
+				}
440
+			}
441
+		}
442
+		return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options);
443
+	}
444 444
 } //end EE_Message_List_Table class
445 445
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     {
82 82
         $class = parent::_get_row_class($item);
83 83
         //add status class
84
-        $class .= ' ee-status-strip msg-status-' . $item->STS_ID();
84
+        $class .= ' ee-status-strip msg-status-'.$item->STS_ID();
85 85
         if ($this->_has_checkbox_column) {
86 86
             $class .= ' has-checkbox-column';
87 87
         }
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
                 ),
169 169
                 admin_url('admin.php')
170 170
             )
171
-                             . '">' . __('Delete', 'event_espresso') . '</a>';
172
-        return esc_html($message->to()) . $this->row_actions($actions);
171
+                             . '">'.__('Delete', 'event_espresso').'</a>';
172
+        return esc_html($message->to()).$this->row_actions($actions);
173 173
     }
174 174
 
175 175
 
@@ -238,26 +238,26 @@  discard block
 block discarded – undo
238 238
             'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message),
239 239
             'view_transaction'    => EEH_MSG_Template::get_message_action_link('view_transaction', $message),
240 240
         );
241
-        $content      = '';
241
+        $content = '';
242 242
         switch ($message->STS_ID()) {
243 243
             case EEM_Message::status_sent :
244
-                $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
244
+                $content = $action_links['view'].$action_links['queue_for_resending'].$action_links['view_transaction'];
245 245
                 break;
246 246
             case EEM_Message::status_resend :
247
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
247
+                $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction'];
248 248
                 break;
249 249
             case EEM_Message::status_retry :
250
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
250
+                $content = $action_links['view'].$action_links['send_now'].$action_links['error'].$action_links['view_transaction'];
251 251
                 break;
252 252
             case EEM_Message::status_failed :
253 253
             case EEM_Message::status_debug_only :
254
-                $content = $action_links['error'] . $action_links['view_transaction'];
254
+                $content = $action_links['error'].$action_links['view_transaction'];
255 255
                 break;
256 256
             case EEM_Message::status_idle :
257
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
257
+                $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction'];
258 258
                 break;
259 259
             case EEM_Message::status_incomplete;
260
-                $content = $action_links['generate_now'] . $action_links['view_transaction'];
260
+                $content = $action_links['generate_now'].$action_links['view_transaction'];
261 261
                 break;
262 262
         }
263 263
         return $content;
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
             );
311 311
         }
312 312
 
313
-        if (! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
313
+        if ( ! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
314 314
             $query_params[0]['AND*view_conditional'] = $this->_req_data === EEM_Message::status_failed
315 315
                 ? array(
316 316
                     'STS_ID' => array(
@@ -318,11 +318,11 @@  discard block
 block discarded – undo
318 318
                         array(EEM_Message::status_failed, EEM_Message::status_messenger_executing)
319 319
                     )
320 320
                 )
321
-                : array( 'STS_ID' => strtoupper($this->_req_data['status']) );
321
+                : array('STS_ID' => strtoupper($this->_req_data['status']));
322 322
         }
323 323
 
324
-        if (! $all && ! empty($this->_req_data['s'])) {
325
-            $search_string         = '%' . $this->_req_data['s'] . '%';
324
+        if ( ! $all && ! empty($this->_req_data['s'])) {
325
+            $search_string         = '%'.$this->_req_data['s'].'%';
326 326
             $query_params[0]['OR'] = array(
327 327
                 'MSG_to'      => array('LIKE', $search_string),
328 328
                 'MSG_from'    => array('LIKE', $search_string),
@@ -335,14 +335,14 @@  discard block
 block discarded – undo
335 335
         //the messages system is in debug mode.
336 336
         //Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only
337 337
         //messages in the database.
338
-        if (! EEM_Message::debug()) {
338
+        if ( ! EEM_Message::debug()) {
339 339
             $query_params[0]['AND*debug_only_conditional'] = array(
340 340
                 'STS_ID' => array('!=', EEM_Message::status_debug_only),
341 341
             );
342 342
         }
343 343
 
344 344
         //account for filters
345
-        if (! $all
345
+        if ( ! $all
346 346
             && isset($this->_req_data['ee_messenger_filter_by'])
347 347
             && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected'
348 348
         ) {
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
                 'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'],
351 351
             );
352 352
         }
353
-        if (! $all
353
+        if ( ! $all
354 354
             && ! empty($this->_req_data['ee_message_type_filter_by'])
355 355
             && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected'
356 356
         ) {
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
             );
360 360
         }
361 361
 
362
-        if (! $all
362
+        if ( ! $all
363 363
             && ! empty($this->_req_data['ee_context_filter_by'])
364 364
             && $this->_req_data['ee_context_filter_by'] !== 'none_selected'
365 365
         ) {
Please login to merge, or discard this patch.