@@ -1,22 +1,22 @@ discard block |
||
1 | 1 | |
2 | 2 | <div class="misc-pub-section"> |
3 | 3 | <span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span> |
4 | - <a href="<?php echo $view_approved_reg_url;?>"> |
|
5 | - <?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence') ); ?> |
|
4 | + <a href="<?php echo $view_approved_reg_url; ?>"> |
|
5 | + <?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_approved, FALSE, 'sentence')); ?> |
|
6 | 6 | </a>: |
7 | 7 | <?php echo $approved_regs; ?> |
8 | 8 | </div> |
9 | 9 | <div class="misc-pub-section"> |
10 | 10 | <span class="dashicons dashicons-groups ee-icon-color-ee-blue ee-icon-size-20"></span> |
11 | - <a href="<?php echo $view_pending_payment_reg_url;?>"> |
|
12 | - <?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence') ); ?> |
|
11 | + <a href="<?php echo $view_pending_payment_reg_url; ?>"> |
|
12 | + <?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, FALSE, 'sentence')); ?> |
|
13 | 13 | </a>: |
14 | 14 | <?php echo $pending_payment_regs; ?> |
15 | 15 | </div> |
16 | 16 | <div class="misc-pub-section"> |
17 | 17 | <span class="dashicons dashicons-groups ee-icon-color-ee-orange ee-icon-size-20"></span> |
18 | - <a href="<?php echo $view_not_approved_reg_url;?>"> |
|
19 | - <?php printf( __('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence') ); ?> |
|
18 | + <a href="<?php echo $view_not_approved_reg_url; ?>"> |
|
19 | + <?php printf(__('%s Registrations', 'event_espresso'), EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, FALSE, 'sentence')); ?> |
|
20 | 20 | </a>: |
21 | 21 | <?php echo $not_approved_regs; ?> |
22 | 22 | </div> |
@@ -29,5 +29,5 @@ discard block |
||
29 | 29 | </a> |
30 | 30 | </div> /**/ ?> |
31 | 31 | |
32 | -<?php echo $event_editor_overview_add;?> |
|
32 | +<?php echo $event_editor_overview_add; ?> |
|
33 | 33 | <br/> |
@@ -588,6 +588,7 @@ |
||
588 | 588 | * @param EE_Registration $registration |
589 | 589 | * @param EE_Question $question |
590 | 590 | * @param mixed EE_Answer|NULL $answer |
591 | + * @param EE_Answer $answer |
|
591 | 592 | * @return EE_Form_Input_Base |
592 | 593 | * @throws \EE_Error |
593 | 594 | */ |
@@ -2,17 +2,17 @@ discard block |
||
2 | 2 | |
3 | 3 | if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
4 | 4 | /** |
5 | - * |
|
6 | - * Class EE_SPCO_Reg_Step_Attendee_Information |
|
7 | - * |
|
8 | - * Description |
|
9 | - * |
|
10 | - * @package Event Espresso |
|
11 | - * @subpackage core |
|
12 | - * @author Brent Christensen |
|
13 | - * @since 4.5.0 |
|
14 | - * |
|
15 | - */ |
|
5 | + * |
|
6 | + * Class EE_SPCO_Reg_Step_Attendee_Information |
|
7 | + * |
|
8 | + * Description |
|
9 | + * |
|
10 | + * @package Event Espresso |
|
11 | + * @subpackage core |
|
12 | + * @author Brent Christensen |
|
13 | + * @since 4.5.0 |
|
14 | + * |
|
15 | + */ |
|
16 | 16 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step { |
17 | 17 | |
18 | 18 | /** |
@@ -137,28 +137,28 @@ discard block |
||
137 | 137 | $registration instanceof EE_Registration |
138 | 138 | && $this->checkout->visit_allows_processing_of_this_registration( $registration ) |
139 | 139 | ) { |
140 | - $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
141 | - if ( ! $this->checkout->admin_request) { |
|
142 | - $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
143 | - $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
144 | - $template_args['ticket_count'][$registration->ticket()->ID()] |
|
145 | - ) |
|
146 | - ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
147 | - : 1; |
|
148 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
149 | - $this->checkout->cart->get_grand_total(), |
|
150 | - 'Ticket', |
|
151 | - array($registration->ticket()->ID()) |
|
152 | - ); |
|
153 | - $ticket_line_item = is_array($ticket_line_item) |
|
154 | - ? reset($ticket_line_item) |
|
155 | - : $ticket_line_item; |
|
156 | - $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
157 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
158 | - } |
|
159 | - if ($registration->is_primary_registrant()) { |
|
160 | - $primary_registrant = $registration->reg_url_link(); |
|
161 | - } |
|
140 | + $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
141 | + if ( ! $this->checkout->admin_request) { |
|
142 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
143 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
144 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
145 | + ) |
|
146 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
147 | + : 1; |
|
148 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
149 | + $this->checkout->cart->get_grand_total(), |
|
150 | + 'Ticket', |
|
151 | + array($registration->ticket()->ID()) |
|
152 | + ); |
|
153 | + $ticket_line_item = is_array($ticket_line_item) |
|
154 | + ? reset($ticket_line_item) |
|
155 | + : $ticket_line_item; |
|
156 | + $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
157 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
158 | + } |
|
159 | + if ($registration->is_primary_registrant()) { |
|
160 | + $primary_registrant = $registration->reg_url_link(); |
|
161 | + } |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | // print_copy_info ? |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | // generate hidden input |
171 | 171 | if ( |
172 | 172 | isset( $subsections[ $primary_registrant ] ) |
173 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
173 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
174 | 174 | ) { |
175 | 175 | $subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false ); |
176 | 176 | } |
@@ -198,42 +198,42 @@ discard block |
||
198 | 198 | |
199 | 199 | |
200 | 200 | |
201 | - /** |
|
201 | + /** |
|
202 | 202 | * @param EE_Registration $registration |
203 | 203 | * @return EE_Form_Section_Base |
204 | 204 | * @throws \EE_Error |
205 | 205 | */ |
206 | 206 | private function _registrations_reg_form( EE_Registration $registration ) { |
207 | 207 | static $attendee_nmbr = 1; |
208 | - $form_args = array(); |
|
208 | + $form_args = array(); |
|
209 | 209 | // verify that registration has valid event |
210 | 210 | if ( $registration->event() instanceof EE_Event ) { |
211 | 211 | $question_groups = $registration->event()->question_groups( |
212 | - array( |
|
213 | - array( |
|
214 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
215 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false |
|
216 | - ), |
|
217 | - 'order_by' => array('QSG_order' => 'ASC') |
|
218 | - ) |
|
219 | - ); |
|
212 | + array( |
|
213 | + array( |
|
214 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
215 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false |
|
216 | + ), |
|
217 | + 'order_by' => array('QSG_order' => 'ASC') |
|
218 | + ) |
|
219 | + ); |
|
220 | 220 | if ( $question_groups ) { |
221 | - // array of params to pass to parent constructor |
|
222 | - $form_args = array( |
|
223 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
224 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
225 | - 'html_style' => $this->checkout->admin_request |
|
226 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
227 | - : '', |
|
228 | - 'subsections' => array(), |
|
229 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
230 | - array( |
|
231 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
232 | - 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr) |
|
233 | - ) |
|
234 | - ) |
|
235 | - ); |
|
236 | - foreach ( $question_groups as $question_group ) { |
|
221 | + // array of params to pass to parent constructor |
|
222 | + $form_args = array( |
|
223 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
224 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
225 | + 'html_style' => $this->checkout->admin_request |
|
226 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
227 | + : '', |
|
228 | + 'subsections' => array(), |
|
229 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
230 | + array( |
|
231 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
232 | + 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr) |
|
233 | + ) |
|
234 | + ) |
|
235 | + ); |
|
236 | + foreach ( $question_groups as $question_group ) { |
|
237 | 237 | if ( $question_group instanceof EE_Question_Group ) { |
238 | 238 | $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
239 | 239 | $registration, |
@@ -241,19 +241,19 @@ discard block |
||
241 | 241 | ); |
242 | 242 | } |
243 | 243 | } |
244 | - // add hidden input |
|
245 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
246 | - $registration |
|
247 | - ); |
|
248 | - // if we have question groups for additional attendees, then display the copy options |
|
244 | + // add hidden input |
|
245 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
246 | + $registration |
|
247 | + ); |
|
248 | + // if we have question groups for additional attendees, then display the copy options |
|
249 | 249 | $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
250 | - if ($registration->is_primary_registrant()) { |
|
251 | - // generate hidden input |
|
252 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs($registration); |
|
253 | - } |
|
254 | - } |
|
250 | + if ($registration->is_primary_registrant()) { |
|
251 | + // generate hidden input |
|
252 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs($registration); |
|
253 | + } |
|
254 | + } |
|
255 | 255 | } |
256 | - $attendee_nmbr++; |
|
256 | + $attendee_nmbr++; |
|
257 | 257 | return ! empty($form_args) ? new EE_Form_Section_Proper( $form_args ) : new EE_Form_Section_HTML(); |
258 | 258 | } |
259 | 259 | |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | if ( isset( $valid_data[ $reg_url_link ] ) ) { |
887 | 887 | // do we need to copy basic info from primary attendee ? |
888 | 888 | $copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) |
889 | - && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
889 | + && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
890 | 890 | ? true |
891 | 891 | : false; |
892 | 892 | // filter form input data for this registration |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | ) ) { |
1047 | 1047 | return true; |
1048 | 1048 | } |
1049 | - /* |
|
1049 | + /* |
|
1050 | 1050 | * $answer_cache_id is the key used to find the EE_Answer we want |
1051 | 1051 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1052 | 1052 | */ |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | ? $form_input . '-' . $registration->reg_url_link() |
1055 | 1055 | : $form_input; |
1056 | 1056 | $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
1057 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
1057 | + && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
1058 | 1058 | ? true |
1059 | 1059 | : false; |
1060 | 1060 | //rename form_inputs if they are EE_Attendee properties |
@@ -1221,7 +1221,7 @@ discard block |
||
1221 | 1221 | } |
1222 | 1222 | foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
1223 | 1223 | if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
1224 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
1224 | + || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
1225 | 1225 | ) { |
1226 | 1226 | $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
1227 | 1227 | $critical_attendee_detail |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\commands\attendee\CreateAttendeeCommand; |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
4 | 4 | /** |
5 | 5 | * |
6 | 6 | * Class EE_SPCO_Reg_Step_Attendee_Information |
@@ -43,21 +43,21 @@ discard block |
||
43 | 43 | * @access public |
44 | 44 | * @param EE_Checkout $checkout |
45 | 45 | */ |
46 | - public function __construct( EE_Checkout $checkout ) { |
|
46 | + public function __construct(EE_Checkout $checkout) { |
|
47 | 47 | $this->_slug = 'attendee_information'; |
48 | 48 | $this->_name = __('Attendee Information', 'event_espresso'); |
49 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
49 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php'; |
|
50 | 50 | $this->checkout = $checkout; |
51 | 51 | $this->_reset_success_message(); |
52 | 52 | $this->set_instructions( |
53 | - __( 'Please answer the following registration questions before proceeding.', 'event_espresso' ) |
|
53 | + __('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
54 | 54 | ); |
55 | 55 | } |
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | 59 | public function translate_js_strings() { |
60 | - EE_Registry::$i18n_js_strings['required_field'] = __( ' is a required question.', 'event_espresso' ); |
|
60 | + EE_Registry::$i18n_js_strings['required_field'] = __(' is a required question.', 'event_espresso'); |
|
61 | 61 | EE_Registry::$i18n_js_strings['required_multi_field'] = __( |
62 | 62 | ' is a required question. Please enter a value for at least one of the options.', |
63 | 63 | 'event_espresso' |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | // calculate taxes |
118 | 118 | $Line_Item_Display->display_line_item( |
119 | 119 | $this->checkout->cart->get_grand_total(), |
120 | - array( 'set_tax_rate' => true ) |
|
120 | + array('set_tax_rate' => true) |
|
121 | 121 | ); |
122 | 122 | /** @var $subsections EE_Form_Section_Proper[] */ |
123 | 123 | $subsections = array( |
@@ -129,13 +129,13 @@ discard block |
||
129 | 129 | 'ticket_count' => array() |
130 | 130 | ); |
131 | 131 | // grab the saved registrations from the transaction |
132 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
133 | - if ( $registrations ) { |
|
134 | - foreach ( $registrations as $registration ) { |
|
132 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
133 | + if ($registrations) { |
|
134 | + foreach ($registrations as $registration) { |
|
135 | 135 | // can this registration be processed during this visit ? |
136 | 136 | if ( |
137 | 137 | $registration instanceof EE_Registration |
138 | - && $this->checkout->visit_allows_processing_of_this_registration( $registration ) |
|
138 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
139 | 139 | ) { |
140 | 140 | $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
141 | 141 | if ( ! $this->checkout->admin_request) { |
@@ -162,17 +162,17 @@ discard block |
||
162 | 162 | } |
163 | 163 | } |
164 | 164 | // print_copy_info ? |
165 | - if ( $primary_registrant && ! $this->checkout->admin_request && count( $registrations ) > 1 ) { |
|
165 | + if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
166 | 166 | // TODO: add admin option for toggling copy attendee info, then use that value to change $this->_print_copy_info |
167 | 167 | $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
168 | 168 | ? $this->_copy_attendee_info_form() |
169 | 169 | : $this->_auto_copy_attendee_info(); |
170 | 170 | // generate hidden input |
171 | 171 | if ( |
172 | - isset( $subsections[ $primary_registrant ] ) |
|
173 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
172 | + isset($subsections[$primary_registrant]) |
|
173 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
174 | 174 | ) { |
175 | - $subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false ); |
|
175 | + $subsections[$primary_registrant]->add_subsections($copy_options, 'primary_registrant', false); |
|
176 | 176 | } |
177 | 177 | } |
178 | 178 | |
@@ -184,8 +184,7 @@ discard block |
||
184 | 184 | 'html_id' => $this->reg_form_name(), |
185 | 185 | 'subsections' => $subsections, |
186 | 186 | 'layout_strategy' => $this->checkout->admin_request ? |
187 | - new EE_Div_Per_Section_Layout() : |
|
188 | - new EE_Template_Layout( |
|
187 | + new EE_Div_Per_Section_Layout() : new EE_Template_Layout( |
|
189 | 188 | array( |
190 | 189 | 'layout_template_file' => $this->_template, // layout_template |
191 | 190 | 'template_args' => $template_args |
@@ -203,11 +202,11 @@ discard block |
||
203 | 202 | * @return EE_Form_Section_Base |
204 | 203 | * @throws \EE_Error |
205 | 204 | */ |
206 | - private function _registrations_reg_form( EE_Registration $registration ) { |
|
205 | + private function _registrations_reg_form(EE_Registration $registration) { |
|
207 | 206 | static $attendee_nmbr = 1; |
208 | 207 | $form_args = array(); |
209 | 208 | // verify that registration has valid event |
210 | - if ( $registration->event() instanceof EE_Event ) { |
|
209 | + if ($registration->event() instanceof EE_Event) { |
|
211 | 210 | $question_groups = $registration->event()->question_groups( |
212 | 211 | array( |
213 | 212 | array( |
@@ -217,10 +216,10 @@ discard block |
||
217 | 216 | 'order_by' => array('QSG_order' => 'ASC') |
218 | 217 | ) |
219 | 218 | ); |
220 | - if ( $question_groups ) { |
|
219 | + if ($question_groups) { |
|
221 | 220 | // array of params to pass to parent constructor |
222 | 221 | $form_args = array( |
223 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
222 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
224 | 223 | 'html_class' => 'ee-reg-form-attendee-dv', |
225 | 224 | 'html_style' => $this->checkout->admin_request |
226 | 225 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -233,9 +232,9 @@ discard block |
||
233 | 232 | ) |
234 | 233 | ) |
235 | 234 | ); |
236 | - foreach ( $question_groups as $question_group ) { |
|
237 | - if ( $question_group instanceof EE_Question_Group ) { |
|
238 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
235 | + foreach ($question_groups as $question_group) { |
|
236 | + if ($question_group instanceof EE_Question_Group) { |
|
237 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
239 | 238 | $registration, |
240 | 239 | $question_group |
241 | 240 | ); |
@@ -254,7 +253,7 @@ discard block |
||
254 | 253 | } |
255 | 254 | } |
256 | 255 | $attendee_nmbr++; |
257 | - return ! empty($form_args) ? new EE_Form_Section_Proper( $form_args ) : new EE_Form_Section_HTML(); |
|
256 | + return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML(); |
|
258 | 257 | } |
259 | 258 | |
260 | 259 | |
@@ -275,7 +274,7 @@ discard block |
||
275 | 274 | // generate hidden input |
276 | 275 | return new EE_Hidden_Input( |
277 | 276 | array( |
278 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
277 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
279 | 278 | 'default' => $additional_attendee_reg_info |
280 | 279 | ) |
281 | 280 | ); |
@@ -289,26 +288,26 @@ discard block |
||
289 | 288 | * @return EE_Form_Section_Proper |
290 | 289 | * @throws \EE_Error |
291 | 290 | */ |
292 | - private function _question_group_reg_form( EE_Registration $registration, EE_Question_Group $question_group ){ |
|
291 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) { |
|
293 | 292 | // array of params to pass to parent constructor |
294 | 293 | $form_args = array( |
295 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier(), |
|
294 | + 'html_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier(), |
|
296 | 295 | 'html_class' => $this->checkout->admin_request |
297 | 296 | ? 'form-table ee-reg-form-qstn-grp-dv' |
298 | 297 | : 'ee-reg-form-qstn-grp-dv', |
299 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl', |
|
298 | + 'html_label_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-lbl', |
|
300 | 299 | 'subsections' => array( |
301 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header( $question_group ) |
|
300 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group) |
|
302 | 301 | ), |
303 | 302 | 'layout_strategy' => $this->checkout->admin_request |
304 | 303 | ? new EE_Admin_Two_Column_Layout() |
305 | 304 | : new EE_Div_Per_Section_Layout() |
306 | 305 | ); |
307 | 306 | // where params |
308 | - $query_params = array( 'QST_deleted' => 0 ); |
|
307 | + $query_params = array('QST_deleted' => 0); |
|
309 | 308 | // don't load admin only questions on the frontend |
310 | - if ( ! $this->checkout->admin_request ) { |
|
311 | - $query_params['QST_admin_only'] = array( '!=', true ); |
|
309 | + if ( ! $this->checkout->admin_request) { |
|
310 | + $query_params['QST_admin_only'] = array('!=', true); |
|
312 | 311 | } |
313 | 312 | $questions = $question_group->get_many_related( |
314 | 313 | 'Question', |
@@ -330,10 +329,10 @@ discard block |
||
330 | 329 | ) |
331 | 330 | ); |
332 | 331 | // loop thru questions |
333 | - foreach ( $questions as $question ) { |
|
334 | - if( $question instanceof EE_Question ){ |
|
332 | + foreach ($questions as $question) { |
|
333 | + if ($question instanceof EE_Question) { |
|
335 | 334 | $identifier = $question->is_system_question() ? $question->system_ID() : $question->ID(); |
336 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question( $registration, $question ); |
|
335 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
337 | 336 | } |
338 | 337 | } |
339 | 338 | $form_args['subsections'] = apply_filters( |
@@ -354,7 +353,7 @@ discard block |
||
354 | 353 | ) |
355 | 354 | ); |
356 | 355 | // d( $form_args ); |
357 | - $question_group_reg_form = new EE_Form_Section_Proper( $form_args ); |
|
356 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
358 | 357 | return apply_filters( |
359 | 358 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
360 | 359 | $question_group_reg_form, |
@@ -371,11 +370,11 @@ discard block |
||
371 | 370 | * @param EE_Question_Group $question_group |
372 | 371 | * @return EE_Form_Section_HTML |
373 | 372 | */ |
374 | - private function _question_group_header( EE_Question_Group $question_group ){ |
|
373 | + private function _question_group_header(EE_Question_Group $question_group) { |
|
375 | 374 | $html = ''; |
376 | 375 | // group_name |
377 | - if ( $question_group->show_group_name() && $question_group->name() !== '' ) { |
|
378 | - if ( $this->checkout->admin_request ) { |
|
376 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
377 | + if ($this->checkout->admin_request) { |
|
379 | 378 | $html .= EEH_HTML::br(); |
380 | 379 | $html .= EEH_HTML::h3( |
381 | 380 | $question_group->name(), |
@@ -389,7 +388,7 @@ discard block |
||
389 | 388 | } |
390 | 389 | } |
391 | 390 | // group_desc |
392 | - if ( $question_group->show_group_desc() && $question_group->desc() !== '' ) { |
|
391 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
393 | 392 | $html .= EEH_HTML::p( |
394 | 393 | $question_group->desc(), |
395 | 394 | '', |
@@ -399,7 +398,7 @@ discard block |
||
399 | 398 | ); |
400 | 399 | |
401 | 400 | } |
402 | - return new EE_Form_Section_HTML( $html ); |
|
401 | + return new EE_Form_Section_HTML($html); |
|
403 | 402 | } |
404 | 403 | |
405 | 404 | |
@@ -409,7 +408,7 @@ discard block |
||
409 | 408 | * @return EE_Form_Section_Proper |
410 | 409 | * @throws \EE_Error |
411 | 410 | */ |
412 | - private function _copy_attendee_info_form(){ |
|
411 | + private function _copy_attendee_info_form() { |
|
413 | 412 | // array of params to pass to parent constructor |
414 | 413 | return new EE_Form_Section_Proper( |
415 | 414 | array( |
@@ -438,7 +437,7 @@ discard block |
||
438 | 437 | private function _auto_copy_attendee_info() { |
439 | 438 | return new EE_Form_Section_HTML( |
440 | 439 | EEH_Template::locate_template( |
441 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
440 | + SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php', |
|
442 | 441 | apply_filters( |
443 | 442 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
444 | 443 | array() |
@@ -462,32 +461,32 @@ discard block |
||
462 | 461 | $copy_attendee_info_inputs = array(); |
463 | 462 | $prev_ticket = NULL; |
464 | 463 | // grab the saved registrations from the transaction |
465 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
466 | - foreach ( $registrations as $registration ) { |
|
464 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
465 | + foreach ($registrations as $registration) { |
|
467 | 466 | // for all attendees other than the primary attendee |
468 | - if ( $registration instanceof EE_Registration && ! $registration->is_primary_registrant() ) { |
|
467 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
469 | 468 | // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
470 | - if ( $registration->ticket()->ID() !== $prev_ticket ) { |
|
469 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
471 | 470 | $item_name = $registration->ticket()->name(); |
472 | 471 | $item_name .= $registration->ticket()->description() !== '' |
473 | - ? ' - ' . $registration->ticket()->description() |
|
472 | + ? ' - '.$registration->ticket()->description() |
|
474 | 473 | : ''; |
475 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] = new EE_Form_Section_HTML( |
|
476 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
474 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] = new EE_Form_Section_HTML( |
|
475 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
477 | 476 | ); |
478 | 477 | $prev_ticket = $registration->ticket()->ID(); |
479 | 478 | } |
480 | 479 | |
481 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = new |
|
480 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = new |
|
482 | 481 | EE_Checkbox_Multi_Input( |
483 | 482 | array( |
484 | 483 | $registration->ID() => sprintf( |
485 | - __( 'Attendee #%s', 'event_espresso' ), |
|
484 | + __('Attendee #%s', 'event_espresso'), |
|
486 | 485 | $registration->count() |
487 | 486 | ) |
488 | 487 | ), |
489 | 488 | array( |
490 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
489 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
491 | 490 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
492 | 491 | 'display_html_label_text' => false |
493 | 492 | ) |
@@ -507,7 +506,7 @@ discard block |
||
507 | 506 | * @return EE_Form_Input_Base |
508 | 507 | * @throws \EE_Error |
509 | 508 | */ |
510 | - private function _additional_primary_registrant_inputs( EE_Registration $registration ){ |
|
509 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) { |
|
511 | 510 | // generate hidden input |
512 | 511 | return new EE_Hidden_Input( |
513 | 512 | array( |
@@ -526,7 +525,7 @@ discard block |
||
526 | 525 | * @return EE_Form_Input_Base |
527 | 526 | * @throws \EE_Error |
528 | 527 | */ |
529 | - public function reg_form_question( EE_Registration $registration, EE_Question $question ){ |
|
528 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) { |
|
530 | 529 | |
531 | 530 | // if this question was for an attendee detail, then check for that answer |
532 | 531 | $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
@@ -535,32 +534,32 @@ discard block |
||
535 | 534 | ); |
536 | 535 | $answer = $answer_value === null |
537 | 536 | ? EEM_Answer::instance()->get_one( |
538 | - array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) ) |
|
537 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
539 | 538 | ) |
540 | 539 | : null; |
541 | 540 | // if NOT returning to edit an existing registration |
542 | 541 | // OR if this question is for an attendee property |
543 | 542 | // OR we still don't have an EE_Answer object |
544 | - if( $answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link() ) { |
|
543 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
545 | 544 | // create an EE_Answer object for storing everything in |
546 | - $answer = EE_Answer::new_instance ( array( |
|
545 | + $answer = EE_Answer::new_instance(array( |
|
547 | 546 | 'QST_ID'=> $question->ID(), |
548 | 547 | 'REG_ID'=> $registration->ID() |
549 | 548 | )); |
550 | 549 | } |
551 | 550 | // verify instance |
552 | - if( $answer instanceof EE_Answer ){ |
|
553 | - if ( ! empty( $answer_value )) { |
|
554 | - $answer->set( 'ANS_value', $answer_value ); |
|
551 | + if ($answer instanceof EE_Answer) { |
|
552 | + if ( ! empty($answer_value)) { |
|
553 | + $answer->set('ANS_value', $answer_value); |
|
555 | 554 | } |
556 | - $answer->cache( 'Question', $question ); |
|
555 | + $answer->cache('Question', $question); |
|
557 | 556 | //remember system ID had a bug where sometimes it could be null |
558 | - $answer_cache_id =$question->is_system_question() |
|
559 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
560 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
561 | - $registration->cache( 'Answer', $answer, $answer_cache_id ); |
|
557 | + $answer_cache_id = $question->is_system_question() |
|
558 | + ? $question->system_ID().'-'.$registration->reg_url_link() |
|
559 | + : $question->ID().'-'.$registration->reg_url_link(); |
|
560 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
562 | 561 | } |
563 | - return $this->_generate_question_input( $registration, $question, $answer ); |
|
562 | + return $this->_generate_question_input($registration, $question, $answer); |
|
564 | 563 | |
565 | 564 | } |
566 | 565 | |
@@ -573,46 +572,46 @@ discard block |
||
573 | 572 | * @return EE_Form_Input_Base |
574 | 573 | * @throws \EE_Error |
575 | 574 | */ |
576 | - private function _generate_question_input( EE_Registration $registration, EE_Question $question, $answer ){ |
|
575 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) { |
|
577 | 576 | $identifier = $question->is_system_question() ? $question->system_ID() : $question->ID(); |
578 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
577 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
579 | 578 | add_filter( |
580 | 579 | 'FHEE__EE_Question__generate_form_input__country_options', |
581 | - array( $this, 'use_cached_countries_for_form_input' ), |
|
580 | + array($this, 'use_cached_countries_for_form_input'), |
|
582 | 581 | 10, |
583 | 582 | 4 |
584 | 583 | ); |
585 | 584 | add_filter( |
586 | 585 | 'FHEE__EE_Question__generate_form_input__state_options', |
587 | - array( $this, 'use_cached_states_for_form_input' ), |
|
586 | + array($this, 'use_cached_states_for_form_input'), |
|
588 | 587 | 10, |
589 | 588 | 4 |
590 | 589 | ); |
591 | 590 | $input_constructor_args = array( |
592 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
593 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
594 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
595 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
591 | + 'html_name' => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']', |
|
592 | + 'html_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
593 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-'.$identifier, |
|
594 | + 'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
596 | 595 | 'html_label_class' => 'ee-reg-qstn', |
597 | 596 | ); |
598 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
599 | - if ( $answer instanceof EE_Answer && $answer->ID() ) { |
|
600 | - $input_constructor_args[ 'html_name' ] .= '[' . $answer->ID() . ']'; |
|
601 | - $input_constructor_args[ 'html_id' ] .= '-' . $answer->ID(); |
|
602 | - $input_constructor_args[ 'html_label_id' ] .= '-' . $answer->ID(); |
|
597 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
598 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
599 | + $input_constructor_args['html_name'] .= '['.$answer->ID().']'; |
|
600 | + $input_constructor_args['html_id'] .= '-'.$answer->ID(); |
|
601 | + $input_constructor_args['html_label_id'] .= '-'.$answer->ID(); |
|
603 | 602 | } |
604 | - $form_input = $question->generate_form_input( |
|
603 | + $form_input = $question->generate_form_input( |
|
605 | 604 | $registration, |
606 | 605 | $answer, |
607 | 606 | $input_constructor_args |
608 | 607 | ); |
609 | 608 | remove_filter( |
610 | 609 | 'FHEE__EE_Question__generate_form_input__country_options', |
611 | - array( $this, 'use_cached_countries_for_form_input' ) |
|
610 | + array($this, 'use_cached_countries_for_form_input') |
|
612 | 611 | ); |
613 | 612 | remove_filter( |
614 | 613 | 'FHEE__EE_Question__generate_form_input__state_options', |
615 | - array( $this, 'use_cached_states_for_form_input' ) |
|
614 | + array($this, 'use_cached_states_for_form_input') |
|
616 | 615 | ); |
617 | 616 | return $form_input; |
618 | 617 | } |
@@ -634,22 +633,22 @@ discard block |
||
634 | 633 | \EE_Registration $registration = null, |
635 | 634 | \EE_Answer $answer = null |
636 | 635 | ) { |
637 | - $country_options = array( '' => '' ); |
|
636 | + $country_options = array('' => ''); |
|
638 | 637 | // get possibly cached list of countries |
639 | 638 | $countries = $this->checkout->action === 'process_reg_step' |
640 | 639 | ? EEM_Country::instance()->get_all_countries() |
641 | 640 | : EEM_Country::instance()->get_all_active_countries(); |
642 | - if ( ! empty( $countries )) { |
|
643 | - foreach( $countries as $country ){ |
|
644 | - if ( $country instanceof EE_Country ) { |
|
645 | - $country_options[ $country->ID() ] = $country->name(); |
|
641 | + if ( ! empty($countries)) { |
|
642 | + foreach ($countries as $country) { |
|
643 | + if ($country instanceof EE_Country) { |
|
644 | + $country_options[$country->ID()] = $country->name(); |
|
646 | 645 | } |
647 | 646 | } |
648 | 647 | } |
649 | - if( $question instanceof EE_Question |
|
650 | - && $registration instanceof EE_Registration ) { |
|
648 | + if ($question instanceof EE_Question |
|
649 | + && $registration instanceof EE_Registration) { |
|
651 | 650 | $answer = EEM_Answer::instance()->get_one( |
652 | - array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) ) |
|
651 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
653 | 652 | ); |
654 | 653 | } else { |
655 | 654 | $answer = EE_Answer::new_instance(); |
@@ -682,14 +681,14 @@ discard block |
||
682 | 681 | \EE_Registration $registration = null, |
683 | 682 | \EE_Answer $answer = null |
684 | 683 | ) { |
685 | - $state_options = array( '' => array( '' => '')); |
|
684 | + $state_options = array('' => array('' => '')); |
|
686 | 685 | $states = $this->checkout->action === 'process_reg_step' |
687 | 686 | ? EEM_State::instance()->get_all_states() |
688 | 687 | : EEM_State::instance()->get_all_active_states(); |
689 | - if ( ! empty( $states )) { |
|
690 | - foreach( $states as $state ){ |
|
691 | - if ( $state instanceof EE_State ) { |
|
692 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
688 | + if ( ! empty($states)) { |
|
689 | + foreach ($states as $state) { |
|
690 | + if ($state instanceof EE_State) { |
|
691 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
693 | 692 | } |
694 | 693 | } |
695 | 694 | } |
@@ -717,24 +716,24 @@ discard block |
||
717 | 716 | * @throws \EE_Error |
718 | 717 | */ |
719 | 718 | public function process_reg_step() { |
720 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
719 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
721 | 720 | // grab validated data from form |
722 | 721 | $valid_data = $this->checkout->current_step->valid_data(); |
723 | 722 | // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
724 | 723 | // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
725 | 724 | // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
726 | - if ( empty( $valid_data )) { |
|
725 | + if (empty($valid_data)) { |
|
727 | 726 | EE_Error::add_error( |
728 | - __( 'No valid question responses were received.', 'event_espresso' ), |
|
727 | + __('No valid question responses were received.', 'event_espresso'), |
|
729 | 728 | __FILE__, |
730 | 729 | __FUNCTION__, |
731 | 730 | __LINE__ |
732 | 731 | ); |
733 | 732 | return false; |
734 | 733 | } |
735 | - if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg ) { |
|
734 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
736 | 735 | EE_Error::add_error( |
737 | - __( 'A valid transaction could not be initiated for processing your registrations.', 'event_espresso' ), |
|
736 | + __('A valid transaction could not be initiated for processing your registrations.', 'event_espresso'), |
|
738 | 737 | __FILE__, |
739 | 738 | __FUNCTION__, |
740 | 739 | __LINE__ |
@@ -742,11 +741,11 @@ discard block |
||
742 | 741 | return false; |
743 | 742 | } |
744 | 743 | // get cached registrations |
745 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
744 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
746 | 745 | // verify we got the goods |
747 | - if ( empty( $registrations )) { |
|
746 | + if (empty($registrations)) { |
|
748 | 747 | EE_Error::add_error( |
749 | - __( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ), |
|
748 | + __('Your form data could not be applied to any valid registrations.', 'event_espresso'), |
|
750 | 749 | __FILE__, |
751 | 750 | __FUNCTION__, |
752 | 751 | __LINE__ |
@@ -754,15 +753,15 @@ discard block |
||
754 | 753 | return false; |
755 | 754 | } |
756 | 755 | // extract attendee info from form data and save to model objects |
757 | - $registrations_processed = $this->_process_registrations( $registrations, $valid_data ); |
|
756 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
758 | 757 | // if first pass thru SPCO, |
759 | 758 | // then let's check processed registrations against the total number of tickets in the cart |
760 | - if ( $registrations_processed === false ) { |
|
759 | + if ($registrations_processed === false) { |
|
761 | 760 | // but return immediately if the previous step exited early due to errors |
762 | 761 | return false; |
763 | - } else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count ) { |
|
762 | + } else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
764 | 763 | // generate a correctly translated string for all possible singular/plural combinations |
765 | - if ( $this->checkout->total_ticket_count === 1 && $registrations_processed !== 1 ) { |
|
764 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
766 | 765 | $error_msg = sprintf( |
767 | 766 | __( |
768 | 767 | 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
@@ -771,7 +770,7 @@ discard block |
||
771 | 770 | $this->checkout->total_ticket_count, |
772 | 771 | $registrations_processed |
773 | 772 | ); |
774 | - } else if ( $this->checkout->total_ticket_count !== 1 && $registrations_processed === 1 ) { |
|
773 | + } else if ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
775 | 774 | $error_msg = sprintf( |
776 | 775 | __( |
777 | 776 | 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
@@ -790,17 +789,17 @@ discard block |
||
790 | 789 | $registrations_processed |
791 | 790 | ); |
792 | 791 | } |
793 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
792 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
794 | 793 | return false; |
795 | 794 | } |
796 | 795 | // mark this reg step as completed |
797 | 796 | $this->set_completed(); |
798 | 797 | $this->_set_success_message( |
799 | - __( 'The Attendee Information Step has been successfully completed.', 'event_espresso' ) |
|
798 | + __('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
800 | 799 | ); |
801 | 800 | //do action in case a plugin wants to do something with the data submitted in step 1. |
802 | 801 | //passes EE_Single_Page_Checkout, and it's posted data |
803 | - do_action( 'AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data ); |
|
802 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
804 | 803 | return true; |
805 | 804 | } |
806 | 805 | |
@@ -814,9 +813,9 @@ discard block |
||
814 | 813 | * @return boolean | int |
815 | 814 | * @throws \EE_Error |
816 | 815 | */ |
817 | - private function _process_registrations( $registrations = array(), $valid_data = array() ) { |
|
816 | + private function _process_registrations($registrations = array(), $valid_data = array()) { |
|
818 | 817 | // load resources and set some defaults |
819 | - EE_Registry::instance()->load_model( 'Attendee' ); |
|
818 | + EE_Registry::instance()->load_model('Attendee'); |
|
820 | 819 | // holder for primary registrant attendee object |
821 | 820 | $this->checkout->primary_attendee_obj = NULL; |
822 | 821 | // array for tracking reg form data for the primary registrant |
@@ -833,9 +832,9 @@ discard block |
||
833 | 832 | // attendee counter |
834 | 833 | $att_nmbr = 0; |
835 | 834 | // grab the saved registrations from the transaction |
836 | - foreach ( $registrations as $registration ) { |
|
835 | + foreach ($registrations as $registration) { |
|
837 | 836 | // verify EE_Registration object |
838 | - if ( ! $registration instanceof EE_Registration ) { |
|
837 | + if ( ! $registration instanceof EE_Registration) { |
|
839 | 838 | EE_Error::add_error( |
840 | 839 | __( |
841 | 840 | 'An invalid Registration object was discovered when attempting to process your registration information.', |
@@ -850,12 +849,12 @@ discard block |
||
850 | 849 | /** @var string $reg_url_link */ |
851 | 850 | $reg_url_link = $registration->reg_url_link(); |
852 | 851 | // reg_url_link exists ? |
853 | - if ( ! empty( $reg_url_link ) ) { |
|
852 | + if ( ! empty($reg_url_link)) { |
|
854 | 853 | // should this registration be processed during this visit ? |
855 | - if ( $this->checkout->visit_allows_processing_of_this_registration( $registration ) ) { |
|
854 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
856 | 855 | // if NOT revisiting, then let's save the registration now, |
857 | 856 | // so that we have a REG_ID to use when generating other objects |
858 | - if ( ! $this->checkout->revisit ) { |
|
857 | + if ( ! $this->checkout->revisit) { |
|
859 | 858 | $registration->save(); |
860 | 859 | } |
861 | 860 | /** |
@@ -865,7 +864,7 @@ discard block |
||
865 | 864 | * @var bool if true is returned by the plugin then the |
866 | 865 | * registration processing is halted. |
867 | 866 | */ |
868 | - if ( apply_filters( |
|
867 | + if (apply_filters( |
|
869 | 868 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
870 | 869 | false, |
871 | 870 | $att_nmbr, |
@@ -873,38 +872,38 @@ discard block |
||
873 | 872 | $registrations, |
874 | 873 | $valid_data, |
875 | 874 | $this |
876 | - ) ) { |
|
875 | + )) { |
|
877 | 876 | return false; |
878 | 877 | } |
879 | 878 | |
880 | 879 | // Houston, we have a registration! |
881 | 880 | $att_nmbr++; |
882 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
881 | + $this->_attendee_data[$reg_url_link] = array(); |
|
883 | 882 | // grab any existing related answer objects |
884 | 883 | $this->_registration_answers = $registration->answers(); |
885 | 884 | // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
886 | - if ( isset( $valid_data[ $reg_url_link ] ) ) { |
|
885 | + if (isset($valid_data[$reg_url_link])) { |
|
887 | 886 | // do we need to copy basic info from primary attendee ? |
888 | - $copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) |
|
889 | - && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
887 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
888 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
890 | 889 | ? true |
891 | 890 | : false; |
892 | 891 | // filter form input data for this registration |
893 | - $valid_data[ $reg_url_link ] = (array)apply_filters( |
|
892 | + $valid_data[$reg_url_link] = (array) apply_filters( |
|
894 | 893 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
895 | - $valid_data[ $reg_url_link ] |
|
894 | + $valid_data[$reg_url_link] |
|
896 | 895 | ); |
897 | 896 | // EEH_Debug_Tools::printr( $valid_data[ $reg_url_link ], '$valid_data[ $reg_url_link ]', __FILE__, __LINE__ ); |
898 | - if ( isset( $valid_data['primary_attendee'] )) { |
|
899 | - $primary_registrant['line_item_id'] = ! empty( $valid_data['primary_attendee'] ) |
|
897 | + if (isset($valid_data['primary_attendee'])) { |
|
898 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
900 | 899 | ? $valid_data['primary_attendee'] |
901 | 900 | : false; |
902 | - unset( $valid_data['primary_attendee'] ); |
|
901 | + unset($valid_data['primary_attendee']); |
|
903 | 902 | } |
904 | 903 | // now loop through our array of valid post data && process attendee reg forms |
905 | - foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) { |
|
906 | - if ( ! in_array( $form_section, $non_input_form_sections )) { |
|
907 | - foreach ( $form_inputs as $form_input => $input_value ) { |
|
904 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
905 | + if ( ! in_array($form_section, $non_input_form_sections)) { |
|
906 | + foreach ($form_inputs as $form_input => $input_value) { |
|
908 | 907 | // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
909 | 908 | // check for critical inputs |
910 | 909 | if ( |
@@ -918,16 +917,16 @@ discard block |
||
918 | 917 | // store a bit of data about the primary attendee |
919 | 918 | if ( |
920 | 919 | $att_nmbr === 1 |
921 | - && ! empty( $input_value ) |
|
920 | + && ! empty($input_value) |
|
922 | 921 | && $reg_url_link === $primary_registrant['line_item_id'] |
923 | 922 | ) { |
924 | - $primary_registrant[ $form_input ] = $input_value; |
|
923 | + $primary_registrant[$form_input] = $input_value; |
|
925 | 924 | } else if ( |
926 | 925 | $copy_primary |
927 | 926 | && $input_value === null |
928 | - && isset( $primary_registrant[ $form_input ] ) |
|
927 | + && isset($primary_registrant[$form_input]) |
|
929 | 928 | ) { |
930 | - $input_value = $primary_registrant[ $form_input ]; |
|
929 | + $input_value = $primary_registrant[$form_input]; |
|
931 | 930 | } |
932 | 931 | // now attempt to save the input data |
933 | 932 | if ( |
@@ -967,47 +966,47 @@ discard block |
||
967 | 966 | $attendee = $this->checkout->primary_attendee_obj; |
968 | 967 | } else { |
969 | 968 | // ensure critical details are set for additional attendees |
970 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
969 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
971 | 970 | ? $this->_copy_critical_attendee_details_from_primary_registrant( |
972 | - $this->_attendee_data[ $reg_url_link ] |
|
971 | + $this->_attendee_data[$reg_url_link] |
|
973 | 972 | ) |
974 | - : $this->_attendee_data[ $reg_url_link ]; |
|
973 | + : $this->_attendee_data[$reg_url_link]; |
|
975 | 974 | // execute create attendee command (which may return an existing attendee) |
976 | 975 | $attendee = EE_Registry::instance()->BUS->execute( |
977 | 976 | new CreateAttendeeCommand( |
978 | - $this->_attendee_data[ $reg_url_link ], |
|
977 | + $this->_attendee_data[$reg_url_link], |
|
979 | 978 | $registration |
980 | 979 | ) |
981 | 980 | ); |
982 | 981 | // who's #1 ? |
983 | - if ( $att_nmbr === 1 ) { |
|
982 | + if ($att_nmbr === 1) { |
|
984 | 983 | $this->checkout->primary_attendee_obj = $attendee; |
985 | 984 | } |
986 | 985 | } |
987 | 986 | // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
988 | 987 | // add relation to registration, set attendee ID, and cache attendee |
989 | - $this->_associate_attendee_with_registration( $registration, $attendee ); |
|
988 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
990 | 989 | // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
991 | - if ( ! $registration->attendee() instanceof EE_Attendee ) { |
|
992 | - EE_Error::add_error( sprintf( __( 'Registration %s has an invalid or missing Attendee object.', 'event_espresso' ), $reg_url_link ), __FILE__, __FUNCTION__, __LINE__ ); |
|
990 | + if ( ! $registration->attendee() instanceof EE_Attendee) { |
|
991 | + EE_Error::add_error(sprintf(__('Registration %s has an invalid or missing Attendee object.', 'event_espresso'), $reg_url_link), __FILE__, __FUNCTION__, __LINE__); |
|
993 | 992 | return false; |
994 | 993 | } |
995 | 994 | /** @type EE_Registration_Processor $registration_processor */ |
996 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
995 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
997 | 996 | // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
998 | - $registration_processor->toggle_incomplete_registration_status_to_default( $registration, false ); |
|
997 | + $registration_processor->toggle_incomplete_registration_status_to_default($registration, false); |
|
999 | 998 | // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
1000 | 999 | $this->checkout->transaction->toggle_failed_transaction_status(); |
1001 | 1000 | // if we've gotten this far, then let's save what we have |
1002 | 1001 | $registration->save(); |
1003 | 1002 | // add relation between TXN and registration |
1004 | - $this->_associate_registration_with_transaction( $registration ); |
|
1003 | + $this->_associate_registration_with_transaction($registration); |
|
1005 | 1004 | } // end of if ( ! $this->checkout->revisit || $this->checkout->primary_revisit || ( $this->checkout->revisit && $this->checkout->reg_url_link == $reg_url_link )) { |
1006 | 1005 | |
1007 | - } else { |
|
1008 | - EE_Error::add_error( __( 'An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1006 | + } else { |
|
1007 | + EE_Error::add_error(__('An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1009 | 1008 | // remove malformed data |
1010 | - unset( $valid_data[ $reg_url_link ] ); |
|
1009 | + unset($valid_data[$reg_url_link]); |
|
1011 | 1010 | return false; |
1012 | 1011 | } |
1013 | 1012 | |
@@ -1036,14 +1035,14 @@ discard block |
||
1036 | 1035 | // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
1037 | 1036 | // allow for plugins to hook in and do their own processing of the form input. |
1038 | 1037 | // For plugins to bypass normal processing here, they just need to return a boolean value. |
1039 | - if ( apply_filters( |
|
1038 | + if (apply_filters( |
|
1040 | 1039 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
1041 | 1040 | false, |
1042 | 1041 | $registration, |
1043 | 1042 | $form_input, |
1044 | 1043 | $input_value, |
1045 | 1044 | $this |
1046 | - ) ) { |
|
1045 | + )) { |
|
1047 | 1046 | return true; |
1048 | 1047 | } |
1049 | 1048 | /* |
@@ -1051,14 +1050,14 @@ discard block |
||
1051 | 1050 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1052 | 1051 | */ |
1053 | 1052 | $answer_cache_id = $this->checkout->reg_url_link |
1054 | - ? $form_input . '-' . $registration->reg_url_link() |
|
1053 | + ? $form_input.'-'.$registration->reg_url_link() |
|
1055 | 1054 | : $form_input; |
1056 | - $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
|
1057 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
1055 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
1056 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
1058 | 1057 | ? true |
1059 | 1058 | : false; |
1060 | 1059 | //rename form_inputs if they are EE_Attendee properties |
1061 | - switch( (string)$form_input ) { |
|
1060 | + switch ((string) $form_input) { |
|
1062 | 1061 | |
1063 | 1062 | case 'state' : |
1064 | 1063 | case 'STA_ID' : |
@@ -1073,32 +1072,32 @@ discard block |
||
1073 | 1072 | break; |
1074 | 1073 | |
1075 | 1074 | default : |
1076 | - $ATT_input = 'ATT_' . $form_input; |
|
1075 | + $ATT_input = 'ATT_'.$form_input; |
|
1077 | 1076 | //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
1078 | - $attendee_property = EEM_Attendee::instance()->has_field( $ATT_input ) ? true : false; |
|
1079 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1077 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1078 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
1080 | 1079 | } |
1081 | 1080 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
1082 | 1081 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
1083 | 1082 | // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
1084 | 1083 | // if this form input has a corresponding attendee property |
1085 | - if ( $attendee_property ) { |
|
1086 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1087 | - if ( $answer_is_obj ) { |
|
1084 | + if ($attendee_property) { |
|
1085 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
1086 | + if ($answer_is_obj) { |
|
1088 | 1087 | // and delete the corresponding answer since we won't be storing this data in that object |
1089 | - $registration->_remove_relation_to( $this->_registration_answers[ $answer_cache_id ], 'Answer' ); |
|
1090 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1088 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
1089 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
1091 | 1090 | } |
1092 | 1091 | return true; |
1093 | - } elseif ( $answer_is_obj ) { |
|
1092 | + } elseif ($answer_is_obj) { |
|
1094 | 1093 | // save this data to the answer object |
1095 | - $this->_registration_answers[ $answer_cache_id ]->set_value( $input_value ); |
|
1096 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1094 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
1095 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
1097 | 1096 | return $result !== false ? true : false; |
1098 | 1097 | } else { |
1099 | - foreach ( $this->_registration_answers as $answer ) { |
|
1100 | - if ( $answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id ) { |
|
1101 | - $answer->set_value( $input_value ); |
|
1098 | + foreach ($this->_registration_answers as $answer) { |
|
1099 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1100 | + $answer->set_value($input_value); |
|
1102 | 1101 | $result = $answer->save(); |
1103 | 1102 | return $result !== false ? true : false; |
1104 | 1103 | } |
@@ -1120,15 +1119,15 @@ discard block |
||
1120 | 1119 | $form_input = '', |
1121 | 1120 | $input_value = '' |
1122 | 1121 | ) { |
1123 | - if ( empty( $input_value ) ) { |
|
1122 | + if (empty($input_value)) { |
|
1124 | 1123 | // if the form input isn't marked as being required, then just return |
1125 | - if ( ! isset( $this->_required_questions[ $form_input ] ) || ! $this->_required_questions[ $form_input ] ) { |
|
1124 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1126 | 1125 | return true; |
1127 | 1126 | } |
1128 | - switch ( $form_input ) { |
|
1127 | + switch ($form_input) { |
|
1129 | 1128 | case 'fname' : |
1130 | 1129 | EE_Error::add_error( |
1131 | - __( 'First Name is a required value.', 'event_espresso' ), |
|
1130 | + __('First Name is a required value.', 'event_espresso'), |
|
1132 | 1131 | __FILE__, |
1133 | 1132 | __FUNCTION__, |
1134 | 1133 | __LINE__ |
@@ -1137,7 +1136,7 @@ discard block |
||
1137 | 1136 | break; |
1138 | 1137 | case 'lname' : |
1139 | 1138 | EE_Error::add_error( |
1140 | - __( 'Last Name is a required value.', 'event_espresso' ), |
|
1139 | + __('Last Name is a required value.', 'event_espresso'), |
|
1141 | 1140 | __FILE__, |
1142 | 1141 | __FUNCTION__, |
1143 | 1142 | __LINE__ |
@@ -1146,7 +1145,7 @@ discard block |
||
1146 | 1145 | break; |
1147 | 1146 | case 'email' : |
1148 | 1147 | EE_Error::add_error( |
1149 | - __( 'Please enter a valid email address.', 'event_espresso' ), |
|
1148 | + __('Please enter a valid email address.', 'event_espresso'), |
|
1150 | 1149 | __FILE__, |
1151 | 1150 | __FUNCTION__, |
1152 | 1151 | __LINE__ |
@@ -1168,11 +1167,11 @@ discard block |
||
1168 | 1167 | * @return void |
1169 | 1168 | * @throws \EE_Error |
1170 | 1169 | */ |
1171 | - private function _associate_attendee_with_registration( EE_Registration $registration, EE_Attendee $attendee ) { |
|
1170 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) { |
|
1172 | 1171 | // add relation to attendee |
1173 | - $registration->_add_relation_to( $attendee, 'Attendee' ); |
|
1174 | - $registration->set_attendee_id( $attendee->ID() ); |
|
1175 | - $registration->update_cache_after_object_save( 'Attendee', $attendee ); |
|
1172 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1173 | + $registration->set_attendee_id($attendee->ID()); |
|
1174 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1176 | 1175 | } |
1177 | 1176 | |
1178 | 1177 | |
@@ -1184,10 +1183,10 @@ discard block |
||
1184 | 1183 | * @return void |
1185 | 1184 | * @throws \EE_Error |
1186 | 1185 | */ |
1187 | - private function _associate_registration_with_transaction( EE_Registration $registration ) { |
|
1186 | + private function _associate_registration_with_transaction(EE_Registration $registration) { |
|
1188 | 1187 | // add relation to registration |
1189 | - $this->checkout->transaction->_add_relation_to( $registration, 'Registration' ); |
|
1190 | - $this->checkout->transaction->update_cache_after_object_save( 'Registration', $registration ); |
|
1188 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1189 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1191 | 1190 | } |
1192 | 1191 | |
1193 | 1192 | |
@@ -1200,14 +1199,14 @@ discard block |
||
1200 | 1199 | * @return array |
1201 | 1200 | * @throws \EE_Error |
1202 | 1201 | */ |
1203 | - private function _copy_critical_attendee_details_from_primary_registrant( $attendee_data = array() ) { |
|
1202 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) { |
|
1204 | 1203 | // bare minimum critical details include first name, last name, email address |
1205 | - $critical_attendee_details = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
1204 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1206 | 1205 | // add address info to critical details? |
1207 | - if ( apply_filters( |
|
1206 | + if (apply_filters( |
|
1208 | 1207 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
1209 | 1208 | false |
1210 | - ) ) { |
|
1209 | + )) { |
|
1211 | 1210 | $address_details = array( |
1212 | 1211 | 'ATT_address', |
1213 | 1212 | 'ATT_address2', |
@@ -1217,13 +1216,13 @@ discard block |
||
1217 | 1216 | 'ATT_zip', |
1218 | 1217 | 'ATT_phone' |
1219 | 1218 | ); |
1220 | - $critical_attendee_details = array_merge( $critical_attendee_details, $address_details ); |
|
1219 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1221 | 1220 | } |
1222 | - foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
|
1223 | - if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
|
1224 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
1221 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1222 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
1223 | + || empty($attendee_data[$critical_attendee_detail]) |
|
1225 | 1224 | ) { |
1226 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1225 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
1227 | 1226 | $critical_attendee_detail |
1228 | 1227 | ); |
1229 | 1228 | } |
@@ -1243,7 +1242,7 @@ discard block |
||
1243 | 1242 | */ |
1244 | 1243 | public function update_reg_step() { |
1245 | 1244 | // save everything |
1246 | - if ( $this->process_reg_step() ) { |
|
1245 | + if ($this->process_reg_step()) { |
|
1247 | 1246 | $this->checkout->redirect = true; |
1248 | 1247 | $this->checkout->redirect_url = add_query_arg( |
1249 | 1248 | array( |
@@ -1252,7 +1251,7 @@ discard block |
||
1252 | 1251 | ), |
1253 | 1252 | $this->checkout->thank_you_page_url |
1254 | 1253 | ); |
1255 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
1254 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1256 | 1255 | return true; |
1257 | 1256 | } |
1258 | 1257 | return false; |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | use EventEspresso\core\services\commands\CommandHandler; |
7 | 7 | use EventEspresso\core\services\commands\CommandInterface; |
8 | 8 | |
9 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
10 | - exit( 'No direct script access allowed' ); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | * @throws \EventEspresso\core\exceptions\UnexpectedEntityException |
50 | 50 | * @throws \EE_Error |
51 | 51 | */ |
52 | - public function handle( CommandInterface $command ) { |
|
52 | + public function handle(CommandInterface $command) { |
|
53 | 53 | /** @var CreateTicketLineItemCommand $command */ |
54 | - if ( ! $command instanceof CreateTicketLineItemCommand ) { |
|
55 | - throw new InvalidEntityException( get_class( $command ), 'CreateTicketLineItemCommand' ); |
|
54 | + if ( ! $command instanceof CreateTicketLineItemCommand) { |
|
55 | + throw new InvalidEntityException(get_class($command), 'CreateTicketLineItemCommand'); |
|
56 | 56 | } |
57 | 57 | // create new line item for ticket |
58 | 58 | return $this->factory->create( |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
2 | 2 | /** |
3 | 3 | * |
4 | 4 | * EEH_Line_Item |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @return boolean success |
46 | 46 | * @throws \EE_Error |
47 | 47 | */ |
48 | - public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
|
49 | - $items_subtotal = self::get_pre_tax_subtotal( $parent_line_item ); |
|
48 | + public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) { |
|
49 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
50 | 50 | $line_item = EE_Line_Item::new_instance(array( |
51 | 51 | 'LIN_name' => $name, |
52 | 52 | 'LIN_desc' => $description, |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'LIN_quantity' => $quantity, |
55 | 55 | 'LIN_percent' => null, |
56 | 56 | 'LIN_is_taxable' => $taxable, |
57 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0, |
|
57 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
58 | 58 | 'LIN_total' => (float) $unit_price * (int) $quantity, |
59 | 59 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
60 | 60 | 'LIN_code' => $code, |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $line_item, |
65 | 65 | $parent_line_item |
66 | 66 | ); |
67 | - return self::add_item( $parent_line_item, $line_item ); |
|
67 | + return self::add_item($parent_line_item, $line_item); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return boolean success |
87 | 87 | * @throws \EE_Error |
88 | 88 | */ |
89 | - public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
|
89 | + public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) { |
|
90 | 90 | $line_item = EE_Line_Item::new_instance(array( |
91 | 91 | 'LIN_name' => $name, |
92 | 92 | 'LIN_desc' => $description, |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | 'LIN_percent' => $percentage_amount, |
95 | 95 | 'LIN_quantity' => NULL, |
96 | 96 | 'LIN_is_taxable' => $taxable, |
97 | - 'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ), |
|
97 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
98 | 98 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
99 | 99 | 'LIN_parent' => $parent_line_item->ID() |
100 | 100 | )); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
103 | 103 | $line_item |
104 | 104 | ); |
105 | - return self::add_item( $parent_line_item, $line_item ); |
|
105 | + return self::add_item($parent_line_item, $line_item); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * @return \EE_Line_Item |
124 | 124 | * @throws \EE_Error |
125 | 125 | */ |
126 | - public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
|
127 | - if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) { |
|
128 | - throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) ); |
|
126 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
127 | + if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
128 | + throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID())); |
|
129 | 129 | } |
130 | 130 | // either increment the qty for an existing ticket |
131 | - $line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty ); |
|
131 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
132 | 132 | // or add a new one |
133 | - if ( ! $line_item instanceof EE_Line_Item ) { |
|
134 | - $line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty ); |
|
133 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
134 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
135 | 135 | } |
136 | 136 | $total_line_item->recalculate_total_including_taxes(); |
137 | 137 | return $line_item; |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @return \EE_Line_Item |
148 | 148 | * @throws \EE_Error |
149 | 149 | */ |
150 | - public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
150 | + public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
151 | 151 | $line_item = null; |
152 | - if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) { |
|
153 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item ); |
|
154 | - foreach ( (array)$ticket_line_items as $ticket_line_item ) { |
|
152 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
153 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
154 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
155 | 155 | if ( |
156 | 156 | $ticket_line_item instanceof EE_Line_Item |
157 | 157 | && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | - if ( $line_item instanceof EE_Line_Item ) { |
|
165 | - EEH_Line_Item::increment_quantity( $line_item, $qty ); |
|
164 | + if ($line_item instanceof EE_Line_Item) { |
|
165 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
166 | 166 | return $line_item; |
167 | 167 | } |
168 | 168 | return null; |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | * @return void |
180 | 180 | * @throws \EE_Error |
181 | 181 | */ |
182 | - public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
183 | - if( ! $line_item->is_percent() ) { |
|
182 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
183 | + if ( ! $line_item->is_percent()) { |
|
184 | 184 | $qty += $line_item->quantity(); |
185 | - $line_item->set_quantity( $qty ); |
|
186 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
185 | + $line_item->set_quantity($qty); |
|
186 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
187 | 187 | $line_item->save(); |
188 | 188 | } |
189 | - foreach( $line_item->children() as $child ) { |
|
190 | - if( $child->is_sub_line_item() ) { |
|
191 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
189 | + foreach ($line_item->children() as $child) { |
|
190 | + if ($child->is_sub_line_item()) { |
|
191 | + EEH_Line_Item::update_quantity($child, $qty); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | * @return void |
205 | 205 | * @throws \EE_Error |
206 | 206 | */ |
207 | - public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
208 | - if( ! $line_item->is_percent() ) { |
|
207 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
208 | + if ( ! $line_item->is_percent()) { |
|
209 | 209 | $qty = $line_item->quantity() - $qty; |
210 | - $qty = max( $qty, 0 ); |
|
211 | - $line_item->set_quantity( $qty ); |
|
212 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
210 | + $qty = max($qty, 0); |
|
211 | + $line_item->set_quantity($qty); |
|
212 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
213 | 213 | $line_item->save(); |
214 | 214 | } |
215 | - foreach( $line_item->children() as $child ) { |
|
216 | - if( $child->is_sub_line_item() ) { |
|
217 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
215 | + foreach ($line_item->children() as $child) { |
|
216 | + if ($child->is_sub_line_item()) { |
|
217 | + EEH_Line_Item::update_quantity($child, $qty); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | * @param int $new_quantity |
230 | 230 | * @throws \EE_Error |
231 | 231 | */ |
232 | - public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
|
233 | - if( ! $line_item->is_percent() ) { |
|
234 | - $line_item->set_quantity( $new_quantity ); |
|
235 | - $line_item->set_total( $line_item->unit_price() * $new_quantity ); |
|
232 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) { |
|
233 | + if ( ! $line_item->is_percent()) { |
|
234 | + $line_item->set_quantity($new_quantity); |
|
235 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
236 | 236 | $line_item->save(); |
237 | 237 | } |
238 | - foreach( $line_item->children() as $child ) { |
|
239 | - if( $child->is_sub_line_item() ) { |
|
240 | - EEH_Line_Item::update_quantity( $child, $new_quantity ); |
|
238 | + foreach ($line_item->children() as $child) { |
|
239 | + if ($child->is_sub_line_item()) { |
|
240 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
@@ -252,43 +252,43 @@ discard block |
||
252 | 252 | * @return \EE_Line_Item |
253 | 253 | * @throws \EE_Error |
254 | 254 | */ |
255 | - public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
255 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
256 | 256 | $datetimes = $ticket->datetimes(); |
257 | - $first_datetime = reset( $datetimes ); |
|
258 | - if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) { |
|
257 | + $first_datetime = reset($datetimes); |
|
258 | + if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
259 | 259 | $first_datetime_name = $first_datetime->event()->name(); |
260 | 260 | } else { |
261 | - $first_datetime_name = __( 'Event', 'event_espresso' ); |
|
261 | + $first_datetime_name = __('Event', 'event_espresso'); |
|
262 | 262 | } |
263 | - $event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name ); |
|
263 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
264 | 264 | // get event subtotal line |
265 | - $events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket ); |
|
265 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
266 | 266 | // add $ticket to cart |
267 | - $line_item = EE_Line_Item::new_instance( array( |
|
267 | + $line_item = EE_Line_Item::new_instance(array( |
|
268 | 268 | 'LIN_name' => $ticket->name(), |
269 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
269 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description().' '.$event : $event, |
|
270 | 270 | 'LIN_unit_price' => $ticket->price(), |
271 | 271 | 'LIN_quantity' => $qty, |
272 | 272 | 'LIN_is_taxable' => $ticket->taxable(), |
273 | - 'LIN_order' => count( $events_sub_total->children() ), |
|
273 | + 'LIN_order' => count($events_sub_total->children()), |
|
274 | 274 | 'LIN_total' => $ticket->price() * $qty, |
275 | 275 | 'LIN_type' => EEM_Line_Item::type_line_item, |
276 | 276 | 'OBJ_ID' => $ticket->ID(), |
277 | 277 | 'OBJ_type' => 'Ticket' |
278 | - ) ); |
|
278 | + )); |
|
279 | 279 | $line_item = apply_filters( |
280 | 280 | 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
281 | 281 | $line_item |
282 | 282 | ); |
283 | - $events_sub_total->add_child_line_item( $line_item ); |
|
283 | + $events_sub_total->add_child_line_item($line_item); |
|
284 | 284 | //now add the sub-line items |
285 | 285 | $running_total_for_ticket = 0; |
286 | - foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) { |
|
286 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
287 | 287 | $sign = $price->is_discount() ? -1 : 1; |
288 | 288 | $price_total = $price->is_percent() |
289 | 289 | ? $running_total_for_ticket * $price->amount() / 100 |
290 | 290 | : $price->amount() * $qty; |
291 | - $sub_line_item = EE_Line_Item::new_instance( array( |
|
291 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
292 | 292 | 'LIN_name' => $price->name(), |
293 | 293 | 'LIN_desc' => $price->desc(), |
294 | 294 | 'LIN_quantity' => $price->is_percent() ? null : $qty, |
@@ -298,18 +298,18 @@ discard block |
||
298 | 298 | 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
299 | 299 | 'OBJ_ID' => $price->ID(), |
300 | 300 | 'OBJ_type' => 'Price' |
301 | - ) ); |
|
301 | + )); |
|
302 | 302 | $sub_line_item = apply_filters( |
303 | 303 | 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
304 | 304 | $sub_line_item |
305 | 305 | ); |
306 | - if ( $price->is_percent() ) { |
|
307 | - $sub_line_item->set_percent( $sign * $price->amount() ); |
|
306 | + if ($price->is_percent()) { |
|
307 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
308 | 308 | } else { |
309 | - $sub_line_item->set_unit_price( $sign * $price->amount() ); |
|
309 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
310 | 310 | } |
311 | 311 | $running_total_for_ticket += $price_total; |
312 | - $line_item->add_child_line_item( $sub_line_item ); |
|
312 | + $line_item->add_child_line_item($sub_line_item); |
|
313 | 313 | } |
314 | 314 | return $line_item; |
315 | 315 | } |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | * @return boolean |
330 | 330 | * @throws \EE_Error |
331 | 331 | */ |
332 | - public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
|
333 | - $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
|
334 | - if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
|
332 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) { |
|
333 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
334 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
335 | 335 | $success = $pre_tax_subtotal->add_child_line_item($item); |
336 | - }else{ |
|
336 | + } else { |
|
337 | 337 | return FALSE; |
338 | 338 | } |
339 | 339 | $total_line_item->recalculate_total_including_taxes(); |
@@ -352,34 +352,34 @@ discard block |
||
352 | 352 | * @return bool success |
353 | 353 | * @throws \EE_Error |
354 | 354 | */ |
355 | - public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
355 | + public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
356 | 356 | // validate incoming line_item |
357 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
357 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
358 | 358 | throw new EE_Error( |
359 | 359 | sprintf( |
360 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
360 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
361 | 361 | $ticket_line_item->type() |
362 | 362 | ) |
363 | 363 | ); |
364 | 364 | } |
365 | - if ( $ticket_line_item->quantity() < $qty ) { |
|
365 | + if ($ticket_line_item->quantity() < $qty) { |
|
366 | 366 | throw new EE_Error( |
367 | 367 | sprintf( |
368 | - __( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ), |
|
368 | + __('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'), |
|
369 | 369 | $qty, |
370 | 370 | $ticket_line_item->quantity() |
371 | 371 | ) |
372 | 372 | ); |
373 | 373 | } |
374 | 374 | // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
375 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty ); |
|
376 | - foreach( $ticket_line_item->children() as $child_line_item ) { |
|
377 | - if( |
|
375 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
376 | + foreach ($ticket_line_item->children() as $child_line_item) { |
|
377 | + if ( |
|
378 | 378 | $child_line_item->is_sub_line_item() |
379 | 379 | && ! $child_line_item->is_percent() |
380 | 380 | && ! $child_line_item->is_cancellation() |
381 | 381 | ) { |
382 | - $child_line_item->set_quantity( $child_line_item->quantity() - $qty ); |
|
382 | + $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | // get cancellation sub line item |
@@ -387,37 +387,37 @@ discard block |
||
387 | 387 | $ticket_line_item, |
388 | 388 | EEM_Line_Item::type_cancellation |
389 | 389 | ); |
390 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
390 | + $cancellation_line_item = reset($cancellation_line_item); |
|
391 | 391 | // verify that this ticket was indeed previously cancelled |
392 | - if ( $cancellation_line_item instanceof EE_Line_Item ) { |
|
392 | + if ($cancellation_line_item instanceof EE_Line_Item) { |
|
393 | 393 | // increment cancelled quantity |
394 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty ); |
|
394 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
395 | 395 | } else { |
396 | 396 | // create cancellation sub line item |
397 | - $cancellation_line_item = EE_Line_Item::new_instance( array( |
|
398 | - 'LIN_name' => __( 'Cancellation', 'event_espresso' ), |
|
397 | + $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
398 | + 'LIN_name' => __('Cancellation', 'event_espresso'), |
|
399 | 399 | 'LIN_desc' => sprintf( |
400 | - _x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ), |
|
400 | + _x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'), |
|
401 | 401 | $ticket_line_item->name(), |
402 | - current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) |
|
402 | + current_time(get_option('date_format').' '.get_option('time_format')) |
|
403 | 403 | ), |
404 | 404 | 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
405 | 405 | 'LIN_quantity' => $qty, |
406 | 406 | 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
407 | - 'LIN_order' => count( $ticket_line_item->children() ), |
|
407 | + 'LIN_order' => count($ticket_line_item->children()), |
|
408 | 408 | 'LIN_total' => 0, // $ticket_line_item->unit_price() |
409 | 409 | 'LIN_type' => EEM_Line_Item::type_cancellation, |
410 | - ) ); |
|
411 | - $ticket_line_item->add_child_line_item( $cancellation_line_item ); |
|
410 | + )); |
|
411 | + $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
412 | 412 | } |
413 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
413 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
414 | 414 | // decrement parent line item quantity |
415 | 415 | $event_line_item = $ticket_line_item->parent(); |
416 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
417 | - $event_line_item->set_quantity( $event_line_item->quantity() - $qty ); |
|
416 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
417 | + $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
418 | 418 | $event_line_item->save(); |
419 | 419 | } |
420 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
420 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
421 | 421 | return true; |
422 | 422 | } |
423 | 423 | return false; |
@@ -435,12 +435,12 @@ discard block |
||
435 | 435 | * @return bool success |
436 | 436 | * @throws \EE_Error |
437 | 437 | */ |
438 | - public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
438 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
439 | 439 | // validate incoming line_item |
440 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
440 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
441 | 441 | throw new EE_Error( |
442 | 442 | sprintf( |
443 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
443 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
444 | 444 | $ticket_line_item->type() |
445 | 445 | ) |
446 | 446 | ); |
@@ -450,42 +450,42 @@ discard block |
||
450 | 450 | $ticket_line_item, |
451 | 451 | EEM_Line_Item::type_cancellation |
452 | 452 | ); |
453 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
453 | + $cancellation_line_item = reset($cancellation_line_item); |
|
454 | 454 | // verify that this ticket was indeed previously cancelled |
455 | - if ( ! $cancellation_line_item instanceof EE_Line_Item ) { |
|
455 | + if ( ! $cancellation_line_item instanceof EE_Line_Item) { |
|
456 | 456 | return false; |
457 | 457 | } |
458 | - if ( $cancellation_line_item->quantity() > $qty ) { |
|
458 | + if ($cancellation_line_item->quantity() > $qty) { |
|
459 | 459 | // decrement cancelled quantity |
460 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
461 | - } else if ( $cancellation_line_item->quantity() == $qty ) { |
|
460 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
461 | + } else if ($cancellation_line_item->quantity() == $qty) { |
|
462 | 462 | // decrement cancelled quantity in case anyone still has the object kicking around |
463 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
463 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
464 | 464 | // delete because quantity will end up as 0 |
465 | 465 | $cancellation_line_item->delete(); |
466 | 466 | // and attempt to destroy the object, |
467 | 467 | // even though PHP won't actually destroy it until it needs the memory |
468 | - unset( $cancellation_line_item ); |
|
468 | + unset($cancellation_line_item); |
|
469 | 469 | } else { |
470 | 470 | // what ?!?! negative quantity ?!?! |
471 | 471 | throw new EE_Error( |
472 | 472 | sprintf( |
473 | - __( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
474 | - 'event_espresso' ), |
|
473 | + __('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
474 | + 'event_espresso'), |
|
475 | 475 | $qty, |
476 | 476 | $cancellation_line_item->quantity() |
477 | 477 | ) |
478 | 478 | ); |
479 | 479 | } |
480 | 480 | // increment ticket quantity |
481 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty ); |
|
482 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
481 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
482 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
483 | 483 | // increment parent line item quantity |
484 | 484 | $event_line_item = $ticket_line_item->parent(); |
485 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
486 | - $event_line_item->set_quantity( $event_line_item->quantity() + $qty ); |
|
485 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
486 | + $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
487 | 487 | } |
488 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
488 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
489 | 489 | return true; |
490 | 490 | } |
491 | 491 | return false; |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param EE_Line_Item $line_item |
501 | 501 | * @return \EE_Line_Item |
502 | 502 | */ |
503 | - public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){ |
|
504 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item ); |
|
503 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) { |
|
504 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
505 | 505 | return $grand_total_line_item->recalculate_total_including_taxes(); |
506 | 506 | } |
507 | 507 | |
@@ -514,11 +514,11 @@ discard block |
||
514 | 514 | * @return \EE_Line_Item |
515 | 515 | * @throws \EE_Error |
516 | 516 | */ |
517 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
518 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
517 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
518 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
519 | 519 | return $pre_tax_subtotal instanceof EE_Line_Item |
520 | 520 | ? $pre_tax_subtotal |
521 | - : self::create_pre_tax_subtotal( $total_line_item ); |
|
521 | + : self::create_pre_tax_subtotal($total_line_item); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | |
@@ -530,9 +530,9 @@ discard block |
||
530 | 530 | * @return \EE_Line_Item |
531 | 531 | * @throws \EE_Error |
532 | 532 | */ |
533 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
534 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
535 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
533 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
534 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
535 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | |
@@ -545,12 +545,12 @@ discard block |
||
545 | 545 | * @return void |
546 | 546 | * @throws \EE_Error |
547 | 547 | */ |
548 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
549 | - if( $transaction ){ |
|
548 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
549 | + if ($transaction) { |
|
550 | 550 | /** @type EEM_Transaction $EEM_Transaction */ |
551 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
552 | - $TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
553 | - $line_item->set_TXN_ID( $TXN_ID ); |
|
551 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
552 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
553 | + $line_item->set_TXN_ID($TXN_ID); |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | * @return \EE_Line_Item of type total |
566 | 566 | * @throws \EE_Error |
567 | 567 | */ |
568 | - public static function create_total_line_item( $transaction = NULL ){ |
|
569 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
568 | + public static function create_total_line_item($transaction = NULL) { |
|
569 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
570 | 570 | 'LIN_code' => 'total', |
571 | 571 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
572 | 572 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
577 | 577 | $total_line_item |
578 | 578 | ); |
579 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
580 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
581 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
579 | + self::set_TXN_ID($total_line_item, $transaction); |
|
580 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
581 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
582 | 582 | return $total_line_item; |
583 | 583 | } |
584 | 584 | |
@@ -592,19 +592,19 @@ discard block |
||
592 | 592 | * @return EE_Line_Item |
593 | 593 | * @throws \EE_Error |
594 | 594 | */ |
595 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
596 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
595 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
596 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
597 | 597 | 'LIN_code' => 'pre-tax-subtotal', |
598 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
598 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
599 | 599 | 'LIN_type' => EEM_Line_Item::type_sub_total |
600 | - ) ); |
|
600 | + )); |
|
601 | 601 | $pre_tax_line_item = apply_filters( |
602 | 602 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
603 | 603 | $pre_tax_line_item |
604 | 604 | ); |
605 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
606 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
607 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
605 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
606 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
607 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
608 | 608 | return $pre_tax_line_item; |
609 | 609 | } |
610 | 610 | |
@@ -619,21 +619,21 @@ discard block |
||
619 | 619 | * @return EE_Line_Item |
620 | 620 | * @throws \EE_Error |
621 | 621 | */ |
622 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
622 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
623 | 623 | $tax_line_item = EE_Line_Item::new_instance(array( |
624 | 624 | 'LIN_code' => 'taxes', |
625 | 625 | 'LIN_name' => __('Taxes', 'event_espresso'), |
626 | 626 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
627 | - 'LIN_order' => 1000,//this should always come last |
|
627 | + 'LIN_order' => 1000, //this should always come last |
|
628 | 628 | )); |
629 | 629 | $tax_line_item = apply_filters( |
630 | 630 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
631 | 631 | $tax_line_item |
632 | 632 | ); |
633 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
634 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
633 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
634 | + $total_line_item->add_child_line_item($tax_line_item); |
|
635 | 635 | //and lastly, add the actual taxes |
636 | - self::apply_taxes( $total_line_item ); |
|
636 | + self::apply_taxes($total_line_item); |
|
637 | 637 | return $tax_line_item; |
638 | 638 | } |
639 | 639 | |
@@ -648,11 +648,11 @@ discard block |
||
648 | 648 | * @return EE_Line_Item |
649 | 649 | * @throws \EE_Error |
650 | 650 | */ |
651 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
651 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
652 | 652 | $event_line_item = EE_Line_Item::new_instance(array( |
653 | - 'LIN_code' => self::get_event_code( $event ), |
|
654 | - 'LIN_name' => self::get_event_name( $event ), |
|
655 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
653 | + 'LIN_code' => self::get_event_code($event), |
|
654 | + 'LIN_name' => self::get_event_name($event), |
|
655 | + 'LIN_desc' => self::get_event_desc($event), |
|
656 | 656 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
657 | 657 | 'OBJ_type' => 'Event', |
658 | 658 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -661,8 +661,8 @@ discard block |
||
661 | 661 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
662 | 662 | $event_line_item |
663 | 663 | ); |
664 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
665 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
664 | + self::set_TXN_ID($event_line_item, $transaction); |
|
665 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
666 | 666 | return $event_line_item; |
667 | 667 | } |
668 | 668 | |
@@ -675,8 +675,8 @@ discard block |
||
675 | 675 | * @return string |
676 | 676 | * @throws \EE_Error |
677 | 677 | */ |
678 | - public static function get_event_code( $event ) { |
|
679 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
678 | + public static function get_event_code($event) { |
|
679 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | /** |
@@ -684,8 +684,8 @@ discard block |
||
684 | 684 | * @param EE_Event $event |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - public static function get_event_name( $event ) { |
|
688 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
687 | + public static function get_event_name($event) { |
|
688 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | /** |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | * @param EE_Event $event |
694 | 694 | * @return string |
695 | 695 | */ |
696 | - public static function get_event_desc( $event ) { |
|
696 | + public static function get_event_desc($event) { |
|
697 | 697 | return $event instanceof EE_Event ? $event->short_description() : ''; |
698 | 698 | } |
699 | 699 | |
@@ -707,27 +707,27 @@ discard block |
||
707 | 707 | * @throws \EE_Error |
708 | 708 | * @return EE_Line_Item |
709 | 709 | */ |
710 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
710 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
711 | 711 | $first_datetime = $ticket->first_datetime(); |
712 | - if ( ! $first_datetime instanceof EE_Datetime ) { |
|
712 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
713 | 713 | throw new EE_Error( |
714 | - sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) |
|
714 | + sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()) |
|
715 | 715 | ); |
716 | 716 | } |
717 | 717 | $event = $first_datetime->event(); |
718 | - if ( ! $event instanceof EE_Event ) { |
|
718 | + if ( ! $event instanceof EE_Event) { |
|
719 | 719 | throw new EE_Error( |
720 | 720 | sprintf( |
721 | - __( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ), |
|
721 | + __('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), |
|
722 | 722 | $ticket->ID() |
723 | 723 | ) |
724 | 724 | ); |
725 | 725 | } |
726 | - $events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
727 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
726 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
727 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
728 | 728 | throw new EE_Error( |
729 | 729 | sprintf( |
730 | - __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), |
|
730 | + __('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), |
|
731 | 731 | $ticket->ID(), |
732 | 732 | $grand_total->ID() |
733 | 733 | ) |
@@ -746,31 +746,31 @@ discard block |
||
746 | 746 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
747 | 747 | * @throws \EE_Error |
748 | 748 | */ |
749 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
749 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
750 | 750 | /** @type EE_Event $event */ |
751 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
751 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
752 | 752 | $event_line_item = NULL; |
753 | 753 | $found = false; |
754 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
754 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
755 | 755 | // default event subtotal, we should only ever find this the first time this method is called |
756 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
756 | + if ( ! $event_line_item->OBJ_ID()) { |
|
757 | 757 | // let's use this! but first... set the event details |
758 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
758 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
759 | 759 | $found = true; |
760 | 760 | break; |
761 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
761 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
762 | 762 | // found existing line item for this event in the cart, so break out of loop and use this one |
763 | 763 | $found = true; |
764 | 764 | break; |
765 | 765 | } |
766 | 766 | } |
767 | - if ( ! $found ) { |
|
767 | + if ( ! $found) { |
|
768 | 768 | //there is no event sub-total yet, so add it |
769 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
769 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
770 | 770 | // create a new "event" subtotal below that |
771 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
771 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
772 | 772 | // and set the event details |
773 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
773 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
774 | 774 | } |
775 | 775 | return $event_line_item; |
776 | 776 | } |
@@ -791,13 +791,13 @@ discard block |
||
791 | 791 | EE_Event $event, |
792 | 792 | $transaction = null |
793 | 793 | ) { |
794 | - if ( $event instanceof EE_Event ) { |
|
795 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
796 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
797 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
798 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
794 | + if ($event instanceof EE_Event) { |
|
795 | + $event_line_item->set_code(self::get_event_code($event)); |
|
796 | + $event_line_item->set_name(self::get_event_name($event)); |
|
797 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
798 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
799 | 799 | } |
800 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
800 | + self::set_TXN_ID($event_line_item, $transaction); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | |
@@ -810,19 +810,19 @@ discard block |
||
810 | 810 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
811 | 811 | * @throws \EE_Error |
812 | 812 | */ |
813 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
813 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
814 | 814 | /** @type EEM_Price $EEM_Price */ |
815 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
815 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
816 | 816 | // get array of taxes via Price Model |
817 | 817 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
818 | - ksort( $ordered_taxes ); |
|
819 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
818 | + ksort($ordered_taxes); |
|
819 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
820 | 820 | //just to be safe, remove its old tax line items |
821 | 821 | $taxes_line_item->delete_children_line_items(); |
822 | 822 | //loop thru taxes |
823 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
824 | - foreach ( $taxes as $tax ) { |
|
825 | - if ( $tax instanceof EE_Price ) { |
|
823 | + foreach ($ordered_taxes as $order => $taxes) { |
|
824 | + foreach ($taxes as $tax) { |
|
825 | + if ($tax instanceof EE_Price) { |
|
826 | 826 | $tax_line_item = EE_Line_Item::new_instance( |
827 | 827 | array( |
828 | 828 | 'LIN_name' => $tax->name(), |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
841 | 841 | $tax_line_item |
842 | 842 | ); |
843 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
843 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
844 | 844 | } |
845 | 845 | } |
846 | 846 | } |
@@ -857,10 +857,10 @@ discard block |
||
857 | 857 | * @return float |
858 | 858 | * @throws \EE_Error |
859 | 859 | */ |
860 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
861 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
862 | - if( ! $taxes_subtotal->children()){ |
|
863 | - self::apply_taxes( $total_line_item ); |
|
860 | + public static function ensure_taxes_applied($total_line_item) { |
|
861 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
862 | + if ( ! $taxes_subtotal->children()) { |
|
863 | + self::apply_taxes($total_line_item); |
|
864 | 864 | } |
865 | 865 | return $taxes_subtotal->total(); |
866 | 866 | } |
@@ -874,16 +874,16 @@ discard block |
||
874 | 874 | * @return bool |
875 | 875 | * @throws \EE_Error |
876 | 876 | */ |
877 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
877 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
878 | 878 | $deleted = 0; |
879 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
880 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
881 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
882 | - if ( $child_line_item->ID() ) { |
|
879 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
880 | + if ($child_line_item instanceof EE_Line_Item) { |
|
881 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
882 | + if ($child_line_item->ID()) { |
|
883 | 883 | $child_line_item->delete(); |
884 | - unset( $child_line_item ); |
|
884 | + unset($child_line_item); |
|
885 | 885 | } else { |
886 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
886 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
887 | 887 | } |
888 | 888 | $deleted++; |
889 | 889 | } |
@@ -905,9 +905,9 @@ discard block |
||
905 | 905 | * @param array|bool|string $line_item_codes |
906 | 906 | * @return int number of items successfully removed |
907 | 907 | */ |
908 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
908 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
909 | 909 | |
910 | - if( $total_line_item->type() !== EEM_Line_Item::type_total ){ |
|
910 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
911 | 911 | EE_Error::doing_it_wrong( |
912 | 912 | 'EEH_Line_Item::delete_items', |
913 | 913 | __( |
@@ -917,20 +917,20 @@ discard block |
||
917 | 917 | '4.6.18' |
918 | 918 | ); |
919 | 919 | } |
920 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
920 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
921 | 921 | |
922 | 922 | // check if only a single line_item_id was passed |
923 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
923 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
924 | 924 | // place single line_item_id in an array to appear as multiple line_item_ids |
925 | - $line_item_codes = array ( $line_item_codes ); |
|
925 | + $line_item_codes = array($line_item_codes); |
|
926 | 926 | } |
927 | 927 | $removals = 0; |
928 | 928 | // cycle thru line_item_ids |
929 | - foreach ( $line_item_codes as $line_item_id ) { |
|
929 | + foreach ($line_item_codes as $line_item_id) { |
|
930 | 930 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
931 | 931 | } |
932 | 932 | |
933 | - if ( $removals > 0 ) { |
|
933 | + if ($removals > 0) { |
|
934 | 934 | $total_line_item->recalculate_taxes_and_tax_total(); |
935 | 935 | return $removals; |
936 | 936 | } else { |
@@ -963,33 +963,33 @@ discard block |
||
963 | 963 | $code = null, |
964 | 964 | $add_to_existing_line_item = false |
965 | 965 | ) { |
966 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
966 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
967 | 967 | $taxable_total = $total_line_item->taxable_total(); |
968 | 968 | |
969 | - if( $add_to_existing_line_item ) { |
|
970 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
969 | + if ($add_to_existing_line_item) { |
|
970 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
971 | 971 | EEM_Line_Item::instance()->delete( |
972 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
972 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
973 | 973 | ); |
974 | 974 | } else { |
975 | 975 | $new_tax = null; |
976 | 976 | $tax_subtotal->delete_children_line_items(); |
977 | 977 | } |
978 | - if( $new_tax ) { |
|
979 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
980 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
978 | + if ($new_tax) { |
|
979 | + $new_tax->set_total($new_tax->total() + $amount); |
|
980 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
981 | 981 | } else { |
982 | 982 | //no existing tax item. Create it |
983 | - $new_tax = EE_Line_Item::new_instance( array( |
|
983 | + $new_tax = EE_Line_Item::new_instance(array( |
|
984 | 984 | 'TXN_ID' => $total_line_item->TXN_ID(), |
985 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
985 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
986 | 986 | 'LIN_desc' => $description ? $description : '', |
987 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
987 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
988 | 988 | 'LIN_total' => $amount, |
989 | 989 | 'LIN_parent' => $tax_subtotal->ID(), |
990 | 990 | 'LIN_type' => EEM_Line_Item::type_tax, |
991 | 991 | 'LIN_code' => $code |
992 | - ) ); |
|
992 | + )); |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | $new_tax = apply_filters( |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | $total_line_item |
999 | 999 | ); |
1000 | 1000 | $new_tax->save(); |
1001 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
1001 | + $tax_subtotal->set_total($new_tax->total()); |
|
1002 | 1002 | $tax_subtotal->save(); |
1003 | 1003 | $total_line_item->recalculate_total_including_taxes(); |
1004 | 1004 | return $new_tax; |
@@ -1020,14 +1020,14 @@ discard block |
||
1020 | 1020 | $code_substring_for_whitelist = null |
1021 | 1021 | ) { |
1022 | 1022 | $whitelisted = false; |
1023 | - if( $code_substring_for_whitelist !== null ) { |
|
1024 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
1023 | + if ($code_substring_for_whitelist !== null) { |
|
1024 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
1025 | 1025 | } |
1026 | - if( ! $whitelisted && $line_item->is_line_item() ) { |
|
1027 | - $line_item->set_is_taxable( $taxable ); |
|
1026 | + if ( ! $whitelisted && $line_item->is_line_item()) { |
|
1027 | + $line_item->set_is_taxable($taxable); |
|
1028 | 1028 | } |
1029 | - foreach( $line_item->children() as $child_line_item ) { |
|
1030 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
1029 | + foreach ($line_item->children() as $child_line_item) { |
|
1030 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
1031 | 1031 | } |
1032 | 1032 | } |
1033 | 1033 | |
@@ -1040,8 +1040,8 @@ discard block |
||
1040 | 1040 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1041 | 1041 | * @return EE_Line_Item[] |
1042 | 1042 | */ |
1043 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
1044 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
1043 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
1044 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | * @param string $obj_type |
1055 | 1055 | * @return EE_Line_Item[] |
1056 | 1056 | */ |
1057 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1057 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1058 | 1058 | return self::_get_descendants_by_type_and_object_type( |
1059 | 1059 | $parent_line_item, |
1060 | 1060 | EEM_Line_Item::type_sub_total, |
@@ -1071,8 +1071,8 @@ discard block |
||
1071 | 1071 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1072 | 1072 | * @return EE_Line_Item[] |
1073 | 1073 | */ |
1074 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
1075 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
1074 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
1075 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | 1078 | |
@@ -1085,8 +1085,8 @@ discard block |
||
1085 | 1085 | * @param string $obj_type |
1086 | 1086 | * @return EE_Line_Item[] |
1087 | 1087 | */ |
1088 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1089 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
1088 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1089 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1098 | 1098 | * @return EE_Line_Item[] |
1099 | 1099 | */ |
1100 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
1101 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
1100 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
1101 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | |
@@ -1109,8 +1109,8 @@ discard block |
||
1109 | 1109 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1110 | 1110 | * @return EE_Line_Item[] |
1111 | 1111 | */ |
1112 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
1113 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
1112 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
1113 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
1114 | 1114 | } |
1115 | 1115 | |
1116 | 1116 | |
@@ -1123,8 +1123,8 @@ discard block |
||
1123 | 1123 | * @param string $line_item_type one of the EEM_Line_Item constants |
1124 | 1124 | * @return EE_Line_Item[] |
1125 | 1125 | */ |
1126 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
1127 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
1126 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
1127 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | |
@@ -1143,8 +1143,8 @@ discard block |
||
1143 | 1143 | $obj_type = null |
1144 | 1144 | ) { |
1145 | 1145 | $objects = array(); |
1146 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1147 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1146 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1147 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1148 | 1148 | if ( |
1149 | 1149 | $child_line_item->type() === $line_item_type |
1150 | 1150 | && ( |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | $OBJ_type = '', |
1185 | 1185 | $OBJ_IDs = array() |
1186 | 1186 | ) { |
1187 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
1187 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | |
@@ -1203,12 +1203,12 @@ discard block |
||
1203 | 1203 | $OBJ_IDs |
1204 | 1204 | ) { |
1205 | 1205 | $objects = array(); |
1206 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1207 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1206 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1207 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1208 | 1208 | if ( |
1209 | 1209 | $child_line_item->OBJ_type() === $OBJ_type |
1210 | - && is_array( $OBJ_IDs ) |
|
1211 | - && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs ) |
|
1210 | + && is_array($OBJ_IDs) |
|
1211 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
1212 | 1212 | ) { |
1213 | 1213 | $objects[] = $child_line_item; |
1214 | 1214 | } else { |
@@ -1238,8 +1238,8 @@ discard block |
||
1238 | 1238 | * @param string $type like one of the EEM_Line_Item::type_* |
1239 | 1239 | * @return EE_Line_Item |
1240 | 1240 | */ |
1241 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
1242 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
1241 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
1242 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
1243 | 1243 | } |
1244 | 1244 | |
1245 | 1245 | |
@@ -1253,8 +1253,8 @@ discard block |
||
1253 | 1253 | * @param string $code any value used for LIN_code |
1254 | 1254 | * @return EE_Line_Item |
1255 | 1255 | */ |
1256 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
1257 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
1256 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
1257 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
1258 | 1258 | } |
1259 | 1259 | |
1260 | 1260 | |
@@ -1268,15 +1268,15 @@ discard block |
||
1268 | 1268 | * @param string $value any value stored in $search_field |
1269 | 1269 | * @return EE_Line_Item |
1270 | 1270 | */ |
1271 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
1272 | - foreach( $parent_line_item->children() as $child ){ |
|
1273 | - if ( $child->get( $search_field ) == $value ){ |
|
1271 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
1272 | + foreach ($parent_line_item->children() as $child) { |
|
1273 | + if ($child->get($search_field) == $value) { |
|
1274 | 1274 | return $child; |
1275 | 1275 | } |
1276 | 1276 | } |
1277 | - foreach( $parent_line_item->children() as $child ){ |
|
1278 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
1279 | - if ( $descendant_found ){ |
|
1277 | + foreach ($parent_line_item->children() as $child) { |
|
1278 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
1279 | + if ($descendant_found) { |
|
1280 | 1280 | return $descendant_found; |
1281 | 1281 | } |
1282 | 1282 | } |
@@ -1293,24 +1293,24 @@ discard block |
||
1293 | 1293 | * @return \EE_Line_Item |
1294 | 1294 | * @throws \EE_Error |
1295 | 1295 | */ |
1296 | - public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){ |
|
1297 | - if ( $line_item->TXN_ID() ) { |
|
1298 | - $total_line_item = $line_item->transaction()->total_line_item( false ); |
|
1299 | - if ( $total_line_item instanceof EE_Line_Item ) { |
|
1296 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) { |
|
1297 | + if ($line_item->TXN_ID()) { |
|
1298 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
1299 | + if ($total_line_item instanceof EE_Line_Item) { |
|
1300 | 1300 | return $total_line_item; |
1301 | 1301 | } |
1302 | 1302 | } else { |
1303 | 1303 | $line_item_parent = $line_item->parent(); |
1304 | - if ( $line_item_parent instanceof EE_Line_Item ) { |
|
1305 | - if ( $line_item_parent->is_total() ) { |
|
1304 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
1305 | + if ($line_item_parent->is_total()) { |
|
1306 | 1306 | return $line_item_parent; |
1307 | 1307 | } |
1308 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent ); |
|
1308 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
1309 | 1309 | } |
1310 | 1310 | } |
1311 | 1311 | throw new EE_Error( |
1312 | 1312 | sprintf( |
1313 | - __( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ), |
|
1313 | + __('A valid grand total for line item %1$d was not found.', 'event_espresso'), |
|
1314 | 1314 | $line_item->ID() |
1315 | 1315 | ) |
1316 | 1316 | ); |
@@ -1327,31 +1327,31 @@ discard block |
||
1327 | 1327 | * @return void |
1328 | 1328 | * @throws \EE_Error |
1329 | 1329 | */ |
1330 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
1330 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
1331 | 1331 | echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
1332 | - if ( ! $indentation ) { |
|
1333 | - echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />'; |
|
1332 | + if ( ! $indentation) { |
|
1333 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1334 | 1334 | } |
1335 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
1335 | + for ($i = 0; $i < $indentation; $i++) { |
|
1336 | 1336 | echo ". "; |
1337 | 1337 | } |
1338 | 1338 | $breakdown = ''; |
1339 | - if ( $line_item->is_line_item()){ |
|
1340 | - if ( $line_item->is_percent() ) { |
|
1339 | + if ($line_item->is_line_item()) { |
|
1340 | + if ($line_item->is_percent()) { |
|
1341 | 1341 | $breakdown = "{$line_item->percent()}%"; |
1342 | 1342 | } else { |
1343 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1343 | + $breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1344 | 1344 | } |
1345 | 1345 | } |
1346 | - echo $line_item->name() . " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : " . '$' . "{$line_item->total()}"; |
|
1347 | - if ( $breakdown ) { |
|
1346 | + echo $line_item->name()." [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ".'$'."{$line_item->total()}"; |
|
1347 | + if ($breakdown) { |
|
1348 | 1348 | echo " ( {$breakdown} )"; |
1349 | 1349 | } |
1350 | - if( $line_item->is_taxable() ){ |
|
1350 | + if ($line_item->is_taxable()) { |
|
1351 | 1351 | echo " * taxable"; |
1352 | 1352 | } |
1353 | - if( $line_item->children() ){ |
|
1354 | - foreach($line_item->children() as $child){ |
|
1353 | + if ($line_item->children()) { |
|
1354 | + foreach ($line_item->children() as $child) { |
|
1355 | 1355 | self::visualize($child, $indentation + 1); |
1356 | 1356 | } |
1357 | 1357 | } |
@@ -1392,97 +1392,97 @@ discard block |
||
1392 | 1392 | * is theirs, which can be done with |
1393 | 1393 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
1394 | 1394 | */ |
1395 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
1395 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
1396 | 1396 | //init running grand total if not already |
1397 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
1398 | - $running_totals[ 'total' ] = 0; |
|
1397 | + if ( ! isset($running_totals['total'])) { |
|
1398 | + $running_totals['total'] = 0; |
|
1399 | 1399 | } |
1400 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
1401 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
1400 | + if ( ! isset($running_totals['taxable'])) { |
|
1401 | + $running_totals['taxable'] = array('total' => 0); |
|
1402 | 1402 | } |
1403 | - foreach ( $line_item->children() as $child_line_item ) { |
|
1404 | - switch ( $child_line_item->type() ) { |
|
1403 | + foreach ($line_item->children() as $child_line_item) { |
|
1404 | + switch ($child_line_item->type()) { |
|
1405 | 1405 | |
1406 | 1406 | case EEM_Line_Item::type_sub_total : |
1407 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
1407 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
1408 | 1408 | //combine arrays but preserve numeric keys |
1409 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
1410 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
1411 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
1409 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
1410 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
1411 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
1412 | 1412 | break; |
1413 | 1413 | |
1414 | 1414 | case EEM_Line_Item::type_tax_sub_total : |
1415 | 1415 | |
1416 | 1416 | //find how much the taxes percentage is |
1417 | - if ( $child_line_item->percent() !== 0 ) { |
|
1417 | + if ($child_line_item->percent() !== 0) { |
|
1418 | 1418 | $tax_percent_decimal = $child_line_item->percent() / 100; |
1419 | 1419 | } else { |
1420 | 1420 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
1421 | 1421 | } |
1422 | 1422 | //and apply to all the taxable totals, and add to the pretax totals |
1423 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1423 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1424 | 1424 | //"total" and "taxable" array key is an exception |
1425 | - if ( $line_item_id === 'taxable' ) { |
|
1425 | + if ($line_item_id === 'taxable') { |
|
1426 | 1426 | continue; |
1427 | 1427 | } |
1428 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1429 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
1428 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
1429 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
1430 | 1430 | } |
1431 | 1431 | break; |
1432 | 1432 | |
1433 | 1433 | case EEM_Line_Item::type_line_item : |
1434 | 1434 | |
1435 | 1435 | // ticket line items or ???? |
1436 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
1436 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
1437 | 1437 | // kk it's a ticket |
1438 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
1438 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
1439 | 1439 | //huh? that shouldn't happen. |
1440 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
1440 | + $running_totals['total'] += $child_line_item->total(); |
|
1441 | 1441 | } else { |
1442 | 1442 | //its not in our running totals yet. great. |
1443 | - if ( $child_line_item->is_taxable() ) { |
|
1443 | + if ($child_line_item->is_taxable()) { |
|
1444 | 1444 | $taxable_amount = $child_line_item->unit_price(); |
1445 | 1445 | } else { |
1446 | 1446 | $taxable_amount = 0; |
1447 | 1447 | } |
1448 | 1448 | // are we only calculating totals for some tickets? |
1449 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
1450 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
1451 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
1449 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
1450 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
1451 | + $running_totals[$child_line_item->ID()] = $quantity |
|
1452 | 1452 | ? $child_line_item->unit_price() |
1453 | 1453 | : 0; |
1454 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity |
|
1454 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity |
|
1455 | 1455 | ? $taxable_amount |
1456 | 1456 | : 0; |
1457 | 1457 | } else { |
1458 | 1458 | $quantity = $child_line_item->quantity(); |
1459 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
1460 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
1459 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
1460 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
1461 | 1461 | } |
1462 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
1463 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
1462 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
1463 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
1464 | 1464 | } |
1465 | 1465 | } else { |
1466 | 1466 | // it's some other type of item added to the cart |
1467 | 1467 | // it should affect the running totals |
1468 | 1468 | // basically we want to convert it into a PERCENT modifier. Because |
1469 | 1469 | // more clearly affect all registration's final price equally |
1470 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 |
|
1471 | - ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 |
|
1470 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
1471 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
1472 | 1472 | : 1; |
1473 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1473 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1474 | 1474 | //the "taxable" array key is an exception |
1475 | - if ( $line_item_id === 'taxable' ) { |
|
1475 | + if ($line_item_id === 'taxable') { |
|
1476 | 1476 | continue; |
1477 | 1477 | } |
1478 | 1478 | // update the running totals |
1479 | 1479 | // yes this actually even works for the running grand total! |
1480 | - $running_totals[ $line_item_id ] = |
|
1480 | + $running_totals[$line_item_id] = |
|
1481 | 1481 | $line_items_percent_of_running_total * $this_running_total; |
1482 | 1482 | |
1483 | - if ( $child_line_item->is_taxable() ) { |
|
1484 | - $running_totals[ 'taxable' ][ $line_item_id ] = |
|
1485 | - $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1483 | + if ($child_line_item->is_taxable()) { |
|
1484 | + $running_totals['taxable'][$line_item_id] = |
|
1485 | + $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
1486 | 1486 | } |
1487 | 1487 | } |
1488 | 1488 | } |
@@ -1500,16 +1500,16 @@ discard block |
||
1500 | 1500 | * @return float | null |
1501 | 1501 | * @throws \OutOfRangeException |
1502 | 1502 | */ |
1503 | - public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) { |
|
1503 | + public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) { |
|
1504 | 1504 | static $final_prices_per_ticket_line_item = array(); |
1505 | - if ( empty( $final_prices_per_ticket_line_item ) ) { |
|
1505 | + if (empty($final_prices_per_ticket_line_item)) { |
|
1506 | 1506 | $final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
1507 | 1507 | $total_line_item |
1508 | 1508 | ); |
1509 | 1509 | } |
1510 | 1510 | //ok now find this new registration's final price |
1511 | - if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) { |
|
1512 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
1511 | + if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) { |
|
1512 | + return $final_prices_per_ticket_line_item[$ticket_line_item->ID()]; |
|
1513 | 1513 | } |
1514 | 1514 | $message = sprintf( |
1515 | 1515 | __( |
@@ -1518,11 +1518,11 @@ discard block |
||
1518 | 1518 | ), |
1519 | 1519 | $ticket_line_item->ID() |
1520 | 1520 | ); |
1521 | - if ( WP_DEBUG ) { |
|
1522 | - $message .= '<br>' . print_r( $final_prices_per_ticket_line_item, true ); |
|
1523 | - throw new \OutOfRangeException( $message ); |
|
1521 | + if (WP_DEBUG) { |
|
1522 | + $message .= '<br>'.print_r($final_prices_per_ticket_line_item, true); |
|
1523 | + throw new \OutOfRangeException($message); |
|
1524 | 1524 | } else { |
1525 | - EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message ); |
|
1525 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
1526 | 1526 | } |
1527 | 1527 | return null; |
1528 | 1528 | } |
@@ -1538,15 +1538,15 @@ discard block |
||
1538 | 1538 | * @return \EE_Line_Item |
1539 | 1539 | * @throws \EE_Error |
1540 | 1540 | */ |
1541 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
1542 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
1543 | - foreach ( $line_item->children() as $child_li ) { |
|
1544 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
1541 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
1542 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
1543 | + foreach ($line_item->children() as $child_li) { |
|
1544 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
1545 | 1545 | } |
1546 | 1546 | //if this is the grand total line item, make sure the totals all add up |
1547 | 1547 | //(we could have duplicated this logic AS we copied the line items, but |
1548 | 1548 | //it seems DRYer this way) |
1549 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
1549 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
1550 | 1550 | $copy_li->recalculate_total_including_taxes(); |
1551 | 1551 | } |
1552 | 1552 | return $copy_li; |
@@ -1563,24 +1563,24 @@ discard block |
||
1563 | 1563 | * @throws \EE_Error |
1564 | 1564 | * @param EE_Registration[] $registrations |
1565 | 1565 | */ |
1566 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
1566 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
1567 | 1567 | $new_li_fields = $line_item->model_field_array(); |
1568 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1568 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1569 | 1569 | $line_item->OBJ_type() === 'Ticket' |
1570 | 1570 | ) { |
1571 | 1571 | $count = 0; |
1572 | - foreach ( $registrations as $registration ) { |
|
1573 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1574 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
1572 | + foreach ($registrations as $registration) { |
|
1573 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1574 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
1575 | 1575 | ) { |
1576 | 1576 | $count++; |
1577 | 1577 | } |
1578 | 1578 | } |
1579 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
1579 | + $new_li_fields['LIN_quantity'] = $count; |
|
1580 | 1580 | } |
1581 | 1581 | //don't set the total. We'll leave that up to the code that calculates it |
1582 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] ); |
|
1583 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1582 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
1583 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1584 | 1584 | } |
1585 | 1585 | |
1586 | 1586 | |
@@ -1593,19 +1593,19 @@ discard block |
||
1593 | 1593 | * @return \EE_Line_Item|null |
1594 | 1594 | * @throws \EE_Error |
1595 | 1595 | */ |
1596 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
1597 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
1598 | - if ( $copied_li === null ) { |
|
1596 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
1597 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
1598 | + if ($copied_li === null) { |
|
1599 | 1599 | return null; |
1600 | 1600 | } |
1601 | 1601 | //if this is an event subtotal, we want to only include it if it |
1602 | 1602 | //has a non-zero total and at least one ticket line item child |
1603 | 1603 | $ticket_children = 0; |
1604 | - foreach ( $line_item->children() as $child_li ) { |
|
1605 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
1606 | - if ( $child_li_copy !== null ) { |
|
1607 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
1608 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1604 | + foreach ($line_item->children() as $child_li) { |
|
1605 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
1606 | + if ($child_li_copy !== null) { |
|
1607 | + $copied_li->add_child_line_item($child_li_copy); |
|
1608 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1609 | 1609 | $child_li_copy->OBJ_type() === 'Ticket' |
1610 | 1610 | ) { |
1611 | 1611 | $ticket_children++; |
@@ -1635,8 +1635,8 @@ discard block |
||
1635 | 1635 | * @return EE_Line_Item |
1636 | 1636 | * @throws \EE_Error |
1637 | 1637 | */ |
1638 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
1639 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1638 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
1639 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1640 | 1640 | $line_item->OBJ_type() === 'Ticket' && |
1641 | 1641 | $line_item->quantity() === 0 |
1642 | 1642 | ) { |
@@ -1644,8 +1644,8 @@ discard block |
||
1644 | 1644 | } |
1645 | 1645 | $new_li_fields = $line_item->model_field_array(); |
1646 | 1646 | //don't set the total. We'll leave that up to the code that calculates it |
1647 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] ); |
|
1648 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1647 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
1648 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1649 | 1649 | } |
1650 | 1650 | |
1651 | 1651 | |
@@ -1657,9 +1657,9 @@ discard block |
||
1657 | 1657 | * @return \EE_Line_Item |
1658 | 1658 | * @throws \EE_Error |
1659 | 1659 | */ |
1660 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
1661 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1662 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
1660 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
1661 | + EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1662 | + return self::get_pre_tax_subtotal($total_line_item); |
|
1663 | 1663 | } |
1664 | 1664 | |
1665 | 1665 | |
@@ -1670,9 +1670,9 @@ discard block |
||
1670 | 1670 | * @return \EE_Line_Item |
1671 | 1671 | * @throws \EE_Error |
1672 | 1672 | */ |
1673 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
1674 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' ); |
|
1675 | - return self::create_total_line_item( $transaction ); |
|
1673 | + public static function create_default_total_line_item($transaction = NULL) { |
|
1674 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0'); |
|
1675 | + return self::create_total_line_item($transaction); |
|
1676 | 1676 | } |
1677 | 1677 | |
1678 | 1678 | |
@@ -1684,9 +1684,9 @@ discard block |
||
1684 | 1684 | * @return \EE_Line_Item |
1685 | 1685 | * @throws \EE_Error |
1686 | 1686 | */ |
1687 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1688 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1689 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
1687 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1688 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1689 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
1690 | 1690 | } |
1691 | 1691 | |
1692 | 1692 | |
@@ -1698,9 +1698,9 @@ discard block |
||
1698 | 1698 | * @return \EE_Line_Item |
1699 | 1699 | * @throws \EE_Error |
1700 | 1700 | */ |
1701 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1702 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1703 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
1701 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1702 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0'); |
|
1703 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
1704 | 1704 | } |
1705 | 1705 | |
1706 | 1706 | |
@@ -1712,9 +1712,9 @@ discard block |
||
1712 | 1712 | * @return \EE_Line_Item |
1713 | 1713 | * @throws \EE_Error |
1714 | 1714 | */ |
1715 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1716 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1717 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
1715 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1716 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0'); |
|
1717 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
1718 | 1718 | } |
1719 | 1719 | |
1720 | 1720 |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | |
211 | 211 | default : |
212 | 212 | return $pretty |
213 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
214 | - : $this->_date_format . ' ' . $this->_time_format; |
|
213 | + ? $this->_pretty_date_format.' '.$this->_pretty_time_format |
|
214 | + : $this->_date_format.' '.$this->_time_format; |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | */ |
468 | 468 | protected function _prepare_for_display($DateTime, $schema = false) |
469 | 469 | { |
470 | - if (! $DateTime instanceof DateTime) { |
|
470 | + if ( ! $DateTime instanceof DateTime) { |
|
471 | 471 | if ($this->_nullable) { |
472 | 472 | return ''; |
473 | 473 | } else { |
@@ -502,15 +502,15 @@ discard block |
||
502 | 502 | if ($this->_display_timezone()) { |
503 | 503 | //must be explicit because schema could equal true. |
504 | 504 | if ($schema === 'no_html') { |
505 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
505 | + $timezone_string = ' ('.$DateTime->format('T').')'; |
|
506 | 506 | } else { |
507 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
507 | + $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>'; |
|
508 | 508 | } |
509 | 509 | } else { |
510 | 510 | $timezone_string = ''; |
511 | 511 | } |
512 | 512 | |
513 | - return $DateTime->format($format_string) . $timezone_string; |
|
513 | + return $DateTime->format($format_string).$timezone_string; |
|
514 | 514 | } else { |
515 | 515 | return $DateTime->format($format_string); |
516 | 516 | } |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | public function prepare_for_use_in_db($datetime_value) |
529 | 529 | { |
530 | 530 | //we allow an empty value or DateTime object, but nothing else. |
531 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
531 | + if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
532 | 532 | throw new EE_Error( |
533 | 533 | sprintf( |
534 | 534 | __( |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | } |
589 | 589 | } |
590 | 590 | |
591 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
591 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
592 | 592 | // if still no datetime object, then let's just use now |
593 | 593 | $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
594 | 594 | } |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | } |
668 | 668 | //not a unix timestamp. So we will use the set format on this object and set timezone to |
669 | 669 | //create the DateTime object. |
670 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
670 | + $format = $this->_date_format.' '.$this->_time_format; |
|
671 | 671 | try { |
672 | 672 | $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
673 | 673 | if ($DateTime instanceof DateTime) { |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | $this->_DateTimeZone |
677 | 677 | ); |
678 | 678 | } |
679 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
679 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
680 | 680 | throw new EE_Error( |
681 | 681 | sprintf( |
682 | 682 | __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
@@ -15,760 +15,760 @@ |
||
15 | 15 | class EE_Datetime_Field extends EE_Model_Field_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
20 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
21 | - * |
|
22 | - * @type string unix_timestamp_regex |
|
23 | - */ |
|
24 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type string mysql_timestamp_format |
|
28 | - */ |
|
29 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
30 | - |
|
31 | - /** |
|
32 | - * @type string mysql_date_format |
|
33 | - */ |
|
34 | - const mysql_date_format = 'Y-m-d'; |
|
35 | - |
|
36 | - /** |
|
37 | - * @type string mysql_time_format |
|
38 | - */ |
|
39 | - const mysql_time_format = 'H:i:s'; |
|
40 | - |
|
41 | - /** |
|
42 | - * Const for using in the default value. If the field's default is set to this, |
|
43 | - * then we will return the time of calling `get_default_value()`, not |
|
44 | - * just the current time at construction |
|
45 | - */ |
|
46 | - const now = 'now'; |
|
47 | - |
|
48 | - /** |
|
49 | - * The following properties hold the default formats for date and time. |
|
50 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
51 | - * However they can also be overridden later by the set_format() method |
|
52 | - * (and corresponding set_date_format, set_time_format methods); |
|
53 | - */ |
|
54 | - /** |
|
55 | - * @type string $_date_format |
|
56 | - */ |
|
57 | - protected $_date_format = ''; |
|
58 | - |
|
59 | - /** |
|
60 | - * @type string $_time_format |
|
61 | - */ |
|
62 | - protected $_time_format = ''; |
|
63 | - |
|
64 | - /** |
|
65 | - * @type string $_pretty_date_format |
|
66 | - */ |
|
67 | - protected $_pretty_date_format = ''; |
|
68 | - |
|
69 | - /** |
|
70 | - * @type string $_pretty_time_format |
|
71 | - */ |
|
72 | - protected $_pretty_time_format = ''; |
|
73 | - |
|
74 | - /** |
|
75 | - * @type DateTimeZone $_DateTimeZone |
|
76 | - */ |
|
77 | - protected $_DateTimeZone; |
|
78 | - |
|
79 | - /** |
|
80 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
81 | - */ |
|
82 | - protected $_UTC_DateTimeZone; |
|
83 | - |
|
84 | - /** |
|
85 | - * @type DateTimeZone $_blog_DateTimeZone |
|
86 | - */ |
|
87 | - protected $_blog_DateTimeZone; |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
92 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
93 | - * and time returned via getters. |
|
94 | - * |
|
95 | - * @var mixed (null|string) |
|
96 | - */ |
|
97 | - protected $_date_time_output; |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * timezone string |
|
102 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
108 | - protected $_timezone_string; |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
113 | - * offsets for comparison purposes). |
|
114 | - * |
|
115 | - * @var int |
|
116 | - */ |
|
117 | - protected $_blog_offset; |
|
118 | - |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param string $table_column |
|
123 | - * @param string $nice_name |
|
124 | - * @param bool $nullable |
|
125 | - * @param string $default_value |
|
126 | - * @param string $timezone_string |
|
127 | - * @param string $date_format |
|
128 | - * @param string $time_format |
|
129 | - * @param string $pretty_date_format |
|
130 | - * @param string $pretty_time_format |
|
131 | - * @throws EE_Error |
|
132 | - * @throws InvalidArgumentException |
|
133 | - */ |
|
134 | - public function __construct( |
|
135 | - $table_column, |
|
136 | - $nice_name, |
|
137 | - $nullable, |
|
138 | - $default_value, |
|
139 | - $timezone_string = '', |
|
140 | - $date_format = '', |
|
141 | - $time_format = '', |
|
142 | - $pretty_date_format = '', |
|
143 | - $pretty_time_format = '' |
|
144 | - ) { |
|
145 | - |
|
146 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
147 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
148 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
149 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
150 | - |
|
151 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
152 | - $this->set_timezone($timezone_string); |
|
153 | - $this->setSchemaFormat('date-time'); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return DateTimeZone |
|
159 | - * @throws \EE_Error |
|
160 | - */ |
|
161 | - public function get_UTC_DateTimeZone() |
|
162 | - { |
|
163 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
164 | - ? $this->_UTC_DateTimeZone |
|
165 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @return DateTimeZone |
|
171 | - * @throws \EE_Error |
|
172 | - */ |
|
173 | - public function get_blog_DateTimeZone() |
|
174 | - { |
|
175 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
176 | - ? $this->_blog_DateTimeZone |
|
177 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
183 | - * |
|
184 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
185 | - * timestamp |
|
186 | - * @return DateTime |
|
187 | - */ |
|
188 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
189 | - { |
|
190 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
196 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
197 | - * |
|
198 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
199 | - * @return string The final assembled format string. |
|
200 | - */ |
|
201 | - protected function _get_date_time_output($pretty = false) |
|
202 | - { |
|
203 | - |
|
204 | - switch ($this->_date_time_output) { |
|
205 | - case 'time' : |
|
206 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
207 | - break; |
|
208 | - |
|
209 | - case 'date' : |
|
210 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
211 | - break; |
|
212 | - |
|
213 | - default : |
|
214 | - return $pretty |
|
215 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
216 | - : $this->_date_format . ' ' . $this->_time_format; |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
223 | - * returned (using the format properties) |
|
224 | - * |
|
225 | - * @param string $what acceptable values are 'time' or 'date'. |
|
226 | - * Any other value will be set but will always result |
|
227 | - * in both 'date' and 'time' being returned. |
|
228 | - * @return void |
|
229 | - */ |
|
230 | - public function set_date_time_output($what = null) |
|
231 | - { |
|
232 | - $this->_date_time_output = $what; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
238 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
239 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
240 | - * We also set some other properties in this method. |
|
241 | - * |
|
242 | - * @param string $timezone_string A valid timezone string as described by @link |
|
243 | - * http://www.php.net/manual/en/timezones.php |
|
244 | - * @return void |
|
245 | - * @throws \EE_Error |
|
246 | - */ |
|
247 | - public function set_timezone($timezone_string) |
|
248 | - { |
|
249 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
250 | - // leave the timezone AS-IS if we already have one and |
|
251 | - // the function arg didn't provide one |
|
252 | - return; |
|
253 | - } |
|
254 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
255 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
256 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * _create_timezone_object_from_timezone_name |
|
262 | - * |
|
263 | - * @access protected |
|
264 | - * @param string $timezone_string |
|
265 | - * @return \DateTimeZone |
|
266 | - * @throws \EE_Error |
|
267 | - */ |
|
268 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
269 | - { |
|
270 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * This just returns whatever is set for the current timezone. |
|
276 | - * |
|
277 | - * @access public |
|
278 | - * @return string timezone string |
|
279 | - */ |
|
280 | - public function get_timezone() |
|
281 | - { |
|
282 | - return $this->_timezone_string; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * set the $_date_format property |
|
288 | - * |
|
289 | - * @access public |
|
290 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
291 | - * @param bool $pretty Whether to set pretty format or not. |
|
292 | - * @return void |
|
293 | - */ |
|
294 | - public function set_date_format($format, $pretty = false) |
|
295 | - { |
|
296 | - if ($pretty) { |
|
297 | - $this->_pretty_date_format = $format; |
|
298 | - } else { |
|
299 | - $this->_date_format = $format; |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * return the $_date_format property value. |
|
306 | - * |
|
307 | - * @param bool $pretty Whether to get pretty format or not. |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - public function get_date_format($pretty = false) |
|
311 | - { |
|
312 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * set the $_time_format property |
|
318 | - * |
|
319 | - * @access public |
|
320 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
321 | - * @param bool $pretty Whether to set pretty format or not. |
|
322 | - * @return void |
|
323 | - */ |
|
324 | - public function set_time_format($format, $pretty = false) |
|
325 | - { |
|
326 | - if ($pretty) { |
|
327 | - $this->_pretty_time_format = $format; |
|
328 | - } else { |
|
329 | - $this->_time_format = $format; |
|
330 | - } |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * return the $_time_format property value. |
|
336 | - * |
|
337 | - * @param bool $pretty Whether to get pretty format or not. |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - public function get_time_format($pretty = false) |
|
341 | - { |
|
342 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * set the $_pretty_date_format property |
|
348 | - * |
|
349 | - * @access public |
|
350 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
351 | - * @return void |
|
352 | - */ |
|
353 | - public function set_pretty_date_format($format) |
|
354 | - { |
|
355 | - $this->_pretty_date_format = $format; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * set the $_pretty_time_format property |
|
361 | - * |
|
362 | - * @access public |
|
363 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
364 | - * @return void |
|
365 | - */ |
|
366 | - public function set_pretty_time_format($format) |
|
367 | - { |
|
368 | - $this->_pretty_time_format = $format; |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * Only sets the time portion of the datetime. |
|
374 | - * |
|
375 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
376 | - * @param DateTime $current current DateTime object for the datetime field |
|
377 | - * @return DateTime |
|
378 | - */ |
|
379 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
380 | - { |
|
381 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
382 | - // Otherwise parse the string. |
|
383 | - if ($time_to_set_string instanceof DateTime) { |
|
384 | - $parsed = array( |
|
385 | - 'hour' => $time_to_set_string->format('H'), |
|
386 | - 'minute' => $time_to_set_string->format('i'), |
|
387 | - 'second' => $time_to_set_string->format('s'), |
|
388 | - ); |
|
389 | - } else { |
|
390 | - //parse incoming string |
|
391 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
392 | - } |
|
393 | - |
|
394 | - //make sure $current is in the correct timezone. |
|
395 | - $current->setTimezone($this->_DateTimeZone); |
|
396 | - |
|
397 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * Only sets the date portion of the datetime. |
|
403 | - * |
|
404 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
405 | - * @param DateTime $current current DateTime object for the datetime field |
|
406 | - * @return DateTime |
|
407 | - */ |
|
408 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
409 | - { |
|
410 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
411 | - // Otherwise parse the string. |
|
412 | - if ($date_to_set_string instanceof DateTime) { |
|
413 | - $parsed = array( |
|
414 | - 'year' => $date_to_set_string->format('Y'), |
|
415 | - 'month' => $date_to_set_string->format('m'), |
|
416 | - 'day' => $date_to_set_string->format('d'), |
|
417 | - ); |
|
418 | - } else { |
|
419 | - //parse incoming string |
|
420 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
421 | - } |
|
422 | - |
|
423 | - //make sure $current is in the correct timezone |
|
424 | - $current->setTimezone($this->_DateTimeZone); |
|
425 | - |
|
426 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
432 | - * datetime gets to this stage it should ALREADY be in UTC time |
|
433 | - * |
|
434 | - * @param DateTime $DateTime |
|
435 | - * @return string formatted date time for given timezone |
|
436 | - * @throws \EE_Error |
|
437 | - */ |
|
438 | - public function prepare_for_get($DateTime) |
|
439 | - { |
|
440 | - return $this->_prepare_for_display($DateTime); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
446 | - * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
447 | - * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
448 | - * abbreviation to the date_string. |
|
449 | - * |
|
450 | - * @param mixed $DateTime |
|
451 | - * @param null $schema |
|
452 | - * @return string |
|
453 | - * @throws \EE_Error |
|
454 | - */ |
|
455 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
456 | - { |
|
457 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
463 | - * timezone). |
|
464 | - * |
|
465 | - * @param DateTime $DateTime |
|
466 | - * @param bool|string $schema |
|
467 | - * @return string |
|
468 | - * @throws \EE_Error |
|
469 | - */ |
|
470 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
471 | - { |
|
472 | - if (! $DateTime instanceof DateTime) { |
|
473 | - if ($this->_nullable) { |
|
474 | - return ''; |
|
475 | - } else { |
|
476 | - if (WP_DEBUG) { |
|
477 | - throw new EE_Error( |
|
478 | - sprintf( |
|
479 | - __( |
|
480 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
481 | - 'event_espresso' |
|
482 | - ), |
|
483 | - $this->_nicename |
|
484 | - ) |
|
485 | - ); |
|
486 | - } else { |
|
487 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
488 | - EE_Error::add_error( |
|
489 | - sprintf( |
|
490 | - __( |
|
491 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
492 | - 'event_espresso' |
|
493 | - ), |
|
494 | - $this->_nicename |
|
495 | - ) |
|
496 | - ); |
|
497 | - } |
|
498 | - } |
|
499 | - } |
|
500 | - $format_string = $this->_get_date_time_output($schema); |
|
501 | - //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
502 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
503 | - if ($schema) { |
|
504 | - if ($this->_display_timezone()) { |
|
505 | - //must be explicit because schema could equal true. |
|
506 | - if ($schema === 'no_html') { |
|
507 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
508 | - } else { |
|
509 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
510 | - } |
|
511 | - } else { |
|
512 | - $timezone_string = ''; |
|
513 | - } |
|
514 | - |
|
515 | - return $DateTime->format($format_string) . $timezone_string; |
|
516 | - } else { |
|
517 | - return $DateTime->format($format_string); |
|
518 | - } |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
524 | - * timezone). |
|
525 | - * |
|
526 | - * @param mixed $datetime_value u |
|
527 | - * @return string mysql timestamp in UTC |
|
528 | - * @throws \EE_Error |
|
529 | - */ |
|
530 | - public function prepare_for_use_in_db($datetime_value) |
|
531 | - { |
|
532 | - //we allow an empty value or DateTime object, but nothing else. |
|
533 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
534 | - throw new EE_Error( |
|
535 | - sprintf( |
|
536 | - __( |
|
537 | - 'The incoming value being prepared for setting in the database must either be empty or a php |
|
18 | + /** |
|
19 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
20 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
21 | + * |
|
22 | + * @type string unix_timestamp_regex |
|
23 | + */ |
|
24 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type string mysql_timestamp_format |
|
28 | + */ |
|
29 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
30 | + |
|
31 | + /** |
|
32 | + * @type string mysql_date_format |
|
33 | + */ |
|
34 | + const mysql_date_format = 'Y-m-d'; |
|
35 | + |
|
36 | + /** |
|
37 | + * @type string mysql_time_format |
|
38 | + */ |
|
39 | + const mysql_time_format = 'H:i:s'; |
|
40 | + |
|
41 | + /** |
|
42 | + * Const for using in the default value. If the field's default is set to this, |
|
43 | + * then we will return the time of calling `get_default_value()`, not |
|
44 | + * just the current time at construction |
|
45 | + */ |
|
46 | + const now = 'now'; |
|
47 | + |
|
48 | + /** |
|
49 | + * The following properties hold the default formats for date and time. |
|
50 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
51 | + * However they can also be overridden later by the set_format() method |
|
52 | + * (and corresponding set_date_format, set_time_format methods); |
|
53 | + */ |
|
54 | + /** |
|
55 | + * @type string $_date_format |
|
56 | + */ |
|
57 | + protected $_date_format = ''; |
|
58 | + |
|
59 | + /** |
|
60 | + * @type string $_time_format |
|
61 | + */ |
|
62 | + protected $_time_format = ''; |
|
63 | + |
|
64 | + /** |
|
65 | + * @type string $_pretty_date_format |
|
66 | + */ |
|
67 | + protected $_pretty_date_format = ''; |
|
68 | + |
|
69 | + /** |
|
70 | + * @type string $_pretty_time_format |
|
71 | + */ |
|
72 | + protected $_pretty_time_format = ''; |
|
73 | + |
|
74 | + /** |
|
75 | + * @type DateTimeZone $_DateTimeZone |
|
76 | + */ |
|
77 | + protected $_DateTimeZone; |
|
78 | + |
|
79 | + /** |
|
80 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
81 | + */ |
|
82 | + protected $_UTC_DateTimeZone; |
|
83 | + |
|
84 | + /** |
|
85 | + * @type DateTimeZone $_blog_DateTimeZone |
|
86 | + */ |
|
87 | + protected $_blog_DateTimeZone; |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
92 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
93 | + * and time returned via getters. |
|
94 | + * |
|
95 | + * @var mixed (null|string) |
|
96 | + */ |
|
97 | + protected $_date_time_output; |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * timezone string |
|
102 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
103 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
104 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | + protected $_timezone_string; |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
113 | + * offsets for comparison purposes). |
|
114 | + * |
|
115 | + * @var int |
|
116 | + */ |
|
117 | + protected $_blog_offset; |
|
118 | + |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param string $table_column |
|
123 | + * @param string $nice_name |
|
124 | + * @param bool $nullable |
|
125 | + * @param string $default_value |
|
126 | + * @param string $timezone_string |
|
127 | + * @param string $date_format |
|
128 | + * @param string $time_format |
|
129 | + * @param string $pretty_date_format |
|
130 | + * @param string $pretty_time_format |
|
131 | + * @throws EE_Error |
|
132 | + * @throws InvalidArgumentException |
|
133 | + */ |
|
134 | + public function __construct( |
|
135 | + $table_column, |
|
136 | + $nice_name, |
|
137 | + $nullable, |
|
138 | + $default_value, |
|
139 | + $timezone_string = '', |
|
140 | + $date_format = '', |
|
141 | + $time_format = '', |
|
142 | + $pretty_date_format = '', |
|
143 | + $pretty_time_format = '' |
|
144 | + ) { |
|
145 | + |
|
146 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
147 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
148 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
149 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
150 | + |
|
151 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
152 | + $this->set_timezone($timezone_string); |
|
153 | + $this->setSchemaFormat('date-time'); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return DateTimeZone |
|
159 | + * @throws \EE_Error |
|
160 | + */ |
|
161 | + public function get_UTC_DateTimeZone() |
|
162 | + { |
|
163 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
164 | + ? $this->_UTC_DateTimeZone |
|
165 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @return DateTimeZone |
|
171 | + * @throws \EE_Error |
|
172 | + */ |
|
173 | + public function get_blog_DateTimeZone() |
|
174 | + { |
|
175 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
176 | + ? $this->_blog_DateTimeZone |
|
177 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
183 | + * |
|
184 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
185 | + * timestamp |
|
186 | + * @return DateTime |
|
187 | + */ |
|
188 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
189 | + { |
|
190 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
196 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
197 | + * |
|
198 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
199 | + * @return string The final assembled format string. |
|
200 | + */ |
|
201 | + protected function _get_date_time_output($pretty = false) |
|
202 | + { |
|
203 | + |
|
204 | + switch ($this->_date_time_output) { |
|
205 | + case 'time' : |
|
206 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
207 | + break; |
|
208 | + |
|
209 | + case 'date' : |
|
210 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
211 | + break; |
|
212 | + |
|
213 | + default : |
|
214 | + return $pretty |
|
215 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
216 | + : $this->_date_format . ' ' . $this->_time_format; |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
223 | + * returned (using the format properties) |
|
224 | + * |
|
225 | + * @param string $what acceptable values are 'time' or 'date'. |
|
226 | + * Any other value will be set but will always result |
|
227 | + * in both 'date' and 'time' being returned. |
|
228 | + * @return void |
|
229 | + */ |
|
230 | + public function set_date_time_output($what = null) |
|
231 | + { |
|
232 | + $this->_date_time_output = $what; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
238 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
239 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
240 | + * We also set some other properties in this method. |
|
241 | + * |
|
242 | + * @param string $timezone_string A valid timezone string as described by @link |
|
243 | + * http://www.php.net/manual/en/timezones.php |
|
244 | + * @return void |
|
245 | + * @throws \EE_Error |
|
246 | + */ |
|
247 | + public function set_timezone($timezone_string) |
|
248 | + { |
|
249 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
250 | + // leave the timezone AS-IS if we already have one and |
|
251 | + // the function arg didn't provide one |
|
252 | + return; |
|
253 | + } |
|
254 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
255 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
256 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * _create_timezone_object_from_timezone_name |
|
262 | + * |
|
263 | + * @access protected |
|
264 | + * @param string $timezone_string |
|
265 | + * @return \DateTimeZone |
|
266 | + * @throws \EE_Error |
|
267 | + */ |
|
268 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
269 | + { |
|
270 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * This just returns whatever is set for the current timezone. |
|
276 | + * |
|
277 | + * @access public |
|
278 | + * @return string timezone string |
|
279 | + */ |
|
280 | + public function get_timezone() |
|
281 | + { |
|
282 | + return $this->_timezone_string; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * set the $_date_format property |
|
288 | + * |
|
289 | + * @access public |
|
290 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
291 | + * @param bool $pretty Whether to set pretty format or not. |
|
292 | + * @return void |
|
293 | + */ |
|
294 | + public function set_date_format($format, $pretty = false) |
|
295 | + { |
|
296 | + if ($pretty) { |
|
297 | + $this->_pretty_date_format = $format; |
|
298 | + } else { |
|
299 | + $this->_date_format = $format; |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * return the $_date_format property value. |
|
306 | + * |
|
307 | + * @param bool $pretty Whether to get pretty format or not. |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + public function get_date_format($pretty = false) |
|
311 | + { |
|
312 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * set the $_time_format property |
|
318 | + * |
|
319 | + * @access public |
|
320 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
321 | + * @param bool $pretty Whether to set pretty format or not. |
|
322 | + * @return void |
|
323 | + */ |
|
324 | + public function set_time_format($format, $pretty = false) |
|
325 | + { |
|
326 | + if ($pretty) { |
|
327 | + $this->_pretty_time_format = $format; |
|
328 | + } else { |
|
329 | + $this->_time_format = $format; |
|
330 | + } |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * return the $_time_format property value. |
|
336 | + * |
|
337 | + * @param bool $pretty Whether to get pretty format or not. |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + public function get_time_format($pretty = false) |
|
341 | + { |
|
342 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * set the $_pretty_date_format property |
|
348 | + * |
|
349 | + * @access public |
|
350 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
351 | + * @return void |
|
352 | + */ |
|
353 | + public function set_pretty_date_format($format) |
|
354 | + { |
|
355 | + $this->_pretty_date_format = $format; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * set the $_pretty_time_format property |
|
361 | + * |
|
362 | + * @access public |
|
363 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
364 | + * @return void |
|
365 | + */ |
|
366 | + public function set_pretty_time_format($format) |
|
367 | + { |
|
368 | + $this->_pretty_time_format = $format; |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * Only sets the time portion of the datetime. |
|
374 | + * |
|
375 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
376 | + * @param DateTime $current current DateTime object for the datetime field |
|
377 | + * @return DateTime |
|
378 | + */ |
|
379 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
380 | + { |
|
381 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
382 | + // Otherwise parse the string. |
|
383 | + if ($time_to_set_string instanceof DateTime) { |
|
384 | + $parsed = array( |
|
385 | + 'hour' => $time_to_set_string->format('H'), |
|
386 | + 'minute' => $time_to_set_string->format('i'), |
|
387 | + 'second' => $time_to_set_string->format('s'), |
|
388 | + ); |
|
389 | + } else { |
|
390 | + //parse incoming string |
|
391 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
392 | + } |
|
393 | + |
|
394 | + //make sure $current is in the correct timezone. |
|
395 | + $current->setTimezone($this->_DateTimeZone); |
|
396 | + |
|
397 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * Only sets the date portion of the datetime. |
|
403 | + * |
|
404 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
405 | + * @param DateTime $current current DateTime object for the datetime field |
|
406 | + * @return DateTime |
|
407 | + */ |
|
408 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
409 | + { |
|
410 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
411 | + // Otherwise parse the string. |
|
412 | + if ($date_to_set_string instanceof DateTime) { |
|
413 | + $parsed = array( |
|
414 | + 'year' => $date_to_set_string->format('Y'), |
|
415 | + 'month' => $date_to_set_string->format('m'), |
|
416 | + 'day' => $date_to_set_string->format('d'), |
|
417 | + ); |
|
418 | + } else { |
|
419 | + //parse incoming string |
|
420 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
421 | + } |
|
422 | + |
|
423 | + //make sure $current is in the correct timezone |
|
424 | + $current->setTimezone($this->_DateTimeZone); |
|
425 | + |
|
426 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
432 | + * datetime gets to this stage it should ALREADY be in UTC time |
|
433 | + * |
|
434 | + * @param DateTime $DateTime |
|
435 | + * @return string formatted date time for given timezone |
|
436 | + * @throws \EE_Error |
|
437 | + */ |
|
438 | + public function prepare_for_get($DateTime) |
|
439 | + { |
|
440 | + return $this->_prepare_for_display($DateTime); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
446 | + * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
447 | + * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
448 | + * abbreviation to the date_string. |
|
449 | + * |
|
450 | + * @param mixed $DateTime |
|
451 | + * @param null $schema |
|
452 | + * @return string |
|
453 | + * @throws \EE_Error |
|
454 | + */ |
|
455 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
456 | + { |
|
457 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
463 | + * timezone). |
|
464 | + * |
|
465 | + * @param DateTime $DateTime |
|
466 | + * @param bool|string $schema |
|
467 | + * @return string |
|
468 | + * @throws \EE_Error |
|
469 | + */ |
|
470 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
471 | + { |
|
472 | + if (! $DateTime instanceof DateTime) { |
|
473 | + if ($this->_nullable) { |
|
474 | + return ''; |
|
475 | + } else { |
|
476 | + if (WP_DEBUG) { |
|
477 | + throw new EE_Error( |
|
478 | + sprintf( |
|
479 | + __( |
|
480 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
481 | + 'event_espresso' |
|
482 | + ), |
|
483 | + $this->_nicename |
|
484 | + ) |
|
485 | + ); |
|
486 | + } else { |
|
487 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
488 | + EE_Error::add_error( |
|
489 | + sprintf( |
|
490 | + __( |
|
491 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
492 | + 'event_espresso' |
|
493 | + ), |
|
494 | + $this->_nicename |
|
495 | + ) |
|
496 | + ); |
|
497 | + } |
|
498 | + } |
|
499 | + } |
|
500 | + $format_string = $this->_get_date_time_output($schema); |
|
501 | + //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
502 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
503 | + if ($schema) { |
|
504 | + if ($this->_display_timezone()) { |
|
505 | + //must be explicit because schema could equal true. |
|
506 | + if ($schema === 'no_html') { |
|
507 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
508 | + } else { |
|
509 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
510 | + } |
|
511 | + } else { |
|
512 | + $timezone_string = ''; |
|
513 | + } |
|
514 | + |
|
515 | + return $DateTime->format($format_string) . $timezone_string; |
|
516 | + } else { |
|
517 | + return $DateTime->format($format_string); |
|
518 | + } |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
524 | + * timezone). |
|
525 | + * |
|
526 | + * @param mixed $datetime_value u |
|
527 | + * @return string mysql timestamp in UTC |
|
528 | + * @throws \EE_Error |
|
529 | + */ |
|
530 | + public function prepare_for_use_in_db($datetime_value) |
|
531 | + { |
|
532 | + //we allow an empty value or DateTime object, but nothing else. |
|
533 | + if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
534 | + throw new EE_Error( |
|
535 | + sprintf( |
|
536 | + __( |
|
537 | + 'The incoming value being prepared for setting in the database must either be empty or a php |
|
538 | 538 | DateTime object, instead of: %1$s %2$s', |
539 | - 'event_espresso' |
|
540 | - ), |
|
541 | - '<br />', |
|
542 | - print_r($datetime_value, true) |
|
543 | - ) |
|
544 | - ); |
|
545 | - } |
|
546 | - |
|
547 | - if ($datetime_value instanceof DateTime) { |
|
548 | - if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
549 | - $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
550 | - } |
|
551 | - |
|
552 | - return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
553 | - EE_Datetime_Field::mysql_timestamp_format |
|
554 | - ); |
|
555 | - } |
|
556 | - |
|
557 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
558 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - /** |
|
563 | - * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
564 | - * allowed) |
|
565 | - * |
|
566 | - * @param string $datetime_string mysql timestamp in UTC |
|
567 | - * @return mixed null | DateTime |
|
568 | - * @throws \EE_Error |
|
569 | - */ |
|
570 | - public function prepare_for_set_from_db($datetime_string) |
|
571 | - { |
|
572 | - //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
573 | - if (empty($datetime_string) && $this->_nullable) { |
|
574 | - return null; |
|
575 | - } |
|
576 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
577 | - if (empty($datetime_string)) { |
|
578 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
579 | - } else { |
|
580 | - $DateTime = DateTime::createFromFormat( |
|
581 | - EE_Datetime_Field::mysql_timestamp_format, |
|
582 | - $datetime_string, |
|
583 | - $this->get_UTC_DateTimeZone() |
|
584 | - ); |
|
585 | - if ($DateTime instanceof \DateTime) { |
|
586 | - $DateTime = new DbSafeDateTime( |
|
587 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
588 | - $this->get_UTC_DateTimeZone() |
|
589 | - ); |
|
590 | - } |
|
591 | - } |
|
592 | - |
|
593 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
594 | - // if still no datetime object, then let's just use now |
|
595 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
596 | - } |
|
597 | - // THEN apply the field's set DateTimeZone |
|
598 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
599 | - |
|
600 | - return $DateTime; |
|
601 | - } |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * All this method does is determine if we're going to display the timezone string or not on any output. |
|
606 | - * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
607 | - * If so, then true. |
|
608 | - * |
|
609 | - * @return bool true for yes false for no |
|
610 | - * @throws \EE_Error |
|
611 | - */ |
|
612 | - protected function _display_timezone() |
|
613 | - { |
|
614 | - |
|
615 | - // first let's do a comparison of timezone strings. |
|
616 | - // If they match then we can get out without any further calculations |
|
617 | - $blog_string = get_option('timezone_string'); |
|
618 | - if ($blog_string === $this->_timezone_string) { |
|
619 | - return false; |
|
620 | - } |
|
621 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
622 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
623 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
624 | - // now compare |
|
625 | - return $blog_offset !== $this_offset; |
|
626 | - } |
|
627 | - |
|
628 | - |
|
629 | - /** |
|
630 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
631 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
632 | - * with. |
|
633 | - * |
|
634 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
635 | - * in the format that is set on the date_field (or DateTime |
|
636 | - * object)! |
|
637 | - * @return DateTime |
|
638 | - */ |
|
639 | - protected function _get_date_object($date_string) |
|
640 | - { |
|
641 | - //first if this is an empty date_string and nullable is allowed, just return null. |
|
642 | - if ($this->_nullable && empty($date_string)) { |
|
643 | - return null; |
|
644 | - } |
|
645 | - |
|
646 | - // if incoming date |
|
647 | - if ($date_string instanceof DateTime) { |
|
648 | - $date_string->setTimezone($this->_DateTimeZone); |
|
649 | - |
|
650 | - return $date_string; |
|
651 | - } |
|
652 | - // if empty date_string and made it here. |
|
653 | - // Return a datetime object for now in the given timezone. |
|
654 | - if (empty($date_string)) { |
|
655 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
656 | - } |
|
657 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
658 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
659 | - try { |
|
660 | - // This is operating under the assumption that the incoming Unix timestamp |
|
661 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
662 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
663 | - $DateTime->setTimestamp($date_string); |
|
664 | - |
|
665 | - return $DateTime; |
|
666 | - } catch (Exception $e) { |
|
667 | - // should be rare, but if things got fooled then let's just continue |
|
668 | - } |
|
669 | - } |
|
670 | - //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
671 | - //create the DateTime object. |
|
672 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
673 | - try { |
|
674 | - $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
675 | - if ($DateTime instanceof DateTime) { |
|
676 | - $DateTime = new DbSafeDateTime( |
|
677 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
678 | - $this->_DateTimeZone |
|
679 | - ); |
|
680 | - } |
|
681 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
682 | - throw new EE_Error( |
|
683 | - sprintf( |
|
684 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
685 | - $date_string, |
|
686 | - $format |
|
687 | - ) |
|
688 | - ); |
|
689 | - } |
|
690 | - } catch (Exception $e) { |
|
691 | - // if we made it here then likely then something went really wrong. |
|
692 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
693 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
694 | - } |
|
695 | - |
|
696 | - return $DateTime; |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * get_timezone_transitions |
|
703 | - * |
|
704 | - * @param \DateTimeZone $DateTimeZone |
|
705 | - * @param int $time |
|
706 | - * @param bool $first_only |
|
707 | - * @return mixed |
|
708 | - */ |
|
709 | - public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
710 | - { |
|
711 | - $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
712 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
713 | - $transitions = $DateTimeZone->getTransitions($time); |
|
714 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
715 | - } |
|
716 | - |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * get_timezone_offset |
|
721 | - * |
|
722 | - * @param \DateTimeZone $DateTimeZone |
|
723 | - * @param int $time |
|
724 | - * @return mixed |
|
725 | - * @throws \DomainException |
|
726 | - */ |
|
727 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
728 | - { |
|
729 | - $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
730 | - if ( ! isset($transitions['offset'])) { |
|
731 | - throw new DomainException(); |
|
732 | - } |
|
733 | - return $transitions['offset']; |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - /** |
|
738 | - * This will take an incoming timezone string and return the abbreviation for that timezone |
|
739 | - * |
|
740 | - * @param string $timezone_string |
|
741 | - * @return string abbreviation |
|
742 | - * @throws \EE_Error |
|
743 | - */ |
|
744 | - public function get_timezone_abbrev($timezone_string) |
|
745 | - { |
|
746 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
747 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
748 | - |
|
749 | - return $dateTime->format('T'); |
|
750 | - } |
|
751 | - |
|
752 | - /** |
|
753 | - * Overrides the parent to allow for having a dynamic "now" value |
|
754 | - * |
|
755 | - * @return mixed |
|
756 | - */ |
|
757 | - public function get_default_value() |
|
758 | - { |
|
759 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
760 | - return time(); |
|
761 | - } else { |
|
762 | - return parent::get_default_value(); |
|
763 | - } |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - public function getSchemaDescription() |
|
768 | - { |
|
769 | - return sprintf( |
|
770 | - esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
771 | - $this->get_nicename() |
|
772 | - ); |
|
773 | - } |
|
539 | + 'event_espresso' |
|
540 | + ), |
|
541 | + '<br />', |
|
542 | + print_r($datetime_value, true) |
|
543 | + ) |
|
544 | + ); |
|
545 | + } |
|
546 | + |
|
547 | + if ($datetime_value instanceof DateTime) { |
|
548 | + if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
549 | + $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
550 | + } |
|
551 | + |
|
552 | + return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
553 | + EE_Datetime_Field::mysql_timestamp_format |
|
554 | + ); |
|
555 | + } |
|
556 | + |
|
557 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
558 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + /** |
|
563 | + * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
564 | + * allowed) |
|
565 | + * |
|
566 | + * @param string $datetime_string mysql timestamp in UTC |
|
567 | + * @return mixed null | DateTime |
|
568 | + * @throws \EE_Error |
|
569 | + */ |
|
570 | + public function prepare_for_set_from_db($datetime_string) |
|
571 | + { |
|
572 | + //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
573 | + if (empty($datetime_string) && $this->_nullable) { |
|
574 | + return null; |
|
575 | + } |
|
576 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
577 | + if (empty($datetime_string)) { |
|
578 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
579 | + } else { |
|
580 | + $DateTime = DateTime::createFromFormat( |
|
581 | + EE_Datetime_Field::mysql_timestamp_format, |
|
582 | + $datetime_string, |
|
583 | + $this->get_UTC_DateTimeZone() |
|
584 | + ); |
|
585 | + if ($DateTime instanceof \DateTime) { |
|
586 | + $DateTime = new DbSafeDateTime( |
|
587 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
588 | + $this->get_UTC_DateTimeZone() |
|
589 | + ); |
|
590 | + } |
|
591 | + } |
|
592 | + |
|
593 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
594 | + // if still no datetime object, then let's just use now |
|
595 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
596 | + } |
|
597 | + // THEN apply the field's set DateTimeZone |
|
598 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
599 | + |
|
600 | + return $DateTime; |
|
601 | + } |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * All this method does is determine if we're going to display the timezone string or not on any output. |
|
606 | + * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
607 | + * If so, then true. |
|
608 | + * |
|
609 | + * @return bool true for yes false for no |
|
610 | + * @throws \EE_Error |
|
611 | + */ |
|
612 | + protected function _display_timezone() |
|
613 | + { |
|
614 | + |
|
615 | + // first let's do a comparison of timezone strings. |
|
616 | + // If they match then we can get out without any further calculations |
|
617 | + $blog_string = get_option('timezone_string'); |
|
618 | + if ($blog_string === $this->_timezone_string) { |
|
619 | + return false; |
|
620 | + } |
|
621 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
622 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
623 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
624 | + // now compare |
|
625 | + return $blog_offset !== $this_offset; |
|
626 | + } |
|
627 | + |
|
628 | + |
|
629 | + /** |
|
630 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
631 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
632 | + * with. |
|
633 | + * |
|
634 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
635 | + * in the format that is set on the date_field (or DateTime |
|
636 | + * object)! |
|
637 | + * @return DateTime |
|
638 | + */ |
|
639 | + protected function _get_date_object($date_string) |
|
640 | + { |
|
641 | + //first if this is an empty date_string and nullable is allowed, just return null. |
|
642 | + if ($this->_nullable && empty($date_string)) { |
|
643 | + return null; |
|
644 | + } |
|
645 | + |
|
646 | + // if incoming date |
|
647 | + if ($date_string instanceof DateTime) { |
|
648 | + $date_string->setTimezone($this->_DateTimeZone); |
|
649 | + |
|
650 | + return $date_string; |
|
651 | + } |
|
652 | + // if empty date_string and made it here. |
|
653 | + // Return a datetime object for now in the given timezone. |
|
654 | + if (empty($date_string)) { |
|
655 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
656 | + } |
|
657 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
658 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
659 | + try { |
|
660 | + // This is operating under the assumption that the incoming Unix timestamp |
|
661 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
662 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
663 | + $DateTime->setTimestamp($date_string); |
|
664 | + |
|
665 | + return $DateTime; |
|
666 | + } catch (Exception $e) { |
|
667 | + // should be rare, but if things got fooled then let's just continue |
|
668 | + } |
|
669 | + } |
|
670 | + //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
671 | + //create the DateTime object. |
|
672 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
673 | + try { |
|
674 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
675 | + if ($DateTime instanceof DateTime) { |
|
676 | + $DateTime = new DbSafeDateTime( |
|
677 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
678 | + $this->_DateTimeZone |
|
679 | + ); |
|
680 | + } |
|
681 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
682 | + throw new EE_Error( |
|
683 | + sprintf( |
|
684 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
685 | + $date_string, |
|
686 | + $format |
|
687 | + ) |
|
688 | + ); |
|
689 | + } |
|
690 | + } catch (Exception $e) { |
|
691 | + // if we made it here then likely then something went really wrong. |
|
692 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
693 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
694 | + } |
|
695 | + |
|
696 | + return $DateTime; |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * get_timezone_transitions |
|
703 | + * |
|
704 | + * @param \DateTimeZone $DateTimeZone |
|
705 | + * @param int $time |
|
706 | + * @param bool $first_only |
|
707 | + * @return mixed |
|
708 | + */ |
|
709 | + public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
710 | + { |
|
711 | + $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
712 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
713 | + $transitions = $DateTimeZone->getTransitions($time); |
|
714 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
715 | + } |
|
716 | + |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * get_timezone_offset |
|
721 | + * |
|
722 | + * @param \DateTimeZone $DateTimeZone |
|
723 | + * @param int $time |
|
724 | + * @return mixed |
|
725 | + * @throws \DomainException |
|
726 | + */ |
|
727 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
728 | + { |
|
729 | + $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
730 | + if ( ! isset($transitions['offset'])) { |
|
731 | + throw new DomainException(); |
|
732 | + } |
|
733 | + return $transitions['offset']; |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + /** |
|
738 | + * This will take an incoming timezone string and return the abbreviation for that timezone |
|
739 | + * |
|
740 | + * @param string $timezone_string |
|
741 | + * @return string abbreviation |
|
742 | + * @throws \EE_Error |
|
743 | + */ |
|
744 | + public function get_timezone_abbrev($timezone_string) |
|
745 | + { |
|
746 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
747 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
748 | + |
|
749 | + return $dateTime->format('T'); |
|
750 | + } |
|
751 | + |
|
752 | + /** |
|
753 | + * Overrides the parent to allow for having a dynamic "now" value |
|
754 | + * |
|
755 | + * @return mixed |
|
756 | + */ |
|
757 | + public function get_default_value() |
|
758 | + { |
|
759 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
760 | + return time(); |
|
761 | + } else { |
|
762 | + return parent::get_default_value(); |
|
763 | + } |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + public function getSchemaDescription() |
|
768 | + { |
|
769 | + return sprintf( |
|
770 | + esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
771 | + $this->get_nicename() |
|
772 | + ); |
|
773 | + } |
|
774 | 774 | } |
@@ -7,7 +7,7 @@ |
||
7 | 7 | use EventEspresso\core\services\commands\CommandInterface; |
8 | 8 | use EventEspresso\core\services\commands\CommandRequiresCapCheckInterface; |
9 | 9 | |
10 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
11 | 11 | exit('No direct script access allowed'); |
12 | 12 | } |
13 | 13 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | use EventEspresso\core\services\commands\CommandRequiresCapCheckInterface; |
10 | 10 | |
11 | 11 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
12 | - exit('No direct script access allowed'); |
|
12 | + exit('No direct script access allowed'); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | |
@@ -29,41 +29,41 @@ discard block |
||
29 | 29 | class CapChecker implements CommandBusMiddlewareInterface |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * @type CapabilitiesCheckerInterface $capabilities_checker |
|
34 | - */ |
|
35 | - private $capabilities_checker; |
|
32 | + /** |
|
33 | + * @type CapabilitiesCheckerInterface $capabilities_checker |
|
34 | + */ |
|
35 | + private $capabilities_checker; |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * CapChecker constructor |
|
41 | - * |
|
42 | - * @param CapabilitiesCheckerInterface $capabilities_checker |
|
43 | - */ |
|
44 | - public function __construct(CapabilitiesCheckerInterface $capabilities_checker) |
|
45 | - { |
|
46 | - $this->capabilities_checker = $capabilities_checker; |
|
47 | - } |
|
39 | + /** |
|
40 | + * CapChecker constructor |
|
41 | + * |
|
42 | + * @param CapabilitiesCheckerInterface $capabilities_checker |
|
43 | + */ |
|
44 | + public function __construct(CapabilitiesCheckerInterface $capabilities_checker) |
|
45 | + { |
|
46 | + $this->capabilities_checker = $capabilities_checker; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @param CommandInterface $command |
|
53 | - * @param Closure $next |
|
54 | - * @return mixed |
|
55 | - * @throws InvalidClassException |
|
56 | - * @throws InsufficientPermissionsException |
|
57 | - */ |
|
58 | - public function handle(CommandInterface $command, Closure $next) |
|
59 | - { |
|
60 | - if ($command instanceof CommandRequiresCapCheckInterface) { |
|
61 | - $this->capabilities_checker->processCapCheck( |
|
62 | - $command->getCapCheck() |
|
63 | - ); |
|
64 | - } |
|
65 | - return $next($command); |
|
66 | - } |
|
51 | + /** |
|
52 | + * @param CommandInterface $command |
|
53 | + * @param Closure $next |
|
54 | + * @return mixed |
|
55 | + * @throws InvalidClassException |
|
56 | + * @throws InsufficientPermissionsException |
|
57 | + */ |
|
58 | + public function handle(CommandInterface $command, Closure $next) |
|
59 | + { |
|
60 | + if ($command instanceof CommandRequiresCapCheckInterface) { |
|
61 | + $this->capabilities_checker->processCapCheck( |
|
62 | + $command->getCapCheck() |
|
63 | + ); |
|
64 | + } |
|
65 | + return $next($command); |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | 69 | } |
@@ -24,66 +24,66 @@ |
||
24 | 24 | class CreateTransactionCommand extends Command implements CommandRequiresCapCheckInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var EE_Checkout $checkout |
|
29 | - */ |
|
30 | - protected $checkout; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array $transaction_details |
|
34 | - */ |
|
35 | - protected $transaction_details; |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * CreateTransactionCommand constructor. |
|
41 | - * |
|
42 | - * @param EE_Checkout $checkout |
|
43 | - * @param array $transaction_details |
|
44 | - */ |
|
45 | - public function __construct(EE_Checkout $checkout = null, array $transaction_details = array()) |
|
46 | - { |
|
47 | - $this->checkout = $checkout; |
|
48 | - $this->transaction_details = $transaction_details; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @return CapCheckInterface |
|
55 | - * @throws InvalidDataTypeException |
|
56 | - */ |
|
57 | - public function getCapCheck() |
|
58 | - { |
|
59 | - // need cap for non-AJAX admin requests |
|
60 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
61 | - // there's no specific caps for editing/creating transactions, |
|
62 | - // so that's why we are using ee_edit_registrations |
|
63 | - return new CapCheck('ee_edit_registrations', 'create_new_transaction'); |
|
64 | - } |
|
65 | - return new PublicCapabilities('', 'create_new_transaction'); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @return EE_Checkout |
|
72 | - */ |
|
73 | - public function checkout() |
|
74 | - { |
|
75 | - return $this->checkout; |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - public function transactionDetails() |
|
84 | - { |
|
85 | - return $this->transaction_details; |
|
86 | - } |
|
27 | + /** |
|
28 | + * @var EE_Checkout $checkout |
|
29 | + */ |
|
30 | + protected $checkout; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array $transaction_details |
|
34 | + */ |
|
35 | + protected $transaction_details; |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * CreateTransactionCommand constructor. |
|
41 | + * |
|
42 | + * @param EE_Checkout $checkout |
|
43 | + * @param array $transaction_details |
|
44 | + */ |
|
45 | + public function __construct(EE_Checkout $checkout = null, array $transaction_details = array()) |
|
46 | + { |
|
47 | + $this->checkout = $checkout; |
|
48 | + $this->transaction_details = $transaction_details; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @return CapCheckInterface |
|
55 | + * @throws InvalidDataTypeException |
|
56 | + */ |
|
57 | + public function getCapCheck() |
|
58 | + { |
|
59 | + // need cap for non-AJAX admin requests |
|
60 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
61 | + // there's no specific caps for editing/creating transactions, |
|
62 | + // so that's why we are using ee_edit_registrations |
|
63 | + return new CapCheck('ee_edit_registrations', 'create_new_transaction'); |
|
64 | + } |
|
65 | + return new PublicCapabilities('', 'create_new_transaction'); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @return EE_Checkout |
|
72 | + */ |
|
73 | + public function checkout() |
|
74 | + { |
|
75 | + return $this->checkout; |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + public function transactionDetails() |
|
84 | + { |
|
85 | + return $this->transaction_details; |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | 89 |
@@ -57,7 +57,7 @@ |
||
57 | 57 | public function getCapCheck() |
58 | 58 | { |
59 | 59 | // need cap for non-AJAX admin requests |
60 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
60 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
61 | 61 | // there's no specific caps for editing/creating transactions, |
62 | 62 | // so that's why we are using ee_edit_registrations |
63 | 63 | return new CapCheck('ee_edit_registrations', 'create_new_transaction'); |
@@ -26,44 +26,44 @@ |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @param CommandInterface $command |
|
31 | - * @return mixed |
|
32 | - * @throws EE_Error |
|
33 | - * @throws InvalidEntityException |
|
34 | - */ |
|
35 | - public function handle(CommandInterface $command) |
|
36 | - { |
|
37 | - /** @var CreateTransactionCommand $command */ |
|
38 | - if (! $command instanceof CreateTransactionCommand) { |
|
39 | - throw new InvalidEntityException(get_class($command), 'CreateTransactionCommand'); |
|
40 | - } |
|
41 | - $transaction_details = $command->transactionDetails(); |
|
42 | - $cart_total = null; |
|
43 | - if ($command->checkout() instanceof EE_Checkout) { |
|
44 | - // ensure cart totals have been calculated |
|
45 | - $command->checkout()->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
46 | - // grab the cart grand total |
|
47 | - $cart_total = $command->checkout()->cart->get_cart_grand_total(); |
|
48 | - $transaction_details['TXN_reg_steps'] = $command->checkout()->initialize_txn_reg_steps_array(); |
|
49 | - $transaction_details['TXN_total'] = $cart_total > 0 ? $cart_total : 0; |
|
50 | - } |
|
51 | - // create new TXN and save it so it has an ID |
|
52 | - $transaction = EE_Transaction::new_instance($transaction_details); |
|
53 | - if (! $transaction instanceof EE_Transaction) { |
|
54 | - throw new InvalidEntityException(get_class($transaction), 'EE_Transaction'); |
|
55 | - } |
|
56 | - $transaction->save(); |
|
57 | - // ensure grand total line item created |
|
58 | - $cart_total = $cart_total instanceof EE_Line_Item |
|
59 | - ? $cart_total |
|
60 | - : EEH_Line_Item::create_total_line_item($transaction); |
|
61 | - if (! $cart_total instanceof EE_Line_Item) { |
|
62 | - throw new InvalidEntityException(get_class($cart_total), 'EE_Line_Item'); |
|
63 | - } |
|
64 | - $cart_total->save_this_and_descendants_to_txn($transaction->ID()); |
|
65 | - return $transaction; |
|
66 | - } |
|
29 | + /** |
|
30 | + * @param CommandInterface $command |
|
31 | + * @return mixed |
|
32 | + * @throws EE_Error |
|
33 | + * @throws InvalidEntityException |
|
34 | + */ |
|
35 | + public function handle(CommandInterface $command) |
|
36 | + { |
|
37 | + /** @var CreateTransactionCommand $command */ |
|
38 | + if (! $command instanceof CreateTransactionCommand) { |
|
39 | + throw new InvalidEntityException(get_class($command), 'CreateTransactionCommand'); |
|
40 | + } |
|
41 | + $transaction_details = $command->transactionDetails(); |
|
42 | + $cart_total = null; |
|
43 | + if ($command->checkout() instanceof EE_Checkout) { |
|
44 | + // ensure cart totals have been calculated |
|
45 | + $command->checkout()->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
46 | + // grab the cart grand total |
|
47 | + $cart_total = $command->checkout()->cart->get_cart_grand_total(); |
|
48 | + $transaction_details['TXN_reg_steps'] = $command->checkout()->initialize_txn_reg_steps_array(); |
|
49 | + $transaction_details['TXN_total'] = $cart_total > 0 ? $cart_total : 0; |
|
50 | + } |
|
51 | + // create new TXN and save it so it has an ID |
|
52 | + $transaction = EE_Transaction::new_instance($transaction_details); |
|
53 | + if (! $transaction instanceof EE_Transaction) { |
|
54 | + throw new InvalidEntityException(get_class($transaction), 'EE_Transaction'); |
|
55 | + } |
|
56 | + $transaction->save(); |
|
57 | + // ensure grand total line item created |
|
58 | + $cart_total = $cart_total instanceof EE_Line_Item |
|
59 | + ? $cart_total |
|
60 | + : EEH_Line_Item::create_total_line_item($transaction); |
|
61 | + if (! $cart_total instanceof EE_Line_Item) { |
|
62 | + throw new InvalidEntityException(get_class($cart_total), 'EE_Line_Item'); |
|
63 | + } |
|
64 | + $cart_total->save_this_and_descendants_to_txn($transaction->ID()); |
|
65 | + return $transaction; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | 69 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function handle(CommandInterface $command) |
36 | 36 | { |
37 | 37 | /** @var CreateTransactionCommand $command */ |
38 | - if (! $command instanceof CreateTransactionCommand) { |
|
38 | + if ( ! $command instanceof CreateTransactionCommand) { |
|
39 | 39 | throw new InvalidEntityException(get_class($command), 'CreateTransactionCommand'); |
40 | 40 | } |
41 | 41 | $transaction_details = $command->transactionDetails(); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | } |
51 | 51 | // create new TXN and save it so it has an ID |
52 | 52 | $transaction = EE_Transaction::new_instance($transaction_details); |
53 | - if (! $transaction instanceof EE_Transaction) { |
|
53 | + if ( ! $transaction instanceof EE_Transaction) { |
|
54 | 54 | throw new InvalidEntityException(get_class($transaction), 'EE_Transaction'); |
55 | 55 | } |
56 | 56 | $transaction->save(); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $cart_total = $cart_total instanceof EE_Line_Item |
59 | 59 | ? $cart_total |
60 | 60 | : EEH_Line_Item::create_total_line_item($transaction); |
61 | - if (! $cart_total instanceof EE_Line_Item) { |
|
61 | + if ( ! $cart_total instanceof EE_Line_Item) { |
|
62 | 62 | throw new InvalidEntityException(get_class($cart_total), 'EE_Line_Item'); |
63 | 63 | } |
64 | 64 | $cart_total->save_this_and_descendants_to_txn($transaction->ID()); |
@@ -24,68 +24,68 @@ |
||
24 | 24 | class CreateAttendeeCommand extends Command implements CommandRequiresCapCheckInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * array of details where keys are names of EEM_Attendee model fields |
|
29 | - * |
|
30 | - * @var array $attendee_details |
|
31 | - */ |
|
32 | - protected $attendee_details; |
|
33 | - |
|
34 | - /** |
|
35 | - * an existing registration to associate this attendee with |
|
36 | - * |
|
37 | - * @var EE_Registration $registration |
|
38 | - */ |
|
39 | - protected $registration; |
|
40 | - |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * CreateAttendeeCommand constructor. |
|
45 | - * |
|
46 | - * @param array $attendee_details |
|
47 | - * @param EE_Registration $registration |
|
48 | - */ |
|
49 | - public function __construct(array $attendee_details, EE_Registration $registration) |
|
50 | - { |
|
51 | - $this->attendee_details = $attendee_details; |
|
52 | - $this->registration = $registration; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @return array |
|
59 | - */ |
|
60 | - public function attendeeDetails() |
|
61 | - { |
|
62 | - return $this->attendee_details; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return EE_Registration |
|
69 | - */ |
|
70 | - public function registration() |
|
71 | - { |
|
72 | - return $this->registration; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return CapCheckInterface |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - */ |
|
81 | - public function getCapCheck() |
|
82 | - { |
|
83 | - // need cap for non-AJAX admin requests |
|
84 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
85 | - return new CapCheck('ee_edit_contacts', 'create_new_contact'); |
|
86 | - } |
|
87 | - return new PublicCapabilities('', 'create_new_contact'); |
|
88 | - } |
|
27 | + /** |
|
28 | + * array of details where keys are names of EEM_Attendee model fields |
|
29 | + * |
|
30 | + * @var array $attendee_details |
|
31 | + */ |
|
32 | + protected $attendee_details; |
|
33 | + |
|
34 | + /** |
|
35 | + * an existing registration to associate this attendee with |
|
36 | + * |
|
37 | + * @var EE_Registration $registration |
|
38 | + */ |
|
39 | + protected $registration; |
|
40 | + |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * CreateAttendeeCommand constructor. |
|
45 | + * |
|
46 | + * @param array $attendee_details |
|
47 | + * @param EE_Registration $registration |
|
48 | + */ |
|
49 | + public function __construct(array $attendee_details, EE_Registration $registration) |
|
50 | + { |
|
51 | + $this->attendee_details = $attendee_details; |
|
52 | + $this->registration = $registration; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @return array |
|
59 | + */ |
|
60 | + public function attendeeDetails() |
|
61 | + { |
|
62 | + return $this->attendee_details; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return EE_Registration |
|
69 | + */ |
|
70 | + public function registration() |
|
71 | + { |
|
72 | + return $this->registration; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return CapCheckInterface |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + */ |
|
81 | + public function getCapCheck() |
|
82 | + { |
|
83 | + // need cap for non-AJAX admin requests |
|
84 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
85 | + return new CapCheck('ee_edit_contacts', 'create_new_contact'); |
|
86 | + } |
|
87 | + return new PublicCapabilities('', 'create_new_contact'); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | 91 |
@@ -81,7 +81,7 @@ |
||
81 | 81 | public function getCapCheck() |
82 | 82 | { |
83 | 83 | // need cap for non-AJAX admin requests |
84 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
84 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
85 | 85 | return new CapCheck('ee_edit_contacts', 'create_new_contact'); |
86 | 86 | } |
87 | 87 | return new PublicCapabilities('', 'create_new_contact'); |