@@ -514,7 +514,7 @@ |
||
514 | 514 | // set new REG_Status |
515 | 515 | $this->set_new_reg_status( $registration->ID(), $registration->status_ID() ); |
516 | 516 | return $this->reg_status_updated( $registration->ID() ) |
517 | - && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved |
|
517 | + && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved |
|
518 | 518 | ? true |
519 | 519 | : false; |
520 | 520 | } |
@@ -565,7 +565,7 @@ |
||
565 | 565 | * @since 4.9.1 |
566 | 566 | * @param int $att_nmbr |
567 | 567 | * @param EE_Line_Item | string $item |
568 | - * @return string |
|
568 | + * @return RegUrlLink |
|
569 | 569 | */ |
570 | 570 | public function generate_reg_url_link($att_nmbr, $item) |
571 | 571 | { |
@@ -1,5 +1,4 @@ |
||
1 | 1 | <?php |
2 | -use EventEspresso\core\domain\entities\RegCode; |
|
3 | 2 | use EventEspresso\core\domain\entities\RegUrlLink; |
4 | 3 | use EventEspresso\core\domain\services\registration\CreateRegistrationService; |
5 | 4 |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | use EventEspresso\core\domain\entities\RegUrlLink; |
4 | 4 | use EventEspresso\core\domain\services\registration\CreateRegistrationService; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
7 | -EE_Registry::instance()->load_class( 'Processor_Base' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
7 | +EE_Registry::instance()->load_class('Processor_Base'); |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Class EE_Registration_Processor |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public static function instance() { |
68 | 68 | // check if class object is instantiated |
69 | - if ( ! self::$_instance instanceof EE_Registration_Processor ) { |
|
69 | + if ( ! self::$_instance instanceof EE_Registration_Processor) { |
|
70 | 70 | self::$_instance = new self(); |
71 | 71 | } |
72 | 72 | return self::$_instance; |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @param int $REG_ID |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - public function old_reg_status( $REG_ID ) { |
|
90 | - return isset( $this->_old_reg_status[ $REG_ID ] ) ? $this->_old_reg_status[ $REG_ID ] : null; |
|
89 | + public function old_reg_status($REG_ID) { |
|
90 | + return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | * @param int $REG_ID |
97 | 97 | * @param string $old_reg_status |
98 | 98 | */ |
99 | - public function set_old_reg_status( $REG_ID, $old_reg_status ) { |
|
99 | + public function set_old_reg_status($REG_ID, $old_reg_status) { |
|
100 | 100 | // only set the first time |
101 | - if ( ! isset( $this->_old_reg_status[ $REG_ID ] ) ) { |
|
102 | - $this->_old_reg_status[ $REG_ID ] = $old_reg_status; |
|
101 | + if ( ! isset($this->_old_reg_status[$REG_ID])) { |
|
102 | + $this->_old_reg_status[$REG_ID] = $old_reg_status; |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * @param int $REG_ID |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - public function new_reg_status( $REG_ID ) { |
|
113 | - return isset( $this->_new_reg_status[ $REG_ID ] ) ? $this->_new_reg_status[ $REG_ID ] : null; |
|
112 | + public function new_reg_status($REG_ID) { |
|
113 | + return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @param int $REG_ID |
120 | 120 | * @param string $new_reg_status |
121 | 121 | */ |
122 | - public function set_new_reg_status( $REG_ID, $new_reg_status ) { |
|
123 | - $this->_new_reg_status[ $REG_ID ] = $new_reg_status; |
|
122 | + public function set_new_reg_status($REG_ID, $new_reg_status) { |
|
123 | + $this->_new_reg_status[$REG_ID] = $new_reg_status; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | * @param int $REG_ID |
132 | 132 | * @return bool |
133 | 133 | */ |
134 | - public function reg_status_updated( $REG_ID ) { |
|
135 | - return $this->new_reg_status( $REG_ID ) !== $this->old_reg_status( $REG_ID ) ? true : false; |
|
134 | + public function reg_status_updated($REG_ID) { |
|
135 | + return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID) ? true : false; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | * @param \EE_Registration $registration |
142 | 142 | * @throws \EE_Error |
143 | 143 | */ |
144 | - public function update_registration_status_and_trigger_notifications( \EE_Registration $registration ) { |
|
145 | - $this->toggle_incomplete_registration_status_to_default( $registration, false ); |
|
146 | - $this->toggle_registration_status_for_default_approved_events( $registration, false ); |
|
147 | - $this->toggle_registration_status_if_no_monies_owing( $registration, false ); |
|
144 | + public function update_registration_status_and_trigger_notifications(\EE_Registration $registration) { |
|
145 | + $this->toggle_incomplete_registration_status_to_default($registration, false); |
|
146 | + $this->toggle_registration_status_for_default_approved_events($registration, false); |
|
147 | + $this->toggle_registration_status_if_no_monies_owing($registration, false); |
|
148 | 148 | $registration->save(); |
149 | 149 | // trigger notifications |
150 | - $this->trigger_registration_update_notifications( $registration ); |
|
150 | + $this->trigger_registration_update_notifications($registration); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -162,18 +162,18 @@ discard block |
||
162 | 162 | * @return boolean |
163 | 163 | * @throws \EE_Error |
164 | 164 | */ |
165 | - public function manually_update_registration_status( EE_Registration $registration, $new_reg_status = '', $save = true ) { |
|
165 | + public function manually_update_registration_status(EE_Registration $registration, $new_reg_status = '', $save = true) { |
|
166 | 166 | // set initial REG_Status |
167 | - $this->set_old_reg_status( $registration->ID(), $registration->status_ID() ); |
|
167 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
168 | 168 | // set incoming REG_Status |
169 | - $this->set_new_reg_status( $registration->ID(), $new_reg_status ); |
|
169 | + $this->set_new_reg_status($registration->ID(), $new_reg_status); |
|
170 | 170 | // toggle reg status but only if it has changed and the user can do so |
171 | 171 | if ( |
172 | - $this->reg_status_updated( $registration->ID() ) && |
|
173 | - EE_Registry::instance()->CAP->current_user_can( 'ee_edit_registration', 'toggle_registration_status', $registration->ID() ) |
|
172 | + $this->reg_status_updated($registration->ID()) && |
|
173 | + EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'toggle_registration_status', $registration->ID()) |
|
174 | 174 | ) { |
175 | 175 | // change status to new value |
176 | - if ( $registration->set_status( $this->new_reg_status( $registration->ID() ) ) && $save ) { |
|
176 | + if ($registration->set_status($this->new_reg_status($registration->ID())) && $save) { |
|
177 | 177 | $registration->save(); |
178 | 178 | } |
179 | 179 | return TRUE; |
@@ -193,30 +193,30 @@ discard block |
||
193 | 193 | * @return void |
194 | 194 | * @throws \EE_Error |
195 | 195 | */ |
196 | - public function toggle_incomplete_registration_status_to_default( EE_Registration $registration, $save = TRUE ) { |
|
196 | + public function toggle_incomplete_registration_status_to_default(EE_Registration $registration, $save = TRUE) { |
|
197 | 197 | $existing_reg_status = $registration->status_ID(); |
198 | 198 | // set initial REG_Status |
199 | - $this->set_old_reg_status( $registration->ID(), $existing_reg_status ); |
|
199 | + $this->set_old_reg_status($registration->ID(), $existing_reg_status); |
|
200 | 200 | // is the registration currently incomplete ? |
201 | - if ( $registration->status_ID() === EEM_Registration::status_id_incomplete ) { |
|
201 | + if ($registration->status_ID() === EEM_Registration::status_id_incomplete) { |
|
202 | 202 | // grab default reg status for the event, if set |
203 | 203 | $event_default_registration_status = $registration->event()->default_registration_status(); |
204 | 204 | // if no default reg status is set for the event, then use the global value |
205 | - $STS_ID = ! empty( $event_default_registration_status ) |
|
205 | + $STS_ID = ! empty($event_default_registration_status) |
|
206 | 206 | ? $event_default_registration_status |
207 | 207 | : EE_Registry::instance()->CFG->registration->default_STS_ID; |
208 | 208 | // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered |
209 | 209 | $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment : $STS_ID; |
210 | 210 | // set incoming REG_Status |
211 | - $this->set_new_reg_status( $registration->ID(), $STS_ID ); |
|
212 | - $registration->set_status( $STS_ID ); |
|
213 | - if ( $save ) { |
|
211 | + $this->set_new_reg_status($registration->ID(), $STS_ID); |
|
212 | + $registration->set_status($STS_ID); |
|
213 | + if ($save) { |
|
214 | 214 | $registration->save(); |
215 | 215 | } |
216 | 216 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
217 | - if ( ! EE_Processor_Base::$IPN ) { |
|
217 | + if ( ! EE_Processor_Base::$IPN) { |
|
218 | 218 | // otherwise, send out notifications |
219 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 ); |
|
219 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
220 | 220 | } |
221 | 221 | // DEBUG LOG |
222 | 222 | //$this->log( |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | * @return boolean |
242 | 242 | * @throws \EE_Error |
243 | 243 | */ |
244 | - public function toggle_registration_status_for_default_approved_events( EE_Registration $registration, $save = TRUE ) { |
|
244 | + public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = TRUE) { |
|
245 | 245 | $reg_status = $registration->status_ID(); |
246 | 246 | // set initial REG_Status |
247 | - $this->set_old_reg_status( $registration->ID(), $reg_status ); |
|
247 | + $this->set_old_reg_status($registration->ID(), $reg_status); |
|
248 | 248 | // if not already, toggle reg status to approved IF the event default reg status is approved |
249 | 249 | // ( as long as the registration wasn't cancelled or declined at some point ) |
250 | 250 | if ( |
@@ -254,16 +254,16 @@ discard block |
||
254 | 254 | $registration->event()->default_registration_status() === EEM_Registration::status_id_approved |
255 | 255 | ) { |
256 | 256 | // set incoming REG_Status |
257 | - $this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved ); |
|
257 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
258 | 258 | // toggle status to approved |
259 | - $registration->set_status( EEM_Registration::status_id_approved ); |
|
260 | - if ( $save ) { |
|
259 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
260 | + if ($save) { |
|
261 | 261 | $registration->save(); |
262 | 262 | } |
263 | 263 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
264 | - if ( ! EE_Processor_Base::$IPN ) { |
|
264 | + if ( ! EE_Processor_Base::$IPN) { |
|
265 | 265 | // otherwise, send out notifications |
266 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 ); |
|
266 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
267 | 267 | } |
268 | 268 | // DEBUG LOG |
269 | 269 | //$this->log( |
@@ -291,19 +291,19 @@ discard block |
||
291 | 291 | * @return bool |
292 | 292 | * @throws \EE_Error |
293 | 293 | */ |
294 | - public function toggle_registration_status_if_no_monies_owing( EE_Registration $registration, $save = TRUE, $additional_details = array() ) { |
|
294 | + public function toggle_registration_status_if_no_monies_owing(EE_Registration $registration, $save = TRUE, $additional_details = array()) { |
|
295 | 295 | // set initial REG_Status |
296 | - $this->set_old_reg_status( $registration->ID(), $registration->status_ID() ); |
|
296 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
297 | 297 | //EEH_Debug_Tools::printr( $additional_details, '$additional_details', __FILE__, __LINE__ ); |
298 | 298 | // was a payment just made ? |
299 | 299 | if ( |
300 | - isset( $additional_details[ 'payment_updates' ], $additional_details[ 'last_payment' ] ) && |
|
301 | - $additional_details[ 'payment_updates' ] && |
|
302 | - $additional_details[ 'last_payment' ] instanceof EE_Payment |
|
300 | + isset($additional_details['payment_updates'], $additional_details['last_payment']) && |
|
301 | + $additional_details['payment_updates'] && |
|
302 | + $additional_details['last_payment'] instanceof EE_Payment |
|
303 | 303 | ) { |
304 | - $payment = $additional_details[ 'last_payment' ]; |
|
304 | + $payment = $additional_details['last_payment']; |
|
305 | 305 | $total_paid = 0; |
306 | - foreach ( self::$_amount_paid as $reg => $amount_paid ) { |
|
306 | + foreach (self::$_amount_paid as $reg => $amount_paid) { |
|
307 | 307 | $total_paid += $amount_paid; |
308 | 308 | } |
309 | 309 | } else { |
@@ -327,30 +327,30 @@ discard block |
||
327 | 327 | $registration->transaction()->is_completed() || |
328 | 328 | $registration->transaction()->is_overpaid() || |
329 | 329 | $registration->transaction()->is_free() || |
330 | - apply_filters( 'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration ) |
|
330 | + apply_filters('FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing', false, $registration) |
|
331 | 331 | ) || ( |
332 | 332 | $payment instanceof EE_Payment && |
333 | 333 | $payment->is_approved() && |
334 | 334 | // this specific registration has not yet been paid for |
335 | - ! isset( self::$_amount_paid[ $registration->ID() ] ) && |
|
335 | + ! isset(self::$_amount_paid[$registration->ID()]) && |
|
336 | 336 | // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price |
337 | 337 | $payment->amount() - $total_paid >= $registration->final_price() |
338 | 338 | ) |
339 | 339 | ) |
340 | 340 | ) { |
341 | 341 | // mark as paid |
342 | - self::$_amount_paid[ $registration->ID() ] = $registration->final_price(); |
|
342 | + self::$_amount_paid[$registration->ID()] = $registration->final_price(); |
|
343 | 343 | // track new REG_Status |
344 | - $this->set_new_reg_status( $registration->ID(), EEM_Registration::status_id_approved ); |
|
344 | + $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved); |
|
345 | 345 | // toggle status to approved |
346 | - $registration->set_status( EEM_Registration::status_id_approved ); |
|
347 | - if ( $save ) { |
|
346 | + $registration->set_status(EEM_Registration::status_id_approved); |
|
347 | + if ($save) { |
|
348 | 348 | $registration->save(); |
349 | 349 | } |
350 | 350 | // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor |
351 | - if ( ! EE_Processor_Base::$IPN ) { |
|
351 | + if ( ! EE_Processor_Base::$IPN) { |
|
352 | 352 | // otherwise, send out notifications |
353 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10 ); |
|
353 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10); |
|
354 | 354 | } |
355 | 355 | // DEBUG LOG |
356 | 356 | //$this->log( |
@@ -376,27 +376,27 @@ discard block |
||
376 | 376 | * @param array $additional_details |
377 | 377 | * @return void |
378 | 378 | */ |
379 | - public function trigger_registration_update_notifications( $registration, $additional_details = array() ) { |
|
379 | + public function trigger_registration_update_notifications($registration, $additional_details = array()) { |
|
380 | 380 | try { |
381 | - if ( ! $registration instanceof EE_Registration ) { |
|
382 | - throw new EE_Error( __( 'An invalid registration was received.', 'event_espresso' ) ); |
|
381 | + if ( ! $registration instanceof EE_Registration) { |
|
382 | + throw new EE_Error(__('An invalid registration was received.', 'event_espresso')); |
|
383 | 383 | } |
384 | - EE_Registry::instance()->load_helper( 'Debug_Tools' ); |
|
384 | + EE_Registry::instance()->load_helper('Debug_Tools'); |
|
385 | 385 | EEH_Debug_Tools::log( |
386 | 386 | __CLASS__, |
387 | 387 | __FUNCTION__, |
388 | 388 | __LINE__, |
389 | - array( $registration->transaction(), $additional_details ), |
|
389 | + array($registration->transaction(), $additional_details), |
|
390 | 390 | false, |
391 | - 'EE_Transaction: ' . $registration->transaction()->ID() |
|
391 | + 'EE_Transaction: '.$registration->transaction()->ID() |
|
392 | 392 | ); |
393 | 393 | do_action( |
394 | 394 | 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
395 | 395 | $registration, |
396 | 396 | $additional_details |
397 | 397 | ); |
398 | - } catch( Exception $e ) { |
|
399 | - EE_Error::add_error( $e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine() ); |
|
398 | + } catch (Exception $e) { |
|
399 | + EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine()); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
@@ -410,22 +410,22 @@ discard block |
||
410 | 410 | * @return bool |
411 | 411 | * @throws \EE_Error |
412 | 412 | */ |
413 | - public function update_registration_after_checkout_or_payment( EE_Registration $registration, $additional_details = array() ) { |
|
413 | + public function update_registration_after_checkout_or_payment(EE_Registration $registration, $additional_details = array()) { |
|
414 | 414 | // set initial REG_Status |
415 | - $this->set_old_reg_status( $registration->ID(), $registration->status_ID() ); |
|
415 | + $this->set_old_reg_status($registration->ID(), $registration->status_ID()); |
|
416 | 416 | |
417 | 417 | // if the registration status gets updated, then save the registration |
418 | 418 | if ( |
419 | - $this->toggle_registration_status_for_default_approved_events( $registration, false ) |
|
420 | - || $this->toggle_registration_status_if_no_monies_owing( $registration, false, $additional_details ) |
|
419 | + $this->toggle_registration_status_for_default_approved_events($registration, false) |
|
420 | + || $this->toggle_registration_status_if_no_monies_owing($registration, false, $additional_details) |
|
421 | 421 | ) { |
422 | 422 | $registration->save(); |
423 | 423 | } |
424 | 424 | |
425 | 425 | // set new REG_Status |
426 | - $this->set_new_reg_status( $registration->ID(), $registration->status_ID() ); |
|
427 | - return $this->reg_status_updated( $registration->ID() ) |
|
428 | - && $this->new_reg_status( $registration->ID() ) === EEM_Registration::status_id_approved |
|
426 | + $this->set_new_reg_status($registration->ID(), $registration->status_ID()); |
|
427 | + return $this->reg_status_updated($registration->ID()) |
|
428 | + && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved |
|
429 | 429 | ? true |
430 | 430 | : false; |
431 | 431 | } |
@@ -441,20 +441,20 @@ discard block |
||
441 | 441 | * @return void |
442 | 442 | * @throws \EE_Error |
443 | 443 | */ |
444 | - public function update_registration_final_prices( $transaction, $save_regs = true ) { |
|
445 | - $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $transaction->total_line_item() ); |
|
446 | - foreach( $transaction->registrations() as $registration ) { |
|
444 | + public function update_registration_final_prices($transaction, $save_regs = true) { |
|
445 | + $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item($transaction->total_line_item()); |
|
446 | + foreach ($transaction->registrations() as $registration) { |
|
447 | 447 | /** @var EE_Line_Item $line_item */ |
448 | - $line_item = EEM_Line_Item::instance()->get_line_item_for_registration( $registration ); |
|
449 | - if( isset( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] ) ) { |
|
450 | - $registration->set_final_price( $reg_final_price_per_ticket_line_item[ $line_item->ID() ] ); |
|
451 | - if( $save_regs ) { |
|
448 | + $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration); |
|
449 | + if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) { |
|
450 | + $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]); |
|
451 | + if ($save_regs) { |
|
452 | 452 | $registration->save(); |
453 | 453 | } |
454 | 454 | } |
455 | 455 | } |
456 | 456 | //and make sure there's no rounding problem |
457 | - $this->fix_reg_final_price_rounding_issue( $transaction ); |
|
457 | + $this->fix_reg_final_price_rounding_issue($transaction); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | * @return boolean success verifying that there is NO difference after this method is done |
475 | 475 | * @throws \EE_Error |
476 | 476 | */ |
477 | - public function fix_reg_final_price_rounding_issue( $transaction ) { |
|
477 | + public function fix_reg_final_price_rounding_issue($transaction) { |
|
478 | 478 | $reg_final_price_sum = EEM_Registration::instance()->sum( |
479 | 479 | array( |
480 | 480 | array( |
@@ -483,9 +483,9 @@ discard block |
||
483 | 483 | ), |
484 | 484 | 'REG_final_price' |
485 | 485 | ); |
486 | - $diff = $transaction->total() - (float) $reg_final_price_sum; |
|
486 | + $diff = $transaction->total() - (float) $reg_final_price_sum; |
|
487 | 487 | //ok then, just grab one of the registrations |
488 | - if( $diff !== 0 ) { |
|
488 | + if ($diff !== 0) { |
|
489 | 489 | $a_reg = EEM_Registration::instance()->get_one( |
490 | 490 | array( |
491 | 491 | array( |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | )); |
495 | 495 | $success = $a_reg instanceof EE_Registration |
496 | 496 | ? $a_reg->save( |
497 | - array( 'REG_final_price' => $a_reg->final_price() + $diff ) |
|
497 | + array('REG_final_price' => $a_reg->final_price() + $diff) |
|
498 | 498 | ) |
499 | 499 | : false; |
500 | 500 | return $success ? true : false; |
@@ -519,13 +519,13 @@ discard block |
||
519 | 519 | $update_reg = true |
520 | 520 | ) { |
521 | 521 | // these reg statuses should not be considered in any calculations involving monies owing |
522 | - $closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses |
|
522 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
523 | 523 | : EEM_Registration::closed_reg_statuses(); |
524 | - if ( ! in_array( $registration->status_ID(), $closed_reg_statuses ) ) { |
|
524 | + if ( ! in_array($registration->status_ID(), $closed_reg_statuses)) { |
|
525 | 525 | return false; |
526 | 526 | } |
527 | 527 | $registration->set_final_price(0); |
528 | - if ( $update_reg ) { |
|
528 | + if ($update_reg) { |
|
529 | 529 | $registration->save(); |
530 | 530 | } |
531 | 531 | return true; |
@@ -548,23 +548,23 @@ discard block |
||
548 | 548 | $update_reg = true |
549 | 549 | ) { |
550 | 550 | // these reg statuses should not be considered in any calculations involving monies owing |
551 | - $closed_reg_statuses = ! empty( $closed_reg_statuses ) ? $closed_reg_statuses |
|
551 | + $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses |
|
552 | 552 | : EEM_Registration::closed_reg_statuses(); |
553 | - if ( in_array( $registration->status_ID(), $closed_reg_statuses ) ) { |
|
553 | + if (in_array($registration->status_ID(), $closed_reg_statuses)) { |
|
554 | 554 | return false; |
555 | 555 | } |
556 | 556 | $ticket = $registration->ticket(); |
557 | - if ( ! $ticket instanceof EE_Ticket ) { |
|
557 | + if ( ! $ticket instanceof EE_Ticket) { |
|
558 | 558 | throw new EE_Error( |
559 | 559 | sprintf( |
560 | - __( 'The Ticket for Registration %1$d was not found or is invalid.', |
|
561 | - 'event_espresso' ), |
|
560 | + __('The Ticket for Registration %1$d was not found or is invalid.', |
|
561 | + 'event_espresso'), |
|
562 | 562 | $registration->ticket_ID() |
563 | 563 | ) |
564 | 564 | ); |
565 | 565 | } |
566 | - $registration->set_final_price( $ticket->price() ); |
|
567 | - if ( $update_reg ) { |
|
566 | + $registration->set_final_price($ticket->price()); |
|
567 | + if ($update_reg) { |
|
568 | 568 | $registration->save(); |
569 | 569 | } |
570 | 570 | return true; |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | $total_ticket_count = 1 |
603 | 603 | ) { |
604 | 604 | EE_Error::doing_it_wrong( |
605 | - __CLASS__ . '::' . __FUNCTION__, |
|
605 | + __CLASS__.'::'.__FUNCTION__, |
|
606 | 606 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
607 | 607 | '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'), |
608 | 608 | '4.9.1', |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | public function generate_reg_url_link($att_nmbr, $item) |
646 | 646 | { |
647 | 647 | EE_Error::doing_it_wrong( |
648 | - __CLASS__ . '::' . __FUNCTION__, |
|
648 | + __CLASS__.'::'.__FUNCTION__, |
|
649 | 649 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
650 | 650 | 'EventEspresso\core\domain\entities\RegUrlLink'), |
651 | 651 | '4.9.1', |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | if( isset( $this->_children[ $code ] ) ) { |
672 | 672 | unset( $this->_children[ $code ] ); |
673 | 673 | return 1; |
674 | - }else{ |
|
674 | + } else{ |
|
675 | 675 | return 0; |
676 | 676 | } |
677 | 677 | } |
@@ -1110,10 +1110,10 @@ discard block |
||
1110 | 1110 | //that's taxable too (the taxable total so far) |
1111 | 1111 | if( $child_line_item->is_percent() ) { |
1112 | 1112 | $total = $total + ( $total * $child_line_item->percent() / 100 ); |
1113 | - }else{ |
|
1113 | + } else{ |
|
1114 | 1114 | $total += $child_line_item->total(); |
1115 | 1115 | } |
1116 | - }elseif( $child_line_item->type() === EEM_Line_Item::type_sub_total ){ |
|
1116 | + } elseif( $child_line_item->type() === EEM_Line_Item::type_sub_total ){ |
|
1117 | 1117 | $total += $child_line_item->taxable_total(); |
1118 | 1118 | } |
1119 | 1119 | } |
@@ -218,24 +218,24 @@ |
||
218 | 218 | * @return string |
219 | 219 | */ |
220 | 220 | function OBJ_type_i18n() { |
221 | - $obj_type = $this->OBJ_type(); |
|
222 | - switch ($obj_type) { |
|
223 | - case 'Event': |
|
224 | - $obj_type = __('Event', 'event_espresso'); |
|
225 | - break; |
|
226 | - case 'Price': |
|
227 | - $obj_type = __('Price', 'event_espresso'); |
|
228 | - break; |
|
229 | - case 'Promotion': |
|
230 | - $obj_type = __('Promotion', 'event_espresso'); |
|
231 | - break; |
|
232 | - case 'Ticket': |
|
233 | - $obj_type = __('Ticket', 'event_espresso'); |
|
234 | - break; |
|
235 | - case 'Transaction': |
|
236 | - $obj_type = __('Transaction', 'event_espresso'); |
|
237 | - break; |
|
238 | - } |
|
221 | + $obj_type = $this->OBJ_type(); |
|
222 | + switch ($obj_type) { |
|
223 | + case 'Event': |
|
224 | + $obj_type = __('Event', 'event_espresso'); |
|
225 | + break; |
|
226 | + case 'Price': |
|
227 | + $obj_type = __('Price', 'event_espresso'); |
|
228 | + break; |
|
229 | + case 'Promotion': |
|
230 | + $obj_type = __('Promotion', 'event_espresso'); |
|
231 | + break; |
|
232 | + case 'Ticket': |
|
233 | + $obj_type = __('Ticket', 'event_espresso'); |
|
234 | + break; |
|
235 | + case 'Transaction': |
|
236 | + $obj_type = __('Transaction', 'event_espresso'); |
|
237 | + break; |
|
238 | + } |
|
239 | 239 | return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
240 | 240 | } |
241 | 241 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | * date_format and the second value is the time format |
51 | 51 | * @return EE_Line_Item |
52 | 52 | */ |
53 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
54 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
55 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
53 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
54 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
55 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * the website will be used. |
64 | 64 | * @return EE_Line_Item |
65 | 65 | */ |
66 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
67 | - return new self( $props_n_values, TRUE, $timezone ); |
|
66 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
67 | + return new self($props_n_values, TRUE, $timezone); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | * @param bool $bydb |
76 | 76 | * @param string $timezone |
77 | 77 | */ |
78 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '' ) { |
|
79 | - parent::__construct( $fieldValues, $bydb, $timezone ); |
|
80 | - if ( ! $this->get( 'LIN_code' ) ) { |
|
81 | - $this->set_code( $this->generate_code() ); |
|
78 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '') { |
|
79 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
80 | + if ( ! $this->get('LIN_code')) { |
|
81 | + $this->set_code($this->generate_code()); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * @return int |
90 | 90 | */ |
91 | 91 | public function ID() { |
92 | - return $this->get( 'LIN_ID' ); |
|
92 | + return $this->get('LIN_ID'); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @return int |
100 | 100 | */ |
101 | 101 | public function TXN_ID() { |
102 | - return $this->get( 'TXN_ID' ); |
|
102 | + return $this->get('TXN_ID'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * @param int $TXN_ID |
110 | 110 | * @return boolean |
111 | 111 | */ |
112 | - public function set_TXN_ID( $TXN_ID ) { |
|
113 | - $this->set( 'TXN_ID', $TXN_ID ); |
|
112 | + public function set_TXN_ID($TXN_ID) { |
|
113 | + $this->set('TXN_ID', $TXN_ID); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | * @return string |
121 | 121 | */ |
122 | 122 | public function name() { |
123 | - $name = $this->get( 'LIN_name' ); |
|
124 | - if( ! $name ){ |
|
125 | - $name = ucwords( str_replace( '-', ' ', $this->type() ) ); |
|
123 | + $name = $this->get('LIN_name'); |
|
124 | + if ( ! $name) { |
|
125 | + $name = ucwords(str_replace('-', ' ', $this->type())); |
|
126 | 126 | } |
127 | 127 | return $name; |
128 | 128 | } |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @param string $name |
135 | 135 | * @return boolean |
136 | 136 | */ |
137 | - public function set_name( $name ) { |
|
138 | - $this->set( 'LIN_name', $name ); |
|
137 | + public function set_name($name) { |
|
138 | + $this->set('LIN_name', $name); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @return string |
146 | 146 | */ |
147 | 147 | public function desc() { |
148 | - return $this->get( 'LIN_desc' ); |
|
148 | + return $this->get('LIN_desc'); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * @param string $desc |
156 | 156 | * @return boolean |
157 | 157 | */ |
158 | - public function set_desc( $desc ) { |
|
159 | - $this->set( 'LIN_desc', $desc ); |
|
158 | + public function set_desc($desc) { |
|
159 | + $this->set('LIN_desc', $desc); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @return int |
167 | 167 | */ |
168 | 168 | public function quantity() { |
169 | - return $this->get( 'LIN_quantity' ); |
|
169 | + return $this->get('LIN_quantity'); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | * @param int $quantity |
177 | 177 | * @return boolean |
178 | 178 | */ |
179 | - function set_quantity( $quantity ) { |
|
180 | - $this->set( 'LIN_quantity', max( $quantity, 0 ) ); |
|
179 | + function set_quantity($quantity) { |
|
180 | + $this->set('LIN_quantity', max($quantity, 0)); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @return string |
188 | 188 | */ |
189 | 189 | public function OBJ_ID() { |
190 | - return $this->get( 'OBJ_ID' ); |
|
190 | + return $this->get('OBJ_ID'); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | * @param string $item_id |
198 | 198 | * @return boolean |
199 | 199 | */ |
200 | - public function set_OBJ_ID( $item_id ) { |
|
201 | - $this->set( 'OBJ_ID', $item_id ); |
|
200 | + public function set_OBJ_ID($item_id) { |
|
201 | + $this->set('OBJ_ID', $item_id); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | * @return string |
209 | 209 | */ |
210 | 210 | public function OBJ_type() { |
211 | - return $this->get( 'OBJ_type' ); |
|
211 | + return $this->get('OBJ_type'); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | * @param string $OBJ_type |
247 | 247 | * @return boolean |
248 | 248 | */ |
249 | - public function set_OBJ_type( $OBJ_type ) { |
|
250 | - $this->set( 'OBJ_type', $OBJ_type ); |
|
249 | + public function set_OBJ_type($OBJ_type) { |
|
250 | + $this->set('OBJ_type', $OBJ_type); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @return float |
258 | 258 | */ |
259 | 259 | public function unit_price() { |
260 | - return $this->get( 'LIN_unit_price' ); |
|
260 | + return $this->get('LIN_unit_price'); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | |
@@ -267,8 +267,8 @@ discard block |
||
267 | 267 | * @param float $unit_price |
268 | 268 | * @return boolean |
269 | 269 | */ |
270 | - public function set_unit_price( $unit_price ) { |
|
271 | - $this->set( 'LIN_unit_price', $unit_price ); |
|
270 | + public function set_unit_price($unit_price) { |
|
271 | + $this->set('LIN_unit_price', $unit_price); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | |
@@ -279,19 +279,19 @@ discard block |
||
279 | 279 | * @return boolean |
280 | 280 | */ |
281 | 281 | public function is_percent() { |
282 | - if( $this->is_tax_sub_total() ) { |
|
282 | + if ($this->is_tax_sub_total()) { |
|
283 | 283 | //tax subtotals HAVE a percent on them, that percentage only applies |
284 | 284 | //to taxable items, so its' an exception. Treat it like a flat line item |
285 | 285 | return false; |
286 | 286 | } |
287 | - $unit_price = abs( $this->get( 'LIN_unit_price' ) ); |
|
288 | - $percent = abs( $this->get( 'LIN_percent' ) ); |
|
289 | - if ( $unit_price < .001 && $percent ) { |
|
287 | + $unit_price = abs($this->get('LIN_unit_price')); |
|
288 | + $percent = abs($this->get('LIN_percent')); |
|
289 | + if ($unit_price < .001 && $percent) { |
|
290 | 290 | return TRUE; |
291 | - } elseif ( $unit_price >= .001 && !$percent ) { |
|
291 | + } elseif ($unit_price >= .001 && ! $percent) { |
|
292 | 292 | return FALSE; |
293 | - } elseif ( $unit_price >= .001 && $percent ) { |
|
294 | - throw new EE_Error( sprintf( __( "A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso" ), $unit_price, $percent ) ); |
|
293 | + } elseif ($unit_price >= .001 && $percent) { |
|
294 | + throw new EE_Error(sprintf(__("A Line Item can not have a unit price of (%s) AND a percent (%s)!", "event_espresso"), $unit_price, $percent)); |
|
295 | 295 | } else { |
296 | 296 | // if they're both 0, assume its not a percent item |
297 | 297 | return FALSE; |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | * @return float |
306 | 306 | */ |
307 | 307 | public function percent() { |
308 | - return $this->get( 'LIN_percent' ); |
|
308 | + return $this->get('LIN_percent'); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | |
@@ -315,8 +315,8 @@ discard block |
||
315 | 315 | * @param float $percent |
316 | 316 | * @return boolean |
317 | 317 | */ |
318 | - public function set_percent( $percent ) { |
|
319 | - $this->set( 'LIN_percent', $percent ); |
|
318 | + public function set_percent($percent) { |
|
319 | + $this->set('LIN_percent', $percent); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | * @return float |
327 | 327 | */ |
328 | 328 | public function total() { |
329 | - return $this->get( 'LIN_total' ); |
|
329 | + return $this->get('LIN_total'); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | * @param float $total |
337 | 337 | * @return boolean |
338 | 338 | */ |
339 | - public function set_total( $total ) { |
|
340 | - $this->set( 'LIN_total', $total ); |
|
339 | + public function set_total($total) { |
|
340 | + $this->set('LIN_total', $total); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * @return int |
348 | 348 | */ |
349 | 349 | public function order() { |
350 | - return $this->get( 'LIN_order' ); |
|
350 | + return $this->get('LIN_order'); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | * Sets order |
357 | 357 | * @param int $order |
358 | 358 | */ |
359 | - public function set_order( $order ) { |
|
360 | - $this->set( 'LIN_order', $order ); |
|
359 | + public function set_order($order) { |
|
360 | + $this->set('LIN_order', $order); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | * @return int |
368 | 368 | */ |
369 | 369 | public function parent_ID() { |
370 | - return $this->get( 'LIN_parent' ); |
|
370 | + return $this->get('LIN_parent'); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | |
@@ -377,8 +377,8 @@ discard block |
||
377 | 377 | * @param int $parent |
378 | 378 | * @return boolean |
379 | 379 | */ |
380 | - public function set_parent_ID( $parent ) { |
|
381 | - $this->set( 'LIN_parent', $parent ); |
|
380 | + public function set_parent_ID($parent) { |
|
381 | + $this->set('LIN_parent', $parent); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | * @return string |
389 | 389 | */ |
390 | 390 | public function type() { |
391 | - return $this->get( 'LIN_type' ); |
|
391 | + return $this->get('LIN_type'); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | |
@@ -398,8 +398,8 @@ discard block |
||
398 | 398 | * @param string $type |
399 | 399 | * @return boolean |
400 | 400 | */ |
401 | - public function set_type( $type ) { |
|
402 | - $this->set( 'LIN_type', $type ); |
|
401 | + public function set_type($type) { |
|
402 | + $this->set('LIN_type', $type); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | * @return EE_Line_Item |
413 | 413 | */ |
414 | 414 | public function parent() { |
415 | - if( $this->ID() ) { |
|
416 | - return $this->get_model()->get_one_by_ID( $this->parent_ID() ); |
|
415 | + if ($this->ID()) { |
|
416 | + return $this->get_model()->get_one_by_ID($this->parent_ID()); |
|
417 | 417 | } else { |
418 | 418 | return $this->_parent; |
419 | 419 | } |
@@ -426,13 +426,13 @@ discard block |
||
426 | 426 | * @return EE_Line_Item[] |
427 | 427 | */ |
428 | 428 | public function children() { |
429 | - if ( $this->ID() ) { |
|
429 | + if ($this->ID()) { |
|
430 | 430 | return $this->get_model()->get_all( |
431 | 431 | array( |
432 | - array( 'LIN_parent' => $this->ID() ), |
|
433 | - 'order_by' => array( 'LIN_order' => 'ASC' ) ) ); |
|
432 | + array('LIN_parent' => $this->ID()), |
|
433 | + 'order_by' => array('LIN_order' => 'ASC') ) ); |
|
434 | 434 | } else { |
435 | - if ( ! is_array( $this->_children ) ) { |
|
435 | + if ( ! is_array($this->_children)) { |
|
436 | 436 | $this->_children = array(); |
437 | 437 | } |
438 | 438 | return $this->_children; |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | * @return string |
447 | 447 | */ |
448 | 448 | public function code() { |
449 | - return $this->get( 'LIN_code' ); |
|
449 | + return $this->get('LIN_code'); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | |
@@ -456,8 +456,8 @@ discard block |
||
456 | 456 | * @param string $code |
457 | 457 | * @return boolean |
458 | 458 | */ |
459 | - public function set_code( $code ) { |
|
460 | - $this->set( 'LIN_code', $code ); |
|
459 | + public function set_code($code) { |
|
460 | + $this->set('LIN_code', $code); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | * @return boolean |
468 | 468 | */ |
469 | 469 | public function is_taxable() { |
470 | - return $this->get( 'LIN_is_taxable' ); |
|
470 | + return $this->get('LIN_is_taxable'); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | |
@@ -477,8 +477,8 @@ discard block |
||
477 | 477 | * @param boolean $is_taxable |
478 | 478 | * @return boolean |
479 | 479 | */ |
480 | - public function set_is_taxable( $is_taxable ) { |
|
481 | - $this->set( 'LIN_is_taxable', $is_taxable ); |
|
480 | + public function set_is_taxable($is_taxable) { |
|
481 | + $this->set('LIN_is_taxable', $is_taxable); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | */ |
494 | 494 | public function get_object() { |
495 | 495 | $model_name_of_related_obj = $this->OBJ_type(); |
496 | - return $this->get_model()->has_relation( $model_name_of_related_obj ) ? $this->get_first_related( $model_name_of_related_obj ) : NULL; |
|
496 | + return $this->get_model()->has_relation($model_name_of_related_obj) ? $this->get_first_related($model_name_of_related_obj) : NULL; |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | |
@@ -504,11 +504,11 @@ discard block |
||
504 | 504 | * @param array $query_params |
505 | 505 | * @return EE_Ticket |
506 | 506 | */ |
507 | - public function ticket( $query_params = array() ) { |
|
507 | + public function ticket($query_params = array()) { |
|
508 | 508 | //we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived. This can be overridden via the incoming $query_params argument |
509 | - $remove_defaults = array( 'default_where_conditions' => 'none' ); |
|
510 | - $query_params = array_merge( $remove_defaults, $query_params ); |
|
511 | - return $this->get_first_related( 'Ticket', $query_params ); |
|
509 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
510 | + $query_params = array_merge($remove_defaults, $query_params); |
|
511 | + return $this->get_first_related('Ticket', $query_params); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | |
@@ -518,11 +518,11 @@ discard block |
||
518 | 518 | * @return EE_Datetime | NULL |
519 | 519 | */ |
520 | 520 | public function get_ticket_datetime() { |
521 | - if ( $this->OBJ_type() === 'Ticket' ) { |
|
521 | + if ($this->OBJ_type() === 'Ticket') { |
|
522 | 522 | $ticket = $this->ticket(); |
523 | - if ( $ticket instanceof EE_Ticket ) { |
|
523 | + if ($ticket instanceof EE_Ticket) { |
|
524 | 524 | $datetime = $ticket->first_datetime(); |
525 | - if ( $datetime instanceof EE_Datetime ) { |
|
525 | + if ($datetime instanceof EE_Datetime) { |
|
526 | 526 | return $datetime; |
527 | 527 | } |
528 | 528 | } |
@@ -538,9 +538,9 @@ discard block |
||
538 | 538 | * @return string |
539 | 539 | */ |
540 | 540 | public function ticket_event_name() { |
541 | - $event_name = __( "Unknown", "event_espresso" ); |
|
541 | + $event_name = __("Unknown", "event_espresso"); |
|
542 | 542 | $event = $this->ticket_event(); |
543 | - if ( $event instanceof EE_Event ) { |
|
543 | + if ($event instanceof EE_Event) { |
|
544 | 544 | $event_name = $event->name(); |
545 | 545 | } |
546 | 546 | return $event_name; |
@@ -554,9 +554,9 @@ discard block |
||
554 | 554 | public function ticket_event() { |
555 | 555 | $event = null; |
556 | 556 | $ticket = $this->ticket(); |
557 | - if ( $ticket instanceof EE_Ticket ) { |
|
557 | + if ($ticket instanceof EE_Ticket) { |
|
558 | 558 | $datetime = $ticket->first_datetime(); |
559 | - if ( $datetime instanceof EE_Datetime ) { |
|
559 | + if ($datetime instanceof EE_Datetime) { |
|
560 | 560 | $event = $datetime->event(); |
561 | 561 | } |
562 | 562 | } |
@@ -571,11 +571,11 @@ discard block |
||
571 | 571 | * @param string $time_format |
572 | 572 | * @return string |
573 | 573 | */ |
574 | - public function ticket_datetime_start( $date_format = '', $time_format = '' ) { |
|
575 | - $first_datetime_string = __( "Unknown", "event_espresso" ); |
|
574 | + public function ticket_datetime_start($date_format = '', $time_format = '') { |
|
575 | + $first_datetime_string = __("Unknown", "event_espresso"); |
|
576 | 576 | $datetime = $this->get_ticket_datetime(); |
577 | - if ( $datetime ) { |
|
578 | - $first_datetime_string = $datetime->start_date_and_time( $date_format, $time_format ); |
|
577 | + if ($datetime) { |
|
578 | + $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
579 | 579 | } |
580 | 580 | return $first_datetime_string; |
581 | 581 | } |
@@ -590,26 +590,26 @@ discard block |
||
590 | 590 | * @return bool success |
591 | 591 | * @throws \EE_Error |
592 | 592 | */ |
593 | - public function add_child_line_item( EEI_Line_Item $line_item, $set_order = true ) { |
|
593 | + public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) { |
|
594 | 594 | // should we calculate the LIN_order for this line item ? |
595 | - if ( $set_order || $line_item->order() === null ) { |
|
596 | - $line_item->set_order( count( $this->children() ) ); |
|
595 | + if ($set_order || $line_item->order() === null) { |
|
596 | + $line_item->set_order(count($this->children())); |
|
597 | 597 | } |
598 | - if ( $this->ID() ) { |
|
598 | + if ($this->ID()) { |
|
599 | 599 | //check for any duplicate line items (with the same code), if so, this replaces it |
600 | - $line_item_with_same_code = $this->get_child_line_item( $line_item->code() ); |
|
601 | - if( $line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item ) { |
|
602 | - $this->delete_child_line_item( $line_item_with_same_code->code() ); |
|
600 | + $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
601 | + if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
602 | + $this->delete_child_line_item($line_item_with_same_code->code()); |
|
603 | 603 | } |
604 | - $line_item->set_parent_ID( $this->ID() ); |
|
605 | - if( $this->TXN_ID() ){ |
|
606 | - $line_item->set_TXN_ID( $this->TXN_ID() ); |
|
604 | + $line_item->set_parent_ID($this->ID()); |
|
605 | + if ($this->TXN_ID()) { |
|
606 | + $line_item->set_TXN_ID($this->TXN_ID()); |
|
607 | 607 | } |
608 | 608 | return $line_item->save(); |
609 | 609 | } else { |
610 | - $this->_children[ $line_item->code() ] = $line_item; |
|
611 | - if( $line_item->parent() != $this ) { |
|
612 | - $line_item->set_parent( $this ); |
|
610 | + $this->_children[$line_item->code()] = $line_item; |
|
611 | + if ($line_item->parent() != $this) { |
|
612 | + $line_item->set_parent($this); |
|
613 | 613 | } |
614 | 614 | return TRUE; |
615 | 615 | } |
@@ -623,16 +623,16 @@ discard block |
||
623 | 623 | * @param EE_Line_Item $line_item |
624 | 624 | * |
625 | 625 | */ |
626 | - public function set_parent( $line_item ) { |
|
627 | - if ( $this->ID() ) { |
|
628 | - if( ! $line_item->ID() ) { |
|
626 | + public function set_parent($line_item) { |
|
627 | + if ($this->ID()) { |
|
628 | + if ( ! $line_item->ID()) { |
|
629 | 629 | $line_item->save(); |
630 | 630 | } |
631 | - $this->set_parent_ID( $line_item->ID() ); |
|
631 | + $this->set_parent_ID($line_item->ID()); |
|
632 | 632 | $this->save(); |
633 | 633 | } else { |
634 | 634 | $this->_parent = $line_item; |
635 | - $this->set_parent_ID( $line_item->ID() ); |
|
635 | + $this->set_parent_ID($line_item->ID()); |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | |
@@ -645,11 +645,11 @@ discard block |
||
645 | 645 | * @param string $code |
646 | 646 | * @return EE_Line_Item |
647 | 647 | */ |
648 | - public function get_child_line_item( $code ) { |
|
649 | - if ( $this->ID() ) { |
|
650 | - return $this->get_model()->get_one( array( array( 'LIN_parent' => $this->ID(), 'LIN_code' => $code ) ) ); |
|
648 | + public function get_child_line_item($code) { |
|
649 | + if ($this->ID()) { |
|
650 | + return $this->get_model()->get_one(array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))); |
|
651 | 651 | } else { |
652 | - return isset( $this->_children[ $code ] ) ? $this->_children[ $code ] : null; |
|
652 | + return isset($this->_children[$code]) ? $this->_children[$code] : null; |
|
653 | 653 | } |
654 | 654 | } |
655 | 655 | |
@@ -660,10 +660,10 @@ discard block |
||
660 | 660 | * @return int |
661 | 661 | */ |
662 | 662 | public function delete_children_line_items() { |
663 | - if ( $this->ID() ) { |
|
664 | - return $this->get_model()->delete( array( array( 'LIN_parent' => $this->ID() ) ) ); |
|
663 | + if ($this->ID()) { |
|
664 | + return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
665 | 665 | } else { |
666 | - $count = count( $this->_children ); |
|
666 | + $count = count($this->_children); |
|
667 | 667 | $this->_children = array(); |
668 | 668 | return $count; |
669 | 669 | } |
@@ -680,25 +680,25 @@ discard block |
||
680 | 680 | * @param bool $stop_search_once_found |
681 | 681 | * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to the DB yet) |
682 | 682 | */ |
683 | - public function delete_child_line_item( $code, $stop_search_once_found = true ) { |
|
684 | - if ( $this->ID() ) { |
|
683 | + public function delete_child_line_item($code, $stop_search_once_found = true) { |
|
684 | + if ($this->ID()) { |
|
685 | 685 | $items_deleted = 0; |
686 | - if( $this->code() == $code ) { |
|
687 | - $items_deleted += EEH_Line_Item::delete_all_child_items( $this ); |
|
686 | + if ($this->code() == $code) { |
|
687 | + $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
688 | 688 | $items_deleted += (int) $this->delete(); |
689 | - if( $stop_search_once_found ){ |
|
689 | + if ($stop_search_once_found) { |
|
690 | 690 | return $items_deleted; |
691 | 691 | } |
692 | 692 | } |
693 | - foreach( $this->children() as $child_line_item ) { |
|
694 | - $items_deleted += $child_line_item->delete_child_line_item( $code, $stop_search_once_found ); |
|
693 | + foreach ($this->children() as $child_line_item) { |
|
694 | + $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
695 | 695 | } |
696 | 696 | return $items_deleted; |
697 | 697 | } else { |
698 | - if( isset( $this->_children[ $code ] ) ) { |
|
699 | - unset( $this->_children[ $code ] ); |
|
698 | + if (isset($this->_children[$code])) { |
|
699 | + unset($this->_children[$code]); |
|
700 | 700 | return 1; |
701 | - }else{ |
|
701 | + } else { |
|
702 | 702 | return 0; |
703 | 703 | } |
704 | 704 | } |
@@ -711,9 +711,9 @@ discard block |
||
711 | 711 | * @return boolean |
712 | 712 | */ |
713 | 713 | public function delete_if_childless_subtotal() { |
714 | - if( $this->ID() && |
|
714 | + if ($this->ID() && |
|
715 | 715 | $this->type() == EEM_Line_Item::type_sub_total && |
716 | - ! $this->children() ) { |
|
716 | + ! $this->children()) { |
|
717 | 717 | return $this->delete(); |
718 | 718 | } else { |
719 | 719 | return false; |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | */ |
729 | 729 | public function generate_code() { |
730 | 730 | // each line item in the cart requires a unique identifier |
731 | - return md5( $this->get( 'OBJ_type' ) . $this->get( 'OBJ_ID' ) . microtime() ); |
|
731 | + return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime()); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | * @return string like '2, 004.00', formatted according to the localized currency |
812 | 812 | */ |
813 | 813 | public function unit_price_no_code() { |
814 | - return $this->get_pretty( 'LIN_unit_price', 'no_currency_code' ); |
|
814 | + return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
815 | 815 | } |
816 | 816 | |
817 | 817 | |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | * @return string like '2, 004.00', formatted according to the localized currency |
822 | 822 | */ |
823 | 823 | public function total_no_code() { |
824 | - return $this->get_pretty( 'LIN_total', 'no_currency_code' ); |
|
824 | + return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | |
@@ -841,17 +841,17 @@ discard block |
||
841 | 841 | $tax_total = $this->recalculate_taxes_and_tax_total(); |
842 | 842 | $total = $pre_tax_total + $tax_total; |
843 | 843 | // no negative totals plz |
844 | - $total = max( $total, 0 ); |
|
845 | - $this->set_total( $total ); |
|
844 | + $total = max($total, 0); |
|
845 | + $this->set_total($total); |
|
846 | 846 | //only update the related transaction's total |
847 | 847 | //if we intend to save this line item and its a grand total |
848 | - if( |
|
848 | + if ( |
|
849 | 849 | $this->allow_persist() && |
850 | 850 | $this->type() === EEM_Line_Item::type_total && |
851 | 851 | $this->transaction() instanceof EE_Transaction |
852 | - ){ |
|
853 | - $this->transaction()->set_total( $total ); |
|
854 | - if ( $this->transaction()->ID() ) { |
|
852 | + ) { |
|
853 | + $this->transaction()->set_total($total); |
|
854 | + if ($this->transaction()->ID()) { |
|
855 | 855 | $this->transaction()->save(); |
856 | 856 | } |
857 | 857 | } |
@@ -871,46 +871,46 @@ discard block |
||
871 | 871 | $total = 0; |
872 | 872 | $my_children = $this->children(); |
873 | 873 | // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total |
874 | - if ( $this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled() ) { |
|
874 | + if ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) { |
|
875 | 875 | return 0; |
876 | 876 | } elseif ( |
877 | - empty( $my_children ) |
|
878 | - && ( $this->is_sub_line_item() || $this->is_line_item() ) |
|
877 | + empty($my_children) |
|
878 | + && ($this->is_sub_line_item() || $this->is_line_item()) |
|
879 | 879 | ) { |
880 | 880 | $total = $this->unit_price() * $this->quantity(); |
881 | - } elseif( $this->is_sub_total() || $this->is_total() ) { |
|
882 | - $total = $this->_recalculate_pretax_total_for_subtotal( $total, $my_children ); |
|
883 | - } elseif ( ! empty( $my_children ) && $this->is_line_item() ) { |
|
884 | - $total = $this->_recalculate_pretax_total_for_line_item( $total, $my_children ); |
|
881 | + } elseif ($this->is_sub_total() || $this->is_total()) { |
|
882 | + $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children); |
|
883 | + } elseif ( ! empty($my_children) && $this->is_line_item()) { |
|
884 | + $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children); |
|
885 | 885 | } |
886 | 886 | //ensure all non-line items and non-sub-line-items have a quantity of 1 |
887 | - if( |
|
887 | + if ( |
|
888 | 888 | ! $this->is_line_item() && |
889 | 889 | ! $this->is_sub_line_item() && |
890 | 890 | ! $this->is_cancellation() |
891 | 891 | ) { |
892 | - $this->set_quantity( 1 ); |
|
893 | - if( ! $this->is_percent() ) { |
|
894 | - $this->set_unit_price( $this->total() ); |
|
892 | + $this->set_quantity(1); |
|
893 | + if ( ! $this->is_percent()) { |
|
894 | + $this->set_unit_price($this->total()); |
|
895 | 895 | } |
896 | 896 | } |
897 | 897 | |
898 | 898 | //we don't want to bother saving grand totals, because that needs to factor in taxes anyways |
899 | 899 | //so it ought to be |
900 | - if( ! $this->is_total() ) { |
|
901 | - $this->set_total( $total ); |
|
900 | + if ( ! $this->is_total()) { |
|
901 | + $this->set_total($total); |
|
902 | 902 | //if not a percent line item, make sure we keep the unit price in sync |
903 | - if( |
|
904 | - ! empty( $my_children ) |
|
903 | + if ( |
|
904 | + ! empty($my_children) |
|
905 | 905 | && $this->is_line_item() |
906 | 906 | && ! $this->is_percent() |
907 | 907 | ) { |
908 | - if( $this->quantity() === 0 ){ |
|
908 | + if ($this->quantity() === 0) { |
|
909 | 909 | $new_unit_price = 0; |
910 | 910 | } else { |
911 | 911 | $new_unit_price = $this->total() / $this->quantity(); |
912 | 912 | } |
913 | - $this->set_unit_price( $new_unit_price ); |
|
913 | + $this->set_unit_price($new_unit_price); |
|
914 | 914 | } |
915 | 915 | $this->maybe_save(); |
916 | 916 | } |
@@ -930,39 +930,39 @@ discard block |
||
930 | 930 | * @return float |
931 | 931 | * @throws \EE_Error |
932 | 932 | */ |
933 | - protected function _recalculate_pretax_total_for_subtotal( $calculated_total_so_far, $my_children = null ) { |
|
934 | - if( $my_children === null ) { |
|
933 | + protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) { |
|
934 | + if ($my_children === null) { |
|
935 | 935 | $my_children = $this->children(); |
936 | 936 | } |
937 | 937 | //get the total of all its children |
938 | - foreach ( $my_children as $child_line_item ) { |
|
939 | - if ( $child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation() ) { |
|
938 | + foreach ($my_children as $child_line_item) { |
|
939 | + if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) { |
|
940 | 940 | // percentage line items are based on total so far |
941 | - if ( $child_line_item->is_percent() ) { |
|
941 | + if ($child_line_item->is_percent()) { |
|
942 | 942 | //round as we go so that the line items add up ok |
943 | 943 | $percent_total = round( |
944 | 944 | $calculated_total_so_far * $child_line_item->percent() / 100, |
945 | 945 | EE_Registry::instance()->CFG->currency->dec_plc |
946 | 946 | ); |
947 | - $child_line_item->set_total( $percent_total ); |
|
947 | + $child_line_item->set_total($percent_total); |
|
948 | 948 | //so far all percent line items should have a quantity of 1 |
949 | 949 | //(ie, no double percent discounts. Although that might be requested someday) |
950 | - $child_line_item->set_quantity( 1 ); |
|
950 | + $child_line_item->set_quantity(1); |
|
951 | 951 | $child_line_item->maybe_save(); |
952 | 952 | $calculated_total_so_far += $percent_total; |
953 | 953 | } else { |
954 | 954 | //verify flat sub-line-item quantities match their parent |
955 | - if( $child_line_item->is_sub_line_item() ) { |
|
956 | - $child_line_item->set_quantity( $this->quantity() ); |
|
955 | + if ($child_line_item->is_sub_line_item()) { |
|
956 | + $child_line_item->set_quantity($this->quantity()); |
|
957 | 957 | } |
958 | 958 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
959 | 959 | } |
960 | 960 | } |
961 | 961 | } |
962 | 962 | |
963 | - if( $this->is_sub_total() ){ |
|
963 | + if ($this->is_sub_total()) { |
|
964 | 964 | // no negative totals plz |
965 | - $calculated_total_so_far = max( $calculated_total_so_far, 0 ); |
|
965 | + $calculated_total_so_far = max($calculated_total_so_far, 0); |
|
966 | 966 | } |
967 | 967 | return $calculated_total_so_far; |
968 | 968 | } |
@@ -980,8 +980,8 @@ discard block |
||
980 | 980 | * @return float |
981 | 981 | * @throws \EE_Error |
982 | 982 | */ |
983 | - protected function _recalculate_pretax_total_for_line_item( $calculated_total_so_far, $my_children = null ) { |
|
984 | - if( $my_children === null ) { |
|
983 | + protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) { |
|
984 | + if ($my_children === null) { |
|
985 | 985 | $my_children = $this->children(); |
986 | 986 | } |
987 | 987 | //we need to keep track of the running total for a single item, |
@@ -989,10 +989,10 @@ discard block |
||
989 | 989 | $unit_price_for_total = 0; |
990 | 990 | $quantity_for_total = 1; |
991 | 991 | //get the total of all its children |
992 | - foreach ( $my_children as $child_line_item ) { |
|
993 | - if ( $child_line_item instanceof EE_Line_Item && |
|
992 | + foreach ($my_children as $child_line_item) { |
|
993 | + if ($child_line_item instanceof EE_Line_Item && |
|
994 | 994 | ! $child_line_item->is_cancellation()) { |
995 | - if ( $child_line_item->is_percent() ) { |
|
995 | + if ($child_line_item->is_percent()) { |
|
996 | 996 | //it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity |
997 | 997 | //not total multiplied by percent, because that ignores rounding along-the-way |
998 | 998 | $percent_unit_price = round( |
@@ -1000,17 +1000,17 @@ discard block |
||
1000 | 1000 | EE_Registry::instance()->CFG->currency->dec_plc |
1001 | 1001 | ); |
1002 | 1002 | $percent_total = $percent_unit_price * $quantity_for_total; |
1003 | - $child_line_item->set_total( $percent_total ); |
|
1003 | + $child_line_item->set_total($percent_total); |
|
1004 | 1004 | //so far all percent line items should have a quantity of 1 |
1005 | 1005 | //(ie, no double percent discounts. Although that might be requested someday) |
1006 | - $child_line_item->set_quantity( 1 ); |
|
1006 | + $child_line_item->set_quantity(1); |
|
1007 | 1007 | $child_line_item->maybe_save(); |
1008 | 1008 | $calculated_total_so_far += $percent_total; |
1009 | 1009 | $unit_price_for_total += $percent_unit_price; |
1010 | 1010 | } else { |
1011 | 1011 | //verify flat sub-line-item quantities match their parent |
1012 | - if( $child_line_item->is_sub_line_item() ) { |
|
1013 | - $child_line_item->set_quantity( $this->quantity() ); |
|
1012 | + if ($child_line_item->is_sub_line_item()) { |
|
1013 | + $child_line_item->set_quantity($this->quantity()); |
|
1014 | 1014 | } |
1015 | 1015 | $quantity_for_total = $child_line_item->quantity(); |
1016 | 1016 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
@@ -1034,10 +1034,10 @@ discard block |
||
1034 | 1034 | //calculate the pretax total |
1035 | 1035 | $taxable_total = $this->taxable_total(); |
1036 | 1036 | $tax_total = 0; |
1037 | - foreach ( $taxes as $tax ) { |
|
1037 | + foreach ($taxes as $tax) { |
|
1038 | 1038 | $total_on_this_tax = $taxable_total * $tax->percent() / 100; |
1039 | 1039 | //remember the total on this line item |
1040 | - $tax->set_total( $total_on_this_tax ); |
|
1040 | + $tax->set_total($total_on_this_tax); |
|
1041 | 1041 | $tax_total += $tax->total(); |
1042 | 1042 | } |
1043 | 1043 | $this->_recalculate_tax_sub_total(); |
@@ -1051,21 +1051,21 @@ discard block |
||
1051 | 1051 | * @return void |
1052 | 1052 | */ |
1053 | 1053 | private function _recalculate_tax_sub_total() { |
1054 | - if ( $this->is_tax_sub_total() ) { |
|
1054 | + if ($this->is_tax_sub_total()) { |
|
1055 | 1055 | $total = 0; |
1056 | 1056 | $total_percent = 0; |
1057 | 1057 | //simply loop through all its children (which should be taxes) and sum their total |
1058 | - foreach ( $this->children() as $child_tax ) { |
|
1059 | - if ( $child_tax instanceof EE_Line_Item ) { |
|
1058 | + foreach ($this->children() as $child_tax) { |
|
1059 | + if ($child_tax instanceof EE_Line_Item) { |
|
1060 | 1060 | $total += $child_tax->total(); |
1061 | 1061 | $total_percent += $child_tax->percent(); |
1062 | 1062 | } |
1063 | 1063 | } |
1064 | - $this->set_total( $total ); |
|
1065 | - $this->set_percent( $total_percent ); |
|
1066 | - } elseif ( $this->is_total() ) { |
|
1067 | - foreach ( $this->children() as $maybe_tax_subtotal ) { |
|
1068 | - if ( $maybe_tax_subtotal instanceof EE_Line_Item ) { |
|
1064 | + $this->set_total($total); |
|
1065 | + $this->set_percent($total_percent); |
|
1066 | + } elseif ($this->is_total()) { |
|
1067 | + foreach ($this->children() as $maybe_tax_subtotal) { |
|
1068 | + if ($maybe_tax_subtotal instanceof EE_Line_Item) { |
|
1069 | 1069 | $maybe_tax_subtotal->_recalculate_tax_sub_total(); |
1070 | 1070 | } |
1071 | 1071 | } |
@@ -1081,8 +1081,8 @@ discard block |
||
1081 | 1081 | public function get_total_tax() { |
1082 | 1082 | $this->_recalculate_tax_sub_total(); |
1083 | 1083 | $total = 0; |
1084 | - foreach ( $this->tax_descendants() as $tax_line_item ) { |
|
1085 | - if ( $tax_line_item instanceof EE_Line_Item ) { |
|
1084 | + foreach ($this->tax_descendants() as $tax_line_item) { |
|
1085 | + if ($tax_line_item instanceof EE_Line_Item) { |
|
1086 | 1086 | $total += $tax_line_item->total(); |
1087 | 1087 | } |
1088 | 1088 | } |
@@ -1096,15 +1096,15 @@ discard block |
||
1096 | 1096 | */ |
1097 | 1097 | public function get_items_total() { |
1098 | 1098 | //by default, let's make sure we're consistent with the existing line item |
1099 | - if( $this->is_total() ) { |
|
1100 | - $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal( $this ); |
|
1101 | - if( $pretax_subtotal_li instanceof EE_Line_Item ) { |
|
1099 | + if ($this->is_total()) { |
|
1100 | + $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this); |
|
1101 | + if ($pretax_subtotal_li instanceof EE_Line_Item) { |
|
1102 | 1102 | return $pretax_subtotal_li->total(); |
1103 | 1103 | } |
1104 | 1104 | } |
1105 | 1105 | $total = 0; |
1106 | - foreach ( $this->get_items() as $item ) { |
|
1107 | - if ( $item instanceof EE_Line_Item ) { |
|
1106 | + foreach ($this->get_items() as $item) { |
|
1107 | + if ($item instanceof EE_Line_Item) { |
|
1108 | 1108 | $total += $item->total(); |
1109 | 1109 | } |
1110 | 1110 | } |
@@ -1119,7 +1119,7 @@ discard block |
||
1119 | 1119 | * @return EE_Line_Item[] |
1120 | 1120 | */ |
1121 | 1121 | public function tax_descendants() { |
1122 | - return EEH_Line_Item::get_tax_descendants( $this ); |
|
1122 | + return EEH_Line_Item::get_tax_descendants($this); |
|
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | |
@@ -1129,7 +1129,7 @@ discard block |
||
1129 | 1129 | * @return EE_Line_Item[] |
1130 | 1130 | */ |
1131 | 1131 | public function get_items() { |
1132 | - return EEH_Line_Item::get_line_item_descendants( $this ); |
|
1132 | + return EEH_Line_Item::get_line_item_descendants($this); |
|
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | |
@@ -1145,22 +1145,22 @@ discard block |
||
1145 | 1145 | */ |
1146 | 1146 | public function taxable_total() { |
1147 | 1147 | $total = 0; |
1148 | - if ( $this->children() ) { |
|
1149 | - foreach ( $this->children() as $child_line_item ) { |
|
1150 | - if ( $child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1148 | + if ($this->children()) { |
|
1149 | + foreach ($this->children() as $child_line_item) { |
|
1150 | + if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1151 | 1151 | //if it's a percent item, only take into account the percent |
1152 | 1152 | //that's taxable too (the taxable total so far) |
1153 | - if( $child_line_item->is_percent() ) { |
|
1154 | - $total = $total + ( $total * $child_line_item->percent() / 100 ); |
|
1155 | - }else{ |
|
1153 | + if ($child_line_item->is_percent()) { |
|
1154 | + $total = $total + ($total * $child_line_item->percent() / 100); |
|
1155 | + } else { |
|
1156 | 1156 | $total += $child_line_item->total(); |
1157 | 1157 | } |
1158 | - }elseif( $child_line_item->type() === EEM_Line_Item::type_sub_total ){ |
|
1158 | + }elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) { |
|
1159 | 1159 | $total += $child_line_item->taxable_total(); |
1160 | 1160 | } |
1161 | 1161 | } |
1162 | 1162 | } |
1163 | - return max( $total, 0 ); |
|
1163 | + return max($total, 0); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | |
@@ -1170,7 +1170,7 @@ discard block |
||
1170 | 1170 | * @return EE_Transaction |
1171 | 1171 | */ |
1172 | 1172 | public function transaction() { |
1173 | - return $this->get_first_related( 'Transaction' ); |
|
1173 | + return $this->get_first_related('Transaction'); |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | |
@@ -1183,18 +1183,18 @@ discard block |
||
1183 | 1183 | * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
1184 | 1184 | * @return int count of items saved |
1185 | 1185 | */ |
1186 | - public function save_this_and_descendants_to_txn( $txn_id = NULL ) { |
|
1186 | + public function save_this_and_descendants_to_txn($txn_id = NULL) { |
|
1187 | 1187 | $count = 0; |
1188 | - if ( ! $txn_id ) { |
|
1188 | + if ( ! $txn_id) { |
|
1189 | 1189 | $txn_id = $this->TXN_ID(); |
1190 | 1190 | } |
1191 | - $this->set_TXN_ID( $txn_id ); |
|
1191 | + $this->set_TXN_ID($txn_id); |
|
1192 | 1192 | $children = $this->children(); |
1193 | 1193 | $count += $this->save() ? 1 : 0; |
1194 | - foreach ( $children as $child_line_item ) { |
|
1195 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1196 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
1197 | - $count += $child_line_item->save_this_and_descendants_to_txn( $txn_id ); |
|
1194 | + foreach ($children as $child_line_item) { |
|
1195 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1196 | + $child_line_item->set_parent_ID($this->ID()); |
|
1197 | + $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1198 | 1198 | } |
1199 | 1199 | } |
1200 | 1200 | return $count; |
@@ -1211,9 +1211,9 @@ discard block |
||
1211 | 1211 | $count = 0; |
1212 | 1212 | $children = $this->children(); |
1213 | 1213 | $count += $this->save() ? 1 : 0; |
1214 | - foreach ( $children as $child_line_item ) { |
|
1215 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1216 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
1214 | + foreach ($children as $child_line_item) { |
|
1215 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1216 | + $child_line_item->set_parent_ID($this->ID()); |
|
1217 | 1217 | $count += $child_line_item->save_this_and_descendants(); |
1218 | 1218 | } |
1219 | 1219 | } |
@@ -1227,8 +1227,8 @@ discard block |
||
1227 | 1227 | * @return EE_Line_Item[] |
1228 | 1228 | */ |
1229 | 1229 | function get_cancellations() { |
1230 | - EE_Registry::instance()->load_helper( 'Line_Item' ); |
|
1231 | - return EEH_Line_Item::get_descendants_of_type( $this, EEM_Line_Item::type_cancellation ); |
|
1230 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
1231 | + return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | |
@@ -1238,9 +1238,9 @@ discard block |
||
1238 | 1238 | * @param string $type one of the constants on EEM_Line_Item |
1239 | 1239 | * @return EE_Line_Item[] |
1240 | 1240 | */ |
1241 | - protected function _get_descendants_of_type( $type ) { |
|
1242 | - EE_Error::doing_it_wrong( 'EE_Line_Item::_get_descendants_of_type()', __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0' ); |
|
1243 | - return EEH_Line_Item::get_descendants_of_type( $this, $type ); |
|
1241 | + protected function _get_descendants_of_type($type) { |
|
1242 | + EE_Error::doing_it_wrong('EE_Line_Item::_get_descendants_of_type()', __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0'); |
|
1243 | + return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | |
@@ -1250,9 +1250,9 @@ discard block |
||
1250 | 1250 | * @param string $type like one of the EEM_Line_Item::type_* |
1251 | 1251 | * @return EE_Line_Item |
1252 | 1252 | */ |
1253 | - public function get_nearest_descendant_of_type( $type ) { |
|
1254 | - EE_Error::doing_it_wrong( 'EE_Line_Item::get_nearest_descendant_of_type()', __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0' ); |
|
1255 | - return EEH_Line_Item::get_nearest_descendant_of_type( $this, $type ); |
|
1253 | + public function get_nearest_descendant_of_type($type) { |
|
1254 | + EE_Error::doing_it_wrong('EE_Line_Item::get_nearest_descendant_of_type()', __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0'); |
|
1255 | + return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1256 | 1256 | } |
1257 | 1257 | |
1258 | 1258 | |
@@ -1263,7 +1263,7 @@ discard block |
||
1263 | 1263 | * @return int count of items saved |
1264 | 1264 | */ |
1265 | 1265 | public function maybe_save() { |
1266 | - if ( $this->ID() ) { |
|
1266 | + if ($this->ID()) { |
|
1267 | 1267 | return $this->save(); |
1268 | 1268 | } |
1269 | 1269 | return false; |
@@ -551,15 +551,15 @@ discard block |
||
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
554 | - * Given the grand total line item and a ticket, finds the event sub-total |
|
555 | - * line item the ticket's purchase should be added onto |
|
556 | - * |
|
557 | - * @access public |
|
558 | - * @param EE_Line_Item $grand_total the grand total line item |
|
559 | - * @param EE_Ticket $ticket |
|
560 | - * @throws \EE_Error |
|
561 | - * @return EE_Line_Item |
|
562 | - */ |
|
554 | + * Given the grand total line item and a ticket, finds the event sub-total |
|
555 | + * line item the ticket's purchase should be added onto |
|
556 | + * |
|
557 | + * @access public |
|
558 | + * @param EE_Line_Item $grand_total the grand total line item |
|
559 | + * @param EE_Ticket $ticket |
|
560 | + * @throws \EE_Error |
|
561 | + * @return EE_Line_Item |
|
562 | + */ |
|
563 | 563 | public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
564 | 564 | $first_datetime = $ticket->first_datetime(); |
565 | 565 | if ( ! $first_datetime instanceof EE_Datetime ) { |
@@ -807,22 +807,22 @@ discard block |
||
807 | 807 | $add_to_existing_line_item = false |
808 | 808 | ) { |
809 | 809 | $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
810 | - $taxable_total = $total_line_item->taxable_total(); |
|
811 | - |
|
812 | - if( $add_to_existing_line_item ) { |
|
813 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
814 | - EEM_Line_Item::instance()->delete( |
|
815 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
816 | - ); |
|
817 | - } else { |
|
818 | - $new_tax = null; |
|
819 | - $tax_subtotal->delete_children_line_items(); |
|
820 | - } |
|
821 | - if( $new_tax ) { |
|
822 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
823 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
824 | - } else { |
|
825 | - //no existing tax item. Create it |
|
810 | + $taxable_total = $total_line_item->taxable_total(); |
|
811 | + |
|
812 | + if( $add_to_existing_line_item ) { |
|
813 | + $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
814 | + EEM_Line_Item::instance()->delete( |
|
815 | + array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
816 | + ); |
|
817 | + } else { |
|
818 | + $new_tax = null; |
|
819 | + $tax_subtotal->delete_children_line_items(); |
|
820 | + } |
|
821 | + if( $new_tax ) { |
|
822 | + $new_tax->set_total( $new_tax->total() + $amount ); |
|
823 | + $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
824 | + } else { |
|
825 | + //no existing tax item. Create it |
|
826 | 826 | $new_tax = EE_Line_Item::new_instance( array( |
827 | 827 | 'TXN_ID' => $total_line_item->TXN_ID(), |
828 | 828 | 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
@@ -835,16 +835,16 @@ discard block |
||
835 | 835 | ) ); |
836 | 836 | } |
837 | 837 | |
838 | - $new_tax = apply_filters( |
|
838 | + $new_tax = apply_filters( |
|
839 | 839 | 'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal', |
840 | 840 | $new_tax, |
841 | 841 | $total_line_item |
842 | - ); |
|
843 | - $new_tax->save(); |
|
844 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
845 | - $tax_subtotal->save(); |
|
846 | - $total_line_item->recalculate_total_including_taxes(); |
|
847 | - return $new_tax; |
|
842 | + ); |
|
843 | + $new_tax->save(); |
|
844 | + $tax_subtotal->set_total( $new_tax->total() ); |
|
845 | + $tax_subtotal->save(); |
|
846 | + $total_line_item->recalculate_total_including_taxes(); |
|
847 | + return $new_tax; |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | |
@@ -990,7 +990,7 @@ discard block |
||
990 | 990 | if ( $child_line_item instanceof EE_Line_Item ) { |
991 | 991 | if ( |
992 | 992 | $child_line_item->type() === $line_item_type |
993 | - && ( |
|
993 | + && ( |
|
994 | 994 | $child_line_item->OBJ_type() === $obj_type || $obj_type === null |
995 | 995 | ) |
996 | 996 | ) { |
@@ -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,31 +387,31 @@ 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 ) { |
|
414 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
413 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
414 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
415 | 415 | return true; |
416 | 416 | } |
417 | 417 | return false; |
@@ -429,12 +429,12 @@ discard block |
||
429 | 429 | * @return bool success |
430 | 430 | * @throws \EE_Error |
431 | 431 | */ |
432 | - public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
432 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
433 | 433 | // validate incoming line_item |
434 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
434 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
435 | 435 | throw new EE_Error( |
436 | 436 | sprintf( |
437 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
437 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
438 | 438 | $ticket_line_item->type() |
439 | 439 | ) |
440 | 440 | ); |
@@ -444,37 +444,37 @@ discard block |
||
444 | 444 | $ticket_line_item, |
445 | 445 | EEM_Line_Item::type_cancellation |
446 | 446 | ); |
447 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
447 | + $cancellation_line_item = reset($cancellation_line_item); |
|
448 | 448 | // verify that this ticket was indeed previously cancelled |
449 | - if ( ! $cancellation_line_item instanceof EE_Line_Item ) { |
|
449 | + if ( ! $cancellation_line_item instanceof EE_Line_Item) { |
|
450 | 450 | return false; |
451 | 451 | } |
452 | - if ( $cancellation_line_item->quantity() > $qty ) { |
|
452 | + if ($cancellation_line_item->quantity() > $qty) { |
|
453 | 453 | // decrement cancelled quantity |
454 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
455 | - } else if ( $cancellation_line_item->quantity() == $qty ) { |
|
454 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
455 | + } else if ($cancellation_line_item->quantity() == $qty) { |
|
456 | 456 | // decrement cancelled quantity in case anyone still has the object kicking around |
457 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
457 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
458 | 458 | // delete because quantity will end up as 0 |
459 | 459 | $cancellation_line_item->delete(); |
460 | 460 | // and attempt to destroy the object, |
461 | 461 | // even though PHP won't actually destroy it until it needs the memory |
462 | - unset( $cancellation_line_item ); |
|
462 | + unset($cancellation_line_item); |
|
463 | 463 | } else { |
464 | 464 | // what ?!?! negative quantity ?!?! |
465 | 465 | throw new EE_Error( |
466 | 466 | sprintf( |
467 | - __( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
468 | - 'event_espresso' ), |
|
467 | + __('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
468 | + 'event_espresso'), |
|
469 | 469 | $qty, |
470 | 470 | $cancellation_line_item->quantity() |
471 | 471 | ) |
472 | 472 | ); |
473 | 473 | } |
474 | 474 | // increment ticket quantity |
475 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty ); |
|
476 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
477 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
475 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
476 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
477 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
478 | 478 | return true; |
479 | 479 | } |
480 | 480 | return false; |
@@ -489,8 +489,8 @@ discard block |
||
489 | 489 | * @param EE_Line_Item $line_item |
490 | 490 | * @return \EE_Line_Item |
491 | 491 | */ |
492 | - public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){ |
|
493 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item ); |
|
492 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) { |
|
493 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
494 | 494 | return $grand_total_line_item->recalculate_total_including_taxes(); |
495 | 495 | } |
496 | 496 | |
@@ -503,11 +503,11 @@ discard block |
||
503 | 503 | * @return \EE_Line_Item |
504 | 504 | * @throws \EE_Error |
505 | 505 | */ |
506 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
507 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
506 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
507 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
508 | 508 | return $pre_tax_subtotal instanceof EE_Line_Item |
509 | 509 | ? $pre_tax_subtotal |
510 | - : self::create_pre_tax_subtotal( $total_line_item ); |
|
510 | + : self::create_pre_tax_subtotal($total_line_item); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | |
@@ -519,9 +519,9 @@ discard block |
||
519 | 519 | * @return \EE_Line_Item |
520 | 520 | * @throws \EE_Error |
521 | 521 | */ |
522 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
523 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
524 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
522 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
523 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
524 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | |
@@ -534,12 +534,12 @@ discard block |
||
534 | 534 | * @return void |
535 | 535 | * @throws \EE_Error |
536 | 536 | */ |
537 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
538 | - if( $transaction ){ |
|
537 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
538 | + if ($transaction) { |
|
539 | 539 | /** @type EEM_Transaction $EEM_Transaction */ |
540 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
541 | - $TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
542 | - $line_item->set_TXN_ID( $TXN_ID ); |
|
540 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
541 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
542 | + $line_item->set_TXN_ID($TXN_ID); |
|
543 | 543 | } |
544 | 544 | } |
545 | 545 | |
@@ -554,8 +554,8 @@ discard block |
||
554 | 554 | * @return \EE_Line_Item of type total |
555 | 555 | * @throws \EE_Error |
556 | 556 | */ |
557 | - public static function create_total_line_item( $transaction = NULL ){ |
|
558 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
557 | + public static function create_total_line_item($transaction = NULL) { |
|
558 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
559 | 559 | 'LIN_code' => 'total', |
560 | 560 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
561 | 561 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -565,9 +565,9 @@ discard block |
||
565 | 565 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
566 | 566 | $total_line_item |
567 | 567 | ); |
568 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
569 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
570 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
568 | + self::set_TXN_ID($total_line_item, $transaction); |
|
569 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
570 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
571 | 571 | return $total_line_item; |
572 | 572 | } |
573 | 573 | |
@@ -581,19 +581,19 @@ discard block |
||
581 | 581 | * @return EE_Line_Item |
582 | 582 | * @throws \EE_Error |
583 | 583 | */ |
584 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
585 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
584 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
585 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
586 | 586 | 'LIN_code' => 'pre-tax-subtotal', |
587 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
587 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
588 | 588 | 'LIN_type' => EEM_Line_Item::type_sub_total |
589 | - ) ); |
|
589 | + )); |
|
590 | 590 | $pre_tax_line_item = apply_filters( |
591 | 591 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
592 | 592 | $pre_tax_line_item |
593 | 593 | ); |
594 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
595 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
596 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
594 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
595 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
596 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
597 | 597 | return $pre_tax_line_item; |
598 | 598 | } |
599 | 599 | |
@@ -608,21 +608,21 @@ discard block |
||
608 | 608 | * @return EE_Line_Item |
609 | 609 | * @throws \EE_Error |
610 | 610 | */ |
611 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
611 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
612 | 612 | $tax_line_item = EE_Line_Item::new_instance(array( |
613 | 613 | 'LIN_code' => 'taxes', |
614 | 614 | 'LIN_name' => __('Taxes', 'event_espresso'), |
615 | 615 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
616 | - 'LIN_order' => 1000,//this should always come last |
|
616 | + 'LIN_order' => 1000, //this should always come last |
|
617 | 617 | )); |
618 | 618 | $tax_line_item = apply_filters( |
619 | 619 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
620 | 620 | $tax_line_item |
621 | 621 | ); |
622 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
623 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
622 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
623 | + $total_line_item->add_child_line_item($tax_line_item); |
|
624 | 624 | //and lastly, add the actual taxes |
625 | - self::apply_taxes( $total_line_item ); |
|
625 | + self::apply_taxes($total_line_item); |
|
626 | 626 | return $tax_line_item; |
627 | 627 | } |
628 | 628 | |
@@ -637,11 +637,11 @@ discard block |
||
637 | 637 | * @return EE_Line_Item |
638 | 638 | * @throws \EE_Error |
639 | 639 | */ |
640 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
640 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
641 | 641 | $event_line_item = EE_Line_Item::new_instance(array( |
642 | - 'LIN_code' => self::get_event_code( $event ), |
|
643 | - 'LIN_name' => self::get_event_name( $event ), |
|
644 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
642 | + 'LIN_code' => self::get_event_code($event), |
|
643 | + 'LIN_name' => self::get_event_name($event), |
|
644 | + 'LIN_desc' => self::get_event_desc($event), |
|
645 | 645 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
646 | 646 | 'OBJ_type' => 'Event', |
647 | 647 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -650,8 +650,8 @@ discard block |
||
650 | 650 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
651 | 651 | $event_line_item |
652 | 652 | ); |
653 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
654 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
653 | + self::set_TXN_ID($event_line_item, $transaction); |
|
654 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
655 | 655 | return $event_line_item; |
656 | 656 | } |
657 | 657 | |
@@ -664,8 +664,8 @@ discard block |
||
664 | 664 | * @return string |
665 | 665 | * @throws \EE_Error |
666 | 666 | */ |
667 | - public static function get_event_code( $event ) { |
|
668 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
667 | + public static function get_event_code($event) { |
|
668 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
669 | 669 | } |
670 | 670 | |
671 | 671 | /** |
@@ -673,8 +673,8 @@ discard block |
||
673 | 673 | * @param EE_Event $event |
674 | 674 | * @return string |
675 | 675 | */ |
676 | - public static function get_event_name( $event ) { |
|
677 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
676 | + public static function get_event_name($event) { |
|
677 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | * @param EE_Event $event |
683 | 683 | * @return string |
684 | 684 | */ |
685 | - public static function get_event_desc( $event ) { |
|
685 | + public static function get_event_desc($event) { |
|
686 | 686 | return $event instanceof EE_Event ? $event->short_description() : ''; |
687 | 687 | } |
688 | 688 | |
@@ -696,27 +696,27 @@ discard block |
||
696 | 696 | * @throws \EE_Error |
697 | 697 | * @return EE_Line_Item |
698 | 698 | */ |
699 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
699 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
700 | 700 | $first_datetime = $ticket->first_datetime(); |
701 | - if ( ! $first_datetime instanceof EE_Datetime ) { |
|
701 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
702 | 702 | throw new EE_Error( |
703 | - sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) |
|
703 | + sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()) |
|
704 | 704 | ); |
705 | 705 | } |
706 | 706 | $event = $first_datetime->event(); |
707 | - if ( ! $event instanceof EE_Event ) { |
|
707 | + if ( ! $event instanceof EE_Event) { |
|
708 | 708 | throw new EE_Error( |
709 | 709 | sprintf( |
710 | - __( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ), |
|
710 | + __('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), |
|
711 | 711 | $ticket->ID() |
712 | 712 | ) |
713 | 713 | ); |
714 | 714 | } |
715 | - $events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
716 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
715 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
716 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
717 | 717 | throw new EE_Error( |
718 | 718 | sprintf( |
719 | - __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), |
|
719 | + __('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), |
|
720 | 720 | $ticket->ID(), |
721 | 721 | $grand_total->ID() |
722 | 722 | ) |
@@ -735,31 +735,31 @@ discard block |
||
735 | 735 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
736 | 736 | * @throws \EE_Error |
737 | 737 | */ |
738 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
738 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
739 | 739 | /** @type EE_Event $event */ |
740 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
740 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
741 | 741 | $event_line_item = NULL; |
742 | 742 | $found = false; |
743 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
743 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
744 | 744 | // default event subtotal, we should only ever find this the first time this method is called |
745 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
745 | + if ( ! $event_line_item->OBJ_ID()) { |
|
746 | 746 | // let's use this! but first... set the event details |
747 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
747 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
748 | 748 | $found = true; |
749 | 749 | break; |
750 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
750 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
751 | 751 | // found existing line item for this event in the cart, so break out of loop and use this one |
752 | 752 | $found = true; |
753 | 753 | break; |
754 | 754 | } |
755 | 755 | } |
756 | - if ( ! $found ) { |
|
756 | + if ( ! $found) { |
|
757 | 757 | //there is no event sub-total yet, so add it |
758 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
758 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
759 | 759 | // create a new "event" subtotal below that |
760 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
760 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
761 | 761 | // and set the event details |
762 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
762 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
763 | 763 | } |
764 | 764 | return $event_line_item; |
765 | 765 | } |
@@ -780,13 +780,13 @@ discard block |
||
780 | 780 | EE_Event $event, |
781 | 781 | $transaction = null |
782 | 782 | ) { |
783 | - if ( $event instanceof EE_Event ) { |
|
784 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
785 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
786 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
787 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
783 | + if ($event instanceof EE_Event) { |
|
784 | + $event_line_item->set_code(self::get_event_code($event)); |
|
785 | + $event_line_item->set_name(self::get_event_name($event)); |
|
786 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
787 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
788 | 788 | } |
789 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
789 | + self::set_TXN_ID($event_line_item, $transaction); |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | |
@@ -799,19 +799,19 @@ discard block |
||
799 | 799 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
800 | 800 | * @throws \EE_Error |
801 | 801 | */ |
802 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
802 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
803 | 803 | /** @type EEM_Price $EEM_Price */ |
804 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
804 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
805 | 805 | // get array of taxes via Price Model |
806 | 806 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
807 | - ksort( $ordered_taxes ); |
|
808 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
807 | + ksort($ordered_taxes); |
|
808 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
809 | 809 | //just to be safe, remove its old tax line items |
810 | 810 | $taxes_line_item->delete_children_line_items(); |
811 | 811 | //loop thru taxes |
812 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
813 | - foreach ( $taxes as $tax ) { |
|
814 | - if ( $tax instanceof EE_Price ) { |
|
812 | + foreach ($ordered_taxes as $order => $taxes) { |
|
813 | + foreach ($taxes as $tax) { |
|
814 | + if ($tax instanceof EE_Price) { |
|
815 | 815 | $tax_line_item = EE_Line_Item::new_instance( |
816 | 816 | array( |
817 | 817 | 'LIN_name' => $tax->name(), |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
830 | 830 | $tax_line_item |
831 | 831 | ); |
832 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
832 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
833 | 833 | } |
834 | 834 | } |
835 | 835 | } |
@@ -846,10 +846,10 @@ discard block |
||
846 | 846 | * @return float |
847 | 847 | * @throws \EE_Error |
848 | 848 | */ |
849 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
850 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
851 | - if( ! $taxes_subtotal->children()){ |
|
852 | - self::apply_taxes( $total_line_item ); |
|
849 | + public static function ensure_taxes_applied($total_line_item) { |
|
850 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
851 | + if ( ! $taxes_subtotal->children()) { |
|
852 | + self::apply_taxes($total_line_item); |
|
853 | 853 | } |
854 | 854 | return $taxes_subtotal->total(); |
855 | 855 | } |
@@ -863,16 +863,16 @@ discard block |
||
863 | 863 | * @return bool |
864 | 864 | * @throws \EE_Error |
865 | 865 | */ |
866 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
866 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
867 | 867 | $deleted = 0; |
868 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
869 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
870 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
871 | - if ( $child_line_item->ID() ) { |
|
868 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
869 | + if ($child_line_item instanceof EE_Line_Item) { |
|
870 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
871 | + if ($child_line_item->ID()) { |
|
872 | 872 | $child_line_item->delete(); |
873 | - unset( $child_line_item ); |
|
873 | + unset($child_line_item); |
|
874 | 874 | } else { |
875 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
875 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
876 | 876 | } |
877 | 877 | $deleted++; |
878 | 878 | } |
@@ -894,9 +894,9 @@ discard block |
||
894 | 894 | * @param array|bool|string $line_item_codes |
895 | 895 | * @return int number of items successfully removed |
896 | 896 | */ |
897 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
897 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
898 | 898 | |
899 | - if( $total_line_item->type() !== EEM_Line_Item::type_total ){ |
|
899 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
900 | 900 | EE_Error::doing_it_wrong( |
901 | 901 | 'EEH_Line_Item::delete_items', |
902 | 902 | __( |
@@ -906,20 +906,20 @@ discard block |
||
906 | 906 | '4.6.18' |
907 | 907 | ); |
908 | 908 | } |
909 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
909 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
910 | 910 | |
911 | 911 | // check if only a single line_item_id was passed |
912 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
912 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
913 | 913 | // place single line_item_id in an array to appear as multiple line_item_ids |
914 | - $line_item_codes = array ( $line_item_codes ); |
|
914 | + $line_item_codes = array($line_item_codes); |
|
915 | 915 | } |
916 | 916 | $removals = 0; |
917 | 917 | // cycle thru line_item_ids |
918 | - foreach ( $line_item_codes as $line_item_id ) { |
|
918 | + foreach ($line_item_codes as $line_item_id) { |
|
919 | 919 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
920 | 920 | } |
921 | 921 | |
922 | - if ( $removals > 0 ) { |
|
922 | + if ($removals > 0) { |
|
923 | 923 | $total_line_item->recalculate_taxes_and_tax_total(); |
924 | 924 | return $removals; |
925 | 925 | } else { |
@@ -952,33 +952,33 @@ discard block |
||
952 | 952 | $code = null, |
953 | 953 | $add_to_existing_line_item = false |
954 | 954 | ) { |
955 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
955 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
956 | 956 | $taxable_total = $total_line_item->taxable_total(); |
957 | 957 | |
958 | - if( $add_to_existing_line_item ) { |
|
959 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
958 | + if ($add_to_existing_line_item) { |
|
959 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
960 | 960 | EEM_Line_Item::instance()->delete( |
961 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
961 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
962 | 962 | ); |
963 | 963 | } else { |
964 | 964 | $new_tax = null; |
965 | 965 | $tax_subtotal->delete_children_line_items(); |
966 | 966 | } |
967 | - if( $new_tax ) { |
|
968 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
969 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
967 | + if ($new_tax) { |
|
968 | + $new_tax->set_total($new_tax->total() + $amount); |
|
969 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
970 | 970 | } else { |
971 | 971 | //no existing tax item. Create it |
972 | - $new_tax = EE_Line_Item::new_instance( array( |
|
972 | + $new_tax = EE_Line_Item::new_instance(array( |
|
973 | 973 | 'TXN_ID' => $total_line_item->TXN_ID(), |
974 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
974 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
975 | 975 | 'LIN_desc' => $description ? $description : '', |
976 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
976 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
977 | 977 | 'LIN_total' => $amount, |
978 | 978 | 'LIN_parent' => $tax_subtotal->ID(), |
979 | 979 | 'LIN_type' => EEM_Line_Item::type_tax, |
980 | 980 | 'LIN_code' => $code |
981 | - ) ); |
|
981 | + )); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | $new_tax = apply_filters( |
@@ -987,7 +987,7 @@ discard block |
||
987 | 987 | $total_line_item |
988 | 988 | ); |
989 | 989 | $new_tax->save(); |
990 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
990 | + $tax_subtotal->set_total($new_tax->total()); |
|
991 | 991 | $tax_subtotal->save(); |
992 | 992 | $total_line_item->recalculate_total_including_taxes(); |
993 | 993 | return $new_tax; |
@@ -1009,14 +1009,14 @@ discard block |
||
1009 | 1009 | $code_substring_for_whitelist = null |
1010 | 1010 | ) { |
1011 | 1011 | $whitelisted = false; |
1012 | - if( $code_substring_for_whitelist !== null ) { |
|
1013 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
1012 | + if ($code_substring_for_whitelist !== null) { |
|
1013 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
1014 | 1014 | } |
1015 | - if( ! $whitelisted && $line_item->is_line_item() ) { |
|
1016 | - $line_item->set_is_taxable( $taxable ); |
|
1015 | + if ( ! $whitelisted && $line_item->is_line_item()) { |
|
1016 | + $line_item->set_is_taxable($taxable); |
|
1017 | 1017 | } |
1018 | - foreach( $line_item->children() as $child_line_item ) { |
|
1019 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
1018 | + foreach ($line_item->children() as $child_line_item) { |
|
1019 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
1020 | 1020 | } |
1021 | 1021 | } |
1022 | 1022 | |
@@ -1029,8 +1029,8 @@ discard block |
||
1029 | 1029 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1030 | 1030 | * @return EE_Line_Item[] |
1031 | 1031 | */ |
1032 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
1033 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
1032 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
1033 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
1034 | 1034 | } |
1035 | 1035 | |
1036 | 1036 | |
@@ -1043,7 +1043,7 @@ discard block |
||
1043 | 1043 | * @param string $obj_type |
1044 | 1044 | * @return EE_Line_Item[] |
1045 | 1045 | */ |
1046 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1046 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1047 | 1047 | return self::_get_descendants_by_type_and_object_type( |
1048 | 1048 | $parent_line_item, |
1049 | 1049 | EEM_Line_Item::type_sub_total, |
@@ -1060,8 +1060,8 @@ discard block |
||
1060 | 1060 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1061 | 1061 | * @return EE_Line_Item[] |
1062 | 1062 | */ |
1063 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
1064 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
1063 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
1064 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | 1067 | |
@@ -1074,8 +1074,8 @@ discard block |
||
1074 | 1074 | * @param string $obj_type |
1075 | 1075 | * @return EE_Line_Item[] |
1076 | 1076 | */ |
1077 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1078 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
1077 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1078 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | |
@@ -1086,8 +1086,8 @@ discard block |
||
1086 | 1086 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1087 | 1087 | * @return EE_Line_Item[] |
1088 | 1088 | */ |
1089 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
1090 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
1089 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
1090 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | |
@@ -1098,8 +1098,8 @@ discard block |
||
1098 | 1098 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1099 | 1099 | * @return EE_Line_Item[] |
1100 | 1100 | */ |
1101 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
1102 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
1101 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
1102 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | |
@@ -1112,8 +1112,8 @@ discard block |
||
1112 | 1112 | * @param string $line_item_type one of the EEM_Line_Item constants |
1113 | 1113 | * @return EE_Line_Item[] |
1114 | 1114 | */ |
1115 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
1116 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
1115 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
1116 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | |
@@ -1132,8 +1132,8 @@ discard block |
||
1132 | 1132 | $obj_type = null |
1133 | 1133 | ) { |
1134 | 1134 | $objects = array(); |
1135 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1136 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1135 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1136 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1137 | 1137 | if ( |
1138 | 1138 | $child_line_item->type() === $line_item_type |
1139 | 1139 | && ( |
@@ -1173,7 +1173,7 @@ discard block |
||
1173 | 1173 | $OBJ_type = '', |
1174 | 1174 | $OBJ_IDs = array() |
1175 | 1175 | ) { |
1176 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
1176 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
1177 | 1177 | } |
1178 | 1178 | |
1179 | 1179 | |
@@ -1192,12 +1192,12 @@ discard block |
||
1192 | 1192 | $OBJ_IDs |
1193 | 1193 | ) { |
1194 | 1194 | $objects = array(); |
1195 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1196 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1195 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1196 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1197 | 1197 | if ( |
1198 | - is_array( $OBJ_IDs ) |
|
1198 | + is_array($OBJ_IDs) |
|
1199 | 1199 | && $child_line_item->OBJ_type() === $OBJ_type |
1200 | - && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs ) |
|
1200 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
1201 | 1201 | ) { |
1202 | 1202 | $objects[] = $child_line_item; |
1203 | 1203 | } else { |
@@ -1227,8 +1227,8 @@ discard block |
||
1227 | 1227 | * @param string $type like one of the EEM_Line_Item::type_* |
1228 | 1228 | * @return EE_Line_Item |
1229 | 1229 | */ |
1230 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
1231 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
1230 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
1231 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | |
@@ -1242,8 +1242,8 @@ discard block |
||
1242 | 1242 | * @param string $code any value used for LIN_code |
1243 | 1243 | * @return EE_Line_Item |
1244 | 1244 | */ |
1245 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
1246 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
1245 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
1246 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
1247 | 1247 | } |
1248 | 1248 | |
1249 | 1249 | |
@@ -1257,15 +1257,15 @@ discard block |
||
1257 | 1257 | * @param string $value any value stored in $search_field |
1258 | 1258 | * @return EE_Line_Item |
1259 | 1259 | */ |
1260 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
1261 | - foreach( $parent_line_item->children() as $child ){ |
|
1262 | - if ( $child->get( $search_field ) == $value ){ |
|
1260 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
1261 | + foreach ($parent_line_item->children() as $child) { |
|
1262 | + if ($child->get($search_field) == $value) { |
|
1263 | 1263 | return $child; |
1264 | 1264 | } |
1265 | 1265 | } |
1266 | - foreach( $parent_line_item->children() as $child ){ |
|
1267 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
1268 | - if ( $descendant_found ){ |
|
1266 | + foreach ($parent_line_item->children() as $child) { |
|
1267 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
1268 | + if ($descendant_found) { |
|
1269 | 1269 | return $descendant_found; |
1270 | 1270 | } |
1271 | 1271 | } |
@@ -1282,24 +1282,24 @@ discard block |
||
1282 | 1282 | * @return \EE_Line_Item |
1283 | 1283 | * @throws \EE_Error |
1284 | 1284 | */ |
1285 | - public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){ |
|
1286 | - if ( $line_item->TXN_ID() ) { |
|
1287 | - $total_line_item = $line_item->transaction()->total_line_item( false ); |
|
1288 | - if ( $total_line_item instanceof EE_Line_Item ) { |
|
1285 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) { |
|
1286 | + if ($line_item->TXN_ID()) { |
|
1287 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
1288 | + if ($total_line_item instanceof EE_Line_Item) { |
|
1289 | 1289 | return $total_line_item; |
1290 | 1290 | } |
1291 | 1291 | } else { |
1292 | 1292 | $line_item_parent = $line_item->parent(); |
1293 | - if ( $line_item_parent instanceof EE_Line_Item ) { |
|
1294 | - if ( $line_item_parent->is_total() ) { |
|
1293 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
1294 | + if ($line_item_parent->is_total()) { |
|
1295 | 1295 | return $line_item_parent; |
1296 | 1296 | } |
1297 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent ); |
|
1297 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
1298 | 1298 | } |
1299 | 1299 | } |
1300 | 1300 | throw new EE_Error( |
1301 | 1301 | sprintf( |
1302 | - __( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ), |
|
1302 | + __('A valid grand total for line item %1$d was not found.', 'event_espresso'), |
|
1303 | 1303 | $line_item->ID() |
1304 | 1304 | ) |
1305 | 1305 | ); |
@@ -1316,31 +1316,31 @@ discard block |
||
1316 | 1316 | * @return void |
1317 | 1317 | * @throws \EE_Error |
1318 | 1318 | */ |
1319 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
1319 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
1320 | 1320 | echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
1321 | - if ( ! $indentation ) { |
|
1322 | - echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />'; |
|
1321 | + if ( ! $indentation) { |
|
1322 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1323 | 1323 | } |
1324 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
1324 | + for ($i = 0; $i < $indentation; $i++) { |
|
1325 | 1325 | echo ". "; |
1326 | 1326 | } |
1327 | 1327 | $breakdown = ''; |
1328 | - if ( $line_item->is_line_item()){ |
|
1329 | - if ( $line_item->is_percent() ) { |
|
1328 | + if ($line_item->is_line_item()) { |
|
1329 | + if ($line_item->is_percent()) { |
|
1330 | 1330 | $breakdown = "{$line_item->percent()}%"; |
1331 | 1331 | } else { |
1332 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1332 | + $breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1333 | 1333 | } |
1334 | 1334 | } |
1335 | - echo $line_item->name() . " ( ID:{$line_item->ID()} ) : {$line_item->type()} " . '$' . "{$line_item->total()}"; |
|
1336 | - if ( $breakdown ) { |
|
1335 | + echo $line_item->name()." ( ID:{$line_item->ID()} ) : {$line_item->type()} ".'$'."{$line_item->total()}"; |
|
1336 | + if ($breakdown) { |
|
1337 | 1337 | echo " ( {$breakdown} )"; |
1338 | 1338 | } |
1339 | - if( $line_item->is_taxable() ){ |
|
1339 | + if ($line_item->is_taxable()) { |
|
1340 | 1340 | echo " * taxable"; |
1341 | 1341 | } |
1342 | - if( $line_item->children() ){ |
|
1343 | - foreach($line_item->children() as $child){ |
|
1342 | + if ($line_item->children()) { |
|
1343 | + foreach ($line_item->children() as $child) { |
|
1344 | 1344 | self::visualize($child, $indentation + 1); |
1345 | 1345 | } |
1346 | 1346 | } |
@@ -1381,97 +1381,97 @@ discard block |
||
1381 | 1381 | * is theirs, which can be done with |
1382 | 1382 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
1383 | 1383 | */ |
1384 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
1384 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
1385 | 1385 | //init running grand total if not already |
1386 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
1387 | - $running_totals[ 'total' ] = 0; |
|
1386 | + if ( ! isset($running_totals['total'])) { |
|
1387 | + $running_totals['total'] = 0; |
|
1388 | 1388 | } |
1389 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
1390 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
1389 | + if ( ! isset($running_totals['taxable'])) { |
|
1390 | + $running_totals['taxable'] = array('total' => 0); |
|
1391 | 1391 | } |
1392 | - foreach ( $line_item->children() as $child_line_item ) { |
|
1393 | - switch ( $child_line_item->type() ) { |
|
1392 | + foreach ($line_item->children() as $child_line_item) { |
|
1393 | + switch ($child_line_item->type()) { |
|
1394 | 1394 | |
1395 | 1395 | case EEM_Line_Item::type_sub_total : |
1396 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
1396 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
1397 | 1397 | //combine arrays but preserve numeric keys |
1398 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
1399 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
1400 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
1398 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
1399 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
1400 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
1401 | 1401 | break; |
1402 | 1402 | |
1403 | 1403 | case EEM_Line_Item::type_tax_sub_total : |
1404 | 1404 | |
1405 | 1405 | //find how much the taxes percentage is |
1406 | - if ( $child_line_item->percent() !== 0 ) { |
|
1406 | + if ($child_line_item->percent() !== 0) { |
|
1407 | 1407 | $tax_percent_decimal = $child_line_item->percent() / 100; |
1408 | 1408 | } else { |
1409 | 1409 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
1410 | 1410 | } |
1411 | 1411 | //and apply to all the taxable totals, and add to the pretax totals |
1412 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1412 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1413 | 1413 | //"total" and "taxable" array key is an exception |
1414 | - if ( $line_item_id === 'taxable' ) { |
|
1414 | + if ($line_item_id === 'taxable') { |
|
1415 | 1415 | continue; |
1416 | 1416 | } |
1417 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1418 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
1417 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
1418 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
1419 | 1419 | } |
1420 | 1420 | break; |
1421 | 1421 | |
1422 | 1422 | case EEM_Line_Item::type_line_item : |
1423 | 1423 | |
1424 | 1424 | // ticket line items or ???? |
1425 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
1425 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
1426 | 1426 | // kk it's a ticket |
1427 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
1427 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
1428 | 1428 | //huh? that shouldn't happen. |
1429 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
1429 | + $running_totals['total'] += $child_line_item->total(); |
|
1430 | 1430 | } else { |
1431 | 1431 | //its not in our running totals yet. great. |
1432 | - if ( $child_line_item->is_taxable() ) { |
|
1432 | + if ($child_line_item->is_taxable()) { |
|
1433 | 1433 | $taxable_amount = $child_line_item->unit_price(); |
1434 | 1434 | } else { |
1435 | 1435 | $taxable_amount = 0; |
1436 | 1436 | } |
1437 | 1437 | // are we only calculating totals for some tickets? |
1438 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
1439 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
1440 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
1438 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
1439 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
1440 | + $running_totals[$child_line_item->ID()] = $quantity |
|
1441 | 1441 | ? $child_line_item->unit_price() |
1442 | 1442 | : 0; |
1443 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity |
|
1443 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity |
|
1444 | 1444 | ? $taxable_amount |
1445 | 1445 | : 0; |
1446 | 1446 | } else { |
1447 | 1447 | $quantity = $child_line_item->quantity(); |
1448 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
1449 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
1448 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
1449 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
1450 | 1450 | } |
1451 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
1452 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
1451 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
1452 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
1453 | 1453 | } |
1454 | 1454 | } else { |
1455 | 1455 | // it's some other type of item added to the cart |
1456 | 1456 | // it should affect the running totals |
1457 | 1457 | // basically we want to convert it into a PERCENT modifier. Because |
1458 | 1458 | // more clearly affect all registration's final price equally |
1459 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 |
|
1460 | - ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 |
|
1459 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
1460 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
1461 | 1461 | : 1; |
1462 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1462 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1463 | 1463 | //the "taxable" array key is an exception |
1464 | - if ( $line_item_id === 'taxable' ) { |
|
1464 | + if ($line_item_id === 'taxable') { |
|
1465 | 1465 | continue; |
1466 | 1466 | } |
1467 | 1467 | // update the running totals |
1468 | 1468 | // yes this actually even works for the running grand total! |
1469 | - $running_totals[ $line_item_id ] = |
|
1469 | + $running_totals[$line_item_id] = |
|
1470 | 1470 | $line_items_percent_of_running_total * $this_running_total; |
1471 | 1471 | |
1472 | - if ( $child_line_item->is_taxable() ) { |
|
1473 | - $running_totals[ 'taxable' ][ $line_item_id ] = |
|
1474 | - $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1472 | + if ($child_line_item->is_taxable()) { |
|
1473 | + $running_totals['taxable'][$line_item_id] = |
|
1474 | + $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
1475 | 1475 | } |
1476 | 1476 | } |
1477 | 1477 | } |
@@ -1489,16 +1489,16 @@ discard block |
||
1489 | 1489 | * @return float | null |
1490 | 1490 | * @throws \OutOfRangeException |
1491 | 1491 | */ |
1492 | - public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) { |
|
1492 | + public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) { |
|
1493 | 1493 | static $final_prices_per_ticket_line_item = array(); |
1494 | - if ( empty( $final_prices_per_ticket_line_item ) ) { |
|
1494 | + if (empty($final_prices_per_ticket_line_item)) { |
|
1495 | 1495 | $final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
1496 | 1496 | $total_line_item |
1497 | 1497 | ); |
1498 | 1498 | } |
1499 | 1499 | //ok now find this new registration's final price |
1500 | - if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) { |
|
1501 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
1500 | + if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) { |
|
1501 | + return $final_prices_per_ticket_line_item[$ticket_line_item->ID()]; |
|
1502 | 1502 | } |
1503 | 1503 | $message = sprintf( |
1504 | 1504 | __( |
@@ -1507,10 +1507,10 @@ discard block |
||
1507 | 1507 | ), |
1508 | 1508 | $ticket_line_item->ID() |
1509 | 1509 | ); |
1510 | - if ( WP_DEBUG ) { |
|
1511 | - throw new \OutOfRangeException( $message ); |
|
1510 | + if (WP_DEBUG) { |
|
1511 | + throw new \OutOfRangeException($message); |
|
1512 | 1512 | } else { |
1513 | - EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message ); |
|
1513 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
1514 | 1514 | } |
1515 | 1515 | return null; |
1516 | 1516 | } |
@@ -1526,15 +1526,15 @@ discard block |
||
1526 | 1526 | * @return \EE_Line_Item |
1527 | 1527 | * @throws \EE_Error |
1528 | 1528 | */ |
1529 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
1530 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
1531 | - foreach ( $line_item->children() as $child_li ) { |
|
1532 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
1529 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
1530 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
1531 | + foreach ($line_item->children() as $child_li) { |
|
1532 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
1533 | 1533 | } |
1534 | 1534 | //if this is the grand total line item, make sure the totals all add up |
1535 | 1535 | //(we could have duplicated this logic AS we copied the line items, but |
1536 | 1536 | //it seems DRYer this way) |
1537 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
1537 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
1538 | 1538 | $copy_li->recalculate_total_including_taxes(); |
1539 | 1539 | } |
1540 | 1540 | return $copy_li; |
@@ -1551,24 +1551,24 @@ discard block |
||
1551 | 1551 | * @throws \EE_Error |
1552 | 1552 | * @param EE_Registration[] $registrations |
1553 | 1553 | */ |
1554 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
1554 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
1555 | 1555 | $new_li_fields = $line_item->model_field_array(); |
1556 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1556 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1557 | 1557 | $line_item->OBJ_type() === 'Ticket' |
1558 | 1558 | ) { |
1559 | 1559 | $count = 0; |
1560 | - foreach ( $registrations as $registration ) { |
|
1561 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1562 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
1560 | + foreach ($registrations as $registration) { |
|
1561 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1562 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
1563 | 1563 | ) { |
1564 | 1564 | $count++; |
1565 | 1565 | } |
1566 | 1566 | } |
1567 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
1567 | + $new_li_fields['LIN_quantity'] = $count; |
|
1568 | 1568 | } |
1569 | 1569 | //don't set the total. We'll leave that up to the code that calculates it |
1570 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] ); |
|
1571 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1570 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
1571 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1572 | 1572 | } |
1573 | 1573 | |
1574 | 1574 | |
@@ -1581,19 +1581,19 @@ discard block |
||
1581 | 1581 | * @return \EE_Line_Item|null |
1582 | 1582 | * @throws \EE_Error |
1583 | 1583 | */ |
1584 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
1585 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
1586 | - if ( $copied_li === null ) { |
|
1584 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
1585 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
1586 | + if ($copied_li === null) { |
|
1587 | 1587 | return null; |
1588 | 1588 | } |
1589 | 1589 | //if this is an event subtotal, we want to only include it if it |
1590 | 1590 | //has a non-zero total and at least one ticket line item child |
1591 | 1591 | $ticket_children = 0; |
1592 | - foreach ( $line_item->children() as $child_li ) { |
|
1593 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
1594 | - if ( $child_li_copy !== null ) { |
|
1595 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
1596 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1592 | + foreach ($line_item->children() as $child_li) { |
|
1593 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
1594 | + if ($child_li_copy !== null) { |
|
1595 | + $copied_li->add_child_line_item($child_li_copy); |
|
1596 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1597 | 1597 | $child_li_copy->OBJ_type() === 'Ticket' |
1598 | 1598 | ) { |
1599 | 1599 | $ticket_children++; |
@@ -1623,8 +1623,8 @@ discard block |
||
1623 | 1623 | * @return EE_Line_Item |
1624 | 1624 | * @throws \EE_Error |
1625 | 1625 | */ |
1626 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
1627 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1626 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
1627 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1628 | 1628 | $line_item->OBJ_type() === 'Ticket' && |
1629 | 1629 | $line_item->quantity() === 0 |
1630 | 1630 | ) { |
@@ -1632,8 +1632,8 @@ discard block |
||
1632 | 1632 | } |
1633 | 1633 | $new_li_fields = $line_item->model_field_array(); |
1634 | 1634 | //don't set the total. We'll leave that up to the code that calculates it |
1635 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] ); |
|
1636 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1635 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
1636 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1637 | 1637 | } |
1638 | 1638 | |
1639 | 1639 | |
@@ -1645,9 +1645,9 @@ discard block |
||
1645 | 1645 | * @return \EE_Line_Item |
1646 | 1646 | * @throws \EE_Error |
1647 | 1647 | */ |
1648 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
1649 | - 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' ); |
|
1650 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
1648 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
1649 | + 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'); |
|
1650 | + return self::get_pre_tax_subtotal($total_line_item); |
|
1651 | 1651 | } |
1652 | 1652 | |
1653 | 1653 | |
@@ -1658,9 +1658,9 @@ discard block |
||
1658 | 1658 | * @return \EE_Line_Item |
1659 | 1659 | * @throws \EE_Error |
1660 | 1660 | */ |
1661 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
1662 | - 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' ); |
|
1663 | - return self::create_total_line_item( $transaction ); |
|
1661 | + public static function create_default_total_line_item($transaction = NULL) { |
|
1662 | + 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'); |
|
1663 | + return self::create_total_line_item($transaction); |
|
1664 | 1664 | } |
1665 | 1665 | |
1666 | 1666 | |
@@ -1672,9 +1672,9 @@ discard block |
||
1672 | 1672 | * @return \EE_Line_Item |
1673 | 1673 | * @throws \EE_Error |
1674 | 1674 | */ |
1675 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1676 | - 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' ); |
|
1677 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
1675 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1676 | + 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'); |
|
1677 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | |
@@ -1686,9 +1686,9 @@ discard block |
||
1686 | 1686 | * @return \EE_Line_Item |
1687 | 1687 | * @throws \EE_Error |
1688 | 1688 | */ |
1689 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1690 | - 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' ); |
|
1691 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
1689 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1690 | + 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'); |
|
1691 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
1692 | 1692 | } |
1693 | 1693 | |
1694 | 1694 | |
@@ -1700,9 +1700,9 @@ discard block |
||
1700 | 1700 | * @return \EE_Line_Item |
1701 | 1701 | * @throws \EE_Error |
1702 | 1702 | */ |
1703 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1704 | - 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' ); |
|
1705 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
1703 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1704 | + 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'); |
|
1705 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
1706 | 1706 | } |
1707 | 1707 | |
1708 | 1708 |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | |
4 | 4 | use DomainException; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
7 | - exit( 'No direct script access allowed' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | * @param int $code |
29 | 29 | * @param \Exception $previous |
30 | 30 | */ |
31 | - public function __construct( $entity, $expected_class, $message = '', $code = 0, \Exception $previous = null ) { |
|
32 | - if ( empty( $message ) ) { |
|
31 | + public function __construct($entity, $expected_class, $message = '', $code = 0, \Exception $previous = null) { |
|
32 | + if (empty($message)) { |
|
33 | 33 | $message = sprintf( |
34 | 34 | __( |
35 | 35 | 'The retrieved entity is an instance of "%1$s", but an instance of "%2$s" was expected.', |
36 | 36 | 'event_espresso' |
37 | 37 | ), |
38 | - is_object( $entity ) ? get_class( $entity ) : gettype( $entity ), |
|
38 | + is_object($entity) ? get_class($entity) : gettype($entity), |
|
39 | 39 | $expected_class |
40 | 40 | ); |
41 | 41 | } |
42 | - parent::__construct( $message, $code, $previous ); |
|
42 | + parent::__construct($message, $code, $previous); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | } |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | |
4 | 4 | use DomainException; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
7 | - exit( 'No direct script access allowed' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | * @param int $code |
29 | 29 | * @param \Exception $previous |
30 | 30 | */ |
31 | - public function __construct( $entity_class, $message = '', $code = 0, \Exception $previous = null ) { |
|
32 | - if ( empty( $message ) ) { |
|
31 | + public function __construct($entity_class, $message = '', $code = 0, \Exception $previous = null) { |
|
32 | + if (empty($message)) { |
|
33 | 33 | $message = sprintf( |
34 | 34 | __( |
35 | 35 | 'The "%1$s" entity could not be instantiated for an unknown reason', |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | $entity_class |
39 | 39 | ); |
40 | 40 | } |
41 | - parent::__construct( $message, $code, $previous ); |
|
41 | + parent::__construct($message, $code, $previous); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | } |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | |
4 | 4 | use UnexpectedValueException; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
7 | - exit( 'No direct script access allowed' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | * @param int $code |
31 | 31 | * @param \Exception $previous |
32 | 32 | */ |
33 | - public function __construct( $identifier_type, $identifier, $message = '', $code = 0, \Exception $previous = null ) { |
|
34 | - if ( empty( $message ) ) { |
|
33 | + public function __construct($identifier_type, $identifier, $message = '', $code = 0, \Exception $previous = null) { |
|
34 | + if (empty($message)) { |
|
35 | 35 | $message = sprintf( |
36 | 36 | __( |
37 | 37 | 'The requested entity with %1$s="%2$s" was not found.', |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | $identifier |
42 | 42 | ); |
43 | 43 | } |
44 | - parent::__construct( $message, $code, $previous ); |
|
44 | + parent::__construct($message, $code, $previous); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 |
@@ -111,12 +111,12 @@ |
||
111 | 111 | public function previous(); |
112 | 112 | |
113 | 113 | /** |
114 | - * Returns the index of a given object, or false if not found |
|
115 | - * |
|
116 | - * @see http://stackoverflow.com/a/8736013 |
|
117 | - * @param $object |
|
118 | - * @return boolean|int|string |
|
119 | - */ |
|
114 | + * Returns the index of a given object, or false if not found |
|
115 | + * |
|
116 | + * @see http://stackoverflow.com/a/8736013 |
|
117 | + * @param $object |
|
118 | + * @return boolean|int|string |
|
119 | + */ |
|
120 | 120 | public function indexOf( $object ); |
121 | 121 | |
122 | 122 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\services\collections; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param mixed $identifier |
26 | 26 | * @return bool |
27 | 27 | */ |
28 | - public function add( $object, $identifier = null ); |
|
28 | + public function add($object, $identifier = null); |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * setIdentifier |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param mixed $identifier |
38 | 38 | * @return bool |
39 | 39 | */ |
40 | - public function setIdentifier( $object, $identifier = null ); |
|
40 | + public function setIdentifier($object, $identifier = null); |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * get |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * @param mixed $identifier |
49 | 49 | * @return mixed |
50 | 50 | */ |
51 | - public function get( $identifier ); |
|
51 | + public function get($identifier); |
|
52 | 52 | |
53 | 53 | /** |
54 | 54 | * has |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param mixed $identifier |
61 | 61 | * @return bool |
62 | 62 | */ |
63 | - public function has( $identifier ); |
|
63 | + public function has($identifier); |
|
64 | 64 | |
65 | 65 | /** |
66 | 66 | * hasObject |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @param $object |
71 | 71 | * @return bool |
72 | 72 | */ |
73 | - public function hasObject( $object ); |
|
73 | + public function hasObject($object); |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * remove |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @param $object |
81 | 81 | * @return bool |
82 | 82 | */ |
83 | - public function remove( $object ); |
|
83 | + public function remove($object); |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * setCurrent |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param mixed $identifier |
91 | 91 | * @return boolean |
92 | 92 | */ |
93 | - public function setCurrent( $identifier ) ; |
|
93 | + public function setCurrent($identifier); |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * setCurrentUsingObject |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * @param $object |
101 | 101 | * @return boolean |
102 | 102 | */ |
103 | - public function setCurrentUsingObject( $object ); |
|
103 | + public function setCurrentUsingObject($object); |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Returns the object occupying the index before the current object, |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param $object |
118 | 118 | * @return boolean|int|string |
119 | 119 | */ |
120 | - public function indexOf( $object ); |
|
120 | + public function indexOf($object); |
|
121 | 121 | |
122 | 122 | |
123 | 123 | /** |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @param $index |
128 | 128 | * @return mixed |
129 | 129 | */ |
130 | - public function objectAtIndex( $index ); |
|
130 | + public function objectAtIndex($index); |
|
131 | 131 | |
132 | 132 | /** |
133 | 133 | * Returns the sequence of objects as specified by the offset and length |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * @param int $length |
138 | 138 | * @return array |
139 | 139 | */ |
140 | - public function slice( $offset, $length ); |
|
140 | + public function slice($offset, $length); |
|
141 | 141 | |
142 | 142 | /** |
143 | 143 | * Inserts an object (or an array of objects) at a certain point |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @param mixed $objects A single object or an array of objects |
147 | 147 | * @param integer $index |
148 | 148 | */ |
149 | - public function insertAt( $objects, $index ); |
|
149 | + public function insertAt($objects, $index); |
|
150 | 150 | |
151 | 151 | /** |
152 | 152 | * Removes the object at the given index |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | * @see http://stackoverflow.com/a/8736013 |
155 | 155 | * @param integer $index |
156 | 156 | */ |
157 | - public function removeAt( $index ) ; |
|
157 | + public function removeAt($index); |
|
158 | 158 | |
159 | 159 | |
160 | 160 | } |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | |
4 | 4 | use EventEspresso\Core\Exceptions\InvalidDataTypeException; |
5 | 5 | |
6 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
7 | - exit( 'No direct script access allowed' ); |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @author Brent Christensen |
20 | 20 | * @since 4.9.0 |
21 | 21 | */ |
22 | -class ProgressStep implements ProgressStepInterface{ |
|
22 | +class ProgressStep implements ProgressStepInterface { |
|
23 | 23 | |
24 | 24 | |
25 | 25 | /** |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | * @param string $text |
66 | 66 | * @throws InvalidDataTypeException |
67 | 67 | */ |
68 | - public function __construct( $order, $id, $html_class, $text ) { |
|
69 | - $this->setOrder( $order ); |
|
70 | - $this->setId( $id ); |
|
71 | - $this->setHtmlClass( $html_class ); |
|
72 | - $this->setText( $text ); |
|
68 | + public function __construct($order, $id, $html_class, $text) { |
|
69 | + $this->setOrder($order); |
|
70 | + $this->setId($id); |
|
71 | + $this->setHtmlClass($html_class); |
|
72 | + $this->setText($text); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * @param boolean $current |
88 | 88 | */ |
89 | - public function setIsCurrent( $current = true ) { |
|
90 | - $this->current = filter_var( $current, FILTER_VALIDATE_BOOLEAN ); |
|
89 | + public function setIsCurrent($current = true) { |
|
90 | + $this->current = filter_var($current, FILTER_VALIDATE_BOOLEAN); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | /** |
105 | 105 | * @param boolean $completed |
106 | 106 | */ |
107 | - public function setIsCompleted( $completed = true ) { |
|
108 | - $this->completed = filter_var( $completed, FILTER_VALIDATE_BOOLEAN ); |
|
107 | + public function setIsCompleted($completed = true) { |
|
108 | + $this->completed = filter_var($completed, FILTER_VALIDATE_BOOLEAN); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * @param string $id |
125 | 125 | * @throws InvalidDataTypeException |
126 | 126 | */ |
127 | - protected function setId( $id = '' ) { |
|
128 | - if ( ! is_string( $id ) ) { |
|
129 | - throw new InvalidDataTypeException( '$id', $id, 'string' ); |
|
127 | + protected function setId($id = '') { |
|
128 | + if ( ! is_string($id)) { |
|
129 | + throw new InvalidDataTypeException('$id', $id, 'string'); |
|
130 | 130 | } |
131 | 131 | $this->id = $id; |
132 | 132 | } |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param int $order |
149 | 149 | * @throws InvalidDataTypeException |
150 | 150 | */ |
151 | - protected function setOrder( $order = 0 ) { |
|
152 | - if ( ! is_int( $order ) ) { |
|
153 | - throw new InvalidDataTypeException( '$order', $order, 'integer' ); |
|
151 | + protected function setOrder($order = 0) { |
|
152 | + if ( ! is_int($order)) { |
|
153 | + throw new InvalidDataTypeException('$order', $order, 'integer'); |
|
154 | 154 | } |
155 | 155 | $this->order = $order; |
156 | 156 | } |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function htmlClass() { |
164 | 164 | $html_class = $this->html_class; |
165 | - if ( $this->isCurrent() ) { |
|
165 | + if ($this->isCurrent()) { |
|
166 | 166 | $html_class .= ' progress-step-active'; |
167 | - } else if ( $this->isCompleted() ) { |
|
167 | + } else if ($this->isCompleted()) { |
|
168 | 168 | $html_class .= ' progress-step-completed'; |
169 | 169 | } |
170 | 170 | return $html_class; |
@@ -177,12 +177,12 @@ discard block |
||
177 | 177 | * @param string $html_class |
178 | 178 | * @throws InvalidDataTypeException |
179 | 179 | */ |
180 | - protected function setHtmlClass( $html_class ) { |
|
181 | - if ( ! is_string( $html_class ) ) { |
|
182 | - throw new InvalidDataTypeException( '$html_class', $html_class, 'string' ); |
|
180 | + protected function setHtmlClass($html_class) { |
|
181 | + if ( ! is_string($html_class)) { |
|
182 | + throw new InvalidDataTypeException('$html_class', $html_class, 'string'); |
|
183 | 183 | } |
184 | - if ( strpos( $html_class, 'progress-step-' ) === false ) { |
|
185 | - $html_class = 'progress-step-' . $html_class; |
|
184 | + if (strpos($html_class, 'progress-step-') === false) { |
|
185 | + $html_class = 'progress-step-'.$html_class; |
|
186 | 186 | } |
187 | 187 | $this->html_class = $html_class; |
188 | 188 | } |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | * @param string $text |
204 | 204 | * @throws InvalidDataTypeException |
205 | 205 | */ |
206 | - protected function setText( $text ) { |
|
207 | - if ( ! is_string( $text ) ) { |
|
208 | - throw new InvalidDataTypeException( '$text', $text, 'string' ); |
|
206 | + protected function setText($text) { |
|
207 | + if ( ! is_string($text)) { |
|
208 | + throw new InvalidDataTypeException('$text', $text, 'string'); |
|
209 | 209 | } |
210 | 210 | $this->text = $text; |
211 | 211 | } |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | use EventEspresso\core\services\collections\CollectionInterface; |
11 | 11 | use EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface; |
12 | 12 | |
13 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
14 | - exit( 'No direct script access allowed' ); |
|
13 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
14 | + exit('No direct script access allowed'); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | CollectionInterface $collection = null, |
79 | 79 | EE_Request $request = null |
80 | 80 | ) { |
81 | - $this->setDisplayStrategy( $display_strategy_name ); |
|
82 | - $this->setDefaultStep( $default_step ); |
|
83 | - $this->setFormStepUrlKey( $form_step_url_key ); |
|
84 | - if ( ! $collection instanceof CollectionInterface ) { |
|
85 | - $collection = new Collection( '\EventEspresso\core\services\progress_steps\ProgressStepInterface' ); |
|
81 | + $this->setDisplayStrategy($display_strategy_name); |
|
82 | + $this->setDefaultStep($default_step); |
|
83 | + $this->setFormStepUrlKey($form_step_url_key); |
|
84 | + if ( ! $collection instanceof CollectionInterface) { |
|
85 | + $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface'); |
|
86 | 86 | } |
87 | 87 | $this->collection = $collection; |
88 | - if ( ! $request instanceof EE_Request ) { |
|
89 | - $request = \EE_Registry::instance()->load_core( 'Request' ); |
|
88 | + if ( ! $request instanceof EE_Request) { |
|
89 | + $request = \EE_Registry::instance()->load_core('Request'); |
|
90 | 90 | } |
91 | 91 | $this->request = $request; |
92 | 92 | } |
@@ -98,28 +98,28 @@ discard block |
||
98 | 98 | * @throws InvalidDataTypeException |
99 | 99 | * @throws InvalidClassException |
100 | 100 | */ |
101 | - protected function setDisplayStrategy( $display_strategy_name = 'number_bubbles' ) { |
|
102 | - if ( ! is_string( $display_strategy_name ) ) { |
|
103 | - throw new InvalidDataTypeException( '$display_strategy_name', $display_strategy_name, 'string' ); |
|
101 | + protected function setDisplayStrategy($display_strategy_name = 'number_bubbles') { |
|
102 | + if ( ! is_string($display_strategy_name)) { |
|
103 | + throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string'); |
|
104 | 104 | } |
105 | 105 | // build up FQCN from incoming display strategy folder name |
106 | 106 | $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\'; |
107 | - $display_strategy_class .= $display_strategy_name . '\\'; |
|
108 | - $display_strategy_class .= str_replace( ' ', '', ucwords( str_replace( '_', ' ', $display_strategy_name ) ) ); |
|
107 | + $display_strategy_class .= $display_strategy_name.'\\'; |
|
108 | + $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name))); |
|
109 | 109 | $display_strategy_class .= 'ProgressStepsDisplay'; |
110 | 110 | $display_strategy_class = apply_filters( |
111 | 111 | 'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class', |
112 | 112 | $display_strategy_class |
113 | 113 | ); |
114 | - if ( ! class_exists( $display_strategy_class ) ) { |
|
115 | - throw new InvalidClassException( $display_strategy_class ); |
|
114 | + if ( ! class_exists($display_strategy_class)) { |
|
115 | + throw new InvalidClassException($display_strategy_class); |
|
116 | 116 | } |
117 | 117 | $display_strategy = new $display_strategy_class(); |
118 | - if ( ! $display_strategy instanceof ProgressStepsDisplayInterface ) { |
|
118 | + if ( ! $display_strategy instanceof ProgressStepsDisplayInterface) { |
|
119 | 119 | throw new InvalidClassException( |
120 | 120 | $display_strategy_class, |
121 | 121 | sprintf( |
122 | - __( 'The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso' ), |
|
122 | + __('The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso'), |
|
123 | 123 | $display_strategy_class, |
124 | 124 | '\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface' |
125 | 125 | ) |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * @param string $default_step |
135 | 135 | * @throws InvalidDataTypeException |
136 | 136 | */ |
137 | - public function setDefaultStep( $default_step ) { |
|
138 | - if ( ! is_string( $default_step ) ) { |
|
139 | - throw new InvalidDataTypeException( '$default_step', $default_step, 'string' ); |
|
137 | + public function setDefaultStep($default_step) { |
|
138 | + if ( ! is_string($default_step)) { |
|
139 | + throw new InvalidDataTypeException('$default_step', $default_step, 'string'); |
|
140 | 140 | } |
141 | 141 | $this->default_step = $default_step; |
142 | 142 | } |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @param string $form_step_url_key |
148 | 148 | * @throws InvalidDataTypeException |
149 | 149 | */ |
150 | - public function setFormStepUrlKey( $form_step_url_key = 'ee-form-step' ) { |
|
151 | - if ( ! is_string( $form_step_url_key ) ) { |
|
152 | - throw new InvalidDataTypeException( '$form_step_key', $form_step_url_key, 'string' ); |
|
150 | + public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') { |
|
151 | + if ( ! is_string($form_step_url_key)) { |
|
152 | + throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
153 | 153 | } |
154 | - $this->form_step_url_key = ! empty( $form_step_url_key ) ? $form_step_url_key : 'ee-form-step'; |
|
154 | + $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | |
@@ -160,26 +160,26 @@ discard block |
||
160 | 160 | * @param string $step |
161 | 161 | * @throws InvalidIdentifierException |
162 | 162 | */ |
163 | - public function setCurrentStep( $step = '' ) { |
|
163 | + public function setCurrentStep($step = '') { |
|
164 | 164 | // use incoming value if it's set, otherwise use request param if it's set, otherwise use default |
165 | - $step = ! empty( $step ) |
|
165 | + $step = ! empty($step) |
|
166 | 166 | ? $step |
167 | - : $this->request->get( $this->form_step_url_key, $this->default_step ); |
|
167 | + : $this->request->get($this->form_step_url_key, $this->default_step); |
|
168 | 168 | // grab the step previously known as current, in case we need to revert |
169 | 169 | $current_current_step = $this->collection->current(); |
170 | 170 | // verify that requested step exists |
171 | - if ( ! $this->collection->has( $step ) ) { |
|
172 | - throw new InvalidIdentifierException( $step, $this->default_step ); |
|
171 | + if ( ! $this->collection->has($step)) { |
|
172 | + throw new InvalidIdentifierException($step, $this->default_step); |
|
173 | 173 | } |
174 | - if ( $this->collection->setCurrent( $step ) ) { |
|
174 | + if ($this->collection->setCurrent($step)) { |
|
175 | 175 | // if the old boss is the same as the new boss, then nothing changes |
176 | - if ( $this->collection->current() !== $current_current_step ) { |
|
177 | - $current_current_step->setIsCurrent( false ); |
|
176 | + if ($this->collection->current() !== $current_current_step) { |
|
177 | + $current_current_step->setIsCurrent(false); |
|
178 | 178 | } |
179 | 179 | $this->collection->current()->setIsCurrent(); |
180 | 180 | } else { |
181 | - $this->collection->setCurrent( $current_current_step->id() ); |
|
182 | - $current_current_step->setIsCurrent( true ); |
|
181 | + $this->collection->setCurrent($current_current_step->id()); |
|
182 | + $current_current_step->setIsCurrent(true); |
|
183 | 183 | } |
184 | 184 | } |
185 | 185 | |
@@ -191,14 +191,14 @@ discard block |
||
191 | 191 | public function setPreviousStepsCompleted() { |
192 | 192 | $current_current_step = $this->collection->current(); |
193 | 193 | $this->collection->rewind(); |
194 | - while ( $this->collection->valid() ) { |
|
195 | - if ( $this->collection->current() === $current_current_step ) { |
|
194 | + while ($this->collection->valid()) { |
|
195 | + if ($this->collection->current() === $current_current_step) { |
|
196 | 196 | break; |
197 | 197 | } |
198 | 198 | $this->setCurrentStepCompleted(); |
199 | 199 | $this->collection->next(); |
200 | 200 | } |
201 | - $this->collection->setCurrentUsingObject( $current_current_step ); |
|
201 | + $this->collection->setCurrentUsingObject($current_current_step); |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | public function displaySteps() { |
240 | 240 | return \EEH_Template::display_template( |
241 | 241 | $this->display_strategy->getTemplate(), |
242 | - array( 'progress_steps' => $this->collection ), |
|
242 | + array('progress_steps' => $this->collection), |
|
243 | 243 | true |
244 | 244 | ); |
245 | 245 | } |
@@ -250,8 +250,8 @@ discard block |
||
250 | 250 | * @param bool $completed |
251 | 251 | * @return \EventEspresso\core\services\progress_steps\ProgressStepInterface |
252 | 252 | */ |
253 | - public function setCurrentStepCompleted( $completed = true ) { |
|
254 | - return $this->collection->current()->setIsCompleted( $completed ); |
|
253 | + public function setCurrentStepCompleted($completed = true) { |
|
254 | + return $this->collection->current()->setIsCompleted($completed); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 |
@@ -2,10 +2,10 @@ |
||
2 | 2 | namespace EventEspresso\core\services\progress_steps; |
3 | 3 | |
4 | 4 | use EE_Request; |
5 | -use EventEspresso\core\exceptions\InvalidClassException; |
|
6 | -use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
7 | -use EventEspresso\core\exceptions\InvalidIdentifierException; |
|
8 | -use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
5 | +use EventEspresso\core\exceptions\InvalidClassException; |
|
6 | +use EventEspresso\core\exceptions\InvalidDataTypeException; |
|
7 | +use EventEspresso\core\exceptions\InvalidIdentifierException; |
|
8 | +use EventEspresso\core\exceptions\InvalidInterfaceException; |
|
9 | 9 | use EventEspresso\core\services\collections\Collection; |
10 | 10 | use EventEspresso\core\services\collections\CollectionInterface; |
11 | 11 | use EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface; |