@@ -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,9 +176,9 @@ discard block |
||
176 | 176 | * @param int $quantity |
177 | 177 | * @return boolean |
178 | 178 | */ |
179 | - public function set_quantity( $quantity ) { |
|
180 | - $quantity = max( $quantity, 0 ); |
|
181 | - $this->set( 'LIN_quantity', $quantity ); |
|
179 | + public function set_quantity($quantity) { |
|
180 | + $quantity = max($quantity, 0); |
|
181 | + $this->set('LIN_quantity', $quantity); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @return string |
189 | 189 | */ |
190 | 190 | public function OBJ_ID() { |
191 | - return $this->get( 'OBJ_ID' ); |
|
191 | + return $this->get('OBJ_ID'); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | * @param string $item_id |
199 | 199 | * @return boolean |
200 | 200 | */ |
201 | - public function set_OBJ_ID( $item_id ) { |
|
202 | - $this->set( 'OBJ_ID', $item_id ); |
|
201 | + public function set_OBJ_ID($item_id) { |
|
202 | + $this->set('OBJ_ID', $item_id); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @return string |
210 | 210 | */ |
211 | 211 | public function OBJ_type() { |
212 | - return $this->get( 'OBJ_type' ); |
|
212 | + return $this->get('OBJ_type'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | * @param string $OBJ_type |
220 | 220 | * @return boolean |
221 | 221 | */ |
222 | - public function set_OBJ_type( $OBJ_type ) { |
|
223 | - $this->set( 'OBJ_type', $OBJ_type ); |
|
222 | + public function set_OBJ_type($OBJ_type) { |
|
223 | + $this->set('OBJ_type', $OBJ_type); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | * @return float |
231 | 231 | */ |
232 | 232 | public function unit_price() { |
233 | - return $this->get( 'LIN_unit_price' ); |
|
233 | + return $this->get('LIN_unit_price'); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | * @param float $unit_price |
241 | 241 | * @return boolean |
242 | 242 | */ |
243 | - public function set_unit_price( $unit_price ) { |
|
244 | - $this->set( 'LIN_unit_price', $unit_price ); |
|
243 | + public function set_unit_price($unit_price) { |
|
244 | + $this->set('LIN_unit_price', $unit_price); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | |
@@ -252,19 +252,19 @@ discard block |
||
252 | 252 | * @return boolean |
253 | 253 | */ |
254 | 254 | public function is_percent() { |
255 | - if( $this->is_tax_sub_total() ) { |
|
255 | + if ($this->is_tax_sub_total()) { |
|
256 | 256 | //tax subtotals HAVE a percent on them, that percentage only applies |
257 | 257 | //to taxable items, so its' an exception. Treat it like a flat line item |
258 | 258 | return false; |
259 | 259 | } |
260 | - $unit_price = abs( $this->get( 'LIN_unit_price' ) ); |
|
261 | - $percent = abs( $this->get( 'LIN_percent' ) ); |
|
262 | - if ( $unit_price < .001 && $percent ) { |
|
260 | + $unit_price = abs($this->get('LIN_unit_price')); |
|
261 | + $percent = abs($this->get('LIN_percent')); |
|
262 | + if ($unit_price < .001 && $percent) { |
|
263 | 263 | return TRUE; |
264 | - } elseif ( $unit_price >= .001 && !$percent ) { |
|
264 | + } elseif ($unit_price >= .001 && ! $percent) { |
|
265 | 265 | return FALSE; |
266 | - } elseif ( $unit_price >= .001 && $percent ) { |
|
267 | - 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 ) ); |
|
266 | + } elseif ($unit_price >= .001 && $percent) { |
|
267 | + 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)); |
|
268 | 268 | } else { |
269 | 269 | // if they're both 0, assume its not a percent item |
270 | 270 | return FALSE; |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @return float |
279 | 279 | */ |
280 | 280 | public function percent() { |
281 | - return $this->get( 'LIN_percent' ); |
|
281 | + return $this->get('LIN_percent'); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -288,8 +288,8 @@ discard block |
||
288 | 288 | * @param float $percent |
289 | 289 | * @return boolean |
290 | 290 | */ |
291 | - public function set_percent( $percent ) { |
|
292 | - $this->set( 'LIN_percent', $percent ); |
|
291 | + public function set_percent($percent) { |
|
292 | + $this->set('LIN_percent', $percent); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return float |
300 | 300 | */ |
301 | 301 | public function total() { |
302 | - return $this->get( 'LIN_total' ); |
|
302 | + return $this->get('LIN_total'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -309,8 +309,8 @@ discard block |
||
309 | 309 | * @param float $total |
310 | 310 | * @return boolean |
311 | 311 | */ |
312 | - public function set_total( $total ) { |
|
313 | - $this->set( 'LIN_total', $total ); |
|
312 | + public function set_total($total) { |
|
313 | + $this->set('LIN_total', $total); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | * @return int |
321 | 321 | */ |
322 | 322 | public function order() { |
323 | - return $this->get( 'LIN_order' ); |
|
323 | + return $this->get('LIN_order'); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | * Sets order |
330 | 330 | * @param int $order |
331 | 331 | */ |
332 | - public function set_order( $order ) { |
|
333 | - $this->set( 'LIN_order', $order ); |
|
332 | + public function set_order($order) { |
|
333 | + $this->set('LIN_order', $order); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | * @return int |
341 | 341 | */ |
342 | 342 | public function parent_ID() { |
343 | - return $this->get( 'LIN_parent' ); |
|
343 | + return $this->get('LIN_parent'); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -350,8 +350,8 @@ discard block |
||
350 | 350 | * @param int $parent |
351 | 351 | * @return boolean |
352 | 352 | */ |
353 | - public function set_parent_ID( $parent ) { |
|
354 | - $this->set( 'LIN_parent', $parent ); |
|
353 | + public function set_parent_ID($parent) { |
|
354 | + $this->set('LIN_parent', $parent); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | * @return string |
362 | 362 | */ |
363 | 363 | public function type() { |
364 | - return $this->get( 'LIN_type' ); |
|
364 | + return $this->get('LIN_type'); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | * @param string $type |
372 | 372 | * @return boolean |
373 | 373 | */ |
374 | - public function set_type( $type ) { |
|
375 | - $this->set( 'LIN_type', $type ); |
|
374 | + public function set_type($type) { |
|
375 | + $this->set('LIN_type', $type); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | * @return EE_Line_Item |
386 | 386 | */ |
387 | 387 | public function parent() { |
388 | - if( $this->ID() ) { |
|
389 | - return $this->get_model()->get_one_by_ID( $this->parent_ID() ); |
|
388 | + if ($this->ID()) { |
|
389 | + return $this->get_model()->get_one_by_ID($this->parent_ID()); |
|
390 | 390 | } else { |
391 | 391 | return $this->_parent; |
392 | 392 | } |
@@ -399,13 +399,13 @@ discard block |
||
399 | 399 | * @return EE_Line_Item[] |
400 | 400 | */ |
401 | 401 | public function children() { |
402 | - if ( $this->ID() ) { |
|
402 | + if ($this->ID()) { |
|
403 | 403 | return $this->get_model()->get_all( |
404 | 404 | array( |
405 | - array( 'LIN_parent' => $this->ID() ), |
|
406 | - 'order_by' => array( 'LIN_order' => 'ASC' ) ) ); |
|
405 | + array('LIN_parent' => $this->ID()), |
|
406 | + 'order_by' => array('LIN_order' => 'ASC') ) ); |
|
407 | 407 | } else { |
408 | - if ( ! is_array( $this->_children ) ) { |
|
408 | + if ( ! is_array($this->_children)) { |
|
409 | 409 | $this->_children = array(); |
410 | 410 | } |
411 | 411 | return $this->_children; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | * @return string |
420 | 420 | */ |
421 | 421 | public function code() { |
422 | - return $this->get( 'LIN_code' ); |
|
422 | + return $this->get('LIN_code'); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | * @param string $code |
430 | 430 | * @return boolean |
431 | 431 | */ |
432 | - public function set_code( $code ) { |
|
433 | - $this->set( 'LIN_code', $code ); |
|
432 | + public function set_code($code) { |
|
433 | + $this->set('LIN_code', $code); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * @return boolean |
441 | 441 | */ |
442 | 442 | public function is_taxable() { |
443 | - return $this->get( 'LIN_is_taxable' ); |
|
443 | + return $this->get('LIN_is_taxable'); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | |
@@ -450,8 +450,8 @@ discard block |
||
450 | 450 | * @param boolean $is_taxable |
451 | 451 | * @return boolean |
452 | 452 | */ |
453 | - public function set_is_taxable( $is_taxable ) { |
|
454 | - $this->set( 'LIN_is_taxable', $is_taxable ); |
|
453 | + public function set_is_taxable($is_taxable) { |
|
454 | + $this->set('LIN_is_taxable', $is_taxable); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | */ |
467 | 467 | public function get_object() { |
468 | 468 | $model_name_of_related_obj = $this->OBJ_type(); |
469 | - return $this->get_model()->has_relation( $model_name_of_related_obj ) ? $this->get_first_related( $model_name_of_related_obj ) : NULL; |
|
469 | + return $this->get_model()->has_relation($model_name_of_related_obj) ? $this->get_first_related($model_name_of_related_obj) : NULL; |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | |
@@ -477,11 +477,11 @@ discard block |
||
477 | 477 | * @param array $query_params |
478 | 478 | * @return EE_Ticket |
479 | 479 | */ |
480 | - public function ticket( $query_params = array() ) { |
|
480 | + public function ticket($query_params = array()) { |
|
481 | 481 | //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 |
482 | - $remove_defaults = array( 'default_where_conditions' => 'none' ); |
|
483 | - $query_params = array_merge( $remove_defaults, $query_params ); |
|
484 | - return $this->get_first_related( 'Ticket', $query_params ); |
|
482 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
483 | + $query_params = array_merge($remove_defaults, $query_params); |
|
484 | + return $this->get_first_related('Ticket', $query_params); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | |
@@ -491,11 +491,11 @@ discard block |
||
491 | 491 | * @return EE_Datetime | NULL |
492 | 492 | */ |
493 | 493 | public function get_ticket_datetime() { |
494 | - if ( $this->OBJ_type() === 'Ticket' ) { |
|
494 | + if ($this->OBJ_type() === 'Ticket') { |
|
495 | 495 | $ticket = $this->ticket(); |
496 | - if ( $ticket instanceof EE_Ticket ) { |
|
496 | + if ($ticket instanceof EE_Ticket) { |
|
497 | 497 | $datetime = $ticket->first_datetime(); |
498 | - if ( $datetime instanceof EE_Datetime ) { |
|
498 | + if ($datetime instanceof EE_Datetime) { |
|
499 | 499 | return $datetime; |
500 | 500 | } |
501 | 501 | } |
@@ -511,9 +511,9 @@ discard block |
||
511 | 511 | * @return string |
512 | 512 | */ |
513 | 513 | public function ticket_event_name() { |
514 | - $event_name = __( "Unknown", "event_espresso" ); |
|
514 | + $event_name = __("Unknown", "event_espresso"); |
|
515 | 515 | $event = $this->ticket_event(); |
516 | - if ( $event instanceof EE_Event ) { |
|
516 | + if ($event instanceof EE_Event) { |
|
517 | 517 | $event_name = $event->name(); |
518 | 518 | } |
519 | 519 | return $event_name; |
@@ -527,9 +527,9 @@ discard block |
||
527 | 527 | public function ticket_event() { |
528 | 528 | $event = null; |
529 | 529 | $ticket = $this->ticket(); |
530 | - if ( $ticket instanceof EE_Ticket ) { |
|
530 | + if ($ticket instanceof EE_Ticket) { |
|
531 | 531 | $datetime = $ticket->first_datetime(); |
532 | - if ( $datetime instanceof EE_Datetime ) { |
|
532 | + if ($datetime instanceof EE_Datetime) { |
|
533 | 533 | $event = $datetime->event(); |
534 | 534 | } |
535 | 535 | } |
@@ -544,11 +544,11 @@ discard block |
||
544 | 544 | * @param string $time_format |
545 | 545 | * @return string |
546 | 546 | */ |
547 | - public function ticket_datetime_start( $date_format = '', $time_format = '' ) { |
|
548 | - $first_datetime_string = __( "Unknown", "event_espresso" ); |
|
547 | + public function ticket_datetime_start($date_format = '', $time_format = '') { |
|
548 | + $first_datetime_string = __("Unknown", "event_espresso"); |
|
549 | 549 | $datetime = $this->get_ticket_datetime(); |
550 | - if ( $datetime ) { |
|
551 | - $first_datetime_string = $datetime->start_date_and_time( $date_format, $time_format ); |
|
550 | + if ($datetime) { |
|
551 | + $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
552 | 552 | } |
553 | 553 | return $first_datetime_string; |
554 | 554 | } |
@@ -563,26 +563,26 @@ discard block |
||
563 | 563 | * @return bool success |
564 | 564 | * @throws \EE_Error |
565 | 565 | */ |
566 | - public function add_child_line_item( EEI_Line_Item $line_item, $set_order = true ) { |
|
566 | + public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) { |
|
567 | 567 | // should we calculate the LIN_order for this line item ? |
568 | - if ( $set_order || $line_item->order() === null ) { |
|
569 | - $line_item->set_order( count( $this->children() ) ); |
|
568 | + if ($set_order || $line_item->order() === null) { |
|
569 | + $line_item->set_order(count($this->children())); |
|
570 | 570 | } |
571 | - if ( $this->ID() ) { |
|
571 | + if ($this->ID()) { |
|
572 | 572 | //check for any duplicate line items (with the same code), if so, this replaces it |
573 | - $line_item_with_same_code = $this->get_child_line_item( $line_item->code() ); |
|
574 | - if( $line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item ) { |
|
575 | - $this->delete_child_line_item( $line_item_with_same_code->code() ); |
|
573 | + $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
574 | + if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
575 | + $this->delete_child_line_item($line_item_with_same_code->code()); |
|
576 | 576 | } |
577 | - $line_item->set_parent_ID( $this->ID() ); |
|
578 | - if( $this->TXN_ID() ){ |
|
579 | - $line_item->set_TXN_ID( $this->TXN_ID() ); |
|
577 | + $line_item->set_parent_ID($this->ID()); |
|
578 | + if ($this->TXN_ID()) { |
|
579 | + $line_item->set_TXN_ID($this->TXN_ID()); |
|
580 | 580 | } |
581 | 581 | return $line_item->save(); |
582 | 582 | } else { |
583 | - $this->_children[ $line_item->code() ] = $line_item; |
|
584 | - if( $line_item->parent() != $this ) { |
|
585 | - $line_item->set_parent( $this ); |
|
583 | + $this->_children[$line_item->code()] = $line_item; |
|
584 | + if ($line_item->parent() != $this) { |
|
585 | + $line_item->set_parent($this); |
|
586 | 586 | } |
587 | 587 | return TRUE; |
588 | 588 | } |
@@ -596,16 +596,16 @@ discard block |
||
596 | 596 | * @param EE_Line_Item $line_item |
597 | 597 | * |
598 | 598 | */ |
599 | - public function set_parent( $line_item ) { |
|
600 | - if ( $this->ID() ) { |
|
601 | - if( ! $line_item->ID() ) { |
|
599 | + public function set_parent($line_item) { |
|
600 | + if ($this->ID()) { |
|
601 | + if ( ! $line_item->ID()) { |
|
602 | 602 | $line_item->save(); |
603 | 603 | } |
604 | - $this->set_parent_ID( $line_item->ID() ); |
|
604 | + $this->set_parent_ID($line_item->ID()); |
|
605 | 605 | $this->save(); |
606 | 606 | } else { |
607 | 607 | $this->_parent = $line_item; |
608 | - $this->set_parent_ID( $line_item->ID() ); |
|
608 | + $this->set_parent_ID($line_item->ID()); |
|
609 | 609 | } |
610 | 610 | } |
611 | 611 | |
@@ -618,11 +618,11 @@ discard block |
||
618 | 618 | * @param string $code |
619 | 619 | * @return EE_Line_Item |
620 | 620 | */ |
621 | - public function get_child_line_item( $code ) { |
|
622 | - if ( $this->ID() ) { |
|
623 | - return $this->get_model()->get_one( array( array( 'LIN_parent' => $this->ID(), 'LIN_code' => $code ) ) ); |
|
621 | + public function get_child_line_item($code) { |
|
622 | + if ($this->ID()) { |
|
623 | + return $this->get_model()->get_one(array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code))); |
|
624 | 624 | } else { |
625 | - return isset( $this->_children[ $code ] ) ? $this->_children[ $code ] : null; |
|
625 | + return isset($this->_children[$code]) ? $this->_children[$code] : null; |
|
626 | 626 | } |
627 | 627 | } |
628 | 628 | |
@@ -633,10 +633,10 @@ discard block |
||
633 | 633 | * @return int |
634 | 634 | */ |
635 | 635 | public function delete_children_line_items() { |
636 | - if ( $this->ID() ) { |
|
637 | - return $this->get_model()->delete( array( array( 'LIN_parent' => $this->ID() ) ) ); |
|
636 | + if ($this->ID()) { |
|
637 | + return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
638 | 638 | } else { |
639 | - $count = count( $this->_children ); |
|
639 | + $count = count($this->_children); |
|
640 | 640 | $this->_children = array(); |
641 | 641 | return $count; |
642 | 642 | } |
@@ -653,25 +653,25 @@ discard block |
||
653 | 653 | * @param bool $stop_search_once_found |
654 | 654 | * @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) |
655 | 655 | */ |
656 | - public function delete_child_line_item( $code, $stop_search_once_found = true ) { |
|
657 | - if ( $this->ID() ) { |
|
656 | + public function delete_child_line_item($code, $stop_search_once_found = true) { |
|
657 | + if ($this->ID()) { |
|
658 | 658 | $items_deleted = 0; |
659 | - if( $this->code() == $code ) { |
|
660 | - $items_deleted += EEH_Line_Item::delete_all_child_items( $this ); |
|
659 | + if ($this->code() == $code) { |
|
660 | + $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
661 | 661 | $items_deleted += (int) $this->delete(); |
662 | - if( $stop_search_once_found ){ |
|
662 | + if ($stop_search_once_found) { |
|
663 | 663 | return $items_deleted; |
664 | 664 | } |
665 | 665 | } |
666 | - foreach( $this->children() as $child_line_item ) { |
|
667 | - $items_deleted += $child_line_item->delete_child_line_item( $code, $stop_search_once_found ); |
|
666 | + foreach ($this->children() as $child_line_item) { |
|
667 | + $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
668 | 668 | } |
669 | 669 | return $items_deleted; |
670 | 670 | } else { |
671 | - if( isset( $this->_children[ $code ] ) ) { |
|
672 | - unset( $this->_children[ $code ] ); |
|
671 | + if (isset($this->_children[$code])) { |
|
672 | + unset($this->_children[$code]); |
|
673 | 673 | return 1; |
674 | - }else{ |
|
674 | + } else { |
|
675 | 675 | return 0; |
676 | 676 | } |
677 | 677 | } |
@@ -684,9 +684,9 @@ discard block |
||
684 | 684 | * @return boolean |
685 | 685 | */ |
686 | 686 | public function delete_if_childless_subtotal() { |
687 | - if( $this->ID() && |
|
687 | + if ($this->ID() && |
|
688 | 688 | $this->type() == EEM_Line_Item::type_sub_total && |
689 | - ! $this->children() ) { |
|
689 | + ! $this->children()) { |
|
690 | 690 | return $this->delete(); |
691 | 691 | } else { |
692 | 692 | return false; |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | */ |
702 | 702 | public function generate_code() { |
703 | 703 | // each line item in the cart requires a unique identifier |
704 | - return md5( $this->get( 'OBJ_type' ) . $this->get( 'OBJ_ID' ) . microtime() ); |
|
704 | + return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime()); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | * @return string like '2, 004.00', formatted according to the localized currency |
775 | 775 | */ |
776 | 776 | public function unit_price_no_code() { |
777 | - return $this->get_pretty( 'LIN_unit_price', 'no_currency_code' ); |
|
777 | + return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | * @return string like '2, 004.00', formatted according to the localized currency |
785 | 785 | */ |
786 | 786 | public function total_no_code() { |
787 | - return $this->get_pretty( 'LIN_total', 'no_currency_code' ); |
|
787 | + return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
788 | 788 | } |
789 | 789 | |
790 | 790 | |
@@ -804,17 +804,17 @@ discard block |
||
804 | 804 | $tax_total = $this->recalculate_taxes_and_tax_total(); |
805 | 805 | $total = $pre_tax_total + $tax_total; |
806 | 806 | // no negative totals plz |
807 | - $total = max( $total, 0 ); |
|
808 | - $this->set_total( $total ); |
|
807 | + $total = max($total, 0); |
|
808 | + $this->set_total($total); |
|
809 | 809 | //only update the related transaction's total |
810 | 810 | //if we intend to save this line item and its a grand total |
811 | - if( |
|
811 | + if ( |
|
812 | 812 | $this->allow_persist() && |
813 | 813 | $this->type() === EEM_Line_Item::type_total && |
814 | 814 | $this->transaction() instanceof EE_Transaction |
815 | - ){ |
|
816 | - $this->transaction()->set_total( $total ); |
|
817 | - if ( $this->transaction()->ID() ) { |
|
815 | + ) { |
|
816 | + $this->transaction()->set_total($total); |
|
817 | + if ($this->transaction()->ID()) { |
|
818 | 818 | $this->transaction()->save(); |
819 | 819 | } |
820 | 820 | } |
@@ -834,42 +834,42 @@ discard block |
||
834 | 834 | $total = 0; |
835 | 835 | $my_children = $this->children(); |
836 | 836 | // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total |
837 | - if ( $this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled() ) { |
|
837 | + if ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) { |
|
838 | 838 | return 0; |
839 | 839 | } elseif ( |
840 | - empty( $my_children ) |
|
841 | - && ( $this->is_sub_line_item() || $this->is_line_item() ) |
|
840 | + empty($my_children) |
|
841 | + && ($this->is_sub_line_item() || $this->is_line_item()) |
|
842 | 842 | ) { |
843 | 843 | $total = $this->unit_price() * $this->quantity(); |
844 | - } elseif( $this->is_sub_total() || $this->is_total() ) { |
|
845 | - $total = $this->_recalculate_pretax_total_for_subtotal( $total, $my_children ); |
|
846 | - } elseif ( ! empty( $my_children ) && $this->is_line_item() ) { |
|
847 | - $total = $this->_recalculate_pretax_total_for_line_item( $total, $my_children ); |
|
844 | + } elseif ($this->is_sub_total() || $this->is_total()) { |
|
845 | + $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children); |
|
846 | + } elseif ( ! empty($my_children) && $this->is_line_item()) { |
|
847 | + $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children); |
|
848 | 848 | } |
849 | 849 | //ensure all non-line items and non-sub-line-items have a quantity of 1 |
850 | - if( ! $this->is_line_item() && ! $this->is_sub_line_item() ) { |
|
851 | - $this->set_quantity( 1 ); |
|
852 | - if( ! $this->is_percent() ) { |
|
853 | - $this->set_unit_price( $this->total() ); |
|
850 | + if ( ! $this->is_line_item() && ! $this->is_sub_line_item()) { |
|
851 | + $this->set_quantity(1); |
|
852 | + if ( ! $this->is_percent()) { |
|
853 | + $this->set_unit_price($this->total()); |
|
854 | 854 | } |
855 | 855 | } |
856 | 856 | |
857 | 857 | //we don't want to bother saving grand totals, because that needs to factor in taxes anyways |
858 | 858 | //so it ought to be |
859 | - if( ! $this->is_total() ) { |
|
860 | - $this->set_total( $total ); |
|
859 | + if ( ! $this->is_total()) { |
|
860 | + $this->set_total($total); |
|
861 | 861 | //if not a percent line item, make sure we keep the unit price in sync |
862 | - if( |
|
863 | - ! empty( $my_children ) |
|
862 | + if ( |
|
863 | + ! empty($my_children) |
|
864 | 864 | && $this->is_line_item() |
865 | 865 | && ! $this->is_percent() |
866 | 866 | ) { |
867 | - if( $this->quantity() === 0 ){ |
|
867 | + if ($this->quantity() === 0) { |
|
868 | 868 | $new_unit_price = 0; |
869 | 869 | } else { |
870 | 870 | $new_unit_price = $this->total() / $this->quantity(); |
871 | 871 | } |
872 | - $this->set_unit_price( $new_unit_price ); |
|
872 | + $this->set_unit_price($new_unit_price); |
|
873 | 873 | } |
874 | 874 | $this->maybe_save(); |
875 | 875 | } |
@@ -889,39 +889,39 @@ discard block |
||
889 | 889 | * @return float |
890 | 890 | * @throws \EE_Error |
891 | 891 | */ |
892 | - protected function _recalculate_pretax_total_for_subtotal( $calculated_total_so_far, $my_children = null ) { |
|
893 | - if( $my_children === null ) { |
|
892 | + protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) { |
|
893 | + if ($my_children === null) { |
|
894 | 894 | $my_children = $this->children(); |
895 | 895 | } |
896 | 896 | //get the total of all its children |
897 | - foreach ( $my_children as $child_line_item ) { |
|
898 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
897 | + foreach ($my_children as $child_line_item) { |
|
898 | + if ($child_line_item instanceof EE_Line_Item) { |
|
899 | 899 | // percentage line items are based on total so far |
900 | - if ( $child_line_item->is_percent() ) { |
|
900 | + if ($child_line_item->is_percent()) { |
|
901 | 901 | //round as we go so that the line items add up ok |
902 | 902 | $percent_total = round( |
903 | 903 | $calculated_total_so_far * $child_line_item->percent() / 100, |
904 | 904 | EE_Registry::instance()->CFG->currency->dec_plc |
905 | 905 | ); |
906 | - $child_line_item->set_total( $percent_total ); |
|
906 | + $child_line_item->set_total($percent_total); |
|
907 | 907 | //so far all percent line items should have a quantity of 1 |
908 | 908 | //(ie, no double percent discounts. Although that might be requested someday) |
909 | - $child_line_item->set_quantity( 1 ); |
|
909 | + $child_line_item->set_quantity(1); |
|
910 | 910 | $child_line_item->maybe_save(); |
911 | 911 | $calculated_total_so_far += $percent_total; |
912 | 912 | } else { |
913 | 913 | //verify flat sub-line-item quantities match their parent |
914 | - if( $child_line_item->is_sub_line_item() ) { |
|
915 | - $child_line_item->set_quantity( $this->quantity() ); |
|
914 | + if ($child_line_item->is_sub_line_item()) { |
|
915 | + $child_line_item->set_quantity($this->quantity()); |
|
916 | 916 | } |
917 | 917 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
918 | 918 | } |
919 | 919 | } |
920 | 920 | } |
921 | 921 | |
922 | - if( $this->is_sub_total() ){ |
|
922 | + if ($this->is_sub_total()) { |
|
923 | 923 | // no negative totals plz |
924 | - $calculated_total_so_far = max( $calculated_total_so_far, 0 ); |
|
924 | + $calculated_total_so_far = max($calculated_total_so_far, 0); |
|
925 | 925 | } |
926 | 926 | return $calculated_total_so_far; |
927 | 927 | } |
@@ -939,8 +939,8 @@ discard block |
||
939 | 939 | * @return float |
940 | 940 | * @throws \EE_Error |
941 | 941 | */ |
942 | - protected function _recalculate_pretax_total_for_line_item( $calculated_total_so_far, $my_children = null ) { |
|
943 | - if( $my_children === null ) { |
|
942 | + protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) { |
|
943 | + if ($my_children === null) { |
|
944 | 944 | $my_children = $this->children(); |
945 | 945 | } |
946 | 946 | //we need to keep track of the running total for a single item, |
@@ -948,9 +948,9 @@ discard block |
||
948 | 948 | $unit_price_for_total = 0; |
949 | 949 | $quantity_for_total = 1; |
950 | 950 | //get the total of all its children |
951 | - foreach ( $my_children as $child_line_item ) { |
|
952 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
953 | - if ( $child_line_item->is_percent() ) { |
|
951 | + foreach ($my_children as $child_line_item) { |
|
952 | + if ($child_line_item instanceof EE_Line_Item) { |
|
953 | + if ($child_line_item->is_percent()) { |
|
954 | 954 | //it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity |
955 | 955 | //not total multiplied by percent, because that ignores rounding along-the-way |
956 | 956 | $percent_unit_price = round( |
@@ -958,17 +958,17 @@ discard block |
||
958 | 958 | EE_Registry::instance()->CFG->currency->dec_plc |
959 | 959 | ); |
960 | 960 | $percent_total = $percent_unit_price * $quantity_for_total; |
961 | - $child_line_item->set_total( $percent_total ); |
|
961 | + $child_line_item->set_total($percent_total); |
|
962 | 962 | //so far all percent line items should have a quantity of 1 |
963 | 963 | //(ie, no double percent discounts. Although that might be requested someday) |
964 | - $child_line_item->set_quantity( 1 ); |
|
964 | + $child_line_item->set_quantity(1); |
|
965 | 965 | $child_line_item->maybe_save(); |
966 | 966 | $calculated_total_so_far += $percent_total; |
967 | 967 | $unit_price_for_total += $percent_unit_price; |
968 | 968 | } else { |
969 | 969 | //verify flat sub-line-item quantities match their parent |
970 | - if( $child_line_item->is_sub_line_item() ) { |
|
971 | - $child_line_item->set_quantity( $this->quantity() ); |
|
970 | + if ($child_line_item->is_sub_line_item()) { |
|
971 | + $child_line_item->set_quantity($this->quantity()); |
|
972 | 972 | } |
973 | 973 | $quantity_for_total = $child_line_item->quantity(); |
974 | 974 | $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
@@ -992,10 +992,10 @@ discard block |
||
992 | 992 | //calculate the pretax total |
993 | 993 | $taxable_total = $this->taxable_total(); |
994 | 994 | $tax_total = 0; |
995 | - foreach ( $taxes as $tax ) { |
|
995 | + foreach ($taxes as $tax) { |
|
996 | 996 | $total_on_this_tax = $taxable_total * $tax->percent() / 100; |
997 | 997 | //remember the total on this line item |
998 | - $tax->set_total( $total_on_this_tax ); |
|
998 | + $tax->set_total($total_on_this_tax); |
|
999 | 999 | $tax_total += $tax->total(); |
1000 | 1000 | } |
1001 | 1001 | $this->_recalculate_tax_sub_total(); |
@@ -1009,21 +1009,21 @@ discard block |
||
1009 | 1009 | * @return void |
1010 | 1010 | */ |
1011 | 1011 | private function _recalculate_tax_sub_total() { |
1012 | - if ( $this->is_tax_sub_total() ) { |
|
1012 | + if ($this->is_tax_sub_total()) { |
|
1013 | 1013 | $total = 0; |
1014 | 1014 | $total_percent = 0; |
1015 | 1015 | //simply loop through all its children (which should be taxes) and sum their total |
1016 | - foreach ( $this->children() as $child_tax ) { |
|
1017 | - if ( $child_tax instanceof EE_Line_Item ) { |
|
1016 | + foreach ($this->children() as $child_tax) { |
|
1017 | + if ($child_tax instanceof EE_Line_Item) { |
|
1018 | 1018 | $total += $child_tax->total(); |
1019 | 1019 | $total_percent += $child_tax->percent(); |
1020 | 1020 | } |
1021 | 1021 | } |
1022 | - $this->set_total( $total ); |
|
1023 | - $this->set_percent( $total_percent ); |
|
1024 | - } elseif ( $this->is_total() ) { |
|
1025 | - foreach ( $this->children() as $maybe_tax_subtotal ) { |
|
1026 | - if ( $maybe_tax_subtotal instanceof EE_Line_Item ) { |
|
1022 | + $this->set_total($total); |
|
1023 | + $this->set_percent($total_percent); |
|
1024 | + } elseif ($this->is_total()) { |
|
1025 | + foreach ($this->children() as $maybe_tax_subtotal) { |
|
1026 | + if ($maybe_tax_subtotal instanceof EE_Line_Item) { |
|
1027 | 1027 | $maybe_tax_subtotal->_recalculate_tax_sub_total(); |
1028 | 1028 | } |
1029 | 1029 | } |
@@ -1039,8 +1039,8 @@ discard block |
||
1039 | 1039 | public function get_total_tax() { |
1040 | 1040 | $this->_recalculate_tax_sub_total(); |
1041 | 1041 | $total = 0; |
1042 | - foreach ( $this->tax_descendants() as $tax_line_item ) { |
|
1043 | - if ( $tax_line_item instanceof EE_Line_Item ) { |
|
1042 | + foreach ($this->tax_descendants() as $tax_line_item) { |
|
1043 | + if ($tax_line_item instanceof EE_Line_Item) { |
|
1044 | 1044 | $total += $tax_line_item->total(); |
1045 | 1045 | } |
1046 | 1046 | } |
@@ -1054,15 +1054,15 @@ discard block |
||
1054 | 1054 | */ |
1055 | 1055 | public function get_items_total() { |
1056 | 1056 | //by default, let's make sure we're consistent with the existing line item |
1057 | - if( $this->is_total() ) { |
|
1058 | - $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal( $this ); |
|
1059 | - if( $pretax_subtotal_li instanceof EE_Line_Item ) { |
|
1057 | + if ($this->is_total()) { |
|
1058 | + $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this); |
|
1059 | + if ($pretax_subtotal_li instanceof EE_Line_Item) { |
|
1060 | 1060 | return $pretax_subtotal_li->total(); |
1061 | 1061 | } |
1062 | 1062 | } |
1063 | 1063 | $total = 0; |
1064 | - foreach ( $this->get_items() as $item ) { |
|
1065 | - if ( $item instanceof EE_Line_Item ) { |
|
1064 | + foreach ($this->get_items() as $item) { |
|
1065 | + if ($item instanceof EE_Line_Item) { |
|
1066 | 1066 | $total += $item->total(); |
1067 | 1067 | } |
1068 | 1068 | } |
@@ -1077,7 +1077,7 @@ discard block |
||
1077 | 1077 | * @return EE_Line_Item[] |
1078 | 1078 | */ |
1079 | 1079 | public function tax_descendants() { |
1080 | - return EEH_Line_Item::get_tax_descendants( $this ); |
|
1080 | + return EEH_Line_Item::get_tax_descendants($this); |
|
1081 | 1081 | } |
1082 | 1082 | |
1083 | 1083 | |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | * @return EE_Line_Item[] |
1088 | 1088 | */ |
1089 | 1089 | public function get_items() { |
1090 | - return EEH_Line_Item::get_line_item_descendants( $this ); |
|
1090 | + return EEH_Line_Item::get_line_item_descendants($this); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | |
@@ -1103,22 +1103,22 @@ discard block |
||
1103 | 1103 | */ |
1104 | 1104 | public function taxable_total() { |
1105 | 1105 | $total = 0; |
1106 | - if ( $this->children() ) { |
|
1107 | - foreach ( $this->children() as $child_line_item ) { |
|
1108 | - if ( $child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1106 | + if ($this->children()) { |
|
1107 | + foreach ($this->children() as $child_line_item) { |
|
1108 | + if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1109 | 1109 | //if it's a percent item, only take into account the percent |
1110 | 1110 | //that's taxable too (the taxable total so far) |
1111 | - if( $child_line_item->is_percent() ) { |
|
1112 | - $total = $total + ( $total * $child_line_item->percent() / 100 ); |
|
1113 | - }else{ |
|
1111 | + if ($child_line_item->is_percent()) { |
|
1112 | + $total = $total + ($total * $child_line_item->percent() / 100); |
|
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 | } |
1120 | 1120 | } |
1121 | - return max( $total, 0 ); |
|
1121 | + return max($total, 0); |
|
1122 | 1122 | } |
1123 | 1123 | |
1124 | 1124 | |
@@ -1128,7 +1128,7 @@ discard block |
||
1128 | 1128 | * @return EE_Transaction |
1129 | 1129 | */ |
1130 | 1130 | public function transaction() { |
1131 | - return $this->get_first_related( 'Transaction' ); |
|
1131 | + return $this->get_first_related('Transaction'); |
|
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | |
@@ -1141,17 +1141,17 @@ discard block |
||
1141 | 1141 | * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
1142 | 1142 | * @return int count of items saved |
1143 | 1143 | */ |
1144 | - public function save_this_and_descendants_to_txn( $txn_id = NULL ) { |
|
1145 | - if ( ! $txn_id ) { |
|
1144 | + public function save_this_and_descendants_to_txn($txn_id = NULL) { |
|
1145 | + if ( ! $txn_id) { |
|
1146 | 1146 | $txn_id = $this->TXN_ID(); |
1147 | 1147 | } |
1148 | - $this->set_TXN_ID( $txn_id ); |
|
1148 | + $this->set_TXN_ID($txn_id); |
|
1149 | 1149 | $children = $this->children(); |
1150 | 1150 | $this->save(); |
1151 | - foreach ( $children as $child_line_item ) { |
|
1152 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1153 | - $child_line_item->set_parent_ID( $this->ID() ); |
|
1154 | - $child_line_item->save_this_and_descendants_to_txn( $txn_id ); |
|
1151 | + foreach ($children as $child_line_item) { |
|
1152 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1153 | + $child_line_item->set_parent_ID($this->ID()); |
|
1154 | + $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1155 | 1155 | } |
1156 | 1156 | } |
1157 | 1157 | } |
@@ -1163,9 +1163,9 @@ discard block |
||
1163 | 1163 | * @param string $type one of the constants on EEM_Line_Item |
1164 | 1164 | * @return EE_Line_Item[] |
1165 | 1165 | */ |
1166 | - protected function _get_descendants_of_type( $type ) { |
|
1167 | - 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' ); |
|
1168 | - return EEH_Line_Item::get_descendants_of_type( $this, $type ); |
|
1166 | + protected function _get_descendants_of_type($type) { |
|
1167 | + 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'); |
|
1168 | + return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | |
@@ -1175,9 +1175,9 @@ discard block |
||
1175 | 1175 | * @param string $type like one of the EEM_Line_Item::type_* |
1176 | 1176 | * @return EE_Line_Item |
1177 | 1177 | */ |
1178 | - public function get_nearest_descendant_of_type( $type ) { |
|
1179 | - 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' ); |
|
1180 | - return EEH_Line_Item::get_nearest_descendant_of_type( $this, $type ); |
|
1178 | + public function get_nearest_descendant_of_type($type) { |
|
1179 | + 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'); |
|
1180 | + return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 | |
@@ -1188,7 +1188,7 @@ discard block |
||
1188 | 1188 | * @return int count of items saved |
1189 | 1189 | */ |
1190 | 1190 | public function maybe_save() { |
1191 | - if ( $this->ID() ) { |
|
1191 | + if ($this->ID()) { |
|
1192 | 1192 | return $this->save(); |
1193 | 1193 | } |
1194 | 1194 | return false; |
@@ -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 |
@@ -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 |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * @return boolean success |
43 | 43 | * @throws \EE_Error |
44 | 44 | */ |
45 | - public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
|
46 | - $items_subtotal = self::get_pre_tax_subtotal( $parent_line_item ); |
|
45 | + public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) { |
|
46 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
47 | 47 | $line_item = EE_Line_Item::new_instance(array( |
48 | 48 | 'LIN_name' => $name, |
49 | 49 | 'LIN_desc' => $description, |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | 'LIN_quantity' => $quantity, |
52 | 52 | 'LIN_percent' => null, |
53 | 53 | 'LIN_is_taxable' => $taxable, |
54 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0, |
|
54 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
55 | 55 | 'LIN_total' => (float) $unit_price * (int) $quantity, |
56 | 56 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
57 | 57 | 'LIN_code' => $code, |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | $line_item, |
62 | 62 | $parent_line_item |
63 | 63 | ); |
64 | - return self::add_item( $parent_line_item, $line_item ); |
|
64 | + return self::add_item($parent_line_item, $line_item); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * @return boolean success |
84 | 84 | * @throws \EE_Error |
85 | 85 | */ |
86 | - public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
|
86 | + public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) { |
|
87 | 87 | $line_item = EE_Line_Item::new_instance(array( |
88 | 88 | 'LIN_name' => $name, |
89 | 89 | 'LIN_desc' => $description, |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | 'LIN_percent' => $percentage_amount, |
92 | 92 | 'LIN_quantity' => NULL, |
93 | 93 | 'LIN_is_taxable' => $taxable, |
94 | - 'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ), |
|
94 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
95 | 95 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
96 | 96 | 'LIN_parent' => $parent_line_item->ID() |
97 | 97 | )); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
100 | 100 | $line_item |
101 | 101 | ); |
102 | - return self::add_item( $parent_line_item, $line_item ); |
|
102 | + return self::add_item($parent_line_item, $line_item); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -120,15 +120,15 @@ discard block |
||
120 | 120 | * @return \EE_Line_Item |
121 | 121 | * @throws \EE_Error |
122 | 122 | */ |
123 | - public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
|
124 | - if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) { |
|
125 | - 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() ) ); |
|
123 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
124 | + if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
125 | + 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 | 126 | } |
127 | 127 | // either increment the qty for an existing ticket |
128 | - $line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty ); |
|
128 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
129 | 129 | // or add a new one |
130 | - if ( ! $line_item instanceof EE_Line_Item ) { |
|
131 | - $line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty ); |
|
130 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
131 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
132 | 132 | } |
133 | 133 | $total_line_item->recalculate_total_including_taxes(); |
134 | 134 | return $line_item; |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | * @return \EE_Line_Item |
145 | 145 | * @throws \EE_Error |
146 | 146 | */ |
147 | - public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
147 | + public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
148 | 148 | $line_item = null; |
149 | - if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) { |
|
150 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item ); |
|
151 | - foreach ( (array)$ticket_line_items as $ticket_line_item ) { |
|
149 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
150 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
151 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
152 | 152 | if ( |
153 | 153 | $ticket_line_item instanceof EE_Line_Item |
154 | 154 | && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
161 | - if ( $line_item instanceof EE_Line_Item ) { |
|
162 | - EEH_Line_Item::increment_quantity( $line_item, $qty ); |
|
161 | + if ($line_item instanceof EE_Line_Item) { |
|
162 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
163 | 163 | return $line_item; |
164 | 164 | } |
165 | 165 | return null; |
@@ -176,16 +176,16 @@ discard block |
||
176 | 176 | * @return void |
177 | 177 | * @throws \EE_Error |
178 | 178 | */ |
179 | - public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
180 | - if( ! $line_item->is_percent() ) { |
|
179 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
180 | + if ( ! $line_item->is_percent()) { |
|
181 | 181 | $qty += $line_item->quantity(); |
182 | - $line_item->set_quantity( $qty ); |
|
183 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
182 | + $line_item->set_quantity($qty); |
|
183 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
184 | 184 | $line_item->save(); |
185 | 185 | } |
186 | - foreach( $line_item->children() as $child ) { |
|
187 | - if( $child->is_sub_line_item() ) { |
|
188 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
186 | + foreach ($line_item->children() as $child) { |
|
187 | + if ($child->is_sub_line_item()) { |
|
188 | + EEH_Line_Item::update_quantity($child, $qty); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
@@ -201,17 +201,17 @@ discard block |
||
201 | 201 | * @return void |
202 | 202 | * @throws \EE_Error |
203 | 203 | */ |
204 | - public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
205 | - if( ! $line_item->is_percent() ) { |
|
204 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
205 | + if ( ! $line_item->is_percent()) { |
|
206 | 206 | $qty = $line_item->quantity() - $qty; |
207 | - $qty = max( $qty, 0 ); |
|
208 | - $line_item->set_quantity( $qty ); |
|
209 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
207 | + $qty = max($qty, 0); |
|
208 | + $line_item->set_quantity($qty); |
|
209 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
210 | 210 | $line_item->save(); |
211 | 211 | } |
212 | - foreach( $line_item->children() as $child ) { |
|
213 | - if( $child->is_sub_line_item() ) { |
|
214 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
212 | + foreach ($line_item->children() as $child) { |
|
213 | + if ($child->is_sub_line_item()) { |
|
214 | + EEH_Line_Item::update_quantity($child, $qty); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | } |
@@ -226,15 +226,15 @@ discard block |
||
226 | 226 | * @param int $new_quantity |
227 | 227 | * @throws \EE_Error |
228 | 228 | */ |
229 | - public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
|
230 | - if( ! $line_item->is_percent() ) { |
|
231 | - $line_item->set_quantity( $new_quantity ); |
|
232 | - $line_item->set_total( $line_item->unit_price() * $new_quantity ); |
|
229 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) { |
|
230 | + if ( ! $line_item->is_percent()) { |
|
231 | + $line_item->set_quantity($new_quantity); |
|
232 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
233 | 233 | $line_item->save(); |
234 | 234 | } |
235 | - foreach( $line_item->children() as $child ) { |
|
236 | - if( $child->is_sub_line_item() ) { |
|
237 | - EEH_Line_Item::update_quantity( $child, $new_quantity ); |
|
235 | + foreach ($line_item->children() as $child) { |
|
236 | + if ($child->is_sub_line_item()) { |
|
237 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | } |
@@ -249,44 +249,44 @@ discard block |
||
249 | 249 | * @return \EE_Line_Item |
250 | 250 | * @throws \EE_Error |
251 | 251 | */ |
252 | - public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
252 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
253 | 253 | $datetimes = $ticket->datetimes(); |
254 | - $first_datetime = reset( $datetimes ); |
|
255 | - if( $first_datetime instanceof EE_Datetime && |
|
256 | - $first_datetime->event() instanceof EE_Event ) { |
|
254 | + $first_datetime = reset($datetimes); |
|
255 | + if ($first_datetime instanceof EE_Datetime && |
|
256 | + $first_datetime->event() instanceof EE_Event) { |
|
257 | 257 | $first_datetime_name = $first_datetime->event()->name(); |
258 | 258 | } else { |
259 | - $first_datetime_name = __( 'Event', 'event_espresso' ); |
|
259 | + $first_datetime_name = __('Event', 'event_espresso'); |
|
260 | 260 | } |
261 | - $event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name ); |
|
261 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
262 | 262 | // get event subtotal line |
263 | - $events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket ); |
|
263 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
264 | 264 | // add $ticket to cart |
265 | - $line_item = EE_Line_Item::new_instance( array( |
|
265 | + $line_item = EE_Line_Item::new_instance(array( |
|
266 | 266 | 'LIN_name' => $ticket->name(), |
267 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
267 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description().' '.$event : $event, |
|
268 | 268 | 'LIN_unit_price' => $ticket->price(), |
269 | 269 | 'LIN_quantity' => $qty, |
270 | 270 | 'LIN_is_taxable' => $ticket->taxable(), |
271 | - 'LIN_order' => count( $events_sub_total->children() ), |
|
271 | + 'LIN_order' => count($events_sub_total->children()), |
|
272 | 272 | 'LIN_total' => $ticket->price() * $qty, |
273 | 273 | 'LIN_type' => EEM_Line_Item::type_line_item, |
274 | 274 | 'OBJ_ID' => $ticket->ID(), |
275 | 275 | 'OBJ_type' => 'Ticket' |
276 | - ) ); |
|
276 | + )); |
|
277 | 277 | $line_item = apply_filters( |
278 | 278 | 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
279 | 279 | $line_item |
280 | 280 | ); |
281 | - $events_sub_total->add_child_line_item( $line_item ); |
|
281 | + $events_sub_total->add_child_line_item($line_item); |
|
282 | 282 | //now add the sub-line items |
283 | 283 | $running_total_for_ticket = 0; |
284 | - foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) { |
|
284 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
285 | 285 | $sign = $price->is_discount() ? -1 : 1; |
286 | 286 | $price_total = $price->is_percent() |
287 | 287 | ? $running_total_for_ticket * $price->amount() / 100 |
288 | 288 | : $price->amount() * $qty; |
289 | - $sub_line_item = EE_Line_Item::new_instance( array( |
|
289 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
290 | 290 | 'LIN_name' => $price->name(), |
291 | 291 | 'LIN_desc' => $price->desc(), |
292 | 292 | 'LIN_quantity' => $price->is_percent() ? null : $qty, |
@@ -296,18 +296,18 @@ discard block |
||
296 | 296 | 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
297 | 297 | 'OBJ_ID' => $price->ID(), |
298 | 298 | 'OBJ_type' => 'Price' |
299 | - ) ); |
|
299 | + )); |
|
300 | 300 | $sub_line_item = apply_filters( |
301 | 301 | 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
302 | 302 | $sub_line_item |
303 | 303 | ); |
304 | - if ( $price->is_percent() ) { |
|
305 | - $sub_line_item->set_percent( $sign * $price->amount() ); |
|
304 | + if ($price->is_percent()) { |
|
305 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
306 | 306 | } else { |
307 | - $sub_line_item->set_unit_price( $sign * $price->amount() ); |
|
307 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
308 | 308 | } |
309 | 309 | $running_total_for_ticket += $price_total; |
310 | - $line_item->add_child_line_item( $sub_line_item ); |
|
310 | + $line_item->add_child_line_item($sub_line_item); |
|
311 | 311 | } |
312 | 312 | return $line_item; |
313 | 313 | } |
@@ -327,11 +327,11 @@ discard block |
||
327 | 327 | * @return boolean |
328 | 328 | * @throws \EE_Error |
329 | 329 | */ |
330 | - public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
|
331 | - $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
|
332 | - if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
|
330 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) { |
|
331 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
332 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
333 | 333 | $success = $pre_tax_subtotal->add_child_line_item($item); |
334 | - }else{ |
|
334 | + } else { |
|
335 | 335 | return FALSE; |
336 | 336 | } |
337 | 337 | $total_line_item->recalculate_total_including_taxes(); |
@@ -347,11 +347,11 @@ discard block |
||
347 | 347 | * @return \EE_Line_Item |
348 | 348 | * @throws \EE_Error |
349 | 349 | */ |
350 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
351 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
350 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
351 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
352 | 352 | return $pre_tax_subtotal instanceof EE_Line_Item |
353 | 353 | ? $pre_tax_subtotal |
354 | - : self::create_pre_tax_subtotal( $total_line_item ); |
|
354 | + : self::create_pre_tax_subtotal($total_line_item); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | * @return \EE_Line_Item |
364 | 364 | * @throws \EE_Error |
365 | 365 | */ |
366 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
367 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
368 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
366 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
367 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
368 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | |
@@ -378,12 +378,12 @@ discard block |
||
378 | 378 | * @return void |
379 | 379 | * @throws \EE_Error |
380 | 380 | */ |
381 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
382 | - if( $transaction ){ |
|
381 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
382 | + if ($transaction) { |
|
383 | 383 | /** @type EEM_Transaction $EEM_Transaction */ |
384 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
385 | - $TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
386 | - $line_item->set_TXN_ID( $TXN_ID ); |
|
384 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
385 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
386 | + $line_item->set_TXN_ID($TXN_ID); |
|
387 | 387 | } |
388 | 388 | } |
389 | 389 | |
@@ -398,8 +398,8 @@ discard block |
||
398 | 398 | * @return \EE_Line_Item of type total |
399 | 399 | * @throws \EE_Error |
400 | 400 | */ |
401 | - public static function create_total_line_item( $transaction = NULL ){ |
|
402 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
401 | + public static function create_total_line_item($transaction = NULL) { |
|
402 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
403 | 403 | 'LIN_code' => 'total', |
404 | 404 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
405 | 405 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
410 | 410 | $total_line_item |
411 | 411 | ); |
412 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
413 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
414 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
412 | + self::set_TXN_ID($total_line_item, $transaction); |
|
413 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
414 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
415 | 415 | return $total_line_item; |
416 | 416 | } |
417 | 417 | |
@@ -425,19 +425,19 @@ discard block |
||
425 | 425 | * @return EE_Line_Item |
426 | 426 | * @throws \EE_Error |
427 | 427 | */ |
428 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
429 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
428 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
429 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
430 | 430 | 'LIN_code' => 'pre-tax-subtotal', |
431 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
431 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
432 | 432 | 'LIN_type' => EEM_Line_Item::type_sub_total |
433 | - ) ); |
|
433 | + )); |
|
434 | 434 | $pre_tax_line_item = apply_filters( |
435 | 435 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
436 | 436 | $pre_tax_line_item |
437 | 437 | ); |
438 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
439 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
440 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
438 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
439 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
440 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
441 | 441 | return $pre_tax_line_item; |
442 | 442 | } |
443 | 443 | |
@@ -452,21 +452,21 @@ discard block |
||
452 | 452 | * @return EE_Line_Item |
453 | 453 | * @throws \EE_Error |
454 | 454 | */ |
455 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
455 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
456 | 456 | $tax_line_item = EE_Line_Item::new_instance(array( |
457 | 457 | 'LIN_code' => 'taxes', |
458 | 458 | 'LIN_name' => __('Taxes', 'event_espresso'), |
459 | 459 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
460 | - 'LIN_order' => 1000,//this should always come last |
|
460 | + 'LIN_order' => 1000, //this should always come last |
|
461 | 461 | )); |
462 | 462 | $tax_line_item = apply_filters( |
463 | 463 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
464 | 464 | $tax_line_item |
465 | 465 | ); |
466 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
467 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
466 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
467 | + $total_line_item->add_child_line_item($tax_line_item); |
|
468 | 468 | //and lastly, add the actual taxes |
469 | - self::apply_taxes( $total_line_item ); |
|
469 | + self::apply_taxes($total_line_item); |
|
470 | 470 | return $tax_line_item; |
471 | 471 | } |
472 | 472 | |
@@ -481,11 +481,11 @@ discard block |
||
481 | 481 | * @return EE_Line_Item |
482 | 482 | * @throws \EE_Error |
483 | 483 | */ |
484 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
484 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
485 | 485 | $event_line_item = EE_Line_Item::new_instance(array( |
486 | - 'LIN_code' => self::get_event_code( $event ), |
|
487 | - 'LIN_name' => self::get_event_name( $event ), |
|
488 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
486 | + 'LIN_code' => self::get_event_code($event), |
|
487 | + 'LIN_name' => self::get_event_name($event), |
|
488 | + 'LIN_desc' => self::get_event_desc($event), |
|
489 | 489 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
490 | 490 | 'OBJ_type' => 'Event', |
491 | 491 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -494,8 +494,8 @@ discard block |
||
494 | 494 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
495 | 495 | $event_line_item |
496 | 496 | ); |
497 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
498 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
497 | + self::set_TXN_ID($event_line_item, $transaction); |
|
498 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
499 | 499 | return $event_line_item; |
500 | 500 | } |
501 | 501 | |
@@ -508,8 +508,8 @@ discard block |
||
508 | 508 | * @return string |
509 | 509 | * @throws \EE_Error |
510 | 510 | */ |
511 | - public static function get_event_code( $event ) { |
|
512 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
511 | + public static function get_event_code($event) { |
|
512 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -517,8 +517,8 @@ discard block |
||
517 | 517 | * @param EE_Event $event |
518 | 518 | * @return string |
519 | 519 | */ |
520 | - public static function get_event_name( $event ) { |
|
521 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
520 | + public static function get_event_name($event) { |
|
521 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | * @param EE_Event $event |
527 | 527 | * @return string |
528 | 528 | */ |
529 | - public static function get_event_desc( $event ) { |
|
529 | + public static function get_event_desc($event) { |
|
530 | 530 | return $event instanceof EE_Event ? $event->short_description() : ''; |
531 | 531 | } |
532 | 532 | |
@@ -540,27 +540,27 @@ discard block |
||
540 | 540 | * @throws \EE_Error |
541 | 541 | * @return EE_Line_Item |
542 | 542 | */ |
543 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
543 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
544 | 544 | $first_datetime = $ticket->first_datetime(); |
545 | - if ( ! $first_datetime instanceof EE_Datetime ) { |
|
545 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
546 | 546 | throw new EE_Error( |
547 | - sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) |
|
547 | + sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()) |
|
548 | 548 | ); |
549 | 549 | } |
550 | 550 | $event = $first_datetime->event(); |
551 | - if ( ! $event instanceof EE_Event ) { |
|
551 | + if ( ! $event instanceof EE_Event) { |
|
552 | 552 | throw new EE_Error( |
553 | 553 | sprintf( |
554 | - __( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ), |
|
554 | + __('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), |
|
555 | 555 | $ticket->ID() |
556 | 556 | ) |
557 | 557 | ); |
558 | 558 | } |
559 | - $events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
560 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
559 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
560 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
561 | 561 | throw new EE_Error( |
562 | 562 | sprintf( |
563 | - __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), |
|
563 | + __('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), |
|
564 | 564 | $ticket->ID(), |
565 | 565 | $grand_total->ID() |
566 | 566 | ) |
@@ -579,31 +579,31 @@ discard block |
||
579 | 579 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
580 | 580 | * @throws \EE_Error |
581 | 581 | */ |
582 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
582 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
583 | 583 | /** @type EE_Event $event */ |
584 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
584 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
585 | 585 | $event_line_item = NULL; |
586 | 586 | $found = false; |
587 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
587 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
588 | 588 | // default event subtotal, we should only ever find this the first time this method is called |
589 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
589 | + if ( ! $event_line_item->OBJ_ID()) { |
|
590 | 590 | // let's use this! but first... set the event details |
591 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
591 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
592 | 592 | $found = true; |
593 | 593 | break; |
594 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
594 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
595 | 595 | // found existing line item for this event in the cart, so break out of loop and use this one |
596 | 596 | $found = true; |
597 | 597 | break; |
598 | 598 | } |
599 | 599 | } |
600 | - if ( ! $found ) { |
|
600 | + if ( ! $found) { |
|
601 | 601 | //there is no event sub-total yet, so add it |
602 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
602 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
603 | 603 | // create a new "event" subtotal below that |
604 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
604 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
605 | 605 | // and set the event details |
606 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
606 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
607 | 607 | } |
608 | 608 | return $event_line_item; |
609 | 609 | } |
@@ -624,13 +624,13 @@ discard block |
||
624 | 624 | EE_Event $event, |
625 | 625 | $transaction = null |
626 | 626 | ) { |
627 | - if ( $event instanceof EE_Event ) { |
|
628 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
629 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
630 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
631 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
627 | + if ($event instanceof EE_Event) { |
|
628 | + $event_line_item->set_code(self::get_event_code($event)); |
|
629 | + $event_line_item->set_name(self::get_event_name($event)); |
|
630 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
631 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
632 | 632 | } |
633 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
633 | + self::set_TXN_ID($event_line_item, $transaction); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | |
@@ -643,19 +643,19 @@ discard block |
||
643 | 643 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
644 | 644 | * @throws \EE_Error |
645 | 645 | */ |
646 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
646 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
647 | 647 | /** @type EEM_Price $EEM_Price */ |
648 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
648 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
649 | 649 | // get array of taxes via Price Model |
650 | 650 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
651 | - ksort( $ordered_taxes ); |
|
652 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
651 | + ksort($ordered_taxes); |
|
652 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
653 | 653 | //just to be safe, remove its old tax line items |
654 | 654 | $taxes_line_item->delete_children_line_items(); |
655 | 655 | //loop thru taxes |
656 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
657 | - foreach ( $taxes as $tax ) { |
|
658 | - if ( $tax instanceof EE_Price ) { |
|
656 | + foreach ($ordered_taxes as $order => $taxes) { |
|
657 | + foreach ($taxes as $tax) { |
|
658 | + if ($tax instanceof EE_Price) { |
|
659 | 659 | $tax_line_item = EE_Line_Item::new_instance( |
660 | 660 | array( |
661 | 661 | 'LIN_name' => $tax->name(), |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
674 | 674 | $tax_line_item |
675 | 675 | ); |
676 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
676 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
677 | 677 | } |
678 | 678 | } |
679 | 679 | } |
@@ -690,10 +690,10 @@ discard block |
||
690 | 690 | * @return float |
691 | 691 | * @throws \EE_Error |
692 | 692 | */ |
693 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
694 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
695 | - if( ! $taxes_subtotal->children()){ |
|
696 | - self::apply_taxes( $total_line_item ); |
|
693 | + public static function ensure_taxes_applied($total_line_item) { |
|
694 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
695 | + if ( ! $taxes_subtotal->children()) { |
|
696 | + self::apply_taxes($total_line_item); |
|
697 | 697 | } |
698 | 698 | return $taxes_subtotal->total(); |
699 | 699 | } |
@@ -707,16 +707,16 @@ discard block |
||
707 | 707 | * @return bool |
708 | 708 | * @throws \EE_Error |
709 | 709 | */ |
710 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
710 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
711 | 711 | $deleted = 0; |
712 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
713 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
714 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
715 | - if ( $child_line_item->ID() ) { |
|
712 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
713 | + if ($child_line_item instanceof EE_Line_Item) { |
|
714 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
715 | + if ($child_line_item->ID()) { |
|
716 | 716 | $child_line_item->delete(); |
717 | - unset( $child_line_item ); |
|
717 | + unset($child_line_item); |
|
718 | 718 | } else { |
719 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
719 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
720 | 720 | } |
721 | 721 | $deleted++; |
722 | 722 | } |
@@ -738,9 +738,9 @@ discard block |
||
738 | 738 | * @param array|bool|string $line_item_codes |
739 | 739 | * @return int number of items successfully removed |
740 | 740 | */ |
741 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
741 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
742 | 742 | |
743 | - if( $total_line_item->type() !== EEM_Line_Item::type_total ){ |
|
743 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
744 | 744 | EE_Error::doing_it_wrong( |
745 | 745 | 'EEH_Line_Item::delete_items', |
746 | 746 | __( |
@@ -750,20 +750,20 @@ discard block |
||
750 | 750 | '4.6.18' |
751 | 751 | ); |
752 | 752 | } |
753 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
753 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
754 | 754 | |
755 | 755 | // check if only a single line_item_id was passed |
756 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
756 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
757 | 757 | // place single line_item_id in an array to appear as multiple line_item_ids |
758 | - $line_item_codes = array ( $line_item_codes ); |
|
758 | + $line_item_codes = array($line_item_codes); |
|
759 | 759 | } |
760 | 760 | $removals = 0; |
761 | 761 | // cycle thru line_item_ids |
762 | - foreach ( $line_item_codes as $line_item_id ) { |
|
762 | + foreach ($line_item_codes as $line_item_id) { |
|
763 | 763 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
764 | 764 | } |
765 | 765 | |
766 | - if ( $removals > 0 ) { |
|
766 | + if ($removals > 0) { |
|
767 | 767 | $total_line_item->recalculate_taxes_and_tax_total(); |
768 | 768 | return $removals; |
769 | 769 | } else { |
@@ -796,33 +796,33 @@ discard block |
||
796 | 796 | $code = null, |
797 | 797 | $add_to_existing_line_item = false |
798 | 798 | ) { |
799 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
799 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
800 | 800 | $taxable_total = $total_line_item->taxable_total(); |
801 | 801 | |
802 | - if( $add_to_existing_line_item ) { |
|
803 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
802 | + if ($add_to_existing_line_item) { |
|
803 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
804 | 804 | EEM_Line_Item::instance()->delete( |
805 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
805 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
806 | 806 | ); |
807 | 807 | } else { |
808 | 808 | $new_tax = null; |
809 | 809 | $tax_subtotal->delete_children_line_items(); |
810 | 810 | } |
811 | - if( $new_tax ) { |
|
812 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
813 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
811 | + if ($new_tax) { |
|
812 | + $new_tax->set_total($new_tax->total() + $amount); |
|
813 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
814 | 814 | } else { |
815 | 815 | //no existing tax item. Create it |
816 | - $new_tax = EE_Line_Item::new_instance( array( |
|
816 | + $new_tax = EE_Line_Item::new_instance(array( |
|
817 | 817 | 'TXN_ID' => $total_line_item->TXN_ID(), |
818 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
818 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
819 | 819 | 'LIN_desc' => $description ? $description : '', |
820 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
820 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
821 | 821 | 'LIN_total' => $amount, |
822 | 822 | 'LIN_parent' => $tax_subtotal->ID(), |
823 | 823 | 'LIN_type' => EEM_Line_Item::type_tax, |
824 | 824 | 'LIN_code' => $code |
825 | - ) ); |
|
825 | + )); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | $new_tax = apply_filters( |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | $total_line_item |
832 | 832 | ); |
833 | 833 | $new_tax->save(); |
834 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
834 | + $tax_subtotal->set_total($new_tax->total()); |
|
835 | 835 | $tax_subtotal->save(); |
836 | 836 | $total_line_item->recalculate_total_including_taxes(); |
837 | 837 | return $new_tax; |
@@ -853,14 +853,14 @@ discard block |
||
853 | 853 | $code_substring_for_whitelist = null |
854 | 854 | ) { |
855 | 855 | $whitelisted = false; |
856 | - if( $code_substring_for_whitelist !== null ) { |
|
857 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
856 | + if ($code_substring_for_whitelist !== null) { |
|
857 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
858 | 858 | } |
859 | - if( ! $whitelisted && $line_item->is_line_item() ) { |
|
860 | - $line_item->set_is_taxable( $taxable ); |
|
859 | + if ( ! $whitelisted && $line_item->is_line_item()) { |
|
860 | + $line_item->set_is_taxable($taxable); |
|
861 | 861 | } |
862 | - foreach( $line_item->children() as $child_line_item ) { |
|
863 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
862 | + foreach ($line_item->children() as $child_line_item) { |
|
863 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
864 | 864 | } |
865 | 865 | } |
866 | 866 | |
@@ -873,8 +873,8 @@ discard block |
||
873 | 873 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
874 | 874 | * @return EE_Line_Item[] |
875 | 875 | */ |
876 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
877 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
876 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
877 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
878 | 878 | } |
879 | 879 | |
880 | 880 | |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | * @param string $obj_type |
888 | 888 | * @return EE_Line_Item[] |
889 | 889 | */ |
890 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
890 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
891 | 891 | return self::_get_descendants_by_type_and_object_type( |
892 | 892 | $parent_line_item, |
893 | 893 | EEM_Line_Item::type_sub_total, |
@@ -904,8 +904,8 @@ discard block |
||
904 | 904 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
905 | 905 | * @return EE_Line_Item[] |
906 | 906 | */ |
907 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
908 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
907 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
908 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
909 | 909 | } |
910 | 910 | |
911 | 911 | |
@@ -918,8 +918,8 @@ discard block |
||
918 | 918 | * @param string $obj_type |
919 | 919 | * @return EE_Line_Item[] |
920 | 920 | */ |
921 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
922 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
921 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
922 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
923 | 923 | } |
924 | 924 | |
925 | 925 | |
@@ -930,8 +930,8 @@ discard block |
||
930 | 930 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
931 | 931 | * @return EE_Line_Item[] |
932 | 932 | */ |
933 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
934 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
933 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
934 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
935 | 935 | } |
936 | 936 | |
937 | 937 | |
@@ -942,8 +942,8 @@ discard block |
||
942 | 942 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
943 | 943 | * @return EE_Line_Item[] |
944 | 944 | */ |
945 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
946 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
945 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
946 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | |
@@ -956,8 +956,8 @@ discard block |
||
956 | 956 | * @param string $line_item_type one of the EEM_Line_Item constants |
957 | 957 | * @return EE_Line_Item[] |
958 | 958 | */ |
959 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
960 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
959 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
960 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | |
@@ -976,8 +976,8 @@ discard block |
||
976 | 976 | $obj_type = null |
977 | 977 | ) { |
978 | 978 | $objects = array(); |
979 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
980 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
979 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
980 | + if ($child_line_item instanceof EE_Line_Item) { |
|
981 | 981 | if ( |
982 | 982 | $child_line_item->type() === $line_item_type |
983 | 983 | && ( |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | $OBJ_type = '', |
1018 | 1018 | $OBJ_IDs = array() |
1019 | 1019 | ) { |
1020 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
1020 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | |
@@ -1036,12 +1036,12 @@ discard block |
||
1036 | 1036 | $OBJ_IDs |
1037 | 1037 | ) { |
1038 | 1038 | $objects = array(); |
1039 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1040 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1039 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1040 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1041 | 1041 | if ( |
1042 | - is_array( $OBJ_IDs ) |
|
1042 | + is_array($OBJ_IDs) |
|
1043 | 1043 | && $child_line_item->OBJ_type() === $OBJ_type |
1044 | - && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs ) |
|
1044 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
1045 | 1045 | ) { |
1046 | 1046 | $objects[] = $child_line_item; |
1047 | 1047 | } else { |
@@ -1071,8 +1071,8 @@ discard block |
||
1071 | 1071 | * @param string $type like one of the EEM_Line_Item::type_* |
1072 | 1072 | * @return EE_Line_Item |
1073 | 1073 | */ |
1074 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
1075 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
1074 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
1075 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | 1078 | |
@@ -1086,8 +1086,8 @@ discard block |
||
1086 | 1086 | * @param string $code any value used for LIN_code |
1087 | 1087 | * @return EE_Line_Item |
1088 | 1088 | */ |
1089 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
1090 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
1089 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
1090 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | 1093 | |
@@ -1101,15 +1101,15 @@ discard block |
||
1101 | 1101 | * @param string $value any value stored in $search_field |
1102 | 1102 | * @return EE_Line_Item |
1103 | 1103 | */ |
1104 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
1105 | - foreach( $parent_line_item->children() as $child ){ |
|
1106 | - if ( $child->get( $search_field ) == $value ){ |
|
1104 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
1105 | + foreach ($parent_line_item->children() as $child) { |
|
1106 | + if ($child->get($search_field) == $value) { |
|
1107 | 1107 | return $child; |
1108 | 1108 | } |
1109 | 1109 | } |
1110 | - foreach( $parent_line_item->children() as $child ){ |
|
1111 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
1112 | - if ( $descendant_found ){ |
|
1110 | + foreach ($parent_line_item->children() as $child) { |
|
1111 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
1112 | + if ($descendant_found) { |
|
1113 | 1113 | return $descendant_found; |
1114 | 1114 | } |
1115 | 1115 | } |
@@ -1126,22 +1126,22 @@ discard block |
||
1126 | 1126 | * @return void |
1127 | 1127 | * @throws \EE_Error |
1128 | 1128 | */ |
1129 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
1129 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
1130 | 1130 | echo "\n<br />"; |
1131 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
1131 | + for ($i = 0; $i < $indentation; $i++) { |
|
1132 | 1132 | echo " - "; |
1133 | 1133 | } |
1134 | - if( $line_item->is_percent() ) { |
|
1135 | - $breakdown = $line_item->percent() . '%'; |
|
1134 | + if ($line_item->is_percent()) { |
|
1135 | + $breakdown = $line_item->percent().'%'; |
|
1136 | 1136 | } else { |
1137 | - $breakdown = '$' . $line_item->unit_price() . "x" . $line_item->quantity(); |
|
1137 | + $breakdown = '$'.$line_item->unit_price()."x".$line_item->quantity(); |
|
1138 | 1138 | } |
1139 | - echo $line_item->name() . "( " . $line_item->ID() . " ) : " . $line_item->type() . " $" . $line_item->total() . "(" . $breakdown . ")"; |
|
1140 | - if( $line_item->is_taxable() ){ |
|
1139 | + echo $line_item->name()."( ".$line_item->ID()." ) : ".$line_item->type()." $".$line_item->total()."(".$breakdown.")"; |
|
1140 | + if ($line_item->is_taxable()) { |
|
1141 | 1141 | echo " * taxable"; |
1142 | 1142 | } |
1143 | - if( $line_item->children() ){ |
|
1144 | - foreach($line_item->children() as $child){ |
|
1143 | + if ($line_item->children()) { |
|
1144 | + foreach ($line_item->children() as $child) { |
|
1145 | 1145 | self::visualize($child, $indentation + 1); |
1146 | 1146 | } |
1147 | 1147 | } |
@@ -1182,97 +1182,97 @@ discard block |
||
1182 | 1182 | * is theirs, which can be done with |
1183 | 1183 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
1184 | 1184 | */ |
1185 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
1185 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
1186 | 1186 | //init running grand total if not already |
1187 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
1188 | - $running_totals[ 'total' ] = 0; |
|
1187 | + if ( ! isset($running_totals['total'])) { |
|
1188 | + $running_totals['total'] = 0; |
|
1189 | 1189 | } |
1190 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
1191 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
1190 | + if ( ! isset($running_totals['taxable'])) { |
|
1191 | + $running_totals['taxable'] = array('total' => 0); |
|
1192 | 1192 | } |
1193 | - foreach ( $line_item->children() as $child_line_item ) { |
|
1194 | - switch ( $child_line_item->type() ) { |
|
1193 | + foreach ($line_item->children() as $child_line_item) { |
|
1194 | + switch ($child_line_item->type()) { |
|
1195 | 1195 | |
1196 | 1196 | case EEM_Line_Item::type_sub_total : |
1197 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
1197 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
1198 | 1198 | //combine arrays but preserve numeric keys |
1199 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
1200 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
1201 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
1199 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
1200 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
1201 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
1202 | 1202 | break; |
1203 | 1203 | |
1204 | 1204 | case EEM_Line_Item::type_tax_sub_total : |
1205 | 1205 | |
1206 | 1206 | //find how much the taxes percentage is |
1207 | - if ( $child_line_item->percent() !== 0 ) { |
|
1207 | + if ($child_line_item->percent() !== 0) { |
|
1208 | 1208 | $tax_percent_decimal = $child_line_item->percent() / 100; |
1209 | 1209 | } else { |
1210 | 1210 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
1211 | 1211 | } |
1212 | 1212 | //and apply to all the taxable totals, and add to the pretax totals |
1213 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1213 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1214 | 1214 | //"total" and "taxable" array key is an exception |
1215 | - if ( $line_item_id === 'taxable' ) { |
|
1215 | + if ($line_item_id === 'taxable') { |
|
1216 | 1216 | continue; |
1217 | 1217 | } |
1218 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1219 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
1218 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
1219 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
1220 | 1220 | } |
1221 | 1221 | break; |
1222 | 1222 | |
1223 | 1223 | case EEM_Line_Item::type_line_item : |
1224 | 1224 | |
1225 | 1225 | // ticket line items or ???? |
1226 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
1226 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
1227 | 1227 | // kk it's a ticket |
1228 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
1228 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
1229 | 1229 | //huh? that shouldn't happen. |
1230 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
1230 | + $running_totals['total'] += $child_line_item->total(); |
|
1231 | 1231 | } else { |
1232 | 1232 | //its not in our running totals yet. great. |
1233 | - if ( $child_line_item->is_taxable() ) { |
|
1233 | + if ($child_line_item->is_taxable()) { |
|
1234 | 1234 | $taxable_amount = $child_line_item->unit_price(); |
1235 | 1235 | } else { |
1236 | 1236 | $taxable_amount = 0; |
1237 | 1237 | } |
1238 | 1238 | // are we only calculating totals for some tickets? |
1239 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
1240 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
1241 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
1239 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
1240 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
1241 | + $running_totals[$child_line_item->ID()] = $quantity |
|
1242 | 1242 | ? $child_line_item->unit_price() |
1243 | 1243 | : 0; |
1244 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity |
|
1244 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity |
|
1245 | 1245 | ? $taxable_amount |
1246 | 1246 | : 0; |
1247 | 1247 | } else { |
1248 | 1248 | $quantity = $child_line_item->quantity(); |
1249 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
1250 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
1249 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
1250 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
1251 | 1251 | } |
1252 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
1253 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
1252 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
1253 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
1254 | 1254 | } |
1255 | 1255 | } else { |
1256 | 1256 | // it's some other type of item added to the cart |
1257 | 1257 | // it should affect the running totals |
1258 | 1258 | // basically we want to convert it into a PERCENT modifier. Because |
1259 | 1259 | // more clearly affect all registration's final price equally |
1260 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 |
|
1261 | - ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 |
|
1260 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
1261 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
1262 | 1262 | : 1; |
1263 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1263 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1264 | 1264 | //the "taxable" array key is an exception |
1265 | - if ( $line_item_id === 'taxable' ) { |
|
1265 | + if ($line_item_id === 'taxable') { |
|
1266 | 1266 | continue; |
1267 | 1267 | } |
1268 | 1268 | // update the running totals |
1269 | 1269 | // yes this actually even works for the running grand total! |
1270 | - $running_totals[ $line_item_id ] = |
|
1270 | + $running_totals[$line_item_id] = |
|
1271 | 1271 | $line_items_percent_of_running_total * $this_running_total; |
1272 | 1272 | |
1273 | - if ( $child_line_item->is_taxable() ) { |
|
1274 | - $running_totals[ 'taxable' ][ $line_item_id ] = |
|
1275 | - $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1273 | + if ($child_line_item->is_taxable()) { |
|
1274 | + $running_totals['taxable'][$line_item_id] = |
|
1275 | + $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
1276 | 1276 | } |
1277 | 1277 | } |
1278 | 1278 | } |
@@ -1290,16 +1290,16 @@ discard block |
||
1290 | 1290 | * @return float | null |
1291 | 1291 | * @throws \OutOfRangeException |
1292 | 1292 | */ |
1293 | - public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) { |
|
1293 | + public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) { |
|
1294 | 1294 | static $final_prices_per_ticket_line_item = array(); |
1295 | - if ( empty( $final_prices_per_ticket_line_item ) ) { |
|
1295 | + if (empty($final_prices_per_ticket_line_item)) { |
|
1296 | 1296 | $final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
1297 | 1297 | $total_line_item |
1298 | 1298 | ); |
1299 | 1299 | } |
1300 | 1300 | //ok now find this new registration's final price |
1301 | - if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) { |
|
1302 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
1301 | + if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) { |
|
1302 | + return $final_prices_per_ticket_line_item[$ticket_line_item->ID()]; |
|
1303 | 1303 | } |
1304 | 1304 | $message = sprintf( |
1305 | 1305 | __( |
@@ -1308,10 +1308,10 @@ discard block |
||
1308 | 1308 | ), |
1309 | 1309 | $ticket_line_item->ID() |
1310 | 1310 | ); |
1311 | - if ( WP_DEBUG ) { |
|
1312 | - throw new \OutOfRangeException( $message ); |
|
1311 | + if (WP_DEBUG) { |
|
1312 | + throw new \OutOfRangeException($message); |
|
1313 | 1313 | } else { |
1314 | - EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message ); |
|
1314 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
1315 | 1315 | } |
1316 | 1316 | return null; |
1317 | 1317 | } |
@@ -1327,15 +1327,15 @@ discard block |
||
1327 | 1327 | * @return \EE_Line_Item |
1328 | 1328 | * @throws \EE_Error |
1329 | 1329 | */ |
1330 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
1331 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
1332 | - foreach ( $line_item->children() as $child_li ) { |
|
1333 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
1330 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
1331 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
1332 | + foreach ($line_item->children() as $child_li) { |
|
1333 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
1334 | 1334 | } |
1335 | 1335 | //if this is the grand total line item, make sure the totals all add up |
1336 | 1336 | //(we could have duplicated this logic AS we copied the line items, but |
1337 | 1337 | //it seems DRYer this way) |
1338 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
1338 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
1339 | 1339 | $copy_li->recalculate_total_including_taxes(); |
1340 | 1340 | } |
1341 | 1341 | return $copy_li; |
@@ -1352,24 +1352,24 @@ discard block |
||
1352 | 1352 | * @throws \EE_Error |
1353 | 1353 | * @param EE_Registration[] $registrations |
1354 | 1354 | */ |
1355 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
1355 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
1356 | 1356 | $new_li_fields = $line_item->model_field_array(); |
1357 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1357 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1358 | 1358 | $line_item->OBJ_type() === 'Ticket' |
1359 | 1359 | ) { |
1360 | 1360 | $count = 0; |
1361 | - foreach ( $registrations as $registration ) { |
|
1362 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1363 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
1361 | + foreach ($registrations as $registration) { |
|
1362 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1363 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
1364 | 1364 | ) { |
1365 | 1365 | $count++; |
1366 | 1366 | } |
1367 | 1367 | } |
1368 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
1368 | + $new_li_fields['LIN_quantity'] = $count; |
|
1369 | 1369 | } |
1370 | 1370 | //don't set the total. We'll leave that up to the code that calculates it |
1371 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] ); |
|
1372 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1371 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
1372 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1373 | 1373 | } |
1374 | 1374 | |
1375 | 1375 | |
@@ -1382,19 +1382,19 @@ discard block |
||
1382 | 1382 | * @return \EE_Line_Item|null |
1383 | 1383 | * @throws \EE_Error |
1384 | 1384 | */ |
1385 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
1386 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
1387 | - if ( $copied_li === null ) { |
|
1385 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
1386 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
1387 | + if ($copied_li === null) { |
|
1388 | 1388 | return null; |
1389 | 1389 | } |
1390 | 1390 | //if this is an event subtotal, we want to only include it if it |
1391 | 1391 | //has a non-zero total and at least one ticket line item child |
1392 | 1392 | $ticket_children = 0; |
1393 | - foreach ( $line_item->children() as $child_li ) { |
|
1394 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
1395 | - if ( $child_li_copy !== null ) { |
|
1396 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
1397 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1393 | + foreach ($line_item->children() as $child_li) { |
|
1394 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
1395 | + if ($child_li_copy !== null) { |
|
1396 | + $copied_li->add_child_line_item($child_li_copy); |
|
1397 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1398 | 1398 | $child_li_copy->OBJ_type() === 'Ticket' |
1399 | 1399 | ) { |
1400 | 1400 | $ticket_children++; |
@@ -1424,8 +1424,8 @@ discard block |
||
1424 | 1424 | * @return EE_Line_Item |
1425 | 1425 | * @throws \EE_Error |
1426 | 1426 | */ |
1427 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
1428 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1427 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
1428 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1429 | 1429 | $line_item->OBJ_type() === 'Ticket' && |
1430 | 1430 | $line_item->quantity() === 0 |
1431 | 1431 | ) { |
@@ -1433,8 +1433,8 @@ discard block |
||
1433 | 1433 | } |
1434 | 1434 | $new_li_fields = $line_item->model_field_array(); |
1435 | 1435 | //don't set the total. We'll leave that up to the code that calculates it |
1436 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] ); |
|
1437 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1436 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
1437 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1438 | 1438 | } |
1439 | 1439 | |
1440 | 1440 | |
@@ -1446,9 +1446,9 @@ discard block |
||
1446 | 1446 | * @return \EE_Line_Item |
1447 | 1447 | * @throws \EE_Error |
1448 | 1448 | */ |
1449 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
1450 | - 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' ); |
|
1451 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
1449 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
1450 | + 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'); |
|
1451 | + return self::get_pre_tax_subtotal($total_line_item); |
|
1452 | 1452 | } |
1453 | 1453 | |
1454 | 1454 | |
@@ -1459,9 +1459,9 @@ discard block |
||
1459 | 1459 | * @return \EE_Line_Item |
1460 | 1460 | * @throws \EE_Error |
1461 | 1461 | */ |
1462 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
1463 | - 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' ); |
|
1464 | - return self::create_total_line_item( $transaction ); |
|
1462 | + public static function create_default_total_line_item($transaction = NULL) { |
|
1463 | + 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'); |
|
1464 | + return self::create_total_line_item($transaction); |
|
1465 | 1465 | } |
1466 | 1466 | |
1467 | 1467 | |
@@ -1473,9 +1473,9 @@ discard block |
||
1473 | 1473 | * @return \EE_Line_Item |
1474 | 1474 | * @throws \EE_Error |
1475 | 1475 | */ |
1476 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1477 | - 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' ); |
|
1478 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
1476 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1477 | + 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'); |
|
1478 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
1479 | 1479 | } |
1480 | 1480 | |
1481 | 1481 | |
@@ -1487,9 +1487,9 @@ discard block |
||
1487 | 1487 | * @return \EE_Line_Item |
1488 | 1488 | * @throws \EE_Error |
1489 | 1489 | */ |
1490 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1491 | - 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' ); |
|
1492 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
1490 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1491 | + 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'); |
|
1492 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
1493 | 1493 | } |
1494 | 1494 | |
1495 | 1495 | |
@@ -1501,9 +1501,9 @@ discard block |
||
1501 | 1501 | * @return \EE_Line_Item |
1502 | 1502 | * @throws \EE_Error |
1503 | 1503 | */ |
1504 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1505 | - 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' ); |
|
1506 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
1504 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1505 | + 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'); |
|
1506 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
1507 | 1507 | } |
1508 | 1508 | |
1509 | 1509 |
@@ -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 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | /** |
57 | 57 | * Prepares an array of field values FOR use in JSON/REST API |
58 | - * @param type $field_obj |
|
58 | + * @param \EE_Model_Field_Base $field_obj |
|
59 | 59 | * @param type $original_value_maybe_array |
60 | 60 | * @param string $request_version (eg 4.8.36) |
61 | 61 | * @return array |
@@ -97,6 +97,7 @@ discard block |
||
97 | 97 | * Prepares a field's value for display in the API |
98 | 98 | * @param \EE_Model_Field_Base $field_obj |
99 | 99 | * @param mixed $original_value |
100 | + * @param string $requested_version |
|
100 | 101 | * @return mixed |
101 | 102 | */ |
102 | 103 | public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) { |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
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 | |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | * @param string $requested_version |
42 | 42 | * @return mixed |
43 | 43 | */ |
44 | - public static function prepare_field_values_from_json( $field_obj, $original_value_maybe_array, $requested_version ) { |
|
45 | - if( is_array( $original_value_maybe_array ) ) { |
|
44 | + public static function prepare_field_values_from_json($field_obj, $original_value_maybe_array, $requested_version) { |
|
45 | + if (is_array($original_value_maybe_array)) { |
|
46 | 46 | $new_value_maybe_array = array(); |
47 | - foreach( $original_value_maybe_array as $array_key => $array_item ) { |
|
48 | - $new_value_maybe_array[ $array_key ] = Model_Data_Translator::prepare_field_value_from_json( $field_obj, $array_item, $requested_version ); |
|
47 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
48 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json($field_obj, $array_item, $requested_version); |
|
49 | 49 | } |
50 | 50 | } else { |
51 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json( $field_obj, $original_value_maybe_array, $requested_version ); |
|
51 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json($field_obj, $original_value_maybe_array, $requested_version); |
|
52 | 52 | } |
53 | 53 | return $new_value_maybe_array; |
54 | 54 | } |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | * @param string $request_version (eg 4.8.36) |
61 | 61 | * @return array |
62 | 62 | */ |
63 | - public static function prepare_field_values_for_json( $field_obj, $original_value_maybe_array, $request_version ){ |
|
64 | - if( is_array( $original_value_maybe_array ) ) { |
|
63 | + public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version) { |
|
64 | + if (is_array($original_value_maybe_array)) { |
|
65 | 65 | $new_value_maybe_array = array(); |
66 | - foreach( $original_value_maybe_array as $array_key => $array_item ) { |
|
67 | - $new_value_maybe_array[ $array_key ] = Model_Data_Translator::prepare_field_value_for_json( $field_obj, $array_item, $request_version ); |
|
66 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
67 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json($field_obj, $array_item, $request_version); |
|
68 | 68 | } |
69 | 69 | } else { |
70 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json( $field_obj, $original_value_maybe_array, $request_version ); |
|
70 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json($field_obj, $original_value_maybe_array, $request_version); |
|
71 | 71 | } |
72 | 72 | return $new_value_maybe_array; |
73 | 73 | } |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | * @param string $requested_version |
81 | 81 | * @return mixed |
82 | 82 | */ |
83 | - public static function prepare_field_value_from_json( $field_obj, $original_value, $requested_version ) { |
|
83 | + public static function prepare_field_value_from_json($field_obj, $original_value, $requested_version) { |
|
84 | 84 | $new_value = null; |
85 | - if( $field_obj instanceof \EE_Infinite_Integer_Field |
|
86 | - && in_array( $original_value, array( null, '' ), true ) ) { |
|
85 | + if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
86 | + && in_array($original_value, array(null, ''), true)) { |
|
87 | 87 | $new_value = EE_INF; |
88 | - } elseif( $field_obj instanceof \EE_Datetime_Field ) { |
|
89 | - $new_value = rest_parse_date( $original_value ); |
|
88 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
89 | + $new_value = rest_parse_date($original_value); |
|
90 | 90 | } else { |
91 | 91 | $new_value = $original_value; |
92 | 92 | } |
@@ -99,22 +99,22 @@ discard block |
||
99 | 99 | * @param mixed $original_value |
100 | 100 | * @return mixed |
101 | 101 | */ |
102 | - public static function prepare_field_value_for_json( $field_obj, $original_value, $requested_version ) { |
|
103 | - if( $original_value === EE_INF ) { |
|
102 | + public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) { |
|
103 | + if ($original_value === EE_INF) { |
|
104 | 104 | $new_value = Model_Data_Translator::ee_inf_in_rest; |
105 | - } elseif( $field_obj instanceof \EE_Datetime_Field ) { |
|
106 | - if( $original_value instanceof \DateTime ) { |
|
107 | - $new_value = $original_value->format( 'Y-m-d H:i:s' ); |
|
108 | - } elseif( is_int( $original_value ) ) { |
|
109 | - $new_value = date( 'Y-m-d H:i:s', $original_value ); |
|
105 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
106 | + if ($original_value instanceof \DateTime) { |
|
107 | + $new_value = $original_value->format('Y-m-d H:i:s'); |
|
108 | + } elseif (is_int($original_value)) { |
|
109 | + $new_value = date('Y-m-d H:i:s', $original_value); |
|
110 | 110 | } else { |
111 | 111 | $new_value = $original_value; |
112 | 112 | } |
113 | - $new_value = mysql_to_rfc3339( $new_value ); |
|
113 | + $new_value = mysql_to_rfc3339($new_value); |
|
114 | 114 | } else { |
115 | 115 | $new_value = $original_value; |
116 | 116 | } |
117 | - return apply_filters( 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
117 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
118 | 118 | $new_value, |
119 | 119 | $field_obj, |
120 | 120 | $original_value, |
@@ -134,29 +134,29 @@ discard block |
||
134 | 134 | * @return array |
135 | 135 | * @throws \EE_Error |
136 | 136 | */ |
137 | - public static function prepare_conditions_query_params_for_models( $inputted_query_params_of_this_type, \EEM_Base $model, $requested_version ) { |
|
137 | + public static function prepare_conditions_query_params_for_models($inputted_query_params_of_this_type, \EEM_Base $model, $requested_version) { |
|
138 | 138 | $query_param_for_models = array(); |
139 | - foreach( $inputted_query_params_of_this_type as $query_param_key => $query_param_value ) { |
|
139 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
140 | 140 | $field = Model_Data_Translator::deduce_field_from_query_param( |
141 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key( $query_param_key ), |
|
141 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
142 | 142 | $model |
143 | 143 | ); |
144 | - if( $field instanceof \EE_Model_Field_Base ) { |
|
144 | + if ($field instanceof \EE_Model_Field_Base) { |
|
145 | 145 | //did they specify an operator? |
146 | - if( is_array( $query_param_value ) ) { |
|
147 | - $op = $query_param_value[ 0 ]; |
|
148 | - $translated_value = array( $op ); |
|
149 | - if( isset( $query_param_value[ 1 ] ) ) { |
|
150 | - $value = $query_param_value[ 1 ]; |
|
151 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json( $field, $value, $requested_version ); |
|
146 | + if (is_array($query_param_value)) { |
|
147 | + $op = $query_param_value[0]; |
|
148 | + $translated_value = array($op); |
|
149 | + if (isset($query_param_value[1])) { |
|
150 | + $value = $query_param_value[1]; |
|
151 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value, $requested_version); |
|
152 | 152 | } |
153 | 153 | } else { |
154 | - $translated_value = Model_Data_Translator::prepare_field_value_from_json( $field, $query_param_value, $requested_version ); |
|
154 | + $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value, $requested_version); |
|
155 | 155 | } |
156 | - $query_param_for_models[ $query_param_key ] = $translated_value; |
|
156 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
157 | 157 | } else { |
158 | 158 | //so it's not for a field, assume it's a logic query param key |
159 | - $query_param_for_models[ $query_param_key ] = Model_Data_Translator::prepare_conditions_query_params_for_models( $query_param_value, $model, $requested_version ); |
|
159 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value, $model, $requested_version); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | return $query_param_for_models; |
@@ -171,27 +171,27 @@ discard block |
||
171 | 171 | * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 REST API |
172 | 172 | * @return array which can be passed into the EE4 REST API when querying a model resource |
173 | 173 | */ |
174 | - public static function prepare_query_params_for_rest_api( $model_query_params, \EEM_Base $model, $requested_version = null ) { |
|
175 | - if( $requested_version === null ) { |
|
176 | - $requested_version = \EED_Core_Rest_Api::latest_rest_api_version() ; |
|
174 | + public static function prepare_query_params_for_rest_api($model_query_params, \EEM_Base $model, $requested_version = null) { |
|
175 | + if ($requested_version === null) { |
|
176 | + $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
177 | 177 | } |
178 | 178 | $rest_query_params = $model_query_params; |
179 | - if ( isset( $model_query_params[0] ) ) { |
|
180 | - $rest_query_params[ 'where' ] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
181 | - $model_query_params[ 0 ], |
|
179 | + if (isset($model_query_params[0])) { |
|
180 | + $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
181 | + $model_query_params[0], |
|
182 | 182 | $model, |
183 | 183 | $requested_version |
184 | 184 | ); |
185 | - unset( $rest_query_params[0] ); |
|
185 | + unset($rest_query_params[0]); |
|
186 | 186 | } |
187 | - if ( isset( $model_query_params[ 'having' ] ) ) { |
|
188 | - $rest_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
189 | - $model_query_params[ 'having' ], |
|
187 | + if (isset($model_query_params['having'])) { |
|
188 | + $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
189 | + $model_query_params['having'], |
|
190 | 190 | $model, |
191 | 191 | $requested_version |
192 | 192 | ); |
193 | 193 | } |
194 | - return apply_filters( 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', $rest_query_params, $model_query_params, $model, $requested_version ); |
|
194 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', $rest_query_params, $model_query_params, $model, $requested_version); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -201,29 +201,29 @@ discard block |
||
201 | 201 | * @param string $requested_version eg "4.8.36" |
202 | 202 | * @return array ready for use in the rest api query params |
203 | 203 | */ |
204 | - public static function prepare_conditions_query_params_for_rest_api( $inputted_query_params_of_this_type, \EEM_Base $model, $requested_version ) { |
|
204 | + public static function prepare_conditions_query_params_for_rest_api($inputted_query_params_of_this_type, \EEM_Base $model, $requested_version) { |
|
205 | 205 | $query_param_for_models = array(); |
206 | - foreach( $inputted_query_params_of_this_type as $query_param_key => $query_param_value ) { |
|
206 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
207 | 207 | $field = Model_Data_Translator::deduce_field_from_query_param( |
208 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key( $query_param_key ), |
|
208 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
209 | 209 | $model |
210 | 210 | ); |
211 | - if( $field instanceof \EE_Model_Field_Base ) { |
|
211 | + if ($field instanceof \EE_Model_Field_Base) { |
|
212 | 212 | //did they specify an operator? |
213 | - if( is_array( $query_param_value ) ) { |
|
214 | - $op = $query_param_value[ 0 ]; |
|
215 | - $translated_value = array( $op ); |
|
216 | - if( isset( $query_param_value[ 1 ] ) ) { |
|
217 | - $value = $query_param_value[ 1 ]; |
|
218 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json( $field, $value, $requested_version ); |
|
213 | + if (is_array($query_param_value)) { |
|
214 | + $op = $query_param_value[0]; |
|
215 | + $translated_value = array($op); |
|
216 | + if (isset($query_param_value[1])) { |
|
217 | + $value = $query_param_value[1]; |
|
218 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value, $requested_version); |
|
219 | 219 | } |
220 | 220 | } else { |
221 | - $translated_value = Model_Data_Translator::prepare_field_value_for_json( $field, $query_param_value, $requested_version ); |
|
221 | + $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value, $requested_version); |
|
222 | 222 | } |
223 | - $query_param_for_models[ $query_param_key ] = $translated_value; |
|
223 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
224 | 224 | } else { |
225 | 225 | //so it's not for a field, assume it's a logic query param key |
226 | - $query_param_for_models[ $query_param_key ] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( $query_param_value, $model, $requested_version ); |
|
226 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value, $model, $requested_version); |
|
227 | 227 | } |
228 | 228 | } |
229 | 229 | return $query_param_for_models; |
@@ -235,11 +235,11 @@ discard block |
||
235 | 235 | * @param $condition_query_param_key |
236 | 236 | * @return string |
237 | 237 | */ |
238 | - public static function remove_stars_and_anything_after_from_condition_query_param_key( $condition_query_param_key ) { |
|
238 | + public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) { |
|
239 | 239 | $pos_of_star = strpos($condition_query_param_key, '*'); |
240 | - if($pos_of_star === FALSE){ |
|
240 | + if ($pos_of_star === FALSE) { |
|
241 | 241 | return $condition_query_param_key; |
242 | - }else{ |
|
242 | + } else { |
|
243 | 243 | $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
244 | 244 | return $condition_query_param_sans_star; |
245 | 245 | } |
@@ -255,26 +255,26 @@ discard block |
||
255 | 255 | * @return \EE_Model_Field_Base |
256 | 256 | * @throws \EE_Error |
257 | 257 | */ |
258 | - public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model){ |
|
258 | + public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) { |
|
259 | 259 | //ok, now proceed with deducing which part is the model's name, and which is the field's name |
260 | 260 | //which will help us find the database table and column |
261 | 261 | |
262 | - $query_param_parts = explode(".",$query_param_name); |
|
263 | - if(empty($query_param_parts)){ |
|
264 | - throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name)); |
|
262 | + $query_param_parts = explode(".", $query_param_name); |
|
263 | + if (empty($query_param_parts)) { |
|
264 | + throw new \EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name)); |
|
265 | 265 | } |
266 | 266 | $number_of_parts = count($query_param_parts); |
267 | - $last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ]; |
|
268 | - if($number_of_parts == 1){ |
|
267 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
268 | + if ($number_of_parts == 1) { |
|
269 | 269 | $field_name = $last_query_param_part; |
270 | - }else{// $number_of_parts >= 2 |
|
270 | + } else {// $number_of_parts >= 2 |
|
271 | 271 | //the last part is the column name, and there are only 2parts. therefore... |
272 | 272 | $field_name = $last_query_param_part; |
273 | - $model = \EE_Registry::instance()->load_model( $query_param_parts[ $number_of_parts - 2 ]); |
|
273 | + $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
274 | 274 | } |
275 | - try{ |
|
275 | + try { |
|
276 | 276 | return $model->field_settings_for($field_name); |
277 | - }catch(\EE_Error $e){ |
|
277 | + } catch (\EE_Error $e) { |
|
278 | 278 | return null; |
279 | 279 | } |
280 | 280 | } |
@@ -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; |