@@ -40,8 +40,11 @@ discard block |
||
40 | 40 | <?php echo do_shortcode( $venue_description ); ?> |
41 | 41 | </p> |
42 | 42 | <?php endif; ?> |
43 | - <?php else : ?> |
|
44 | - <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); ?> |
|
43 | + <?php else { |
|
44 | + : ?> |
|
45 | + <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); |
|
46 | +} |
|
47 | +?> |
|
45 | 48 | <?php if ( $venue_excerpt ) : ?> |
46 | 49 | <p> |
47 | 50 | <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
@@ -53,12 +56,15 @@ discard block |
||
53 | 56 | <!-- .espresso-venue-dv --> |
54 | 57 | <?php |
55 | 58 | do_action( 'AHEE_event_details_after_venue_details', $post ); |
56 | -else : |
|
59 | +else { |
|
60 | + : |
|
57 | 61 | if ( espresso_venue_is_password_protected() ) : |
58 | 62 | ?> |
59 | 63 | <div class="espresso-venue-dv espresso-password-protected-venue-dv" > |
60 | 64 | <h3 class="event-venues-h3 ee-event-h3"> |
61 | - <?php _e( 'Location', 'event_espresso' );?> |
|
65 | + <?php _e( 'Location', 'event_espresso' ); |
|
66 | +} |
|
67 | +?> |
|
62 | 68 | </h3> |
63 | 69 | <?php echo espresso_password_protected_venue_form(); ?> |
64 | 70 | </div> |
@@ -1,66 +1,66 @@ |
||
1 | 1 | <?php |
2 | 2 | //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>'; |
3 | 3 | if ( |
4 | - ( is_single() && espresso_display_venue_in_event_details() ) |
|
5 | - || ( is_archive() && espresso_display_venue_in_event_list() ) |
|
4 | + (is_single() && espresso_display_venue_in_event_details()) |
|
5 | + || (is_archive() && espresso_display_venue_in_event_list()) |
|
6 | 6 | ) : |
7 | 7 | global $post; |
8 | - do_action( 'AHEE_event_details_before_venue_details', $post ); |
|
9 | - $venue_name = espresso_venue_name( 0, 'details', FALSE ); |
|
10 | - if ( empty( $venue_name ) && espresso_is_venue_private() ) { |
|
11 | - do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
8 | + do_action('AHEE_event_details_before_venue_details', $post); |
|
9 | + $venue_name = espresso_venue_name(0, 'details', FALSE); |
|
10 | + if (empty($venue_name) && espresso_is_venue_private()) { |
|
11 | + do_action('AHEE_event_details_after_venue_details', $post); |
|
12 | 12 | return ''; |
13 | 13 | } |
14 | 14 | ?> |
15 | 15 | |
16 | 16 | <div class="espresso-venue-dv<?php echo espresso_is_venue_private() ? ' espresso-private-venue-dv' : ''; ?>"> |
17 | - <h4><strong><?php _e( 'Venue:', 'event_espresso' ); ?></strong> <strong> <?php echo $venue_name; ?></strong></h4> |
|
17 | + <h4><strong><?php _e('Venue:', 'event_espresso'); ?></strong> <strong> <?php echo $venue_name; ?></strong></h4> |
|
18 | 18 | <p><span class="smaller-text tags-links"><?php echo espresso_venue_categories(); ?></span></p> |
19 | -<?php if ( $venue_phone = espresso_venue_phone( $post->ID, FALSE )) : ?> |
|
19 | +<?php if ($venue_phone = espresso_venue_phone($post->ID, FALSE)) : ?> |
|
20 | 20 | <p> |
21 | - <span class="small-text"><strong><?php _e( 'Venue Phone:', 'event_espresso' ); ?></strong></span> <?php echo $venue_phone; ?> |
|
21 | + <span class="small-text"><strong><?php _e('Venue Phone:', 'event_espresso'); ?></strong></span> <?php echo $venue_phone; ?> |
|
22 | 22 | </p> |
23 | -<?php endif; ?> |
|
24 | -<?php if ( $venue_website = espresso_venue_website( $post->ID, FALSE )) : ?> |
|
23 | +<?php endif; ?> |
|
24 | +<?php if ($venue_website = espresso_venue_website($post->ID, FALSE)) : ?> |
|
25 | 25 | <p> |
26 | - <span class="small-text"><strong><?php _e( 'Venue Website:', 'event_espresso' ); ?></strong></span> <?php echo $venue_website; ?> |
|
26 | + <span class="small-text"><strong><?php _e('Venue Website:', 'event_espresso'); ?></strong></span> <?php echo $venue_website; ?> |
|
27 | 27 | </p> |
28 | 28 | <?php endif; ?> |
29 | -<?php if ( espresso_venue_has_address( $post->ID )) : ?> |
|
30 | - <strong><span class="dashicons dashicons-location-alt"></span><?php _e( 'Address:', 'event_espresso' ); ?></strong> |
|
31 | - <?php espresso_venue_address( 'inline' ); ?> |
|
32 | - <?php espresso_venue_gmap( $post->ID ); ?> |
|
29 | +<?php if (espresso_venue_has_address($post->ID)) : ?> |
|
30 | + <strong><span class="dashicons dashicons-location-alt"></span><?php _e('Address:', 'event_espresso'); ?></strong> |
|
31 | + <?php espresso_venue_address('inline'); ?> |
|
32 | + <?php espresso_venue_gmap($post->ID); ?> |
|
33 | 33 | <div class="clear"><br/></div> |
34 | -<?php endif; ?> |
|
34 | +<?php endif; ?> |
|
35 | 35 | |
36 | - <?php $VNU_ID = espresso_venue_id( $post->ID ); ?> |
|
37 | - <?php if ( is_single() ) : ?> |
|
38 | - <?php $venue_description = espresso_venue_description( $VNU_ID, FALSE ); ?> |
|
39 | - <?php if ( $venue_description ) : ?> |
|
36 | + <?php $VNU_ID = espresso_venue_id($post->ID); ?> |
|
37 | + <?php if (is_single()) : ?> |
|
38 | + <?php $venue_description = espresso_venue_description($VNU_ID, FALSE); ?> |
|
39 | + <?php if ($venue_description) : ?> |
|
40 | 40 | <p> |
41 | - <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
42 | - <?php echo do_shortcode( $venue_description ); ?> |
|
41 | + <strong><?php _e('Description:', 'event_espresso'); ?></strong><br/> |
|
42 | + <?php echo do_shortcode($venue_description); ?> |
|
43 | 43 | </p> |
44 | - <?php endif; ?> |
|
44 | + <?php endif; ?> |
|
45 | 45 | <?php else : ?> |
46 | - <?php $venue_excerpt = espresso_venue_excerpt( $VNU_ID, FALSE ); ?> |
|
47 | - <?php if ( $venue_excerpt ) : ?> |
|
46 | + <?php $venue_excerpt = espresso_venue_excerpt($VNU_ID, FALSE); ?> |
|
47 | + <?php if ($venue_excerpt) : ?> |
|
48 | 48 | <p> |
49 | - <strong><?php _e( 'Description:', 'event_espresso' ); ?></strong><br/> |
|
49 | + <strong><?php _e('Description:', 'event_espresso'); ?></strong><br/> |
|
50 | 50 | <?php echo $venue_excerpt; ?> |
51 | 51 | </p> |
52 | - <?php endif; ?> |
|
53 | - <?php endif; ?> |
|
52 | + <?php endif; ?> |
|
53 | + <?php endif; ?> |
|
54 | 54 | </div> |
55 | 55 | <!-- .espresso-venue-dv --> |
56 | 56 | <?php |
57 | -do_action( 'AHEE_event_details_after_venue_details', $post ); |
|
57 | +do_action('AHEE_event_details_after_venue_details', $post); |
|
58 | 58 | else : |
59 | - if ( espresso_venue_is_password_protected() ) : |
|
59 | + if (espresso_venue_is_password_protected()) : |
|
60 | 60 | ?> |
61 | 61 | <div class="espresso-venue-dv espresso-password-protected-venue-dv" > |
62 | 62 | <h3 class="event-venues-h3 ee-event-h3"> |
63 | - <?php _e( 'Location', 'event_espresso' );?> |
|
63 | + <?php _e('Location', 'event_espresso'); ?> |
|
64 | 64 | </h3> |
65 | 65 | <?php echo espresso_password_protected_venue_form(); ?> |
66 | 66 | </div> |
@@ -20,13 +20,13 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function capability() |
|
27 | - { |
|
28 | - return ''; |
|
29 | - } |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function capability() |
|
27 | + { |
|
28 | + return ''; |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 | } |
@@ -8,9 +8,9 @@ discard block |
||
8 | 8 | * @param $class_file |
9 | 9 | * @return array |
10 | 10 | */ |
11 | -function espresso_invoice_template_files( $class_file) { |
|
11 | +function espresso_invoice_template_files($class_file) { |
|
12 | 12 | // read our template dir and build an array of files |
13 | - $dhandle = opendir(dirname($class_file) . '/lib/templates/css/'); //If the template files have been moved to the uploads folder |
|
13 | + $dhandle = opendir(dirname($class_file).'/lib/templates/css/'); //If the template files have been moved to the uploads folder |
|
14 | 14 | //} else return FALSE; |
15 | 15 | |
16 | 16 | $files = array(); |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * @param string $selected |
51 | 51 | * @return string |
52 | 52 | */ |
53 | -function espresso_invoice_is_selected( $input_item, $selected='') { |
|
54 | - if ( $input_item === $selected ) { |
|
53 | +function espresso_invoice_is_selected($input_item, $selected = '') { |
|
54 | + if ($input_item === $selected) { |
|
55 | 55 | return 'selected="selected"'; |
56 | 56 | } else { |
57 | 57 | return ''; |
@@ -418,7 +418,7 @@ |
||
418 | 418 | * In this case, we delete the temporary file |
419 | 419 | * |
420 | 420 | * @param JobParameters $job_parameters |
421 | - * @return boolean |
|
421 | + * @return JobStepResponse |
|
422 | 422 | */ |
423 | 423 | public function cleanup_job(JobParameters $job_parameters) |
424 | 424 | { |
@@ -31,524 +31,524 @@ |
||
31 | 31 | */ |
32 | 32 | class RegistrationsReport extends JobHandlerFile |
33 | 33 | { |
34 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
36 | - /** |
|
37 | - * Performs any necessary setup for starting the job. This is also a good |
|
38 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
39 | - * when continue_job will be called |
|
40 | - * |
|
41 | - * @param JobParameters $job_parameters |
|
42 | - * @throws BatchRequestException |
|
43 | - * @return JobStepResponse |
|
44 | - */ |
|
45 | - public function create_job(JobParameters $job_parameters) |
|
46 | - { |
|
47 | - $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
48 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | - throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
50 | - } |
|
51 | - $filepath = $this->create_file_from_job_with_name( |
|
52 | - $job_parameters->job_id(), |
|
53 | - $this->get_filename($event_id) |
|
54 | - ); |
|
55 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
56 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
57 | - $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
58 | - } else { |
|
59 | - $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
60 | - array( |
|
61 | - 'OR' => array( |
|
62 | - // don't include registrations from failed or abandoned transactions... |
|
63 | - 'Transaction.STS_ID' => array( |
|
64 | - 'NOT IN', |
|
65 | - array( |
|
66 | - EEM_Transaction::failed_status_code, |
|
67 | - EEM_Transaction::abandoned_status_code, |
|
68 | - ), |
|
69 | - ), |
|
70 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
71 | - 'STS_ID' => \EEM_Registration::status_id_approved, |
|
72 | - ), |
|
73 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
74 | - ), |
|
75 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
76 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
77 | - 'caps' => \EEM_Base::caps_read_admin, |
|
78 | - ), $event_id); |
|
79 | - if ($event_id) { |
|
80 | - $query_params[0]['EVT_ID'] = $event_id; |
|
81 | - } else { |
|
82 | - $query_params['force_join'][] = 'Event'; |
|
83 | - } |
|
84 | - } |
|
85 | - if (! isset($query_params['force_join'])) { |
|
86 | - $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
87 | - } |
|
88 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
89 | - $question_labels = $this->_get_question_labels($query_params); |
|
90 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
91 | - $job_parameters->set_job_size( |
|
92 | - \EEM_Registration::instance()->count( |
|
93 | - array_diff_key( |
|
94 | - $query_params, |
|
95 | - array_flip( |
|
96 | - array('limit') |
|
97 | - ) |
|
98 | - ) |
|
99 | - ) |
|
100 | - ); |
|
101 | - // we should also set the header columns |
|
102 | - $csv_data_for_row = $this->get_csv_data_for( |
|
103 | - $event_id, |
|
104 | - 0, |
|
105 | - 1, |
|
106 | - $job_parameters->extra_datum('question_labels'), |
|
107 | - $job_parameters->extra_datum('query_params') |
|
108 | - ); |
|
109 | - EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
110 | - // if we actually processed a row there, record it |
|
111 | - if ($job_parameters->job_size()) { |
|
112 | - $job_parameters->mark_processed(1); |
|
113 | - } |
|
114 | - return new JobStepResponse( |
|
115 | - $job_parameters, |
|
116 | - __('Registrations report started successfully...', 'event_espresso') |
|
117 | - ); |
|
118 | - } |
|
34 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
36 | + /** |
|
37 | + * Performs any necessary setup for starting the job. This is also a good |
|
38 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
39 | + * when continue_job will be called |
|
40 | + * |
|
41 | + * @param JobParameters $job_parameters |
|
42 | + * @throws BatchRequestException |
|
43 | + * @return JobStepResponse |
|
44 | + */ |
|
45 | + public function create_job(JobParameters $job_parameters) |
|
46 | + { |
|
47 | + $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
48 | + if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | + throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
50 | + } |
|
51 | + $filepath = $this->create_file_from_job_with_name( |
|
52 | + $job_parameters->job_id(), |
|
53 | + $this->get_filename($event_id) |
|
54 | + ); |
|
55 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
56 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
57 | + $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
58 | + } else { |
|
59 | + $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
60 | + array( |
|
61 | + 'OR' => array( |
|
62 | + // don't include registrations from failed or abandoned transactions... |
|
63 | + 'Transaction.STS_ID' => array( |
|
64 | + 'NOT IN', |
|
65 | + array( |
|
66 | + EEM_Transaction::failed_status_code, |
|
67 | + EEM_Transaction::abandoned_status_code, |
|
68 | + ), |
|
69 | + ), |
|
70 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
71 | + 'STS_ID' => \EEM_Registration::status_id_approved, |
|
72 | + ), |
|
73 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
74 | + ), |
|
75 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
76 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
77 | + 'caps' => \EEM_Base::caps_read_admin, |
|
78 | + ), $event_id); |
|
79 | + if ($event_id) { |
|
80 | + $query_params[0]['EVT_ID'] = $event_id; |
|
81 | + } else { |
|
82 | + $query_params['force_join'][] = 'Event'; |
|
83 | + } |
|
84 | + } |
|
85 | + if (! isset($query_params['force_join'])) { |
|
86 | + $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
87 | + } |
|
88 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
89 | + $question_labels = $this->_get_question_labels($query_params); |
|
90 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
91 | + $job_parameters->set_job_size( |
|
92 | + \EEM_Registration::instance()->count( |
|
93 | + array_diff_key( |
|
94 | + $query_params, |
|
95 | + array_flip( |
|
96 | + array('limit') |
|
97 | + ) |
|
98 | + ) |
|
99 | + ) |
|
100 | + ); |
|
101 | + // we should also set the header columns |
|
102 | + $csv_data_for_row = $this->get_csv_data_for( |
|
103 | + $event_id, |
|
104 | + 0, |
|
105 | + 1, |
|
106 | + $job_parameters->extra_datum('question_labels'), |
|
107 | + $job_parameters->extra_datum('query_params') |
|
108 | + ); |
|
109 | + EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
110 | + // if we actually processed a row there, record it |
|
111 | + if ($job_parameters->job_size()) { |
|
112 | + $job_parameters->mark_processed(1); |
|
113 | + } |
|
114 | + return new JobStepResponse( |
|
115 | + $job_parameters, |
|
116 | + __('Registrations report started successfully...', 'event_espresso') |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * Gets the filename |
|
123 | - * |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - protected function get_filename() |
|
127 | - { |
|
128 | - return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
129 | - } |
|
121 | + /** |
|
122 | + * Gets the filename |
|
123 | + * |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + protected function get_filename() |
|
127 | + { |
|
128 | + return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * Gets the questions which are to be used for this report, so they |
|
134 | - * can be remembered for later |
|
135 | - * |
|
136 | - * @param array $registration_query_params |
|
137 | - * @return array question admin labels to be used for this report |
|
138 | - */ |
|
139 | - protected function _get_question_labels($registration_query_params) |
|
140 | - { |
|
141 | - $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
142 | - $question_query_params = array(); |
|
143 | - if ($where !== null) { |
|
144 | - $question_query_params = array( |
|
145 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
146 | - ); |
|
147 | - } |
|
148 | - $question_query_params[0]['QST_system'] = array( |
|
149 | - 'NOT_IN', |
|
150 | - array_keys(EEM_Attendee::instance()->system_question_to_attendee_field_mapping()), |
|
151 | - ); |
|
152 | - if (apply_filters( |
|
153 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
154 | - false, |
|
155 | - $registration_query_params |
|
156 | - )) { |
|
157 | - $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
158 | - } |
|
159 | - $question_query_params['group_by'] = array('QST_ID'); |
|
160 | - return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
161 | - } |
|
132 | + /** |
|
133 | + * Gets the questions which are to be used for this report, so they |
|
134 | + * can be remembered for later |
|
135 | + * |
|
136 | + * @param array $registration_query_params |
|
137 | + * @return array question admin labels to be used for this report |
|
138 | + */ |
|
139 | + protected function _get_question_labels($registration_query_params) |
|
140 | + { |
|
141 | + $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
142 | + $question_query_params = array(); |
|
143 | + if ($where !== null) { |
|
144 | + $question_query_params = array( |
|
145 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
146 | + ); |
|
147 | + } |
|
148 | + $question_query_params[0]['QST_system'] = array( |
|
149 | + 'NOT_IN', |
|
150 | + array_keys(EEM_Attendee::instance()->system_question_to_attendee_field_mapping()), |
|
151 | + ); |
|
152 | + if (apply_filters( |
|
153 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
154 | + false, |
|
155 | + $registration_query_params |
|
156 | + )) { |
|
157 | + $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
158 | + } |
|
159 | + $question_query_params['group_by'] = array('QST_ID'); |
|
160 | + return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * Takes where params meant for registrations and changes them to work for questions |
|
166 | - * |
|
167 | - * @param array $reg_where_params |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
171 | - { |
|
172 | - $question_where_params = array(); |
|
173 | - foreach ($reg_where_params as $key => $val) { |
|
174 | - if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
175 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
176 | - } else { |
|
177 | - // it's a normal where condition |
|
178 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
179 | - } |
|
180 | - } |
|
181 | - return $question_where_params; |
|
182 | - } |
|
164 | + /** |
|
165 | + * Takes where params meant for registrations and changes them to work for questions |
|
166 | + * |
|
167 | + * @param array $reg_where_params |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
171 | + { |
|
172 | + $question_where_params = array(); |
|
173 | + foreach ($reg_where_params as $key => $val) { |
|
174 | + if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
175 | + $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
176 | + } else { |
|
177 | + // it's a normal where condition |
|
178 | + $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
179 | + } |
|
180 | + } |
|
181 | + return $question_where_params; |
|
182 | + } |
|
183 | 183 | |
184 | 184 | |
185 | - /** |
|
186 | - * Performs another step of the job |
|
187 | - * |
|
188 | - * @param JobParameters $job_parameters |
|
189 | - * @param int $batch_size |
|
190 | - * @return JobStepResponse |
|
191 | - * @throws \EE_Error |
|
192 | - */ |
|
193 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
194 | - { |
|
195 | - if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
196 | - $csv_data = $this->get_csv_data_for( |
|
197 | - $job_parameters->request_datum('EVT_ID', '0'), |
|
198 | - $job_parameters->units_processed(), |
|
199 | - $batch_size, |
|
200 | - $job_parameters->extra_datum('question_labels'), |
|
201 | - $job_parameters->extra_datum('query_params') |
|
202 | - ); |
|
203 | - EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
204 | - $units_processed = count($csv_data); |
|
205 | - } else { |
|
206 | - $csv_data = array(); |
|
207 | - $units_processed = 0; |
|
208 | - } |
|
209 | - $job_parameters->mark_processed($units_processed); |
|
210 | - $extra_response_data = array( |
|
211 | - 'file_url' => '', |
|
212 | - ); |
|
213 | - if ($units_processed < $batch_size) { |
|
214 | - $job_parameters->set_status(JobParameters::status_complete); |
|
215 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
216 | - } |
|
185 | + /** |
|
186 | + * Performs another step of the job |
|
187 | + * |
|
188 | + * @param JobParameters $job_parameters |
|
189 | + * @param int $batch_size |
|
190 | + * @return JobStepResponse |
|
191 | + * @throws \EE_Error |
|
192 | + */ |
|
193 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
194 | + { |
|
195 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
196 | + $csv_data = $this->get_csv_data_for( |
|
197 | + $job_parameters->request_datum('EVT_ID', '0'), |
|
198 | + $job_parameters->units_processed(), |
|
199 | + $batch_size, |
|
200 | + $job_parameters->extra_datum('question_labels'), |
|
201 | + $job_parameters->extra_datum('query_params') |
|
202 | + ); |
|
203 | + EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
204 | + $units_processed = count($csv_data); |
|
205 | + } else { |
|
206 | + $csv_data = array(); |
|
207 | + $units_processed = 0; |
|
208 | + } |
|
209 | + $job_parameters->mark_processed($units_processed); |
|
210 | + $extra_response_data = array( |
|
211 | + 'file_url' => '', |
|
212 | + ); |
|
213 | + if ($units_processed < $batch_size) { |
|
214 | + $job_parameters->set_status(JobParameters::status_complete); |
|
215 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
216 | + } |
|
217 | 217 | |
218 | - return new JobStepResponse( |
|
219 | - $job_parameters, |
|
220 | - sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
221 | - $extra_response_data |
|
222 | - ); |
|
223 | - } |
|
218 | + return new JobStepResponse( |
|
219 | + $job_parameters, |
|
220 | + sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
221 | + $extra_response_data |
|
222 | + ); |
|
223 | + } |
|
224 | 224 | |
225 | 225 | |
226 | - /** |
|
227 | - * Gets the csv data for a batch of registrations |
|
228 | - * |
|
229 | - * @param int|null $event_id |
|
230 | - * @param int $offset |
|
231 | - * @param int $limit |
|
232 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
233 | - * @param array $query_params for using where querying the model |
|
234 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
235 | - * @throws \EE_Error |
|
236 | - */ |
|
237 | - public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
238 | - { |
|
239 | - $reg_fields_to_include = array( |
|
240 | - 'TXN_ID', |
|
241 | - 'ATT_ID', |
|
242 | - 'REG_ID', |
|
243 | - 'REG_date', |
|
244 | - 'REG_code', |
|
245 | - 'REG_count', |
|
246 | - 'REG_final_price', |
|
247 | - ); |
|
248 | - $att_fields_to_include = array( |
|
249 | - 'ATT_fname', |
|
250 | - 'ATT_lname', |
|
251 | - 'ATT_email', |
|
252 | - 'ATT_address', |
|
253 | - 'ATT_address2', |
|
254 | - 'ATT_city', |
|
255 | - 'STA_ID', |
|
256 | - 'CNT_ISO', |
|
257 | - 'ATT_zip', |
|
258 | - 'ATT_phone', |
|
259 | - ); |
|
260 | - $registrations_csv_ready_array = array(); |
|
261 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
262 | - $query_params['limit'] = array($offset, $limit); |
|
263 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
264 | - $registration_ids = array(); |
|
265 | - foreach ($registration_rows as $reg_row) { |
|
266 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
267 | - } |
|
268 | - foreach ($registration_rows as $reg_row) { |
|
269 | - if (is_array($reg_row)) { |
|
270 | - $reg_csv_array = array(); |
|
271 | - if (! $event_id) { |
|
272 | - // get the event's name and Id |
|
273 | - $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
274 | - /* translators: 1: event name, 2: event ID */ |
|
275 | - __('%1$s (%2$s)', 'event_espresso'), |
|
276 | - EEH_Export::prepare_value_from_db_for_display( |
|
277 | - EEM_Event::instance(), |
|
278 | - 'EVT_name', |
|
279 | - $reg_row['Event_CPT.post_title'] |
|
280 | - ), |
|
281 | - $reg_row['Event_CPT.ID'] |
|
282 | - ); |
|
283 | - } |
|
284 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
285 | - /*@var $reg_row EE_Registration */ |
|
286 | - foreach ($reg_fields_to_include as $field_name) { |
|
287 | - $field = $reg_model->field_settings_for($field_name); |
|
288 | - if ($field_name == 'REG_final_price') { |
|
289 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
290 | - $reg_model, |
|
291 | - $field_name, |
|
292 | - $reg_row['Registration.REG_final_price'], |
|
293 | - 'localized_float' |
|
294 | - ); |
|
295 | - } elseif ($field_name == 'REG_count') { |
|
296 | - $value = sprintf( |
|
297 | - /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
298 | - __('%1$s of %2$s', 'event_espresso'), |
|
299 | - EEH_Export::prepare_value_from_db_for_display( |
|
300 | - $reg_model, |
|
301 | - 'REG_count', |
|
302 | - $reg_row['Registration.REG_count'] |
|
303 | - ), |
|
304 | - EEH_Export::prepare_value_from_db_for_display( |
|
305 | - $reg_model, |
|
306 | - 'REG_group_size', |
|
307 | - $reg_row['Registration.REG_group_size'] |
|
308 | - ) |
|
309 | - ); |
|
310 | - } elseif ($field_name == 'REG_date') { |
|
311 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
312 | - $reg_model, |
|
313 | - $field_name, |
|
314 | - $reg_row['Registration.REG_date'], |
|
315 | - 'no_html' |
|
316 | - ); |
|
317 | - } else { |
|
318 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
319 | - $reg_model, |
|
320 | - $field_name, |
|
321 | - $reg_row[ $field->get_qualified_column() ] |
|
322 | - ); |
|
323 | - } |
|
324 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
325 | - if ($field_name == 'REG_final_price') { |
|
326 | - // add a column named Currency after the final price |
|
327 | - $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
328 | - } |
|
329 | - } |
|
330 | - // get pretty status |
|
331 | - $stati = EEM_Status::instance()->localized_status( |
|
332 | - array( |
|
333 | - $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
334 | - $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
335 | - ), |
|
336 | - false, |
|
337 | - 'sentence' |
|
338 | - ); |
|
339 | - $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
340 | - // get pretty transaction status |
|
341 | - $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
342 | - $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
343 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
344 | - EEM_Transaction::instance(), |
|
345 | - 'TXN_total', |
|
346 | - $reg_row['TransactionTable.TXN_total'], |
|
347 | - 'localized_float' |
|
348 | - ) : '0.00'; |
|
349 | - $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
350 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
351 | - EEM_Transaction::instance(), |
|
352 | - 'TXN_paid', |
|
353 | - $reg_row['TransactionTable.TXN_paid'], |
|
354 | - 'localized_float' |
|
355 | - ) : '0.00'; |
|
356 | - $payment_methods = array(); |
|
357 | - $gateway_txn_ids_etc = array(); |
|
358 | - $payment_times = array(); |
|
359 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
360 | - $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
361 | - array( |
|
362 | - array( |
|
363 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
364 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
365 | - ), |
|
366 | - 'force_join' => array('Payment_Method'), |
|
367 | - ), |
|
368 | - ARRAY_A, |
|
369 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
370 | - ); |
|
371 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
372 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
373 | - ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
374 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
375 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
376 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
377 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
378 | - } |
|
379 | - } |
|
380 | - $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
381 | - $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
382 | - $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
383 | - ',', |
|
384 | - $gateway_txn_ids_etc |
|
385 | - ); |
|
386 | - // get whether or not the user has checked in |
|
387 | - $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
388 | - $reg_row['Registration.REG_ID'], |
|
389 | - 'Checkin' |
|
390 | - ); |
|
391 | - // get ticket of registration and its price |
|
392 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
393 | - if ($reg_row['Ticket.TKT_ID']) { |
|
394 | - $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
395 | - $ticket_model, |
|
396 | - 'TKT_name', |
|
397 | - $reg_row['Ticket.TKT_name'] |
|
398 | - ); |
|
399 | - $datetimes_strings = array(); |
|
400 | - foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
401 | - array( |
|
402 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
403 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
404 | - 'default_where_conditions' => 'none', |
|
405 | - ) |
|
406 | - ) as $datetime) { |
|
407 | - $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
408 | - EEM_Datetime::instance(), |
|
409 | - 'DTT_EVT_start', |
|
410 | - $datetime['Datetime.DTT_EVT_start'] |
|
411 | - ); |
|
412 | - } |
|
413 | - } else { |
|
414 | - $ticket_name = __('Unknown', 'event_espresso'); |
|
415 | - $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
416 | - } |
|
417 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
418 | - $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
419 | - // get datetime(s) of registration |
|
420 | - // add attendee columns |
|
421 | - foreach ($att_fields_to_include as $att_field_name) { |
|
422 | - $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
423 | - if ($reg_row['Attendee_CPT.ID']) { |
|
424 | - if ($att_field_name == 'STA_ID') { |
|
425 | - $value = EEM_State::instance()->get_var( |
|
426 | - array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
427 | - 'STA_name' |
|
428 | - ); |
|
429 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
430 | - $value = EEM_Country::instance()->get_var( |
|
431 | - array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
432 | - 'CNT_name' |
|
433 | - ); |
|
434 | - } else { |
|
435 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
436 | - EEM_Attendee::instance(), |
|
437 | - $att_field_name, |
|
438 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
439 | - ); |
|
440 | - } |
|
441 | - } else { |
|
442 | - $value = ''; |
|
443 | - } |
|
444 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
445 | - } |
|
446 | - // make sure each registration has the same questions in the same order |
|
447 | - foreach ($question_labels as $question_label) { |
|
448 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
449 | - $reg_csv_array[ $question_label ] = null; |
|
450 | - } |
|
451 | - } |
|
452 | - $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
453 | - array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
454 | - 'force_join' => array('Question'), |
|
455 | - )); |
|
456 | - // now fill out the questions THEY answered |
|
457 | - foreach ($answers as $answer_row) { |
|
458 | - if ($answer_row['Question.QST_ID']) { |
|
459 | - $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
460 | - EEM_Question::instance(), |
|
461 | - 'QST_admin_label', |
|
462 | - $answer_row['Question.QST_admin_label'] |
|
463 | - ); |
|
464 | - } else { |
|
465 | - $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
466 | - } |
|
467 | - if (isset($answer_row['Question.QST_type']) |
|
468 | - && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
469 | - ) { |
|
470 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
471 | - $answer_row['Answer.ANS_value'] |
|
472 | - ); |
|
473 | - } else { |
|
474 | - // this isn't for html, so don't show html entities |
|
475 | - $reg_csv_array[ $question_label ] = html_entity_decode( |
|
476 | - EEH_Export::prepare_value_from_db_for_display( |
|
477 | - EEM_Answer::instance(), |
|
478 | - 'ANS_value', |
|
479 | - $answer_row['Answer.ANS_value'] |
|
480 | - ) |
|
481 | - ); |
|
482 | - } |
|
483 | - } |
|
226 | + /** |
|
227 | + * Gets the csv data for a batch of registrations |
|
228 | + * |
|
229 | + * @param int|null $event_id |
|
230 | + * @param int $offset |
|
231 | + * @param int $limit |
|
232 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
233 | + * @param array $query_params for using where querying the model |
|
234 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
235 | + * @throws \EE_Error |
|
236 | + */ |
|
237 | + public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
238 | + { |
|
239 | + $reg_fields_to_include = array( |
|
240 | + 'TXN_ID', |
|
241 | + 'ATT_ID', |
|
242 | + 'REG_ID', |
|
243 | + 'REG_date', |
|
244 | + 'REG_code', |
|
245 | + 'REG_count', |
|
246 | + 'REG_final_price', |
|
247 | + ); |
|
248 | + $att_fields_to_include = array( |
|
249 | + 'ATT_fname', |
|
250 | + 'ATT_lname', |
|
251 | + 'ATT_email', |
|
252 | + 'ATT_address', |
|
253 | + 'ATT_address2', |
|
254 | + 'ATT_city', |
|
255 | + 'STA_ID', |
|
256 | + 'CNT_ISO', |
|
257 | + 'ATT_zip', |
|
258 | + 'ATT_phone', |
|
259 | + ); |
|
260 | + $registrations_csv_ready_array = array(); |
|
261 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
262 | + $query_params['limit'] = array($offset, $limit); |
|
263 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
264 | + $registration_ids = array(); |
|
265 | + foreach ($registration_rows as $reg_row) { |
|
266 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
267 | + } |
|
268 | + foreach ($registration_rows as $reg_row) { |
|
269 | + if (is_array($reg_row)) { |
|
270 | + $reg_csv_array = array(); |
|
271 | + if (! $event_id) { |
|
272 | + // get the event's name and Id |
|
273 | + $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
274 | + /* translators: 1: event name, 2: event ID */ |
|
275 | + __('%1$s (%2$s)', 'event_espresso'), |
|
276 | + EEH_Export::prepare_value_from_db_for_display( |
|
277 | + EEM_Event::instance(), |
|
278 | + 'EVT_name', |
|
279 | + $reg_row['Event_CPT.post_title'] |
|
280 | + ), |
|
281 | + $reg_row['Event_CPT.ID'] |
|
282 | + ); |
|
283 | + } |
|
284 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
285 | + /*@var $reg_row EE_Registration */ |
|
286 | + foreach ($reg_fields_to_include as $field_name) { |
|
287 | + $field = $reg_model->field_settings_for($field_name); |
|
288 | + if ($field_name == 'REG_final_price') { |
|
289 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
290 | + $reg_model, |
|
291 | + $field_name, |
|
292 | + $reg_row['Registration.REG_final_price'], |
|
293 | + 'localized_float' |
|
294 | + ); |
|
295 | + } elseif ($field_name == 'REG_count') { |
|
296 | + $value = sprintf( |
|
297 | + /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
298 | + __('%1$s of %2$s', 'event_espresso'), |
|
299 | + EEH_Export::prepare_value_from_db_for_display( |
|
300 | + $reg_model, |
|
301 | + 'REG_count', |
|
302 | + $reg_row['Registration.REG_count'] |
|
303 | + ), |
|
304 | + EEH_Export::prepare_value_from_db_for_display( |
|
305 | + $reg_model, |
|
306 | + 'REG_group_size', |
|
307 | + $reg_row['Registration.REG_group_size'] |
|
308 | + ) |
|
309 | + ); |
|
310 | + } elseif ($field_name == 'REG_date') { |
|
311 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
312 | + $reg_model, |
|
313 | + $field_name, |
|
314 | + $reg_row['Registration.REG_date'], |
|
315 | + 'no_html' |
|
316 | + ); |
|
317 | + } else { |
|
318 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
319 | + $reg_model, |
|
320 | + $field_name, |
|
321 | + $reg_row[ $field->get_qualified_column() ] |
|
322 | + ); |
|
323 | + } |
|
324 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
325 | + if ($field_name == 'REG_final_price') { |
|
326 | + // add a column named Currency after the final price |
|
327 | + $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
328 | + } |
|
329 | + } |
|
330 | + // get pretty status |
|
331 | + $stati = EEM_Status::instance()->localized_status( |
|
332 | + array( |
|
333 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
334 | + $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
335 | + ), |
|
336 | + false, |
|
337 | + 'sentence' |
|
338 | + ); |
|
339 | + $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
340 | + // get pretty transaction status |
|
341 | + $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
342 | + $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
343 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
344 | + EEM_Transaction::instance(), |
|
345 | + 'TXN_total', |
|
346 | + $reg_row['TransactionTable.TXN_total'], |
|
347 | + 'localized_float' |
|
348 | + ) : '0.00'; |
|
349 | + $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
350 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
351 | + EEM_Transaction::instance(), |
|
352 | + 'TXN_paid', |
|
353 | + $reg_row['TransactionTable.TXN_paid'], |
|
354 | + 'localized_float' |
|
355 | + ) : '0.00'; |
|
356 | + $payment_methods = array(); |
|
357 | + $gateway_txn_ids_etc = array(); |
|
358 | + $payment_times = array(); |
|
359 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
360 | + $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
361 | + array( |
|
362 | + array( |
|
363 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
364 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
365 | + ), |
|
366 | + 'force_join' => array('Payment_Method'), |
|
367 | + ), |
|
368 | + ARRAY_A, |
|
369 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
370 | + ); |
|
371 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
372 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
373 | + ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
374 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
375 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
376 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
377 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
378 | + } |
|
379 | + } |
|
380 | + $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
381 | + $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
382 | + $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
383 | + ',', |
|
384 | + $gateway_txn_ids_etc |
|
385 | + ); |
|
386 | + // get whether or not the user has checked in |
|
387 | + $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
388 | + $reg_row['Registration.REG_ID'], |
|
389 | + 'Checkin' |
|
390 | + ); |
|
391 | + // get ticket of registration and its price |
|
392 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
393 | + if ($reg_row['Ticket.TKT_ID']) { |
|
394 | + $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
395 | + $ticket_model, |
|
396 | + 'TKT_name', |
|
397 | + $reg_row['Ticket.TKT_name'] |
|
398 | + ); |
|
399 | + $datetimes_strings = array(); |
|
400 | + foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
401 | + array( |
|
402 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
403 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
404 | + 'default_where_conditions' => 'none', |
|
405 | + ) |
|
406 | + ) as $datetime) { |
|
407 | + $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
408 | + EEM_Datetime::instance(), |
|
409 | + 'DTT_EVT_start', |
|
410 | + $datetime['Datetime.DTT_EVT_start'] |
|
411 | + ); |
|
412 | + } |
|
413 | + } else { |
|
414 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
415 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
416 | + } |
|
417 | + $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
418 | + $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
419 | + // get datetime(s) of registration |
|
420 | + // add attendee columns |
|
421 | + foreach ($att_fields_to_include as $att_field_name) { |
|
422 | + $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
423 | + if ($reg_row['Attendee_CPT.ID']) { |
|
424 | + if ($att_field_name == 'STA_ID') { |
|
425 | + $value = EEM_State::instance()->get_var( |
|
426 | + array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
427 | + 'STA_name' |
|
428 | + ); |
|
429 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
430 | + $value = EEM_Country::instance()->get_var( |
|
431 | + array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
432 | + 'CNT_name' |
|
433 | + ); |
|
434 | + } else { |
|
435 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
436 | + EEM_Attendee::instance(), |
|
437 | + $att_field_name, |
|
438 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
439 | + ); |
|
440 | + } |
|
441 | + } else { |
|
442 | + $value = ''; |
|
443 | + } |
|
444 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
445 | + } |
|
446 | + // make sure each registration has the same questions in the same order |
|
447 | + foreach ($question_labels as $question_label) { |
|
448 | + if (! isset($reg_csv_array[ $question_label ])) { |
|
449 | + $reg_csv_array[ $question_label ] = null; |
|
450 | + } |
|
451 | + } |
|
452 | + $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
453 | + array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
454 | + 'force_join' => array('Question'), |
|
455 | + )); |
|
456 | + // now fill out the questions THEY answered |
|
457 | + foreach ($answers as $answer_row) { |
|
458 | + if ($answer_row['Question.QST_ID']) { |
|
459 | + $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
460 | + EEM_Question::instance(), |
|
461 | + 'QST_admin_label', |
|
462 | + $answer_row['Question.QST_admin_label'] |
|
463 | + ); |
|
464 | + } else { |
|
465 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
466 | + } |
|
467 | + if (isset($answer_row['Question.QST_type']) |
|
468 | + && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
469 | + ) { |
|
470 | + $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
471 | + $answer_row['Answer.ANS_value'] |
|
472 | + ); |
|
473 | + } else { |
|
474 | + // this isn't for html, so don't show html entities |
|
475 | + $reg_csv_array[ $question_label ] = html_entity_decode( |
|
476 | + EEH_Export::prepare_value_from_db_for_display( |
|
477 | + EEM_Answer::instance(), |
|
478 | + 'ANS_value', |
|
479 | + $answer_row['Answer.ANS_value'] |
|
480 | + ) |
|
481 | + ); |
|
482 | + } |
|
483 | + } |
|
484 | 484 | |
485 | - /** |
|
486 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
487 | - * This can be used to add or remote columns from the CSV file, or change their values. |
|
488 | - * Note when using: all rows in the CSV should have the same columns. |
|
489 | - * @param array $reg_csv_array keys are the column names, values are their cell values |
|
490 | - * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
491 | - */ |
|
492 | - $registrations_csv_ready_array[] = apply_filters( |
|
493 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
494 | - $reg_csv_array, |
|
495 | - $reg_row |
|
496 | - ); |
|
497 | - } |
|
498 | - } |
|
499 | - // if we couldn't export anything, we want to at least show the column headers |
|
500 | - if (empty($registrations_csv_ready_array)) { |
|
501 | - $reg_csv_array = array(); |
|
502 | - $model_and_fields_to_include = array( |
|
503 | - 'Registration' => $reg_fields_to_include, |
|
504 | - 'Attendee' => $att_fields_to_include, |
|
505 | - ); |
|
506 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
507 | - $model = EE_Registry::instance()->load_model($model_name); |
|
508 | - foreach ($field_list as $field_name) { |
|
509 | - $field = $model->field_settings_for($field_name); |
|
510 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
511 | - } |
|
512 | - } |
|
513 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
514 | - } |
|
515 | - return $registrations_csv_ready_array; |
|
516 | - } |
|
485 | + /** |
|
486 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
487 | + * This can be used to add or remote columns from the CSV file, or change their values. |
|
488 | + * Note when using: all rows in the CSV should have the same columns. |
|
489 | + * @param array $reg_csv_array keys are the column names, values are their cell values |
|
490 | + * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
491 | + */ |
|
492 | + $registrations_csv_ready_array[] = apply_filters( |
|
493 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
494 | + $reg_csv_array, |
|
495 | + $reg_row |
|
496 | + ); |
|
497 | + } |
|
498 | + } |
|
499 | + // if we couldn't export anything, we want to at least show the column headers |
|
500 | + if (empty($registrations_csv_ready_array)) { |
|
501 | + $reg_csv_array = array(); |
|
502 | + $model_and_fields_to_include = array( |
|
503 | + 'Registration' => $reg_fields_to_include, |
|
504 | + 'Attendee' => $att_fields_to_include, |
|
505 | + ); |
|
506 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
507 | + $model = EE_Registry::instance()->load_model($model_name); |
|
508 | + foreach ($field_list as $field_name) { |
|
509 | + $field = $model->field_settings_for($field_name); |
|
510 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
511 | + } |
|
512 | + } |
|
513 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
514 | + } |
|
515 | + return $registrations_csv_ready_array; |
|
516 | + } |
|
517 | 517 | |
518 | 518 | |
519 | - /** |
|
520 | - * Counts total unit to process |
|
521 | - * |
|
522 | - * @deprecated since 4.9.19 |
|
523 | - * @param int|array $event_id |
|
524 | - * @return int |
|
525 | - */ |
|
526 | - public function count_units_to_process($event_id) |
|
527 | - { |
|
528 | - // use the legacy filter |
|
529 | - if ($event_id) { |
|
530 | - $query_params[0]['EVT_ID'] = $event_id; |
|
531 | - } else { |
|
532 | - $query_params['force_join'][] = 'Event'; |
|
533 | - } |
|
534 | - return \EEM_Registration::instance()->count($query_params); |
|
535 | - } |
|
519 | + /** |
|
520 | + * Counts total unit to process |
|
521 | + * |
|
522 | + * @deprecated since 4.9.19 |
|
523 | + * @param int|array $event_id |
|
524 | + * @return int |
|
525 | + */ |
|
526 | + public function count_units_to_process($event_id) |
|
527 | + { |
|
528 | + // use the legacy filter |
|
529 | + if ($event_id) { |
|
530 | + $query_params[0]['EVT_ID'] = $event_id; |
|
531 | + } else { |
|
532 | + $query_params['force_join'][] = 'Event'; |
|
533 | + } |
|
534 | + return \EEM_Registration::instance()->count($query_params); |
|
535 | + } |
|
536 | 536 | |
537 | 537 | |
538 | - /** |
|
539 | - * Performs any clean-up logic when we know the job is completed. |
|
540 | - * In this case, we delete the temporary file |
|
541 | - * |
|
542 | - * @param JobParameters $job_parameters |
|
543 | - * @return boolean |
|
544 | - */ |
|
545 | - public function cleanup_job(JobParameters $job_parameters) |
|
546 | - { |
|
547 | - $this->_file_helper->delete( |
|
548 | - \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
549 | - true, |
|
550 | - 'd' |
|
551 | - ); |
|
552 | - return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
553 | - } |
|
538 | + /** |
|
539 | + * Performs any clean-up logic when we know the job is completed. |
|
540 | + * In this case, we delete the temporary file |
|
541 | + * |
|
542 | + * @param JobParameters $job_parameters |
|
543 | + * @return boolean |
|
544 | + */ |
|
545 | + public function cleanup_job(JobParameters $job_parameters) |
|
546 | + { |
|
547 | + $this->_file_helper->delete( |
|
548 | + \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
549 | + true, |
|
550 | + 'd' |
|
551 | + ); |
|
552 | + return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
553 | + } |
|
554 | 554 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public function create_job(JobParameters $job_parameters) |
46 | 46 | { |
47 | 47 | $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
48 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
48 | + if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | 49 | throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
50 | 50 | } |
51 | 51 | $filepath = $this->create_file_from_job_with_name( |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $query_params['force_join'][] = 'Event'; |
83 | 83 | } |
84 | 84 | } |
85 | - if (! isset($query_params['force_join'])) { |
|
85 | + if ( ! isset($query_params['force_join'])) { |
|
86 | 86 | $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
87 | 87 | } |
88 | 88 | $job_parameters->add_extra_data('query_params', $query_params); |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | $question_where_params = array(); |
173 | 173 | foreach ($reg_where_params as $key => $val) { |
174 | 174 | if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
175 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
175 | + $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
|
176 | 176 | } else { |
177 | 177 | // it's a normal where condition |
178 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
178 | + $question_where_params['Question_Group.Event.Registration.'.$key] = $val; |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | return $question_where_params; |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | foreach ($registration_rows as $reg_row) { |
269 | 269 | if (is_array($reg_row)) { |
270 | 270 | $reg_csv_array = array(); |
271 | - if (! $event_id) { |
|
271 | + if ( ! $event_id) { |
|
272 | 272 | // get the event's name and Id |
273 | - $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
273 | + $reg_csv_array[(string) __('Event', 'event_espresso')] = sprintf( |
|
274 | 274 | /* translators: 1: event name, 2: event ID */ |
275 | 275 | __('%1$s (%2$s)', 'event_espresso'), |
276 | 276 | EEH_Export::prepare_value_from_db_for_display( |
@@ -318,13 +318,13 @@ discard block |
||
318 | 318 | $value = EEH_Export::prepare_value_from_db_for_display( |
319 | 319 | $reg_model, |
320 | 320 | $field_name, |
321 | - $reg_row[ $field->get_qualified_column() ] |
|
321 | + $reg_row[$field->get_qualified_column()] |
|
322 | 322 | ); |
323 | 323 | } |
324 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
324 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = $value; |
|
325 | 325 | if ($field_name == 'REG_final_price') { |
326 | 326 | // add a column named Currency after the final price |
327 | - $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
327 | + $reg_csv_array[(string) __("Currency", "event_espresso")] = \EE_Config::instance()->currency->code; |
|
328 | 328 | } |
329 | 329 | } |
330 | 330 | // get pretty status |
@@ -336,17 +336,17 @@ discard block |
||
336 | 336 | false, |
337 | 337 | 'sentence' |
338 | 338 | ); |
339 | - $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
339 | + $reg_csv_array[(string) __("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
340 | 340 | // get pretty transaction status |
341 | - $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
342 | - $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
341 | + $reg_csv_array[(string) __("Transaction Status", 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
342 | + $reg_csv_array[(string) __('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
343 | 343 | ? EEH_Export::prepare_value_from_db_for_display( |
344 | 344 | EEM_Transaction::instance(), |
345 | 345 | 'TXN_total', |
346 | 346 | $reg_row['TransactionTable.TXN_total'], |
347 | 347 | 'localized_float' |
348 | 348 | ) : '0.00'; |
349 | - $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
349 | + $reg_csv_array[(string) __('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
350 | 350 | ? EEH_Export::prepare_value_from_db_for_display( |
351 | 351 | EEM_Transaction::instance(), |
352 | 352 | 'TXN_paid', |
@@ -377,14 +377,14 @@ discard block |
||
377 | 377 | ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
378 | 378 | } |
379 | 379 | } |
380 | - $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
381 | - $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
382 | - $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
380 | + $reg_csv_array[(string) __('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
381 | + $reg_csv_array[(string) __('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
382 | + $reg_csv_array[(string) __('Gateway Transaction ID(s)', 'event_espresso')] = implode( |
|
383 | 383 | ',', |
384 | 384 | $gateway_txn_ids_etc |
385 | 385 | ); |
386 | 386 | // get whether or not the user has checked in |
387 | - $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
387 | + $reg_csv_array[(string) __("Check-Ins", "event_espresso")] = $reg_model->count_related( |
|
388 | 388 | $reg_row['Registration.REG_ID'], |
389 | 389 | 'Checkin' |
390 | 390 | ); |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | $ticket_name = __('Unknown', 'event_espresso'); |
415 | 415 | $datetimes_strings = array(__('Unknown', 'event_espresso')); |
416 | 416 | } |
417 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
418 | - $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
417 | + $reg_csv_array[(string) $ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
418 | + $reg_csv_array[(string) __("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
419 | 419 | // get datetime(s) of registration |
420 | 420 | // add attendee columns |
421 | 421 | foreach ($att_fields_to_include as $att_field_name) { |
@@ -435,18 +435,18 @@ discard block |
||
435 | 435 | $value = EEH_Export::prepare_value_from_db_for_display( |
436 | 436 | EEM_Attendee::instance(), |
437 | 437 | $att_field_name, |
438 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
438 | + $reg_row[$field_obj->get_qualified_column()] |
|
439 | 439 | ); |
440 | 440 | } |
441 | 441 | } else { |
442 | 442 | $value = ''; |
443 | 443 | } |
444 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
444 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field_obj)] = $value; |
|
445 | 445 | } |
446 | 446 | // make sure each registration has the same questions in the same order |
447 | 447 | foreach ($question_labels as $question_label) { |
448 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
449 | - $reg_csv_array[ $question_label ] = null; |
|
448 | + if ( ! isset($reg_csv_array[$question_label])) { |
|
449 | + $reg_csv_array[$question_label] = null; |
|
450 | 450 | } |
451 | 451 | } |
452 | 452 | $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
@@ -467,12 +467,12 @@ discard block |
||
467 | 467 | if (isset($answer_row['Question.QST_type']) |
468 | 468 | && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
469 | 469 | ) { |
470 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
470 | + $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID( |
|
471 | 471 | $answer_row['Answer.ANS_value'] |
472 | 472 | ); |
473 | 473 | } else { |
474 | 474 | // this isn't for html, so don't show html entities |
475 | - $reg_csv_array[ $question_label ] = html_entity_decode( |
|
475 | + $reg_csv_array[$question_label] = html_entity_decode( |
|
476 | 476 | EEH_Export::prepare_value_from_db_for_display( |
477 | 477 | EEM_Answer::instance(), |
478 | 478 | 'ANS_value', |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | $model = EE_Registry::instance()->load_model($model_name); |
508 | 508 | foreach ($field_list as $field_name) { |
509 | 509 | $field = $model->field_settings_for($field_name); |
510 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
510 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null; |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | $registrations_csv_ready_array[] = $reg_csv_array; |
@@ -227,7 +227,7 @@ |
||
227 | 227 | * _get_table_filters |
228 | 228 | * |
229 | 229 | * @access protected |
230 | - * @return array |
|
230 | + * @return string[] |
|
231 | 231 | */ |
232 | 232 | protected function _get_table_filters() |
233 | 233 | { |
@@ -1,5 +1,4 @@ |
||
1 | 1 | <?php use EventEspresso\core\exceptions\EntityNotFoundException; |
2 | - |
|
3 | 2 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
4 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
5 | 4 |
@@ -24,1046 +24,1046 @@ |
||
24 | 24 | { |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private $_status; |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private $_status; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * An array of transaction details for the related transaction to the registration being processed. |
|
35 | - * This is set via the _set_related_details method. |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $_transaction_details = array(); |
|
33 | + /** |
|
34 | + * An array of transaction details for the related transaction to the registration being processed. |
|
35 | + * This is set via the _set_related_details method. |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $_transaction_details = array(); |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * An array of event details for the related event to the registration being processed. |
|
44 | - * This is set via the _set_related_details method. |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected $_event_details = array(); |
|
42 | + /** |
|
43 | + * An array of event details for the related event to the registration being processed. |
|
44 | + * This is set via the _set_related_details method. |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected $_event_details = array(); |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @param \Registrations_Admin_Page $admin_page |
|
53 | - */ |
|
54 | - public function __construct(Registrations_Admin_Page $admin_page) |
|
55 | - { |
|
56 | - if (! empty($_GET['event_id'])) { |
|
57 | - $extra_query_args = array(); |
|
58 | - foreach ($admin_page->get_views() as $key => $view_details) { |
|
59 | - $extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']); |
|
60 | - } |
|
61 | - $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
62 | - } |
|
63 | - parent::__construct($admin_page); |
|
64 | - $this->_status = $this->_admin_page->get_registration_status_array(); |
|
65 | - } |
|
51 | + /** |
|
52 | + * @param \Registrations_Admin_Page $admin_page |
|
53 | + */ |
|
54 | + public function __construct(Registrations_Admin_Page $admin_page) |
|
55 | + { |
|
56 | + if (! empty($_GET['event_id'])) { |
|
57 | + $extra_query_args = array(); |
|
58 | + foreach ($admin_page->get_views() as $key => $view_details) { |
|
59 | + $extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']); |
|
60 | + } |
|
61 | + $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
62 | + } |
|
63 | + parent::__construct($admin_page); |
|
64 | + $this->_status = $this->_admin_page->get_registration_status_array(); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * _setup_data |
|
70 | - * |
|
71 | - * @access protected |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - protected function _setup_data() |
|
75 | - { |
|
76 | - $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
77 | - $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
78 | - } |
|
68 | + /** |
|
69 | + * _setup_data |
|
70 | + * |
|
71 | + * @access protected |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + protected function _setup_data() |
|
75 | + { |
|
76 | + $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
77 | + $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * _set_properties |
|
83 | - * |
|
84 | - * @access protected |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - protected function _set_properties() |
|
88 | - { |
|
89 | - $this->_wp_list_args = array( |
|
90 | - 'singular' => __('registration', 'event_espresso'), |
|
91 | - 'plural' => __('registrations', 'event_espresso'), |
|
92 | - 'ajax' => true, |
|
93 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
94 | - ); |
|
95 | - $ID_column_name = __('ID', 'event_espresso'); |
|
96 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
97 | - $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
98 | - $ID_column_name .= '</span> '; |
|
99 | - if (isset($_GET['event_id'])) { |
|
100 | - $this->_columns = array( |
|
101 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
102 | - '_REG_ID' => $ID_column_name, |
|
103 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
104 | - 'ATT_email' => __('Email', 'event_espresso'), |
|
105 | - '_REG_date' => __('Reg Date', 'event_espresso'), |
|
106 | - 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
107 | - '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
108 | - 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
109 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
110 | - 'actions' => __('Actions', 'event_espresso'), |
|
111 | - ); |
|
112 | - $this->_bottom_buttons = array( |
|
113 | - 'report' => array( |
|
114 | - 'route' => 'registrations_report', |
|
115 | - 'extra_request' => array( |
|
116 | - 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
117 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
118 | - ), |
|
119 | - ), |
|
120 | - ); |
|
121 | - } else { |
|
122 | - $this->_columns = array( |
|
123 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
124 | - '_REG_ID' => $ID_column_name, |
|
125 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
126 | - '_REG_date' => __('TXN Date', 'event_espresso'), |
|
127 | - 'event_name' => __('Event', 'event_espresso'), |
|
128 | - 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
129 | - '_REG_final_price' => __('Price', 'event_espresso'), |
|
130 | - '_REG_paid' => __('Paid', 'event_espresso'), |
|
131 | - 'actions' => __('Actions', 'event_espresso'), |
|
132 | - ); |
|
133 | - $this->_bottom_buttons = array( |
|
134 | - 'report_all' => array( |
|
135 | - 'route' => 'registrations_report', |
|
136 | - 'extra_request' => array( |
|
137 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
138 | - ), |
|
139 | - ), |
|
140 | - ); |
|
141 | - } |
|
142 | - $this->_bottom_buttons['report_filtered'] = array( |
|
143 | - 'route' => 'registrations_report', |
|
144 | - 'extra_request' => array( |
|
145 | - 'use_filters' => true, |
|
146 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
147 | - ), |
|
148 | - ); |
|
149 | - $filters = array_diff_key( |
|
150 | - $this->_req_data, |
|
151 | - array_flip( |
|
152 | - array( |
|
153 | - 'page', |
|
154 | - 'action', |
|
155 | - 'default_nonce', |
|
156 | - ) |
|
157 | - ) |
|
158 | - ); |
|
159 | - if (!empty($filters)) { |
|
160 | - $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters; |
|
161 | - } |
|
162 | - $this->_primary_column = '_REG_ID'; |
|
163 | - $this->_sortable_columns = array( |
|
164 | - '_REG_date' => array('_REG_date' => true), // true means its already sorted |
|
165 | - /** |
|
166 | - * Allows users to change the default sort if they wish. |
|
167 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last |
|
168 | - * name. |
|
169 | - */ |
|
170 | - 'ATT_fname' => array( |
|
171 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
172 | - true, |
|
173 | - $this, |
|
174 | - ) |
|
175 | - ? array('ATT_lname' => false) |
|
176 | - : array('ATT_fname' => false), |
|
177 | - 'event_name' => array('event_name' => false), |
|
178 | - 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
179 | - '_REG_ID' => array('_REG_ID' => false), |
|
180 | - ); |
|
181 | - $this->_hidden_columns = array(); |
|
182 | - } |
|
81 | + /** |
|
82 | + * _set_properties |
|
83 | + * |
|
84 | + * @access protected |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + protected function _set_properties() |
|
88 | + { |
|
89 | + $this->_wp_list_args = array( |
|
90 | + 'singular' => __('registration', 'event_espresso'), |
|
91 | + 'plural' => __('registrations', 'event_espresso'), |
|
92 | + 'ajax' => true, |
|
93 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
94 | + ); |
|
95 | + $ID_column_name = __('ID', 'event_espresso'); |
|
96 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
97 | + $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
98 | + $ID_column_name .= '</span> '; |
|
99 | + if (isset($_GET['event_id'])) { |
|
100 | + $this->_columns = array( |
|
101 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
102 | + '_REG_ID' => $ID_column_name, |
|
103 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
104 | + 'ATT_email' => __('Email', 'event_espresso'), |
|
105 | + '_REG_date' => __('Reg Date', 'event_espresso'), |
|
106 | + 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
107 | + '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
108 | + 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
109 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
110 | + 'actions' => __('Actions', 'event_espresso'), |
|
111 | + ); |
|
112 | + $this->_bottom_buttons = array( |
|
113 | + 'report' => array( |
|
114 | + 'route' => 'registrations_report', |
|
115 | + 'extra_request' => array( |
|
116 | + 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
117 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
118 | + ), |
|
119 | + ), |
|
120 | + ); |
|
121 | + } else { |
|
122 | + $this->_columns = array( |
|
123 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
124 | + '_REG_ID' => $ID_column_name, |
|
125 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
126 | + '_REG_date' => __('TXN Date', 'event_espresso'), |
|
127 | + 'event_name' => __('Event', 'event_espresso'), |
|
128 | + 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
129 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
130 | + '_REG_paid' => __('Paid', 'event_espresso'), |
|
131 | + 'actions' => __('Actions', 'event_espresso'), |
|
132 | + ); |
|
133 | + $this->_bottom_buttons = array( |
|
134 | + 'report_all' => array( |
|
135 | + 'route' => 'registrations_report', |
|
136 | + 'extra_request' => array( |
|
137 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
138 | + ), |
|
139 | + ), |
|
140 | + ); |
|
141 | + } |
|
142 | + $this->_bottom_buttons['report_filtered'] = array( |
|
143 | + 'route' => 'registrations_report', |
|
144 | + 'extra_request' => array( |
|
145 | + 'use_filters' => true, |
|
146 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
147 | + ), |
|
148 | + ); |
|
149 | + $filters = array_diff_key( |
|
150 | + $this->_req_data, |
|
151 | + array_flip( |
|
152 | + array( |
|
153 | + 'page', |
|
154 | + 'action', |
|
155 | + 'default_nonce', |
|
156 | + ) |
|
157 | + ) |
|
158 | + ); |
|
159 | + if (!empty($filters)) { |
|
160 | + $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters; |
|
161 | + } |
|
162 | + $this->_primary_column = '_REG_ID'; |
|
163 | + $this->_sortable_columns = array( |
|
164 | + '_REG_date' => array('_REG_date' => true), // true means its already sorted |
|
165 | + /** |
|
166 | + * Allows users to change the default sort if they wish. |
|
167 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last |
|
168 | + * name. |
|
169 | + */ |
|
170 | + 'ATT_fname' => array( |
|
171 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
172 | + true, |
|
173 | + $this, |
|
174 | + ) |
|
175 | + ? array('ATT_lname' => false) |
|
176 | + : array('ATT_fname' => false), |
|
177 | + 'event_name' => array('event_name' => false), |
|
178 | + 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
179 | + '_REG_ID' => array('_REG_ID' => false), |
|
180 | + ); |
|
181 | + $this->_hidden_columns = array(); |
|
182 | + } |
|
183 | 183 | |
184 | 184 | |
185 | - /** |
|
186 | - * This simply sets up the row class for the table rows. |
|
187 | - * Allows for easier overriding of child methods for setting up sorting. |
|
188 | - * |
|
189 | - * @param EE_Registration $item the current item |
|
190 | - * @return string |
|
191 | - */ |
|
192 | - protected function _get_row_class($item) |
|
193 | - { |
|
194 | - $class = parent::_get_row_class($item); |
|
195 | - // add status class |
|
196 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
197 | - if ($this->_has_checkbox_column) { |
|
198 | - $class .= ' has-checkbox-column'; |
|
199 | - } |
|
200 | - return $class; |
|
201 | - } |
|
185 | + /** |
|
186 | + * This simply sets up the row class for the table rows. |
|
187 | + * Allows for easier overriding of child methods for setting up sorting. |
|
188 | + * |
|
189 | + * @param EE_Registration $item the current item |
|
190 | + * @return string |
|
191 | + */ |
|
192 | + protected function _get_row_class($item) |
|
193 | + { |
|
194 | + $class = parent::_get_row_class($item); |
|
195 | + // add status class |
|
196 | + $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
197 | + if ($this->_has_checkbox_column) { |
|
198 | + $class .= ' has-checkbox-column'; |
|
199 | + } |
|
200 | + return $class; |
|
201 | + } |
|
202 | 202 | |
203 | 203 | |
204 | - /** |
|
205 | - * Set the $_transaction_details property if not set yet. |
|
206 | - * |
|
207 | - * @param EE_Registration $registration |
|
208 | - * @throws EE_Error |
|
209 | - * @throws InvalidArgumentException |
|
210 | - * @throws ReflectionException |
|
211 | - * @throws InvalidDataTypeException |
|
212 | - * @throws InvalidInterfaceException |
|
213 | - */ |
|
214 | - protected function _set_related_details(EE_Registration $registration) |
|
215 | - { |
|
216 | - $transaction = $registration->get_first_related('Transaction'); |
|
217 | - $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
218 | - : EEM_Transaction::failed_status_code; |
|
219 | - $this->_transaction_details = array( |
|
220 | - 'transaction' => $transaction, |
|
221 | - 'status' => $status, |
|
222 | - 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
223 | - 'title_attr' => sprintf( |
|
224 | - __('View Transaction Details (%s)', 'event_espresso'), |
|
225 | - EEH_Template::pretty_status($status, false, 'sentence') |
|
226 | - ), |
|
227 | - ); |
|
228 | - try { |
|
229 | - $event = $registration->event(); |
|
230 | - } catch (EntityNotFoundException $e) { |
|
231 | - $event = null; |
|
232 | - } |
|
233 | - $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
234 | - $this->_event_details = array( |
|
235 | - 'event' => $event, |
|
236 | - 'status' => $status, |
|
237 | - 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
238 | - 'title_attr' => sprintf( |
|
239 | - __('Edit Event (%s)', 'event_espresso'), |
|
240 | - EEH_Template::pretty_status($status, false, 'sentence') |
|
241 | - ), |
|
242 | - ); |
|
243 | - } |
|
204 | + /** |
|
205 | + * Set the $_transaction_details property if not set yet. |
|
206 | + * |
|
207 | + * @param EE_Registration $registration |
|
208 | + * @throws EE_Error |
|
209 | + * @throws InvalidArgumentException |
|
210 | + * @throws ReflectionException |
|
211 | + * @throws InvalidDataTypeException |
|
212 | + * @throws InvalidInterfaceException |
|
213 | + */ |
|
214 | + protected function _set_related_details(EE_Registration $registration) |
|
215 | + { |
|
216 | + $transaction = $registration->get_first_related('Transaction'); |
|
217 | + $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
218 | + : EEM_Transaction::failed_status_code; |
|
219 | + $this->_transaction_details = array( |
|
220 | + 'transaction' => $transaction, |
|
221 | + 'status' => $status, |
|
222 | + 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
223 | + 'title_attr' => sprintf( |
|
224 | + __('View Transaction Details (%s)', 'event_espresso'), |
|
225 | + EEH_Template::pretty_status($status, false, 'sentence') |
|
226 | + ), |
|
227 | + ); |
|
228 | + try { |
|
229 | + $event = $registration->event(); |
|
230 | + } catch (EntityNotFoundException $e) { |
|
231 | + $event = null; |
|
232 | + } |
|
233 | + $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
234 | + $this->_event_details = array( |
|
235 | + 'event' => $event, |
|
236 | + 'status' => $status, |
|
237 | + 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
238 | + 'title_attr' => sprintf( |
|
239 | + __('Edit Event (%s)', 'event_espresso'), |
|
240 | + EEH_Template::pretty_status($status, false, 'sentence') |
|
241 | + ), |
|
242 | + ); |
|
243 | + } |
|
244 | 244 | |
245 | 245 | |
246 | - /** |
|
247 | - * _get_table_filters |
|
248 | - * |
|
249 | - * @access protected |
|
250 | - * @return array |
|
251 | - */ |
|
252 | - protected function _get_table_filters() |
|
253 | - { |
|
254 | - $filters = array(); |
|
255 | - // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as |
|
256 | - // methods. |
|
257 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
258 | - $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
259 | - $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
260 | - $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
261 | - $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
262 | - $status = array(); |
|
263 | - $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
264 | - foreach ($this->_status as $key => $value) { |
|
265 | - $status[] = array('id' => $key, 'text' => $value); |
|
266 | - } |
|
267 | - if ($this->_view !== 'incomplete') { |
|
268 | - $filters[] = EEH_Form_Fields::select_input( |
|
269 | - '_reg_status', |
|
270 | - $status, |
|
271 | - isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
272 | - : '' |
|
273 | - ); |
|
274 | - } |
|
275 | - if (isset($this->_req_data['event_id'])) { |
|
276 | - $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
277 | - } |
|
278 | - return $filters; |
|
279 | - } |
|
246 | + /** |
|
247 | + * _get_table_filters |
|
248 | + * |
|
249 | + * @access protected |
|
250 | + * @return array |
|
251 | + */ |
|
252 | + protected function _get_table_filters() |
|
253 | + { |
|
254 | + $filters = array(); |
|
255 | + // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as |
|
256 | + // methods. |
|
257 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
258 | + $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
259 | + $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
260 | + $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
261 | + $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
262 | + $status = array(); |
|
263 | + $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
264 | + foreach ($this->_status as $key => $value) { |
|
265 | + $status[] = array('id' => $key, 'text' => $value); |
|
266 | + } |
|
267 | + if ($this->_view !== 'incomplete') { |
|
268 | + $filters[] = EEH_Form_Fields::select_input( |
|
269 | + '_reg_status', |
|
270 | + $status, |
|
271 | + isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
272 | + : '' |
|
273 | + ); |
|
274 | + } |
|
275 | + if (isset($this->_req_data['event_id'])) { |
|
276 | + $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
277 | + } |
|
278 | + return $filters; |
|
279 | + } |
|
280 | 280 | |
281 | 281 | |
282 | - /** |
|
283 | - * _add_view_counts |
|
284 | - * |
|
285 | - * @access protected |
|
286 | - * @return void |
|
287 | - * @throws EE_Error |
|
288 | - * @throws InvalidArgumentException |
|
289 | - * @throws InvalidDataTypeException |
|
290 | - * @throws InvalidInterfaceException |
|
291 | - */ |
|
292 | - protected function _add_view_counts() |
|
293 | - { |
|
294 | - $this->_views['all']['count'] = $this->_total_registrations(); |
|
295 | - $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
296 | - $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
297 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
298 | - 'ee_delete_registrations', |
|
299 | - 'espresso_registrations_trash_registrations' |
|
300 | - )) { |
|
301 | - $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
302 | - $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
303 | - } |
|
304 | - } |
|
282 | + /** |
|
283 | + * _add_view_counts |
|
284 | + * |
|
285 | + * @access protected |
|
286 | + * @return void |
|
287 | + * @throws EE_Error |
|
288 | + * @throws InvalidArgumentException |
|
289 | + * @throws InvalidDataTypeException |
|
290 | + * @throws InvalidInterfaceException |
|
291 | + */ |
|
292 | + protected function _add_view_counts() |
|
293 | + { |
|
294 | + $this->_views['all']['count'] = $this->_total_registrations(); |
|
295 | + $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
296 | + $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
297 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
298 | + 'ee_delete_registrations', |
|
299 | + 'espresso_registrations_trash_registrations' |
|
300 | + )) { |
|
301 | + $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
302 | + $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
303 | + } |
|
304 | + } |
|
305 | 305 | |
306 | 306 | |
307 | - /** |
|
308 | - * _total_registrations |
|
309 | - * |
|
310 | - * @access protected |
|
311 | - * @param string $view |
|
312 | - * @return int |
|
313 | - * @throws EE_Error |
|
314 | - * @throws InvalidArgumentException |
|
315 | - * @throws InvalidDataTypeException |
|
316 | - * @throws InvalidInterfaceException |
|
317 | - */ |
|
318 | - protected function _total_registrations($view = '') |
|
319 | - { |
|
320 | - $_where = array(); |
|
321 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
322 | - if ($EVT_ID) { |
|
323 | - $_where['EVT_ID'] = $EVT_ID; |
|
324 | - } |
|
325 | - switch ($view) { |
|
326 | - case 'trash': |
|
327 | - return EEM_Registration::instance()->count_deleted(array($_where)); |
|
328 | - break; |
|
329 | - case 'incomplete': |
|
330 | - $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
331 | - break; |
|
332 | - default: |
|
333 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
334 | - } |
|
335 | - return EEM_Registration::instance()->count(array($_where)); |
|
336 | - } |
|
307 | + /** |
|
308 | + * _total_registrations |
|
309 | + * |
|
310 | + * @access protected |
|
311 | + * @param string $view |
|
312 | + * @return int |
|
313 | + * @throws EE_Error |
|
314 | + * @throws InvalidArgumentException |
|
315 | + * @throws InvalidDataTypeException |
|
316 | + * @throws InvalidInterfaceException |
|
317 | + */ |
|
318 | + protected function _total_registrations($view = '') |
|
319 | + { |
|
320 | + $_where = array(); |
|
321 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
322 | + if ($EVT_ID) { |
|
323 | + $_where['EVT_ID'] = $EVT_ID; |
|
324 | + } |
|
325 | + switch ($view) { |
|
326 | + case 'trash': |
|
327 | + return EEM_Registration::instance()->count_deleted(array($_where)); |
|
328 | + break; |
|
329 | + case 'incomplete': |
|
330 | + $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
331 | + break; |
|
332 | + default: |
|
333 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
334 | + } |
|
335 | + return EEM_Registration::instance()->count(array($_where)); |
|
336 | + } |
|
337 | 337 | |
338 | 338 | |
339 | - /** |
|
340 | - * _total_registrations_this_month |
|
341 | - * |
|
342 | - * @access protected |
|
343 | - * @return int |
|
344 | - * @throws EE_Error |
|
345 | - * @throws InvalidArgumentException |
|
346 | - * @throws InvalidDataTypeException |
|
347 | - * @throws InvalidInterfaceException |
|
348 | - */ |
|
349 | - protected function _total_registrations_this_month() |
|
350 | - { |
|
351 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
352 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
353 | - $this_year_r = date('Y', current_time('timestamp')); |
|
354 | - $time_start = ' 00:00:00'; |
|
355 | - $time_end = ' 23:59:59'; |
|
356 | - $this_month_r = date('m', current_time('timestamp')); |
|
357 | - $days_this_month = date('t', current_time('timestamp')); |
|
358 | - // setup date query. |
|
359 | - $beginning_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
360 | - 'REG_date', |
|
361 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
362 | - 'Y-m-d H:i:s' |
|
363 | - ); |
|
364 | - $end_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
365 | - 'REG_date', |
|
366 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
367 | - 'Y-m-d H:i:s' |
|
368 | - ); |
|
369 | - $_where['REG_date'] = array( |
|
370 | - 'BETWEEN', |
|
371 | - array( |
|
372 | - $beginning_string, |
|
373 | - $end_string, |
|
374 | - ), |
|
375 | - ); |
|
376 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
377 | - return EEM_Registration::instance()->count(array($_where)); |
|
378 | - } |
|
339 | + /** |
|
340 | + * _total_registrations_this_month |
|
341 | + * |
|
342 | + * @access protected |
|
343 | + * @return int |
|
344 | + * @throws EE_Error |
|
345 | + * @throws InvalidArgumentException |
|
346 | + * @throws InvalidDataTypeException |
|
347 | + * @throws InvalidInterfaceException |
|
348 | + */ |
|
349 | + protected function _total_registrations_this_month() |
|
350 | + { |
|
351 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
352 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
353 | + $this_year_r = date('Y', current_time('timestamp')); |
|
354 | + $time_start = ' 00:00:00'; |
|
355 | + $time_end = ' 23:59:59'; |
|
356 | + $this_month_r = date('m', current_time('timestamp')); |
|
357 | + $days_this_month = date('t', current_time('timestamp')); |
|
358 | + // setup date query. |
|
359 | + $beginning_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
360 | + 'REG_date', |
|
361 | + $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
362 | + 'Y-m-d H:i:s' |
|
363 | + ); |
|
364 | + $end_string = EEM_Registration::instance()->convert_datetime_for_query( |
|
365 | + 'REG_date', |
|
366 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
367 | + 'Y-m-d H:i:s' |
|
368 | + ); |
|
369 | + $_where['REG_date'] = array( |
|
370 | + 'BETWEEN', |
|
371 | + array( |
|
372 | + $beginning_string, |
|
373 | + $end_string, |
|
374 | + ), |
|
375 | + ); |
|
376 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
377 | + return EEM_Registration::instance()->count(array($_where)); |
|
378 | + } |
|
379 | 379 | |
380 | 380 | |
381 | - /** |
|
382 | - * _total_registrations_today |
|
383 | - * |
|
384 | - * @access protected |
|
385 | - * @return int |
|
386 | - * @throws EE_Error |
|
387 | - * @throws InvalidArgumentException |
|
388 | - * @throws InvalidDataTypeException |
|
389 | - * @throws InvalidInterfaceException |
|
390 | - */ |
|
391 | - protected function _total_registrations_today() |
|
392 | - { |
|
393 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
394 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
395 | - $current_date = date('Y-m-d', current_time('timestamp')); |
|
396 | - $time_start = ' 00:00:00'; |
|
397 | - $time_end = ' 23:59:59'; |
|
398 | - $_where['REG_date'] = array( |
|
399 | - 'BETWEEN', |
|
400 | - array( |
|
401 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
402 | - 'REG_date', |
|
403 | - $current_date . $time_start, |
|
404 | - 'Y-m-d H:i:s' |
|
405 | - ), |
|
406 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
407 | - 'REG_date', |
|
408 | - $current_date . $time_end, |
|
409 | - 'Y-m-d H:i:s' |
|
410 | - ), |
|
411 | - ), |
|
412 | - ); |
|
413 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
414 | - return EEM_Registration::instance()->count(array($_where)); |
|
415 | - } |
|
381 | + /** |
|
382 | + * _total_registrations_today |
|
383 | + * |
|
384 | + * @access protected |
|
385 | + * @return int |
|
386 | + * @throws EE_Error |
|
387 | + * @throws InvalidArgumentException |
|
388 | + * @throws InvalidDataTypeException |
|
389 | + * @throws InvalidInterfaceException |
|
390 | + */ |
|
391 | + protected function _total_registrations_today() |
|
392 | + { |
|
393 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
394 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
395 | + $current_date = date('Y-m-d', current_time('timestamp')); |
|
396 | + $time_start = ' 00:00:00'; |
|
397 | + $time_end = ' 23:59:59'; |
|
398 | + $_where['REG_date'] = array( |
|
399 | + 'BETWEEN', |
|
400 | + array( |
|
401 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
402 | + 'REG_date', |
|
403 | + $current_date . $time_start, |
|
404 | + 'Y-m-d H:i:s' |
|
405 | + ), |
|
406 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
407 | + 'REG_date', |
|
408 | + $current_date . $time_end, |
|
409 | + 'Y-m-d H:i:s' |
|
410 | + ), |
|
411 | + ), |
|
412 | + ); |
|
413 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
414 | + return EEM_Registration::instance()->count(array($_where)); |
|
415 | + } |
|
416 | 416 | |
417 | 417 | |
418 | - /** |
|
419 | - * column_cb |
|
420 | - * |
|
421 | - * @access public |
|
422 | - * @param \EE_Registration $item |
|
423 | - * @return string |
|
424 | - * @throws EE_Error |
|
425 | - * @throws InvalidArgumentException |
|
426 | - * @throws InvalidDataTypeException |
|
427 | - * @throws InvalidInterfaceException |
|
428 | - * @throws ReflectionException |
|
429 | - */ |
|
430 | - public function column_cb($item) |
|
431 | - { |
|
432 | - /** checkbox/lock **/ |
|
433 | - $transaction = $item->get_first_related('Transaction'); |
|
434 | - $payment_count = $transaction instanceof EE_Transaction |
|
435 | - ? $transaction->count_related('Payment') |
|
436 | - : 0; |
|
437 | - return $payment_count > 0 |
|
438 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
439 | - 'ee_edit_registration', |
|
440 | - 'registration_list_table_checkbox_input', |
|
441 | - $item->ID() |
|
442 | - ) |
|
443 | - ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
444 | - . '<span class="ee-lock-icon"></span>' |
|
445 | - : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
446 | - } |
|
418 | + /** |
|
419 | + * column_cb |
|
420 | + * |
|
421 | + * @access public |
|
422 | + * @param \EE_Registration $item |
|
423 | + * @return string |
|
424 | + * @throws EE_Error |
|
425 | + * @throws InvalidArgumentException |
|
426 | + * @throws InvalidDataTypeException |
|
427 | + * @throws InvalidInterfaceException |
|
428 | + * @throws ReflectionException |
|
429 | + */ |
|
430 | + public function column_cb($item) |
|
431 | + { |
|
432 | + /** checkbox/lock **/ |
|
433 | + $transaction = $item->get_first_related('Transaction'); |
|
434 | + $payment_count = $transaction instanceof EE_Transaction |
|
435 | + ? $transaction->count_related('Payment') |
|
436 | + : 0; |
|
437 | + return $payment_count > 0 |
|
438 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
439 | + 'ee_edit_registration', |
|
440 | + 'registration_list_table_checkbox_input', |
|
441 | + $item->ID() |
|
442 | + ) |
|
443 | + ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
444 | + . '<span class="ee-lock-icon"></span>' |
|
445 | + : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
446 | + } |
|
447 | 447 | |
448 | 448 | |
449 | - /** |
|
450 | - * column__REG_ID |
|
451 | - * |
|
452 | - * @access public |
|
453 | - * @param \EE_Registration $item |
|
454 | - * @return string |
|
455 | - * @throws EE_Error |
|
456 | - * @throws InvalidArgumentException |
|
457 | - * @throws InvalidDataTypeException |
|
458 | - * @throws InvalidInterfaceException |
|
459 | - * @throws ReflectionException |
|
460 | - */ |
|
461 | - public function column__REG_ID(EE_Registration $item) |
|
462 | - { |
|
463 | - $attendee = $item->attendee(); |
|
464 | - $content = $item->ID(); |
|
465 | - $content .= '<div class="show-on-mobile-view-only">'; |
|
466 | - $content .= '<br>'; |
|
467 | - $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
468 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
469 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
470 | - $content .= '</div>'; |
|
471 | - return $content; |
|
472 | - } |
|
449 | + /** |
|
450 | + * column__REG_ID |
|
451 | + * |
|
452 | + * @access public |
|
453 | + * @param \EE_Registration $item |
|
454 | + * @return string |
|
455 | + * @throws EE_Error |
|
456 | + * @throws InvalidArgumentException |
|
457 | + * @throws InvalidDataTypeException |
|
458 | + * @throws InvalidInterfaceException |
|
459 | + * @throws ReflectionException |
|
460 | + */ |
|
461 | + public function column__REG_ID(EE_Registration $item) |
|
462 | + { |
|
463 | + $attendee = $item->attendee(); |
|
464 | + $content = $item->ID(); |
|
465 | + $content .= '<div class="show-on-mobile-view-only">'; |
|
466 | + $content .= '<br>'; |
|
467 | + $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
468 | + $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
469 | + $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
470 | + $content .= '</div>'; |
|
471 | + return $content; |
|
472 | + } |
|
473 | 473 | |
474 | 474 | |
475 | - /** |
|
476 | - * column__REG_date |
|
477 | - * |
|
478 | - * @access public |
|
479 | - * @param \EE_Registration $item |
|
480 | - * @return string |
|
481 | - * @throws EE_Error |
|
482 | - * @throws InvalidArgumentException |
|
483 | - * @throws InvalidDataTypeException |
|
484 | - * @throws InvalidInterfaceException |
|
485 | - * @throws ReflectionException |
|
486 | - */ |
|
487 | - public function column__REG_date(EE_Registration $item) |
|
488 | - { |
|
489 | - $this->_set_related_details($item); |
|
490 | - // Build row actions |
|
491 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
492 | - array( |
|
493 | - 'action' => 'view_transaction', |
|
494 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
495 | - ), |
|
496 | - TXN_ADMIN_URL |
|
497 | - ); |
|
498 | - $view_link = EE_Registry::instance()->CAP->current_user_can( |
|
499 | - 'ee_read_transaction', |
|
500 | - 'espresso_transactions_view_transaction' |
|
501 | - ) |
|
502 | - ? '<a class="ee-status-color-' |
|
503 | - . $this->_transaction_details['status'] |
|
504 | - . '" href="' |
|
505 | - . $view_lnk_url |
|
506 | - . '" title="' |
|
507 | - . esc_attr($this->_transaction_details['title_attr']) |
|
508 | - . '">' |
|
509 | - . $item->get_i18n_datetime('REG_date') |
|
510 | - . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
511 | - $view_link .= '<br><span class="ee-status-text-small">' |
|
512 | - . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
513 | - . '</span>'; |
|
514 | - return $view_link; |
|
515 | - } |
|
475 | + /** |
|
476 | + * column__REG_date |
|
477 | + * |
|
478 | + * @access public |
|
479 | + * @param \EE_Registration $item |
|
480 | + * @return string |
|
481 | + * @throws EE_Error |
|
482 | + * @throws InvalidArgumentException |
|
483 | + * @throws InvalidDataTypeException |
|
484 | + * @throws InvalidInterfaceException |
|
485 | + * @throws ReflectionException |
|
486 | + */ |
|
487 | + public function column__REG_date(EE_Registration $item) |
|
488 | + { |
|
489 | + $this->_set_related_details($item); |
|
490 | + // Build row actions |
|
491 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
492 | + array( |
|
493 | + 'action' => 'view_transaction', |
|
494 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
495 | + ), |
|
496 | + TXN_ADMIN_URL |
|
497 | + ); |
|
498 | + $view_link = EE_Registry::instance()->CAP->current_user_can( |
|
499 | + 'ee_read_transaction', |
|
500 | + 'espresso_transactions_view_transaction' |
|
501 | + ) |
|
502 | + ? '<a class="ee-status-color-' |
|
503 | + . $this->_transaction_details['status'] |
|
504 | + . '" href="' |
|
505 | + . $view_lnk_url |
|
506 | + . '" title="' |
|
507 | + . esc_attr($this->_transaction_details['title_attr']) |
|
508 | + . '">' |
|
509 | + . $item->get_i18n_datetime('REG_date') |
|
510 | + . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
511 | + $view_link .= '<br><span class="ee-status-text-small">' |
|
512 | + . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
513 | + . '</span>'; |
|
514 | + return $view_link; |
|
515 | + } |
|
516 | 516 | |
517 | 517 | |
518 | - /** |
|
519 | - * column_event_name |
|
520 | - * |
|
521 | - * @access public |
|
522 | - * @param \EE_Registration $item |
|
523 | - * @return string |
|
524 | - * @throws EE_Error |
|
525 | - * @throws InvalidArgumentException |
|
526 | - * @throws InvalidDataTypeException |
|
527 | - * @throws InvalidInterfaceException |
|
528 | - * @throws ReflectionException |
|
529 | - */ |
|
530 | - public function column_event_name(EE_Registration $item) |
|
531 | - { |
|
532 | - $this->_set_related_details($item); |
|
533 | - // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
534 | - $EVT_ID = $item->event_ID(); |
|
535 | - $event_name = $item->event_name(); |
|
536 | - $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
537 | - $event_name = wp_trim_words($event_name, 30, '...'); |
|
538 | - if ($EVT_ID) { |
|
539 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
540 | - array('action' => 'edit', 'post' => $EVT_ID), |
|
541 | - EVENTS_ADMIN_URL |
|
542 | - ); |
|
543 | - $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
544 | - ? '<a class="ee-status-color-' |
|
545 | - . $this->_event_details['status'] |
|
546 | - . '" href="' |
|
547 | - . $edit_event_url |
|
548 | - . '" title="' |
|
549 | - . esc_attr($this->_event_details['title_attr']) |
|
550 | - . '">' |
|
551 | - . $event_name |
|
552 | - . '</a>' : $event_name; |
|
553 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
554 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
555 | - $actions['event_filter'] .= sprintf( |
|
556 | - esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'), |
|
557 | - $event_name |
|
558 | - ); |
|
559 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
560 | - } else { |
|
561 | - $edit_event = $event_name; |
|
562 | - $actions['event_filter'] = ''; |
|
563 | - } |
|
564 | - return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
565 | - } |
|
518 | + /** |
|
519 | + * column_event_name |
|
520 | + * |
|
521 | + * @access public |
|
522 | + * @param \EE_Registration $item |
|
523 | + * @return string |
|
524 | + * @throws EE_Error |
|
525 | + * @throws InvalidArgumentException |
|
526 | + * @throws InvalidDataTypeException |
|
527 | + * @throws InvalidInterfaceException |
|
528 | + * @throws ReflectionException |
|
529 | + */ |
|
530 | + public function column_event_name(EE_Registration $item) |
|
531 | + { |
|
532 | + $this->_set_related_details($item); |
|
533 | + // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
534 | + $EVT_ID = $item->event_ID(); |
|
535 | + $event_name = $item->event_name(); |
|
536 | + $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
537 | + $event_name = wp_trim_words($event_name, 30, '...'); |
|
538 | + if ($EVT_ID) { |
|
539 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
540 | + array('action' => 'edit', 'post' => $EVT_ID), |
|
541 | + EVENTS_ADMIN_URL |
|
542 | + ); |
|
543 | + $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
544 | + ? '<a class="ee-status-color-' |
|
545 | + . $this->_event_details['status'] |
|
546 | + . '" href="' |
|
547 | + . $edit_event_url |
|
548 | + . '" title="' |
|
549 | + . esc_attr($this->_event_details['title_attr']) |
|
550 | + . '">' |
|
551 | + . $event_name |
|
552 | + . '</a>' : $event_name; |
|
553 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
554 | + $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
555 | + $actions['event_filter'] .= sprintf( |
|
556 | + esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'), |
|
557 | + $event_name |
|
558 | + ); |
|
559 | + $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
560 | + } else { |
|
561 | + $edit_event = $event_name; |
|
562 | + $actions['event_filter'] = ''; |
|
563 | + } |
|
564 | + return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
565 | + } |
|
566 | 566 | |
567 | 567 | |
568 | - /** |
|
569 | - * column_DTT_EVT_start |
|
570 | - * |
|
571 | - * @access public |
|
572 | - * @param \EE_Registration $item |
|
573 | - * @return string |
|
574 | - * @throws EE_Error |
|
575 | - * @throws InvalidArgumentException |
|
576 | - * @throws InvalidDataTypeException |
|
577 | - * @throws InvalidInterfaceException |
|
578 | - * @throws ReflectionException |
|
579 | - */ |
|
580 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
581 | - { |
|
582 | - $datetime_strings = array(); |
|
583 | - $ticket = $item->ticket(true); |
|
584 | - if ($ticket instanceof EE_Ticket) { |
|
585 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
586 | - $datetimes = $ticket->datetimes($remove_defaults); |
|
587 | - foreach ($datetimes as $datetime) { |
|
588 | - $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
589 | - } |
|
590 | - return $this->generateDisplayForDatetimes($datetime_strings); |
|
591 | - } |
|
592 | - return __('There is no ticket on this registration', 'event_espresso'); |
|
593 | - } |
|
568 | + /** |
|
569 | + * column_DTT_EVT_start |
|
570 | + * |
|
571 | + * @access public |
|
572 | + * @param \EE_Registration $item |
|
573 | + * @return string |
|
574 | + * @throws EE_Error |
|
575 | + * @throws InvalidArgumentException |
|
576 | + * @throws InvalidDataTypeException |
|
577 | + * @throws InvalidInterfaceException |
|
578 | + * @throws ReflectionException |
|
579 | + */ |
|
580 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
581 | + { |
|
582 | + $datetime_strings = array(); |
|
583 | + $ticket = $item->ticket(true); |
|
584 | + if ($ticket instanceof EE_Ticket) { |
|
585 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
586 | + $datetimes = $ticket->datetimes($remove_defaults); |
|
587 | + foreach ($datetimes as $datetime) { |
|
588 | + $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
589 | + } |
|
590 | + return $this->generateDisplayForDatetimes($datetime_strings); |
|
591 | + } |
|
592 | + return __('There is no ticket on this registration', 'event_espresso'); |
|
593 | + } |
|
594 | 594 | |
595 | 595 | |
596 | - /** |
|
597 | - * Receives an array of datetime strings to display and converts them to the html container for the column. |
|
598 | - * |
|
599 | - * @param array $datetime_strings |
|
600 | - * @return string |
|
601 | - */ |
|
602 | - public function generateDisplayForDateTimes(array $datetime_strings) |
|
603 | - { |
|
604 | - $content = '<div class="ee-registration-event-datetimes-container">'; |
|
605 | - $expand_toggle = count($datetime_strings) > 1 |
|
606 | - ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso') |
|
607 | - . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>' |
|
608 | - : ''; |
|
609 | - // get first item for initial visibility |
|
610 | - $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>'; |
|
611 | - $content .= $expand_toggle; |
|
612 | - if ($datetime_strings) { |
|
613 | - $content .= '<div style="clear:both"></div>'; |
|
614 | - $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">'; |
|
615 | - $content .= implode("<br />", $datetime_strings); |
|
616 | - $content .= '</div>'; |
|
617 | - } |
|
618 | - $content .= '</div>'; |
|
619 | - return $content; |
|
620 | - } |
|
596 | + /** |
|
597 | + * Receives an array of datetime strings to display and converts them to the html container for the column. |
|
598 | + * |
|
599 | + * @param array $datetime_strings |
|
600 | + * @return string |
|
601 | + */ |
|
602 | + public function generateDisplayForDateTimes(array $datetime_strings) |
|
603 | + { |
|
604 | + $content = '<div class="ee-registration-event-datetimes-container">'; |
|
605 | + $expand_toggle = count($datetime_strings) > 1 |
|
606 | + ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso') |
|
607 | + . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>' |
|
608 | + : ''; |
|
609 | + // get first item for initial visibility |
|
610 | + $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>'; |
|
611 | + $content .= $expand_toggle; |
|
612 | + if ($datetime_strings) { |
|
613 | + $content .= '<div style="clear:both"></div>'; |
|
614 | + $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">'; |
|
615 | + $content .= implode("<br />", $datetime_strings); |
|
616 | + $content .= '</div>'; |
|
617 | + } |
|
618 | + $content .= '</div>'; |
|
619 | + return $content; |
|
620 | + } |
|
621 | 621 | |
622 | 622 | |
623 | - /** |
|
624 | - * column_ATT_fname |
|
625 | - * |
|
626 | - * @access public |
|
627 | - * @param \EE_Registration $item |
|
628 | - * @return string |
|
629 | - * @throws EE_Error |
|
630 | - * @throws InvalidArgumentException |
|
631 | - * @throws InvalidDataTypeException |
|
632 | - * @throws InvalidInterfaceException |
|
633 | - * @throws ReflectionException |
|
634 | - */ |
|
635 | - public function column_ATT_fname(EE_Registration $item) |
|
636 | - { |
|
637 | - $attendee = $item->attendee(); |
|
638 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
639 | - array( |
|
640 | - 'action' => 'view_registration', |
|
641 | - '_REG_ID' => $item->ID(), |
|
642 | - ), |
|
643 | - REG_ADMIN_URL |
|
644 | - ); |
|
645 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
646 | - $link = EE_Registry::instance()->CAP->current_user_can( |
|
647 | - 'ee_read_registration', |
|
648 | - 'espresso_registrations_view_registration', |
|
649 | - $item->ID() |
|
650 | - ) |
|
651 | - ? '<a href="' |
|
652 | - . $edit_lnk_url |
|
653 | - . '" title="' |
|
654 | - . esc_attr__('View Registration Details', 'event_espresso') |
|
655 | - . '">' |
|
656 | - . $attendee_name |
|
657 | - . '</a>' : $attendee_name; |
|
658 | - $link .= $item->count() === 1 |
|
659 | - ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
660 | - $t = $item->get_first_related('Transaction'); |
|
661 | - $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
662 | - // append group count to name |
|
663 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
664 | - // append reg_code |
|
665 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
666 | - // reg status text for accessibility |
|
667 | - $link .= '<br><span class="ee-status-text-small">' |
|
668 | - . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') |
|
669 | - . '</span>'; |
|
670 | - $action = [ '_REG_ID' => $item->ID() ]; |
|
671 | - if (isset($this->_req_data['event_id'])) { |
|
672 | - $action['event_id'] = $item->event_ID(); |
|
673 | - } |
|
674 | - // trash/restore/delete actions |
|
675 | - $actions = array(); |
|
676 | - if ($this->_view !== 'trash' |
|
677 | - && $payment_count === 0 |
|
678 | - && EE_Registry::instance()->CAP->current_user_can( |
|
679 | - 'ee_delete_registration', |
|
680 | - 'espresso_registrations_trash_registrations', |
|
681 | - $item->ID() |
|
682 | - )) { |
|
683 | - $action['action'] = 'trash_registrations'; |
|
684 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
685 | - $action, |
|
686 | - REG_ADMIN_URL |
|
687 | - ); |
|
688 | - $actions['trash'] = '<a href="' |
|
689 | - . $trash_lnk_url |
|
690 | - . '" title="' |
|
691 | - . esc_attr__('Trash Registration', 'event_espresso') |
|
692 | - . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
693 | - } elseif ($this->_view === 'trash') { |
|
694 | - // restore registration link |
|
695 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
696 | - 'ee_delete_registration', |
|
697 | - 'espresso_registrations_restore_registrations', |
|
698 | - $item->ID() |
|
699 | - )) { |
|
700 | - $action['action'] = 'restore_registrations'; |
|
701 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
702 | - $action, |
|
703 | - REG_ADMIN_URL |
|
704 | - ); |
|
705 | - $actions['restore'] = '<a href="' |
|
706 | - . $restore_lnk_url |
|
707 | - . '" title="' |
|
708 | - . esc_attr__('Restore Registration', 'event_espresso') . '">' |
|
709 | - . __('Restore', 'event_espresso') . '</a>'; |
|
710 | - } |
|
711 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
712 | - 'ee_delete_registration', |
|
713 | - 'espresso_registrations_ee_delete_registrations', |
|
714 | - $item->ID() |
|
715 | - )) { |
|
716 | - $action['action'] = 'delete_registrations'; |
|
717 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
718 | - $action, |
|
719 | - REG_ADMIN_URL |
|
720 | - ); |
|
721 | - $actions['delete'] = '<a href="' |
|
722 | - . $delete_lnk_url |
|
723 | - . '" title="' |
|
724 | - . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
725 | - . '">' |
|
726 | - . __('Delete', 'event_espresso') |
|
727 | - . '</a>'; |
|
728 | - } |
|
729 | - } |
|
730 | - return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
731 | - } |
|
623 | + /** |
|
624 | + * column_ATT_fname |
|
625 | + * |
|
626 | + * @access public |
|
627 | + * @param \EE_Registration $item |
|
628 | + * @return string |
|
629 | + * @throws EE_Error |
|
630 | + * @throws InvalidArgumentException |
|
631 | + * @throws InvalidDataTypeException |
|
632 | + * @throws InvalidInterfaceException |
|
633 | + * @throws ReflectionException |
|
634 | + */ |
|
635 | + public function column_ATT_fname(EE_Registration $item) |
|
636 | + { |
|
637 | + $attendee = $item->attendee(); |
|
638 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
639 | + array( |
|
640 | + 'action' => 'view_registration', |
|
641 | + '_REG_ID' => $item->ID(), |
|
642 | + ), |
|
643 | + REG_ADMIN_URL |
|
644 | + ); |
|
645 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
646 | + $link = EE_Registry::instance()->CAP->current_user_can( |
|
647 | + 'ee_read_registration', |
|
648 | + 'espresso_registrations_view_registration', |
|
649 | + $item->ID() |
|
650 | + ) |
|
651 | + ? '<a href="' |
|
652 | + . $edit_lnk_url |
|
653 | + . '" title="' |
|
654 | + . esc_attr__('View Registration Details', 'event_espresso') |
|
655 | + . '">' |
|
656 | + . $attendee_name |
|
657 | + . '</a>' : $attendee_name; |
|
658 | + $link .= $item->count() === 1 |
|
659 | + ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
660 | + $t = $item->get_first_related('Transaction'); |
|
661 | + $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
662 | + // append group count to name |
|
663 | + $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
664 | + // append reg_code |
|
665 | + $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
666 | + // reg status text for accessibility |
|
667 | + $link .= '<br><span class="ee-status-text-small">' |
|
668 | + . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') |
|
669 | + . '</span>'; |
|
670 | + $action = [ '_REG_ID' => $item->ID() ]; |
|
671 | + if (isset($this->_req_data['event_id'])) { |
|
672 | + $action['event_id'] = $item->event_ID(); |
|
673 | + } |
|
674 | + // trash/restore/delete actions |
|
675 | + $actions = array(); |
|
676 | + if ($this->_view !== 'trash' |
|
677 | + && $payment_count === 0 |
|
678 | + && EE_Registry::instance()->CAP->current_user_can( |
|
679 | + 'ee_delete_registration', |
|
680 | + 'espresso_registrations_trash_registrations', |
|
681 | + $item->ID() |
|
682 | + )) { |
|
683 | + $action['action'] = 'trash_registrations'; |
|
684 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
685 | + $action, |
|
686 | + REG_ADMIN_URL |
|
687 | + ); |
|
688 | + $actions['trash'] = '<a href="' |
|
689 | + . $trash_lnk_url |
|
690 | + . '" title="' |
|
691 | + . esc_attr__('Trash Registration', 'event_espresso') |
|
692 | + . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
693 | + } elseif ($this->_view === 'trash') { |
|
694 | + // restore registration link |
|
695 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
696 | + 'ee_delete_registration', |
|
697 | + 'espresso_registrations_restore_registrations', |
|
698 | + $item->ID() |
|
699 | + )) { |
|
700 | + $action['action'] = 'restore_registrations'; |
|
701 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
702 | + $action, |
|
703 | + REG_ADMIN_URL |
|
704 | + ); |
|
705 | + $actions['restore'] = '<a href="' |
|
706 | + . $restore_lnk_url |
|
707 | + . '" title="' |
|
708 | + . esc_attr__('Restore Registration', 'event_espresso') . '">' |
|
709 | + . __('Restore', 'event_espresso') . '</a>'; |
|
710 | + } |
|
711 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
712 | + 'ee_delete_registration', |
|
713 | + 'espresso_registrations_ee_delete_registrations', |
|
714 | + $item->ID() |
|
715 | + )) { |
|
716 | + $action['action'] = 'delete_registrations'; |
|
717 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
718 | + $action, |
|
719 | + REG_ADMIN_URL |
|
720 | + ); |
|
721 | + $actions['delete'] = '<a href="' |
|
722 | + . $delete_lnk_url |
|
723 | + . '" title="' |
|
724 | + . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
725 | + . '">' |
|
726 | + . __('Delete', 'event_espresso') |
|
727 | + . '</a>'; |
|
728 | + } |
|
729 | + } |
|
730 | + return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
731 | + } |
|
732 | 732 | |
733 | 733 | |
734 | - /** |
|
735 | - * column_ATT_email |
|
736 | - * |
|
737 | - * @access public |
|
738 | - * @param \EE_Registration $item |
|
739 | - * @return string |
|
740 | - * @throws EE_Error |
|
741 | - * @throws InvalidArgumentException |
|
742 | - * @throws InvalidDataTypeException |
|
743 | - * @throws InvalidInterfaceException |
|
744 | - * @throws ReflectionException |
|
745 | - */ |
|
746 | - public function column_ATT_email(EE_Registration $item) |
|
747 | - { |
|
748 | - $attendee = $item->get_first_related('Attendee'); |
|
749 | - return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
750 | - : $attendee->email(); |
|
751 | - } |
|
734 | + /** |
|
735 | + * column_ATT_email |
|
736 | + * |
|
737 | + * @access public |
|
738 | + * @param \EE_Registration $item |
|
739 | + * @return string |
|
740 | + * @throws EE_Error |
|
741 | + * @throws InvalidArgumentException |
|
742 | + * @throws InvalidDataTypeException |
|
743 | + * @throws InvalidInterfaceException |
|
744 | + * @throws ReflectionException |
|
745 | + */ |
|
746 | + public function column_ATT_email(EE_Registration $item) |
|
747 | + { |
|
748 | + $attendee = $item->get_first_related('Attendee'); |
|
749 | + return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
750 | + : $attendee->email(); |
|
751 | + } |
|
752 | 752 | |
753 | 753 | |
754 | - /** |
|
755 | - * column__REG_count |
|
756 | - * |
|
757 | - * @access public |
|
758 | - * @param \EE_Registration $item |
|
759 | - * @return string |
|
760 | - */ |
|
761 | - public function column__REG_count(EE_Registration $item) |
|
762 | - { |
|
763 | - return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
764 | - } |
|
754 | + /** |
|
755 | + * column__REG_count |
|
756 | + * |
|
757 | + * @access public |
|
758 | + * @param \EE_Registration $item |
|
759 | + * @return string |
|
760 | + */ |
|
761 | + public function column__REG_count(EE_Registration $item) |
|
762 | + { |
|
763 | + return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
764 | + } |
|
765 | 765 | |
766 | 766 | |
767 | - /** |
|
768 | - * column_PRC_amount |
|
769 | - * |
|
770 | - * @access public |
|
771 | - * @param \EE_Registration $item |
|
772 | - * @return string |
|
773 | - * @throws EE_Error |
|
774 | - */ |
|
775 | - public function column_PRC_amount(EE_Registration $item) |
|
776 | - { |
|
777 | - $ticket = $item->ticket(); |
|
778 | - $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
779 | - . $ticket->name() |
|
780 | - . '</span><br />' : ''; |
|
781 | - if ($item->final_price() > 0) { |
|
782 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
783 | - } else { |
|
784 | - // free event |
|
785 | - $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
786 | - . __('free', 'event_espresso') |
|
787 | - . '</span>'; |
|
788 | - } |
|
789 | - return $content; |
|
790 | - } |
|
767 | + /** |
|
768 | + * column_PRC_amount |
|
769 | + * |
|
770 | + * @access public |
|
771 | + * @param \EE_Registration $item |
|
772 | + * @return string |
|
773 | + * @throws EE_Error |
|
774 | + */ |
|
775 | + public function column_PRC_amount(EE_Registration $item) |
|
776 | + { |
|
777 | + $ticket = $item->ticket(); |
|
778 | + $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
779 | + . $ticket->name() |
|
780 | + . '</span><br />' : ''; |
|
781 | + if ($item->final_price() > 0) { |
|
782 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
783 | + } else { |
|
784 | + // free event |
|
785 | + $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
786 | + . __('free', 'event_espresso') |
|
787 | + . '</span>'; |
|
788 | + } |
|
789 | + return $content; |
|
790 | + } |
|
791 | 791 | |
792 | 792 | |
793 | - /** |
|
794 | - * column__REG_final_price |
|
795 | - * |
|
796 | - * @access public |
|
797 | - * @param \EE_Registration $item |
|
798 | - * @return string |
|
799 | - * @throws EE_Error |
|
800 | - */ |
|
801 | - public function column__REG_final_price(EE_Registration $item) |
|
802 | - { |
|
803 | - $ticket = $item->ticket(); |
|
804 | - $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
805 | - ? '' |
|
806 | - : '<span class="TKT_name">' |
|
807 | - . $ticket->name() |
|
808 | - . '</span><br />'; |
|
809 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
810 | - return $content; |
|
811 | - } |
|
793 | + /** |
|
794 | + * column__REG_final_price |
|
795 | + * |
|
796 | + * @access public |
|
797 | + * @param \EE_Registration $item |
|
798 | + * @return string |
|
799 | + * @throws EE_Error |
|
800 | + */ |
|
801 | + public function column__REG_final_price(EE_Registration $item) |
|
802 | + { |
|
803 | + $ticket = $item->ticket(); |
|
804 | + $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
805 | + ? '' |
|
806 | + : '<span class="TKT_name">' |
|
807 | + . $ticket->name() |
|
808 | + . '</span><br />'; |
|
809 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
810 | + return $content; |
|
811 | + } |
|
812 | 812 | |
813 | 813 | |
814 | - /** |
|
815 | - * column__REG_paid |
|
816 | - * |
|
817 | - * @access public |
|
818 | - * @param \EE_Registration $item |
|
819 | - * @return string |
|
820 | - * @throws EE_Error |
|
821 | - */ |
|
822 | - public function column__REG_paid(EE_Registration $item) |
|
823 | - { |
|
824 | - $payment_method = $item->payment_method(); |
|
825 | - $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
826 | - : __('Unknown', 'event_espresso'); |
|
827 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
828 | - if ($item->paid() > 0) { |
|
829 | - $content .= '<br><span class="ee-status-text-small">' |
|
830 | - . sprintf( |
|
831 | - __('...via %s', 'event_espresso'), |
|
832 | - $payment_method_name |
|
833 | - ) |
|
834 | - . '</span>'; |
|
835 | - } |
|
836 | - return $content; |
|
837 | - } |
|
814 | + /** |
|
815 | + * column__REG_paid |
|
816 | + * |
|
817 | + * @access public |
|
818 | + * @param \EE_Registration $item |
|
819 | + * @return string |
|
820 | + * @throws EE_Error |
|
821 | + */ |
|
822 | + public function column__REG_paid(EE_Registration $item) |
|
823 | + { |
|
824 | + $payment_method = $item->payment_method(); |
|
825 | + $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
826 | + : __('Unknown', 'event_espresso'); |
|
827 | + $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
828 | + if ($item->paid() > 0) { |
|
829 | + $content .= '<br><span class="ee-status-text-small">' |
|
830 | + . sprintf( |
|
831 | + __('...via %s', 'event_espresso'), |
|
832 | + $payment_method_name |
|
833 | + ) |
|
834 | + . '</span>'; |
|
835 | + } |
|
836 | + return $content; |
|
837 | + } |
|
838 | 838 | |
839 | 839 | |
840 | - /** |
|
841 | - * column_TXN_total |
|
842 | - * |
|
843 | - * @access public |
|
844 | - * @param \EE_Registration $item |
|
845 | - * @return string |
|
846 | - * @throws EE_Error |
|
847 | - * @throws EntityNotFoundException |
|
848 | - * @throws InvalidArgumentException |
|
849 | - * @throws InvalidDataTypeException |
|
850 | - * @throws InvalidInterfaceException |
|
851 | - */ |
|
852 | - public function column_TXN_total(EE_Registration $item) |
|
853 | - { |
|
854 | - if ($item->transaction()) { |
|
855 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
856 | - array( |
|
857 | - 'action' => 'view_transaction', |
|
858 | - 'TXN_ID' => $item->transaction_ID(), |
|
859 | - ), |
|
860 | - TXN_ADMIN_URL |
|
861 | - ); |
|
862 | - return EE_Registry::instance()->CAP->current_user_can( |
|
863 | - 'ee_read_transaction', |
|
864 | - 'espresso_transactions_view_transaction', |
|
865 | - $item->transaction_ID() |
|
866 | - ) |
|
867 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
868 | - . $item->transaction()->status_ID() |
|
869 | - . '" href="' |
|
870 | - . $view_txn_lnk_url |
|
871 | - . '" title="' |
|
872 | - . esc_attr__('View Transaction', 'event_espresso') |
|
873 | - . '">' |
|
874 | - . $item->transaction()->pretty_total() |
|
875 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
876 | - } else { |
|
877 | - return __("None", "event_espresso"); |
|
878 | - } |
|
879 | - } |
|
840 | + /** |
|
841 | + * column_TXN_total |
|
842 | + * |
|
843 | + * @access public |
|
844 | + * @param \EE_Registration $item |
|
845 | + * @return string |
|
846 | + * @throws EE_Error |
|
847 | + * @throws EntityNotFoundException |
|
848 | + * @throws InvalidArgumentException |
|
849 | + * @throws InvalidDataTypeException |
|
850 | + * @throws InvalidInterfaceException |
|
851 | + */ |
|
852 | + public function column_TXN_total(EE_Registration $item) |
|
853 | + { |
|
854 | + if ($item->transaction()) { |
|
855 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
856 | + array( |
|
857 | + 'action' => 'view_transaction', |
|
858 | + 'TXN_ID' => $item->transaction_ID(), |
|
859 | + ), |
|
860 | + TXN_ADMIN_URL |
|
861 | + ); |
|
862 | + return EE_Registry::instance()->CAP->current_user_can( |
|
863 | + 'ee_read_transaction', |
|
864 | + 'espresso_transactions_view_transaction', |
|
865 | + $item->transaction_ID() |
|
866 | + ) |
|
867 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
868 | + . $item->transaction()->status_ID() |
|
869 | + . '" href="' |
|
870 | + . $view_txn_lnk_url |
|
871 | + . '" title="' |
|
872 | + . esc_attr__('View Transaction', 'event_espresso') |
|
873 | + . '">' |
|
874 | + . $item->transaction()->pretty_total() |
|
875 | + . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
876 | + } else { |
|
877 | + return __("None", "event_espresso"); |
|
878 | + } |
|
879 | + } |
|
880 | 880 | |
881 | 881 | |
882 | - /** |
|
883 | - * column_TXN_paid |
|
884 | - * |
|
885 | - * @access public |
|
886 | - * @param \EE_Registration $item |
|
887 | - * @return string |
|
888 | - * @throws EE_Error |
|
889 | - * @throws EntityNotFoundException |
|
890 | - * @throws InvalidArgumentException |
|
891 | - * @throws InvalidDataTypeException |
|
892 | - * @throws InvalidInterfaceException |
|
893 | - */ |
|
894 | - public function column_TXN_paid(EE_Registration $item) |
|
895 | - { |
|
896 | - if ($item->count() === 1) { |
|
897 | - $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
898 | - if ($transaction->paid() >= $transaction->total()) { |
|
899 | - return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
900 | - } else { |
|
901 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
902 | - array( |
|
903 | - 'action' => 'view_transaction', |
|
904 | - 'TXN_ID' => $item->transaction_ID(), |
|
905 | - ), |
|
906 | - TXN_ADMIN_URL |
|
907 | - ); |
|
908 | - return EE_Registry::instance()->CAP->current_user_can( |
|
909 | - 'ee_read_transaction', |
|
910 | - 'espresso_transactions_view_transaction', |
|
911 | - $item->transaction_ID() |
|
912 | - ) |
|
913 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
914 | - . $transaction->status_ID() |
|
915 | - . '" href="' |
|
916 | - . $view_txn_lnk_url |
|
917 | - . '" title="' |
|
918 | - . esc_attr__('View Transaction', 'event_espresso') |
|
919 | - . '">' |
|
920 | - . $item->transaction()->pretty_paid() |
|
921 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
922 | - } |
|
923 | - } |
|
924 | - return ' '; |
|
925 | - } |
|
882 | + /** |
|
883 | + * column_TXN_paid |
|
884 | + * |
|
885 | + * @access public |
|
886 | + * @param \EE_Registration $item |
|
887 | + * @return string |
|
888 | + * @throws EE_Error |
|
889 | + * @throws EntityNotFoundException |
|
890 | + * @throws InvalidArgumentException |
|
891 | + * @throws InvalidDataTypeException |
|
892 | + * @throws InvalidInterfaceException |
|
893 | + */ |
|
894 | + public function column_TXN_paid(EE_Registration $item) |
|
895 | + { |
|
896 | + if ($item->count() === 1) { |
|
897 | + $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
898 | + if ($transaction->paid() >= $transaction->total()) { |
|
899 | + return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
900 | + } else { |
|
901 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
902 | + array( |
|
903 | + 'action' => 'view_transaction', |
|
904 | + 'TXN_ID' => $item->transaction_ID(), |
|
905 | + ), |
|
906 | + TXN_ADMIN_URL |
|
907 | + ); |
|
908 | + return EE_Registry::instance()->CAP->current_user_can( |
|
909 | + 'ee_read_transaction', |
|
910 | + 'espresso_transactions_view_transaction', |
|
911 | + $item->transaction_ID() |
|
912 | + ) |
|
913 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
914 | + . $transaction->status_ID() |
|
915 | + . '" href="' |
|
916 | + . $view_txn_lnk_url |
|
917 | + . '" title="' |
|
918 | + . esc_attr__('View Transaction', 'event_espresso') |
|
919 | + . '">' |
|
920 | + . $item->transaction()->pretty_paid() |
|
921 | + . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
922 | + } |
|
923 | + } |
|
924 | + return ' '; |
|
925 | + } |
|
926 | 926 | |
927 | 927 | |
928 | - /** |
|
929 | - * column_actions |
|
930 | - * |
|
931 | - * @access public |
|
932 | - * @param \EE_Registration $item |
|
933 | - * @return string |
|
934 | - * @throws EE_Error |
|
935 | - * @throws InvalidArgumentException |
|
936 | - * @throws InvalidDataTypeException |
|
937 | - * @throws InvalidInterfaceException |
|
938 | - * @throws ReflectionException |
|
939 | - */ |
|
940 | - public function column_actions(EE_Registration $item) |
|
941 | - { |
|
942 | - $actions = array(); |
|
943 | - $attendee = $item->attendee(); |
|
944 | - $this->_set_related_details($item); |
|
945 | - // Build row actions |
|
946 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
947 | - array( |
|
948 | - 'action' => 'view_registration', |
|
949 | - '_REG_ID' => $item->ID(), |
|
950 | - ), |
|
951 | - REG_ADMIN_URL |
|
952 | - ); |
|
953 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
954 | - array( |
|
955 | - 'action' => 'edit_attendee', |
|
956 | - 'post' => $item->attendee_ID(), |
|
957 | - ), |
|
958 | - REG_ADMIN_URL |
|
959 | - ); |
|
960 | - // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
961 | - // $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
962 | - $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
963 | - array( |
|
964 | - 'action' => 'resend_registration', |
|
965 | - '_REG_ID' => $item->ID(), |
|
966 | - ), |
|
967 | - REG_ADMIN_URL, |
|
968 | - true |
|
969 | - ); |
|
970 | - // Build row actions |
|
971 | - $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
972 | - 'ee_read_registration', |
|
973 | - 'espresso_registrations_view_registration', |
|
974 | - $item->ID() |
|
975 | - ) ? '<li><a href="' |
|
976 | - . $view_lnk_url |
|
977 | - . '" title="' |
|
978 | - . esc_attr__('View Registration Details', 'event_espresso') |
|
979 | - . '" class="tiny-text"> |
|
928 | + /** |
|
929 | + * column_actions |
|
930 | + * |
|
931 | + * @access public |
|
932 | + * @param \EE_Registration $item |
|
933 | + * @return string |
|
934 | + * @throws EE_Error |
|
935 | + * @throws InvalidArgumentException |
|
936 | + * @throws InvalidDataTypeException |
|
937 | + * @throws InvalidInterfaceException |
|
938 | + * @throws ReflectionException |
|
939 | + */ |
|
940 | + public function column_actions(EE_Registration $item) |
|
941 | + { |
|
942 | + $actions = array(); |
|
943 | + $attendee = $item->attendee(); |
|
944 | + $this->_set_related_details($item); |
|
945 | + // Build row actions |
|
946 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
947 | + array( |
|
948 | + 'action' => 'view_registration', |
|
949 | + '_REG_ID' => $item->ID(), |
|
950 | + ), |
|
951 | + REG_ADMIN_URL |
|
952 | + ); |
|
953 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
954 | + array( |
|
955 | + 'action' => 'edit_attendee', |
|
956 | + 'post' => $item->attendee_ID(), |
|
957 | + ), |
|
958 | + REG_ADMIN_URL |
|
959 | + ); |
|
960 | + // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
961 | + // $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
962 | + $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
963 | + array( |
|
964 | + 'action' => 'resend_registration', |
|
965 | + '_REG_ID' => $item->ID(), |
|
966 | + ), |
|
967 | + REG_ADMIN_URL, |
|
968 | + true |
|
969 | + ); |
|
970 | + // Build row actions |
|
971 | + $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
972 | + 'ee_read_registration', |
|
973 | + 'espresso_registrations_view_registration', |
|
974 | + $item->ID() |
|
975 | + ) ? '<li><a href="' |
|
976 | + . $view_lnk_url |
|
977 | + . '" title="' |
|
978 | + . esc_attr__('View Registration Details', 'event_espresso') |
|
979 | + . '" class="tiny-text"> |
|
980 | 980 | <div class="dashicons dashicons-clipboard"></div> |
981 | 981 | </a> |
982 | 982 | </li>' |
983 | - : ''; |
|
984 | - $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
985 | - 'ee_edit_contacts', |
|
986 | - 'espresso_registrations_edit_attendee' |
|
987 | - ) |
|
988 | - && $attendee instanceof EE_Attendee |
|
989 | - ? ' |
|
983 | + : ''; |
|
984 | + $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
985 | + 'ee_edit_contacts', |
|
986 | + 'espresso_registrations_edit_attendee' |
|
987 | + ) |
|
988 | + && $attendee instanceof EE_Attendee |
|
989 | + ? ' |
|
990 | 990 | <li> |
991 | 991 | <a href="' . $edit_lnk_url . '" title="' |
992 | - . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
992 | + . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
993 | 993 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
994 | 994 | </a> |
995 | 995 | </li>' : ''; |
996 | - $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
997 | - && EE_Registry::instance()->CAP->current_user_can( |
|
998 | - 'ee_send_message', |
|
999 | - 'espresso_registrations_resend_registration', |
|
1000 | - $item->ID() |
|
1001 | - ) |
|
1002 | - ? ' |
|
996 | + $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
997 | + && EE_Registry::instance()->CAP->current_user_can( |
|
998 | + 'ee_send_message', |
|
999 | + 'espresso_registrations_resend_registration', |
|
1000 | + $item->ID() |
|
1001 | + ) |
|
1002 | + ? ' |
|
1003 | 1003 | <li> |
1004 | 1004 | <a href="' |
1005 | - . $resend_reg_lnk_url |
|
1006 | - . '" title="' |
|
1007 | - . esc_attr__('Resend Registration Details', 'event_espresso') |
|
1008 | - . '" class="tiny-text"> |
|
1005 | + . $resend_reg_lnk_url |
|
1006 | + . '" title="' |
|
1007 | + . esc_attr__('Resend Registration Details', 'event_espresso') |
|
1008 | + . '" class="tiny-text"> |
|
1009 | 1009 | <div class="dashicons dashicons-email-alt"></div> |
1010 | 1010 | </a> |
1011 | 1011 | </li>' : ''; |
1012 | - // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
1013 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
1014 | - array( |
|
1015 | - 'action' => 'view_transaction', |
|
1016 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
1017 | - ), |
|
1018 | - TXN_ADMIN_URL |
|
1019 | - ); |
|
1020 | - $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
1021 | - 'ee_read_transaction', |
|
1022 | - 'espresso_transactions_view_transaction', |
|
1023 | - $this->_transaction_details['id'] |
|
1024 | - ) |
|
1025 | - ? ' |
|
1012 | + // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
1013 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
|
1014 | + array( |
|
1015 | + 'action' => 'view_transaction', |
|
1016 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
1017 | + ), |
|
1018 | + TXN_ADMIN_URL |
|
1019 | + ); |
|
1020 | + $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can( |
|
1021 | + 'ee_read_transaction', |
|
1022 | + 'espresso_transactions_view_transaction', |
|
1023 | + $this->_transaction_details['id'] |
|
1024 | + ) |
|
1025 | + ? ' |
|
1026 | 1026 | <li> |
1027 | 1027 | <a class="ee-status-color-' |
1028 | - . $this->_transaction_details['status'] |
|
1029 | - . ' tiny-text" href="' |
|
1030 | - . $view_txn_lnk_url |
|
1031 | - . '" title="' |
|
1032 | - . $this->_transaction_details['title_attr'] |
|
1033 | - . '"> |
|
1028 | + . $this->_transaction_details['status'] |
|
1029 | + . ' tiny-text" href="' |
|
1030 | + . $view_txn_lnk_url |
|
1031 | + . '" title="' |
|
1032 | + . $this->_transaction_details['title_attr'] |
|
1033 | + . '"> |
|
1034 | 1034 | <div class="dashicons dashicons-cart"></div> |
1035 | 1035 | </a> |
1036 | 1036 | </li>' : ''; |
1037 | - // invoice link |
|
1038 | - $actions['dl_invoice_lnk'] = ''; |
|
1039 | - $dl_invoice_lnk_url = $item->invoice_url(); |
|
1040 | - // only show invoice link if message type is active. |
|
1041 | - if ($attendee instanceof EE_Attendee |
|
1042 | - && $item->is_primary_registrant() |
|
1043 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
1044 | - ) { |
|
1045 | - $actions['dl_invoice_lnk'] = ' |
|
1037 | + // invoice link |
|
1038 | + $actions['dl_invoice_lnk'] = ''; |
|
1039 | + $dl_invoice_lnk_url = $item->invoice_url(); |
|
1040 | + // only show invoice link if message type is active. |
|
1041 | + if ($attendee instanceof EE_Attendee |
|
1042 | + && $item->is_primary_registrant() |
|
1043 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
1044 | + ) { |
|
1045 | + $actions['dl_invoice_lnk'] = ' |
|
1046 | 1046 | <li> |
1047 | 1047 | <a title="' |
1048 | - . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
1049 | - . '" target="_blank" href="' |
|
1050 | - . $dl_invoice_lnk_url |
|
1051 | - . '" class="tiny-text"> |
|
1048 | + . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
1049 | + . '" target="_blank" href="' |
|
1050 | + . $dl_invoice_lnk_url |
|
1051 | + . '" class="tiny-text"> |
|
1052 | 1052 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
1053 | 1053 | </a> |
1054 | 1054 | </li>'; |
1055 | - } |
|
1056 | - $actions['filtered_messages_link'] = ''; |
|
1057 | - // message list table link (filtered by REG_ID |
|
1058 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
1059 | - $actions['filtered_messages_link'] = '<li>' |
|
1060 | - . EEH_MSG_Template::get_message_action_link( |
|
1061 | - 'see_notifications_for', |
|
1062 | - null, |
|
1063 | - array('_REG_ID' => $item->ID()) |
|
1064 | - ) . '</li>'; |
|
1065 | - } |
|
1066 | - $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
1067 | - return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
1068 | - } |
|
1055 | + } |
|
1056 | + $actions['filtered_messages_link'] = ''; |
|
1057 | + // message list table link (filtered by REG_ID |
|
1058 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
1059 | + $actions['filtered_messages_link'] = '<li>' |
|
1060 | + . EEH_MSG_Template::get_message_action_link( |
|
1061 | + 'see_notifications_for', |
|
1062 | + null, |
|
1063 | + array('_REG_ID' => $item->ID()) |
|
1064 | + ) . '</li>'; |
|
1065 | + } |
|
1066 | + $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
1067 | + return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
1068 | + } |
|
1069 | 1069 | } |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function __construct(Registrations_Admin_Page $admin_page) |
55 | 55 | { |
56 | - if (! empty($_GET['event_id'])) { |
|
56 | + if ( ! empty($_GET['event_id'])) { |
|
57 | 57 | $extra_query_args = array(); |
58 | 58 | foreach ($admin_page->get_views() as $key => $view_details) { |
59 | - $extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']); |
|
59 | + $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
|
60 | 60 | } |
61 | 61 | $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
62 | 62 | } |
@@ -156,12 +156,12 @@ discard block |
||
156 | 156 | ) |
157 | 157 | ) |
158 | 158 | ); |
159 | - if (!empty($filters)) { |
|
159 | + if ( ! empty($filters)) { |
|
160 | 160 | $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters; |
161 | 161 | } |
162 | 162 | $this->_primary_column = '_REG_ID'; |
163 | 163 | $this->_sortable_columns = array( |
164 | - '_REG_date' => array('_REG_date' => true), // true means its already sorted |
|
164 | + '_REG_date' => array('_REG_date' => true), // true means its already sorted |
|
165 | 165 | /** |
166 | 166 | * Allows users to change the default sort if they wish. |
167 | 167 | * Returning a falsey on this filter will result in the default sort to be by firstname rather than last |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | { |
194 | 194 | $class = parent::_get_row_class($item); |
195 | 195 | // add status class |
196 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
196 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
197 | 197 | if ($this->_has_checkbox_column) { |
198 | 198 | $class .= ' has-checkbox-column'; |
199 | 199 | } |
@@ -358,12 +358,12 @@ discard block |
||
358 | 358 | // setup date query. |
359 | 359 | $beginning_string = EEM_Registration::instance()->convert_datetime_for_query( |
360 | 360 | 'REG_date', |
361 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
361 | + $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start, |
|
362 | 362 | 'Y-m-d H:i:s' |
363 | 363 | ); |
364 | 364 | $end_string = EEM_Registration::instance()->convert_datetime_for_query( |
365 | 365 | 'REG_date', |
366 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
366 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end, |
|
367 | 367 | 'Y-m-d H:i:s' |
368 | 368 | ); |
369 | 369 | $_where['REG_date'] = array( |
@@ -400,12 +400,12 @@ discard block |
||
400 | 400 | array( |
401 | 401 | EEM_Registration::instance()->convert_datetime_for_query( |
402 | 402 | 'REG_date', |
403 | - $current_date . $time_start, |
|
403 | + $current_date.$time_start, |
|
404 | 404 | 'Y-m-d H:i:s' |
405 | 405 | ), |
406 | 406 | EEM_Registration::instance()->convert_datetime_for_query( |
407 | 407 | 'REG_date', |
408 | - $current_date . $time_end, |
|
408 | + $current_date.$time_end, |
|
409 | 409 | 'Y-m-d H:i:s' |
410 | 410 | ), |
411 | 411 | ), |
@@ -465,8 +465,8 @@ discard block |
||
465 | 465 | $content .= '<div class="show-on-mobile-view-only">'; |
466 | 466 | $content .= '<br>'; |
467 | 467 | $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
468 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
469 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
468 | + $content .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
469 | + $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
470 | 470 | $content .= '</div>'; |
471 | 471 | return $content; |
472 | 472 | } |
@@ -551,12 +551,12 @@ discard block |
||
551 | 551 | . $event_name |
552 | 552 | . '</a>' : $event_name; |
553 | 553 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
554 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
554 | + $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="'; |
|
555 | 555 | $actions['event_filter'] .= sprintf( |
556 | 556 | esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'), |
557 | 557 | $event_name |
558 | 558 | ); |
559 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
559 | + $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>'; |
|
560 | 560 | } else { |
561 | 561 | $edit_event = $event_name; |
562 | 562 | $actions['event_filter'] = ''; |
@@ -603,11 +603,11 @@ discard block |
||
603 | 603 | { |
604 | 604 | $content = '<div class="ee-registration-event-datetimes-container">'; |
605 | 605 | $expand_toggle = count($datetime_strings) > 1 |
606 | - ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso') |
|
606 | + ? ' <span title="'.esc_attr__('Click to view all dates', 'event_espresso') |
|
607 | 607 | . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>' |
608 | 608 | : ''; |
609 | 609 | // get first item for initial visibility |
610 | - $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>'; |
|
610 | + $content .= '<div class="left">'.array_shift($datetime_strings).'</div>'; |
|
611 | 611 | $content .= $expand_toggle; |
612 | 612 | if ($datetime_strings) { |
613 | 613 | $content .= '<div style="clear:both"></div>'; |
@@ -660,14 +660,14 @@ discard block |
||
660 | 660 | $t = $item->get_first_related('Transaction'); |
661 | 661 | $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
662 | 662 | // append group count to name |
663 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
663 | + $link .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
664 | 664 | // append reg_code |
665 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
665 | + $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
666 | 666 | // reg status text for accessibility |
667 | 667 | $link .= '<br><span class="ee-status-text-small">' |
668 | 668 | . EEH_Template::pretty_status($item->status_ID(), false, 'sentence') |
669 | 669 | . '</span>'; |
670 | - $action = [ '_REG_ID' => $item->ID() ]; |
|
670 | + $action = ['_REG_ID' => $item->ID()]; |
|
671 | 671 | if (isset($this->_req_data['event_id'])) { |
672 | 672 | $action['event_id'] = $item->event_ID(); |
673 | 673 | } |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | . $trash_lnk_url |
690 | 690 | . '" title="' |
691 | 691 | . esc_attr__('Trash Registration', 'event_espresso') |
692 | - . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
692 | + . '">'.__('Trash', 'event_espresso').'</a>'; |
|
693 | 693 | } elseif ($this->_view === 'trash') { |
694 | 694 | // restore registration link |
695 | 695 | if (EE_Registry::instance()->CAP->current_user_can( |
@@ -705,8 +705,8 @@ discard block |
||
705 | 705 | $actions['restore'] = '<a href="' |
706 | 706 | . $restore_lnk_url |
707 | 707 | . '" title="' |
708 | - . esc_attr__('Restore Registration', 'event_espresso') . '">' |
|
709 | - . __('Restore', 'event_espresso') . '</a>'; |
|
708 | + . esc_attr__('Restore Registration', 'event_espresso').'">' |
|
709 | + . __('Restore', 'event_espresso').'</a>'; |
|
710 | 710 | } |
711 | 711 | if (EE_Registry::instance()->CAP->current_user_can( |
712 | 712 | 'ee_delete_registration', |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | . $ticket->name() |
780 | 780 | . '</span><br />' : ''; |
781 | 781 | if ($item->final_price() > 0) { |
782 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
782 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
783 | 783 | } else { |
784 | 784 | // free event |
785 | 785 | $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
@@ -806,7 +806,7 @@ discard block |
||
806 | 806 | : '<span class="TKT_name">' |
807 | 807 | . $ticket->name() |
808 | 808 | . '</span><br />'; |
809 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
809 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
810 | 810 | return $content; |
811 | 811 | } |
812 | 812 | |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | $payment_method = $item->payment_method(); |
825 | 825 | $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
826 | 826 | : __('Unknown', 'event_espresso'); |
827 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
827 | + $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>'; |
|
828 | 828 | if ($item->paid() > 0) { |
829 | 829 | $content .= '<br><span class="ee-status-text-small">' |
830 | 830 | . sprintf( |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | . esc_attr__('View Transaction', 'event_espresso') |
873 | 873 | . '">' |
874 | 874 | . $item->transaction()->pretty_total() |
875 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
875 | + . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>'; |
|
876 | 876 | } else { |
877 | 877 | return __("None", "event_espresso"); |
878 | 878 | } |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | . esc_attr__('View Transaction', 'event_espresso') |
919 | 919 | . '">' |
920 | 920 | . $item->transaction()->pretty_paid() |
921 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
921 | + . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
922 | 922 | } |
923 | 923 | } |
924 | 924 | return ' '; |
@@ -988,8 +988,8 @@ discard block |
||
988 | 988 | && $attendee instanceof EE_Attendee |
989 | 989 | ? ' |
990 | 990 | <li> |
991 | - <a href="' . $edit_lnk_url . '" title="' |
|
992 | - . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
991 | + <a href="' . $edit_lnk_url.'" title="' |
|
992 | + . esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text"> |
|
993 | 993 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
994 | 994 | </a> |
995 | 995 | </li>' : ''; |
@@ -1061,7 +1061,7 @@ discard block |
||
1061 | 1061 | 'see_notifications_for', |
1062 | 1062 | null, |
1063 | 1063 | array('_REG_ID' => $item->ID()) |
1064 | - ) . '</li>'; |
|
1064 | + ).'</li>'; |
|
1065 | 1065 | } |
1066 | 1066 | $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
1067 | 1067 | return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
@@ -1421,7 +1421,6 @@ discard block |
||
1421 | 1421 | * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
1422 | 1422 | * and sets it as the featured image on the CPT event |
1423 | 1423 | * |
1424 | - * @param type $old_event |
|
1425 | 1424 | * @param type $new_cpt_id |
1426 | 1425 | * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
1427 | 1426 | * @return boolean whether or not we had to do the big job of creating an image attachment |
@@ -1483,7 +1482,7 @@ discard block |
||
1483 | 1482 | * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
1484 | 1483 | * thumbnails) |
1485 | 1484 | * |
1486 | - * @param type $guid |
|
1485 | + * @param string $guid |
|
1487 | 1486 | * @param EE_Data_Migration_Script_Stage $migration_stage |
1488 | 1487 | * @return int |
1489 | 1488 | */ |
@@ -1571,7 +1570,7 @@ discard block |
||
1571 | 1570 | * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
1572 | 1571 | * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
1573 | 1572 | * |
1574 | - * @param EE_Data_Migration_Script_base $stage |
|
1573 | + * @param EE_Data_Migration_Script_Stage $stage |
|
1575 | 1574 | * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
1576 | 1575 | * UTC time for |
1577 | 1576 | * @param string $DATETIME_string |
@@ -9,13 +9,13 @@ discard block |
||
9 | 9 | // unfortunately, this needs to be done upon INCLUSION of this file, |
10 | 10 | // instead of construction, because it only gets constructed on first page load |
11 | 11 | // (all other times it gets resurrected from a wordpress option) |
12 | -$stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
|
12 | +$stages = glob(EE_CORE.'data_migration_scripts/4_1_0_stages/*'); |
|
13 | 13 | $class_to_filepath = array(); |
14 | -if (! empty($stages)) { |
|
14 | +if ( ! empty($stages)) { |
|
15 | 15 | foreach ($stages as $filepath) { |
16 | 16 | $matches = array(); |
17 | 17 | preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
18 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
18 | + $class_to_filepath[$matches[1]] = $filepath; |
|
19 | 19 | } |
20 | 20 | } |
21 | 21 | // give addons a chance to autoload their stages too |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | private function _checkin_table_exists() |
88 | 88 | { |
89 | 89 | global $wpdb; |
90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '".$wpdb->prefix."events_attendee_checkin"."'"); |
|
91 | 91 | if ($results) { |
92 | 92 | return true; |
93 | 93 | } else { |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
104 | 104 | // echo "$version_string can be migrated fro"; |
105 | 105 | return true; |
106 | - } elseif (! $version_string) { |
|
106 | + } elseif ( ! $version_string) { |
|
107 | 107 | // echo "no version string provided: $version_string"; |
108 | 108 | // no version string provided... this must be pre 4.1 |
109 | 109 | // because since 4.1 we're |
110 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
110 | + return false; // changed mind. dont want people thinking they should migrate yet because they cant |
|
111 | 111 | } else { |
112 | 112 | // echo "$version_string doesnt apply"; |
113 | 113 | return false; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | public function schema_changes_before_migration() |
120 | 120 | { |
121 | 121 | // relies on 4.1's EEH_Activation::create_table |
122 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
122 | + require_once(EE_HELPERS.'EEH_Activation.helper.php'); |
|
123 | 123 | $table_name = 'esp_answer'; |
124 | 124 | $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
125 | 125 | REG_ID INT UNSIGNED NOT NULL, |
@@ -503,12 +503,12 @@ discard block |
||
503 | 503 | public function insert_default_states() |
504 | 504 | { |
505 | 505 | global $wpdb; |
506 | - $state_table = $wpdb->prefix . "esp_state"; |
|
506 | + $state_table = $wpdb->prefix."esp_state"; |
|
507 | 507 | if ($this->_get_table_analysis()->tableExists($state_table)) { |
508 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
508 | + $SQL = "SELECT COUNT('STA_ID') FROM ".$state_table; |
|
509 | 509 | $states = $wpdb->get_var($SQL); |
510 | - if (! $states) { |
|
511 | - $SQL = "INSERT INTO " . $state_table . " |
|
510 | + if ( ! $states) { |
|
511 | + $SQL = "INSERT INTO ".$state_table." |
|
512 | 512 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
513 | 513 | (1, 'US', 'AK', 'Alaska', 1), |
514 | 514 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -596,12 +596,12 @@ discard block |
||
596 | 596 | public function insert_default_countries() |
597 | 597 | { |
598 | 598 | global $wpdb; |
599 | - $country_table = $wpdb->prefix . "esp_country"; |
|
599 | + $country_table = $wpdb->prefix."esp_country"; |
|
600 | 600 | if ($this->_get_table_analysis()->tableExists($country_table)) { |
601 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
601 | + $SQL = "SELECT COUNT('CNT_ISO') FROM ".$country_table; |
|
602 | 602 | $countries = $wpdb->get_var($SQL); |
603 | - if (! $countries) { |
|
604 | - $SQL = "INSERT INTO " . $country_table . " |
|
603 | + if ( ! $countries) { |
|
604 | + $SQL = "INSERT INTO ".$country_table." |
|
605 | 605 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
606 | 606 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
607 | 607 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -846,17 +846,17 @@ discard block |
||
846 | 846 | public function insert_default_price_types() |
847 | 847 | { |
848 | 848 | global $wpdb; |
849 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
849 | + $price_type_table = $wpdb->prefix."esp_price_type"; |
|
850 | 850 | if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
851 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
851 | + $SQL = 'SELECT COUNT(PRT_ID) FROM '.$price_type_table; |
|
852 | 852 | $price_types_exist = $wpdb->get_var($SQL); |
853 | - if (! $price_types_exist) { |
|
853 | + if ( ! $price_types_exist) { |
|
854 | 854 | $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
855 | - (1, '" . esc_html__('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
|
856 | - (2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
|
857 | - (3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
|
858 | - (4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
|
859 | - (5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
|
855 | + (1, '".esc_html__('Base Price', 'event_espresso')."', 1, 0, 0, 0), |
|
856 | + (2, '" . esc_html__('Percent Discount', 'event_espresso')."', 2, 1, 20, 0), |
|
857 | + (3, '" . esc_html__('Fixed Discount', 'event_espresso')."', 2, 0, 30, 0), |
|
858 | + (4, '" . esc_html__('Percent Surcharge', 'event_espresso')."', 3, 1, 40, 0), |
|
859 | + (5, '" . esc_html__('Fixed Surcharge', 'event_espresso')."', 3, 0, 50, 0);"; |
|
860 | 860 | $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
861 | 861 | $wpdb->query($SQL); |
862 | 862 | } |
@@ -878,11 +878,11 @@ discard block |
||
878 | 878 | public function insert_default_prices() |
879 | 879 | { |
880 | 880 | global $wpdb; |
881 | - $price_table = $wpdb->prefix . "esp_price"; |
|
881 | + $price_table = $wpdb->prefix."esp_price"; |
|
882 | 882 | if ($this->_get_table_analysis()->tableExists($price_table)) { |
883 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
883 | + $SQL = 'SELECT COUNT(PRC_ID) FROM '.$price_table; |
|
884 | 884 | $prices_exist = $wpdb->get_var($SQL); |
885 | - if (! $prices_exist) { |
|
885 | + if ( ! $prices_exist) { |
|
886 | 886 | $SQL = "INSERT INTO $price_table |
887 | 887 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES |
888 | 888 | (1, 1, '0.00', 'Free Admission', '', 1, NULL, 0, 0, 0);"; |
@@ -904,11 +904,11 @@ discard block |
||
904 | 904 | public function insert_default_tickets() |
905 | 905 | { |
906 | 906 | global $wpdb; |
907 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
907 | + $ticket_table = $wpdb->prefix."esp_ticket"; |
|
908 | 908 | if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
909 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
909 | + $SQL = 'SELECT COUNT(TKT_ID) FROM '.$ticket_table; |
|
910 | 910 | $tickets_exist = $wpdb->get_var($SQL); |
911 | - if (! $tickets_exist) { |
|
911 | + if ( ! $tickets_exist) { |
|
912 | 912 | $SQL = "INSERT INTO $ticket_table |
913 | 913 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
914 | 914 | ( 1, 0, '" |
@@ -918,11 +918,11 @@ discard block |
||
918 | 918 | $wpdb->query($SQL); |
919 | 919 | } |
920 | 920 | } |
921 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
921 | + $ticket_price_table = $wpdb->prefix."esp_ticket_price"; |
|
922 | 922 | if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
923 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
923 | + $SQL = 'SELECT COUNT(TKP_ID) FROM '.$ticket_price_table; |
|
924 | 924 | $ticket_prc_exist = $wpdb->get_var($SQL); |
925 | - if (! $ticket_prc_exist) { |
|
925 | + if ( ! $ticket_prc_exist) { |
|
926 | 926 | $SQL = "INSERT INTO $ticket_price_table |
927 | 927 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
928 | 928 | ( 1, 1, 1 ) |
@@ -946,11 +946,11 @@ discard block |
||
946 | 946 | */ |
947 | 947 | public function get_or_create_country($country_name) |
948 | 948 | { |
949 | - if (! $country_name) { |
|
949 | + if ( ! $country_name) { |
|
950 | 950 | throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
951 | 951 | } |
952 | 952 | global $wpdb; |
953 | - $country_table = $wpdb->prefix . "esp_country"; |
|
953 | + $country_table = $wpdb->prefix."esp_country"; |
|
954 | 954 | if (is_int($country_name)) { |
955 | 955 | $country_name = $this->get_iso_from_3_1_country_id($country_name); |
956 | 956 | } |
@@ -958,7 +958,7 @@ discard block |
||
958 | 958 | CNT_ISO LIKE %s OR |
959 | 959 | CNT_ISO3 LIKE %s OR |
960 | 960 | CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A); |
961 | - if (! $country) { |
|
961 | + if ( ! $country) { |
|
962 | 962 | // insert a new one then |
963 | 963 | $cols_n_values = array( |
964 | 964 | 'CNT_ISO' => $this->_find_available_country_iso(2), |
@@ -978,28 +978,28 @@ discard block |
||
978 | 978 | 'CNT_active' => true, |
979 | 979 | ); |
980 | 980 | $data_types = array( |
981 | - '%s',// CNT_ISO |
|
982 | - '%s',// CNT_ISO3 |
|
983 | - '%d',// RGN_ID |
|
984 | - '%s',// CNT_name |
|
985 | - '%s',// CNT_cur_code |
|
986 | - '%s',// CNT_cur_single |
|
987 | - '%s',// CNT_cur_plural |
|
988 | - '%s',// CNT_cur_sign |
|
989 | - '%d',// CNT_cur_sign_b4 |
|
990 | - '%d',// CNT_cur_dec_plc |
|
991 | - '%s',// CNT_cur_dec_mrk |
|
992 | - '%s',// CNT_cur_thsnds |
|
993 | - '%s',// CNT_tel_code |
|
994 | - '%d',// CNT_is_EU |
|
995 | - '%d',// CNT_active |
|
981 | + '%s', // CNT_ISO |
|
982 | + '%s', // CNT_ISO3 |
|
983 | + '%d', // RGN_ID |
|
984 | + '%s', // CNT_name |
|
985 | + '%s', // CNT_cur_code |
|
986 | + '%s', // CNT_cur_single |
|
987 | + '%s', // CNT_cur_plural |
|
988 | + '%s', // CNT_cur_sign |
|
989 | + '%d', // CNT_cur_sign_b4 |
|
990 | + '%d', // CNT_cur_dec_plc |
|
991 | + '%s', // CNT_cur_dec_mrk |
|
992 | + '%s', // CNT_cur_thsnds |
|
993 | + '%s', // CNT_tel_code |
|
994 | + '%d', // CNT_is_EU |
|
995 | + '%d', // CNT_active |
|
996 | 996 | ); |
997 | 997 | $success = $wpdb->insert( |
998 | 998 | $country_table, |
999 | 999 | $cols_n_values, |
1000 | 1000 | $data_types |
1001 | 1001 | ); |
1002 | - if (! $success) { |
|
1002 | + if ( ! $success) { |
|
1003 | 1003 | throw new EE_Error($this->_create_error_message_for_db_insertion( |
1004 | 1004 | 'N/A', |
1005 | 1005 | array('country_id' => $country_name), |
@@ -1024,7 +1024,7 @@ discard block |
||
1024 | 1024 | private function _find_available_country_iso($num_letters = 2) |
1025 | 1025 | { |
1026 | 1026 | global $wpdb; |
1027 | - $country_table = $wpdb->prefix . "esp_country"; |
|
1027 | + $country_table = $wpdb->prefix."esp_country"; |
|
1028 | 1028 | $attempts = 0; |
1029 | 1029 | do { |
1030 | 1030 | $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | // keep going until we find an available country code, or we arbitrarily |
1036 | 1036 | // decide we've tried this enough. Somehow they have way too many countries |
1037 | 1037 | // (probably because they're mis-using the EE3 country_id like a custom question) |
1038 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
1038 | + }while (intval($country_with_that_iso) && $attempts < 200); |
|
1039 | 1039 | return $current_iso; |
1040 | 1040 | } |
1041 | 1041 | |
@@ -1051,7 +1051,7 @@ discard block |
||
1051 | 1051 | */ |
1052 | 1052 | public function get_or_create_state($state_name, $country_name = '') |
1053 | 1053 | { |
1054 | - if (! $state_name) { |
|
1054 | + if ( ! $state_name) { |
|
1055 | 1055 | throw new EE_Error(esc_html__( |
1056 | 1056 | "Could not get-or-create state because no state name was provided", |
1057 | 1057 | "event_espresso" |
@@ -1064,12 +1064,12 @@ discard block |
||
1064 | 1064 | $country_iso = $this->get_default_country_iso(); |
1065 | 1065 | } |
1066 | 1066 | global $wpdb; |
1067 | - $state_table = $wpdb->prefix . "esp_state"; |
|
1067 | + $state_table = $wpdb->prefix."esp_state"; |
|
1068 | 1068 | $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
1069 | 1069 | (STA_abbrev LIKE %s OR |
1070 | 1070 | STA_name LIKE %s) AND |
1071 | 1071 | CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A); |
1072 | - if (! $state) { |
|
1072 | + if ( ! $state) { |
|
1073 | 1073 | // insert a new one then |
1074 | 1074 | $cols_n_values = array( |
1075 | 1075 | 'CNT_ISO' => $country_iso, |
@@ -1078,13 +1078,13 @@ discard block |
||
1078 | 1078 | 'STA_active' => true, |
1079 | 1079 | ); |
1080 | 1080 | $data_types = array( |
1081 | - '%s',// CNT_ISO |
|
1082 | - '%s',// STA_abbrev |
|
1083 | - '%s',// STA_name |
|
1084 | - '%d',// STA_active |
|
1081 | + '%s', // CNT_ISO |
|
1082 | + '%s', // STA_abbrev |
|
1083 | + '%s', // STA_name |
|
1084 | + '%d', // STA_active |
|
1085 | 1085 | ); |
1086 | 1086 | $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
1087 | - if (! $success) { |
|
1087 | + if ( ! $success) { |
|
1088 | 1088 | throw new EE_Error($this->_create_error_message_for_db_insertion( |
1089 | 1089 | 'N/A', |
1090 | 1090 | array('state' => $state_name, 'country_id' => $country_name), |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | { |
1114 | 1114 | $matches = array(); |
1115 | 1115 | preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
1116 | - if (! $matches || count($matches) < 3) { |
|
1116 | + if ( ! $matches || count($matches) < 3) { |
|
1117 | 1117 | $hour = '00'; |
1118 | 1118 | $minutes = '00'; |
1119 | 1119 | } else { |
@@ -1418,7 +1418,7 @@ discard block |
||
1418 | 1418 | 'Declined' => 'RPP', |
1419 | 1419 | ); |
1420 | 1420 | } |
1421 | - return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
1421 | + return isset($mapping[$payment_status]) ? $mapping[$payment_status] : 'RNA'; |
|
1422 | 1422 | } |
1423 | 1423 | |
1424 | 1424 | |
@@ -1442,7 +1442,7 @@ discard block |
||
1442 | 1442 | if ($guid) { |
1443 | 1443 | // check for an existing attachment post with this guid |
1444 | 1444 | $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
1445 | - if (! $attachment_post_id) { |
|
1445 | + if ( ! $attachment_post_id) { |
|
1446 | 1446 | // post thumbnail with that GUID doesn't exist, we should create one |
1447 | 1447 | $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
1448 | 1448 | $created_attachment_post = true; |
@@ -1477,7 +1477,7 @@ discard block |
||
1477 | 1477 | $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
1478 | 1478 | // do a head request to verify the file exists |
1479 | 1479 | $head_response = wp_remote_head($original_guid); |
1480 | - if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
1480 | + if ( ! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
1481 | 1481 | return $original_guid; |
1482 | 1482 | } else { |
1483 | 1483 | return $guid_in_old_event; |
@@ -1497,7 +1497,7 @@ discard block |
||
1497 | 1497 | */ |
1498 | 1498 | private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
1499 | 1499 | { |
1500 | - if (! $guid) { |
|
1500 | + if ( ! $guid) { |
|
1501 | 1501 | $migration_stage->add_error(sprintf(esc_html__( |
1502 | 1502 | "Cannot create image attachment for a blank GUID!", |
1503 | 1503 | "event_espresso" |
@@ -1509,7 +1509,7 @@ discard block |
||
1509 | 1509 | // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
1510 | 1510 | if (strpos($guid, $wp_upload_dir['url']) === false) { |
1511 | 1511 | // image is located remotely. download it and place it in the uploads directory |
1512 | - if (! is_readable($guid)) { |
|
1512 | + if ( ! is_readable($guid)) { |
|
1513 | 1513 | $migration_stage->add_error(sprintf(esc_html__( |
1514 | 1514 | "Could not create image attachment from non-existent file: %s", |
1515 | 1515 | "event_espresso" |
@@ -1524,7 +1524,7 @@ discard block |
||
1524 | 1524 | ), $guid)); |
1525 | 1525 | return false; |
1526 | 1526 | } |
1527 | - $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
1527 | + $local_filepath = $wp_upload_dir['path'].DS.basename($guid); |
|
1528 | 1528 | $savefile = fopen($local_filepath, 'w'); |
1529 | 1529 | fwrite($savefile, $contents); |
1530 | 1530 | fclose($savefile); |
@@ -1540,7 +1540,7 @@ discard block |
||
1540 | 1540 | 'post_status' => 'inherit', |
1541 | 1541 | ); |
1542 | 1542 | $attach_id = wp_insert_attachment($attachment, $guid); |
1543 | - if (! $attach_id) { |
|
1543 | + if ( ! $attach_id) { |
|
1544 | 1544 | $migration_stage->add_error(sprintf(esc_html__( |
1545 | 1545 | "Could not create image attachment post from image '%s'. Attachment data was %s.", |
1546 | 1546 | "event_espresso" |
@@ -1549,9 +1549,9 @@ discard block |
||
1549 | 1549 | } |
1550 | 1550 | // you must first include the image.php file |
1551 | 1551 | // for the function wp_generate_attachment_metadata() to work |
1552 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1552 | + require_once(ABSPATH.'wp-admin/includes/image.php'); |
|
1553 | 1553 | $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
1554 | - if (! $attach_data) { |
|
1554 | + if ( ! $attach_data) { |
|
1555 | 1555 | $migration_stage->add_error(sprintf(esc_html__( |
1556 | 1556 | "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
1557 | 1557 | "event_espresso" |
@@ -1559,7 +1559,7 @@ discard block |
||
1559 | 1559 | return $attach_id; |
1560 | 1560 | } |
1561 | 1561 | $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
1562 | - if (! $metadata_save_result) { |
|
1562 | + if ( ! $metadata_save_result) { |
|
1563 | 1563 | $migration_stage->add_error(sprintf(esc_html__( |
1564 | 1564 | "Could not update attachment metadata for attachment %d with data %s", |
1565 | 1565 | "event_espresso" |
@@ -1605,10 +1605,10 @@ discard block |
||
1605 | 1605 | $timezone = null |
1606 | 1606 | ) { |
1607 | 1607 | $original_tz = $timezone; |
1608 | - if (! $timezone) { |
|
1608 | + if ( ! $timezone) { |
|
1609 | 1609 | $timezone = $this->_get_wp_timezone(); |
1610 | 1610 | } |
1611 | - if (! $timezone) { |
|
1611 | + if ( ! $timezone) { |
|
1612 | 1612 | $stage->add_error(sprintf( |
1613 | 1613 | esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
1614 | 1614 | $original_tz, |
@@ -1741,7 +1741,7 @@ discard block |
||
1741 | 1741 | ); |
1742 | 1742 | add_filter( |
1743 | 1743 | 'FHEE__ee_migration_page__migration_options_template', |
1744 | - array($this,'use_migration_options_from_ee3_template') |
|
1744 | + array($this, 'use_migration_options_from_ee3_template') |
|
1745 | 1745 | ); |
1746 | 1746 | } |
1747 | 1747 | |
@@ -1807,6 +1807,6 @@ discard block |
||
1807 | 1807 | */ |
1808 | 1808 | public function use_migration_options_from_ee3_template($template_filepath) |
1809 | 1809 | { |
1810 | - return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
1810 | + return EE_MAINTENANCE_TEMPLATE_PATH.'migration_options_from_ee3.template.php'; |
|
1811 | 1811 | } |
1812 | 1812 | } |
@@ -12,11 +12,11 @@ discard block |
||
12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_1_0_stages/*'); |
13 | 13 | $class_to_filepath = array(); |
14 | 14 | if (! empty($stages)) { |
15 | - foreach ($stages as $filepath) { |
|
16 | - $matches = array(); |
|
17 | - preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
18 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
19 | - } |
|
15 | + foreach ($stages as $filepath) { |
|
16 | + $matches = array(); |
|
17 | + preg_match('~4_1_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
18 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
19 | + } |
|
20 | 20 | } |
21 | 21 | // give addons a chance to autoload their stages too |
22 | 22 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_1_0__autoloaded_stages', $class_to_filepath); |
@@ -44,91 +44,91 @@ discard block |
||
44 | 44 | |
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * EE_DMS_Core_4_1_0 constructor. |
|
49 | - * |
|
50 | - * @param TableManager $table_manager |
|
51 | - * @param TableAnalysis $table_analysis |
|
52 | - */ |
|
53 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
54 | - { |
|
55 | - $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
56 | - $this->_priority = 10; |
|
57 | - $this->_migration_stages = array( |
|
58 | - new EE_DMS_4_1_0_org_options(), |
|
59 | - new EE_DMS_4_1_0_shortcodes(), |
|
60 | - new EE_DMS_4_1_0_gateways(), |
|
61 | - new EE_DMS_4_1_0_events(), |
|
62 | - new EE_DMS_4_1_0_prices(), |
|
63 | - new EE_DMS_4_1_0_category_details(), |
|
64 | - new EE_DMS_4_1_0_event_category(), |
|
65 | - new EE_DMS_4_1_0_venues(), |
|
66 | - new EE_DMS_4_1_0_event_venue(), |
|
67 | - new EE_DMS_4_1_0_question_groups(), |
|
68 | - new EE_DMS_4_1_0_questions(), |
|
69 | - new EE_DMS_4_1_0_question_group_question(), |
|
70 | - new EE_DMS_4_1_0_event_question_group(), |
|
71 | - new EE_DMS_4_1_0_attendees(), |
|
72 | - new EE_DMS_4_1_0_line_items(), |
|
73 | - new EE_DMS_4_1_0_answers(), |
|
74 | - new EE_DMS_4_1_0_checkins(), |
|
75 | - ); |
|
76 | - parent::__construct($table_manager, $table_analysis); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
83 | - * |
|
84 | - * @global wpdb $wpdb |
|
85 | - * @return boolean |
|
86 | - */ |
|
87 | - private function _checkin_table_exists() |
|
88 | - { |
|
89 | - global $wpdb; |
|
90 | - $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
91 | - if ($results) { |
|
92 | - return true; |
|
93 | - } else { |
|
94 | - return false; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - public function can_migrate_from_version($version_array) |
|
101 | - { |
|
102 | - $version_string = $version_array['Core']; |
|
103 | - if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
47 | + /** |
|
48 | + * EE_DMS_Core_4_1_0 constructor. |
|
49 | + * |
|
50 | + * @param TableManager $table_manager |
|
51 | + * @param TableAnalysis $table_analysis |
|
52 | + */ |
|
53 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
54 | + { |
|
55 | + $this->_pretty_name = esc_html__("Data Migration from Event Espresso 3 to Event Espresso 4.1.0", "event_espresso"); |
|
56 | + $this->_priority = 10; |
|
57 | + $this->_migration_stages = array( |
|
58 | + new EE_DMS_4_1_0_org_options(), |
|
59 | + new EE_DMS_4_1_0_shortcodes(), |
|
60 | + new EE_DMS_4_1_0_gateways(), |
|
61 | + new EE_DMS_4_1_0_events(), |
|
62 | + new EE_DMS_4_1_0_prices(), |
|
63 | + new EE_DMS_4_1_0_category_details(), |
|
64 | + new EE_DMS_4_1_0_event_category(), |
|
65 | + new EE_DMS_4_1_0_venues(), |
|
66 | + new EE_DMS_4_1_0_event_venue(), |
|
67 | + new EE_DMS_4_1_0_question_groups(), |
|
68 | + new EE_DMS_4_1_0_questions(), |
|
69 | + new EE_DMS_4_1_0_question_group_question(), |
|
70 | + new EE_DMS_4_1_0_event_question_group(), |
|
71 | + new EE_DMS_4_1_0_attendees(), |
|
72 | + new EE_DMS_4_1_0_line_items(), |
|
73 | + new EE_DMS_4_1_0_answers(), |
|
74 | + new EE_DMS_4_1_0_checkins(), |
|
75 | + ); |
|
76 | + parent::__construct($table_manager, $table_analysis); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Checks if this 3.1 Check-in table exists. If it doesn't we can't migrate Check-ins |
|
83 | + * |
|
84 | + * @global wpdb $wpdb |
|
85 | + * @return boolean |
|
86 | + */ |
|
87 | + private function _checkin_table_exists() |
|
88 | + { |
|
89 | + global $wpdb; |
|
90 | + $results = $wpdb->get_results("SHOW TABLES LIKE '" . $wpdb->prefix . "events_attendee_checkin" . "'"); |
|
91 | + if ($results) { |
|
92 | + return true; |
|
93 | + } else { |
|
94 | + return false; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + public function can_migrate_from_version($version_array) |
|
101 | + { |
|
102 | + $version_string = $version_array['Core']; |
|
103 | + if (version_compare($version_string, '4.0.0', '<=') && version_compare($version_string, '3.1.26', '>=')) { |
|
104 | 104 | // echo "$version_string can be migrated fro"; |
105 | - return true; |
|
106 | - } elseif (! $version_string) { |
|
105 | + return true; |
|
106 | + } elseif (! $version_string) { |
|
107 | 107 | // echo "no version string provided: $version_string"; |
108 | - // no version string provided... this must be pre 4.1 |
|
109 | - // because since 4.1 we're |
|
110 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
111 | - } else { |
|
108 | + // no version string provided... this must be pre 4.1 |
|
109 | + // because since 4.1 we're |
|
110 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
111 | + } else { |
|
112 | 112 | // echo "$version_string doesnt apply"; |
113 | - return false; |
|
114 | - } |
|
115 | - } |
|
113 | + return false; |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | 118 | |
119 | - public function schema_changes_before_migration() |
|
120 | - { |
|
121 | - // relies on 4.1's EEH_Activation::create_table |
|
122 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
123 | - $table_name = 'esp_answer'; |
|
124 | - $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
119 | + public function schema_changes_before_migration() |
|
120 | + { |
|
121 | + // relies on 4.1's EEH_Activation::create_table |
|
122 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
123 | + $table_name = 'esp_answer'; |
|
124 | + $sql = " ANS_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
125 | 125 | REG_ID INT UNSIGNED NOT NULL, |
126 | 126 | QST_ID INT UNSIGNED NOT NULL, |
127 | 127 | ANS_value TEXT NOT NULL, |
128 | 128 | PRIMARY KEY (ANS_ID)"; |
129 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
130 | - $table_name = 'esp_attendee_meta'; |
|
131 | - $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
129 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
130 | + $table_name = 'esp_attendee_meta'; |
|
131 | + $sql = "ATTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
132 | 132 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
133 | 133 | ATT_fname VARCHAR(45) NOT NULL, |
134 | 134 | ATT_lname VARCHAR(45) NOT NULL, |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | KEY ATT_fname (ATT_fname), |
145 | 145 | KEY ATT_lname (ATT_lname), |
146 | 146 | KEY ATT_email (ATT_email(191))"; |
147 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
148 | - $table_name = 'esp_country'; |
|
149 | - $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
147 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
148 | + $table_name = 'esp_country'; |
|
149 | + $sql = "CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
|
150 | 150 | CNT_ISO3 VARCHAR(3) COLLATE utf8_bin NOT NULL, |
151 | 151 | RGN_ID TINYINT(3) UNSIGNED DEFAULT NULL, |
152 | 152 | CNT_name VARCHAR(45) COLLATE utf8_bin NOT NULL, |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | CNT_is_EU TINYINT(1) DEFAULT '0', |
163 | 163 | CNT_active TINYINT(1) DEFAULT '0', |
164 | 164 | PRIMARY KEY (CNT_ISO)"; |
165 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
166 | - $table_name = 'esp_datetime'; |
|
167 | - $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
165 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
166 | + $table_name = 'esp_datetime'; |
|
167 | + $sql = "DTT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
168 | 168 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
169 | 169 | DTT_EVT_start DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
170 | 170 | DTT_EVT_end DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | PRIMARY KEY (DTT_ID), |
178 | 178 | KEY EVT_ID (EVT_ID), |
179 | 179 | KEY DTT_is_primary (DTT_is_primary)"; |
180 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
181 | - $table_name = 'esp_event_meta'; |
|
182 | - $sql = " |
|
180 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
181 | + $table_name = 'esp_event_meta'; |
|
182 | + $sql = " |
|
183 | 183 | EVTM_ID INT NOT NULL AUTO_INCREMENT, |
184 | 184 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
185 | 185 | EVT_display_desc TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
@@ -194,31 +194,31 @@ discard block |
||
194 | 194 | EVT_external_URL VARCHAR(200) NULL, |
195 | 195 | EVT_donations TINYINT(1) NULL, |
196 | 196 | PRIMARY KEY (EVTM_ID)"; |
197 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_event_question_group'; |
|
199 | - $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_event_question_group'; |
|
199 | + $sql = "EQG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
200 | 200 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
201 | 201 | QSG_ID INT UNSIGNED NOT NULL, |
202 | 202 | EQG_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
203 | 203 | PRIMARY KEY (EQG_ID)"; |
204 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
205 | - $table_name = 'esp_event_venue'; |
|
206 | - $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
204 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
205 | + $table_name = 'esp_event_venue'; |
|
206 | + $sql = "EVV_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
207 | 207 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
208 | 208 | VNU_ID BIGINT(20) UNSIGNED NOT NULL, |
209 | 209 | EVV_primary TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
210 | 210 | PRIMARY KEY (EVV_ID)"; |
211 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
212 | - $table_name = 'esp_extra_meta'; |
|
213 | - $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
211 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
212 | + $table_name = 'esp_extra_meta'; |
|
213 | + $sql = "EXM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
214 | 214 | OBJ_ID INT(11) DEFAULT NULL, |
215 | 215 | EXM_type VARCHAR(45) DEFAULT NULL, |
216 | 216 | EXM_key VARCHAR(45) DEFAULT NULL, |
217 | 217 | EXM_value TEXT, |
218 | 218 | PRIMARY KEY (EXM_ID)"; |
219 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
220 | - $table_name = 'esp_line_item'; |
|
221 | - $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
219 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
220 | + $table_name = 'esp_line_item'; |
|
221 | + $sql = "LIN_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
222 | 222 | LIN_code VARCHAR(245) NOT NULL DEFAULT '', |
223 | 223 | TXN_ID INT(11) DEFAULT NULL, |
224 | 224 | LIN_name VARCHAR(245) NOT NULL DEFAULT '', |
@@ -234,18 +234,18 @@ discard block |
||
234 | 234 | OBJ_ID INT(11) DEFAULT NULL, |
235 | 235 | OBJ_type VARCHAR(45)DEFAULT NULL, |
236 | 236 | PRIMARY KEY (LIN_ID)"; |
237 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
238 | - $table_name = 'esp_message_template'; |
|
239 | - $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
237 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
238 | + $table_name = 'esp_message_template'; |
|
239 | + $sql = "MTP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
240 | 240 | GRP_ID INT(10) UNSIGNED NOT NULL, |
241 | 241 | MTP_context VARCHAR(50) NOT NULL, |
242 | 242 | MTP_template_field VARCHAR(30) NOT NULL, |
243 | 243 | MTP_content TEXT NOT NULL, |
244 | 244 | PRIMARY KEY (MTP_ID), |
245 | 245 | KEY GRP_ID (GRP_ID)"; |
246 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
247 | - $table_name = 'esp_message_template_group'; |
|
248 | - $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
246 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
247 | + $table_name = 'esp_message_template_group'; |
|
248 | + $sql = "GRP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
249 | 249 | EVT_ID BIGINT(20) UNSIGNED DEFAULT NULL, |
250 | 250 | MTP_user_id INT(10) NOT NULL DEFAULT '1', |
251 | 251 | MTP_messenger VARCHAR(30) NOT NULL, |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | PRIMARY KEY (GRP_ID), |
258 | 258 | KEY EVT_ID (EVT_ID), |
259 | 259 | KEY MTP_user_id (MTP_user_id)"; |
260 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
261 | - $table_name = 'esp_payment'; |
|
262 | - $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
260 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
261 | + $table_name = 'esp_payment'; |
|
262 | + $sql = "PAY_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
263 | 263 | TXN_ID INT(10) UNSIGNED DEFAULT NULL, |
264 | 264 | STS_ID VARCHAR(3) COLLATE utf8_bin DEFAULT NULL, |
265 | 265 | PAY_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -275,9 +275,9 @@ discard block |
||
275 | 275 | PRIMARY KEY (PAY_ID), |
276 | 276 | KEY TXN_ID (TXN_ID), |
277 | 277 | KEY PAY_timestamp (PAY_timestamp)"; |
278 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
279 | - $table_name = "esp_ticket"; |
|
280 | - $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
278 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
279 | + $table_name = "esp_ticket"; |
|
280 | + $sql = "TKT_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
281 | 281 | TTM_ID INT(10) UNSIGNED NOT NULL, |
282 | 282 | TKT_name VARCHAR(245) NOT NULL DEFAULT '', |
283 | 283 | TKT_description TEXT NOT NULL, |
@@ -296,28 +296,28 @@ discard block |
||
296 | 296 | TKT_parent INT(10) UNSIGNED DEFAULT '0', |
297 | 297 | TKT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
298 | 298 | PRIMARY KEY (TKT_ID)"; |
299 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
300 | - $table_name = "esp_ticket_price"; |
|
301 | - $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
299 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
300 | + $table_name = "esp_ticket_price"; |
|
301 | + $sql = "TKP_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
302 | 302 | TKT_ID INT(10) UNSIGNED NOT NULL, |
303 | 303 | PRC_ID INT(10) UNSIGNED NOT NULL, |
304 | 304 | PRIMARY KEY (TKP_ID)"; |
305 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
306 | - $table_name = "esp_datetime_ticket"; |
|
307 | - $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
305 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
306 | + $table_name = "esp_datetime_ticket"; |
|
307 | + $sql = "DTK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
308 | 308 | DTT_ID INT(10) UNSIGNED NOT NULL, |
309 | 309 | TKT_ID INT(10) UNSIGNED NOT NULL, |
310 | 310 | PRIMARY KEY (DTK_ID)"; |
311 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
312 | - $table_name = "esp_ticket_template"; |
|
313 | - $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
311 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
312 | + $table_name = "esp_ticket_template"; |
|
313 | + $sql = "TTM_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
314 | 314 | TTM_name VARCHAR(45) NOT NULL, |
315 | 315 | TTM_description TEXT, |
316 | 316 | TTM_file VARCHAR(45), |
317 | 317 | PRIMARY KEY (TTM_ID)"; |
318 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
319 | - $table_name = "esp_price"; |
|
320 | - $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
318 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
319 | + $table_name = "esp_price"; |
|
320 | + $sql = "PRC_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
321 | 321 | PRT_ID TINYINT(3) UNSIGNED NOT NULL, |
322 | 322 | PRC_amount DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
323 | 323 | PRC_name VARCHAR(245) NOT NULL, |
@@ -328,9 +328,9 @@ discard block |
||
328 | 328 | PRC_order TINYINT(3) UNSIGNED NOT NULL DEFAULT '0', |
329 | 329 | PRC_parent INT(10) UNSIGNED DEFAULT 0, |
330 | 330 | PRIMARY KEY (PRC_ID)"; |
331 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
332 | - $table_name = "esp_price_type"; |
|
333 | - $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
331 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
332 | + $table_name = "esp_price_type"; |
|
333 | + $sql = "PRT_ID TINYINT(3) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
334 | 334 | PRT_name VARCHAR(45) NOT NULL, |
335 | 335 | PBT_ID TINYINT(3) UNSIGNED NOT NULL DEFAULT '1', |
336 | 336 | PRT_is_percent TINYINT(1) NOT NULL DEFAULT '0', |
@@ -338,9 +338,9 @@ discard block |
||
338 | 338 | PRT_deleted TINYINT(1) NOT NULL DEFAULT '0', |
339 | 339 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
340 | 340 | PRIMARY KEY (PRT_ID)"; |
341 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
342 | - $table_name = 'esp_question'; |
|
343 | - $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
341 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
342 | + $table_name = 'esp_question'; |
|
343 | + $sql = 'QST_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
344 | 344 | QST_display_text TEXT NOT NULL, |
345 | 345 | QST_admin_label VARCHAR(255) NOT NULL, |
346 | 346 | QST_system VARCHAR(25) DEFAULT NULL, |
@@ -352,10 +352,10 @@ discard block |
||
352 | 352 | QST_wp_user BIGINT UNSIGNED NULL, |
353 | 353 | QST_deleted TINYINT UNSIGNED NOT NULL DEFAULT 0, |
354 | 354 | PRIMARY KEY (QST_ID)'; |
355 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
356 | - $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
357 | - $table_name = 'esp_question_group'; |
|
358 | - $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
355 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
356 | + $this->_get_table_manager()->dropIndex('esp_question_group', 'QSG_identifier_UNIQUE'); |
|
357 | + $table_name = 'esp_question_group'; |
|
358 | + $sql = 'QSG_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
359 | 359 | QSG_name VARCHAR(255) NOT NULL, |
360 | 360 | QSG_identifier VARCHAR(100) NOT NULL, |
361 | 361 | QSG_desc TEXT NULL, |
@@ -366,23 +366,23 @@ discard block |
||
366 | 366 | QSG_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
367 | 367 | PRIMARY KEY (QSG_ID), |
368 | 368 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier ASC)'; |
369 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
370 | - $table_name = 'esp_question_group_question'; |
|
371 | - $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
369 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
370 | + $table_name = 'esp_question_group_question'; |
|
371 | + $sql = "QGQ_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
372 | 372 | QSG_ID INT UNSIGNED NOT NULL, |
373 | 373 | QST_ID INT UNSIGNED NOT NULL, |
374 | 374 | PRIMARY KEY (QGQ_ID) "; |
375 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
376 | - $table_name = 'esp_question_option'; |
|
377 | - $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
375 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
376 | + $table_name = 'esp_question_option'; |
|
377 | + $sql = "QSO_ID INT UNSIGNED NOT NULL AUTO_INCREMENT, |
|
378 | 378 | QSO_value VARCHAR(255) NOT NULL, |
379 | 379 | QSO_desc TEXT NOT NULL, |
380 | 380 | QST_ID INT UNSIGNED NOT NULL, |
381 | 381 | QSO_deleted TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, |
382 | 382 | PRIMARY KEY (QSO_ID)"; |
383 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
384 | - $table_name = 'esp_registration'; |
|
385 | - $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
383 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
384 | + $table_name = 'esp_registration'; |
|
385 | + $sql = "REG_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
386 | 386 | EVT_ID BIGINT(20) UNSIGNED NOT NULL, |
387 | 387 | ATT_ID BIGINT(20) UNSIGNED NOT NULL, |
388 | 388 | TXN_ID INT(10) UNSIGNED NOT NULL, |
@@ -405,25 +405,25 @@ discard block |
||
405 | 405 | KEY STS_ID (STS_ID), |
406 | 406 | KEY REG_url_link (REG_url_link), |
407 | 407 | KEY REG_code (REG_code)"; |
408 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
409 | - $table_name = 'esp_checkin'; |
|
410 | - $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
408 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
409 | + $table_name = 'esp_checkin'; |
|
410 | + $sql = "CHK_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
411 | 411 | REG_ID INT(10) UNSIGNED NOT NULL, |
412 | 412 | DTT_ID INT(10) UNSIGNED NOT NULL, |
413 | 413 | CHK_in TINYINT(1) UNSIGNED NOT NULL DEFAULT 1, |
414 | 414 | CHK_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
415 | 415 | PRIMARY KEY (CHK_ID)"; |
416 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
417 | - $table_name = 'esp_state'; |
|
418 | - $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
416 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
417 | + $table_name = 'esp_state'; |
|
418 | + $sql = "STA_ID smallint(5) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
419 | 419 | CNT_ISO VARCHAR(2) COLLATE utf8_bin NOT NULL, |
420 | 420 | STA_abbrev VARCHAR(6) COLLATE utf8_bin NOT NULL, |
421 | 421 | STA_name VARCHAR(100) COLLATE utf8_bin NOT NULL, |
422 | 422 | STA_active TINYINT(1) DEFAULT '1', |
423 | 423 | PRIMARY KEY (STA_ID)"; |
424 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | - $table_name = 'esp_status'; |
|
426 | - $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
424 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | + $table_name = 'esp_status'; |
|
426 | + $sql = "STS_ID VARCHAR(3) COLLATE utf8_bin NOT NULL, |
|
427 | 427 | STS_code VARCHAR(45) COLLATE utf8_bin NOT NULL, |
428 | 428 | STS_type set('event','registration','transaction','payment','email') COLLATE utf8_bin NOT NULL, |
429 | 429 | STS_can_edit TINYINT(1) NOT NULL DEFAULT 0, |
@@ -431,9 +431,9 @@ discard block |
||
431 | 431 | STS_open TINYINT(1) NOT NULL DEFAULT 1, |
432 | 432 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
433 | 433 | KEY STS_type (STS_type)"; |
434 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
435 | - $table_name = 'esp_transaction'; |
|
436 | - $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
434 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
435 | + $table_name = 'esp_transaction'; |
|
436 | + $sql = "TXN_ID INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, |
|
437 | 437 | TXN_timestamp DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', |
438 | 438 | TXN_total DECIMAL(10,3) DEFAULT '0.00', |
439 | 439 | TXN_paid DECIMAL(10,3) NOT NULL DEFAULT '0.00', |
@@ -443,9 +443,9 @@ discard block |
||
443 | 443 | PRIMARY KEY (TXN_ID), |
444 | 444 | KEY TXN_timestamp (TXN_timestamp), |
445 | 445 | KEY STS_ID (STS_ID)"; |
446 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
447 | - $table_name = 'esp_venue_meta'; |
|
448 | - $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
446 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
447 | + $table_name = 'esp_venue_meta'; |
|
448 | + $sql = "VNUM_ID INT(11) NOT NULL AUTO_INCREMENT, |
|
449 | 449 | VNU_ID BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, |
450 | 450 | VNU_address VARCHAR(255) DEFAULT NULL, |
451 | 451 | VNU_address2 VARCHAR(255) DEFAULT NULL, |
@@ -463,52 +463,52 @@ discard block |
||
463 | 463 | PRIMARY KEY (VNUM_ID), |
464 | 464 | KEY STA_ID (STA_ID), |
465 | 465 | KEY CNT_ISO (CNT_ISO)"; |
466 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
467 | - // setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
468 | - // (because many need to convert old string states to foreign keys into the states table) |
|
469 | - $this->insert_default_states(); |
|
470 | - $this->insert_default_countries(); |
|
471 | - // setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
472 | - $this->insert_default_price_types(); |
|
473 | - $this->insert_default_prices(); |
|
474 | - $this->insert_default_tickets(); |
|
475 | - // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
476 | - EE_Config::instance()->update_espresso_config(false, true); |
|
477 | - return true; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
484 | - * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
485 | - * leave them for now. Mayeb remove them in 4.5 or something. |
|
486 | - * |
|
487 | - * @return boolean |
|
488 | - */ |
|
489 | - public function schema_changes_after_migration() |
|
490 | - { |
|
491 | - return true; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * insert_default_states |
|
498 | - * |
|
499 | - * @access public |
|
500 | - * @static |
|
501 | - * @return void |
|
502 | - */ |
|
503 | - public function insert_default_states() |
|
504 | - { |
|
505 | - global $wpdb; |
|
506 | - $state_table = $wpdb->prefix . "esp_state"; |
|
507 | - if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
508 | - $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
509 | - $states = $wpdb->get_var($SQL); |
|
510 | - if (! $states) { |
|
511 | - $SQL = "INSERT INTO " . $state_table . " |
|
466 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
467 | + // setting up the DEFAULT stats and countries is also essential for the data migrations to run |
|
468 | + // (because many need to convert old string states to foreign keys into the states table) |
|
469 | + $this->insert_default_states(); |
|
470 | + $this->insert_default_countries(); |
|
471 | + // setting up DEFAULT prices, price types, and tickets is also essential for the price migrations |
|
472 | + $this->insert_default_price_types(); |
|
473 | + $this->insert_default_prices(); |
|
474 | + $this->insert_default_tickets(); |
|
475 | + // setting up the config wp option pretty well counts as a 'schema change', or at least should happen ehre |
|
476 | + EE_Config::instance()->update_espresso_config(false, true); |
|
477 | + return true; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * Yes we could have cleaned up the ee3 tables here. But just in case someone |
|
484 | + * didn't backup their DB, and decides they want ot keep using EE3, we'll |
|
485 | + * leave them for now. Mayeb remove them in 4.5 or something. |
|
486 | + * |
|
487 | + * @return boolean |
|
488 | + */ |
|
489 | + public function schema_changes_after_migration() |
|
490 | + { |
|
491 | + return true; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * insert_default_states |
|
498 | + * |
|
499 | + * @access public |
|
500 | + * @static |
|
501 | + * @return void |
|
502 | + */ |
|
503 | + public function insert_default_states() |
|
504 | + { |
|
505 | + global $wpdb; |
|
506 | + $state_table = $wpdb->prefix . "esp_state"; |
|
507 | + if ($this->_get_table_analysis()->tableExists($state_table)) { |
|
508 | + $SQL = "SELECT COUNT('STA_ID') FROM " . $state_table; |
|
509 | + $states = $wpdb->get_var($SQL); |
|
510 | + if (! $states) { |
|
511 | + $SQL = "INSERT INTO " . $state_table . " |
|
512 | 512 | (STA_ID, CNT_ISO, STA_abbrev, STA_name, STA_active) VALUES |
513 | 513 | (1, 'US', 'AK', 'Alaska', 1), |
514 | 514 | (2, 'US', 'AL', 'Alabama', 1), |
@@ -579,29 +579,29 @@ discard block |
||
579 | 579 | (67, 'CA', 'PE', 'Prince Edward Island', 1), |
580 | 580 | (68, 'CA', 'QC', 'Quebec', 1), |
581 | 581 | (69, 'CA', 'SK', 'Saskatchewan', 1);"; |
582 | - $wpdb->query($SQL); |
|
583 | - } |
|
584 | - } |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * insert_default_countries |
|
591 | - * |
|
592 | - * @access public |
|
593 | - * @static |
|
594 | - * @return void |
|
595 | - */ |
|
596 | - public function insert_default_countries() |
|
597 | - { |
|
598 | - global $wpdb; |
|
599 | - $country_table = $wpdb->prefix . "esp_country"; |
|
600 | - if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
601 | - $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
602 | - $countries = $wpdb->get_var($SQL); |
|
603 | - if (! $countries) { |
|
604 | - $SQL = "INSERT INTO " . $country_table . " |
|
582 | + $wpdb->query($SQL); |
|
583 | + } |
|
584 | + } |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * insert_default_countries |
|
591 | + * |
|
592 | + * @access public |
|
593 | + * @static |
|
594 | + * @return void |
|
595 | + */ |
|
596 | + public function insert_default_countries() |
|
597 | + { |
|
598 | + global $wpdb; |
|
599 | + $country_table = $wpdb->prefix . "esp_country"; |
|
600 | + if ($this->_get_table_analysis()->tableExists($country_table)) { |
|
601 | + $SQL = "SELECT COUNT('CNT_ISO') FROM " . $country_table; |
|
602 | + $countries = $wpdb->get_var($SQL); |
|
603 | + if (! $countries) { |
|
604 | + $SQL = "INSERT INTO " . $country_table . " |
|
605 | 605 | (CNT_ISO, CNT_ISO3, RGN_ID, CNT_name, CNT_cur_code, CNT_cur_single, CNT_cur_plural, CNT_cur_sign, CNT_cur_sign_b4, CNT_cur_dec_plc, CNT_tel_code, CNT_is_EU, CNT_active) VALUES |
606 | 606 | ('AD', 'AND', 0, 'Andorra', 'EUR', 'Euro', 'Euros', '€', 1, 2, '+376', 0, 0), |
607 | 607 | ('AE', 'ARE', 0, 'United Arab Emirates', 'AED', 'Dirham', 'Dirhams', 'د.إ', 1, 2, '+971', 0, 0), |
@@ -829,984 +829,984 @@ discard block |
||
829 | 829 | ('ZA', 'ZAF', 0, 'South Africa', 'ZAR', 'Rand', 'Rands', 'R', 1, 2, '+27', 0, 0), |
830 | 830 | ('ZM', 'ZMB', 0, 'Zambia', 'ZMK', 'Kwacha', 'Kwachas', '', 1, 2, '+260', 0, 0), |
831 | 831 | ('ZW', 'ZWE', 0, 'Zimbabwe', 'ZWD', 'Dollar', 'Dollars', 'Z$', 1, 2, '+263', 0, 0);"; |
832 | - $wpdb->query($SQL); |
|
833 | - } |
|
834 | - } |
|
835 | - } |
|
836 | - |
|
837 | - |
|
838 | - |
|
839 | - /** |
|
840 | - * insert_default_price_types |
|
841 | - * |
|
842 | - * @access public |
|
843 | - * @static |
|
844 | - * @return void |
|
845 | - */ |
|
846 | - public function insert_default_price_types() |
|
847 | - { |
|
848 | - global $wpdb; |
|
849 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
850 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
851 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
852 | - $price_types_exist = $wpdb->get_var($SQL); |
|
853 | - if (! $price_types_exist) { |
|
854 | - $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
832 | + $wpdb->query($SQL); |
|
833 | + } |
|
834 | + } |
|
835 | + } |
|
836 | + |
|
837 | + |
|
838 | + |
|
839 | + /** |
|
840 | + * insert_default_price_types |
|
841 | + * |
|
842 | + * @access public |
|
843 | + * @static |
|
844 | + * @return void |
|
845 | + */ |
|
846 | + public function insert_default_price_types() |
|
847 | + { |
|
848 | + global $wpdb; |
|
849 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
850 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
851 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table; |
|
852 | + $price_types_exist = $wpdb->get_var($SQL); |
|
853 | + if (! $price_types_exist) { |
|
854 | + $SQL = "INSERT INTO $price_type_table ( PRT_ID, PRT_name, PBT_ID, PRT_is_percent, PRT_order, PRT_deleted ) VALUES |
|
855 | 855 | (1, '" . esc_html__('Base Price', 'event_espresso') . "', 1, 0, 0, 0), |
856 | 856 | (2, '" . esc_html__('Percent Discount', 'event_espresso') . "', 2, 1, 20, 0), |
857 | 857 | (3, '" . esc_html__('Fixed Discount', 'event_espresso') . "', 2, 0, 30, 0), |
858 | 858 | (4, '" . esc_html__('Percent Surcharge', 'event_espresso') . "', 3, 1, 40, 0), |
859 | 859 | (5, '" . esc_html__('Fixed Surcharge', 'event_espresso') . "', 3, 0, 50, 0);"; |
860 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
861 | - $wpdb->query($SQL); |
|
862 | - } |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - |
|
868 | - /** |
|
869 | - * insert_default_prices. We assume we're upgrading to regular here. |
|
870 | - * If we're INSTALLING 4.1 CAF, then we add a few extra DEFAULT prices |
|
871 | - * when EEH_Activaion's initialize_db_content is called via ahook in |
|
872 | - * EE_BRewing_regular |
|
873 | - * |
|
874 | - * @access public |
|
875 | - * @static |
|
876 | - * @return void |
|
877 | - */ |
|
878 | - public function insert_default_prices() |
|
879 | - { |
|
880 | - global $wpdb; |
|
881 | - $price_table = $wpdb->prefix . "esp_price"; |
|
882 | - if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
883 | - $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
884 | - $prices_exist = $wpdb->get_var($SQL); |
|
885 | - if (! $prices_exist) { |
|
886 | - $SQL = "INSERT INTO $price_table |
|
860 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_price_types__SQL', $SQL); |
|
861 | + $wpdb->query($SQL); |
|
862 | + } |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + |
|
868 | + /** |
|
869 | + * insert_default_prices. We assume we're upgrading to regular here. |
|
870 | + * If we're INSTALLING 4.1 CAF, then we add a few extra DEFAULT prices |
|
871 | + * when EEH_Activaion's initialize_db_content is called via ahook in |
|
872 | + * EE_BRewing_regular |
|
873 | + * |
|
874 | + * @access public |
|
875 | + * @static |
|
876 | + * @return void |
|
877 | + */ |
|
878 | + public function insert_default_prices() |
|
879 | + { |
|
880 | + global $wpdb; |
|
881 | + $price_table = $wpdb->prefix . "esp_price"; |
|
882 | + if ($this->_get_table_analysis()->tableExists($price_table)) { |
|
883 | + $SQL = 'SELECT COUNT(PRC_ID) FROM ' . $price_table; |
|
884 | + $prices_exist = $wpdb->get_var($SQL); |
|
885 | + if (! $prices_exist) { |
|
886 | + $SQL = "INSERT INTO $price_table |
|
887 | 887 | (PRC_ID, PRT_ID, PRC_amount, PRC_name, PRC_desc, PRC_is_default, PRC_overrides, PRC_order, PRC_deleted, PRC_parent ) VALUES |
888 | 888 | (1, 1, '0.00', 'Free Admission', '', 1, NULL, 0, 0, 0);"; |
889 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
890 | - $wpdb->query($SQL); |
|
891 | - } |
|
892 | - } |
|
893 | - } |
|
894 | - |
|
895 | - |
|
896 | - |
|
897 | - /** |
|
898 | - * insert DEFAULT ticket |
|
899 | - * |
|
900 | - * @access public |
|
901 | - * @static |
|
902 | - * @return void |
|
903 | - */ |
|
904 | - public function insert_default_tickets() |
|
905 | - { |
|
906 | - global $wpdb; |
|
907 | - $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
908 | - if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
909 | - $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
910 | - $tickets_exist = $wpdb->get_var($SQL); |
|
911 | - if (! $tickets_exist) { |
|
912 | - $SQL = "INSERT INTO $ticket_table |
|
889 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_prices__SQL', $SQL); |
|
890 | + $wpdb->query($SQL); |
|
891 | + } |
|
892 | + } |
|
893 | + } |
|
894 | + |
|
895 | + |
|
896 | + |
|
897 | + /** |
|
898 | + * insert DEFAULT ticket |
|
899 | + * |
|
900 | + * @access public |
|
901 | + * @static |
|
902 | + * @return void |
|
903 | + */ |
|
904 | + public function insert_default_tickets() |
|
905 | + { |
|
906 | + global $wpdb; |
|
907 | + $ticket_table = $wpdb->prefix . "esp_ticket"; |
|
908 | + if ($this->_get_table_analysis()->tableExists($ticket_table)) { |
|
909 | + $SQL = 'SELECT COUNT(TKT_ID) FROM ' . $ticket_table; |
|
910 | + $tickets_exist = $wpdb->get_var($SQL); |
|
911 | + if (! $tickets_exist) { |
|
912 | + $SQL = "INSERT INTO $ticket_table |
|
913 | 913 | ( TKT_ID, TTM_ID, TKT_name, TKT_description, TKT_qty, TKT_sold, TKT_uses, TKT_min, TKT_max, TKT_price, TKT_start_date, TKT_end_date, TKT_taxable, TKT_order, TKT_row, TKT_is_default, TKT_parent, TKT_deleted ) VALUES |
914 | 914 | ( 1, 0, '" |
915 | - . esc_html__("Free Ticket", "event_espresso") |
|
916 | - . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
917 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
918 | - $wpdb->query($SQL); |
|
919 | - } |
|
920 | - } |
|
921 | - $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
922 | - if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
923 | - $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
924 | - $ticket_prc_exist = $wpdb->get_var($SQL); |
|
925 | - if (! $ticket_prc_exist) { |
|
926 | - $SQL = "INSERT INTO $ticket_price_table |
|
915 | + . esc_html__("Free Ticket", "event_espresso") |
|
916 | + . "', '', 100, 0, -1, 0, -1, 0.00, '0000-00-00 00:00:00', '0000-00-00 00:00:00', 0, 0, 1, 1, 0, 0);"; |
|
917 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL', $SQL); |
|
918 | + $wpdb->query($SQL); |
|
919 | + } |
|
920 | + } |
|
921 | + $ticket_price_table = $wpdb->prefix . "esp_ticket_price"; |
|
922 | + if ($this->_get_table_analysis()->tableExists($ticket_price_table)) { |
|
923 | + $SQL = 'SELECT COUNT(TKP_ID) FROM ' . $ticket_price_table; |
|
924 | + $ticket_prc_exist = $wpdb->get_var($SQL); |
|
925 | + if (! $ticket_prc_exist) { |
|
926 | + $SQL = "INSERT INTO $ticket_price_table |
|
927 | 927 | ( TKP_ID, TKT_ID, PRC_ID ) VALUES |
928 | 928 | ( 1, 1, 1 ) |
929 | 929 | "; |
930 | - $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
931 | - $wpdb->query($SQL); |
|
932 | - } |
|
933 | - } |
|
934 | - } |
|
935 | - |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
940 | - * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
941 | - * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
942 | - * |
|
943 | - * @global type $wpdb |
|
944 | - * @param string $country_name |
|
945 | - * @return array where keys are columns, values are column values |
|
946 | - */ |
|
947 | - public function get_or_create_country($country_name) |
|
948 | - { |
|
949 | - if (! $country_name) { |
|
950 | - throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
951 | - } |
|
952 | - global $wpdb; |
|
953 | - $country_table = $wpdb->prefix . "esp_country"; |
|
954 | - if (is_int($country_name)) { |
|
955 | - $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
956 | - } |
|
957 | - $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
930 | + $SQL = apply_filters('FHEE__EE_DMS_4_1_0__insert_default_tickets__SQL__ticket_price', $SQL); |
|
931 | + $wpdb->query($SQL); |
|
932 | + } |
|
933 | + } |
|
934 | + } |
|
935 | + |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * Gets a country entry as an array, or creates one if none is found. Much like EEM_Country::instance()->get_one(), |
|
940 | + * but is independent of outside code which can change in future versions of EE. Also, $country_name CAN be a 3.1 |
|
941 | + * country ID (int), a 2-letter ISO, 3-letter ISO, or name |
|
942 | + * |
|
943 | + * @global type $wpdb |
|
944 | + * @param string $country_name |
|
945 | + * @return array where keys are columns, values are column values |
|
946 | + */ |
|
947 | + public function get_or_create_country($country_name) |
|
948 | + { |
|
949 | + if (! $country_name) { |
|
950 | + throw new EE_Error(esc_html__("Could not get a country because country name is blank", "event_espresso")); |
|
951 | + } |
|
952 | + global $wpdb; |
|
953 | + $country_table = $wpdb->prefix . "esp_country"; |
|
954 | + if (is_int($country_name)) { |
|
955 | + $country_name = $this->get_iso_from_3_1_country_id($country_name); |
|
956 | + } |
|
957 | + $country = $wpdb->get_row($wpdb->prepare("SELECT * FROM $country_table WHERE |
|
958 | 958 | CNT_ISO LIKE %s OR |
959 | 959 | CNT_ISO3 LIKE %s OR |
960 | 960 | CNT_name LIKE %s LIMIT 1", $country_name, $country_name, $country_name), ARRAY_A); |
961 | - if (! $country) { |
|
962 | - // insert a new one then |
|
963 | - $cols_n_values = array( |
|
964 | - 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
965 | - 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
966 | - 'RGN_ID' => 0, |
|
967 | - 'CNT_name' => $country_name, |
|
968 | - 'CNT_cur_code' => 'USD', |
|
969 | - 'CNT_cur_single' => 'Dollar', |
|
970 | - 'CNT_cur_plural' => 'Dollars', |
|
971 | - 'CNT_cur_sign' => '$', |
|
972 | - 'CNT_cur_sign_b4' => true, |
|
973 | - 'CNT_cur_dec_plc' => 2, |
|
974 | - 'CNT_cur_dec_mrk' => '.', |
|
975 | - 'CNT_cur_thsnds' => ',', |
|
976 | - 'CNT_tel_code' => '+1', |
|
977 | - 'CNT_is_EU' => false, |
|
978 | - 'CNT_active' => true, |
|
979 | - ); |
|
980 | - $data_types = array( |
|
981 | - '%s',// CNT_ISO |
|
982 | - '%s',// CNT_ISO3 |
|
983 | - '%d',// RGN_ID |
|
984 | - '%s',// CNT_name |
|
985 | - '%s',// CNT_cur_code |
|
986 | - '%s',// CNT_cur_single |
|
987 | - '%s',// CNT_cur_plural |
|
988 | - '%s',// CNT_cur_sign |
|
989 | - '%d',// CNT_cur_sign_b4 |
|
990 | - '%d',// CNT_cur_dec_plc |
|
991 | - '%s',// CNT_cur_dec_mrk |
|
992 | - '%s',// CNT_cur_thsnds |
|
993 | - '%s',// CNT_tel_code |
|
994 | - '%d',// CNT_is_EU |
|
995 | - '%d',// CNT_active |
|
996 | - ); |
|
997 | - $success = $wpdb->insert( |
|
998 | - $country_table, |
|
999 | - $cols_n_values, |
|
1000 | - $data_types |
|
1001 | - ); |
|
1002 | - if (! $success) { |
|
1003 | - throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
1004 | - 'N/A', |
|
1005 | - array('country_id' => $country_name), |
|
1006 | - $country_table, |
|
1007 | - $cols_n_values, |
|
1008 | - $data_types |
|
1009 | - )); |
|
1010 | - } |
|
1011 | - $country = $cols_n_values; |
|
1012 | - } |
|
1013 | - return $country; |
|
1014 | - } |
|
1015 | - |
|
1016 | - |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * finds a country iso which hasnt been used yet |
|
1020 | - * |
|
1021 | - * @global type $wpdb |
|
1022 | - * @return string |
|
1023 | - */ |
|
1024 | - private function _find_available_country_iso($num_letters = 2) |
|
1025 | - { |
|
1026 | - global $wpdb; |
|
1027 | - $country_table = $wpdb->prefix . "esp_country"; |
|
1028 | - $attempts = 0; |
|
1029 | - do { |
|
1030 | - $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
1031 | - $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
1032 | - . $country_table |
|
1033 | - . " WHERE CNT_ISO=%s", $current_iso)); |
|
1034 | - $attempts++; |
|
1035 | - // keep going until we find an available country code, or we arbitrarily |
|
1036 | - // decide we've tried this enough. Somehow they have way too many countries |
|
1037 | - // (probably because they're mis-using the EE3 country_id like a custom question) |
|
1038 | - } while (intval($country_with_that_iso) && $attempts < 200); |
|
1039 | - return $current_iso; |
|
1040 | - } |
|
1041 | - |
|
1042 | - |
|
1043 | - |
|
1044 | - /** |
|
1045 | - * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
1046 | - * is independent of outside code which can change in future versions of EE |
|
1047 | - * |
|
1048 | - * @global type $wpdb |
|
1049 | - * @param string $state_name |
|
1050 | - * @return array where keys are columns, values are column values |
|
1051 | - */ |
|
1052 | - public function get_or_create_state($state_name, $country_name = '') |
|
1053 | - { |
|
1054 | - if (! $state_name) { |
|
1055 | - throw new EE_Error(esc_html__( |
|
1056 | - "Could not get-or-create state because no state name was provided", |
|
1057 | - "event_espresso" |
|
1058 | - )); |
|
1059 | - } |
|
1060 | - try { |
|
1061 | - $country = $this->get_or_create_country($country_name); |
|
1062 | - $country_iso = $country['CNT_ISO']; |
|
1063 | - } catch (EE_Error $e) { |
|
1064 | - $country_iso = $this->get_default_country_iso(); |
|
1065 | - } |
|
1066 | - global $wpdb; |
|
1067 | - $state_table = $wpdb->prefix . "esp_state"; |
|
1068 | - $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
961 | + if (! $country) { |
|
962 | + // insert a new one then |
|
963 | + $cols_n_values = array( |
|
964 | + 'CNT_ISO' => $this->_find_available_country_iso(2), |
|
965 | + 'CNT_ISO3' => $this->_find_available_country_iso(3), |
|
966 | + 'RGN_ID' => 0, |
|
967 | + 'CNT_name' => $country_name, |
|
968 | + 'CNT_cur_code' => 'USD', |
|
969 | + 'CNT_cur_single' => 'Dollar', |
|
970 | + 'CNT_cur_plural' => 'Dollars', |
|
971 | + 'CNT_cur_sign' => '$', |
|
972 | + 'CNT_cur_sign_b4' => true, |
|
973 | + 'CNT_cur_dec_plc' => 2, |
|
974 | + 'CNT_cur_dec_mrk' => '.', |
|
975 | + 'CNT_cur_thsnds' => ',', |
|
976 | + 'CNT_tel_code' => '+1', |
|
977 | + 'CNT_is_EU' => false, |
|
978 | + 'CNT_active' => true, |
|
979 | + ); |
|
980 | + $data_types = array( |
|
981 | + '%s',// CNT_ISO |
|
982 | + '%s',// CNT_ISO3 |
|
983 | + '%d',// RGN_ID |
|
984 | + '%s',// CNT_name |
|
985 | + '%s',// CNT_cur_code |
|
986 | + '%s',// CNT_cur_single |
|
987 | + '%s',// CNT_cur_plural |
|
988 | + '%s',// CNT_cur_sign |
|
989 | + '%d',// CNT_cur_sign_b4 |
|
990 | + '%d',// CNT_cur_dec_plc |
|
991 | + '%s',// CNT_cur_dec_mrk |
|
992 | + '%s',// CNT_cur_thsnds |
|
993 | + '%s',// CNT_tel_code |
|
994 | + '%d',// CNT_is_EU |
|
995 | + '%d',// CNT_active |
|
996 | + ); |
|
997 | + $success = $wpdb->insert( |
|
998 | + $country_table, |
|
999 | + $cols_n_values, |
|
1000 | + $data_types |
|
1001 | + ); |
|
1002 | + if (! $success) { |
|
1003 | + throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
1004 | + 'N/A', |
|
1005 | + array('country_id' => $country_name), |
|
1006 | + $country_table, |
|
1007 | + $cols_n_values, |
|
1008 | + $data_types |
|
1009 | + )); |
|
1010 | + } |
|
1011 | + $country = $cols_n_values; |
|
1012 | + } |
|
1013 | + return $country; |
|
1014 | + } |
|
1015 | + |
|
1016 | + |
|
1017 | + |
|
1018 | + /** |
|
1019 | + * finds a country iso which hasnt been used yet |
|
1020 | + * |
|
1021 | + * @global type $wpdb |
|
1022 | + * @return string |
|
1023 | + */ |
|
1024 | + private function _find_available_country_iso($num_letters = 2) |
|
1025 | + { |
|
1026 | + global $wpdb; |
|
1027 | + $country_table = $wpdb->prefix . "esp_country"; |
|
1028 | + $attempts = 0; |
|
1029 | + do { |
|
1030 | + $current_iso = strtoupper(wp_generate_password($num_letters, false)); |
|
1031 | + $country_with_that_iso = $wpdb->get_var($wpdb->prepare("SELECT count(CNT_ISO) FROM " |
|
1032 | + . $country_table |
|
1033 | + . " WHERE CNT_ISO=%s", $current_iso)); |
|
1034 | + $attempts++; |
|
1035 | + // keep going until we find an available country code, or we arbitrarily |
|
1036 | + // decide we've tried this enough. Somehow they have way too many countries |
|
1037 | + // (probably because they're mis-using the EE3 country_id like a custom question) |
|
1038 | + } while (intval($country_with_that_iso) && $attempts < 200); |
|
1039 | + return $current_iso; |
|
1040 | + } |
|
1041 | + |
|
1042 | + |
|
1043 | + |
|
1044 | + /** |
|
1045 | + * Gets a state entry as an array, or creates one if none is found. Much like EEM_State::instance()->get_one(), but |
|
1046 | + * is independent of outside code which can change in future versions of EE |
|
1047 | + * |
|
1048 | + * @global type $wpdb |
|
1049 | + * @param string $state_name |
|
1050 | + * @return array where keys are columns, values are column values |
|
1051 | + */ |
|
1052 | + public function get_or_create_state($state_name, $country_name = '') |
|
1053 | + { |
|
1054 | + if (! $state_name) { |
|
1055 | + throw new EE_Error(esc_html__( |
|
1056 | + "Could not get-or-create state because no state name was provided", |
|
1057 | + "event_espresso" |
|
1058 | + )); |
|
1059 | + } |
|
1060 | + try { |
|
1061 | + $country = $this->get_or_create_country($country_name); |
|
1062 | + $country_iso = $country['CNT_ISO']; |
|
1063 | + } catch (EE_Error $e) { |
|
1064 | + $country_iso = $this->get_default_country_iso(); |
|
1065 | + } |
|
1066 | + global $wpdb; |
|
1067 | + $state_table = $wpdb->prefix . "esp_state"; |
|
1068 | + $state = $wpdb->get_row($wpdb->prepare("SELECT * FROM $state_table WHERE |
|
1069 | 1069 | (STA_abbrev LIKE %s OR |
1070 | 1070 | STA_name LIKE %s) AND |
1071 | 1071 | CNT_ISO LIKE %s LIMIT 1", $state_name, $state_name, $country_iso), ARRAY_A); |
1072 | - if (! $state) { |
|
1073 | - // insert a new one then |
|
1074 | - $cols_n_values = array( |
|
1075 | - 'CNT_ISO' => $country_iso, |
|
1076 | - 'STA_abbrev' => substr($state_name, 0, 6), |
|
1077 | - 'STA_name' => $state_name, |
|
1078 | - 'STA_active' => true, |
|
1079 | - ); |
|
1080 | - $data_types = array( |
|
1081 | - '%s',// CNT_ISO |
|
1082 | - '%s',// STA_abbrev |
|
1083 | - '%s',// STA_name |
|
1084 | - '%d',// STA_active |
|
1085 | - ); |
|
1086 | - $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
1087 | - if (! $success) { |
|
1088 | - throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
1089 | - 'N/A', |
|
1090 | - array('state' => $state_name, 'country_id' => $country_name), |
|
1091 | - $state_table, |
|
1092 | - $cols_n_values, |
|
1093 | - $data_types |
|
1094 | - )); |
|
1095 | - } |
|
1096 | - $state = $cols_n_values; |
|
1097 | - $state['STA_ID'] = $wpdb->insert_id; |
|
1098 | - } |
|
1099 | - return $state; |
|
1100 | - } |
|
1101 | - |
|
1102 | - |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
1106 | - * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
1107 | - * |
|
1108 | - * @param type $timeString |
|
1109 | - * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
1110 | - * with leading zeros) |
|
1111 | - */ |
|
1112 | - public function convertTimeFromAMPM($timeString) |
|
1113 | - { |
|
1114 | - $matches = array(); |
|
1115 | - preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
1116 | - if (! $matches || count($matches) < 3) { |
|
1117 | - $hour = '00'; |
|
1118 | - $minutes = '00'; |
|
1119 | - } else { |
|
1120 | - $hour = intval($matches[1]); |
|
1121 | - $minutes = $matches[2]; |
|
1122 | - } |
|
1123 | - if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
1124 | - $hour = intval($hour) + 12; |
|
1125 | - } |
|
1126 | - $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
1127 | - $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
1128 | - return "$hour:$minutes"; |
|
1129 | - } |
|
1130 | - |
|
1131 | - |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * Gets the ISO3 fora country given its 3.1 country ID. |
|
1135 | - * |
|
1136 | - * @param int $country_id |
|
1137 | - * @return string the country's ISO3 code |
|
1138 | - */ |
|
1139 | - public function get_iso_from_3_1_country_id($country_id) |
|
1140 | - { |
|
1141 | - $old_countries = array( |
|
1142 | - array(64, 'United States', 'US', 'USA', 1), |
|
1143 | - array(15, 'Australia', 'AU', 'AUS', 1), |
|
1144 | - array(39, 'Canada', 'CA', 'CAN', 1), |
|
1145 | - array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
1146 | - array(70, 'France', 'FR', 'FRA', 2), |
|
1147 | - array(111, 'Italy', 'IT', 'ITA', 2), |
|
1148 | - array(63, 'Spain', 'ES', 'ESP', 2), |
|
1149 | - array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
1150 | - array(2, 'Albania', 'AL', 'ALB', 1), |
|
1151 | - array(3, 'Germany', 'DE', 'DEU', 2), |
|
1152 | - array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
1153 | - array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
1154 | - array(197, 'Sweden', 'SE', 'SWE', 1), |
|
1155 | - array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
1156 | - array(4, 'Andorra', 'AD', 'AND', 2), |
|
1157 | - array(5, 'Angola', 'AO', 'AGO', 1), |
|
1158 | - array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
1159 | - array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
1160 | - array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
1161 | - array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
1162 | - array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
1163 | - array(12, 'Argentina', 'AR', 'ARG', 1), |
|
1164 | - array(13, 'Armenia', 'AM', 'ARM', 1), |
|
1165 | - array(14, 'Aruba', 'AW', 'ABW', 1), |
|
1166 | - array(16, 'Austria', 'AT', 'AUT', 2), |
|
1167 | - array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
1168 | - array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
1169 | - array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
1170 | - array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
1171 | - array(21, 'Barbados', 'BB', 'BRB', 1), |
|
1172 | - array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
1173 | - array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
1174 | - array(24, 'Benin', 'BJ', 'BEN', 1), |
|
1175 | - array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
1176 | - array(26, 'Belarus', 'BY', 'BLR', 1), |
|
1177 | - array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
1178 | - array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
1179 | - array(29, 'Botswana', 'BW', 'BWA', 1), |
|
1180 | - array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
1181 | - array(30, 'Brazil', 'BR', 'BRA', 1), |
|
1182 | - array(31, 'Brunei', 'BN', 'BRN', 1), |
|
1183 | - array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
1184 | - array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
1185 | - array(34, 'Burundi', 'BI', 'BDI', 1), |
|
1186 | - array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
1187 | - array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
1188 | - array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
1189 | - array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
1190 | - array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
1191 | - array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
1192 | - array(40, 'Chad', 'TD', 'TCD', 1), |
|
1193 | - array(41, 'Chile', 'CL', 'CHL', 1), |
|
1194 | - array(42, 'China', 'CN', 'CHN', 1), |
|
1195 | - array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
1196 | - array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
1197 | - array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
1198 | - array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
1199 | - array(44, 'Colombia', 'CO', 'COL', 1), |
|
1200 | - array(45, 'Comoros', 'KM', 'COM', 1), |
|
1201 | - array(46, 'Congo', 'CG', 'COG', 1), |
|
1202 | - array(47, 'North Korea', 'KP', 'PRK', 1), |
|
1203 | - array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
1204 | - array(51, 'Croatia', 'HR', 'HRV', 1), |
|
1205 | - array(52, 'Cuba', 'CU', 'CUB', 1), |
|
1206 | - array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
1207 | - array(53, 'Denmark', 'DK', 'DNK', 1), |
|
1208 | - array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
1209 | - array(55, 'Dominica', 'DM', 'DMA', 1), |
|
1210 | - array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
1211 | - array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
1212 | - array(57, 'Egypt', 'EG', 'EGY', 1), |
|
1213 | - array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
1214 | - array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
1215 | - array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
1216 | - array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
1217 | - array(65, 'Estonia', 'EE', 'EST', 2), |
|
1218 | - array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
1219 | - array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
1220 | - array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
1221 | - array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
1222 | - array(69, 'Finland', 'FI', 'FIN', 2), |
|
1223 | - array(71, 'Gabon', 'GA', 'GAB', 1), |
|
1224 | - array(72, 'Gambia', 'GM', 'GMB', 1), |
|
1225 | - array(73, 'Georgia', 'GE', 'GEO', 1), |
|
1226 | - array(74, 'Ghana', 'GH', 'GHA', 1), |
|
1227 | - array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
1228 | - array(76, 'Greece', 'GR', 'GRC', 2), |
|
1229 | - array(77, 'Grenada', 'GD', 'GRD', 1), |
|
1230 | - array(78, 'Greenland', 'GL', 'GRL', 1), |
|
1231 | - array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
1232 | - array(80, 'Guam', 'GU', 'GUM', 1), |
|
1233 | - array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
1234 | - array(82, 'Guinea', 'GN', 'GIN', 1), |
|
1235 | - array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
1236 | - array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
1237 | - array(85, 'Guyana', 'GY', 'GUY', 1), |
|
1238 | - array(86, 'Haiti', 'HT', 'HTI', 1), |
|
1239 | - array(88, 'Honduras', 'HN', 'HND', 1), |
|
1240 | - array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
1241 | - array(90, 'Hungary', 'HU', 'HUN', 1), |
|
1242 | - array(91, 'India', 'IN', 'IND', 1), |
|
1243 | - array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
1244 | - array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
1245 | - array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
1246 | - array(94, 'Iran', 'IR', 'IRN', 1), |
|
1247 | - array(95, 'Ireland', 'IE', 'IRL', 2), |
|
1248 | - array(97, 'Iceland', 'IS', 'ISL', 1), |
|
1249 | - array(110, 'Israel', 'IL', 'ISR', 1), |
|
1250 | - array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
1251 | - array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
1252 | - array(113, 'Japan', 'JP', 'JPN', 1), |
|
1253 | - array(114, 'Jordan', 'JO', 'JOR', 1), |
|
1254 | - array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
1255 | - array(116, 'Kenya', 'KE', 'KEN', 1), |
|
1256 | - array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
1257 | - array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
1258 | - array(48, 'South Korea', 'KR', 'KOR', 1), |
|
1259 | - array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
1260 | - // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
1261 | - array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
1262 | - array(120, 'Laos', 'LA', 'LAO', 1), |
|
1263 | - array(121, 'Latvia', 'LV', 'LVA', 2), |
|
1264 | - array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
1265 | - array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
1266 | - array(124, 'Liberia', 'LR', 'LBR', 1), |
|
1267 | - array(125, 'Libya', 'LY', 'LBY', 1), |
|
1268 | - array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
1269 | - array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
1270 | - array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
1271 | - array(129, 'Macao', 'MO', 'MAC', 1), |
|
1272 | - array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
1273 | - array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
1274 | - array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
1275 | - array(133, 'Malawi', 'MW', 'MWI', 1), |
|
1276 | - array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
1277 | - array(135, 'Mali', 'ML', 'MLI', 1), |
|
1278 | - array(136, 'Malta', 'MT', 'MLT', 2), |
|
1279 | - array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
1280 | - array(137, 'Morocco', 'MA', 'MAR', 1), |
|
1281 | - array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
1282 | - array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
1283 | - array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
1284 | - array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
1285 | - array(141, 'Mayote', 'YT', 'MYT', 2), |
|
1286 | - array(142, 'Mexico', 'MX', 'MEX', 1), |
|
1287 | - array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
1288 | - array(144, 'Moldova', 'MD', 'MDA', 1), |
|
1289 | - array(145, 'Monaco', 'MC', 'MCO', 2), |
|
1290 | - array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
1291 | - array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
1292 | - array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
1293 | - array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
1294 | - array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
1295 | - array(150, 'Namibia', 'NA', 'NAM', 1), |
|
1296 | - array(151, 'Nauru', 'NR', 'NRU', 1), |
|
1297 | - array(152, 'Nepal', 'NP', 'NPL', 1), |
|
1298 | - array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
1299 | - array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
1300 | - array(154, 'Niger', 'NE', 'NER', 1), |
|
1301 | - array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
1302 | - array(156, 'Niue', 'NU', 'NIU', 1), |
|
1303 | - array(157, 'Norway', 'NO', 'NOR', 1), |
|
1304 | - array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
1305 | - array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
1306 | - array(160, 'Oman', 'OM', 'OMN', 1), |
|
1307 | - array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
1308 | - array(162, 'Palau', 'PW', 'PLW', 1), |
|
1309 | - array(163, 'Panama', 'PA', 'PAN', 1), |
|
1310 | - array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
1311 | - array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
1312 | - array(166, 'Peru', 'PE', 'PER', 1), |
|
1313 | - array(68, 'Philippines', 'PH', 'PHL', 1), |
|
1314 | - array(167, 'Poland', 'PL', 'POL', 1), |
|
1315 | - array(168, 'Portugal', 'PT', 'PRT', 2), |
|
1316 | - array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
1317 | - array(170, 'Qatar', 'QA', 'QAT', 1), |
|
1318 | - array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
1319 | - array(177, 'Romania', 'RO', 'ROM', 2), |
|
1320 | - array(178, 'Russia', 'RU', 'RUS', 1), |
|
1321 | - array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
1322 | - array(180, 'Samoa', 'WS', 'WSM', 1), |
|
1323 | - array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
1324 | - array(183, 'San Marino', 'SM', 'SMR', 2), |
|
1325 | - array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
1326 | - array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
1327 | - array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
1328 | - array(188, 'Senegal', 'SN', 'SEN', 1), |
|
1329 | - array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
1330 | - array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
1331 | - array(191, 'Singapore', 'SG', 'SGP', 1), |
|
1332 | - array(192, 'Syria', 'SY', 'SYR', 1), |
|
1333 | - array(193, 'Somalia', 'SO', 'SOM', 1), |
|
1334 | - array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
1335 | - array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
1336 | - array(196, 'Sudan', 'SD', 'SDN', 1), |
|
1337 | - array(199, 'Suriname', 'SR', 'SUR', 1), |
|
1338 | - array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
1339 | - array(201, 'Thailand', 'TH', 'THA', 1), |
|
1340 | - array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
1341 | - array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
1342 | - array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
1343 | - array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
1344 | - array(207, 'Togo', 'TG', 'TGO', 1), |
|
1345 | - array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
1346 | - array(209, 'Tonga', 'TO', 'TON', 1), |
|
1347 | - array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
1348 | - array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
1349 | - array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
1350 | - array(213, 'Turkey', 'TR', 'TUR', 1), |
|
1351 | - array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
1352 | - array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
1353 | - array(216, 'Uganda', 'UG', 'UGA', 1), |
|
1354 | - array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
1355 | - array(217, 'Uruguay', 'UY', 'URY', 1), |
|
1356 | - array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
1357 | - array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
1358 | - array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
1359 | - array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
1360 | - array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
1361 | - array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
1362 | - array(223, 'Yemen', 'YE', 'YEM', 1), |
|
1363 | - array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
1364 | - array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
1365 | - ); |
|
1366 | - $country_iso = 'US'; |
|
1367 | - foreach ($old_countries as $country_array) { |
|
1368 | - // note: index 0 is the 3.1 country ID |
|
1369 | - if ($country_array[0] == $country_id) { |
|
1370 | - // note: index 2 is the ISO |
|
1371 | - $country_iso = $country_array[2]; |
|
1372 | - break; |
|
1373 | - } |
|
1374 | - } |
|
1375 | - return $country_iso; |
|
1376 | - } |
|
1377 | - |
|
1378 | - |
|
1379 | - |
|
1380 | - /** |
|
1381 | - * Gets the ISO3 for the |
|
1382 | - * |
|
1383 | - * @return string |
|
1384 | - */ |
|
1385 | - public function get_default_country_iso() |
|
1386 | - { |
|
1387 | - $old_org_options = get_option('events_organization_settings'); |
|
1388 | - $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
1389 | - return $iso; |
|
1390 | - } |
|
1391 | - |
|
1392 | - |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
1396 | - * |
|
1397 | - * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
1398 | - * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
1399 | - * DEFAULT payment status, the event's DEFAULT payment status, or |
|
1400 | - * the attendee's payment status) required pre-approval. |
|
1401 | - * @return string STS_ID for use in 4.1 |
|
1402 | - */ |
|
1403 | - public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
1404 | - { |
|
1405 | - // EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
1406 | - if ($this_thing_required_pre_approval) { |
|
1407 | - return 'RNA'; |
|
1408 | - } else { |
|
1409 | - $mapping = $default_reg_stati_conversions = array( |
|
1410 | - 'Completed' => 'RAP', |
|
1411 | - '' => 'RPP', |
|
1412 | - 'Incomplete' => 'RPP', |
|
1413 | - 'Pending' => 'RAP', |
|
1414 | - // stati that only occurred on 3.1 attendees: |
|
1415 | - 'Payment Declined' => 'RPP', |
|
1416 | - 'Not Completed' => 'RPP', |
|
1417 | - 'Cancelled' => 'RPP', |
|
1418 | - 'Declined' => 'RPP', |
|
1419 | - ); |
|
1420 | - } |
|
1421 | - return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
1422 | - } |
|
1423 | - |
|
1424 | - |
|
1425 | - |
|
1426 | - /** |
|
1427 | - * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
1428 | - * and sets it as the featured image on the CPT event |
|
1429 | - * |
|
1430 | - * @param type $old_event |
|
1431 | - * @param type $new_cpt_id |
|
1432 | - * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
1433 | - * @return boolean whether or not we had to do the big job of creating an image attachment |
|
1434 | - */ |
|
1435 | - public function convert_image_url_to_attachment_and_attach_to_post( |
|
1436 | - $guid, |
|
1437 | - $new_cpt_id, |
|
1438 | - EE_Data_Migration_Script_Stage $migration_stage |
|
1439 | - ) { |
|
1440 | - $created_attachment_post = false; |
|
1441 | - $guid = $this->_get_original_guid($guid); |
|
1442 | - if ($guid) { |
|
1443 | - // check for an existing attachment post with this guid |
|
1444 | - $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
1445 | - if (! $attachment_post_id) { |
|
1446 | - // post thumbnail with that GUID doesn't exist, we should create one |
|
1447 | - $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
1448 | - $created_attachment_post = true; |
|
1449 | - } |
|
1450 | - // double-check we actually have an attachment post |
|
1451 | - if ($attachment_post_id) { |
|
1452 | - update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
1453 | - } else { |
|
1454 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1455 | - "Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
1456 | - "event_espresso" |
|
1457 | - ), $guid, $new_cpt_id, $attachment_post_id)); |
|
1458 | - } |
|
1459 | - } |
|
1460 | - return $created_attachment_post; |
|
1461 | - } |
|
1462 | - |
|
1463 | - |
|
1464 | - |
|
1465 | - /** |
|
1466 | - * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
1467 | - * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
1468 | - * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
1469 | - * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
1470 | - * exists |
|
1471 | - * |
|
1472 | - * @param string $guid_in_old_event |
|
1473 | - * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
1474 | - */ |
|
1475 | - private function _get_original_guid($guid_in_old_event) |
|
1476 | - { |
|
1477 | - $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
1478 | - // do a head request to verify the file exists |
|
1479 | - $head_response = wp_remote_head($original_guid); |
|
1480 | - if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
1481 | - return $original_guid; |
|
1482 | - } else { |
|
1483 | - return $guid_in_old_event; |
|
1484 | - } |
|
1485 | - } |
|
1486 | - |
|
1487 | - |
|
1488 | - |
|
1489 | - /** |
|
1490 | - * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
1491 | - * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
1492 | - * thumbnails) |
|
1493 | - * |
|
1494 | - * @param type $guid |
|
1495 | - * @param EE_Data_Migration_Script_Stage $migration_stage |
|
1496 | - * @return int |
|
1497 | - */ |
|
1498 | - private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
1499 | - { |
|
1500 | - if (! $guid) { |
|
1501 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1502 | - "Cannot create image attachment for a blank GUID!", |
|
1503 | - "event_espresso" |
|
1504 | - ))); |
|
1505 | - return 0; |
|
1506 | - } |
|
1507 | - $wp_filetype = wp_check_filetype(basename($guid), null); |
|
1508 | - $wp_upload_dir = wp_upload_dir(); |
|
1509 | - // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
1510 | - if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
1511 | - // image is located remotely. download it and place it in the uploads directory |
|
1512 | - if (! is_readable($guid)) { |
|
1513 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1514 | - "Could not create image attachment from non-existent file: %s", |
|
1515 | - "event_espresso" |
|
1516 | - ), $guid)); |
|
1517 | - return 0; |
|
1518 | - } |
|
1519 | - $contents = file_get_contents($guid); |
|
1520 | - if ($contents === false) { |
|
1521 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1522 | - "Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
1523 | - "event_espresso" |
|
1524 | - ), $guid)); |
|
1525 | - return false; |
|
1526 | - } |
|
1527 | - $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
1528 | - $savefile = fopen($local_filepath, 'w'); |
|
1529 | - fwrite($savefile, $contents); |
|
1530 | - fclose($savefile); |
|
1531 | - $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
1532 | - } else { |
|
1533 | - $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
1534 | - } |
|
1535 | - $attachment = array( |
|
1536 | - 'guid' => $guid, |
|
1537 | - 'post_mime_type' => $wp_filetype['type'], |
|
1538 | - 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
1539 | - 'post_content' => '', |
|
1540 | - 'post_status' => 'inherit', |
|
1541 | - ); |
|
1542 | - $attach_id = wp_insert_attachment($attachment, $guid); |
|
1543 | - if (! $attach_id) { |
|
1544 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1545 | - "Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
1546 | - "event_espresso" |
|
1547 | - ), $guid, $this->_json_encode($attachment))); |
|
1548 | - return $attach_id; |
|
1549 | - } |
|
1550 | - // you must first include the image.php file |
|
1551 | - // for the function wp_generate_attachment_metadata() to work |
|
1552 | - require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1553 | - $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
1554 | - if (! $attach_data) { |
|
1555 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1556 | - "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
1557 | - "event_espresso" |
|
1558 | - ), $attach_id, $local_filepath, $guid)); |
|
1559 | - return $attach_id; |
|
1560 | - } |
|
1561 | - $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
1562 | - if (! $metadata_save_result) { |
|
1563 | - $migration_stage->add_error(sprintf(esc_html__( |
|
1564 | - "Could not update attachment metadata for attachment %d with data %s", |
|
1565 | - "event_espresso" |
|
1566 | - ), $attach_id, $this->_json_encode($attach_data))); |
|
1567 | - } |
|
1568 | - return $attach_id; |
|
1569 | - } |
|
1570 | - |
|
1571 | - |
|
1572 | - |
|
1573 | - /** |
|
1574 | - * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
1575 | - * and returns its ID. |
|
1576 | - * |
|
1577 | - * @global type $wpdb |
|
1578 | - * @param string $guid |
|
1579 | - * @return int |
|
1580 | - */ |
|
1581 | - private function _get_image_attachment_id_by_GUID($guid) |
|
1582 | - { |
|
1583 | - global $wpdb; |
|
1584 | - $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
1585 | - return $attachment_id; |
|
1586 | - } |
|
1587 | - |
|
1588 | - |
|
1589 | - |
|
1590 | - /** |
|
1591 | - * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
1592 | - * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
|
1593 | - * |
|
1594 | - * @param EE_Data_Migration_Script_base $stage |
|
1595 | - * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
1596 | - * UTC time for |
|
1597 | - * @param string $DATETIME_string |
|
1598 | - * @param string $timezone |
|
1599 | - * @return string |
|
1600 | - */ |
|
1601 | - public function convert_date_string_to_utc( |
|
1602 | - EE_Data_Migration_Script_Stage $stage, |
|
1603 | - $row_of_data, |
|
1604 | - $DATETIME_string, |
|
1605 | - $timezone = null |
|
1606 | - ) { |
|
1607 | - $original_tz = $timezone; |
|
1608 | - if (! $timezone) { |
|
1609 | - $timezone = $this->_get_wp_timezone(); |
|
1610 | - } |
|
1611 | - if (! $timezone) { |
|
1612 | - $stage->add_error(sprintf( |
|
1613 | - esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
|
1614 | - $original_tz, |
|
1615 | - $row_of_data |
|
1616 | - )); |
|
1617 | - $timezone = 'UTC'; |
|
1618 | - } |
|
1619 | - try { |
|
1620 | - $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
1621 | - EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC')); |
|
1622 | - } catch (Exception $e) { |
|
1623 | - $stage->add_error(sprintf(esc_html__( |
|
1624 | - "Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
1625 | - "event_espresso" |
|
1626 | - ), $DATETIME_string, $timezone)); |
|
1627 | - $date_obj = new DateTime(); |
|
1628 | - } |
|
1629 | - return $date_obj->format('Y-m-d H:i:s'); |
|
1630 | - } |
|
1631 | - |
|
1632 | - |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Gets the DEFAULT timezone string from wordpress (even if they set a gmt offset) |
|
1636 | - * |
|
1637 | - * @return string |
|
1638 | - */ |
|
1639 | - private function _get_wp_timezone() |
|
1640 | - { |
|
1641 | - $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
1642 | - // if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
1643 | - if (empty($timezone)) { |
|
1644 | - // let's get a the WordPress UTC offset |
|
1645 | - $offset = get_option('gmt_offset'); |
|
1646 | - $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
1647 | - } |
|
1648 | - return $timezone; |
|
1649 | - } |
|
1650 | - |
|
1651 | - |
|
1652 | - |
|
1653 | - /** |
|
1654 | - * Gets the wordpress timezone string from a UTC offset |
|
1655 | - * |
|
1656 | - * @param int $offset |
|
1657 | - * @return boolean |
|
1658 | - */ |
|
1659 | - private function timezone_convert_to_string_from_offset($offset) |
|
1660 | - { |
|
1661 | - // shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable |
|
1662 | - $offset *= 3600; // convert hour offset to seconds |
|
1663 | - $abbrarray = timezone_abbreviations_list(); |
|
1664 | - foreach ($abbrarray as $abbr) { |
|
1665 | - foreach ($abbr as $city) { |
|
1666 | - if ($city['offset'] == $offset) { |
|
1667 | - return $city['timezone_id']; |
|
1668 | - } |
|
1669 | - } |
|
1670 | - } |
|
1671 | - return false; |
|
1672 | - } |
|
1673 | - |
|
1674 | - |
|
1675 | - |
|
1676 | - public function migration_page_hooks() |
|
1677 | - { |
|
1678 | - add_filter( |
|
1679 | - 'FHEE__ee_migration_page__header', |
|
1680 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1681 | - 10, |
|
1682 | - 3 |
|
1683 | - ); |
|
1684 | - add_filter( |
|
1685 | - 'FHEE__ee_migration_page__p_after_header', |
|
1686 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1687 | - 10, |
|
1688 | - 2 |
|
1689 | - ); |
|
1690 | - add_filter( |
|
1691 | - 'FHEE__ee_migration_page__option_1_main', |
|
1692 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1693 | - 10, |
|
1694 | - 3 |
|
1695 | - ); |
|
1696 | - add_filter( |
|
1697 | - 'FHEE__ee_migration_page__option_1_button_text', |
|
1698 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1699 | - 10, |
|
1700 | - 3 |
|
1701 | - ); |
|
1702 | - add_action( |
|
1703 | - 'AHEE__ee_migration_page__option_1_extra_details', |
|
1704 | - array($this, '_migration_page_hook_option_1_extra_details'), |
|
1705 | - 10, |
|
1706 | - 3 |
|
1707 | - ); |
|
1708 | - add_filter( |
|
1709 | - 'FHEE__ee_migration_page__option_2_main', |
|
1710 | - array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1711 | - 10, |
|
1712 | - 4 |
|
1713 | - ); |
|
1714 | - add_filter( |
|
1715 | - 'FHEE__ee_migration_page__option_2_button_text', |
|
1716 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1717 | - 10, |
|
1718 | - 2 |
|
1719 | - ); |
|
1720 | - add_filter( |
|
1721 | - 'FHEE__ee_migration_page__option_2_details', |
|
1722 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1723 | - 10, |
|
1724 | - 2 |
|
1725 | - ); |
|
1726 | - add_action( |
|
1727 | - 'AHEE__ee_migration_page__after_migration_options_table', |
|
1728 | - array($this, '_migration_page_hook_after_migration_options_table') |
|
1729 | - ); |
|
1730 | - add_filter( |
|
1731 | - 'FHEE__ee_migration_page__done_migration_header', |
|
1732 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1733 | - 10, |
|
1734 | - 2 |
|
1735 | - ); |
|
1736 | - add_filter( |
|
1737 | - 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
1738 | - array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1739 | - 10, |
|
1740 | - 2 |
|
1741 | - ); |
|
1742 | - add_filter( |
|
1743 | - 'FHEE__ee_migration_page__migration_options_template', |
|
1744 | - array($this,'use_migration_options_from_ee3_template') |
|
1745 | - ); |
|
1746 | - } |
|
1747 | - |
|
1748 | - |
|
1749 | - |
|
1750 | - public function _migrate_page_hook_simplify_version_strings( |
|
1751 | - $old_content, |
|
1752 | - $current_db_state, |
|
1753 | - $next_db_state, |
|
1754 | - $ultimate_db_state = null |
|
1755 | - ) { |
|
1756 | - return str_replace( |
|
1757 | - array($current_db_state, $next_db_state, $ultimate_db_state), |
|
1758 | - array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
1759 | - $old_content |
|
1760 | - ); |
|
1761 | - } |
|
1762 | - |
|
1763 | - |
|
1764 | - |
|
1765 | - public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
1766 | - { |
|
1767 | - return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
1768 | - } |
|
1769 | - |
|
1770 | - |
|
1771 | - |
|
1772 | - public function _migration_page_hook_option_1_extra_details() |
|
1773 | - { |
|
1774 | - ?> |
|
1072 | + if (! $state) { |
|
1073 | + // insert a new one then |
|
1074 | + $cols_n_values = array( |
|
1075 | + 'CNT_ISO' => $country_iso, |
|
1076 | + 'STA_abbrev' => substr($state_name, 0, 6), |
|
1077 | + 'STA_name' => $state_name, |
|
1078 | + 'STA_active' => true, |
|
1079 | + ); |
|
1080 | + $data_types = array( |
|
1081 | + '%s',// CNT_ISO |
|
1082 | + '%s',// STA_abbrev |
|
1083 | + '%s',// STA_name |
|
1084 | + '%d',// STA_active |
|
1085 | + ); |
|
1086 | + $success = $wpdb->insert($state_table, $cols_n_values, $data_types); |
|
1087 | + if (! $success) { |
|
1088 | + throw new EE_Error($this->_create_error_message_for_db_insertion( |
|
1089 | + 'N/A', |
|
1090 | + array('state' => $state_name, 'country_id' => $country_name), |
|
1091 | + $state_table, |
|
1092 | + $cols_n_values, |
|
1093 | + $data_types |
|
1094 | + )); |
|
1095 | + } |
|
1096 | + $state = $cols_n_values; |
|
1097 | + $state['STA_ID'] = $wpdb->insert_id; |
|
1098 | + } |
|
1099 | + return $state; |
|
1100 | + } |
|
1101 | + |
|
1102 | + |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * Fixes times like "5:00 PM" into the expected 24-hour format "17:00". |
|
1106 | + * THis is actually just copied from the 3.1 JSON API because it needed to do the exact same thing |
|
1107 | + * |
|
1108 | + * @param type $timeString |
|
1109 | + * @return string in the php DATETIME format: "G:i" (24-hour format hour with leading zeros, a colon, and minutes |
|
1110 | + * with leading zeros) |
|
1111 | + */ |
|
1112 | + public function convertTimeFromAMPM($timeString) |
|
1113 | + { |
|
1114 | + $matches = array(); |
|
1115 | + preg_match("~(\\d*):(\\d*)~", $timeString, $matches); |
|
1116 | + if (! $matches || count($matches) < 3) { |
|
1117 | + $hour = '00'; |
|
1118 | + $minutes = '00'; |
|
1119 | + } else { |
|
1120 | + $hour = intval($matches[1]); |
|
1121 | + $minutes = $matches[2]; |
|
1122 | + } |
|
1123 | + if (strpos($timeString, 'PM') || strpos($timeString, 'pm')) { |
|
1124 | + $hour = intval($hour) + 12; |
|
1125 | + } |
|
1126 | + $hour = str_pad("$hour", 2, '0', STR_PAD_LEFT); |
|
1127 | + $minutes = str_pad("$minutes", 2, '0', STR_PAD_LEFT); |
|
1128 | + return "$hour:$minutes"; |
|
1129 | + } |
|
1130 | + |
|
1131 | + |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * Gets the ISO3 fora country given its 3.1 country ID. |
|
1135 | + * |
|
1136 | + * @param int $country_id |
|
1137 | + * @return string the country's ISO3 code |
|
1138 | + */ |
|
1139 | + public function get_iso_from_3_1_country_id($country_id) |
|
1140 | + { |
|
1141 | + $old_countries = array( |
|
1142 | + array(64, 'United States', 'US', 'USA', 1), |
|
1143 | + array(15, 'Australia', 'AU', 'AUS', 1), |
|
1144 | + array(39, 'Canada', 'CA', 'CAN', 1), |
|
1145 | + array(171, 'United Kingdom', 'GB', 'GBR', 1), |
|
1146 | + array(70, 'France', 'FR', 'FRA', 2), |
|
1147 | + array(111, 'Italy', 'IT', 'ITA', 2), |
|
1148 | + array(63, 'Spain', 'ES', 'ESP', 2), |
|
1149 | + array(1, 'Afghanistan', 'AF', 'AFG', 1), |
|
1150 | + array(2, 'Albania', 'AL', 'ALB', 1), |
|
1151 | + array(3, 'Germany', 'DE', 'DEU', 2), |
|
1152 | + array(198, 'Switzerland', 'CH', 'CHE', 1), |
|
1153 | + array(87, 'Netherlands', 'NL', 'NLD', 2), |
|
1154 | + array(197, 'Sweden', 'SE', 'SWE', 1), |
|
1155 | + array(230, 'Akrotiri and Dhekelia', 'CY', 'CYP', 2), |
|
1156 | + array(4, 'Andorra', 'AD', 'AND', 2), |
|
1157 | + array(5, 'Angola', 'AO', 'AGO', 1), |
|
1158 | + array(6, 'Anguilla', 'AI', 'AIA', 1), |
|
1159 | + array(7, 'Antarctica', 'AQ', 'ATA', 1), |
|
1160 | + array(8, 'Antigua and Barbuda', 'AG', 'ATG', 1), |
|
1161 | + array(10, 'Saudi Arabia', 'SA', 'SAU', 1), |
|
1162 | + array(11, 'Algeria', 'DZ', 'DZA', 1), |
|
1163 | + array(12, 'Argentina', 'AR', 'ARG', 1), |
|
1164 | + array(13, 'Armenia', 'AM', 'ARM', 1), |
|
1165 | + array(14, 'Aruba', 'AW', 'ABW', 1), |
|
1166 | + array(16, 'Austria', 'AT', 'AUT', 2), |
|
1167 | + array(17, 'Azerbaijan', 'AZ', 'AZE', 1), |
|
1168 | + array(18, 'Bahamas', 'BS', 'BHS', 1), |
|
1169 | + array(19, 'Bahrain', 'BH', 'BHR', 1), |
|
1170 | + array(20, 'Bangladesh', 'BD', 'BGD', 1), |
|
1171 | + array(21, 'Barbados', 'BB', 'BRB', 1), |
|
1172 | + array(22, 'Belgium ', 'BE', 'BEL', 2), |
|
1173 | + array(23, 'Belize', 'BZ', 'BLZ', 1), |
|
1174 | + array(24, 'Benin', 'BJ', 'BEN', 1), |
|
1175 | + array(25, 'Bermudas', 'BM', 'BMU', 1), |
|
1176 | + array(26, 'Belarus', 'BY', 'BLR', 1), |
|
1177 | + array(27, 'Bolivia', 'BO', 'BOL', 1), |
|
1178 | + array(28, 'Bosnia and Herzegovina', 'BA', 'BIH', 1), |
|
1179 | + array(29, 'Botswana', 'BW', 'BWA', 1), |
|
1180 | + array(96, 'Bouvet Island', 'BV', 'BVT', 1), |
|
1181 | + array(30, 'Brazil', 'BR', 'BRA', 1), |
|
1182 | + array(31, 'Brunei', 'BN', 'BRN', 1), |
|
1183 | + array(32, 'Bulgaria', 'BG', 'BGR', 1), |
|
1184 | + array(33, 'Burkina Faso', 'BF', 'BFA', 1), |
|
1185 | + array(34, 'Burundi', 'BI', 'BDI', 1), |
|
1186 | + array(35, 'Bhutan', 'BT', 'BTN', 1), |
|
1187 | + array(36, 'Cape Verde', 'CV', 'CPV', 1), |
|
1188 | + array(37, 'Cambodia', 'KH', 'KHM', 1), |
|
1189 | + array(38, 'Cameroon', 'CM', 'CMR', 1), |
|
1190 | + array(98, 'Cayman Islands', 'KY', 'CYM', 1), |
|
1191 | + array(172, 'Central African Republic', 'CF', 'CAF', 1), |
|
1192 | + array(40, 'Chad', 'TD', 'TCD', 1), |
|
1193 | + array(41, 'Chile', 'CL', 'CHL', 1), |
|
1194 | + array(42, 'China', 'CN', 'CHN', 1), |
|
1195 | + array(105, 'Christmas Island', 'CX', 'CXR', 1), |
|
1196 | + array(43, 'Cyprus', 'CY', 'CYP', 2), |
|
1197 | + array(99, 'Cocos Island', 'CC', 'CCK', 1), |
|
1198 | + array(100, 'Cook Islands', 'CK', 'COK', 1), |
|
1199 | + array(44, 'Colombia', 'CO', 'COL', 1), |
|
1200 | + array(45, 'Comoros', 'KM', 'COM', 1), |
|
1201 | + array(46, 'Congo', 'CG', 'COG', 1), |
|
1202 | + array(47, 'North Korea', 'KP', 'PRK', 1), |
|
1203 | + array(50, 'Costa Rica', 'CR', 'CRI', 1), |
|
1204 | + array(51, 'Croatia', 'HR', 'HRV', 1), |
|
1205 | + array(52, 'Cuba', 'CU', 'CUB', 1), |
|
1206 | + array(173, 'Czech Republic', 'CZ', 'CZE', 1), |
|
1207 | + array(53, 'Denmark', 'DK', 'DNK', 1), |
|
1208 | + array(54, 'Djibouti', 'DJ', 'DJI', 1), |
|
1209 | + array(55, 'Dominica', 'DM', 'DMA', 1), |
|
1210 | + array(174, 'Dominican Republic', 'DO', 'DOM', 1), |
|
1211 | + array(56, 'Ecuador', 'EC', 'ECU', 1), |
|
1212 | + array(57, 'Egypt', 'EG', 'EGY', 1), |
|
1213 | + array(58, 'El Salvador', 'SV', 'SLV', 1), |
|
1214 | + array(60, 'Eritrea', 'ER', 'ERI', 1), |
|
1215 | + array(61, 'Slovakia', 'SK', 'SVK', 2), |
|
1216 | + array(62, 'Slovenia', 'SI', 'SVN', 2), |
|
1217 | + array(65, 'Estonia', 'EE', 'EST', 2), |
|
1218 | + array(66, 'Ethiopia', 'ET', 'ETH', 1), |
|
1219 | + array(102, 'Faroe islands', 'FO', 'FRO', 1), |
|
1220 | + array(103, 'Falkland Islands', 'FK', 'FLK', 1), |
|
1221 | + array(67, 'Fiji', 'FJ', 'FJI', 1), |
|
1222 | + array(69, 'Finland', 'FI', 'FIN', 2), |
|
1223 | + array(71, 'Gabon', 'GA', 'GAB', 1), |
|
1224 | + array(72, 'Gambia', 'GM', 'GMB', 1), |
|
1225 | + array(73, 'Georgia', 'GE', 'GEO', 1), |
|
1226 | + array(74, 'Ghana', 'GH', 'GHA', 1), |
|
1227 | + array(75, 'Gibraltar', 'GI', 'GIB', 1), |
|
1228 | + array(76, 'Greece', 'GR', 'GRC', 2), |
|
1229 | + array(77, 'Grenada', 'GD', 'GRD', 1), |
|
1230 | + array(78, 'Greenland', 'GL', 'GRL', 1), |
|
1231 | + array(79, 'Guadeloupe', 'GP', 'GLP', 1), |
|
1232 | + array(80, 'Guam', 'GU', 'GUM', 1), |
|
1233 | + array(81, 'Guatemala', 'GT', 'GTM', 1), |
|
1234 | + array(82, 'Guinea', 'GN', 'GIN', 1), |
|
1235 | + array(83, 'Equatorial Guinea', 'GQ', 'GNQ', 1), |
|
1236 | + array(84, 'Guinea-Bissau', 'GW', 'GNB', 1), |
|
1237 | + array(85, 'Guyana', 'GY', 'GUY', 1), |
|
1238 | + array(86, 'Haiti', 'HT', 'HTI', 1), |
|
1239 | + array(88, 'Honduras', 'HN', 'HND', 1), |
|
1240 | + array(89, 'Hong Kong', 'HK', 'HKG', 1), |
|
1241 | + array(90, 'Hungary', 'HU', 'HUN', 1), |
|
1242 | + array(91, 'India', 'IN', 'IND', 1), |
|
1243 | + array(205, 'British Indian Ocean Territory', 'IO', 'IOT', 1), |
|
1244 | + array(92, 'Indonesia', 'ID', 'IDN', 1), |
|
1245 | + array(93, 'Iraq', 'IQ', 'IRQ', 1), |
|
1246 | + array(94, 'Iran', 'IR', 'IRN', 1), |
|
1247 | + array(95, 'Ireland', 'IE', 'IRL', 2), |
|
1248 | + array(97, 'Iceland', 'IS', 'ISL', 1), |
|
1249 | + array(110, 'Israel', 'IL', 'ISR', 1), |
|
1250 | + array(49, 'Ivory Coast ', 'CI', 'CIV', 1), |
|
1251 | + array(112, 'Jamaica', 'JM', 'JAM', 1), |
|
1252 | + array(113, 'Japan', 'JP', 'JPN', 1), |
|
1253 | + array(114, 'Jordan', 'JO', 'JOR', 1), |
|
1254 | + array(115, 'Kazakhstan', 'KZ', 'KAZ', 1), |
|
1255 | + array(116, 'Kenya', 'KE', 'KEN', 1), |
|
1256 | + array(117, 'Kyrgyzstan', 'KG', 'KGZ', 1), |
|
1257 | + array(118, 'Kiribati', 'KI', 'KIR', 1), |
|
1258 | + array(48, 'South Korea', 'KR', 'KOR', 1), |
|
1259 | + array(228, 'Kosovo', 'XK', 'XKV', 2), |
|
1260 | + // there is no official ISO code for Kosovo yet (http://geonames.wordpress.com/2010/03/08/xk-country-code-for-kosovo/) so using a temporary country code and a modified 3 character code for ISO code -- this should be updated if/when Kosovo gets its own ISO code |
|
1261 | + array(119, 'Kuwait', 'KW', 'KWT', 1), |
|
1262 | + array(120, 'Laos', 'LA', 'LAO', 1), |
|
1263 | + array(121, 'Latvia', 'LV', 'LVA', 2), |
|
1264 | + array(122, 'Lesotho', 'LS', 'LSO', 1), |
|
1265 | + array(123, 'Lebanon', 'LB', 'LBN', 1), |
|
1266 | + array(124, 'Liberia', 'LR', 'LBR', 1), |
|
1267 | + array(125, 'Libya', 'LY', 'LBY', 1), |
|
1268 | + array(126, 'Liechtenstein', 'LI', 'LIE', 1), |
|
1269 | + array(127, 'Lithuania', 'LT', 'LTU', 2), |
|
1270 | + array(128, 'Luxemburg', 'LU', 'LUX', 2), |
|
1271 | + array(129, 'Macao', 'MO', 'MAC', 1), |
|
1272 | + array(130, 'Macedonia', 'MK', 'MKD', 1), |
|
1273 | + array(131, 'Madagascar', 'MG', 'MDG', 1), |
|
1274 | + array(132, 'Malaysia', 'MY', 'MYS', 1), |
|
1275 | + array(133, 'Malawi', 'MW', 'MWI', 1), |
|
1276 | + array(134, 'Maldivas', 'MV', 'MDV', 1), |
|
1277 | + array(135, 'Mali', 'ML', 'MLI', 1), |
|
1278 | + array(136, 'Malta', 'MT', 'MLT', 2), |
|
1279 | + array(101, 'Northern Marianas', 'MP', 'MNP', 1), |
|
1280 | + array(137, 'Morocco', 'MA', 'MAR', 1), |
|
1281 | + array(104, 'Marshall islands', 'MH', 'MHL', 1), |
|
1282 | + array(138, 'Martinique', 'MQ', 'MTQ', 1), |
|
1283 | + array(139, 'Mauritius', 'MU', 'MUS', 1), |
|
1284 | + array(140, 'Mauritania', 'MR', 'MRT', 1), |
|
1285 | + array(141, 'Mayote', 'YT', 'MYT', 2), |
|
1286 | + array(142, 'Mexico', 'MX', 'MEX', 1), |
|
1287 | + array(143, 'Micronesia', 'FM', 'FSM', 1), |
|
1288 | + array(144, 'Moldova', 'MD', 'MDA', 1), |
|
1289 | + array(145, 'Monaco', 'MC', 'MCO', 2), |
|
1290 | + array(146, 'Mongolia', 'MN', 'MNG', 1), |
|
1291 | + array(147, 'Montserrat', 'MS', 'MSR', 1), |
|
1292 | + array(227, 'Montenegro', 'ME', 'MNE', 2), |
|
1293 | + array(148, 'Mozambique', 'MZ', 'MOZ', 1), |
|
1294 | + array(149, 'Myanmar', 'MM', 'MMR', 1), |
|
1295 | + array(150, 'Namibia', 'NA', 'NAM', 1), |
|
1296 | + array(151, 'Nauru', 'NR', 'NRU', 1), |
|
1297 | + array(152, 'Nepal', 'NP', 'NPL', 1), |
|
1298 | + array(9, 'Netherlands Antilles', 'AN', 'ANT', 1), |
|
1299 | + array(153, 'Nicaragua', 'NI', 'NIC', 1), |
|
1300 | + array(154, 'Niger', 'NE', 'NER', 1), |
|
1301 | + array(155, 'Nigeria', 'NG', 'NGA', 1), |
|
1302 | + array(156, 'Niue', 'NU', 'NIU', 1), |
|
1303 | + array(157, 'Norway', 'NO', 'NOR', 1), |
|
1304 | + array(158, 'New Caledonia', 'NC', 'NCL', 1), |
|
1305 | + array(159, 'New Zealand', 'NZ', 'NZL', 1), |
|
1306 | + array(160, 'Oman', 'OM', 'OMN', 1), |
|
1307 | + array(161, 'Pakistan', 'PK', 'PAK', 1), |
|
1308 | + array(162, 'Palau', 'PW', 'PLW', 1), |
|
1309 | + array(163, 'Panama', 'PA', 'PAN', 1), |
|
1310 | + array(164, 'Papua New Guinea', 'PG', 'PNG', 1), |
|
1311 | + array(165, 'Paraguay', 'PY', 'PRY', 1), |
|
1312 | + array(166, 'Peru', 'PE', 'PER', 1), |
|
1313 | + array(68, 'Philippines', 'PH', 'PHL', 1), |
|
1314 | + array(167, 'Poland', 'PL', 'POL', 1), |
|
1315 | + array(168, 'Portugal', 'PT', 'PRT', 2), |
|
1316 | + array(169, 'Puerto Rico', 'PR', 'PRI', 1), |
|
1317 | + array(170, 'Qatar', 'QA', 'QAT', 1), |
|
1318 | + array(176, 'Rwanda', 'RW', 'RWA', 1), |
|
1319 | + array(177, 'Romania', 'RO', 'ROM', 2), |
|
1320 | + array(178, 'Russia', 'RU', 'RUS', 1), |
|
1321 | + array(229, 'Saint Pierre and Miquelon', 'PM', 'SPM', 2), |
|
1322 | + array(180, 'Samoa', 'WS', 'WSM', 1), |
|
1323 | + array(181, 'American Samoa', 'AS', 'ASM', 1), |
|
1324 | + array(183, 'San Marino', 'SM', 'SMR', 2), |
|
1325 | + array(184, 'Saint Vincent and the Grenadines', 'VC', 'VCT', 1), |
|
1326 | + array(185, 'Saint Helena', 'SH', 'SHN', 1), |
|
1327 | + array(186, 'Saint Lucia', 'LC', 'LCA', 1), |
|
1328 | + array(188, 'Senegal', 'SN', 'SEN', 1), |
|
1329 | + array(189, 'Seychelles', 'SC', 'SYC', 1), |
|
1330 | + array(190, 'Sierra Leona', 'SL', 'SLE', 1), |
|
1331 | + array(191, 'Singapore', 'SG', 'SGP', 1), |
|
1332 | + array(192, 'Syria', 'SY', 'SYR', 1), |
|
1333 | + array(193, 'Somalia', 'SO', 'SOM', 1), |
|
1334 | + array(194, 'Sri Lanka', 'LK', 'LKA', 1), |
|
1335 | + array(195, 'South Africa', 'ZA', 'ZAF', 1), |
|
1336 | + array(196, 'Sudan', 'SD', 'SDN', 1), |
|
1337 | + array(199, 'Suriname', 'SR', 'SUR', 1), |
|
1338 | + array(200, 'Swaziland', 'SZ', 'SWZ', 1), |
|
1339 | + array(201, 'Thailand', 'TH', 'THA', 1), |
|
1340 | + array(202, 'Taiwan', 'TW', 'TWN', 1), |
|
1341 | + array(203, 'Tanzania', 'TZ', 'TZA', 1), |
|
1342 | + array(204, 'Tajikistan', 'TJ', 'TJK', 1), |
|
1343 | + array(206, 'Timor-Leste', 'TL', 'TLS', 1), |
|
1344 | + array(207, 'Togo', 'TG', 'TGO', 1), |
|
1345 | + array(208, 'Tokelau', 'TK', 'TKL', 1), |
|
1346 | + array(209, 'Tonga', 'TO', 'TON', 1), |
|
1347 | + array(210, 'Trinidad and Tobago', 'TT', 'TTO', 1), |
|
1348 | + array(211, 'Tunisia', 'TN', 'TUN', 1), |
|
1349 | + array(212, 'Turkmenistan', 'TM', 'TKM', 1), |
|
1350 | + array(213, 'Turkey', 'TR', 'TUR', 1), |
|
1351 | + array(214, 'Tuvalu', 'TV', 'TUV', 1), |
|
1352 | + array(215, 'Ukraine', 'UA', 'UKR', 1), |
|
1353 | + array(216, 'Uganda', 'UG', 'UGA', 1), |
|
1354 | + array(59, 'United Arab Emirates', 'AE', 'ARE', 1), |
|
1355 | + array(217, 'Uruguay', 'UY', 'URY', 1), |
|
1356 | + array(218, 'Uzbekistan', 'UZ', 'UZB', 1), |
|
1357 | + array(219, 'Vanuatu', 'VU', 'VUT', 1), |
|
1358 | + array(220, 'Vatican City', 'VA', 'VAT', 2), |
|
1359 | + array(221, 'Venezuela', 'VE', 'VEN', 1), |
|
1360 | + array(222, 'Vietnam', 'VN', 'VNM', 1), |
|
1361 | + array(108, 'Virgin Islands', 'VI', 'VIR', 1), |
|
1362 | + array(223, 'Yemen', 'YE', 'YEM', 1), |
|
1363 | + array(225, 'Zambia', 'ZM', 'ZMB', 1), |
|
1364 | + array(226, 'Zimbabwe', 'ZW', 'ZWE', 1), |
|
1365 | + ); |
|
1366 | + $country_iso = 'US'; |
|
1367 | + foreach ($old_countries as $country_array) { |
|
1368 | + // note: index 0 is the 3.1 country ID |
|
1369 | + if ($country_array[0] == $country_id) { |
|
1370 | + // note: index 2 is the ISO |
|
1371 | + $country_iso = $country_array[2]; |
|
1372 | + break; |
|
1373 | + } |
|
1374 | + } |
|
1375 | + return $country_iso; |
|
1376 | + } |
|
1377 | + |
|
1378 | + |
|
1379 | + |
|
1380 | + /** |
|
1381 | + * Gets the ISO3 for the |
|
1382 | + * |
|
1383 | + * @return string |
|
1384 | + */ |
|
1385 | + public function get_default_country_iso() |
|
1386 | + { |
|
1387 | + $old_org_options = get_option('events_organization_settings'); |
|
1388 | + $iso = $this->get_iso_from_3_1_country_id($old_org_options['organization_country']); |
|
1389 | + return $iso; |
|
1390 | + } |
|
1391 | + |
|
1392 | + |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * Converst a 3.1 payment status to its equivalent 4.1 regisration status |
|
1396 | + * |
|
1397 | + * @param string $payment_status possible value for 3.1's evens_attendee.payment_status |
|
1398 | + * @param boolean $this_thing_required_pre_approval whether the thing we're considering (the general setting's |
|
1399 | + * DEFAULT payment status, the event's DEFAULT payment status, or |
|
1400 | + * the attendee's payment status) required pre-approval. |
|
1401 | + * @return string STS_ID for use in 4.1 |
|
1402 | + */ |
|
1403 | + public function convert_3_1_payment_status_to_4_1_STS_ID($payment_status, $this_thing_required_pre_approval = false) |
|
1404 | + { |
|
1405 | + // EE team can read the related discussion: https://app.asana.com/0/2400967562914/9418495544455 |
|
1406 | + if ($this_thing_required_pre_approval) { |
|
1407 | + return 'RNA'; |
|
1408 | + } else { |
|
1409 | + $mapping = $default_reg_stati_conversions = array( |
|
1410 | + 'Completed' => 'RAP', |
|
1411 | + '' => 'RPP', |
|
1412 | + 'Incomplete' => 'RPP', |
|
1413 | + 'Pending' => 'RAP', |
|
1414 | + // stati that only occurred on 3.1 attendees: |
|
1415 | + 'Payment Declined' => 'RPP', |
|
1416 | + 'Not Completed' => 'RPP', |
|
1417 | + 'Cancelled' => 'RPP', |
|
1418 | + 'Declined' => 'RPP', |
|
1419 | + ); |
|
1420 | + } |
|
1421 | + return isset($mapping[ $payment_status ]) ? $mapping[ $payment_status ] : 'RNA'; |
|
1422 | + } |
|
1423 | + |
|
1424 | + |
|
1425 | + |
|
1426 | + /** |
|
1427 | + * Makes sure the 3.1's image url is converted to an image attachment post to the 4.1 CPT event |
|
1428 | + * and sets it as the featured image on the CPT event |
|
1429 | + * |
|
1430 | + * @param type $old_event |
|
1431 | + * @param type $new_cpt_id |
|
1432 | + * @param EE_Data_Migration_Script_Stage $migration_stage the stage which called this, where errors should be added |
|
1433 | + * @return boolean whether or not we had to do the big job of creating an image attachment |
|
1434 | + */ |
|
1435 | + public function convert_image_url_to_attachment_and_attach_to_post( |
|
1436 | + $guid, |
|
1437 | + $new_cpt_id, |
|
1438 | + EE_Data_Migration_Script_Stage $migration_stage |
|
1439 | + ) { |
|
1440 | + $created_attachment_post = false; |
|
1441 | + $guid = $this->_get_original_guid($guid); |
|
1442 | + if ($guid) { |
|
1443 | + // check for an existing attachment post with this guid |
|
1444 | + $attachment_post_id = $this->_get_image_attachment_id_by_GUID($guid); |
|
1445 | + if (! $attachment_post_id) { |
|
1446 | + // post thumbnail with that GUID doesn't exist, we should create one |
|
1447 | + $attachment_post_id = $this->_create_image_attachment_from_GUID($guid, $migration_stage); |
|
1448 | + $created_attachment_post = true; |
|
1449 | + } |
|
1450 | + // double-check we actually have an attachment post |
|
1451 | + if ($attachment_post_id) { |
|
1452 | + update_post_meta($new_cpt_id, '_thumbnail_id', $attachment_post_id); |
|
1453 | + } else { |
|
1454 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1455 | + "Could not update event image %s for CPT with ID %d, but attachments post ID is %d", |
|
1456 | + "event_espresso" |
|
1457 | + ), $guid, $new_cpt_id, $attachment_post_id)); |
|
1458 | + } |
|
1459 | + } |
|
1460 | + return $created_attachment_post; |
|
1461 | + } |
|
1462 | + |
|
1463 | + |
|
1464 | + |
|
1465 | + /** |
|
1466 | + * In 3.1, the event thumbnail image DOESN'T point to the orignal image, but instead |
|
1467 | + * to a large thumbnail (which has nearly the same GUID, except it adds "-{width}x{height}" before the filetype, |
|
1468 | + * or whatever dimensions it is. Eg 'http://mysite.com/image1-300x400.jpg' instead of |
|
1469 | + * 'http://mysite.com/image1.jpg' ). This function attempts to strip that off and get the original file, if it |
|
1470 | + * exists |
|
1471 | + * |
|
1472 | + * @param string $guid_in_old_event |
|
1473 | + * @return string either the original guid, or $guid_in_old_event if we couldn't figure out what the original was |
|
1474 | + */ |
|
1475 | + private function _get_original_guid($guid_in_old_event) |
|
1476 | + { |
|
1477 | + $original_guid = preg_replace('~-\d*x\d*\.~', '.', $guid_in_old_event, 1); |
|
1478 | + // do a head request to verify the file exists |
|
1479 | + $head_response = wp_remote_head($original_guid); |
|
1480 | + if (! $head_response instanceof WP_Error && $head_response['response']['message'] == 'OK') { |
|
1481 | + return $original_guid; |
|
1482 | + } else { |
|
1483 | + return $guid_in_old_event; |
|
1484 | + } |
|
1485 | + } |
|
1486 | + |
|
1487 | + |
|
1488 | + |
|
1489 | + /** |
|
1490 | + * Creates an image attachment post for the GUID. If the GUID points to a remote image, |
|
1491 | + * we download it to our uploads directory so that it can be properly processed (eg, creates different sizes of |
|
1492 | + * thumbnails) |
|
1493 | + * |
|
1494 | + * @param type $guid |
|
1495 | + * @param EE_Data_Migration_Script_Stage $migration_stage |
|
1496 | + * @return int |
|
1497 | + */ |
|
1498 | + private function _create_image_attachment_from_GUID($guid, EE_Data_Migration_Script_Stage $migration_stage) |
|
1499 | + { |
|
1500 | + if (! $guid) { |
|
1501 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1502 | + "Cannot create image attachment for a blank GUID!", |
|
1503 | + "event_espresso" |
|
1504 | + ))); |
|
1505 | + return 0; |
|
1506 | + } |
|
1507 | + $wp_filetype = wp_check_filetype(basename($guid), null); |
|
1508 | + $wp_upload_dir = wp_upload_dir(); |
|
1509 | + // if the file is located remotely, download it to our uploads DIR, because wp_genereate_attachmnet_metadata needs the file to be local |
|
1510 | + if (strpos($guid, $wp_upload_dir['url']) === false) { |
|
1511 | + // image is located remotely. download it and place it in the uploads directory |
|
1512 | + if (! is_readable($guid)) { |
|
1513 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1514 | + "Could not create image attachment from non-existent file: %s", |
|
1515 | + "event_espresso" |
|
1516 | + ), $guid)); |
|
1517 | + return 0; |
|
1518 | + } |
|
1519 | + $contents = file_get_contents($guid); |
|
1520 | + if ($contents === false) { |
|
1521 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1522 | + "Could not read image at %s, and therefore couldnt create an attachment post for it.", |
|
1523 | + "event_espresso" |
|
1524 | + ), $guid)); |
|
1525 | + return false; |
|
1526 | + } |
|
1527 | + $local_filepath = $wp_upload_dir['path'] . DS . basename($guid); |
|
1528 | + $savefile = fopen($local_filepath, 'w'); |
|
1529 | + fwrite($savefile, $contents); |
|
1530 | + fclose($savefile); |
|
1531 | + $guid = str_replace($wp_upload_dir['path'], $wp_upload_dir['url'], $local_filepath); |
|
1532 | + } else { |
|
1533 | + $local_filepath = str_replace($wp_upload_dir['url'], $wp_upload_dir['path'], $guid); |
|
1534 | + } |
|
1535 | + $attachment = array( |
|
1536 | + 'guid' => $guid, |
|
1537 | + 'post_mime_type' => $wp_filetype['type'], |
|
1538 | + 'post_title' => preg_replace('/\.[^.]+$/', '', basename($guid)), |
|
1539 | + 'post_content' => '', |
|
1540 | + 'post_status' => 'inherit', |
|
1541 | + ); |
|
1542 | + $attach_id = wp_insert_attachment($attachment, $guid); |
|
1543 | + if (! $attach_id) { |
|
1544 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1545 | + "Could not create image attachment post from image '%s'. Attachment data was %s.", |
|
1546 | + "event_espresso" |
|
1547 | + ), $guid, $this->_json_encode($attachment))); |
|
1548 | + return $attach_id; |
|
1549 | + } |
|
1550 | + // you must first include the image.php file |
|
1551 | + // for the function wp_generate_attachment_metadata() to work |
|
1552 | + require_once(ABSPATH . 'wp-admin/includes/image.php'); |
|
1553 | + $attach_data = wp_generate_attachment_metadata($attach_id, $local_filepath); |
|
1554 | + if (! $attach_data) { |
|
1555 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1556 | + "Coudl not genereate attachment metadata for attachment post %d with filepath %s and GUID %s. Please check the file was downloaded properly.", |
|
1557 | + "event_espresso" |
|
1558 | + ), $attach_id, $local_filepath, $guid)); |
|
1559 | + return $attach_id; |
|
1560 | + } |
|
1561 | + $metadata_save_result = wp_update_attachment_metadata($attach_id, $attach_data); |
|
1562 | + if (! $metadata_save_result) { |
|
1563 | + $migration_stage->add_error(sprintf(esc_html__( |
|
1564 | + "Could not update attachment metadata for attachment %d with data %s", |
|
1565 | + "event_espresso" |
|
1566 | + ), $attach_id, $this->_json_encode($attach_data))); |
|
1567 | + } |
|
1568 | + return $attach_id; |
|
1569 | + } |
|
1570 | + |
|
1571 | + |
|
1572 | + |
|
1573 | + /** |
|
1574 | + * Finds the attachment post containing info about an image attachment given the GUID (link to the image itself), |
|
1575 | + * and returns its ID. |
|
1576 | + * |
|
1577 | + * @global type $wpdb |
|
1578 | + * @param string $guid |
|
1579 | + * @return int |
|
1580 | + */ |
|
1581 | + private function _get_image_attachment_id_by_GUID($guid) |
|
1582 | + { |
|
1583 | + global $wpdb; |
|
1584 | + $attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid=%s LIMIT 1", $guid)); |
|
1585 | + return $attachment_id; |
|
1586 | + } |
|
1587 | + |
|
1588 | + |
|
1589 | + |
|
1590 | + /** |
|
1591 | + * Returns a mysql-formatted DATETIME in UTC time, given a $DATETIME_string |
|
1592 | + * (and optionally a timezone; if none is given, the wp DEFAULT is used) |
|
1593 | + * |
|
1594 | + * @param EE_Data_Migration_Script_base $stage |
|
1595 | + * @param array $row_of_data , the row from the DB (as an array) we're trying to find the |
|
1596 | + * UTC time for |
|
1597 | + * @param string $DATETIME_string |
|
1598 | + * @param string $timezone |
|
1599 | + * @return string |
|
1600 | + */ |
|
1601 | + public function convert_date_string_to_utc( |
|
1602 | + EE_Data_Migration_Script_Stage $stage, |
|
1603 | + $row_of_data, |
|
1604 | + $DATETIME_string, |
|
1605 | + $timezone = null |
|
1606 | + ) { |
|
1607 | + $original_tz = $timezone; |
|
1608 | + if (! $timezone) { |
|
1609 | + $timezone = $this->_get_wp_timezone(); |
|
1610 | + } |
|
1611 | + if (! $timezone) { |
|
1612 | + $stage->add_error(sprintf( |
|
1613 | + esc_html__("Could not find timezone given %s for %s", "event_espresso"), |
|
1614 | + $original_tz, |
|
1615 | + $row_of_data |
|
1616 | + )); |
|
1617 | + $timezone = 'UTC'; |
|
1618 | + } |
|
1619 | + try { |
|
1620 | + $date_obj = new DateTime($DATETIME_string, new DateTimeZone($timezone)); |
|
1621 | + EEH_DTT_Helper::setTimezone($date_obj, new DateTimeZone('UTC')); |
|
1622 | + } catch (Exception $e) { |
|
1623 | + $stage->add_error(sprintf(esc_html__( |
|
1624 | + "Could not convert time string '%s' using timezone '%s' into a proper DATETIME. Using current time instead.", |
|
1625 | + "event_espresso" |
|
1626 | + ), $DATETIME_string, $timezone)); |
|
1627 | + $date_obj = new DateTime(); |
|
1628 | + } |
|
1629 | + return $date_obj->format('Y-m-d H:i:s'); |
|
1630 | + } |
|
1631 | + |
|
1632 | + |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Gets the DEFAULT timezone string from wordpress (even if they set a gmt offset) |
|
1636 | + * |
|
1637 | + * @return string |
|
1638 | + */ |
|
1639 | + private function _get_wp_timezone() |
|
1640 | + { |
|
1641 | + $timezone = empty($timezone) ? get_option('timezone_string') : $timezone; |
|
1642 | + // if timezone is STILL empty then let's get the GMT offset and then set the timezone_string using our converter |
|
1643 | + if (empty($timezone)) { |
|
1644 | + // let's get a the WordPress UTC offset |
|
1645 | + $offset = get_option('gmt_offset'); |
|
1646 | + $timezone = $this->timezone_convert_to_string_from_offset($offset); |
|
1647 | + } |
|
1648 | + return $timezone; |
|
1649 | + } |
|
1650 | + |
|
1651 | + |
|
1652 | + |
|
1653 | + /** |
|
1654 | + * Gets the wordpress timezone string from a UTC offset |
|
1655 | + * |
|
1656 | + * @param int $offset |
|
1657 | + * @return boolean |
|
1658 | + */ |
|
1659 | + private function timezone_convert_to_string_from_offset($offset) |
|
1660 | + { |
|
1661 | + // shamelessly taken from bottom comment at http://ca1.php.net/manual/en/function.timezone-name-from-abbr.php because timezone_name_from_abbr() did NOT work as expected - its not reliable |
|
1662 | + $offset *= 3600; // convert hour offset to seconds |
|
1663 | + $abbrarray = timezone_abbreviations_list(); |
|
1664 | + foreach ($abbrarray as $abbr) { |
|
1665 | + foreach ($abbr as $city) { |
|
1666 | + if ($city['offset'] == $offset) { |
|
1667 | + return $city['timezone_id']; |
|
1668 | + } |
|
1669 | + } |
|
1670 | + } |
|
1671 | + return false; |
|
1672 | + } |
|
1673 | + |
|
1674 | + |
|
1675 | + |
|
1676 | + public function migration_page_hooks() |
|
1677 | + { |
|
1678 | + add_filter( |
|
1679 | + 'FHEE__ee_migration_page__header', |
|
1680 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1681 | + 10, |
|
1682 | + 3 |
|
1683 | + ); |
|
1684 | + add_filter( |
|
1685 | + 'FHEE__ee_migration_page__p_after_header', |
|
1686 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1687 | + 10, |
|
1688 | + 2 |
|
1689 | + ); |
|
1690 | + add_filter( |
|
1691 | + 'FHEE__ee_migration_page__option_1_main', |
|
1692 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1693 | + 10, |
|
1694 | + 3 |
|
1695 | + ); |
|
1696 | + add_filter( |
|
1697 | + 'FHEE__ee_migration_page__option_1_button_text', |
|
1698 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1699 | + 10, |
|
1700 | + 3 |
|
1701 | + ); |
|
1702 | + add_action( |
|
1703 | + 'AHEE__ee_migration_page__option_1_extra_details', |
|
1704 | + array($this, '_migration_page_hook_option_1_extra_details'), |
|
1705 | + 10, |
|
1706 | + 3 |
|
1707 | + ); |
|
1708 | + add_filter( |
|
1709 | + 'FHEE__ee_migration_page__option_2_main', |
|
1710 | + array($this, '_migrate_page_hook_simplify_version_strings'), |
|
1711 | + 10, |
|
1712 | + 4 |
|
1713 | + ); |
|
1714 | + add_filter( |
|
1715 | + 'FHEE__ee_migration_page__option_2_button_text', |
|
1716 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1717 | + 10, |
|
1718 | + 2 |
|
1719 | + ); |
|
1720 | + add_filter( |
|
1721 | + 'FHEE__ee_migration_page__option_2_details', |
|
1722 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1723 | + 10, |
|
1724 | + 2 |
|
1725 | + ); |
|
1726 | + add_action( |
|
1727 | + 'AHEE__ee_migration_page__after_migration_options_table', |
|
1728 | + array($this, '_migration_page_hook_after_migration_options_table') |
|
1729 | + ); |
|
1730 | + add_filter( |
|
1731 | + 'FHEE__ee_migration_page__done_migration_header', |
|
1732 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1733 | + 10, |
|
1734 | + 2 |
|
1735 | + ); |
|
1736 | + add_filter( |
|
1737 | + 'FHEE__ee_migration_page__p_after_done_migration_header', |
|
1738 | + array($this, '_migration_page_hook_simplify_next_db_state'), |
|
1739 | + 10, |
|
1740 | + 2 |
|
1741 | + ); |
|
1742 | + add_filter( |
|
1743 | + 'FHEE__ee_migration_page__migration_options_template', |
|
1744 | + array($this,'use_migration_options_from_ee3_template') |
|
1745 | + ); |
|
1746 | + } |
|
1747 | + |
|
1748 | + |
|
1749 | + |
|
1750 | + public function _migrate_page_hook_simplify_version_strings( |
|
1751 | + $old_content, |
|
1752 | + $current_db_state, |
|
1753 | + $next_db_state, |
|
1754 | + $ultimate_db_state = null |
|
1755 | + ) { |
|
1756 | + return str_replace( |
|
1757 | + array($current_db_state, $next_db_state, $ultimate_db_state), |
|
1758 | + array(esc_html__('EE3', 'event_espresso'), esc_html__('EE4', 'event_espresso'), esc_html__("EE4", 'event_espresso')), |
|
1759 | + $old_content |
|
1760 | + ); |
|
1761 | + } |
|
1762 | + |
|
1763 | + |
|
1764 | + |
|
1765 | + public function _migration_page_hook_simplify_next_db_state($old_content, $next_db_state) |
|
1766 | + { |
|
1767 | + return str_replace($next_db_state, esc_html__("EE4", 'event_espresso'), $old_content); |
|
1768 | + } |
|
1769 | + |
|
1770 | + |
|
1771 | + |
|
1772 | + public function _migration_page_hook_option_1_extra_details() |
|
1773 | + { |
|
1774 | + ?> |
|
1775 | 1775 | <p><?php printf(esc_html__( |
1776 | - "Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
|
1777 | - "event_espresso" |
|
1778 | - )); ?></p><?php |
|
1779 | - } |
|
1776 | + "Note: many of your EE3 shortcodes will be changed to EE4 shortcodes during this migration (among many other things). Should you revert to EE3, then you should restore to your backup or manually change the EE4 shortcodes back to their EE3 equivalents", |
|
1777 | + "event_espresso" |
|
1778 | + )); ?></p><?php |
|
1779 | + } |
|
1780 | 1780 | |
1781 | 1781 | |
1782 | 1782 | |
1783 | - public function _migration_page_hook_after_migration_options_table() |
|
1784 | - { |
|
1785 | - ?><p class="ee-attention"> |
|
1783 | + public function _migration_page_hook_after_migration_options_table() |
|
1784 | + { |
|
1785 | + ?><p class="ee-attention"> |
|
1786 | 1786 | <strong><span class="reminder-spn"> |
1787 | 1787 | <?php _e( |
1788 | - "Important note to those using Event Espresso 3 addons: ", |
|
1789 | - "event_espresso" |
|
1790 | - ); ?></span></strong> |
|
1788 | + "Important note to those using Event Espresso 3 addons: ", |
|
1789 | + "event_espresso" |
|
1790 | + ); ?></span></strong> |
|
1791 | 1791 | <br/> |
1792 | 1792 | <?php _e( |
1793 | - "Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
|
1794 | - "event_espresso" |
|
1795 | - ); ?> |
|
1793 | + "Unless an addon's description on our website explicitly states that it is compatible with EE4, you should consider it incompatible and know that it WILL NOT WORK correctly with this new version of Event Espresso 4 (EE4). As well, any data for incompatible addons will NOT BE MIGRATED until an updated EE4 compatible version of the addon is available. If you want, or need to keep using your EE3 addons, you should simply continue using EE3 until EE4 compatible versions of your addons become available. To continue using EE3 for now, just deactivate EE4 and reactivate EE3.", |
|
1794 | + "event_espresso" |
|
1795 | + ); ?> |
|
1796 | 1796 | </p><?php |
1797 | - } |
|
1797 | + } |
|
1798 | 1798 | |
1799 | 1799 | |
1800 | 1800 | |
1801 | - /** |
|
1802 | - * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
1803 | - * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
1804 | - * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
1805 | - * @param $template_filepath |
|
1806 | - * @return string |
|
1807 | - */ |
|
1808 | - public function use_migration_options_from_ee3_template($template_filepath) |
|
1809 | - { |
|
1810 | - return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
1811 | - } |
|
1801 | + /** |
|
1802 | + * When showing the migration options, show more options and info than normal (ie, give folks the option |
|
1803 | + * to start using EE4 without migrating. From EE3 that's fine, because it doesn't actually remove any data, because |
|
1804 | + * EE4 doesn't have any yet. But when migrating from EE4 it would remove old data, so its not a great idea). |
|
1805 | + * @param $template_filepath |
|
1806 | + * @return string |
|
1807 | + */ |
|
1808 | + public function use_migration_options_from_ee3_template($template_filepath) |
|
1809 | + { |
|
1810 | + return EE_MAINTENANCE_TEMPLATE_PATH . 'migration_options_from_ee3.template.php'; |
|
1811 | + } |
|
1812 | 1812 | } |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | * @since 4.5.0 |
806 | 806 | * |
807 | 807 | * @param string $meta_cap What meta capability is this mapping. |
808 | - * @param array $map_values array { |
|
808 | + * @param string[] $map_values array { |
|
809 | 809 | * //array of values that MUST match a count of 4. It's okay to send an empty string for |
810 | 810 | * capabilities that don't get mapped to. |
811 | 811 | * |
@@ -880,8 +880,8 @@ discard block |
||
880 | 880 | * @since 4.6.x |
881 | 881 | * |
882 | 882 | * @param $caps |
883 | - * @param $cap |
|
884 | - * @param $user_id |
|
883 | + * @param string $cap |
|
884 | + * @param integer $user_id |
|
885 | 885 | * @param $args |
886 | 886 | * |
887 | 887 | * @return array |
@@ -14,979 +14,979 @@ discard block |
||
14 | 14 | final class EE_Capabilities extends EE_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * the name of the wp option used to store caps previously initialized |
|
19 | - */ |
|
20 | - const option_name = 'ee_caps_initialized'; |
|
21 | - |
|
22 | - /** |
|
23 | - * instance of EE_Capabilities object |
|
24 | - * |
|
25 | - * @var EE_Capabilities |
|
26 | - */ |
|
27 | - private static $_instance; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * This is a map of caps that correspond to a default WP_Role. |
|
32 | - * Array is indexed by Role and values are ee capabilities. |
|
33 | - * |
|
34 | - * @since 4.5.0 |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - private $capabilities_map = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * This used to hold an array of EE_Meta_Capability_Map objects |
|
42 | - * that define the granular capabilities mapped to for a user depending on context. |
|
43 | - * |
|
44 | - * @var EE_Meta_Capability_Map[] |
|
45 | - */ |
|
46 | - private $_meta_caps = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * The internal $capabilities_map needs to be initialized before it can be used. |
|
50 | - * This flag tracks whether that has happened or not. |
|
51 | - * But for this to work, we need three states to indicate: |
|
52 | - * initialization has not occurred at all |
|
53 | - * initialization has started but is not complete |
|
54 | - * initialization is complete |
|
55 | - * The reason this is needed is because the addCaps() method |
|
56 | - * normally requires the $capabilities_map to be initialized, |
|
57 | - * but is also used during the initialization process. |
|
58 | - * So: |
|
59 | - * If initialized === null, init_caps() will be called before any other methods will run. |
|
60 | - * If initialized === false, then init_caps() is in the process of running it's logic. |
|
61 | - * If initialized === true, then init_caps() has completed the initialization process. |
|
62 | - * |
|
63 | - * @var boolean|null $initialized |
|
64 | - */ |
|
65 | - private $initialized; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var boolean $reset |
|
69 | - */ |
|
70 | - private $reset = false; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * singleton method used to instantiate class object |
|
75 | - * |
|
76 | - * @since 4.5.0 |
|
77 | - * |
|
78 | - * @return EE_Capabilities |
|
79 | - */ |
|
80 | - public static function instance() |
|
81 | - { |
|
82 | - // check if instantiated, and if not do so. |
|
83 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
84 | - self::$_instance = new self(); |
|
85 | - } |
|
86 | - return self::$_instance; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * private constructor |
|
92 | - * |
|
93 | - * @since 4.5.0 |
|
94 | - */ |
|
95 | - private function __construct() |
|
96 | - { |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
102 | - * |
|
103 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
104 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
105 | - * ensures that they are up to date. |
|
106 | - * |
|
107 | - * @since 4.5.0 |
|
108 | - * @return bool |
|
109 | - * @throws EE_Error |
|
110 | - */ |
|
111 | - public function init_caps($reset = false) |
|
112 | - { |
|
113 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
114 | - return false; |
|
115 | - } |
|
116 | - $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
117 | - // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
118 | - if ($this->reset) { |
|
119 | - $this->initialized = null; |
|
120 | - $this->capabilities_map = array(); |
|
121 | - delete_option(self::option_name); |
|
122 | - } |
|
123 | - if ($this->initialized === null) { |
|
124 | - $this->initialized = false; |
|
125 | - do_action( |
|
126 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
127 | - $this->reset |
|
128 | - ); |
|
129 | - $this->addCaps($this->_init_caps_map()); |
|
130 | - $this->_set_meta_caps(); |
|
131 | - do_action( |
|
132 | - 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
133 | - $this->capabilities_map |
|
134 | - ); |
|
135 | - $this->initialized = true; |
|
136 | - } |
|
137 | - // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
138 | - $this->reset = false; |
|
139 | - return true; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * This sets the meta caps property. |
|
145 | - * |
|
146 | - * @since 4.5.0 |
|
147 | - * @return void |
|
148 | - * @throws EE_Error |
|
149 | - */ |
|
150 | - private function _set_meta_caps() |
|
151 | - { |
|
152 | - // get default meta caps and filter the returned array |
|
153 | - $this->_meta_caps = apply_filters( |
|
154 | - 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
155 | - $this->_get_default_meta_caps_array() |
|
156 | - ); |
|
157 | - // add filter for map_meta_caps but only if models can query. |
|
158 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
159 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * This builds and returns the default meta_caps array only once. |
|
166 | - * |
|
167 | - * @since 4.8.28.rc.012 |
|
168 | - * @return array |
|
169 | - * @throws EE_Error |
|
170 | - */ |
|
171 | - private function _get_default_meta_caps_array() |
|
172 | - { |
|
173 | - static $default_meta_caps = array(); |
|
174 | - // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
175 | - if (empty($default_meta_caps)) { |
|
176 | - $default_meta_caps = array( |
|
177 | - // edits |
|
178 | - new EE_Meta_Capability_Map_Edit( |
|
179 | - 'ee_edit_event', |
|
180 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
181 | - ), |
|
182 | - new EE_Meta_Capability_Map_Edit( |
|
183 | - 'ee_edit_venue', |
|
184 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
185 | - ), |
|
186 | - new EE_Meta_Capability_Map_Edit( |
|
187 | - 'ee_edit_registration', |
|
188 | - array('Registration', '', 'ee_edit_others_registrations', '') |
|
189 | - ), |
|
190 | - new EE_Meta_Capability_Map_Edit( |
|
191 | - 'ee_edit_checkin', |
|
192 | - array('Registration', '', 'ee_edit_others_checkins', '') |
|
193 | - ), |
|
194 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
195 | - 'ee_edit_message', |
|
196 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
197 | - ), |
|
198 | - new EE_Meta_Capability_Map_Edit( |
|
199 | - 'ee_edit_default_ticket', |
|
200 | - array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
201 | - ), |
|
202 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
203 | - 'ee_edit_question', |
|
204 | - array('Question', '', '', 'ee_edit_system_questions') |
|
205 | - ), |
|
206 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
207 | - 'ee_edit_question_group', |
|
208 | - array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
209 | - ), |
|
210 | - new EE_Meta_Capability_Map_Edit( |
|
211 | - 'ee_edit_payment_method', |
|
212 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
213 | - ), |
|
214 | - // reads |
|
215 | - new EE_Meta_Capability_Map_Read( |
|
216 | - 'ee_read_event', |
|
217 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
218 | - ), |
|
219 | - new EE_Meta_Capability_Map_Read( |
|
220 | - 'ee_read_venue', |
|
221 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
222 | - ), |
|
223 | - new EE_Meta_Capability_Map_Read( |
|
224 | - 'ee_read_registration', |
|
225 | - array('Registration', '', 'ee_read_others_registrations', '') |
|
226 | - ), |
|
227 | - new EE_Meta_Capability_Map_Read( |
|
228 | - 'ee_read_checkin', |
|
229 | - array('Registration', '', 'ee_read_others_checkins', '') |
|
230 | - ), |
|
231 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
232 | - 'ee_read_message', |
|
233 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
234 | - ), |
|
235 | - new EE_Meta_Capability_Map_Read( |
|
236 | - 'ee_read_default_ticket', |
|
237 | - array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
238 | - ), |
|
239 | - new EE_Meta_Capability_Map_Read( |
|
240 | - 'ee_read_payment_method', |
|
241 | - array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
242 | - ), |
|
243 | - // deletes |
|
244 | - new EE_Meta_Capability_Map_Delete( |
|
245 | - 'ee_delete_event', |
|
246 | - array( |
|
247 | - 'Event', |
|
248 | - 'ee_delete_published_events', |
|
249 | - 'ee_delete_others_events', |
|
250 | - 'ee_delete_private_events', |
|
251 | - ) |
|
252 | - ), |
|
253 | - new EE_Meta_Capability_Map_Delete( |
|
254 | - 'ee_delete_venue', |
|
255 | - array( |
|
256 | - 'Venue', |
|
257 | - 'ee_delete_published_venues', |
|
258 | - 'ee_delete_others_venues', |
|
259 | - 'ee_delete_private_venues', |
|
260 | - ) |
|
261 | - ), |
|
262 | - new EE_Meta_Capability_Map_Delete( |
|
263 | - 'ee_delete_registration', |
|
264 | - array('Registration', '', 'ee_delete_others_registrations', '') |
|
265 | - ), |
|
266 | - new EE_Meta_Capability_Map_Delete( |
|
267 | - 'ee_delete_checkin', |
|
268 | - array('Registration', '', 'ee_delete_others_checkins', '') |
|
269 | - ), |
|
270 | - new EE_Meta_Capability_Map_Messages_Cap( |
|
271 | - 'ee_delete_message', |
|
272 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
273 | - ), |
|
274 | - new EE_Meta_Capability_Map_Delete( |
|
275 | - 'ee_delete_default_ticket', |
|
276 | - array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
277 | - ), |
|
278 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
279 | - 'ee_delete_question', |
|
280 | - array('Question', '', '', 'delete_system_questions') |
|
281 | - ), |
|
282 | - new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
283 | - 'ee_delete_question_group', |
|
284 | - array('Question_Group', '', '', 'delete_system_question_groups') |
|
285 | - ), |
|
286 | - new EE_Meta_Capability_Map_Delete( |
|
287 | - 'ee_delete_payment_method', |
|
288 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
289 | - ), |
|
290 | - ); |
|
291 | - } |
|
292 | - return $default_meta_caps; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
298 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
299 | - * |
|
300 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
301 | - * |
|
302 | - * @since 4.5.0 |
|
303 | - * @see wp-includes/capabilities.php |
|
304 | - * |
|
305 | - * @param array $caps actual users capabilities |
|
306 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
307 | - * @param int $user_id The user id |
|
308 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
309 | - * @return array actual users capabilities |
|
310 | - * @throws EE_Error |
|
311 | - */ |
|
312 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
313 | - { |
|
314 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
315 | - // loop through our _meta_caps array |
|
316 | - foreach ($this->_meta_caps as $meta_map) { |
|
317 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
318 | - continue; |
|
319 | - } |
|
320 | - // don't load models if there is no object ID in the args |
|
321 | - if (! empty($args[0])) { |
|
322 | - $meta_map->ensure_is_model(); |
|
323 | - } |
|
324 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
325 | - } |
|
326 | - } |
|
327 | - return $caps; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
333 | - * Note this array is filtered. |
|
334 | - * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
335 | - * |
|
336 | - * @since 4.5.0 |
|
337 | - * |
|
338 | - * @return array |
|
339 | - */ |
|
340 | - private function _init_caps_map() |
|
341 | - { |
|
342 | - return apply_filters( |
|
343 | - 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
344 | - array( |
|
345 | - 'administrator' => array( |
|
346 | - // basic access |
|
347 | - 'ee_read_ee', |
|
348 | - // gateways |
|
349 | - /** |
|
350 | - * note that with payment method capabilities, although we've implemented |
|
351 | - * capability mapping which will be used for accessing payment methods owned by |
|
352 | - * other users. This is not fully implemented yet in the payment method ui. |
|
353 | - * Currently only the "plural" caps are in active use. |
|
354 | - * (Specific payment method caps are in use as well). |
|
355 | - **/ |
|
356 | - 'ee_manage_gateways', |
|
357 | - 'ee_read_payment_methods', |
|
358 | - 'ee_read_others_payment_methods', |
|
359 | - 'ee_edit_payment_methods', |
|
360 | - 'ee_edit_others_payment_methods', |
|
361 | - 'ee_delete_payment_methods', |
|
362 | - // events |
|
363 | - 'ee_publish_events', |
|
364 | - 'ee_read_private_events', |
|
365 | - 'ee_read_others_events', |
|
366 | - 'ee_read_events', |
|
367 | - 'ee_edit_events', |
|
368 | - 'ee_edit_published_events', |
|
369 | - 'ee_edit_others_events', |
|
370 | - 'ee_edit_private_events', |
|
371 | - 'ee_delete_published_events', |
|
372 | - 'ee_delete_private_events', |
|
373 | - 'ee_delete_events', |
|
374 | - 'ee_delete_others_events', |
|
375 | - // event categories |
|
376 | - 'ee_manage_event_categories', |
|
377 | - 'ee_edit_event_category', |
|
378 | - 'ee_delete_event_category', |
|
379 | - 'ee_assign_event_category', |
|
380 | - // venues |
|
381 | - 'ee_publish_venues', |
|
382 | - 'ee_read_venues', |
|
383 | - 'ee_read_others_venues', |
|
384 | - 'ee_read_private_venues', |
|
385 | - 'ee_edit_venues', |
|
386 | - 'ee_edit_others_venues', |
|
387 | - 'ee_edit_published_venues', |
|
388 | - 'ee_edit_private_venues', |
|
389 | - 'ee_delete_venues', |
|
390 | - 'ee_delete_others_venues', |
|
391 | - 'ee_delete_private_venues', |
|
392 | - 'ee_delete_published_venues', |
|
393 | - // venue categories |
|
394 | - 'ee_manage_venue_categories', |
|
395 | - 'ee_edit_venue_category', |
|
396 | - 'ee_delete_venue_category', |
|
397 | - 'ee_assign_venue_category', |
|
398 | - // contacts |
|
399 | - 'ee_read_contacts', |
|
400 | - 'ee_edit_contacts', |
|
401 | - 'ee_delete_contacts', |
|
402 | - // registrations |
|
403 | - 'ee_read_registrations', |
|
404 | - 'ee_read_others_registrations', |
|
405 | - 'ee_edit_registrations', |
|
406 | - 'ee_edit_others_registrations', |
|
407 | - 'ee_delete_registrations', |
|
408 | - // checkins |
|
409 | - 'ee_read_others_checkins', |
|
410 | - 'ee_read_checkins', |
|
411 | - 'ee_edit_checkins', |
|
412 | - 'ee_edit_others_checkins', |
|
413 | - 'ee_delete_checkins', |
|
414 | - 'ee_delete_others_checkins', |
|
415 | - // transactions && payments |
|
416 | - 'ee_read_transaction', |
|
417 | - 'ee_read_transactions', |
|
418 | - 'ee_edit_payments', |
|
419 | - 'ee_delete_payments', |
|
420 | - // messages |
|
421 | - 'ee_read_messages', |
|
422 | - 'ee_read_others_messages', |
|
423 | - 'ee_read_global_messages', |
|
424 | - 'ee_edit_global_messages', |
|
425 | - 'ee_edit_messages', |
|
426 | - 'ee_edit_others_messages', |
|
427 | - 'ee_delete_messages', |
|
428 | - 'ee_delete_others_messages', |
|
429 | - 'ee_delete_global_messages', |
|
430 | - 'ee_send_message', |
|
431 | - // tickets |
|
432 | - 'ee_read_default_tickets', |
|
433 | - 'ee_read_others_default_tickets', |
|
434 | - 'ee_edit_default_tickets', |
|
435 | - 'ee_edit_others_default_tickets', |
|
436 | - 'ee_delete_default_tickets', |
|
437 | - 'ee_delete_others_default_tickets', |
|
438 | - // prices |
|
439 | - 'ee_edit_default_price', |
|
440 | - 'ee_edit_default_prices', |
|
441 | - 'ee_delete_default_price', |
|
442 | - 'ee_delete_default_prices', |
|
443 | - 'ee_edit_default_price_type', |
|
444 | - 'ee_edit_default_price_types', |
|
445 | - 'ee_delete_default_price_type', |
|
446 | - 'ee_delete_default_price_types', |
|
447 | - 'ee_read_default_prices', |
|
448 | - 'ee_read_default_price_types', |
|
449 | - // registration form |
|
450 | - 'ee_edit_questions', |
|
451 | - 'ee_edit_system_questions', |
|
452 | - 'ee_read_questions', |
|
453 | - 'ee_delete_questions', |
|
454 | - 'ee_edit_question_groups', |
|
455 | - 'ee_read_question_groups', |
|
456 | - 'ee_edit_system_question_groups', |
|
457 | - 'ee_delete_question_groups', |
|
458 | - // event_type taxonomy |
|
459 | - 'ee_assign_event_type', |
|
460 | - 'ee_manage_event_types', |
|
461 | - 'ee_edit_event_type', |
|
462 | - 'ee_delete_event_type', |
|
463 | - ), |
|
464 | - 'ee_events_administrator' => array( |
|
465 | - // core wp caps |
|
466 | - 'read', |
|
467 | - 'read_private_pages', |
|
468 | - 'read_private_posts', |
|
469 | - 'edit_users', |
|
470 | - 'edit_posts', |
|
471 | - 'edit_pages', |
|
472 | - 'edit_published_posts', |
|
473 | - 'edit_published_pages', |
|
474 | - 'edit_private_pages', |
|
475 | - 'edit_private_posts', |
|
476 | - 'edit_others_posts', |
|
477 | - 'edit_others_pages', |
|
478 | - 'publish_posts', |
|
479 | - 'publish_pages', |
|
480 | - 'delete_posts', |
|
481 | - 'delete_pages', |
|
482 | - 'delete_private_pages', |
|
483 | - 'delete_private_posts', |
|
484 | - 'delete_published_pages', |
|
485 | - 'delete_published_posts', |
|
486 | - 'delete_others_posts', |
|
487 | - 'delete_others_pages', |
|
488 | - 'manage_categories', |
|
489 | - 'manage_links', |
|
490 | - 'moderate_comments', |
|
491 | - 'unfiltered_html', |
|
492 | - 'upload_files', |
|
493 | - 'export', |
|
494 | - 'import', |
|
495 | - 'list_users', |
|
496 | - 'level_1', // required if user with this role shows up in author dropdowns |
|
497 | - // basic ee access |
|
498 | - 'ee_read_ee', |
|
499 | - // events |
|
500 | - 'ee_publish_events', |
|
501 | - 'ee_read_private_events', |
|
502 | - 'ee_read_others_events', |
|
503 | - 'ee_read_event', |
|
504 | - 'ee_read_events', |
|
505 | - 'ee_edit_event', |
|
506 | - 'ee_edit_events', |
|
507 | - 'ee_edit_published_events', |
|
508 | - 'ee_edit_others_events', |
|
509 | - 'ee_edit_private_events', |
|
510 | - 'ee_delete_published_events', |
|
511 | - 'ee_delete_private_events', |
|
512 | - 'ee_delete_event', |
|
513 | - 'ee_delete_events', |
|
514 | - 'ee_delete_others_events', |
|
515 | - // event categories |
|
516 | - 'ee_manage_event_categories', |
|
517 | - 'ee_edit_event_category', |
|
518 | - 'ee_delete_event_category', |
|
519 | - 'ee_assign_event_category', |
|
520 | - // venues |
|
521 | - 'ee_publish_venues', |
|
522 | - 'ee_read_venue', |
|
523 | - 'ee_read_venues', |
|
524 | - 'ee_read_others_venues', |
|
525 | - 'ee_read_private_venues', |
|
526 | - 'ee_edit_venue', |
|
527 | - 'ee_edit_venues', |
|
528 | - 'ee_edit_others_venues', |
|
529 | - 'ee_edit_published_venues', |
|
530 | - 'ee_edit_private_venues', |
|
531 | - 'ee_delete_venue', |
|
532 | - 'ee_delete_venues', |
|
533 | - 'ee_delete_others_venues', |
|
534 | - 'ee_delete_private_venues', |
|
535 | - 'ee_delete_published_venues', |
|
536 | - // venue categories |
|
537 | - 'ee_manage_venue_categories', |
|
538 | - 'ee_edit_venue_category', |
|
539 | - 'ee_delete_venue_category', |
|
540 | - 'ee_assign_venue_category', |
|
541 | - // contacts |
|
542 | - 'ee_read_contacts', |
|
543 | - 'ee_edit_contacts', |
|
544 | - 'ee_delete_contacts', |
|
545 | - // registrations |
|
546 | - 'ee_read_registrations', |
|
547 | - 'ee_read_others_registrations', |
|
548 | - 'ee_edit_registration', |
|
549 | - 'ee_edit_registrations', |
|
550 | - 'ee_edit_others_registrations', |
|
551 | - 'ee_delete_registration', |
|
552 | - 'ee_delete_registrations', |
|
553 | - // checkins |
|
554 | - 'ee_read_others_checkins', |
|
555 | - 'ee_read_checkins', |
|
556 | - 'ee_edit_checkins', |
|
557 | - 'ee_edit_others_checkins', |
|
558 | - 'ee_delete_checkins', |
|
559 | - 'ee_delete_others_checkins', |
|
560 | - // transactions && payments |
|
561 | - 'ee_read_transaction', |
|
562 | - 'ee_read_transactions', |
|
563 | - 'ee_edit_payments', |
|
564 | - 'ee_delete_payments', |
|
565 | - // messages |
|
566 | - 'ee_read_messages', |
|
567 | - 'ee_read_others_messages', |
|
568 | - 'ee_read_global_messages', |
|
569 | - 'ee_edit_global_messages', |
|
570 | - 'ee_edit_messages', |
|
571 | - 'ee_edit_others_messages', |
|
572 | - 'ee_delete_messages', |
|
573 | - 'ee_delete_others_messages', |
|
574 | - 'ee_delete_global_messages', |
|
575 | - 'ee_send_message', |
|
576 | - // tickets |
|
577 | - 'ee_read_default_tickets', |
|
578 | - 'ee_read_others_default_tickets', |
|
579 | - 'ee_edit_default_tickets', |
|
580 | - 'ee_edit_others_default_tickets', |
|
581 | - 'ee_delete_default_tickets', |
|
582 | - 'ee_delete_others_default_tickets', |
|
583 | - // prices |
|
584 | - 'ee_edit_default_price', |
|
585 | - 'ee_edit_default_prices', |
|
586 | - 'ee_delete_default_price', |
|
587 | - 'ee_delete_default_prices', |
|
588 | - 'ee_edit_default_price_type', |
|
589 | - 'ee_edit_default_price_types', |
|
590 | - 'ee_delete_default_price_type', |
|
591 | - 'ee_delete_default_price_types', |
|
592 | - 'ee_read_default_prices', |
|
593 | - 'ee_read_default_price_types', |
|
594 | - // registration form |
|
595 | - 'ee_edit_questions', |
|
596 | - 'ee_edit_system_questions', |
|
597 | - 'ee_read_questions', |
|
598 | - 'ee_delete_questions', |
|
599 | - 'ee_edit_question_groups', |
|
600 | - 'ee_read_question_groups', |
|
601 | - 'ee_edit_system_question_groups', |
|
602 | - 'ee_delete_question_groups', |
|
603 | - // event_type taxonomy |
|
604 | - 'ee_assign_event_type', |
|
605 | - 'ee_manage_event_types', |
|
606 | - 'ee_edit_event_type', |
|
607 | - 'ee_delete_event_type', |
|
608 | - ), |
|
609 | - ) |
|
610 | - ); |
|
611 | - } |
|
612 | - |
|
613 | - |
|
614 | - /** |
|
615 | - * @return bool |
|
616 | - * @throws EE_Error |
|
617 | - */ |
|
618 | - private function setupCapabilitiesMap() |
|
619 | - { |
|
620 | - // if the initialization process hasn't even started, then we need to call init_caps() |
|
621 | - if ($this->initialized === null) { |
|
622 | - return $this->init_caps(); |
|
623 | - } |
|
624 | - // unless resetting, get caps from db if we haven't already |
|
625 | - $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
626 | - ? $this->capabilities_map |
|
627 | - : get_option(self::option_name, array()); |
|
628 | - return true; |
|
629 | - } |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * @param bool $update |
|
634 | - * @return bool |
|
635 | - */ |
|
636 | - private function updateCapabilitiesMap($update = true) |
|
637 | - { |
|
638 | - return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - /** |
|
643 | - * Adds capabilities to roles. |
|
644 | - * |
|
645 | - * @since 4.9.42 |
|
646 | - * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
647 | - * Note that this should ONLY be called on activation hook |
|
648 | - * otherwise the caps will be added on every request. |
|
649 | - * @return bool |
|
650 | - * @throws \EE_Error |
|
651 | - */ |
|
652 | - public function addCaps(array $capabilities_to_add) |
|
653 | - { |
|
654 | - // don't do anything if the capabilities map can not be initialized |
|
655 | - if (! $this->setupCapabilitiesMap()) { |
|
656 | - return false; |
|
657 | - } |
|
658 | - // and filter the array so others can get in on the fun during resets |
|
659 | - $capabilities_to_add = apply_filters( |
|
660 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
661 | - $capabilities_to_add, |
|
662 | - $this->reset, |
|
663 | - $this->capabilities_map |
|
664 | - ); |
|
665 | - $update_capabilities_map = false; |
|
666 | - // if not reset, see what caps are new for each role. if they're new, add them. |
|
667 | - foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
668 | - if (is_array($caps_for_role)) { |
|
669 | - foreach ($caps_for_role as $cap) { |
|
670 | - if (! $this->capHasBeenAddedToRole($role, $cap) |
|
671 | - && $this->add_cap_to_role($role, $cap, true, false) |
|
672 | - ) { |
|
673 | - $update_capabilities_map = true; |
|
674 | - } |
|
675 | - } |
|
676 | - } |
|
677 | - } |
|
678 | - // now let's just save the cap that has been set but only if there's been a change. |
|
679 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
680 | - $this->flushWpUser($updated); |
|
681 | - do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
682 | - return $updated; |
|
683 | - } |
|
684 | - |
|
685 | - |
|
686 | - /** |
|
687 | - * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
688 | - * |
|
689 | - * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
690 | - * @return bool |
|
691 | - * @throws \EE_Error |
|
692 | - */ |
|
693 | - public function removeCaps($caps_map) |
|
694 | - { |
|
695 | - // don't do anything if the capabilities map can not be initialized |
|
696 | - if (! $this->setupCapabilitiesMap()) { |
|
697 | - return false; |
|
698 | - } |
|
699 | - $update_capabilities_map = false; |
|
700 | - foreach ($caps_map as $role => $caps_for_role) { |
|
701 | - if (is_array($caps_for_role)) { |
|
702 | - foreach ($caps_for_role as $cap) { |
|
703 | - if ($this->capHasBeenAddedToRole($role, $cap) |
|
704 | - && $this->remove_cap_from_role($role, $cap, false) |
|
705 | - ) { |
|
706 | - $update_capabilities_map = true; |
|
707 | - } |
|
708 | - } |
|
709 | - } |
|
710 | - } |
|
711 | - // maybe resave the caps |
|
712 | - $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
713 | - $this->flushWpUser($updated); |
|
714 | - return $updated; |
|
715 | - } |
|
716 | - |
|
717 | - |
|
718 | - /** |
|
719 | - * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from |
|
720 | - * the roles on that user. |
|
721 | - * |
|
722 | - * @param bool $flush Default is to flush the WP_User object. If false, then this method effectively does nothing. |
|
723 | - */ |
|
724 | - private function flushWpUser($flush = true) |
|
725 | - { |
|
726 | - if ($flush) { |
|
727 | - $user = wp_get_current_user(); |
|
728 | - if ($user instanceof WP_User) { |
|
729 | - $user->get_role_caps(); |
|
730 | - } |
|
731 | - } |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
737 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
738 | - * this is a wrapper for $wp_role->add_cap() |
|
739 | - * |
|
740 | - * @see wp-includes/capabilities.php |
|
741 | - * @since 4.5.0 |
|
742 | - * @param string|WP_Role $role A WordPress role the capability is being added to |
|
743 | - * @param string $cap The capability being added to the role |
|
744 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
745 | - * @param bool $update_capabilities_map |
|
746 | - * @return bool |
|
747 | - * @throws \EE_Error |
|
748 | - */ |
|
749 | - public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
750 | - { |
|
751 | - // capture incoming value for $role because we may need it to create a new WP_Role |
|
752 | - $orig_role = $role; |
|
753 | - $role = $role instanceof WP_Role ? $role : get_role($role); |
|
754 | - // if the role isn't available then we create it. |
|
755 | - if (! $role instanceof WP_Role) { |
|
756 | - // if a plugin wants to create a specific role name then they should create the role before |
|
757 | - // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
758 | - // - removes any `ee_` namespacing from the start of the slug. |
|
759 | - // - replaces `_` with ` ` (empty space). |
|
760 | - // - sentence case on the resulting string. |
|
761 | - $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
762 | - $role = add_role($orig_role, $role_label); |
|
763 | - } |
|
764 | - if ($role instanceof WP_Role) { |
|
765 | - // don't do anything if the capabilities map can not be initialized |
|
766 | - if (! $this->setupCapabilitiesMap()) { |
|
767 | - return false; |
|
768 | - } |
|
769 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
770 | - $role->add_cap($cap, $grant); |
|
771 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
772 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
773 | - return true; |
|
774 | - } |
|
775 | - } |
|
776 | - return false; |
|
777 | - } |
|
778 | - |
|
779 | - |
|
780 | - /** |
|
781 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
782 | - * Wrapper for $wp_role->remove_cap() |
|
783 | - * |
|
784 | - * @see wp-includes/capabilities.php |
|
785 | - * @since 4.5.0 |
|
786 | - * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
787 | - * @param string $cap The capability being removed |
|
788 | - * @param bool $update_capabilities_map |
|
789 | - * @return bool |
|
790 | - * @throws \EE_Error |
|
791 | - */ |
|
792 | - public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
793 | - { |
|
794 | - // don't do anything if the capabilities map can not be initialized |
|
795 | - if (! $this->setupCapabilitiesMap()) { |
|
796 | - return false; |
|
797 | - } |
|
798 | - |
|
799 | - $role = $role instanceof WP_Role ? $role : get_role($role); |
|
800 | - if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
801 | - $role->remove_cap($cap); |
|
802 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
803 | - $this->updateCapabilitiesMap($update_capabilities_map); |
|
804 | - return true; |
|
805 | - } |
|
806 | - return false; |
|
807 | - } |
|
808 | - |
|
809 | - |
|
810 | - /** |
|
811 | - * @param string $role_name |
|
812 | - * @param string $cap |
|
813 | - * @param bool $get_index |
|
814 | - * @return bool|mixed |
|
815 | - */ |
|
816 | - private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false) |
|
817 | - { |
|
818 | - if (isset($this->capabilities_map[ $role_name ]) |
|
819 | - && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false |
|
820 | - ) { |
|
821 | - return $get_index ? $index : true; |
|
822 | - } |
|
823 | - return false; |
|
824 | - } |
|
825 | - |
|
826 | - |
|
827 | - /** |
|
828 | - * Wrapper for the native WP current_user_can() method. |
|
829 | - * This is provided as a handy method for a couple things: |
|
830 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
831 | - * write those filters wherever current_user_can is called). |
|
832 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
833 | - * |
|
834 | - * @since 4.5.0 |
|
835 | - * |
|
836 | - * @param string $cap The cap being checked. |
|
837 | - * @param string $context The context where the current_user_can is being called from. |
|
838 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
839 | - * filters. |
|
840 | - * |
|
841 | - * @return bool Whether user can or not. |
|
842 | - */ |
|
843 | - public function current_user_can($cap, $context, $id = 0) |
|
844 | - { |
|
845 | - // apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
846 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
847 | - $filtered_cap = apply_filters( |
|
848 | - 'FHEE__EE_Capabilities__current_user_can__cap', |
|
849 | - $filtered_cap, |
|
850 | - $context, |
|
851 | - $cap, |
|
852 | - $id |
|
853 | - ); |
|
854 | - return ! empty($id) |
|
855 | - ? current_user_can($filtered_cap, $id) |
|
856 | - : current_user_can($filtered_cap); |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - /** |
|
861 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
862 | - * |
|
863 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
864 | - * @param string $cap The capability string being checked |
|
865 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
866 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
867 | - * filters) |
|
868 | - * |
|
869 | - * @return bool Whether user can or not. |
|
870 | - */ |
|
871 | - public function user_can($user, $cap, $context, $id = 0) |
|
872 | - { |
|
873 | - // apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
874 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
875 | - $filtered_cap = apply_filters( |
|
876 | - 'FHEE__EE_Capabilities__user_can__cap', |
|
877 | - $filtered_cap, |
|
878 | - $context, |
|
879 | - $cap, |
|
880 | - $user, |
|
881 | - $id |
|
882 | - ); |
|
883 | - return ! empty($id) |
|
884 | - ? user_can($user, $filtered_cap, $id) |
|
885 | - : user_can($user, $filtered_cap); |
|
886 | - } |
|
887 | - |
|
888 | - |
|
889 | - /** |
|
890 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
891 | - * This is provided as a handy method for a couple things: |
|
892 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
893 | - * write those filters wherever current_user_can is called). |
|
894 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
895 | - * |
|
896 | - * @since 4.5.0 |
|
897 | - * |
|
898 | - * @param int $blog_id The blog id that is being checked for. |
|
899 | - * @param string $cap The cap being checked. |
|
900 | - * @param string $context The context where the current_user_can is being called from. |
|
901 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
902 | - * filters. |
|
903 | - * |
|
904 | - * @return bool Whether user can or not. |
|
905 | - */ |
|
906 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
907 | - { |
|
908 | - $user_can = ! empty($id) |
|
909 | - ? current_user_can_for_blog($blog_id, $cap, $id) |
|
910 | - : current_user_can($blog_id, $cap); |
|
911 | - // apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
912 | - $user_can = apply_filters( |
|
913 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
914 | - $user_can, |
|
915 | - $blog_id, |
|
916 | - $cap, |
|
917 | - $id |
|
918 | - ); |
|
919 | - $user_can = apply_filters( |
|
920 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
921 | - $user_can, |
|
922 | - $context, |
|
923 | - $blog_id, |
|
924 | - $cap, |
|
925 | - $id |
|
926 | - ); |
|
927 | - return $user_can; |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * This helper method just returns an array of registered EE capabilities. |
|
933 | - * |
|
934 | - * @since 4.5.0 |
|
935 | - * @param string $role If empty then the entire role/capability map is returned. |
|
936 | - * Otherwise just the capabilities for the given role are returned. |
|
937 | - * @return array |
|
938 | - * @throws EE_Error |
|
939 | - */ |
|
940 | - public function get_ee_capabilities($role = 'administrator') |
|
941 | - { |
|
942 | - if (! $this->initialized) { |
|
943 | - $this->init_caps(); |
|
944 | - } |
|
945 | - if (empty($role)) { |
|
946 | - return $this->capabilities_map; |
|
947 | - } |
|
948 | - return isset($this->capabilities_map[ $role ]) |
|
949 | - ? $this->capabilities_map[ $role ] |
|
950 | - : array(); |
|
951 | - } |
|
952 | - |
|
953 | - |
|
954 | - /** |
|
955 | - * @deprecated 4.9.42 |
|
956 | - * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
957 | - * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
958 | - * @param array $caps_map Optional. |
|
959 | - * Can be used to send a custom map of roles and capabilities for setting them up. |
|
960 | - * Note that this should ONLY be called on activation hook or some other one-time |
|
961 | - * task otherwise the caps will be added on every request. |
|
962 | - * @return void |
|
963 | - * @throws EE_Error |
|
964 | - */ |
|
965 | - public function init_role_caps($reset = false, $caps_map = array()) |
|
966 | - { |
|
967 | - // If this method is called directly and reset is set as 'true', |
|
968 | - // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
969 | - // to guarantee that everything is set up correctly. |
|
970 | - // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
971 | - if ($reset) { |
|
972 | - EE_Error::doing_it_wrong( |
|
973 | - __METHOD__, |
|
974 | - sprintf( |
|
975 | - esc_html__( |
|
976 | - 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
977 | - 'event_espresso' |
|
978 | - ), |
|
979 | - '$reset', |
|
980 | - __METHOD__ . '()', |
|
981 | - 'EE_Capabilities::init_caps()', |
|
982 | - 'true' |
|
983 | - ), |
|
984 | - '4.9.42', |
|
985 | - '5.0.0' |
|
986 | - ); |
|
987 | - } |
|
988 | - $this->addCaps($caps_map); |
|
989 | - } |
|
17 | + /** |
|
18 | + * the name of the wp option used to store caps previously initialized |
|
19 | + */ |
|
20 | + const option_name = 'ee_caps_initialized'; |
|
21 | + |
|
22 | + /** |
|
23 | + * instance of EE_Capabilities object |
|
24 | + * |
|
25 | + * @var EE_Capabilities |
|
26 | + */ |
|
27 | + private static $_instance; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * This is a map of caps that correspond to a default WP_Role. |
|
32 | + * Array is indexed by Role and values are ee capabilities. |
|
33 | + * |
|
34 | + * @since 4.5.0 |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + private $capabilities_map = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * This used to hold an array of EE_Meta_Capability_Map objects |
|
42 | + * that define the granular capabilities mapped to for a user depending on context. |
|
43 | + * |
|
44 | + * @var EE_Meta_Capability_Map[] |
|
45 | + */ |
|
46 | + private $_meta_caps = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * The internal $capabilities_map needs to be initialized before it can be used. |
|
50 | + * This flag tracks whether that has happened or not. |
|
51 | + * But for this to work, we need three states to indicate: |
|
52 | + * initialization has not occurred at all |
|
53 | + * initialization has started but is not complete |
|
54 | + * initialization is complete |
|
55 | + * The reason this is needed is because the addCaps() method |
|
56 | + * normally requires the $capabilities_map to be initialized, |
|
57 | + * but is also used during the initialization process. |
|
58 | + * So: |
|
59 | + * If initialized === null, init_caps() will be called before any other methods will run. |
|
60 | + * If initialized === false, then init_caps() is in the process of running it's logic. |
|
61 | + * If initialized === true, then init_caps() has completed the initialization process. |
|
62 | + * |
|
63 | + * @var boolean|null $initialized |
|
64 | + */ |
|
65 | + private $initialized; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var boolean $reset |
|
69 | + */ |
|
70 | + private $reset = false; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * singleton method used to instantiate class object |
|
75 | + * |
|
76 | + * @since 4.5.0 |
|
77 | + * |
|
78 | + * @return EE_Capabilities |
|
79 | + */ |
|
80 | + public static function instance() |
|
81 | + { |
|
82 | + // check if instantiated, and if not do so. |
|
83 | + if (! self::$_instance instanceof EE_Capabilities) { |
|
84 | + self::$_instance = new self(); |
|
85 | + } |
|
86 | + return self::$_instance; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * private constructor |
|
92 | + * |
|
93 | + * @since 4.5.0 |
|
94 | + */ |
|
95 | + private function __construct() |
|
96 | + { |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
102 | + * |
|
103 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
104 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
105 | + * ensures that they are up to date. |
|
106 | + * |
|
107 | + * @since 4.5.0 |
|
108 | + * @return bool |
|
109 | + * @throws EE_Error |
|
110 | + */ |
|
111 | + public function init_caps($reset = false) |
|
112 | + { |
|
113 | + if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
114 | + return false; |
|
115 | + } |
|
116 | + $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
|
117 | + // if reset, then completely delete the cache option and clear the $capabilities_map property. |
|
118 | + if ($this->reset) { |
|
119 | + $this->initialized = null; |
|
120 | + $this->capabilities_map = array(); |
|
121 | + delete_option(self::option_name); |
|
122 | + } |
|
123 | + if ($this->initialized === null) { |
|
124 | + $this->initialized = false; |
|
125 | + do_action( |
|
126 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
127 | + $this->reset |
|
128 | + ); |
|
129 | + $this->addCaps($this->_init_caps_map()); |
|
130 | + $this->_set_meta_caps(); |
|
131 | + do_action( |
|
132 | + 'AHEE__EE_Capabilities__init_caps__after_initialization', |
|
133 | + $this->capabilities_map |
|
134 | + ); |
|
135 | + $this->initialized = true; |
|
136 | + } |
|
137 | + // reset $this->reset so that it's not stuck on true if init_caps() gets called again |
|
138 | + $this->reset = false; |
|
139 | + return true; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * This sets the meta caps property. |
|
145 | + * |
|
146 | + * @since 4.5.0 |
|
147 | + * @return void |
|
148 | + * @throws EE_Error |
|
149 | + */ |
|
150 | + private function _set_meta_caps() |
|
151 | + { |
|
152 | + // get default meta caps and filter the returned array |
|
153 | + $this->_meta_caps = apply_filters( |
|
154 | + 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', |
|
155 | + $this->_get_default_meta_caps_array() |
|
156 | + ); |
|
157 | + // add filter for map_meta_caps but only if models can query. |
|
158 | + if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
159 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * This builds and returns the default meta_caps array only once. |
|
166 | + * |
|
167 | + * @since 4.8.28.rc.012 |
|
168 | + * @return array |
|
169 | + * @throws EE_Error |
|
170 | + */ |
|
171 | + private function _get_default_meta_caps_array() |
|
172 | + { |
|
173 | + static $default_meta_caps = array(); |
|
174 | + // make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
175 | + if (empty($default_meta_caps)) { |
|
176 | + $default_meta_caps = array( |
|
177 | + // edits |
|
178 | + new EE_Meta_Capability_Map_Edit( |
|
179 | + 'ee_edit_event', |
|
180 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events') |
|
181 | + ), |
|
182 | + new EE_Meta_Capability_Map_Edit( |
|
183 | + 'ee_edit_venue', |
|
184 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues') |
|
185 | + ), |
|
186 | + new EE_Meta_Capability_Map_Edit( |
|
187 | + 'ee_edit_registration', |
|
188 | + array('Registration', '', 'ee_edit_others_registrations', '') |
|
189 | + ), |
|
190 | + new EE_Meta_Capability_Map_Edit( |
|
191 | + 'ee_edit_checkin', |
|
192 | + array('Registration', '', 'ee_edit_others_checkins', '') |
|
193 | + ), |
|
194 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
195 | + 'ee_edit_message', |
|
196 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages') |
|
197 | + ), |
|
198 | + new EE_Meta_Capability_Map_Edit( |
|
199 | + 'ee_edit_default_ticket', |
|
200 | + array('Ticket', '', 'ee_edit_others_default_tickets', '') |
|
201 | + ), |
|
202 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
203 | + 'ee_edit_question', |
|
204 | + array('Question', '', '', 'ee_edit_system_questions') |
|
205 | + ), |
|
206 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
207 | + 'ee_edit_question_group', |
|
208 | + array('Question_Group', '', '', 'ee_edit_system_question_groups') |
|
209 | + ), |
|
210 | + new EE_Meta_Capability_Map_Edit( |
|
211 | + 'ee_edit_payment_method', |
|
212 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '') |
|
213 | + ), |
|
214 | + // reads |
|
215 | + new EE_Meta_Capability_Map_Read( |
|
216 | + 'ee_read_event', |
|
217 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events') |
|
218 | + ), |
|
219 | + new EE_Meta_Capability_Map_Read( |
|
220 | + 'ee_read_venue', |
|
221 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues') |
|
222 | + ), |
|
223 | + new EE_Meta_Capability_Map_Read( |
|
224 | + 'ee_read_registration', |
|
225 | + array('Registration', '', 'ee_read_others_registrations', '') |
|
226 | + ), |
|
227 | + new EE_Meta_Capability_Map_Read( |
|
228 | + 'ee_read_checkin', |
|
229 | + array('Registration', '', 'ee_read_others_checkins', '') |
|
230 | + ), |
|
231 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
232 | + 'ee_read_message', |
|
233 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages') |
|
234 | + ), |
|
235 | + new EE_Meta_Capability_Map_Read( |
|
236 | + 'ee_read_default_ticket', |
|
237 | + array('Ticket', '', 'ee_read_others_default_tickets', '') |
|
238 | + ), |
|
239 | + new EE_Meta_Capability_Map_Read( |
|
240 | + 'ee_read_payment_method', |
|
241 | + array('Payment_Method', '', 'ee_read_others_payment_methods', '') |
|
242 | + ), |
|
243 | + // deletes |
|
244 | + new EE_Meta_Capability_Map_Delete( |
|
245 | + 'ee_delete_event', |
|
246 | + array( |
|
247 | + 'Event', |
|
248 | + 'ee_delete_published_events', |
|
249 | + 'ee_delete_others_events', |
|
250 | + 'ee_delete_private_events', |
|
251 | + ) |
|
252 | + ), |
|
253 | + new EE_Meta_Capability_Map_Delete( |
|
254 | + 'ee_delete_venue', |
|
255 | + array( |
|
256 | + 'Venue', |
|
257 | + 'ee_delete_published_venues', |
|
258 | + 'ee_delete_others_venues', |
|
259 | + 'ee_delete_private_venues', |
|
260 | + ) |
|
261 | + ), |
|
262 | + new EE_Meta_Capability_Map_Delete( |
|
263 | + 'ee_delete_registration', |
|
264 | + array('Registration', '', 'ee_delete_others_registrations', '') |
|
265 | + ), |
|
266 | + new EE_Meta_Capability_Map_Delete( |
|
267 | + 'ee_delete_checkin', |
|
268 | + array('Registration', '', 'ee_delete_others_checkins', '') |
|
269 | + ), |
|
270 | + new EE_Meta_Capability_Map_Messages_Cap( |
|
271 | + 'ee_delete_message', |
|
272 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages') |
|
273 | + ), |
|
274 | + new EE_Meta_Capability_Map_Delete( |
|
275 | + 'ee_delete_default_ticket', |
|
276 | + array('Ticket', '', 'ee_delete_others_default_tickets', '') |
|
277 | + ), |
|
278 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
279 | + 'ee_delete_question', |
|
280 | + array('Question', '', '', 'delete_system_questions') |
|
281 | + ), |
|
282 | + new EE_Meta_Capability_Map_Registration_Form_Cap( |
|
283 | + 'ee_delete_question_group', |
|
284 | + array('Question_Group', '', '', 'delete_system_question_groups') |
|
285 | + ), |
|
286 | + new EE_Meta_Capability_Map_Delete( |
|
287 | + 'ee_delete_payment_method', |
|
288 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '') |
|
289 | + ), |
|
290 | + ); |
|
291 | + } |
|
292 | + return $default_meta_caps; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
298 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
299 | + * |
|
300 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
301 | + * |
|
302 | + * @since 4.5.0 |
|
303 | + * @see wp-includes/capabilities.php |
|
304 | + * |
|
305 | + * @param array $caps actual users capabilities |
|
306 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
307 | + * @param int $user_id The user id |
|
308 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
309 | + * @return array actual users capabilities |
|
310 | + * @throws EE_Error |
|
311 | + */ |
|
312 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
313 | + { |
|
314 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
315 | + // loop through our _meta_caps array |
|
316 | + foreach ($this->_meta_caps as $meta_map) { |
|
317 | + if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
318 | + continue; |
|
319 | + } |
|
320 | + // don't load models if there is no object ID in the args |
|
321 | + if (! empty($args[0])) { |
|
322 | + $meta_map->ensure_is_model(); |
|
323 | + } |
|
324 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
325 | + } |
|
326 | + } |
|
327 | + return $caps; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
333 | + * Note this array is filtered. |
|
334 | + * It is assumed that all available EE capabilities are assigned to the administrator role. |
|
335 | + * |
|
336 | + * @since 4.5.0 |
|
337 | + * |
|
338 | + * @return array |
|
339 | + */ |
|
340 | + private function _init_caps_map() |
|
341 | + { |
|
342 | + return apply_filters( |
|
343 | + 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
344 | + array( |
|
345 | + 'administrator' => array( |
|
346 | + // basic access |
|
347 | + 'ee_read_ee', |
|
348 | + // gateways |
|
349 | + /** |
|
350 | + * note that with payment method capabilities, although we've implemented |
|
351 | + * capability mapping which will be used for accessing payment methods owned by |
|
352 | + * other users. This is not fully implemented yet in the payment method ui. |
|
353 | + * Currently only the "plural" caps are in active use. |
|
354 | + * (Specific payment method caps are in use as well). |
|
355 | + **/ |
|
356 | + 'ee_manage_gateways', |
|
357 | + 'ee_read_payment_methods', |
|
358 | + 'ee_read_others_payment_methods', |
|
359 | + 'ee_edit_payment_methods', |
|
360 | + 'ee_edit_others_payment_methods', |
|
361 | + 'ee_delete_payment_methods', |
|
362 | + // events |
|
363 | + 'ee_publish_events', |
|
364 | + 'ee_read_private_events', |
|
365 | + 'ee_read_others_events', |
|
366 | + 'ee_read_events', |
|
367 | + 'ee_edit_events', |
|
368 | + 'ee_edit_published_events', |
|
369 | + 'ee_edit_others_events', |
|
370 | + 'ee_edit_private_events', |
|
371 | + 'ee_delete_published_events', |
|
372 | + 'ee_delete_private_events', |
|
373 | + 'ee_delete_events', |
|
374 | + 'ee_delete_others_events', |
|
375 | + // event categories |
|
376 | + 'ee_manage_event_categories', |
|
377 | + 'ee_edit_event_category', |
|
378 | + 'ee_delete_event_category', |
|
379 | + 'ee_assign_event_category', |
|
380 | + // venues |
|
381 | + 'ee_publish_venues', |
|
382 | + 'ee_read_venues', |
|
383 | + 'ee_read_others_venues', |
|
384 | + 'ee_read_private_venues', |
|
385 | + 'ee_edit_venues', |
|
386 | + 'ee_edit_others_venues', |
|
387 | + 'ee_edit_published_venues', |
|
388 | + 'ee_edit_private_venues', |
|
389 | + 'ee_delete_venues', |
|
390 | + 'ee_delete_others_venues', |
|
391 | + 'ee_delete_private_venues', |
|
392 | + 'ee_delete_published_venues', |
|
393 | + // venue categories |
|
394 | + 'ee_manage_venue_categories', |
|
395 | + 'ee_edit_venue_category', |
|
396 | + 'ee_delete_venue_category', |
|
397 | + 'ee_assign_venue_category', |
|
398 | + // contacts |
|
399 | + 'ee_read_contacts', |
|
400 | + 'ee_edit_contacts', |
|
401 | + 'ee_delete_contacts', |
|
402 | + // registrations |
|
403 | + 'ee_read_registrations', |
|
404 | + 'ee_read_others_registrations', |
|
405 | + 'ee_edit_registrations', |
|
406 | + 'ee_edit_others_registrations', |
|
407 | + 'ee_delete_registrations', |
|
408 | + // checkins |
|
409 | + 'ee_read_others_checkins', |
|
410 | + 'ee_read_checkins', |
|
411 | + 'ee_edit_checkins', |
|
412 | + 'ee_edit_others_checkins', |
|
413 | + 'ee_delete_checkins', |
|
414 | + 'ee_delete_others_checkins', |
|
415 | + // transactions && payments |
|
416 | + 'ee_read_transaction', |
|
417 | + 'ee_read_transactions', |
|
418 | + 'ee_edit_payments', |
|
419 | + 'ee_delete_payments', |
|
420 | + // messages |
|
421 | + 'ee_read_messages', |
|
422 | + 'ee_read_others_messages', |
|
423 | + 'ee_read_global_messages', |
|
424 | + 'ee_edit_global_messages', |
|
425 | + 'ee_edit_messages', |
|
426 | + 'ee_edit_others_messages', |
|
427 | + 'ee_delete_messages', |
|
428 | + 'ee_delete_others_messages', |
|
429 | + 'ee_delete_global_messages', |
|
430 | + 'ee_send_message', |
|
431 | + // tickets |
|
432 | + 'ee_read_default_tickets', |
|
433 | + 'ee_read_others_default_tickets', |
|
434 | + 'ee_edit_default_tickets', |
|
435 | + 'ee_edit_others_default_tickets', |
|
436 | + 'ee_delete_default_tickets', |
|
437 | + 'ee_delete_others_default_tickets', |
|
438 | + // prices |
|
439 | + 'ee_edit_default_price', |
|
440 | + 'ee_edit_default_prices', |
|
441 | + 'ee_delete_default_price', |
|
442 | + 'ee_delete_default_prices', |
|
443 | + 'ee_edit_default_price_type', |
|
444 | + 'ee_edit_default_price_types', |
|
445 | + 'ee_delete_default_price_type', |
|
446 | + 'ee_delete_default_price_types', |
|
447 | + 'ee_read_default_prices', |
|
448 | + 'ee_read_default_price_types', |
|
449 | + // registration form |
|
450 | + 'ee_edit_questions', |
|
451 | + 'ee_edit_system_questions', |
|
452 | + 'ee_read_questions', |
|
453 | + 'ee_delete_questions', |
|
454 | + 'ee_edit_question_groups', |
|
455 | + 'ee_read_question_groups', |
|
456 | + 'ee_edit_system_question_groups', |
|
457 | + 'ee_delete_question_groups', |
|
458 | + // event_type taxonomy |
|
459 | + 'ee_assign_event_type', |
|
460 | + 'ee_manage_event_types', |
|
461 | + 'ee_edit_event_type', |
|
462 | + 'ee_delete_event_type', |
|
463 | + ), |
|
464 | + 'ee_events_administrator' => array( |
|
465 | + // core wp caps |
|
466 | + 'read', |
|
467 | + 'read_private_pages', |
|
468 | + 'read_private_posts', |
|
469 | + 'edit_users', |
|
470 | + 'edit_posts', |
|
471 | + 'edit_pages', |
|
472 | + 'edit_published_posts', |
|
473 | + 'edit_published_pages', |
|
474 | + 'edit_private_pages', |
|
475 | + 'edit_private_posts', |
|
476 | + 'edit_others_posts', |
|
477 | + 'edit_others_pages', |
|
478 | + 'publish_posts', |
|
479 | + 'publish_pages', |
|
480 | + 'delete_posts', |
|
481 | + 'delete_pages', |
|
482 | + 'delete_private_pages', |
|
483 | + 'delete_private_posts', |
|
484 | + 'delete_published_pages', |
|
485 | + 'delete_published_posts', |
|
486 | + 'delete_others_posts', |
|
487 | + 'delete_others_pages', |
|
488 | + 'manage_categories', |
|
489 | + 'manage_links', |
|
490 | + 'moderate_comments', |
|
491 | + 'unfiltered_html', |
|
492 | + 'upload_files', |
|
493 | + 'export', |
|
494 | + 'import', |
|
495 | + 'list_users', |
|
496 | + 'level_1', // required if user with this role shows up in author dropdowns |
|
497 | + // basic ee access |
|
498 | + 'ee_read_ee', |
|
499 | + // events |
|
500 | + 'ee_publish_events', |
|
501 | + 'ee_read_private_events', |
|
502 | + 'ee_read_others_events', |
|
503 | + 'ee_read_event', |
|
504 | + 'ee_read_events', |
|
505 | + 'ee_edit_event', |
|
506 | + 'ee_edit_events', |
|
507 | + 'ee_edit_published_events', |
|
508 | + 'ee_edit_others_events', |
|
509 | + 'ee_edit_private_events', |
|
510 | + 'ee_delete_published_events', |
|
511 | + 'ee_delete_private_events', |
|
512 | + 'ee_delete_event', |
|
513 | + 'ee_delete_events', |
|
514 | + 'ee_delete_others_events', |
|
515 | + // event categories |
|
516 | + 'ee_manage_event_categories', |
|
517 | + 'ee_edit_event_category', |
|
518 | + 'ee_delete_event_category', |
|
519 | + 'ee_assign_event_category', |
|
520 | + // venues |
|
521 | + 'ee_publish_venues', |
|
522 | + 'ee_read_venue', |
|
523 | + 'ee_read_venues', |
|
524 | + 'ee_read_others_venues', |
|
525 | + 'ee_read_private_venues', |
|
526 | + 'ee_edit_venue', |
|
527 | + 'ee_edit_venues', |
|
528 | + 'ee_edit_others_venues', |
|
529 | + 'ee_edit_published_venues', |
|
530 | + 'ee_edit_private_venues', |
|
531 | + 'ee_delete_venue', |
|
532 | + 'ee_delete_venues', |
|
533 | + 'ee_delete_others_venues', |
|
534 | + 'ee_delete_private_venues', |
|
535 | + 'ee_delete_published_venues', |
|
536 | + // venue categories |
|
537 | + 'ee_manage_venue_categories', |
|
538 | + 'ee_edit_venue_category', |
|
539 | + 'ee_delete_venue_category', |
|
540 | + 'ee_assign_venue_category', |
|
541 | + // contacts |
|
542 | + 'ee_read_contacts', |
|
543 | + 'ee_edit_contacts', |
|
544 | + 'ee_delete_contacts', |
|
545 | + // registrations |
|
546 | + 'ee_read_registrations', |
|
547 | + 'ee_read_others_registrations', |
|
548 | + 'ee_edit_registration', |
|
549 | + 'ee_edit_registrations', |
|
550 | + 'ee_edit_others_registrations', |
|
551 | + 'ee_delete_registration', |
|
552 | + 'ee_delete_registrations', |
|
553 | + // checkins |
|
554 | + 'ee_read_others_checkins', |
|
555 | + 'ee_read_checkins', |
|
556 | + 'ee_edit_checkins', |
|
557 | + 'ee_edit_others_checkins', |
|
558 | + 'ee_delete_checkins', |
|
559 | + 'ee_delete_others_checkins', |
|
560 | + // transactions && payments |
|
561 | + 'ee_read_transaction', |
|
562 | + 'ee_read_transactions', |
|
563 | + 'ee_edit_payments', |
|
564 | + 'ee_delete_payments', |
|
565 | + // messages |
|
566 | + 'ee_read_messages', |
|
567 | + 'ee_read_others_messages', |
|
568 | + 'ee_read_global_messages', |
|
569 | + 'ee_edit_global_messages', |
|
570 | + 'ee_edit_messages', |
|
571 | + 'ee_edit_others_messages', |
|
572 | + 'ee_delete_messages', |
|
573 | + 'ee_delete_others_messages', |
|
574 | + 'ee_delete_global_messages', |
|
575 | + 'ee_send_message', |
|
576 | + // tickets |
|
577 | + 'ee_read_default_tickets', |
|
578 | + 'ee_read_others_default_tickets', |
|
579 | + 'ee_edit_default_tickets', |
|
580 | + 'ee_edit_others_default_tickets', |
|
581 | + 'ee_delete_default_tickets', |
|
582 | + 'ee_delete_others_default_tickets', |
|
583 | + // prices |
|
584 | + 'ee_edit_default_price', |
|
585 | + 'ee_edit_default_prices', |
|
586 | + 'ee_delete_default_price', |
|
587 | + 'ee_delete_default_prices', |
|
588 | + 'ee_edit_default_price_type', |
|
589 | + 'ee_edit_default_price_types', |
|
590 | + 'ee_delete_default_price_type', |
|
591 | + 'ee_delete_default_price_types', |
|
592 | + 'ee_read_default_prices', |
|
593 | + 'ee_read_default_price_types', |
|
594 | + // registration form |
|
595 | + 'ee_edit_questions', |
|
596 | + 'ee_edit_system_questions', |
|
597 | + 'ee_read_questions', |
|
598 | + 'ee_delete_questions', |
|
599 | + 'ee_edit_question_groups', |
|
600 | + 'ee_read_question_groups', |
|
601 | + 'ee_edit_system_question_groups', |
|
602 | + 'ee_delete_question_groups', |
|
603 | + // event_type taxonomy |
|
604 | + 'ee_assign_event_type', |
|
605 | + 'ee_manage_event_types', |
|
606 | + 'ee_edit_event_type', |
|
607 | + 'ee_delete_event_type', |
|
608 | + ), |
|
609 | + ) |
|
610 | + ); |
|
611 | + } |
|
612 | + |
|
613 | + |
|
614 | + /** |
|
615 | + * @return bool |
|
616 | + * @throws EE_Error |
|
617 | + */ |
|
618 | + private function setupCapabilitiesMap() |
|
619 | + { |
|
620 | + // if the initialization process hasn't even started, then we need to call init_caps() |
|
621 | + if ($this->initialized === null) { |
|
622 | + return $this->init_caps(); |
|
623 | + } |
|
624 | + // unless resetting, get caps from db if we haven't already |
|
625 | + $this->capabilities_map = $this->reset || ! empty($this->capabilities_map) |
|
626 | + ? $this->capabilities_map |
|
627 | + : get_option(self::option_name, array()); |
|
628 | + return true; |
|
629 | + } |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * @param bool $update |
|
634 | + * @return bool |
|
635 | + */ |
|
636 | + private function updateCapabilitiesMap($update = true) |
|
637 | + { |
|
638 | + return $update ? update_option(self::option_name, $this->capabilities_map) : false; |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + /** |
|
643 | + * Adds capabilities to roles. |
|
644 | + * |
|
645 | + * @since 4.9.42 |
|
646 | + * @param array $capabilities_to_add array of capabilities to add, indexed by roles. |
|
647 | + * Note that this should ONLY be called on activation hook |
|
648 | + * otherwise the caps will be added on every request. |
|
649 | + * @return bool |
|
650 | + * @throws \EE_Error |
|
651 | + */ |
|
652 | + public function addCaps(array $capabilities_to_add) |
|
653 | + { |
|
654 | + // don't do anything if the capabilities map can not be initialized |
|
655 | + if (! $this->setupCapabilitiesMap()) { |
|
656 | + return false; |
|
657 | + } |
|
658 | + // and filter the array so others can get in on the fun during resets |
|
659 | + $capabilities_to_add = apply_filters( |
|
660 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
661 | + $capabilities_to_add, |
|
662 | + $this->reset, |
|
663 | + $this->capabilities_map |
|
664 | + ); |
|
665 | + $update_capabilities_map = false; |
|
666 | + // if not reset, see what caps are new for each role. if they're new, add them. |
|
667 | + foreach ($capabilities_to_add as $role => $caps_for_role) { |
|
668 | + if (is_array($caps_for_role)) { |
|
669 | + foreach ($caps_for_role as $cap) { |
|
670 | + if (! $this->capHasBeenAddedToRole($role, $cap) |
|
671 | + && $this->add_cap_to_role($role, $cap, true, false) |
|
672 | + ) { |
|
673 | + $update_capabilities_map = true; |
|
674 | + } |
|
675 | + } |
|
676 | + } |
|
677 | + } |
|
678 | + // now let's just save the cap that has been set but only if there's been a change. |
|
679 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
680 | + $this->flushWpUser($updated); |
|
681 | + do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated); |
|
682 | + return $updated; |
|
683 | + } |
|
684 | + |
|
685 | + |
|
686 | + /** |
|
687 | + * Loops through the capabilities map and removes the role caps specified by the incoming array |
|
688 | + * |
|
689 | + * @param array $caps_map map of capabilities to be removed (indexed by roles) |
|
690 | + * @return bool |
|
691 | + * @throws \EE_Error |
|
692 | + */ |
|
693 | + public function removeCaps($caps_map) |
|
694 | + { |
|
695 | + // don't do anything if the capabilities map can not be initialized |
|
696 | + if (! $this->setupCapabilitiesMap()) { |
|
697 | + return false; |
|
698 | + } |
|
699 | + $update_capabilities_map = false; |
|
700 | + foreach ($caps_map as $role => $caps_for_role) { |
|
701 | + if (is_array($caps_for_role)) { |
|
702 | + foreach ($caps_for_role as $cap) { |
|
703 | + if ($this->capHasBeenAddedToRole($role, $cap) |
|
704 | + && $this->remove_cap_from_role($role, $cap, false) |
|
705 | + ) { |
|
706 | + $update_capabilities_map = true; |
|
707 | + } |
|
708 | + } |
|
709 | + } |
|
710 | + } |
|
711 | + // maybe resave the caps |
|
712 | + $updated = $this->updateCapabilitiesMap($update_capabilities_map); |
|
713 | + $this->flushWpUser($updated); |
|
714 | + return $updated; |
|
715 | + } |
|
716 | + |
|
717 | + |
|
718 | + /** |
|
719 | + * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from |
|
720 | + * the roles on that user. |
|
721 | + * |
|
722 | + * @param bool $flush Default is to flush the WP_User object. If false, then this method effectively does nothing. |
|
723 | + */ |
|
724 | + private function flushWpUser($flush = true) |
|
725 | + { |
|
726 | + if ($flush) { |
|
727 | + $user = wp_get_current_user(); |
|
728 | + if ($user instanceof WP_User) { |
|
729 | + $user->get_role_caps(); |
|
730 | + } |
|
731 | + } |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
737 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
738 | + * this is a wrapper for $wp_role->add_cap() |
|
739 | + * |
|
740 | + * @see wp-includes/capabilities.php |
|
741 | + * @since 4.5.0 |
|
742 | + * @param string|WP_Role $role A WordPress role the capability is being added to |
|
743 | + * @param string $cap The capability being added to the role |
|
744 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
745 | + * @param bool $update_capabilities_map |
|
746 | + * @return bool |
|
747 | + * @throws \EE_Error |
|
748 | + */ |
|
749 | + public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true) |
|
750 | + { |
|
751 | + // capture incoming value for $role because we may need it to create a new WP_Role |
|
752 | + $orig_role = $role; |
|
753 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
754 | + // if the role isn't available then we create it. |
|
755 | + if (! $role instanceof WP_Role) { |
|
756 | + // if a plugin wants to create a specific role name then they should create the role before |
|
757 | + // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
758 | + // - removes any `ee_` namespacing from the start of the slug. |
|
759 | + // - replaces `_` with ` ` (empty space). |
|
760 | + // - sentence case on the resulting string. |
|
761 | + $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role)); |
|
762 | + $role = add_role($orig_role, $role_label); |
|
763 | + } |
|
764 | + if ($role instanceof WP_Role) { |
|
765 | + // don't do anything if the capabilities map can not be initialized |
|
766 | + if (! $this->setupCapabilitiesMap()) { |
|
767 | + return false; |
|
768 | + } |
|
769 | + if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
770 | + $role->add_cap($cap, $grant); |
|
771 | + $this->capabilities_map[ $role->name ][] = $cap; |
|
772 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
773 | + return true; |
|
774 | + } |
|
775 | + } |
|
776 | + return false; |
|
777 | + } |
|
778 | + |
|
779 | + |
|
780 | + /** |
|
781 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
782 | + * Wrapper for $wp_role->remove_cap() |
|
783 | + * |
|
784 | + * @see wp-includes/capabilities.php |
|
785 | + * @since 4.5.0 |
|
786 | + * @param string|WP_Role $role A WordPress role the capability is being removed from. |
|
787 | + * @param string $cap The capability being removed |
|
788 | + * @param bool $update_capabilities_map |
|
789 | + * @return bool |
|
790 | + * @throws \EE_Error |
|
791 | + */ |
|
792 | + public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
|
793 | + { |
|
794 | + // don't do anything if the capabilities map can not be initialized |
|
795 | + if (! $this->setupCapabilitiesMap()) { |
|
796 | + return false; |
|
797 | + } |
|
798 | + |
|
799 | + $role = $role instanceof WP_Role ? $role : get_role($role); |
|
800 | + if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
|
801 | + $role->remove_cap($cap); |
|
802 | + unset($this->capabilities_map[ $role->name ][ $index ]); |
|
803 | + $this->updateCapabilitiesMap($update_capabilities_map); |
|
804 | + return true; |
|
805 | + } |
|
806 | + return false; |
|
807 | + } |
|
808 | + |
|
809 | + |
|
810 | + /** |
|
811 | + * @param string $role_name |
|
812 | + * @param string $cap |
|
813 | + * @param bool $get_index |
|
814 | + * @return bool|mixed |
|
815 | + */ |
|
816 | + private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false) |
|
817 | + { |
|
818 | + if (isset($this->capabilities_map[ $role_name ]) |
|
819 | + && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false |
|
820 | + ) { |
|
821 | + return $get_index ? $index : true; |
|
822 | + } |
|
823 | + return false; |
|
824 | + } |
|
825 | + |
|
826 | + |
|
827 | + /** |
|
828 | + * Wrapper for the native WP current_user_can() method. |
|
829 | + * This is provided as a handy method for a couple things: |
|
830 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
831 | + * write those filters wherever current_user_can is called). |
|
832 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
833 | + * |
|
834 | + * @since 4.5.0 |
|
835 | + * |
|
836 | + * @param string $cap The cap being checked. |
|
837 | + * @param string $context The context where the current_user_can is being called from. |
|
838 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
839 | + * filters. |
|
840 | + * |
|
841 | + * @return bool Whether user can or not. |
|
842 | + */ |
|
843 | + public function current_user_can($cap, $context, $id = 0) |
|
844 | + { |
|
845 | + // apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
846 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
847 | + $filtered_cap = apply_filters( |
|
848 | + 'FHEE__EE_Capabilities__current_user_can__cap', |
|
849 | + $filtered_cap, |
|
850 | + $context, |
|
851 | + $cap, |
|
852 | + $id |
|
853 | + ); |
|
854 | + return ! empty($id) |
|
855 | + ? current_user_can($filtered_cap, $id) |
|
856 | + : current_user_can($filtered_cap); |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + /** |
|
861 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
862 | + * |
|
863 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
864 | + * @param string $cap The capability string being checked |
|
865 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
866 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
867 | + * filters) |
|
868 | + * |
|
869 | + * @return bool Whether user can or not. |
|
870 | + */ |
|
871 | + public function user_can($user, $cap, $context, $id = 0) |
|
872 | + { |
|
873 | + // apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
874 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
875 | + $filtered_cap = apply_filters( |
|
876 | + 'FHEE__EE_Capabilities__user_can__cap', |
|
877 | + $filtered_cap, |
|
878 | + $context, |
|
879 | + $cap, |
|
880 | + $user, |
|
881 | + $id |
|
882 | + ); |
|
883 | + return ! empty($id) |
|
884 | + ? user_can($user, $filtered_cap, $id) |
|
885 | + : user_can($user, $filtered_cap); |
|
886 | + } |
|
887 | + |
|
888 | + |
|
889 | + /** |
|
890 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
891 | + * This is provided as a handy method for a couple things: |
|
892 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
893 | + * write those filters wherever current_user_can is called). |
|
894 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
895 | + * |
|
896 | + * @since 4.5.0 |
|
897 | + * |
|
898 | + * @param int $blog_id The blog id that is being checked for. |
|
899 | + * @param string $cap The cap being checked. |
|
900 | + * @param string $context The context where the current_user_can is being called from. |
|
901 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
902 | + * filters. |
|
903 | + * |
|
904 | + * @return bool Whether user can or not. |
|
905 | + */ |
|
906 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
907 | + { |
|
908 | + $user_can = ! empty($id) |
|
909 | + ? current_user_can_for_blog($blog_id, $cap, $id) |
|
910 | + : current_user_can($blog_id, $cap); |
|
911 | + // apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
912 | + $user_can = apply_filters( |
|
913 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
914 | + $user_can, |
|
915 | + $blog_id, |
|
916 | + $cap, |
|
917 | + $id |
|
918 | + ); |
|
919 | + $user_can = apply_filters( |
|
920 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can', |
|
921 | + $user_can, |
|
922 | + $context, |
|
923 | + $blog_id, |
|
924 | + $cap, |
|
925 | + $id |
|
926 | + ); |
|
927 | + return $user_can; |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * This helper method just returns an array of registered EE capabilities. |
|
933 | + * |
|
934 | + * @since 4.5.0 |
|
935 | + * @param string $role If empty then the entire role/capability map is returned. |
|
936 | + * Otherwise just the capabilities for the given role are returned. |
|
937 | + * @return array |
|
938 | + * @throws EE_Error |
|
939 | + */ |
|
940 | + public function get_ee_capabilities($role = 'administrator') |
|
941 | + { |
|
942 | + if (! $this->initialized) { |
|
943 | + $this->init_caps(); |
|
944 | + } |
|
945 | + if (empty($role)) { |
|
946 | + return $this->capabilities_map; |
|
947 | + } |
|
948 | + return isset($this->capabilities_map[ $role ]) |
|
949 | + ? $this->capabilities_map[ $role ] |
|
950 | + : array(); |
|
951 | + } |
|
952 | + |
|
953 | + |
|
954 | + /** |
|
955 | + * @deprecated 4.9.42 |
|
956 | + * @param bool $reset If you need to reset Event Espresso's capabilities, |
|
957 | + * then please use the init_caps() method with the "$reset" parameter set to "true" |
|
958 | + * @param array $caps_map Optional. |
|
959 | + * Can be used to send a custom map of roles and capabilities for setting them up. |
|
960 | + * Note that this should ONLY be called on activation hook or some other one-time |
|
961 | + * task otherwise the caps will be added on every request. |
|
962 | + * @return void |
|
963 | + * @throws EE_Error |
|
964 | + */ |
|
965 | + public function init_role_caps($reset = false, $caps_map = array()) |
|
966 | + { |
|
967 | + // If this method is called directly and reset is set as 'true', |
|
968 | + // then display a doing it wrong notice, because we want resets to go through init_caps() |
|
969 | + // to guarantee that everything is set up correctly. |
|
970 | + // This prevents the capabilities map getting reset incorrectly by direct calls to this method. |
|
971 | + if ($reset) { |
|
972 | + EE_Error::doing_it_wrong( |
|
973 | + __METHOD__, |
|
974 | + sprintf( |
|
975 | + esc_html__( |
|
976 | + 'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".', |
|
977 | + 'event_espresso' |
|
978 | + ), |
|
979 | + '$reset', |
|
980 | + __METHOD__ . '()', |
|
981 | + 'EE_Capabilities::init_caps()', |
|
982 | + 'true' |
|
983 | + ), |
|
984 | + '4.9.42', |
|
985 | + '5.0.0' |
|
986 | + ); |
|
987 | + } |
|
988 | + $this->addCaps($caps_map); |
|
989 | + } |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | |
@@ -1003,142 +1003,142 @@ discard block |
||
1003 | 1003 | abstract class EE_Meta_Capability_Map |
1004 | 1004 | { |
1005 | 1005 | |
1006 | - public $meta_cap; |
|
1007 | - |
|
1008 | - /** |
|
1009 | - * @var EEM_Base |
|
1010 | - */ |
|
1011 | - protected $_model; |
|
1012 | - |
|
1013 | - protected $_model_name; |
|
1014 | - |
|
1015 | - public $published_cap = ''; |
|
1016 | - |
|
1017 | - public $others_cap = ''; |
|
1018 | - |
|
1019 | - public $private_cap = ''; |
|
1020 | - |
|
1021 | - |
|
1022 | - /** |
|
1023 | - * constructor. |
|
1024 | - * Receives the setup arguments for the map. |
|
1025 | - * |
|
1026 | - * @since 4.5.0 |
|
1027 | - * |
|
1028 | - * @param string $meta_cap What meta capability is this mapping. |
|
1029 | - * @param array $map_values array { |
|
1030 | - * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
1031 | - * capabilities that don't get mapped to. |
|
1032 | - * |
|
1033 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
1034 | - * should always be used when Menu Maps are registered via the |
|
1035 | - * plugin API as models are not allowed to be instantiated when |
|
1036 | - * in maintenance mode 2 (migrations). |
|
1037 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
1038 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
1039 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
1040 | - * } |
|
1041 | - * @throws EE_Error |
|
1042 | - */ |
|
1043 | - public function __construct($meta_cap, $map_values) |
|
1044 | - { |
|
1045 | - $this->meta_cap = $meta_cap; |
|
1046 | - // verify there are four args in the $map_values array; |
|
1047 | - if (count($map_values) !== 4) { |
|
1048 | - throw new EE_Error( |
|
1049 | - sprintf( |
|
1050 | - __( |
|
1051 | - 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
1052 | - 'event_espresso' |
|
1053 | - ), |
|
1054 | - '<br>' . print_r($map_values, true) |
|
1055 | - ) |
|
1056 | - ); |
|
1057 | - } |
|
1058 | - // set properties |
|
1059 | - $this->_model = null; |
|
1060 | - $this->_model_name = $map_values[0]; |
|
1061 | - $this->published_cap = (string) $map_values[1]; |
|
1062 | - $this->others_cap = (string) $map_values[2]; |
|
1063 | - $this->private_cap = (string) $map_values[3]; |
|
1064 | - } |
|
1065 | - |
|
1066 | - /** |
|
1067 | - * Makes it so this object stops filtering caps |
|
1068 | - */ |
|
1069 | - public function remove_filters() |
|
1070 | - { |
|
1071 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
1072 | - } |
|
1073 | - |
|
1074 | - |
|
1075 | - /** |
|
1076 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
1077 | - * |
|
1078 | - * @since 4.5.0 |
|
1079 | - * @throws EE_Error |
|
1080 | - * |
|
1081 | - * @return void |
|
1082 | - */ |
|
1083 | - public function ensure_is_model() |
|
1084 | - { |
|
1085 | - // is it already instantiated? |
|
1086 | - if ($this->_model instanceof EEM_Base) { |
|
1087 | - return; |
|
1088 | - } |
|
1089 | - // ensure model name is string |
|
1090 | - $this->_model_name = (string) $this->_model_name; |
|
1091 | - // error proof if the name has EEM in it |
|
1092 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
1093 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
1094 | - if (! $this->_model instanceof EEM_Base) { |
|
1095 | - throw new EE_Error( |
|
1096 | - sprintf( |
|
1097 | - __( |
|
1098 | - 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
1099 | - 'event_espresso' |
|
1100 | - ), |
|
1101 | - get_class($this), |
|
1102 | - $this->_model |
|
1103 | - ) |
|
1104 | - ); |
|
1105 | - } |
|
1106 | - } |
|
1107 | - |
|
1108 | - |
|
1109 | - /** |
|
1110 | - * |
|
1111 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
1112 | - * @since 4.6.x |
|
1113 | - * |
|
1114 | - * @param $caps |
|
1115 | - * @param $cap |
|
1116 | - * @param $user_id |
|
1117 | - * @param $args |
|
1118 | - * |
|
1119 | - * @return array |
|
1120 | - */ |
|
1121 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
1122 | - { |
|
1123 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
1124 | - } |
|
1125 | - |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1129 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1130 | - * |
|
1131 | - * @since 4.5.0 |
|
1132 | - * @see wp-includes/capabilities.php |
|
1133 | - * |
|
1134 | - * @param array $caps actual users capabilities |
|
1135 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1136 | - * @param int $user_id The user id |
|
1137 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1138 | - * |
|
1139 | - * @return array actual users capabilities |
|
1140 | - */ |
|
1141 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
1006 | + public $meta_cap; |
|
1007 | + |
|
1008 | + /** |
|
1009 | + * @var EEM_Base |
|
1010 | + */ |
|
1011 | + protected $_model; |
|
1012 | + |
|
1013 | + protected $_model_name; |
|
1014 | + |
|
1015 | + public $published_cap = ''; |
|
1016 | + |
|
1017 | + public $others_cap = ''; |
|
1018 | + |
|
1019 | + public $private_cap = ''; |
|
1020 | + |
|
1021 | + |
|
1022 | + /** |
|
1023 | + * constructor. |
|
1024 | + * Receives the setup arguments for the map. |
|
1025 | + * |
|
1026 | + * @since 4.5.0 |
|
1027 | + * |
|
1028 | + * @param string $meta_cap What meta capability is this mapping. |
|
1029 | + * @param array $map_values array { |
|
1030 | + * //array of values that MUST match a count of 4. It's okay to send an empty string for |
|
1031 | + * capabilities that don't get mapped to. |
|
1032 | + * |
|
1033 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
1034 | + * should always be used when Menu Maps are registered via the |
|
1035 | + * plugin API as models are not allowed to be instantiated when |
|
1036 | + * in maintenance mode 2 (migrations). |
|
1037 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
1038 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
1039 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
1040 | + * } |
|
1041 | + * @throws EE_Error |
|
1042 | + */ |
|
1043 | + public function __construct($meta_cap, $map_values) |
|
1044 | + { |
|
1045 | + $this->meta_cap = $meta_cap; |
|
1046 | + // verify there are four args in the $map_values array; |
|
1047 | + if (count($map_values) !== 4) { |
|
1048 | + throw new EE_Error( |
|
1049 | + sprintf( |
|
1050 | + __( |
|
1051 | + 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
1052 | + 'event_espresso' |
|
1053 | + ), |
|
1054 | + '<br>' . print_r($map_values, true) |
|
1055 | + ) |
|
1056 | + ); |
|
1057 | + } |
|
1058 | + // set properties |
|
1059 | + $this->_model = null; |
|
1060 | + $this->_model_name = $map_values[0]; |
|
1061 | + $this->published_cap = (string) $map_values[1]; |
|
1062 | + $this->others_cap = (string) $map_values[2]; |
|
1063 | + $this->private_cap = (string) $map_values[3]; |
|
1064 | + } |
|
1065 | + |
|
1066 | + /** |
|
1067 | + * Makes it so this object stops filtering caps |
|
1068 | + */ |
|
1069 | + public function remove_filters() |
|
1070 | + { |
|
1071 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
1072 | + } |
|
1073 | + |
|
1074 | + |
|
1075 | + /** |
|
1076 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
1077 | + * |
|
1078 | + * @since 4.5.0 |
|
1079 | + * @throws EE_Error |
|
1080 | + * |
|
1081 | + * @return void |
|
1082 | + */ |
|
1083 | + public function ensure_is_model() |
|
1084 | + { |
|
1085 | + // is it already instantiated? |
|
1086 | + if ($this->_model instanceof EEM_Base) { |
|
1087 | + return; |
|
1088 | + } |
|
1089 | + // ensure model name is string |
|
1090 | + $this->_model_name = (string) $this->_model_name; |
|
1091 | + // error proof if the name has EEM in it |
|
1092 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
1093 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
1094 | + if (! $this->_model instanceof EEM_Base) { |
|
1095 | + throw new EE_Error( |
|
1096 | + sprintf( |
|
1097 | + __( |
|
1098 | + 'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
1099 | + 'event_espresso' |
|
1100 | + ), |
|
1101 | + get_class($this), |
|
1102 | + $this->_model |
|
1103 | + ) |
|
1104 | + ); |
|
1105 | + } |
|
1106 | + } |
|
1107 | + |
|
1108 | + |
|
1109 | + /** |
|
1110 | + * |
|
1111 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
1112 | + * @since 4.6.x |
|
1113 | + * |
|
1114 | + * @param $caps |
|
1115 | + * @param $cap |
|
1116 | + * @param $user_id |
|
1117 | + * @param $args |
|
1118 | + * |
|
1119 | + * @return array |
|
1120 | + */ |
|
1121 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
1122 | + { |
|
1123 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
1124 | + } |
|
1125 | + |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1129 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1130 | + * |
|
1131 | + * @since 4.5.0 |
|
1132 | + * @see wp-includes/capabilities.php |
|
1133 | + * |
|
1134 | + * @param array $caps actual users capabilities |
|
1135 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1136 | + * @param int $user_id The user id |
|
1137 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1138 | + * |
|
1139 | + * @return array actual users capabilities |
|
1140 | + */ |
|
1141 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | |
@@ -1154,81 +1154,81 @@ discard block |
||
1154 | 1154 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
1155 | 1155 | { |
1156 | 1156 | |
1157 | - /** |
|
1158 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1159 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1160 | - * |
|
1161 | - * @since 4.5.0 |
|
1162 | - * @see wp-includes/capabilities.php |
|
1163 | - * |
|
1164 | - * @param array $caps actual users capabilities |
|
1165 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1166 | - * @param int $user_id The user id |
|
1167 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1168 | - * |
|
1169 | - * @return array actual users capabilities |
|
1170 | - */ |
|
1171 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1172 | - { |
|
1173 | - // only process if we're checking our mapped_cap |
|
1174 | - if ($cap !== $this->meta_cap) { |
|
1175 | - return $caps; |
|
1176 | - } |
|
1177 | - |
|
1178 | - // okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1179 | - if (($key = array_search($cap, $caps)) !== false) { |
|
1180 | - unset($caps[ $key ]); |
|
1181 | - } |
|
1182 | - |
|
1183 | - // cast $user_id to int for later explicit comparisons |
|
1184 | - $user_id = (int) $user_id; |
|
1185 | - |
|
1186 | - /** @var EE_Base_Class $obj */ |
|
1187 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1188 | - // if no obj then let's just do cap |
|
1189 | - if (! $obj instanceof EE_Base_Class) { |
|
1190 | - $caps[] = 'do_not_allow'; |
|
1191 | - return $caps; |
|
1192 | - } |
|
1193 | - $caps[] = $cap . 's'; |
|
1194 | - if ($obj instanceof EE_CPT_Base) { |
|
1195 | - // if the item author is set and the user is the author... |
|
1196 | - if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
1197 | - // if obj is published... |
|
1198 | - if ($obj->status() === 'publish') { |
|
1199 | - $caps[] = $this->published_cap; |
|
1200 | - } |
|
1201 | - } else { |
|
1202 | - // the user is trying to edit someone else's obj |
|
1203 | - if (! empty($this->others_cap)) { |
|
1204 | - $caps[] = $this->others_cap; |
|
1205 | - } |
|
1206 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1207 | - $caps[] = $this->published_cap; |
|
1208 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
1209 | - $caps[] = $this->private_cap; |
|
1210 | - } |
|
1211 | - } |
|
1212 | - } else { |
|
1213 | - // not a cpt object so handled differently |
|
1214 | - $has_cap = false; |
|
1215 | - try { |
|
1216 | - $has_cap = method_exists($obj, 'wp_user') |
|
1217 | - && $obj->wp_user() |
|
1218 | - && $obj->wp_user() === $user_id; |
|
1219 | - } catch (Exception $e) { |
|
1220 | - if (WP_DEBUG) { |
|
1221 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1222 | - } |
|
1223 | - } |
|
1224 | - if (! $has_cap) { |
|
1225 | - if (! empty($this->others_cap)) { |
|
1226 | - $caps[] = $this->others_cap; |
|
1227 | - } |
|
1228 | - } |
|
1229 | - } |
|
1230 | - return $caps; |
|
1231 | - } |
|
1157 | + /** |
|
1158 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1159 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1160 | + * |
|
1161 | + * @since 4.5.0 |
|
1162 | + * @see wp-includes/capabilities.php |
|
1163 | + * |
|
1164 | + * @param array $caps actual users capabilities |
|
1165 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1166 | + * @param int $user_id The user id |
|
1167 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1168 | + * |
|
1169 | + * @return array actual users capabilities |
|
1170 | + */ |
|
1171 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1172 | + { |
|
1173 | + // only process if we're checking our mapped_cap |
|
1174 | + if ($cap !== $this->meta_cap) { |
|
1175 | + return $caps; |
|
1176 | + } |
|
1177 | + |
|
1178 | + // okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1179 | + if (($key = array_search($cap, $caps)) !== false) { |
|
1180 | + unset($caps[ $key ]); |
|
1181 | + } |
|
1182 | + |
|
1183 | + // cast $user_id to int for later explicit comparisons |
|
1184 | + $user_id = (int) $user_id; |
|
1185 | + |
|
1186 | + /** @var EE_Base_Class $obj */ |
|
1187 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1188 | + // if no obj then let's just do cap |
|
1189 | + if (! $obj instanceof EE_Base_Class) { |
|
1190 | + $caps[] = 'do_not_allow'; |
|
1191 | + return $caps; |
|
1192 | + } |
|
1193 | + $caps[] = $cap . 's'; |
|
1194 | + if ($obj instanceof EE_CPT_Base) { |
|
1195 | + // if the item author is set and the user is the author... |
|
1196 | + if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
|
1197 | + // if obj is published... |
|
1198 | + if ($obj->status() === 'publish') { |
|
1199 | + $caps[] = $this->published_cap; |
|
1200 | + } |
|
1201 | + } else { |
|
1202 | + // the user is trying to edit someone else's obj |
|
1203 | + if (! empty($this->others_cap)) { |
|
1204 | + $caps[] = $this->others_cap; |
|
1205 | + } |
|
1206 | + if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1207 | + $caps[] = $this->published_cap; |
|
1208 | + } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
1209 | + $caps[] = $this->private_cap; |
|
1210 | + } |
|
1211 | + } |
|
1212 | + } else { |
|
1213 | + // not a cpt object so handled differently |
|
1214 | + $has_cap = false; |
|
1215 | + try { |
|
1216 | + $has_cap = method_exists($obj, 'wp_user') |
|
1217 | + && $obj->wp_user() |
|
1218 | + && $obj->wp_user() === $user_id; |
|
1219 | + } catch (Exception $e) { |
|
1220 | + if (WP_DEBUG) { |
|
1221 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1222 | + } |
|
1223 | + } |
|
1224 | + if (! $has_cap) { |
|
1225 | + if (! empty($this->others_cap)) { |
|
1226 | + $caps[] = $this->others_cap; |
|
1227 | + } |
|
1228 | + } |
|
1229 | + } |
|
1230 | + return $caps; |
|
1231 | + } |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | |
@@ -1245,24 +1245,24 @@ discard block |
||
1245 | 1245 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
1246 | 1246 | { |
1247 | 1247 | |
1248 | - /** |
|
1249 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1250 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1251 | - * |
|
1252 | - * @since 4.5.0 |
|
1253 | - * @see wp-includes/capabilities.php |
|
1254 | - * |
|
1255 | - * @param array $caps actual users capabilities |
|
1256 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1257 | - * @param int $user_id The user id |
|
1258 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1259 | - * |
|
1260 | - * @return array actual users capabilities |
|
1261 | - */ |
|
1262 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1263 | - { |
|
1264 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
1265 | - } |
|
1248 | + /** |
|
1249 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1250 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1251 | + * |
|
1252 | + * @since 4.5.0 |
|
1253 | + * @see wp-includes/capabilities.php |
|
1254 | + * |
|
1255 | + * @param array $caps actual users capabilities |
|
1256 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1257 | + * @param int $user_id The user id |
|
1258 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1259 | + * |
|
1260 | + * @return array actual users capabilities |
|
1261 | + */ |
|
1262 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1263 | + { |
|
1264 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
1265 | + } |
|
1266 | 1266 | } |
1267 | 1267 | |
1268 | 1268 | |
@@ -1278,85 +1278,85 @@ discard block |
||
1278 | 1278 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
1279 | 1279 | { |
1280 | 1280 | |
1281 | - /** |
|
1282 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1283 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1284 | - * |
|
1285 | - * @since 4.5.0 |
|
1286 | - * @see wp-includes/capabilities.php |
|
1287 | - * |
|
1288 | - * @param array $caps actual users capabilities |
|
1289 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1290 | - * @param int $user_id The user id |
|
1291 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1292 | - * |
|
1293 | - * @return array actual users capabilities |
|
1294 | - */ |
|
1295 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1296 | - { |
|
1297 | - // only process if we're checking our mapped cap; |
|
1298 | - if ($cap !== $this->meta_cap) { |
|
1299 | - return $caps; |
|
1300 | - } |
|
1301 | - |
|
1302 | - // okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1303 | - if (($key = array_search($cap, $caps)) !== false) { |
|
1304 | - unset($caps[ $key ]); |
|
1305 | - } |
|
1306 | - |
|
1307 | - // cast $user_id to int for later explicit comparisons |
|
1308 | - $user_id = (int) $user_id; |
|
1309 | - |
|
1310 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1311 | - // if no obj then let's just do cap |
|
1312 | - if (! $obj instanceof EE_Base_Class) { |
|
1313 | - $caps[] = 'do_not_allow'; |
|
1314 | - return $caps; |
|
1315 | - } |
|
1316 | - |
|
1317 | - $caps[] = $cap . 's'; |
|
1318 | - if ($obj instanceof EE_CPT_Base) { |
|
1319 | - $status_obj = get_post_status_object($obj->status()); |
|
1320 | - if ($status_obj->public) { |
|
1321 | - return $caps; |
|
1322 | - } |
|
1323 | - // if the item author is set and the user is not the author... |
|
1324 | - if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
1325 | - if (! empty($this->others_cap)) { |
|
1326 | - $caps[] = $this->others_cap; |
|
1327 | - } |
|
1328 | - } |
|
1329 | - // yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
1330 | - if ($status_obj->private |
|
1331 | - && ! empty($this->private_cap) |
|
1332 | - && $obj->wp_user() !== $user_id |
|
1333 | - ) { |
|
1334 | - // the user is trying to view a private object for an object they don't own. |
|
1335 | - $caps[] = $this->private_cap; |
|
1336 | - } |
|
1337 | - } else { |
|
1338 | - // not a cpt object so handled differently |
|
1339 | - $has_cap = false; |
|
1340 | - try { |
|
1341 | - $has_cap = method_exists($obj, 'wp_user') |
|
1342 | - && $obj->wp_user() |
|
1343 | - && $obj->wp_user() === $user_id; |
|
1344 | - } catch (Exception $e) { |
|
1345 | - if (WP_DEBUG) { |
|
1346 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1347 | - } |
|
1348 | - } |
|
1349 | - if (! $has_cap) { |
|
1350 | - if (! empty($this->private_cap)) { |
|
1351 | - $caps[] = $this->private_cap; |
|
1352 | - } |
|
1353 | - if (! empty($this->others_cap)) { |
|
1354 | - $caps[] = $this->others_cap; |
|
1355 | - } |
|
1356 | - } |
|
1357 | - } |
|
1358 | - return $caps; |
|
1359 | - } |
|
1281 | + /** |
|
1282 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1283 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1284 | + * |
|
1285 | + * @since 4.5.0 |
|
1286 | + * @see wp-includes/capabilities.php |
|
1287 | + * |
|
1288 | + * @param array $caps actual users capabilities |
|
1289 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1290 | + * @param int $user_id The user id |
|
1291 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1292 | + * |
|
1293 | + * @return array actual users capabilities |
|
1294 | + */ |
|
1295 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1296 | + { |
|
1297 | + // only process if we're checking our mapped cap; |
|
1298 | + if ($cap !== $this->meta_cap) { |
|
1299 | + return $caps; |
|
1300 | + } |
|
1301 | + |
|
1302 | + // okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1303 | + if (($key = array_search($cap, $caps)) !== false) { |
|
1304 | + unset($caps[ $key ]); |
|
1305 | + } |
|
1306 | + |
|
1307 | + // cast $user_id to int for later explicit comparisons |
|
1308 | + $user_id = (int) $user_id; |
|
1309 | + |
|
1310 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1311 | + // if no obj then let's just do cap |
|
1312 | + if (! $obj instanceof EE_Base_Class) { |
|
1313 | + $caps[] = 'do_not_allow'; |
|
1314 | + return $caps; |
|
1315 | + } |
|
1316 | + |
|
1317 | + $caps[] = $cap . 's'; |
|
1318 | + if ($obj instanceof EE_CPT_Base) { |
|
1319 | + $status_obj = get_post_status_object($obj->status()); |
|
1320 | + if ($status_obj->public) { |
|
1321 | + return $caps; |
|
1322 | + } |
|
1323 | + // if the item author is set and the user is not the author... |
|
1324 | + if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
|
1325 | + if (! empty($this->others_cap)) { |
|
1326 | + $caps[] = $this->others_cap; |
|
1327 | + } |
|
1328 | + } |
|
1329 | + // yes this means that if users created the private post, they are able to see it regardless of private cap. |
|
1330 | + if ($status_obj->private |
|
1331 | + && ! empty($this->private_cap) |
|
1332 | + && $obj->wp_user() !== $user_id |
|
1333 | + ) { |
|
1334 | + // the user is trying to view a private object for an object they don't own. |
|
1335 | + $caps[] = $this->private_cap; |
|
1336 | + } |
|
1337 | + } else { |
|
1338 | + // not a cpt object so handled differently |
|
1339 | + $has_cap = false; |
|
1340 | + try { |
|
1341 | + $has_cap = method_exists($obj, 'wp_user') |
|
1342 | + && $obj->wp_user() |
|
1343 | + && $obj->wp_user() === $user_id; |
|
1344 | + } catch (Exception $e) { |
|
1345 | + if (WP_DEBUG) { |
|
1346 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1347 | + } |
|
1348 | + } |
|
1349 | + if (! $has_cap) { |
|
1350 | + if (! empty($this->private_cap)) { |
|
1351 | + $caps[] = $this->private_cap; |
|
1352 | + } |
|
1353 | + if (! empty($this->others_cap)) { |
|
1354 | + $caps[] = $this->others_cap; |
|
1355 | + } |
|
1356 | + } |
|
1357 | + } |
|
1358 | + return $caps; |
|
1359 | + } |
|
1360 | 1360 | } |
1361 | 1361 | |
1362 | 1362 | |
@@ -1373,56 +1373,56 @@ discard block |
||
1373 | 1373 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
1374 | 1374 | { |
1375 | 1375 | |
1376 | - /** |
|
1377 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1378 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1379 | - * |
|
1380 | - * @since 4.5.0 |
|
1381 | - * @see wp-includes/capabilities.php |
|
1382 | - * |
|
1383 | - * @param array $caps actual users capabilities |
|
1384 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1385 | - * @param int $user_id The user id |
|
1386 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1387 | - * |
|
1388 | - * @return array actual users capabilities |
|
1389 | - */ |
|
1390 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1391 | - { |
|
1392 | - // only process if we're checking our mapped_cap |
|
1393 | - if ($cap !== $this->meta_cap) { |
|
1394 | - return $caps; |
|
1395 | - } |
|
1396 | - |
|
1397 | - // okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1398 | - if (($key = array_search($cap, $caps)) !== false) { |
|
1399 | - unset($caps[ $key ]); |
|
1400 | - } |
|
1401 | - |
|
1402 | - // cast $user_id to int for later explicit comparisons |
|
1403 | - $user_id = (int) $user_id; |
|
1404 | - |
|
1405 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1406 | - // if no obj then let's just do cap |
|
1407 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
1408 | - $caps[] = 'do_not_allow'; |
|
1409 | - return $caps; |
|
1410 | - } |
|
1411 | - $caps[] = $cap . 's'; |
|
1412 | - $is_global = $obj->is_global(); |
|
1413 | - if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
1414 | - if ($is_global) { |
|
1415 | - $caps[] = $this->private_cap; |
|
1416 | - } |
|
1417 | - } else { |
|
1418 | - if ($is_global) { |
|
1419 | - $caps[] = $this->private_cap; |
|
1420 | - } else { |
|
1421 | - $caps[] = $this->others_cap; |
|
1422 | - } |
|
1423 | - } |
|
1424 | - return $caps; |
|
1425 | - } |
|
1376 | + /** |
|
1377 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1378 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1379 | + * |
|
1380 | + * @since 4.5.0 |
|
1381 | + * @see wp-includes/capabilities.php |
|
1382 | + * |
|
1383 | + * @param array $caps actual users capabilities |
|
1384 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1385 | + * @param int $user_id The user id |
|
1386 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1387 | + * |
|
1388 | + * @return array actual users capabilities |
|
1389 | + */ |
|
1390 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1391 | + { |
|
1392 | + // only process if we're checking our mapped_cap |
|
1393 | + if ($cap !== $this->meta_cap) { |
|
1394 | + return $caps; |
|
1395 | + } |
|
1396 | + |
|
1397 | + // okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1398 | + if (($key = array_search($cap, $caps)) !== false) { |
|
1399 | + unset($caps[ $key ]); |
|
1400 | + } |
|
1401 | + |
|
1402 | + // cast $user_id to int for later explicit comparisons |
|
1403 | + $user_id = (int) $user_id; |
|
1404 | + |
|
1405 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1406 | + // if no obj then let's just do cap |
|
1407 | + if (! $obj instanceof EE_Message_Template_Group) { |
|
1408 | + $caps[] = 'do_not_allow'; |
|
1409 | + return $caps; |
|
1410 | + } |
|
1411 | + $caps[] = $cap . 's'; |
|
1412 | + $is_global = $obj->is_global(); |
|
1413 | + if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
|
1414 | + if ($is_global) { |
|
1415 | + $caps[] = $this->private_cap; |
|
1416 | + } |
|
1417 | + } else { |
|
1418 | + if ($is_global) { |
|
1419 | + $caps[] = $this->private_cap; |
|
1420 | + } else { |
|
1421 | + $caps[] = $this->others_cap; |
|
1422 | + } |
|
1423 | + } |
|
1424 | + return $caps; |
|
1425 | + } |
|
1426 | 1426 | } |
1427 | 1427 | |
1428 | 1428 | |
@@ -1439,40 +1439,40 @@ discard block |
||
1439 | 1439 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
1440 | 1440 | { |
1441 | 1441 | |
1442 | - /** |
|
1443 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1444 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1445 | - * |
|
1446 | - * @since 4.5.0 |
|
1447 | - * @see wp-includes/capabilities.php |
|
1448 | - * @param array $caps actual users capabilities |
|
1449 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1450 | - * @param int $user_id The user id |
|
1451 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1452 | - * @return array actual users capabilities |
|
1453 | - */ |
|
1454 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1455 | - { |
|
1456 | - // only process if we're checking our mapped_cap |
|
1457 | - if ($cap !== $this->meta_cap) { |
|
1458 | - return $caps; |
|
1459 | - } |
|
1460 | - // okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1461 | - if (($key = array_search($cap, $caps)) !== false) { |
|
1462 | - unset($caps[ $key ]); |
|
1463 | - } |
|
1464 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1465 | - // if no obj then let's just do cap |
|
1466 | - if (! $obj instanceof EE_Base_Class) { |
|
1467 | - $caps[] = 'do_not_allow'; |
|
1468 | - return $caps; |
|
1469 | - } |
|
1470 | - $caps[] = $cap . 's'; |
|
1471 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
1472 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
1473 | - if ($is_system) { |
|
1474 | - $caps[] = $this->private_cap; |
|
1475 | - } |
|
1476 | - return $caps; |
|
1477 | - } |
|
1442 | + /** |
|
1443 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1444 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1445 | + * |
|
1446 | + * @since 4.5.0 |
|
1447 | + * @see wp-includes/capabilities.php |
|
1448 | + * @param array $caps actual users capabilities |
|
1449 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1450 | + * @param int $user_id The user id |
|
1451 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1452 | + * @return array actual users capabilities |
|
1453 | + */ |
|
1454 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1455 | + { |
|
1456 | + // only process if we're checking our mapped_cap |
|
1457 | + if ($cap !== $this->meta_cap) { |
|
1458 | + return $caps; |
|
1459 | + } |
|
1460 | + // okay it is a meta cap so let's first remove that cap from the $caps array. |
|
1461 | + if (($key = array_search($cap, $caps)) !== false) { |
|
1462 | + unset($caps[ $key ]); |
|
1463 | + } |
|
1464 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1465 | + // if no obj then let's just do cap |
|
1466 | + if (! $obj instanceof EE_Base_Class) { |
|
1467 | + $caps[] = 'do_not_allow'; |
|
1468 | + return $caps; |
|
1469 | + } |
|
1470 | + $caps[] = $cap . 's'; |
|
1471 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
1472 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
1473 | + if ($is_system) { |
|
1474 | + $caps[] = $this->private_cap; |
|
1475 | + } |
|
1476 | + return $caps; |
|
1477 | + } |
|
1478 | 1478 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public static function instance() |
81 | 81 | { |
82 | 82 | // check if instantiated, and if not do so. |
83 | - if (! self::$_instance instanceof EE_Capabilities) { |
|
83 | + if ( ! self::$_instance instanceof EE_Capabilities) { |
|
84 | 84 | self::$_instance = new self(); |
85 | 85 | } |
86 | 86 | return self::$_instance; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function init_caps($reset = false) |
112 | 112 | { |
113 | - if (! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
113 | + if ( ! EE_Maintenance_Mode::instance()->models_can_query()) { |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN); |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $this->_get_default_meta_caps_array() |
156 | 156 | ); |
157 | 157 | // add filter for map_meta_caps but only if models can query. |
158 | - if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
158 | + if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) { |
|
159 | 159 | add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
160 | 160 | } |
161 | 161 | } |
@@ -314,11 +314,11 @@ discard block |
||
314 | 314 | if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
315 | 315 | // loop through our _meta_caps array |
316 | 316 | foreach ($this->_meta_caps as $meta_map) { |
317 | - if (! $meta_map instanceof EE_Meta_Capability_Map) { |
|
317 | + if ( ! $meta_map instanceof EE_Meta_Capability_Map) { |
|
318 | 318 | continue; |
319 | 319 | } |
320 | 320 | // don't load models if there is no object ID in the args |
321 | - if (! empty($args[0])) { |
|
321 | + if ( ! empty($args[0])) { |
|
322 | 322 | $meta_map->ensure_is_model(); |
323 | 323 | } |
324 | 324 | $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | public function addCaps(array $capabilities_to_add) |
653 | 653 | { |
654 | 654 | // don't do anything if the capabilities map can not be initialized |
655 | - if (! $this->setupCapabilitiesMap()) { |
|
655 | + if ( ! $this->setupCapabilitiesMap()) { |
|
656 | 656 | return false; |
657 | 657 | } |
658 | 658 | // and filter the array so others can get in on the fun during resets |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | foreach ($capabilities_to_add as $role => $caps_for_role) { |
668 | 668 | if (is_array($caps_for_role)) { |
669 | 669 | foreach ($caps_for_role as $cap) { |
670 | - if (! $this->capHasBeenAddedToRole($role, $cap) |
|
670 | + if ( ! $this->capHasBeenAddedToRole($role, $cap) |
|
671 | 671 | && $this->add_cap_to_role($role, $cap, true, false) |
672 | 672 | ) { |
673 | 673 | $update_capabilities_map = true; |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | public function removeCaps($caps_map) |
694 | 694 | { |
695 | 695 | // don't do anything if the capabilities map can not be initialized |
696 | - if (! $this->setupCapabilitiesMap()) { |
|
696 | + if ( ! $this->setupCapabilitiesMap()) { |
|
697 | 697 | return false; |
698 | 698 | } |
699 | 699 | $update_capabilities_map = false; |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | $orig_role = $role; |
753 | 753 | $role = $role instanceof WP_Role ? $role : get_role($role); |
754 | 754 | // if the role isn't available then we create it. |
755 | - if (! $role instanceof WP_Role) { |
|
755 | + if ( ! $role instanceof WP_Role) { |
|
756 | 756 | // if a plugin wants to create a specific role name then they should create the role before |
757 | 757 | // EE_Capabilities does. Otherwise this function will create the role name from the slug: |
758 | 758 | // - removes any `ee_` namespacing from the start of the slug. |
@@ -763,12 +763,12 @@ discard block |
||
763 | 763 | } |
764 | 764 | if ($role instanceof WP_Role) { |
765 | 765 | // don't do anything if the capabilities map can not be initialized |
766 | - if (! $this->setupCapabilitiesMap()) { |
|
766 | + if ( ! $this->setupCapabilitiesMap()) { |
|
767 | 767 | return false; |
768 | 768 | } |
769 | - if (! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
769 | + if ( ! $this->capHasBeenAddedToRole($role->name, $cap)) { |
|
770 | 770 | $role->add_cap($cap, $grant); |
771 | - $this->capabilities_map[ $role->name ][] = $cap; |
|
771 | + $this->capabilities_map[$role->name][] = $cap; |
|
772 | 772 | $this->updateCapabilitiesMap($update_capabilities_map); |
773 | 773 | return true; |
774 | 774 | } |
@@ -792,14 +792,14 @@ discard block |
||
792 | 792 | public function remove_cap_from_role($role, $cap, $update_capabilities_map = true) |
793 | 793 | { |
794 | 794 | // don't do anything if the capabilities map can not be initialized |
795 | - if (! $this->setupCapabilitiesMap()) { |
|
795 | + if ( ! $this->setupCapabilitiesMap()) { |
|
796 | 796 | return false; |
797 | 797 | } |
798 | 798 | |
799 | 799 | $role = $role instanceof WP_Role ? $role : get_role($role); |
800 | 800 | if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) { |
801 | 801 | $role->remove_cap($cap); |
802 | - unset($this->capabilities_map[ $role->name ][ $index ]); |
|
802 | + unset($this->capabilities_map[$role->name][$index]); |
|
803 | 803 | $this->updateCapabilitiesMap($update_capabilities_map); |
804 | 804 | return true; |
805 | 805 | } |
@@ -815,8 +815,8 @@ discard block |
||
815 | 815 | */ |
816 | 816 | private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false) |
817 | 817 | { |
818 | - if (isset($this->capabilities_map[ $role_name ]) |
|
819 | - && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false |
|
818 | + if (isset($this->capabilities_map[$role_name]) |
|
819 | + && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false |
|
820 | 820 | ) { |
821 | 821 | return $get_index ? $index : true; |
822 | 822 | } |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | public function current_user_can($cap, $context, $id = 0) |
844 | 844 | { |
845 | 845 | // apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
846 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
846 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id); |
|
847 | 847 | $filtered_cap = apply_filters( |
848 | 848 | 'FHEE__EE_Capabilities__current_user_can__cap', |
849 | 849 | $filtered_cap, |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | public function user_can($user, $cap, $context, $id = 0) |
872 | 872 | { |
873 | 873 | // apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
874 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
874 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id); |
|
875 | 875 | $filtered_cap = apply_filters( |
876 | 876 | 'FHEE__EE_Capabilities__user_can__cap', |
877 | 877 | $filtered_cap, |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | : current_user_can($blog_id, $cap); |
911 | 911 | // apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
912 | 912 | $user_can = apply_filters( |
913 | - 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, |
|
913 | + 'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context, |
|
914 | 914 | $user_can, |
915 | 915 | $blog_id, |
916 | 916 | $cap, |
@@ -939,14 +939,14 @@ discard block |
||
939 | 939 | */ |
940 | 940 | public function get_ee_capabilities($role = 'administrator') |
941 | 941 | { |
942 | - if (! $this->initialized) { |
|
942 | + if ( ! $this->initialized) { |
|
943 | 943 | $this->init_caps(); |
944 | 944 | } |
945 | 945 | if (empty($role)) { |
946 | 946 | return $this->capabilities_map; |
947 | 947 | } |
948 | - return isset($this->capabilities_map[ $role ]) |
|
949 | - ? $this->capabilities_map[ $role ] |
|
948 | + return isset($this->capabilities_map[$role]) |
|
949 | + ? $this->capabilities_map[$role] |
|
950 | 950 | : array(); |
951 | 951 | } |
952 | 952 | |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | 'event_espresso' |
978 | 978 | ), |
979 | 979 | '$reset', |
980 | - __METHOD__ . '()', |
|
980 | + __METHOD__.'()', |
|
981 | 981 | 'EE_Capabilities::init_caps()', |
982 | 982 | 'true' |
983 | 983 | ), |
@@ -1051,7 +1051,7 @@ discard block |
||
1051 | 1051 | 'Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
1052 | 1052 | 'event_espresso' |
1053 | 1053 | ), |
1054 | - '<br>' . print_r($map_values, true) |
|
1054 | + '<br>'.print_r($map_values, true) |
|
1055 | 1055 | ) |
1056 | 1056 | ); |
1057 | 1057 | } |
@@ -1091,7 +1091,7 @@ discard block |
||
1091 | 1091 | // error proof if the name has EEM in it |
1092 | 1092 | $this->_model_name = str_replace('EEM', '', $this->_model_name); |
1093 | 1093 | $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
1094 | - if (! $this->_model instanceof EEM_Base) { |
|
1094 | + if ( ! $this->_model instanceof EEM_Base) { |
|
1095 | 1095 | throw new EE_Error( |
1096 | 1096 | sprintf( |
1097 | 1097 | __( |
@@ -1177,7 +1177,7 @@ discard block |
||
1177 | 1177 | |
1178 | 1178 | // okay it is a meta cap so let's first remove that cap from the $caps array. |
1179 | 1179 | if (($key = array_search($cap, $caps)) !== false) { |
1180 | - unset($caps[ $key ]); |
|
1180 | + unset($caps[$key]); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 | // cast $user_id to int for later explicit comparisons |
@@ -1186,11 +1186,11 @@ discard block |
||
1186 | 1186 | /** @var EE_Base_Class $obj */ |
1187 | 1187 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1188 | 1188 | // if no obj then let's just do cap |
1189 | - if (! $obj instanceof EE_Base_Class) { |
|
1189 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1190 | 1190 | $caps[] = 'do_not_allow'; |
1191 | 1191 | return $caps; |
1192 | 1192 | } |
1193 | - $caps[] = $cap . 's'; |
|
1193 | + $caps[] = $cap.'s'; |
|
1194 | 1194 | if ($obj instanceof EE_CPT_Base) { |
1195 | 1195 | // if the item author is set and the user is the author... |
1196 | 1196 | if ($obj->wp_user() && $user_id === $obj->wp_user()) { |
@@ -1200,12 +1200,12 @@ discard block |
||
1200 | 1200 | } |
1201 | 1201 | } else { |
1202 | 1202 | // the user is trying to edit someone else's obj |
1203 | - if (! empty($this->others_cap)) { |
|
1203 | + if ( ! empty($this->others_cap)) { |
|
1204 | 1204 | $caps[] = $this->others_cap; |
1205 | 1205 | } |
1206 | - if (! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1206 | + if ( ! empty($this->published_cap) && $obj->status() === 'publish') { |
|
1207 | 1207 | $caps[] = $this->published_cap; |
1208 | - } elseif (! empty($this->private_cap) && $obj->status() === 'private') { |
|
1208 | + } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') { |
|
1209 | 1209 | $caps[] = $this->private_cap; |
1210 | 1210 | } |
1211 | 1211 | } |
@@ -1221,8 +1221,8 @@ discard block |
||
1221 | 1221 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
1222 | 1222 | } |
1223 | 1223 | } |
1224 | - if (! $has_cap) { |
|
1225 | - if (! empty($this->others_cap)) { |
|
1224 | + if ( ! $has_cap) { |
|
1225 | + if ( ! empty($this->others_cap)) { |
|
1226 | 1226 | $caps[] = $this->others_cap; |
1227 | 1227 | } |
1228 | 1228 | } |
@@ -1301,7 +1301,7 @@ discard block |
||
1301 | 1301 | |
1302 | 1302 | // okay it is a meta cap so let's first remove that cap from the $caps array. |
1303 | 1303 | if (($key = array_search($cap, $caps)) !== false) { |
1304 | - unset($caps[ $key ]); |
|
1304 | + unset($caps[$key]); |
|
1305 | 1305 | } |
1306 | 1306 | |
1307 | 1307 | // cast $user_id to int for later explicit comparisons |
@@ -1309,12 +1309,12 @@ discard block |
||
1309 | 1309 | |
1310 | 1310 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1311 | 1311 | // if no obj then let's just do cap |
1312 | - if (! $obj instanceof EE_Base_Class) { |
|
1312 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1313 | 1313 | $caps[] = 'do_not_allow'; |
1314 | 1314 | return $caps; |
1315 | 1315 | } |
1316 | 1316 | |
1317 | - $caps[] = $cap . 's'; |
|
1317 | + $caps[] = $cap.'s'; |
|
1318 | 1318 | if ($obj instanceof EE_CPT_Base) { |
1319 | 1319 | $status_obj = get_post_status_object($obj->status()); |
1320 | 1320 | if ($status_obj->public) { |
@@ -1322,7 +1322,7 @@ discard block |
||
1322 | 1322 | } |
1323 | 1323 | // if the item author is set and the user is not the author... |
1324 | 1324 | if ($obj->wp_user() && $obj->wp_user() !== $user_id) { |
1325 | - if (! empty($this->others_cap)) { |
|
1325 | + if ( ! empty($this->others_cap)) { |
|
1326 | 1326 | $caps[] = $this->others_cap; |
1327 | 1327 | } |
1328 | 1328 | } |
@@ -1346,11 +1346,11 @@ discard block |
||
1346 | 1346 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
1347 | 1347 | } |
1348 | 1348 | } |
1349 | - if (! $has_cap) { |
|
1350 | - if (! empty($this->private_cap)) { |
|
1349 | + if ( ! $has_cap) { |
|
1350 | + if ( ! empty($this->private_cap)) { |
|
1351 | 1351 | $caps[] = $this->private_cap; |
1352 | 1352 | } |
1353 | - if (! empty($this->others_cap)) { |
|
1353 | + if ( ! empty($this->others_cap)) { |
|
1354 | 1354 | $caps[] = $this->others_cap; |
1355 | 1355 | } |
1356 | 1356 | } |
@@ -1396,7 +1396,7 @@ discard block |
||
1396 | 1396 | |
1397 | 1397 | // okay it is a meta cap so let's first remove that cap from the $caps array. |
1398 | 1398 | if (($key = array_search($cap, $caps)) !== false) { |
1399 | - unset($caps[ $key ]); |
|
1399 | + unset($caps[$key]); |
|
1400 | 1400 | } |
1401 | 1401 | |
1402 | 1402 | // cast $user_id to int for later explicit comparisons |
@@ -1404,11 +1404,11 @@ discard block |
||
1404 | 1404 | |
1405 | 1405 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1406 | 1406 | // if no obj then let's just do cap |
1407 | - if (! $obj instanceof EE_Message_Template_Group) { |
|
1407 | + if ( ! $obj instanceof EE_Message_Template_Group) { |
|
1408 | 1408 | $caps[] = 'do_not_allow'; |
1409 | 1409 | return $caps; |
1410 | 1410 | } |
1411 | - $caps[] = $cap . 's'; |
|
1411 | + $caps[] = $cap.'s'; |
|
1412 | 1412 | $is_global = $obj->is_global(); |
1413 | 1413 | if ($obj->wp_user() && $obj->wp_user() === $user_id) { |
1414 | 1414 | if ($is_global) { |
@@ -1459,15 +1459,15 @@ discard block |
||
1459 | 1459 | } |
1460 | 1460 | // okay it is a meta cap so let's first remove that cap from the $caps array. |
1461 | 1461 | if (($key = array_search($cap, $caps)) !== false) { |
1462 | - unset($caps[ $key ]); |
|
1462 | + unset($caps[$key]); |
|
1463 | 1463 | } |
1464 | 1464 | $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
1465 | 1465 | // if no obj then let's just do cap |
1466 | - if (! $obj instanceof EE_Base_Class) { |
|
1466 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1467 | 1467 | $caps[] = 'do_not_allow'; |
1468 | 1468 | return $caps; |
1469 | 1469 | } |
1470 | - $caps[] = $cap . 's'; |
|
1470 | + $caps[] = $cap.'s'; |
|
1471 | 1471 | $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
1472 | 1472 | $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
1473 | 1473 | if ($is_system) { |
@@ -198,7 +198,7 @@ |
||
198 | 198 | * |
199 | 199 | * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
200 | 200 | * |
201 | - * @return int |
|
201 | + * @return string |
|
202 | 202 | */ |
203 | 203 | private function _revenue_per_event_report($period = '-1 month') |
204 | 204 | { |
@@ -16,239 +16,239 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * This is used to hold the reports template data which is setup early in the request. |
|
21 | - * |
|
22 | - * @type array |
|
23 | - */ |
|
24 | - protected $_reports_template_data = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * @Constructor |
|
28 | - * @access public |
|
29 | - * |
|
30 | - * @param bool $routing |
|
31 | - * |
|
32 | - * @return \Extend_Transactions_Admin_Page |
|
33 | - */ |
|
34 | - public function __construct($routing = true) |
|
35 | - { |
|
36 | - parent::__construct($routing); |
|
37 | - define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/'); |
|
38 | - define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/'); |
|
39 | - define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/'); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * _extend_page_config |
|
45 | - * |
|
46 | - * @access protected |
|
47 | - * @return void |
|
48 | - */ |
|
49 | - protected function _extend_page_config() |
|
50 | - { |
|
51 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions'; |
|
52 | - |
|
53 | - $new_page_routes = array( |
|
54 | - 'reports' => array( |
|
55 | - 'func' => '_transaction_reports', |
|
56 | - 'capability' => 'ee_read_transactions', |
|
57 | - ), |
|
58 | - ); |
|
59 | - |
|
60 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
61 | - |
|
62 | - $new_page_config = array( |
|
63 | - 'reports' => array( |
|
64 | - 'nav' => array( |
|
65 | - 'label' => __('Reports', 'event_espresso'), |
|
66 | - 'order' => 20, |
|
67 | - ), |
|
68 | - 'help_tabs' => array( |
|
69 | - 'transactions_reports_help_tab' => array( |
|
70 | - 'title' => __('Transaction Reports', 'event_espresso'), |
|
71 | - 'filename' => 'transactions_reports', |
|
72 | - ), |
|
73 | - ), |
|
74 | - /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/ |
|
75 | - 'require_nonce' => false, |
|
76 | - ), |
|
77 | - ); |
|
78 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * load_scripts_styles_reports |
|
84 | - * |
|
85 | - * @access public |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - public function load_scripts_styles_reports() |
|
89 | - { |
|
90 | - wp_register_script( |
|
91 | - 'ee-txn-reports-js', |
|
92 | - TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js', |
|
93 | - array('google-charts'), |
|
94 | - EVENT_ESPRESSO_VERSION, |
|
95 | - true |
|
96 | - ); |
|
97 | - wp_enqueue_script('ee-txn-reports-js'); |
|
98 | - $this->_transaction_reports_js_setup(); |
|
99 | - EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts(); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
105 | - * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method. |
|
106 | - */ |
|
107 | - protected function _transaction_reports_js_setup() |
|
108 | - { |
|
109 | - $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report(); |
|
110 | - $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report(); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * _transaction_reports |
|
116 | - * generates Business Reports regarding Transactions |
|
117 | - * |
|
118 | - * @return void |
|
119 | - */ |
|
120 | - protected function _transaction_reports() |
|
121 | - { |
|
122 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
123 | - $this->_admin_page_title = __('Transactions', 'event_espresso'); |
|
124 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
125 | - $template_path, |
|
126 | - $this->_reports_template_data, |
|
127 | - true |
|
128 | - ); |
|
129 | - |
|
130 | - // the final template wrapper |
|
131 | - $this->display_admin_page_with_no_sidebar(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * _revenue_per_day_report |
|
137 | - * generates Business Report showing Total Revenue per Day. |
|
138 | - * |
|
139 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
140 | - * |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - private function _revenue_per_day_report($period = '-1 month') |
|
144 | - { |
|
145 | - |
|
146 | - $report_ID = 'txn-admin-revenue-per-day-report-dv'; |
|
147 | - |
|
148 | - $TXN = EEM_Transaction::instance(); |
|
149 | - |
|
150 | - $results = $TXN->get_revenue_per_day_report($period); |
|
151 | - $results = (array) $results; |
|
152 | - $revenue = array(); |
|
153 | - $subtitle = ''; |
|
154 | - |
|
155 | - if ($results) { |
|
156 | - $revenue[] = array( |
|
157 | - __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'), |
|
158 | - __('Total Revenue', 'event_espresso'), |
|
159 | - ); |
|
160 | - foreach ($results as $result) { |
|
161 | - $revenue[] = array($result->txnDate, (float) $result->revenue); |
|
162 | - } |
|
163 | - |
|
164 | - // setup the date range. |
|
165 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
166 | - $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
167 | - $subtitle = sprintf( |
|
168 | - _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
169 | - $beginning_date->format('Y-m-d'), |
|
170 | - $ending_date->format('Y-m-d') |
|
171 | - ); |
|
172 | - } |
|
173 | - |
|
174 | - $report_title = esc_html__('Total Revenue per Day', 'event_espresso'); |
|
175 | - |
|
176 | - $report_params = array( |
|
177 | - 'title' => $report_title, |
|
178 | - 'subtitle' => $subtitle, |
|
179 | - 'id' => $report_ID, |
|
180 | - 'revenue' => $revenue, |
|
181 | - 'noResults' => empty($revenue) || count($revenue) === 1, |
|
182 | - 'noTxnMsg' => sprintf( |
|
183 | - __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
184 | - '<h2>' . $report_title . '</h2><p>', |
|
185 | - '</p>' |
|
186 | - ), |
|
187 | - ); |
|
188 | - wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params); |
|
189 | - |
|
190 | - return $report_ID; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * _revenue_per_event_report |
|
196 | - * generates Business Report showing total revenue per event. |
|
197 | - * |
|
198 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
199 | - * |
|
200 | - * @return int |
|
201 | - */ |
|
202 | - private function _revenue_per_event_report($period = '-1 month') |
|
203 | - { |
|
204 | - |
|
205 | - $report_ID = 'txn-admin-revenue-per-event-report-dv'; |
|
206 | - |
|
207 | - $TXN = EEM_Transaction::instance(); |
|
208 | - $results = $TXN->get_revenue_per_event_report($period); |
|
209 | - $results = (array) $results; |
|
210 | - $revenue = array(); |
|
211 | - $subtitle = ''; |
|
212 | - |
|
213 | - if ($results) { |
|
214 | - $revenue[] = array( |
|
215 | - __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'), |
|
216 | - __('Total Revenue', 'event_espresso'), |
|
217 | - ); |
|
218 | - foreach ($results as $result) { |
|
219 | - if ($result->revenue > 1) { |
|
220 | - $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8')); |
|
221 | - $event_name = wp_trim_words($event_name, 5, '...'); |
|
222 | - $revenue[] = array($event_name, (float) $result->revenue); |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - // setup the date range. |
|
227 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
228 | - $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
229 | - $subtitle = sprintf( |
|
230 | - _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
231 | - $beginning_date->format('Y-m-d'), |
|
232 | - $ending_date->format('Y-m-d') |
|
233 | - ); |
|
234 | - } |
|
235 | - |
|
236 | - $report_title = esc_html__('Total Revenue per Event', 'event_espresso'); |
|
237 | - |
|
238 | - $report_params = array( |
|
239 | - 'title' => $report_title, |
|
240 | - 'subtitle' => $subtitle, |
|
241 | - 'id' => $report_ID, |
|
242 | - 'revenue' => $revenue, |
|
243 | - 'noResults' => empty($revenue), |
|
244 | - 'noTxnMsg' => sprintf( |
|
245 | - __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
246 | - '<h2>' . $report_title . '</h2><p>', |
|
247 | - '</p>' |
|
248 | - ), |
|
249 | - ); |
|
250 | - wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params); |
|
251 | - |
|
252 | - return $report_ID; |
|
253 | - } |
|
19 | + /** |
|
20 | + * This is used to hold the reports template data which is setup early in the request. |
|
21 | + * |
|
22 | + * @type array |
|
23 | + */ |
|
24 | + protected $_reports_template_data = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * @Constructor |
|
28 | + * @access public |
|
29 | + * |
|
30 | + * @param bool $routing |
|
31 | + * |
|
32 | + * @return \Extend_Transactions_Admin_Page |
|
33 | + */ |
|
34 | + public function __construct($routing = true) |
|
35 | + { |
|
36 | + parent::__construct($routing); |
|
37 | + define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/'); |
|
38 | + define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/'); |
|
39 | + define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/'); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * _extend_page_config |
|
45 | + * |
|
46 | + * @access protected |
|
47 | + * @return void |
|
48 | + */ |
|
49 | + protected function _extend_page_config() |
|
50 | + { |
|
51 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions'; |
|
52 | + |
|
53 | + $new_page_routes = array( |
|
54 | + 'reports' => array( |
|
55 | + 'func' => '_transaction_reports', |
|
56 | + 'capability' => 'ee_read_transactions', |
|
57 | + ), |
|
58 | + ); |
|
59 | + |
|
60 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
61 | + |
|
62 | + $new_page_config = array( |
|
63 | + 'reports' => array( |
|
64 | + 'nav' => array( |
|
65 | + 'label' => __('Reports', 'event_espresso'), |
|
66 | + 'order' => 20, |
|
67 | + ), |
|
68 | + 'help_tabs' => array( |
|
69 | + 'transactions_reports_help_tab' => array( |
|
70 | + 'title' => __('Transaction Reports', 'event_espresso'), |
|
71 | + 'filename' => 'transactions_reports', |
|
72 | + ), |
|
73 | + ), |
|
74 | + /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/ |
|
75 | + 'require_nonce' => false, |
|
76 | + ), |
|
77 | + ); |
|
78 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * load_scripts_styles_reports |
|
84 | + * |
|
85 | + * @access public |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + public function load_scripts_styles_reports() |
|
89 | + { |
|
90 | + wp_register_script( |
|
91 | + 'ee-txn-reports-js', |
|
92 | + TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js', |
|
93 | + array('google-charts'), |
|
94 | + EVENT_ESPRESSO_VERSION, |
|
95 | + true |
|
96 | + ); |
|
97 | + wp_enqueue_script('ee-txn-reports-js'); |
|
98 | + $this->_transaction_reports_js_setup(); |
|
99 | + EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts(); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
105 | + * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method. |
|
106 | + */ |
|
107 | + protected function _transaction_reports_js_setup() |
|
108 | + { |
|
109 | + $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report(); |
|
110 | + $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report(); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * _transaction_reports |
|
116 | + * generates Business Reports regarding Transactions |
|
117 | + * |
|
118 | + * @return void |
|
119 | + */ |
|
120 | + protected function _transaction_reports() |
|
121 | + { |
|
122 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
123 | + $this->_admin_page_title = __('Transactions', 'event_espresso'); |
|
124 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
125 | + $template_path, |
|
126 | + $this->_reports_template_data, |
|
127 | + true |
|
128 | + ); |
|
129 | + |
|
130 | + // the final template wrapper |
|
131 | + $this->display_admin_page_with_no_sidebar(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * _revenue_per_day_report |
|
137 | + * generates Business Report showing Total Revenue per Day. |
|
138 | + * |
|
139 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
140 | + * |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + private function _revenue_per_day_report($period = '-1 month') |
|
144 | + { |
|
145 | + |
|
146 | + $report_ID = 'txn-admin-revenue-per-day-report-dv'; |
|
147 | + |
|
148 | + $TXN = EEM_Transaction::instance(); |
|
149 | + |
|
150 | + $results = $TXN->get_revenue_per_day_report($period); |
|
151 | + $results = (array) $results; |
|
152 | + $revenue = array(); |
|
153 | + $subtitle = ''; |
|
154 | + |
|
155 | + if ($results) { |
|
156 | + $revenue[] = array( |
|
157 | + __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'), |
|
158 | + __('Total Revenue', 'event_espresso'), |
|
159 | + ); |
|
160 | + foreach ($results as $result) { |
|
161 | + $revenue[] = array($result->txnDate, (float) $result->revenue); |
|
162 | + } |
|
163 | + |
|
164 | + // setup the date range. |
|
165 | + $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
166 | + $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
167 | + $subtitle = sprintf( |
|
168 | + _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
169 | + $beginning_date->format('Y-m-d'), |
|
170 | + $ending_date->format('Y-m-d') |
|
171 | + ); |
|
172 | + } |
|
173 | + |
|
174 | + $report_title = esc_html__('Total Revenue per Day', 'event_espresso'); |
|
175 | + |
|
176 | + $report_params = array( |
|
177 | + 'title' => $report_title, |
|
178 | + 'subtitle' => $subtitle, |
|
179 | + 'id' => $report_ID, |
|
180 | + 'revenue' => $revenue, |
|
181 | + 'noResults' => empty($revenue) || count($revenue) === 1, |
|
182 | + 'noTxnMsg' => sprintf( |
|
183 | + __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
184 | + '<h2>' . $report_title . '</h2><p>', |
|
185 | + '</p>' |
|
186 | + ), |
|
187 | + ); |
|
188 | + wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params); |
|
189 | + |
|
190 | + return $report_ID; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * _revenue_per_event_report |
|
196 | + * generates Business Report showing total revenue per event. |
|
197 | + * |
|
198 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
199 | + * |
|
200 | + * @return int |
|
201 | + */ |
|
202 | + private function _revenue_per_event_report($period = '-1 month') |
|
203 | + { |
|
204 | + |
|
205 | + $report_ID = 'txn-admin-revenue-per-event-report-dv'; |
|
206 | + |
|
207 | + $TXN = EEM_Transaction::instance(); |
|
208 | + $results = $TXN->get_revenue_per_event_report($period); |
|
209 | + $results = (array) $results; |
|
210 | + $revenue = array(); |
|
211 | + $subtitle = ''; |
|
212 | + |
|
213 | + if ($results) { |
|
214 | + $revenue[] = array( |
|
215 | + __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'), |
|
216 | + __('Total Revenue', 'event_espresso'), |
|
217 | + ); |
|
218 | + foreach ($results as $result) { |
|
219 | + if ($result->revenue > 1) { |
|
220 | + $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8')); |
|
221 | + $event_name = wp_trim_words($event_name, 5, '...'); |
|
222 | + $revenue[] = array($event_name, (float) $result->revenue); |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + // setup the date range. |
|
227 | + $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
228 | + $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
229 | + $subtitle = sprintf( |
|
230 | + _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
|
231 | + $beginning_date->format('Y-m-d'), |
|
232 | + $ending_date->format('Y-m-d') |
|
233 | + ); |
|
234 | + } |
|
235 | + |
|
236 | + $report_title = esc_html__('Total Revenue per Event', 'event_espresso'); |
|
237 | + |
|
238 | + $report_params = array( |
|
239 | + 'title' => $report_title, |
|
240 | + 'subtitle' => $subtitle, |
|
241 | + 'id' => $report_ID, |
|
242 | + 'revenue' => $revenue, |
|
243 | + 'noResults' => empty($revenue), |
|
244 | + 'noTxnMsg' => sprintf( |
|
245 | + __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
|
246 | + '<h2>' . $report_title . '</h2><p>', |
|
247 | + '</p>' |
|
248 | + ), |
|
249 | + ); |
|
250 | + wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params); |
|
251 | + |
|
252 | + return $report_ID; |
|
253 | + } |
|
254 | 254 | } |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | public function __construct($routing = true) |
35 | 35 | { |
36 | 36 | parent::__construct($routing); |
37 | - define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/'); |
|
38 | - define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/'); |
|
39 | - define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/'); |
|
37 | + define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'transactions/templates/'); |
|
38 | + define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'transactions/assets/'); |
|
39 | + define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'transactions/assets/'); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected function _extend_page_config() |
50 | 50 | { |
51 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions'; |
|
51 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'transactions'; |
|
52 | 52 | |
53 | 53 | $new_page_routes = array( |
54 | 54 | 'reports' => array( |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | { |
90 | 90 | wp_register_script( |
91 | 91 | 'ee-txn-reports-js', |
92 | - TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js', |
|
92 | + TXN_CAF_ASSETS_URL.'ee-transaction-admin-reports.js', |
|
93 | 93 | array('google-charts'), |
94 | 94 | EVENT_ESPRESSO_VERSION, |
95 | 95 | true |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | protected function _transaction_reports() |
121 | 121 | { |
122 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
122 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
123 | 123 | $this->_admin_page_title = __('Transactions', 'event_espresso'); |
124 | 124 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
125 | 125 | $template_path, |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | } |
163 | 163 | |
164 | 164 | // setup the date range. |
165 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
165 | + $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
166 | 166 | $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
167 | 167 | $subtitle = sprintf( |
168 | 168 | _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | 'noResults' => empty($revenue) || count($revenue) === 1, |
182 | 182 | 'noTxnMsg' => sprintf( |
183 | 183 | __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
184 | - '<h2>' . $report_title . '</h2><p>', |
|
184 | + '<h2>'.$report_title.'</h2><p>', |
|
185 | 185 | '</p>' |
186 | 186 | ), |
187 | 187 | ); |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | } |
225 | 225 | |
226 | 226 | // setup the date range. |
227 | - $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
227 | + $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
|
228 | 228 | $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone())); |
229 | 229 | $subtitle = sprintf( |
230 | 230 | _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'), |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | 'noResults' => empty($revenue), |
244 | 244 | 'noTxnMsg' => sprintf( |
245 | 245 | __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'), |
246 | - '<h2>' . $report_title . '</h2><p>', |
|
246 | + '<h2>'.$report_title.'</h2><p>', |
|
247 | 247 | '</p>' |
248 | 248 | ), |
249 | 249 | ); |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @param array $dir_ref original array of paths |
93 | 93 | * |
94 | - * @return array appended paths |
|
94 | + * @return string[] appended paths |
|
95 | 95 | */ |
96 | 96 | public function messages_autoload_paths($dir_ref) |
97 | 97 | { |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | * @param EE_Question[] $questions An array of questions indexed by answer id. |
702 | 702 | * @param EE_Answer[] $answers An array of answer objects |
703 | 703 | * @param string $template Template content to be parsed. |
704 | - * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
704 | + * @param string[] $valid_shortcodes Valid shortcodes for the template being parsed. |
|
705 | 705 | * @param array $extra_data Extra data that might be used when parsing the template. |
706 | 706 | */ |
707 | 707 | protected function _parse_question_list_for_primary_or_recipient_registration( |
@@ -13,803 +13,803 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * constructor. |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->_caf_hooks(); |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
27 | - * |
|
28 | - * @since 4.3.2 |
|
29 | - * |
|
30 | - * @return void |
|
31 | - */ |
|
32 | - private function _caf_hooks() |
|
33 | - { |
|
34 | - add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
35 | - add_filter( |
|
36 | - 'FHEE__EE_Email_messenger__get_validator_config', |
|
37 | - array($this, 'email_messenger_validator_config'), |
|
38 | - 5, |
|
39 | - 2 |
|
40 | - ); |
|
41 | - add_filter( |
|
42 | - 'FHEE__EE_Email_messenger__get_template_fields', |
|
43 | - array($this, 'email_messenger_template_fields'), |
|
44 | - 5, |
|
45 | - 2 |
|
46 | - ); |
|
47 | - add_filter( |
|
48 | - 'FHEE__EE_Html_messenger__get_template_fields', |
|
49 | - array($this, 'html_messenger_template_fields'), |
|
50 | - 5, |
|
51 | - 2 |
|
52 | - ); |
|
53 | - add_filter( |
|
54 | - 'FHEE__EE_Html_messenger__get_validator_config', |
|
55 | - array($this, 'html_messenger_validator_config'), |
|
56 | - 5, |
|
57 | - 2 |
|
58 | - ); |
|
59 | - add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
60 | - add_filter( |
|
61 | - 'FHEE__EE_Pdf_messenger__get_validator_config', |
|
62 | - array($this, 'pdf_messenger_validator_config'), |
|
63 | - 5, |
|
64 | - 2 |
|
65 | - ); |
|
66 | - add_filter( |
|
67 | - 'FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
68 | - array($this, 'new_default_templates'), |
|
69 | - 5, |
|
70 | - 7 |
|
71 | - ); |
|
72 | - add_filter( |
|
73 | - 'FHEE__EE_Messages_Base__get_valid_shortcodes', |
|
74 | - array($this, 'message_types_valid_shortcodes'), |
|
75 | - 5, |
|
76 | - 2 |
|
77 | - ); |
|
78 | - |
|
79 | - // shortcode parsers |
|
80 | - add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
81 | - add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
82 | - add_filter( |
|
83 | - 'FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
84 | - array($this, 'additional_recipient_details_shortcodes'), |
|
85 | - 5, |
|
86 | - 2 |
|
87 | - ); |
|
88 | - add_filter( |
|
89 | - 'FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
90 | - array($this, 'additional_recipient_details_parser'), |
|
91 | - 5, |
|
92 | - 5 |
|
93 | - ); |
|
94 | - add_filter( |
|
95 | - 'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
96 | - array($this, 'additional_primary_registration_details_shortcodes'), |
|
97 | - 5, |
|
98 | - 2 |
|
99 | - ); |
|
100 | - add_filter( |
|
101 | - 'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
102 | - array($this, 'additional_primary_registration_details_parser'), |
|
103 | - 5, |
|
104 | - 5 |
|
105 | - ); |
|
106 | - |
|
107 | - /** |
|
108 | - * @since 4.2.0 |
|
109 | - */ |
|
110 | - add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
111 | - add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
112 | - |
|
113 | - /** |
|
114 | - * @since 4.3.0 |
|
115 | - */ |
|
116 | - // eat our own dog food! |
|
117 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
118 | - add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
119 | - do_action('EE_Brewing_Regular___messages_caf'); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
125 | - * messages system. |
|
126 | - * |
|
127 | - * @param array $dir_ref original array of paths |
|
128 | - * |
|
129 | - * @return array appended paths |
|
130 | - */ |
|
131 | - public function messages_autoload_paths($dir_ref) |
|
132 | - { |
|
133 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
134 | - |
|
135 | - return $dir_ref; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
140 | - { |
|
141 | - $validator_config['attendee_list'] = array( |
|
142 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
143 | - 'required' => array('[ATTENDEE_LIST]'), |
|
144 | - ); |
|
145 | - $validator_config['question_list'] = array( |
|
146 | - 'shortcodes' => array('question'), |
|
147 | - 'required' => array('[QUESTION_LIST]'), |
|
148 | - ); |
|
149 | - |
|
150 | - return $validator_config; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
155 | - { |
|
156 | - $validator_config['attendee_list'] = array( |
|
157 | - 'shortcodes' => array('attendee', 'question_list'), |
|
158 | - 'required' => array('[ATTENDEE_LIST]'), |
|
159 | - ); |
|
160 | - $validator_config['question_list'] = array( |
|
161 | - 'shortcodes' => array('question'), |
|
162 | - 'required' => array('[QUESTION_LIST]'), |
|
163 | - ); |
|
164 | - |
|
165 | - return $validator_config; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
170 | - { |
|
171 | - $validator_config['attendee_list'] = array( |
|
172 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
173 | - 'required' => array('[ATTENDEE_LIST]'), |
|
174 | - ); |
|
175 | - $validator_config['question_list'] = array( |
|
176 | - 'shortcodes' => array('question'), |
|
177 | - 'required' => array('[QUESTION_LIST]'), |
|
178 | - ); |
|
179 | - |
|
180 | - return $validator_config; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
185 | - { |
|
186 | - $template_fields['extra']['content']['question_list'] = array( |
|
187 | - 'input' => 'textarea', |
|
188 | - 'label' => '[QUESTION_LIST]', |
|
189 | - 'type' => 'string', |
|
190 | - 'required' => true, |
|
191 | - 'validation' => true, |
|
192 | - 'format' => '%s', |
|
193 | - 'css_class' => 'large-text', |
|
194 | - 'rows' => '5', |
|
195 | - 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
196 | - ); |
|
197 | - |
|
198 | - return $template_fields; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
203 | - { |
|
204 | - $template_fields['extra']['content']['question_list'] = array( |
|
205 | - 'input' => 'textarea', |
|
206 | - 'label' => '[QUESTION_LIST]', |
|
207 | - 'type' => 'string', |
|
208 | - 'required' => true, |
|
209 | - 'validation' => true, |
|
210 | - 'format' => '%s', |
|
211 | - 'css_class' => 'large-text', |
|
212 | - 'rows' => '5', |
|
213 | - 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
214 | - ); |
|
215 | - |
|
216 | - return $template_fields; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
221 | - { |
|
222 | - $template_fields['extra']['content']['question_list'] = array( |
|
223 | - 'input' => 'textarea', |
|
224 | - 'label' => '[QUESTION_LIST]', |
|
225 | - 'type' => 'string', |
|
226 | - 'required' => true, |
|
227 | - 'validation' => true, |
|
228 | - 'format' => '%s', |
|
229 | - 'css_class' => 'large-text', |
|
230 | - 'rows' => '5', |
|
231 | - 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
232 | - ); |
|
233 | - |
|
234 | - return $template_fields; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - public function new_default_templates( |
|
239 | - $contents, |
|
240 | - $actual_path, |
|
241 | - EE_messenger $messenger, |
|
242 | - EE_message_type $message_type, |
|
243 | - $field, |
|
244 | - $context, |
|
245 | - EE_Messages_Template_Pack $template_pack |
|
246 | - ) { |
|
247 | - |
|
248 | - // we're only modifying templates for the default template pack |
|
249 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
250 | - return $contents; |
|
251 | - } |
|
252 | - |
|
253 | - // the template file name we're replacing contents for. |
|
254 | - $template_file_prefix = $field . '_' . $context; |
|
255 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
256 | - |
|
257 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
258 | - |
|
259 | - if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
260 | - switch ($template_file_prefix) { |
|
261 | - case 'question_list_admin': |
|
262 | - case 'question_list_attendee': |
|
263 | - case 'question_list_primary_attendee': |
|
264 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
265 | - $contents = EEH_Template::display_template($path, array(), true); |
|
266 | - break; |
|
267 | - |
|
268 | - case 'attendee_list_primary_attendee': |
|
269 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
270 | - $contents = EEH_Template::display_template($path, array(), true); |
|
271 | - break; |
|
272 | - |
|
273 | - case 'attendee_list_admin': |
|
274 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
275 | - $contents = EEH_Template::display_template( |
|
276 | - $path, |
|
277 | - array(), |
|
278 | - true |
|
279 | - ); |
|
280 | - break; |
|
281 | - |
|
282 | - case 'attendee_list_attendee': |
|
283 | - $contents = ''; |
|
284 | - break; |
|
285 | - |
|
286 | - case 'event_list_attendee': |
|
287 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
288 | - $contents = EEH_Template::display_template($path, array(), true); |
|
289 | - break; |
|
290 | - } |
|
291 | - } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
292 | - switch ($template_file_prefix) { |
|
293 | - case 'content_attendee': |
|
294 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
295 | - $contents = EEH_Template::display_template($path, array(), true); |
|
296 | - break; |
|
297 | - |
|
298 | - case 'newsletter_content_attendee': |
|
299 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
300 | - $contents = EEH_Template::display_template($path, array(), true); |
|
301 | - break; |
|
302 | - |
|
303 | - case 'newsletter_subject_attendee': |
|
304 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
305 | - $contents = EEH_Template::display_template($path, array(), true); |
|
306 | - break; |
|
307 | - } |
|
308 | - } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
309 | - switch ($template_file_prefix) { |
|
310 | - case 'attendee_list_purchaser': |
|
311 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
312 | - $contents = EEH_Template::display_template($path, array(), true); |
|
313 | - break; |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - return $contents; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
322 | - { |
|
323 | - // make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
324 | - $include_with = array( |
|
325 | - 'registration', |
|
326 | - 'cancelled_registration', |
|
327 | - 'declined_registration', |
|
328 | - 'not_approved_registration', |
|
329 | - 'payment_declined', |
|
330 | - 'payment_failed', |
|
331 | - 'payment_cancelled', |
|
332 | - 'payment', |
|
333 | - 'payment_reminder', |
|
334 | - 'pending_approval', |
|
335 | - 'registration_summary', |
|
336 | - 'invoice', |
|
337 | - 'receipt', |
|
338 | - ); |
|
339 | - if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
340 | - $contexts = array_keys($msg->get_contexts()); |
|
341 | - foreach ($contexts as $context) { |
|
342 | - $valid_shortcodes[ $context ][] = 'question_list'; |
|
343 | - $valid_shortcodes[ $context ][] = 'question'; |
|
344 | - } |
|
345 | - } |
|
346 | - |
|
347 | - return $valid_shortcodes; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
352 | - { |
|
353 | - $shortcodes['[ANSWER_*]'] = __( |
|
354 | - 'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
355 | - 'event_espresso' |
|
356 | - ); |
|
357 | - |
|
358 | - return $shortcodes; |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
363 | - { |
|
364 | - |
|
365 | - if (strpos($shortcode, '[ANSWER_*') === false |
|
366 | - || ! isset($extra_data['data']->questions) |
|
367 | - || ! isset($extra_data['data']->registrations) |
|
368 | - ) { |
|
369 | - return $parsed; |
|
370 | - } |
|
371 | - |
|
372 | - // let's get the question from the code. |
|
373 | - $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
374 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
375 | - |
|
376 | - $registration = $data instanceof EE_Registration ? $data : null; |
|
377 | - $registration = ! $registration instanceof EE_Registration && is_array( |
|
378 | - $extra_data |
|
379 | - ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
380 | - |
|
381 | - $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
382 | - $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
383 | - $extra_data |
|
384 | - ) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
385 | - |
|
386 | - if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
387 | - return $parsed; |
|
388 | - } |
|
389 | - |
|
390 | - // now let's figure out which question has this text. |
|
391 | - foreach ($aee->questions as $ansid => $question) { |
|
392 | - if ($question instanceof EE_Question |
|
393 | - && trim($question->display_text()) == trim($shortcode) |
|
394 | - && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]) |
|
395 | - ) { |
|
396 | - return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty( |
|
397 | - 'ANS_value', |
|
398 | - 'no_wpautop' |
|
399 | - ); |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - // nothing! |
|
404 | - return $parsed; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
410 | - * |
|
411 | - * @since 4.2 |
|
412 | - * |
|
413 | - * @param array $shortcodes array of shortcodes and |
|
414 | - * descriptions |
|
415 | - * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
416 | - * |
|
417 | - * @return array array of shortcodes and |
|
418 | - * descriptions |
|
419 | - */ |
|
420 | - public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
421 | - { |
|
422 | - $shortcodes['[DTT_NAME]'] = __( |
|
423 | - 'This will be parsed to the Title given for a Datetime', |
|
424 | - 'event_espresso' |
|
425 | - ); |
|
426 | - $shortcodes['[DTT_DESCRIPTION]'] = __( |
|
427 | - 'This will be parsed to the description for a Datetime', |
|
428 | - 'event_espresso' |
|
429 | - ); |
|
430 | - $shortcodes['[DTT_NAME_OR_DATES]'] = __( |
|
431 | - 'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
432 | - 'event_espresso' |
|
433 | - ); |
|
434 | - |
|
435 | - return $shortcodes; |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * Callback for additional shortcodes parser filter used for adding parser for new |
|
441 | - * Datetime shortcodes |
|
442 | - * |
|
443 | - * @since 4.2 |
|
444 | - * |
|
445 | - * @param string $parsed The finished parsed string for the given shortcode. |
|
446 | - * @param string $shortcode The shortcode being parsed. |
|
447 | - * @param object $data The incoming data object for the Shortcode Parser. |
|
448 | - * @param object $extra_data The incoming extra date object for the Shortcode |
|
449 | - * Parser. |
|
450 | - * @param EE_Datetime_Shortcodes $shortcode_parser |
|
451 | - * |
|
452 | - * @return string The new parsed string. |
|
453 | - */ |
|
454 | - public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
455 | - { |
|
456 | - |
|
457 | - if (! $data instanceof EE_Datetime) { |
|
458 | - return ''; // get out because we can only parse with the datetime object. |
|
459 | - } |
|
460 | - |
|
461 | - switch ($shortcode) { |
|
462 | - case '[DTT_NAME]': |
|
463 | - return $data->name(); |
|
464 | - break; |
|
465 | - case '[DTT_DESCRIPTION]': |
|
466 | - return $data->description(); |
|
467 | - break; |
|
468 | - case '[DTT_NAME_OR_DATES]': |
|
469 | - return $data->get_dtt_display_name(true); |
|
470 | - break; |
|
471 | - default: |
|
472 | - return $parsed; |
|
473 | - break; |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
479 | - { |
|
480 | - $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __( |
|
481 | - 'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
482 | - 'event_espresso' |
|
483 | - ); |
|
484 | - |
|
485 | - return $shortcodes; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
491 | - * |
|
492 | - * @param string $parsed The original parsed content for the shortcode |
|
493 | - * @param string $shortcode The shortcode being parsed |
|
494 | - * @param array $data The shortcode parser data array |
|
495 | - * @param array $extra_data The shortcode parser extra data array |
|
496 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
497 | - * |
|
498 | - * @return string |
|
499 | - */ |
|
500 | - public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
501 | - { |
|
502 | - |
|
503 | - if (array($data) && ! isset($data['data'])) { |
|
504 | - return $parsed; |
|
505 | - } |
|
506 | - |
|
507 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
508 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
509 | - |
|
510 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
511 | - return $parsed; |
|
512 | - } |
|
513 | - |
|
514 | - switch ($shortcode) { |
|
515 | - case '[RECIPIENT_QUESTION_LIST]': |
|
516 | - $att = $recipient->att_obj; |
|
517 | - $registrations_on_attendee = $att instanceof EE_Attendee |
|
518 | - ? $recipient->attendees[ $att->ID() ]['reg_objs'] |
|
519 | - : array(); |
|
520 | - $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
521 | - $answers = array(); |
|
522 | - |
|
523 | - $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
524 | - ? $data['template']['question_list'] |
|
525 | - : $extra_data['template']['question_list']; |
|
526 | - $valid_shortcodes = array('question'); |
|
527 | - |
|
528 | - // if the context is main_content then get all answers for all registrations on this attendee |
|
529 | - if ($data['data'] instanceof EE_Messages_Addressee) { |
|
530 | - foreach ($registrations_on_attendee as $reg) { |
|
531 | - if ($reg instanceof EE_Registration) { |
|
532 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
533 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
534 | - : array(); |
|
535 | - foreach ($anss as $ans) { |
|
536 | - if ($ans instanceof EE_Answer) { |
|
537 | - $answers[ $ans->ID() ] = $ans; |
|
538 | - } |
|
539 | - } |
|
540 | - } |
|
541 | - } |
|
542 | - } |
|
543 | - |
|
544 | - // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
545 | - if ($data['data'] instanceof EE_Event) { |
|
546 | - $event = $data['data']; |
|
547 | - foreach ($registrations_on_attendee as $reg) { |
|
548 | - if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
549 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
550 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
551 | - : array(); |
|
552 | - foreach ($anss as $ans) { |
|
553 | - if ($ans instanceof EE_Answer) { |
|
554 | - $answers[ $ans->ID() ] = $ans; |
|
555 | - } |
|
556 | - } |
|
557 | - } |
|
558 | - } |
|
559 | - } |
|
560 | - |
|
561 | - $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
562 | - |
|
563 | - // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
564 | - // object on it. |
|
565 | - if (! isset($extra_data['data'])) { |
|
566 | - $extra_data['data'] = $recipient; |
|
567 | - } |
|
568 | - |
|
569 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
570 | - $shortcode_parser, |
|
571 | - $questions, |
|
572 | - $answers, |
|
573 | - $template, |
|
574 | - $valid_shortcodes, |
|
575 | - $extra_data |
|
576 | - ); |
|
577 | - break; |
|
578 | - |
|
579 | - default: |
|
580 | - return $parsed; |
|
581 | - break; |
|
582 | - } |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
587 | - { |
|
588 | - $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __( |
|
589 | - 'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
590 | - 'event_espresso' |
|
591 | - ); |
|
592 | - |
|
593 | - return $shortcodes; |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
599 | - * |
|
600 | - * @param string $parsed The original parsed content for the shortcode |
|
601 | - * @param string $shortcode The shortcode being parsed |
|
602 | - * @param array $data The shortcode parser data array |
|
603 | - * @param array $extra_data The shortcode parser extra data array |
|
604 | - * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
605 | - * |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public function additional_primary_registration_details_parser( |
|
609 | - $parsed, |
|
610 | - $shortcode, |
|
611 | - $data, |
|
612 | - $extra_data, |
|
613 | - $shortcode_parser |
|
614 | - ) { |
|
615 | - if (array($data) && ! isset($data['data'])) { |
|
616 | - return $parsed; |
|
617 | - } |
|
618 | - |
|
619 | - $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
620 | - $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
621 | - |
|
622 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
623 | - return $parsed; |
|
624 | - } |
|
625 | - |
|
626 | - switch ($shortcode) { |
|
627 | - case '[PRIMARY_REGISTRANT_QUESTION_LIST]': |
|
628 | - if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
629 | - return ''; |
|
630 | - } |
|
631 | - $registration = $recipient->primary_reg_obj; |
|
632 | - $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs']) |
|
633 | - ? $recipient->registrations[ $registration->ID() ]['ans_objs'] |
|
634 | - : array(); |
|
635 | - if (empty($answers)) { |
|
636 | - return ''; |
|
637 | - } |
|
638 | - $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
639 | - ? $data['template']['question_list'] |
|
640 | - : $extra_data['template']['question_list']; |
|
641 | - $valid_shortcodes = array('question'); |
|
642 | - $answers = $recipient->registrations[ $registration->ID() ]['ans_objs']; |
|
643 | - $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
644 | - // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
645 | - // object on it. |
|
646 | - if (! isset($extra_data['data'])) { |
|
647 | - $extra_data['data'] = $recipient; |
|
648 | - } |
|
649 | - return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
650 | - $shortcode_parser, |
|
651 | - $questions, |
|
652 | - $answers, |
|
653 | - $template, |
|
654 | - $valid_shortcodes, |
|
655 | - $extra_data |
|
656 | - ); |
|
657 | - break; |
|
658 | - |
|
659 | - default: |
|
660 | - return $parsed; |
|
661 | - break; |
|
662 | - } |
|
663 | - } |
|
664 | - |
|
665 | - |
|
666 | - /** |
|
667 | - * Takes care of registering the message types that are only available in caffeinated EE. |
|
668 | - * |
|
669 | - * @since 4.3.2 |
|
670 | - * |
|
671 | - * @return void |
|
672 | - */ |
|
673 | - public function register_caf_message_types() |
|
674 | - { |
|
675 | - // register newsletter message type |
|
676 | - $setup_args = array( |
|
677 | - 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
678 | - 'autoloadpaths' => array( |
|
679 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/', |
|
680 | - ), |
|
681 | - 'messengers_to_activate_with' => array('email'), |
|
682 | - 'messengers_to_validate_with' => array('email'), |
|
683 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
684 | - ); |
|
685 | - EE_Register_Message_Type::register('newsletter', $setup_args); |
|
686 | - |
|
687 | - // register payment reminder message type |
|
688 | - $setup_args = array( |
|
689 | - 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
690 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
691 | - 'messengers_to_activate_with' => array('email'), |
|
692 | - 'messengers_to_validate_with' => array('email'), |
|
693 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
694 | - ); |
|
695 | - EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
696 | - |
|
697 | - // register payment declined message type |
|
698 | - $setup_args = array( |
|
699 | - 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
700 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
701 | - 'messengers_to_activate_with' => array('email'), |
|
702 | - 'messengers_to_validate_with' => array('email'), |
|
703 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
704 | - ); |
|
705 | - EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
706 | - |
|
707 | - // register registration declined message type |
|
708 | - $setup_args = array( |
|
709 | - 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
710 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
711 | - 'messengers_to_activate_with' => array('email'), |
|
712 | - 'messengers_to_validate_with' => array('email'), |
|
713 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
714 | - ); |
|
715 | - EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
716 | - |
|
717 | - // register registration cancelled message type |
|
718 | - $setup_args = array( |
|
719 | - 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
720 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
721 | - 'messengers_to_activate_with' => array('email'), |
|
722 | - 'messengers_to_validate_with' => array('email'), |
|
723 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
724 | - ); |
|
725 | - EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
726 | - |
|
727 | - |
|
728 | - // register payment failed message type |
|
729 | - $setup_args = array( |
|
730 | - 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
731 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
732 | - 'messengers_to_activate_with' => array('email'), |
|
733 | - 'messengers_to_validate_with' => array('email'), |
|
734 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
735 | - ); |
|
736 | - EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
737 | - |
|
738 | - // register payment declined message type |
|
739 | - $setup_args = array( |
|
740 | - 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
741 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
742 | - 'messengers_to_activate_with' => array('email'), |
|
743 | - 'messengers_to_validate_with' => array('email'), |
|
744 | - 'messengers_supporting_default_template_pack_with' => array('email'), |
|
745 | - ); |
|
746 | - EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
752 | - * |
|
753 | - * @since 4.3.2 |
|
754 | - * |
|
755 | - * @return void |
|
756 | - */ |
|
757 | - public function register_caf_shortcodes() |
|
758 | - { |
|
759 | - $setup_args = array( |
|
760 | - 'autoloadpaths' => array( |
|
761 | - EE_CAF_LIBRARIES . 'shortcodes/', |
|
762 | - ), |
|
763 | - 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
764 | - 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
765 | - 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]'), |
|
766 | - ); |
|
767 | - EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * Parses a question list shortcode using given data and template |
|
773 | - * |
|
774 | - * @param \EE_Shortcodes $shortcode_parser |
|
775 | - * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
776 | - * @param EE_Answer[] $answers An array of answer objects |
|
777 | - * @param string $template Template content to be parsed. |
|
778 | - * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
779 | - * @param array $extra_data Extra data that might be used when parsing the template. |
|
780 | - */ |
|
781 | - protected function _parse_question_list_for_primary_or_recipient_registration( |
|
782 | - $shortcode_parser, |
|
783 | - $questions, |
|
784 | - $answers, |
|
785 | - $template, |
|
786 | - $valid_shortcodes, |
|
787 | - $extra_data |
|
788 | - ) { |
|
789 | - $question_list = ''; |
|
790 | - /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
791 | - $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
792 | - foreach ($answers as $answer) { |
|
793 | - if ($answer instanceof EE_Answer) { |
|
794 | - // first see if the question is in our $questions array. If not then try to get from answer object. |
|
795 | - $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null; |
|
796 | - $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
797 | - if (! $question instanceof EE_Question |
|
798 | - || ( |
|
799 | - $question instanceof EE_Question |
|
800 | - && $question->admin_only() |
|
801 | - ) |
|
802 | - ) { |
|
803 | - continue; |
|
804 | - } |
|
805 | - $question_list .= $shortcode_helper->parse_question_list_template( |
|
806 | - $template, |
|
807 | - $answer, |
|
808 | - $valid_shortcodes, |
|
809 | - $extra_data |
|
810 | - ); |
|
811 | - } |
|
812 | - } |
|
813 | - return $question_list; |
|
814 | - } |
|
16 | + /** |
|
17 | + * constructor. |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->_caf_hooks(); |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Contains all the hooks filters for setting up caffeinated messages functionality. |
|
27 | + * |
|
28 | + * @since 4.3.2 |
|
29 | + * |
|
30 | + * @return void |
|
31 | + */ |
|
32 | + private function _caf_hooks() |
|
33 | + { |
|
34 | + add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5); |
|
35 | + add_filter( |
|
36 | + 'FHEE__EE_Email_messenger__get_validator_config', |
|
37 | + array($this, 'email_messenger_validator_config'), |
|
38 | + 5, |
|
39 | + 2 |
|
40 | + ); |
|
41 | + add_filter( |
|
42 | + 'FHEE__EE_Email_messenger__get_template_fields', |
|
43 | + array($this, 'email_messenger_template_fields'), |
|
44 | + 5, |
|
45 | + 2 |
|
46 | + ); |
|
47 | + add_filter( |
|
48 | + 'FHEE__EE_Html_messenger__get_template_fields', |
|
49 | + array($this, 'html_messenger_template_fields'), |
|
50 | + 5, |
|
51 | + 2 |
|
52 | + ); |
|
53 | + add_filter( |
|
54 | + 'FHEE__EE_Html_messenger__get_validator_config', |
|
55 | + array($this, 'html_messenger_validator_config'), |
|
56 | + 5, |
|
57 | + 2 |
|
58 | + ); |
|
59 | + add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2); |
|
60 | + add_filter( |
|
61 | + 'FHEE__EE_Pdf_messenger__get_validator_config', |
|
62 | + array($this, 'pdf_messenger_validator_config'), |
|
63 | + 5, |
|
64 | + 2 |
|
65 | + ); |
|
66 | + add_filter( |
|
67 | + 'FHEE__EE_Messages_Template_Pack__get_specific_template__contents', |
|
68 | + array($this, 'new_default_templates'), |
|
69 | + 5, |
|
70 | + 7 |
|
71 | + ); |
|
72 | + add_filter( |
|
73 | + 'FHEE__EE_Messages_Base__get_valid_shortcodes', |
|
74 | + array($this, 'message_types_valid_shortcodes'), |
|
75 | + 5, |
|
76 | + 2 |
|
77 | + ); |
|
78 | + |
|
79 | + // shortcode parsers |
|
80 | + add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2); |
|
81 | + add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5); |
|
82 | + add_filter( |
|
83 | + 'FHEE__EE_Recipient_List_Shortcodes__shortcodes', |
|
84 | + array($this, 'additional_recipient_details_shortcodes'), |
|
85 | + 5, |
|
86 | + 2 |
|
87 | + ); |
|
88 | + add_filter( |
|
89 | + 'FHEE__EE_Recipient_List_Shortcodes__parser_after', |
|
90 | + array($this, 'additional_recipient_details_parser'), |
|
91 | + 5, |
|
92 | + 5 |
|
93 | + ); |
|
94 | + add_filter( |
|
95 | + 'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes', |
|
96 | + array($this, 'additional_primary_registration_details_shortcodes'), |
|
97 | + 5, |
|
98 | + 2 |
|
99 | + ); |
|
100 | + add_filter( |
|
101 | + 'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after', |
|
102 | + array($this, 'additional_primary_registration_details_parser'), |
|
103 | + 5, |
|
104 | + 5 |
|
105 | + ); |
|
106 | + |
|
107 | + /** |
|
108 | + * @since 4.2.0 |
|
109 | + */ |
|
110 | + add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2); |
|
111 | + add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5); |
|
112 | + |
|
113 | + /** |
|
114 | + * @since 4.3.0 |
|
115 | + */ |
|
116 | + // eat our own dog food! |
|
117 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types')); |
|
118 | + add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes')); |
|
119 | + do_action('EE_Brewing_Regular___messages_caf'); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the |
|
125 | + * messages system. |
|
126 | + * |
|
127 | + * @param array $dir_ref original array of paths |
|
128 | + * |
|
129 | + * @return array appended paths |
|
130 | + */ |
|
131 | + public function messages_autoload_paths($dir_ref) |
|
132 | + { |
|
133 | + $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
134 | + |
|
135 | + return $dir_ref; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger) |
|
140 | + { |
|
141 | + $validator_config['attendee_list'] = array( |
|
142 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
143 | + 'required' => array('[ATTENDEE_LIST]'), |
|
144 | + ); |
|
145 | + $validator_config['question_list'] = array( |
|
146 | + 'shortcodes' => array('question'), |
|
147 | + 'required' => array('[QUESTION_LIST]'), |
|
148 | + ); |
|
149 | + |
|
150 | + return $validator_config; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger) |
|
155 | + { |
|
156 | + $validator_config['attendee_list'] = array( |
|
157 | + 'shortcodes' => array('attendee', 'question_list'), |
|
158 | + 'required' => array('[ATTENDEE_LIST]'), |
|
159 | + ); |
|
160 | + $validator_config['question_list'] = array( |
|
161 | + 'shortcodes' => array('question'), |
|
162 | + 'required' => array('[QUESTION_LIST]'), |
|
163 | + ); |
|
164 | + |
|
165 | + return $validator_config; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger) |
|
170 | + { |
|
171 | + $validator_config['attendee_list'] = array( |
|
172 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'), |
|
173 | + 'required' => array('[ATTENDEE_LIST]'), |
|
174 | + ); |
|
175 | + $validator_config['question_list'] = array( |
|
176 | + 'shortcodes' => array('question'), |
|
177 | + 'required' => array('[QUESTION_LIST]'), |
|
178 | + ); |
|
179 | + |
|
180 | + return $validator_config; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger) |
|
185 | + { |
|
186 | + $template_fields['extra']['content']['question_list'] = array( |
|
187 | + 'input' => 'textarea', |
|
188 | + 'label' => '[QUESTION_LIST]', |
|
189 | + 'type' => 'string', |
|
190 | + 'required' => true, |
|
191 | + 'validation' => true, |
|
192 | + 'format' => '%s', |
|
193 | + 'css_class' => 'large-text', |
|
194 | + 'rows' => '5', |
|
195 | + 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
196 | + ); |
|
197 | + |
|
198 | + return $template_fields; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger) |
|
203 | + { |
|
204 | + $template_fields['extra']['content']['question_list'] = array( |
|
205 | + 'input' => 'textarea', |
|
206 | + 'label' => '[QUESTION_LIST]', |
|
207 | + 'type' => 'string', |
|
208 | + 'required' => true, |
|
209 | + 'validation' => true, |
|
210 | + 'format' => '%s', |
|
211 | + 'css_class' => 'large-text', |
|
212 | + 'rows' => '5', |
|
213 | + 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
214 | + ); |
|
215 | + |
|
216 | + return $template_fields; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger) |
|
221 | + { |
|
222 | + $template_fields['extra']['content']['question_list'] = array( |
|
223 | + 'input' => 'textarea', |
|
224 | + 'label' => '[QUESTION_LIST]', |
|
225 | + 'type' => 'string', |
|
226 | + 'required' => true, |
|
227 | + 'validation' => true, |
|
228 | + 'format' => '%s', |
|
229 | + 'css_class' => 'large-text', |
|
230 | + 'rows' => '5', |
|
231 | + 'shortcodes_required' => array('[QUESTION_LIST]'), |
|
232 | + ); |
|
233 | + |
|
234 | + return $template_fields; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + public function new_default_templates( |
|
239 | + $contents, |
|
240 | + $actual_path, |
|
241 | + EE_messenger $messenger, |
|
242 | + EE_message_type $message_type, |
|
243 | + $field, |
|
244 | + $context, |
|
245 | + EE_Messages_Template_Pack $template_pack |
|
246 | + ) { |
|
247 | + |
|
248 | + // we're only modifying templates for the default template pack |
|
249 | + if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
250 | + return $contents; |
|
251 | + } |
|
252 | + |
|
253 | + // the template file name we're replacing contents for. |
|
254 | + $template_file_prefix = $field . '_' . $context; |
|
255 | + $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
256 | + |
|
257 | + $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
258 | + |
|
259 | + if ($messenger->name == 'email' && $message_type->name == 'registration') { |
|
260 | + switch ($template_file_prefix) { |
|
261 | + case 'question_list_admin': |
|
262 | + case 'question_list_attendee': |
|
263 | + case 'question_list_primary_attendee': |
|
264 | + $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
265 | + $contents = EEH_Template::display_template($path, array(), true); |
|
266 | + break; |
|
267 | + |
|
268 | + case 'attendee_list_primary_attendee': |
|
269 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
270 | + $contents = EEH_Template::display_template($path, array(), true); |
|
271 | + break; |
|
272 | + |
|
273 | + case 'attendee_list_admin': |
|
274 | + $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
275 | + $contents = EEH_Template::display_template( |
|
276 | + $path, |
|
277 | + array(), |
|
278 | + true |
|
279 | + ); |
|
280 | + break; |
|
281 | + |
|
282 | + case 'attendee_list_attendee': |
|
283 | + $contents = ''; |
|
284 | + break; |
|
285 | + |
|
286 | + case 'event_list_attendee': |
|
287 | + $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
288 | + $contents = EEH_Template::display_template($path, array(), true); |
|
289 | + break; |
|
290 | + } |
|
291 | + } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
|
292 | + switch ($template_file_prefix) { |
|
293 | + case 'content_attendee': |
|
294 | + $path = $base_path . $msg_prefix . 'content.template.php'; |
|
295 | + $contents = EEH_Template::display_template($path, array(), true); |
|
296 | + break; |
|
297 | + |
|
298 | + case 'newsletter_content_attendee': |
|
299 | + $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
300 | + $contents = EEH_Template::display_template($path, array(), true); |
|
301 | + break; |
|
302 | + |
|
303 | + case 'newsletter_subject_attendee': |
|
304 | + $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
305 | + $contents = EEH_Template::display_template($path, array(), true); |
|
306 | + break; |
|
307 | + } |
|
308 | + } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
|
309 | + switch ($template_file_prefix) { |
|
310 | + case 'attendee_list_purchaser': |
|
311 | + $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
312 | + $contents = EEH_Template::display_template($path, array(), true); |
|
313 | + break; |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + return $contents; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg) |
|
322 | + { |
|
323 | + // make sure question_list and question are ONLY added for the core message types. Any other message types will have to explicitly set question_list as a valid shortcode. |
|
324 | + $include_with = array( |
|
325 | + 'registration', |
|
326 | + 'cancelled_registration', |
|
327 | + 'declined_registration', |
|
328 | + 'not_approved_registration', |
|
329 | + 'payment_declined', |
|
330 | + 'payment_failed', |
|
331 | + 'payment_cancelled', |
|
332 | + 'payment', |
|
333 | + 'payment_reminder', |
|
334 | + 'pending_approval', |
|
335 | + 'registration_summary', |
|
336 | + 'invoice', |
|
337 | + 'receipt', |
|
338 | + ); |
|
339 | + if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
|
340 | + $contexts = array_keys($msg->get_contexts()); |
|
341 | + foreach ($contexts as $context) { |
|
342 | + $valid_shortcodes[ $context ][] = 'question_list'; |
|
343 | + $valid_shortcodes[ $context ][] = 'question'; |
|
344 | + } |
|
345 | + } |
|
346 | + |
|
347 | + return $valid_shortcodes; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + public function additional_attendee_shortcodes($shortcodes, $shortcode_parser) |
|
352 | + { |
|
353 | + $shortcodes['[ANSWER_*]'] = __( |
|
354 | + 'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.', |
|
355 | + 'event_espresso' |
|
356 | + ); |
|
357 | + |
|
358 | + return $shortcodes; |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
363 | + { |
|
364 | + |
|
365 | + if (strpos($shortcode, '[ANSWER_*') === false |
|
366 | + || ! isset($extra_data['data']->questions) |
|
367 | + || ! isset($extra_data['data']->registrations) |
|
368 | + ) { |
|
369 | + return $parsed; |
|
370 | + } |
|
371 | + |
|
372 | + // let's get the question from the code. |
|
373 | + $shortcode = str_replace('[ANSWER_*', '', $shortcode); |
|
374 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
375 | + |
|
376 | + $registration = $data instanceof EE_Registration ? $data : null; |
|
377 | + $registration = ! $registration instanceof EE_Registration && is_array( |
|
378 | + $extra_data |
|
379 | + ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration; |
|
380 | + |
|
381 | + $aee = $data instanceof EE_Messages_Addressee ? $data : null; |
|
382 | + $aee = ! $aee instanceof EE_Messages_Addressee && is_array( |
|
383 | + $extra_data |
|
384 | + ) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
|
385 | + |
|
386 | + if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
387 | + return $parsed; |
|
388 | + } |
|
389 | + |
|
390 | + // now let's figure out which question has this text. |
|
391 | + foreach ($aee->questions as $ansid => $question) { |
|
392 | + if ($question instanceof EE_Question |
|
393 | + && trim($question->display_text()) == trim($shortcode) |
|
394 | + && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]) |
|
395 | + ) { |
|
396 | + return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty( |
|
397 | + 'ANS_value', |
|
398 | + 'no_wpautop' |
|
399 | + ); |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + // nothing! |
|
404 | + return $parsed; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Callback for additional shortcodes filter for adding additional datetime shortcodes. |
|
410 | + * |
|
411 | + * @since 4.2 |
|
412 | + * |
|
413 | + * @param array $shortcodes array of shortcodes and |
|
414 | + * descriptions |
|
415 | + * @param EE_Datetime_Shortcodes $shortcode_parser EE_Shortcodes object |
|
416 | + * |
|
417 | + * @return array array of shortcodes and |
|
418 | + * descriptions |
|
419 | + */ |
|
420 | + public function additional_datetime_shortcodes($shortcodes, $shortcode_parser) |
|
421 | + { |
|
422 | + $shortcodes['[DTT_NAME]'] = __( |
|
423 | + 'This will be parsed to the Title given for a Datetime', |
|
424 | + 'event_espresso' |
|
425 | + ); |
|
426 | + $shortcodes['[DTT_DESCRIPTION]'] = __( |
|
427 | + 'This will be parsed to the description for a Datetime', |
|
428 | + 'event_espresso' |
|
429 | + ); |
|
430 | + $shortcodes['[DTT_NAME_OR_DATES]'] = __( |
|
431 | + 'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.', |
|
432 | + 'event_espresso' |
|
433 | + ); |
|
434 | + |
|
435 | + return $shortcodes; |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * Callback for additional shortcodes parser filter used for adding parser for new |
|
441 | + * Datetime shortcodes |
|
442 | + * |
|
443 | + * @since 4.2 |
|
444 | + * |
|
445 | + * @param string $parsed The finished parsed string for the given shortcode. |
|
446 | + * @param string $shortcode The shortcode being parsed. |
|
447 | + * @param object $data The incoming data object for the Shortcode Parser. |
|
448 | + * @param object $extra_data The incoming extra date object for the Shortcode |
|
449 | + * Parser. |
|
450 | + * @param EE_Datetime_Shortcodes $shortcode_parser |
|
451 | + * |
|
452 | + * @return string The new parsed string. |
|
453 | + */ |
|
454 | + public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
455 | + { |
|
456 | + |
|
457 | + if (! $data instanceof EE_Datetime) { |
|
458 | + return ''; // get out because we can only parse with the datetime object. |
|
459 | + } |
|
460 | + |
|
461 | + switch ($shortcode) { |
|
462 | + case '[DTT_NAME]': |
|
463 | + return $data->name(); |
|
464 | + break; |
|
465 | + case '[DTT_DESCRIPTION]': |
|
466 | + return $data->description(); |
|
467 | + break; |
|
468 | + case '[DTT_NAME_OR_DATES]': |
|
469 | + return $data->get_dtt_display_name(true); |
|
470 | + break; |
|
471 | + default: |
|
472 | + return $parsed; |
|
473 | + break; |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser) |
|
479 | + { |
|
480 | + $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __( |
|
481 | + 'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.', |
|
482 | + 'event_espresso' |
|
483 | + ); |
|
484 | + |
|
485 | + return $shortcodes; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter). |
|
491 | + * |
|
492 | + * @param string $parsed The original parsed content for the shortcode |
|
493 | + * @param string $shortcode The shortcode being parsed |
|
494 | + * @param array $data The shortcode parser data array |
|
495 | + * @param array $extra_data The shortcode parser extra data array |
|
496 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
497 | + * |
|
498 | + * @return string |
|
499 | + */ |
|
500 | + public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
|
501 | + { |
|
502 | + |
|
503 | + if (array($data) && ! isset($data['data'])) { |
|
504 | + return $parsed; |
|
505 | + } |
|
506 | + |
|
507 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
508 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
509 | + |
|
510 | + if (! $recipient instanceof EE_Messages_Addressee) { |
|
511 | + return $parsed; |
|
512 | + } |
|
513 | + |
|
514 | + switch ($shortcode) { |
|
515 | + case '[RECIPIENT_QUESTION_LIST]': |
|
516 | + $att = $recipient->att_obj; |
|
517 | + $registrations_on_attendee = $att instanceof EE_Attendee |
|
518 | + ? $recipient->attendees[ $att->ID() ]['reg_objs'] |
|
519 | + : array(); |
|
520 | + $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
|
521 | + $answers = array(); |
|
522 | + |
|
523 | + $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
524 | + ? $data['template']['question_list'] |
|
525 | + : $extra_data['template']['question_list']; |
|
526 | + $valid_shortcodes = array('question'); |
|
527 | + |
|
528 | + // if the context is main_content then get all answers for all registrations on this attendee |
|
529 | + if ($data['data'] instanceof EE_Messages_Addressee) { |
|
530 | + foreach ($registrations_on_attendee as $reg) { |
|
531 | + if ($reg instanceof EE_Registration) { |
|
532 | + $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
533 | + ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
534 | + : array(); |
|
535 | + foreach ($anss as $ans) { |
|
536 | + if ($ans instanceof EE_Answer) { |
|
537 | + $answers[ $ans->ID() ] = $ans; |
|
538 | + } |
|
539 | + } |
|
540 | + } |
|
541 | + } |
|
542 | + } |
|
543 | + |
|
544 | + // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event. |
|
545 | + if ($data['data'] instanceof EE_Event) { |
|
546 | + $event = $data['data']; |
|
547 | + foreach ($registrations_on_attendee as $reg) { |
|
548 | + if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
|
549 | + $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
550 | + ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
551 | + : array(); |
|
552 | + foreach ($anss as $ans) { |
|
553 | + if ($ans instanceof EE_Answer) { |
|
554 | + $answers[ $ans->ID() ] = $ans; |
|
555 | + } |
|
556 | + } |
|
557 | + } |
|
558 | + } |
|
559 | + } |
|
560 | + |
|
561 | + $questions = $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
562 | + |
|
563 | + // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
564 | + // object on it. |
|
565 | + if (! isset($extra_data['data'])) { |
|
566 | + $extra_data['data'] = $recipient; |
|
567 | + } |
|
568 | + |
|
569 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
570 | + $shortcode_parser, |
|
571 | + $questions, |
|
572 | + $answers, |
|
573 | + $template, |
|
574 | + $valid_shortcodes, |
|
575 | + $extra_data |
|
576 | + ); |
|
577 | + break; |
|
578 | + |
|
579 | + default: |
|
580 | + return $parsed; |
|
581 | + break; |
|
582 | + } |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser) |
|
587 | + { |
|
588 | + $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __( |
|
589 | + 'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field', |
|
590 | + 'event_espresso' |
|
591 | + ); |
|
592 | + |
|
593 | + return $shortcodes; |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter). |
|
599 | + * |
|
600 | + * @param string $parsed The original parsed content for the shortcode |
|
601 | + * @param string $shortcode The shortcode being parsed |
|
602 | + * @param array $data The shortcode parser data array |
|
603 | + * @param array $extra_data The shortcode parser extra data array |
|
604 | + * @param \EE_Shortcodes $shortcode_parser Shortcode parser. |
|
605 | + * |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public function additional_primary_registration_details_parser( |
|
609 | + $parsed, |
|
610 | + $shortcode, |
|
611 | + $data, |
|
612 | + $extra_data, |
|
613 | + $shortcode_parser |
|
614 | + ) { |
|
615 | + if (array($data) && ! isset($data['data'])) { |
|
616 | + return $parsed; |
|
617 | + } |
|
618 | + |
|
619 | + $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
|
620 | + $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
|
621 | + |
|
622 | + if (! $recipient instanceof EE_Messages_Addressee) { |
|
623 | + return $parsed; |
|
624 | + } |
|
625 | + |
|
626 | + switch ($shortcode) { |
|
627 | + case '[PRIMARY_REGISTRANT_QUESTION_LIST]': |
|
628 | + if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
629 | + return ''; |
|
630 | + } |
|
631 | + $registration = $recipient->primary_reg_obj; |
|
632 | + $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs']) |
|
633 | + ? $recipient->registrations[ $registration->ID() ]['ans_objs'] |
|
634 | + : array(); |
|
635 | + if (empty($answers)) { |
|
636 | + return ''; |
|
637 | + } |
|
638 | + $template = is_array($data['template']) && isset($data['template']['question_list']) |
|
639 | + ? $data['template']['question_list'] |
|
640 | + : $extra_data['template']['question_list']; |
|
641 | + $valid_shortcodes = array('question'); |
|
642 | + $answers = $recipient->registrations[ $registration->ID() ]['ans_objs']; |
|
643 | + $questions = isset($recipient->questions) ? $recipient->questions : array(); |
|
644 | + // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
|
645 | + // object on it. |
|
646 | + if (! isset($extra_data['data'])) { |
|
647 | + $extra_data['data'] = $recipient; |
|
648 | + } |
|
649 | + return $this->_parse_question_list_for_primary_or_recipient_registration( |
|
650 | + $shortcode_parser, |
|
651 | + $questions, |
|
652 | + $answers, |
|
653 | + $template, |
|
654 | + $valid_shortcodes, |
|
655 | + $extra_data |
|
656 | + ); |
|
657 | + break; |
|
658 | + |
|
659 | + default: |
|
660 | + return $parsed; |
|
661 | + break; |
|
662 | + } |
|
663 | + } |
|
664 | + |
|
665 | + |
|
666 | + /** |
|
667 | + * Takes care of registering the message types that are only available in caffeinated EE. |
|
668 | + * |
|
669 | + * @since 4.3.2 |
|
670 | + * |
|
671 | + * @return void |
|
672 | + */ |
|
673 | + public function register_caf_message_types() |
|
674 | + { |
|
675 | + // register newsletter message type |
|
676 | + $setup_args = array( |
|
677 | + 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
|
678 | + 'autoloadpaths' => array( |
|
679 | + EE_CAF_LIBRARIES . 'messages/message_type/newsletter/', |
|
680 | + ), |
|
681 | + 'messengers_to_activate_with' => array('email'), |
|
682 | + 'messengers_to_validate_with' => array('email'), |
|
683 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
684 | + ); |
|
685 | + EE_Register_Message_Type::register('newsletter', $setup_args); |
|
686 | + |
|
687 | + // register payment reminder message type |
|
688 | + $setup_args = array( |
|
689 | + 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
|
690 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
691 | + 'messengers_to_activate_with' => array('email'), |
|
692 | + 'messengers_to_validate_with' => array('email'), |
|
693 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
694 | + ); |
|
695 | + EE_Register_Message_Type::register('payment_reminder', $setup_args); |
|
696 | + |
|
697 | + // register payment declined message type |
|
698 | + $setup_args = array( |
|
699 | + 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
|
700 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
701 | + 'messengers_to_activate_with' => array('email'), |
|
702 | + 'messengers_to_validate_with' => array('email'), |
|
703 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
704 | + ); |
|
705 | + EE_Register_Message_Type::register('payment_declined', $setup_args); |
|
706 | + |
|
707 | + // register registration declined message type |
|
708 | + $setup_args = array( |
|
709 | + 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
|
710 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
711 | + 'messengers_to_activate_with' => array('email'), |
|
712 | + 'messengers_to_validate_with' => array('email'), |
|
713 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
714 | + ); |
|
715 | + EE_Register_Message_Type::register('declined_registration', $setup_args); |
|
716 | + |
|
717 | + // register registration cancelled message type |
|
718 | + $setup_args = array( |
|
719 | + 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
|
720 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
721 | + 'messengers_to_activate_with' => array('email'), |
|
722 | + 'messengers_to_validate_with' => array('email'), |
|
723 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
724 | + ); |
|
725 | + EE_Register_Message_Type::register('cancelled_registration', $setup_args); |
|
726 | + |
|
727 | + |
|
728 | + // register payment failed message type |
|
729 | + $setup_args = array( |
|
730 | + 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
|
731 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
732 | + 'messengers_to_activate_with' => array('email'), |
|
733 | + 'messengers_to_validate_with' => array('email'), |
|
734 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
735 | + ); |
|
736 | + EE_Register_Message_Type::register('payment_failed', $setup_args); |
|
737 | + |
|
738 | + // register payment declined message type |
|
739 | + $setup_args = array( |
|
740 | + 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
|
741 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
742 | + 'messengers_to_activate_with' => array('email'), |
|
743 | + 'messengers_to_validate_with' => array('email'), |
|
744 | + 'messengers_supporting_default_template_pack_with' => array('email'), |
|
745 | + ); |
|
746 | + EE_Register_Message_Type::register('payment_cancelled', $setup_args); |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * Takes care of registering the shortcode libraries implemented with caffeinated EE and set up related items. |
|
752 | + * |
|
753 | + * @since 4.3.2 |
|
754 | + * |
|
755 | + * @return void |
|
756 | + */ |
|
757 | + public function register_caf_shortcodes() |
|
758 | + { |
|
759 | + $setup_args = array( |
|
760 | + 'autoloadpaths' => array( |
|
761 | + EE_CAF_LIBRARIES . 'shortcodes/', |
|
762 | + ), |
|
763 | + 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
|
764 | + 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
|
765 | + 'list_type_shortcodes' => array('[NEWSLETTER_CONTENT]'), |
|
766 | + ); |
|
767 | + EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args); |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * Parses a question list shortcode using given data and template |
|
773 | + * |
|
774 | + * @param \EE_Shortcodes $shortcode_parser |
|
775 | + * @param EE_Question[] $questions An array of questions indexed by answer id. |
|
776 | + * @param EE_Answer[] $answers An array of answer objects |
|
777 | + * @param string $template Template content to be parsed. |
|
778 | + * @param array $valid_shortcodes Valid shortcodes for the template being parsed. |
|
779 | + * @param array $extra_data Extra data that might be used when parsing the template. |
|
780 | + */ |
|
781 | + protected function _parse_question_list_for_primary_or_recipient_registration( |
|
782 | + $shortcode_parser, |
|
783 | + $questions, |
|
784 | + $answers, |
|
785 | + $template, |
|
786 | + $valid_shortcodes, |
|
787 | + $extra_data |
|
788 | + ) { |
|
789 | + $question_list = ''; |
|
790 | + /** @var EEH_Parse_Shortcodes $shortcode_helper */ |
|
791 | + $shortcode_helper = $shortcode_parser->get_shortcode_helper(); |
|
792 | + foreach ($answers as $answer) { |
|
793 | + if ($answer instanceof EE_Answer) { |
|
794 | + // first see if the question is in our $questions array. If not then try to get from answer object. |
|
795 | + $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null; |
|
796 | + $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
|
797 | + if (! $question instanceof EE_Question |
|
798 | + || ( |
|
799 | + $question instanceof EE_Question |
|
800 | + && $question->admin_only() |
|
801 | + ) |
|
802 | + ) { |
|
803 | + continue; |
|
804 | + } |
|
805 | + $question_list .= $shortcode_helper->parse_question_list_template( |
|
806 | + $template, |
|
807 | + $answer, |
|
808 | + $valid_shortcodes, |
|
809 | + $extra_data |
|
810 | + ); |
|
811 | + } |
|
812 | + } |
|
813 | + return $question_list; |
|
814 | + } |
|
815 | 815 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function messages_autoload_paths($dir_ref) |
132 | 132 | { |
133 | - $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/'; |
|
133 | + $dir_ref[] = EE_CAF_LIBRARIES.'shortcodes/'; |
|
134 | 134 | |
135 | 135 | return $dir_ref; |
136 | 136 | } |
@@ -246,32 +246,32 @@ discard block |
||
246 | 246 | ) { |
247 | 247 | |
248 | 248 | // we're only modifying templates for the default template pack |
249 | - if (! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
249 | + if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) { |
|
250 | 250 | return $contents; |
251 | 251 | } |
252 | 252 | |
253 | 253 | // the template file name we're replacing contents for. |
254 | - $template_file_prefix = $field . '_' . $context; |
|
255 | - $msg_prefix = $messenger->name . '_' . $message_type->name . '_'; |
|
254 | + $template_file_prefix = $field.'_'.$context; |
|
255 | + $msg_prefix = $messenger->name.'_'.$message_type->name.'_'; |
|
256 | 256 | |
257 | - $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/'; |
|
257 | + $base_path = EE_CAF_LIBRARIES.'messages/defaults/default/'; |
|
258 | 258 | |
259 | 259 | if ($messenger->name == 'email' && $message_type->name == 'registration') { |
260 | 260 | switch ($template_file_prefix) { |
261 | 261 | case 'question_list_admin': |
262 | 262 | case 'question_list_attendee': |
263 | 263 | case 'question_list_primary_attendee': |
264 | - $path = $base_path . $msg_prefix . 'question_list.template.php'; |
|
264 | + $path = $base_path.$msg_prefix.'question_list.template.php'; |
|
265 | 265 | $contents = EEH_Template::display_template($path, array(), true); |
266 | 266 | break; |
267 | 267 | |
268 | 268 | case 'attendee_list_primary_attendee': |
269 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
269 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
270 | 270 | $contents = EEH_Template::display_template($path, array(), true); |
271 | 271 | break; |
272 | 272 | |
273 | 273 | case 'attendee_list_admin': |
274 | - $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php'; |
|
274 | + $path = $base_path.$msg_prefix.'attendee_list_admin.template.php'; |
|
275 | 275 | $contents = EEH_Template::display_template( |
276 | 276 | $path, |
277 | 277 | array(), |
@@ -284,31 +284,31 @@ discard block |
||
284 | 284 | break; |
285 | 285 | |
286 | 286 | case 'event_list_attendee': |
287 | - $path = $base_path . $msg_prefix . 'event_list_attendee.template.php'; |
|
287 | + $path = $base_path.$msg_prefix.'event_list_attendee.template.php'; |
|
288 | 288 | $contents = EEH_Template::display_template($path, array(), true); |
289 | 289 | break; |
290 | 290 | } |
291 | 291 | } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') { |
292 | 292 | switch ($template_file_prefix) { |
293 | 293 | case 'content_attendee': |
294 | - $path = $base_path . $msg_prefix . 'content.template.php'; |
|
294 | + $path = $base_path.$msg_prefix.'content.template.php'; |
|
295 | 295 | $contents = EEH_Template::display_template($path, array(), true); |
296 | 296 | break; |
297 | 297 | |
298 | 298 | case 'newsletter_content_attendee': |
299 | - $path = $base_path . $msg_prefix . 'newsletter_content.template.php'; |
|
299 | + $path = $base_path.$msg_prefix.'newsletter_content.template.php'; |
|
300 | 300 | $contents = EEH_Template::display_template($path, array(), true); |
301 | 301 | break; |
302 | 302 | |
303 | 303 | case 'newsletter_subject_attendee': |
304 | - $path = $base_path . $msg_prefix . 'subject.template.php'; |
|
304 | + $path = $base_path.$msg_prefix.'subject.template.php'; |
|
305 | 305 | $contents = EEH_Template::display_template($path, array(), true); |
306 | 306 | break; |
307 | 307 | } |
308 | 308 | } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') { |
309 | 309 | switch ($template_file_prefix) { |
310 | 310 | case 'attendee_list_purchaser': |
311 | - $path = $base_path . $msg_prefix . 'attendee_list.template.php'; |
|
311 | + $path = $base_path.$msg_prefix.'attendee_list.template.php'; |
|
312 | 312 | $contents = EEH_Template::display_template($path, array(), true); |
313 | 313 | break; |
314 | 314 | } |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) { |
340 | 340 | $contexts = array_keys($msg->get_contexts()); |
341 | 341 | foreach ($contexts as $context) { |
342 | - $valid_shortcodes[ $context ][] = 'question_list'; |
|
343 | - $valid_shortcodes[ $context ][] = 'question'; |
|
342 | + $valid_shortcodes[$context][] = 'question_list'; |
|
343 | + $valid_shortcodes[$context][] = 'question'; |
|
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | $extra_data |
384 | 384 | ) && isset($extra_data['data']) ? $extra_data['data'] : $aee; |
385 | 385 | |
386 | - if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
386 | + if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) { |
|
387 | 387 | return $parsed; |
388 | 388 | } |
389 | 389 | |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | foreach ($aee->questions as $ansid => $question) { |
392 | 392 | if ($question instanceof EE_Question |
393 | 393 | && trim($question->display_text()) == trim($shortcode) |
394 | - && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]) |
|
394 | + && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid]) |
|
395 | 395 | ) { |
396 | - return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty( |
|
396 | + return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty( |
|
397 | 397 | 'ANS_value', |
398 | 398 | 'no_wpautop' |
399 | 399 | ); |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser) |
455 | 455 | { |
456 | 456 | |
457 | - if (! $data instanceof EE_Datetime) { |
|
457 | + if ( ! $data instanceof EE_Datetime) { |
|
458 | 458 | return ''; // get out because we can only parse with the datetime object. |
459 | 459 | } |
460 | 460 | |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
508 | 508 | $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
509 | 509 | |
510 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
510 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
511 | 511 | return $parsed; |
512 | 512 | } |
513 | 513 | |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | case '[RECIPIENT_QUESTION_LIST]': |
516 | 516 | $att = $recipient->att_obj; |
517 | 517 | $registrations_on_attendee = $att instanceof EE_Attendee |
518 | - ? $recipient->attendees[ $att->ID() ]['reg_objs'] |
|
518 | + ? $recipient->attendees[$att->ID()]['reg_objs'] |
|
519 | 519 | : array(); |
520 | 520 | $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee; |
521 | 521 | $answers = array(); |
@@ -529,12 +529,12 @@ discard block |
||
529 | 529 | if ($data['data'] instanceof EE_Messages_Addressee) { |
530 | 530 | foreach ($registrations_on_attendee as $reg) { |
531 | 531 | if ($reg instanceof EE_Registration) { |
532 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
533 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
532 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) |
|
533 | + ? $recipient->registrations[$reg->ID()]['ans_objs'] |
|
534 | 534 | : array(); |
535 | 535 | foreach ($anss as $ans) { |
536 | 536 | if ($ans instanceof EE_Answer) { |
537 | - $answers[ $ans->ID() ] = $ans; |
|
537 | + $answers[$ans->ID()] = $ans; |
|
538 | 538 | } |
539 | 539 | } |
540 | 540 | } |
@@ -546,12 +546,12 @@ discard block |
||
546 | 546 | $event = $data['data']; |
547 | 547 | foreach ($registrations_on_attendee as $reg) { |
548 | 548 | if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) { |
549 | - $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs']) |
|
550 | - ? $recipient->registrations[ $reg->ID() ]['ans_objs'] |
|
549 | + $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs']) |
|
550 | + ? $recipient->registrations[$reg->ID()]['ans_objs'] |
|
551 | 551 | : array(); |
552 | 552 | foreach ($anss as $ans) { |
553 | 553 | if ($ans instanceof EE_Answer) { |
554 | - $answers[ $ans->ID() ] = $ans; |
|
554 | + $answers[$ans->ID()] = $ans; |
|
555 | 555 | } |
556 | 556 | } |
557 | 557 | } |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | |
563 | 563 | // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
564 | 564 | // object on it. |
565 | - if (! isset($extra_data['data'])) { |
|
565 | + if ( ! isset($extra_data['data'])) { |
|
566 | 566 | $extra_data['data'] = $recipient; |
567 | 567 | } |
568 | 568 | |
@@ -619,18 +619,18 @@ discard block |
||
619 | 619 | $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null; |
620 | 620 | $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient; |
621 | 621 | |
622 | - if (! $recipient instanceof EE_Messages_Addressee) { |
|
622 | + if ( ! $recipient instanceof EE_Messages_Addressee) { |
|
623 | 623 | return $parsed; |
624 | 624 | } |
625 | 625 | |
626 | 626 | switch ($shortcode) { |
627 | 627 | case '[PRIMARY_REGISTRANT_QUESTION_LIST]': |
628 | - if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
628 | + if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) { |
|
629 | 629 | return ''; |
630 | 630 | } |
631 | 631 | $registration = $recipient->primary_reg_obj; |
632 | - $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs']) |
|
633 | - ? $recipient->registrations[ $registration->ID() ]['ans_objs'] |
|
632 | + $answers = isset($recipient->registrations[$registration->ID()]['ans_objs']) |
|
633 | + ? $recipient->registrations[$registration->ID()]['ans_objs'] |
|
634 | 634 | : array(); |
635 | 635 | if (empty($answers)) { |
636 | 636 | return ''; |
@@ -639,11 +639,11 @@ discard block |
||
639 | 639 | ? $data['template']['question_list'] |
640 | 640 | : $extra_data['template']['question_list']; |
641 | 641 | $valid_shortcodes = array('question'); |
642 | - $answers = $recipient->registrations[ $registration->ID() ]['ans_objs']; |
|
642 | + $answers = $recipient->registrations[$registration->ID()]['ans_objs']; |
|
643 | 643 | $questions = isset($recipient->questions) ? $recipient->questions : array(); |
644 | 644 | // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee |
645 | 645 | // object on it. |
646 | - if (! isset($extra_data['data'])) { |
|
646 | + if ( ! isset($extra_data['data'])) { |
|
647 | 647 | $extra_data['data'] = $recipient; |
648 | 648 | } |
649 | 649 | return $this->_parse_question_list_for_primary_or_recipient_registration( |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | $setup_args = array( |
677 | 677 | 'mtfilename' => 'EE_Newsletter_message_type.class.php', |
678 | 678 | 'autoloadpaths' => array( |
679 | - EE_CAF_LIBRARIES . 'messages/message_type/newsletter/', |
|
679 | + EE_CAF_LIBRARIES.'messages/message_type/newsletter/', |
|
680 | 680 | ), |
681 | 681 | 'messengers_to_activate_with' => array('email'), |
682 | 682 | 'messengers_to_validate_with' => array('email'), |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | // register payment reminder message type |
688 | 688 | $setup_args = array( |
689 | 689 | 'mtfilename' => 'EE_Payment_Reminder_message_type.class.php', |
690 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'), |
|
690 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_reminder/'), |
|
691 | 691 | 'messengers_to_activate_with' => array('email'), |
692 | 692 | 'messengers_to_validate_with' => array('email'), |
693 | 693 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | // register payment declined message type |
698 | 698 | $setup_args = array( |
699 | 699 | 'mtfilename' => 'EE_Payment_Declined_message_type.class.php', |
700 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'), |
|
700 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_declined/'), |
|
701 | 701 | 'messengers_to_activate_with' => array('email'), |
702 | 702 | 'messengers_to_validate_with' => array('email'), |
703 | 703 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | // register registration declined message type |
708 | 708 | $setup_args = array( |
709 | 709 | 'mtfilename' => 'EE_Declined_Registration_message_type.class.php', |
710 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'), |
|
710 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/declined_registration/'), |
|
711 | 711 | 'messengers_to_activate_with' => array('email'), |
712 | 712 | 'messengers_to_validate_with' => array('email'), |
713 | 713 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -717,7 +717,7 @@ discard block |
||
717 | 717 | // register registration cancelled message type |
718 | 718 | $setup_args = array( |
719 | 719 | 'mtfilename' => 'EE_Cancelled_Registration_message_type.class.php', |
720 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'), |
|
720 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/cancelled_registration/'), |
|
721 | 721 | 'messengers_to_activate_with' => array('email'), |
722 | 722 | 'messengers_to_validate_with' => array('email'), |
723 | 723 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | // register payment failed message type |
729 | 729 | $setup_args = array( |
730 | 730 | 'mtfilename' => 'EE_Payment_Failed_message_type.class.php', |
731 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'), |
|
731 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_failed/'), |
|
732 | 732 | 'messengers_to_activate_with' => array('email'), |
733 | 733 | 'messengers_to_validate_with' => array('email'), |
734 | 734 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | // register payment declined message type |
739 | 739 | $setup_args = array( |
740 | 740 | 'mtfilename' => 'EE_Payment_Cancelled_message_type.class.php', |
741 | - 'autoloadpaths' => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'), |
|
741 | + 'autoloadpaths' => array(EE_CAF_LIBRARIES.'messages/message_type/payment_cancelled/'), |
|
742 | 742 | 'messengers_to_activate_with' => array('email'), |
743 | 743 | 'messengers_to_validate_with' => array('email'), |
744 | 744 | 'messengers_supporting_default_template_pack_with' => array('email'), |
@@ -758,7 +758,7 @@ discard block |
||
758 | 758 | { |
759 | 759 | $setup_args = array( |
760 | 760 | 'autoloadpaths' => array( |
761 | - EE_CAF_LIBRARIES . 'shortcodes/', |
|
761 | + EE_CAF_LIBRARIES.'shortcodes/', |
|
762 | 762 | ), |
763 | 763 | 'msgr_validator_callback' => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'), |
764 | 764 | 'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'), |
@@ -792,9 +792,9 @@ discard block |
||
792 | 792 | foreach ($answers as $answer) { |
793 | 793 | if ($answer instanceof EE_Answer) { |
794 | 794 | // first see if the question is in our $questions array. If not then try to get from answer object. |
795 | - $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null; |
|
795 | + $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null; |
|
796 | 796 | $question = ! $question instanceof EE_Question ? $answer->question() : $question; |
797 | - if (! $question instanceof EE_Question |
|
797 | + if ( ! $question instanceof EE_Question |
|
798 | 798 | || ( |
799 | 799 | $question instanceof EE_Question |
800 | 800 | && $question->admin_only() |