@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
| 2 | 2 | /** |
| 3 | 3 | * |
| 4 | 4 | * EEH_Line_Item |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | * @return boolean success |
| 46 | 46 | * @throws \EE_Error |
| 47 | 47 | */ |
| 48 | - public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
|
| 49 | - $items_subtotal = self::get_pre_tax_subtotal( $parent_line_item ); |
|
| 48 | + public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) { |
|
| 49 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
| 50 | 50 | $line_item = EE_Line_Item::new_instance(array( |
| 51 | 51 | 'LIN_name' => $name, |
| 52 | 52 | 'LIN_desc' => $description, |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | 'LIN_quantity' => $quantity, |
| 55 | 55 | 'LIN_percent' => null, |
| 56 | 56 | 'LIN_is_taxable' => $taxable, |
| 57 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0, |
|
| 57 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
| 58 | 58 | 'LIN_total' => (float) $unit_price * (int) $quantity, |
| 59 | 59 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
| 60 | 60 | 'LIN_code' => $code, |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $line_item, |
| 65 | 65 | $parent_line_item |
| 66 | 66 | ); |
| 67 | - return self::add_item( $parent_line_item, $line_item ); |
|
| 67 | + return self::add_item($parent_line_item, $line_item); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return boolean success |
| 87 | 87 | * @throws \EE_Error |
| 88 | 88 | */ |
| 89 | - public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
|
| 89 | + public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) { |
|
| 90 | 90 | $line_item = EE_Line_Item::new_instance(array( |
| 91 | 91 | 'LIN_name' => $name, |
| 92 | 92 | 'LIN_desc' => $description, |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | 'LIN_percent' => $percentage_amount, |
| 95 | 95 | 'LIN_quantity' => NULL, |
| 96 | 96 | 'LIN_is_taxable' => $taxable, |
| 97 | - 'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ), |
|
| 97 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
| 98 | 98 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
| 99 | 99 | 'LIN_parent' => $parent_line_item->ID() |
| 100 | 100 | )); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
| 103 | 103 | $line_item |
| 104 | 104 | ); |
| 105 | - return self::add_item( $parent_line_item, $line_item ); |
|
| 105 | + return self::add_item($parent_line_item, $line_item); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | * @return \EE_Line_Item |
| 124 | 124 | * @throws \EE_Error |
| 125 | 125 | */ |
| 126 | - public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
|
| 127 | - if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) { |
|
| 128 | - throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) ); |
|
| 126 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
| 127 | + if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
| 128 | + throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID())); |
|
| 129 | 129 | } |
| 130 | 130 | // either increment the qty for an existing ticket |
| 131 | - $line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty ); |
|
| 131 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
| 132 | 132 | // or add a new one |
| 133 | - if ( ! $line_item instanceof EE_Line_Item ) { |
|
| 134 | - $line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty ); |
|
| 133 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
| 134 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
| 135 | 135 | } |
| 136 | 136 | $total_line_item->recalculate_total_including_taxes(); |
| 137 | 137 | return $line_item; |
@@ -147,11 +147,11 @@ discard block |
||
| 147 | 147 | * @return \EE_Line_Item |
| 148 | 148 | * @throws \EE_Error |
| 149 | 149 | */ |
| 150 | - public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
| 150 | + public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
| 151 | 151 | $line_item = null; |
| 152 | - if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) { |
|
| 153 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item ); |
|
| 154 | - foreach ( (array)$ticket_line_items as $ticket_line_item ) { |
|
| 152 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
| 153 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 154 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
| 155 | 155 | if ( |
| 156 | 156 | $ticket_line_item instanceof EE_Line_Item |
| 157 | 157 | && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
@@ -161,8 +161,8 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | - if ( $line_item instanceof EE_Line_Item ) { |
|
| 165 | - EEH_Line_Item::increment_quantity( $line_item, $qty ); |
|
| 164 | + if ($line_item instanceof EE_Line_Item) { |
|
| 165 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
| 166 | 166 | return $line_item; |
| 167 | 167 | } |
| 168 | 168 | return null; |
@@ -179,16 +179,16 @@ discard block |
||
| 179 | 179 | * @return void |
| 180 | 180 | * @throws \EE_Error |
| 181 | 181 | */ |
| 182 | - public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
| 183 | - if( ! $line_item->is_percent() ) { |
|
| 182 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
| 183 | + if ( ! $line_item->is_percent()) { |
|
| 184 | 184 | $qty += $line_item->quantity(); |
| 185 | - $line_item->set_quantity( $qty ); |
|
| 186 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
| 185 | + $line_item->set_quantity($qty); |
|
| 186 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
| 187 | 187 | $line_item->save(); |
| 188 | 188 | } |
| 189 | - foreach( $line_item->children() as $child ) { |
|
| 190 | - if( $child->is_sub_line_item() ) { |
|
| 191 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
| 189 | + foreach ($line_item->children() as $child) { |
|
| 190 | + if ($child->is_sub_line_item()) { |
|
| 191 | + EEH_Line_Item::update_quantity($child, $qty); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | } |
@@ -204,17 +204,17 @@ discard block |
||
| 204 | 204 | * @return void |
| 205 | 205 | * @throws \EE_Error |
| 206 | 206 | */ |
| 207 | - public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
| 208 | - if( ! $line_item->is_percent() ) { |
|
| 207 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
| 208 | + if ( ! $line_item->is_percent()) { |
|
| 209 | 209 | $qty = $line_item->quantity() - $qty; |
| 210 | - $qty = max( $qty, 0 ); |
|
| 211 | - $line_item->set_quantity( $qty ); |
|
| 212 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
| 210 | + $qty = max($qty, 0); |
|
| 211 | + $line_item->set_quantity($qty); |
|
| 212 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
| 213 | 213 | $line_item->save(); |
| 214 | 214 | } |
| 215 | - foreach( $line_item->children() as $child ) { |
|
| 216 | - if( $child->is_sub_line_item() ) { |
|
| 217 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
| 215 | + foreach ($line_item->children() as $child) { |
|
| 216 | + if ($child->is_sub_line_item()) { |
|
| 217 | + EEH_Line_Item::update_quantity($child, $qty); |
|
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
| 229 | 229 | * @param int $new_quantity |
| 230 | 230 | * @throws \EE_Error |
| 231 | 231 | */ |
| 232 | - public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
|
| 233 | - if( ! $line_item->is_percent() ) { |
|
| 234 | - $line_item->set_quantity( $new_quantity ); |
|
| 235 | - $line_item->set_total( $line_item->unit_price() * $new_quantity ); |
|
| 232 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) { |
|
| 233 | + if ( ! $line_item->is_percent()) { |
|
| 234 | + $line_item->set_quantity($new_quantity); |
|
| 235 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
| 236 | 236 | $line_item->save(); |
| 237 | 237 | } |
| 238 | - foreach( $line_item->children() as $child ) { |
|
| 239 | - if( $child->is_sub_line_item() ) { |
|
| 240 | - EEH_Line_Item::update_quantity( $child, $new_quantity ); |
|
| 238 | + foreach ($line_item->children() as $child) { |
|
| 239 | + if ($child->is_sub_line_item()) { |
|
| 240 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | } |
@@ -252,43 +252,43 @@ discard block |
||
| 252 | 252 | * @return \EE_Line_Item |
| 253 | 253 | * @throws \EE_Error |
| 254 | 254 | */ |
| 255 | - public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
| 255 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
| 256 | 256 | $datetimes = $ticket->datetimes(); |
| 257 | - $first_datetime = reset( $datetimes ); |
|
| 258 | - if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) { |
|
| 257 | + $first_datetime = reset($datetimes); |
|
| 258 | + if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
| 259 | 259 | $first_datetime_name = $first_datetime->event()->name(); |
| 260 | 260 | } else { |
| 261 | - $first_datetime_name = __( 'Event', 'event_espresso' ); |
|
| 261 | + $first_datetime_name = __('Event', 'event_espresso'); |
|
| 262 | 262 | } |
| 263 | - $event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name ); |
|
| 263 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
| 264 | 264 | // get event subtotal line |
| 265 | - $events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket ); |
|
| 265 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
| 266 | 266 | // add $ticket to cart |
| 267 | - $line_item = EE_Line_Item::new_instance( array( |
|
| 267 | + $line_item = EE_Line_Item::new_instance(array( |
|
| 268 | 268 | 'LIN_name' => $ticket->name(), |
| 269 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
| 269 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description().' '.$event : $event, |
|
| 270 | 270 | 'LIN_unit_price' => $ticket->price(), |
| 271 | 271 | 'LIN_quantity' => $qty, |
| 272 | 272 | 'LIN_is_taxable' => $ticket->taxable(), |
| 273 | - 'LIN_order' => count( $events_sub_total->children() ), |
|
| 273 | + 'LIN_order' => count($events_sub_total->children()), |
|
| 274 | 274 | 'LIN_total' => $ticket->price() * $qty, |
| 275 | 275 | 'LIN_type' => EEM_Line_Item::type_line_item, |
| 276 | 276 | 'OBJ_ID' => $ticket->ID(), |
| 277 | 277 | 'OBJ_type' => 'Ticket' |
| 278 | - ) ); |
|
| 278 | + )); |
|
| 279 | 279 | $line_item = apply_filters( |
| 280 | 280 | 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
| 281 | 281 | $line_item |
| 282 | 282 | ); |
| 283 | - $events_sub_total->add_child_line_item( $line_item ); |
|
| 283 | + $events_sub_total->add_child_line_item($line_item); |
|
| 284 | 284 | //now add the sub-line items |
| 285 | 285 | $running_total_for_ticket = 0; |
| 286 | - foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) { |
|
| 286 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
| 287 | 287 | $sign = $price->is_discount() ? -1 : 1; |
| 288 | 288 | $price_total = $price->is_percent() |
| 289 | 289 | ? $running_total_for_ticket * $price->amount() / 100 |
| 290 | 290 | : $price->amount() * $qty; |
| 291 | - $sub_line_item = EE_Line_Item::new_instance( array( |
|
| 291 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
| 292 | 292 | 'LIN_name' => $price->name(), |
| 293 | 293 | 'LIN_desc' => $price->desc(), |
| 294 | 294 | 'LIN_quantity' => $price->is_percent() ? null : $qty, |
@@ -298,18 +298,18 @@ discard block |
||
| 298 | 298 | 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
| 299 | 299 | 'OBJ_ID' => $price->ID(), |
| 300 | 300 | 'OBJ_type' => 'Price' |
| 301 | - ) ); |
|
| 301 | + )); |
|
| 302 | 302 | $sub_line_item = apply_filters( |
| 303 | 303 | 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
| 304 | 304 | $sub_line_item |
| 305 | 305 | ); |
| 306 | - if ( $price->is_percent() ) { |
|
| 307 | - $sub_line_item->set_percent( $sign * $price->amount() ); |
|
| 306 | + if ($price->is_percent()) { |
|
| 307 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
| 308 | 308 | } else { |
| 309 | - $sub_line_item->set_unit_price( $sign * $price->amount() ); |
|
| 309 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
| 310 | 310 | } |
| 311 | 311 | $running_total_for_ticket += $price_total; |
| 312 | - $line_item->add_child_line_item( $sub_line_item ); |
|
| 312 | + $line_item->add_child_line_item($sub_line_item); |
|
| 313 | 313 | } |
| 314 | 314 | return $line_item; |
| 315 | 315 | } |
@@ -329,11 +329,11 @@ discard block |
||
| 329 | 329 | * @return boolean |
| 330 | 330 | * @throws \EE_Error |
| 331 | 331 | */ |
| 332 | - public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
|
| 333 | - $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
|
| 334 | - if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
|
| 332 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) { |
|
| 333 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
| 334 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
| 335 | 335 | $success = $pre_tax_subtotal->add_child_line_item($item); |
| 336 | - }else{ |
|
| 336 | + } else { |
|
| 337 | 337 | return FALSE; |
| 338 | 338 | } |
| 339 | 339 | $total_line_item->recalculate_total_including_taxes(); |
@@ -352,34 +352,34 @@ discard block |
||
| 352 | 352 | * @return bool success |
| 353 | 353 | * @throws \EE_Error |
| 354 | 354 | */ |
| 355 | - public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
| 355 | + public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
| 356 | 356 | // validate incoming line_item |
| 357 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
| 357 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
| 358 | 358 | throw new EE_Error( |
| 359 | 359 | sprintf( |
| 360 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
| 360 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
| 361 | 361 | $ticket_line_item->type() |
| 362 | 362 | ) |
| 363 | 363 | ); |
| 364 | 364 | } |
| 365 | - if ( $ticket_line_item->quantity() < $qty ) { |
|
| 365 | + if ($ticket_line_item->quantity() < $qty) { |
|
| 366 | 366 | throw new EE_Error( |
| 367 | 367 | sprintf( |
| 368 | - __( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ), |
|
| 368 | + __('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'), |
|
| 369 | 369 | $qty, |
| 370 | 370 | $ticket_line_item->quantity() |
| 371 | 371 | ) |
| 372 | 372 | ); |
| 373 | 373 | } |
| 374 | 374 | // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
| 375 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty ); |
|
| 376 | - foreach( $ticket_line_item->children() as $child_line_item ) { |
|
| 377 | - if( |
|
| 375 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
| 376 | + foreach ($ticket_line_item->children() as $child_line_item) { |
|
| 377 | + if ( |
|
| 378 | 378 | $child_line_item->is_sub_line_item() |
| 379 | 379 | && ! $child_line_item->is_percent() |
| 380 | 380 | && ! $child_line_item->is_cancellation() |
| 381 | 381 | ) { |
| 382 | - $child_line_item->set_quantity( $child_line_item->quantity() - $qty ); |
|
| 382 | + $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | // get cancellation sub line item |
@@ -387,37 +387,37 @@ discard block |
||
| 387 | 387 | $ticket_line_item, |
| 388 | 388 | EEM_Line_Item::type_cancellation |
| 389 | 389 | ); |
| 390 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
| 390 | + $cancellation_line_item = reset($cancellation_line_item); |
|
| 391 | 391 | // verify that this ticket was indeed previously cancelled |
| 392 | - if ( $cancellation_line_item instanceof EE_Line_Item ) { |
|
| 392 | + if ($cancellation_line_item instanceof EE_Line_Item) { |
|
| 393 | 393 | // increment cancelled quantity |
| 394 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty ); |
|
| 394 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
| 395 | 395 | } else { |
| 396 | 396 | // create cancellation sub line item |
| 397 | - $cancellation_line_item = EE_Line_Item::new_instance( array( |
|
| 398 | - 'LIN_name' => __( 'Cancellation', 'event_espresso' ), |
|
| 397 | + $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
| 398 | + 'LIN_name' => __('Cancellation', 'event_espresso'), |
|
| 399 | 399 | 'LIN_desc' => sprintf( |
| 400 | - _x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ), |
|
| 400 | + _x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'), |
|
| 401 | 401 | $ticket_line_item->name(), |
| 402 | - current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) |
|
| 402 | + current_time(get_option('date_format').' '.get_option('time_format')) |
|
| 403 | 403 | ), |
| 404 | 404 | 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
| 405 | 405 | 'LIN_quantity' => $qty, |
| 406 | 406 | 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
| 407 | - 'LIN_order' => count( $ticket_line_item->children() ), |
|
| 407 | + 'LIN_order' => count($ticket_line_item->children()), |
|
| 408 | 408 | 'LIN_total' => 0, // $ticket_line_item->unit_price() |
| 409 | 409 | 'LIN_type' => EEM_Line_Item::type_cancellation, |
| 410 | - ) ); |
|
| 411 | - $ticket_line_item->add_child_line_item( $cancellation_line_item ); |
|
| 410 | + )); |
|
| 411 | + $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
| 412 | 412 | } |
| 413 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
| 413 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
| 414 | 414 | // decrement parent line item quantity |
| 415 | 415 | $event_line_item = $ticket_line_item->parent(); |
| 416 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
| 417 | - $event_line_item->set_quantity( $event_line_item->quantity() - $qty ); |
|
| 416 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
| 417 | + $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
| 418 | 418 | $event_line_item->save(); |
| 419 | 419 | } |
| 420 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
| 420 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
| 421 | 421 | return true; |
| 422 | 422 | } |
| 423 | 423 | return false; |
@@ -435,12 +435,12 @@ discard block |
||
| 435 | 435 | * @return bool success |
| 436 | 436 | * @throws \EE_Error |
| 437 | 437 | */ |
| 438 | - public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
| 438 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
| 439 | 439 | // validate incoming line_item |
| 440 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
| 440 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
| 441 | 441 | throw new EE_Error( |
| 442 | 442 | sprintf( |
| 443 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
| 443 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
| 444 | 444 | $ticket_line_item->type() |
| 445 | 445 | ) |
| 446 | 446 | ); |
@@ -450,42 +450,42 @@ discard block |
||
| 450 | 450 | $ticket_line_item, |
| 451 | 451 | EEM_Line_Item::type_cancellation |
| 452 | 452 | ); |
| 453 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
| 453 | + $cancellation_line_item = reset($cancellation_line_item); |
|
| 454 | 454 | // verify that this ticket was indeed previously cancelled |
| 455 | - if ( ! $cancellation_line_item instanceof EE_Line_Item ) { |
|
| 455 | + if ( ! $cancellation_line_item instanceof EE_Line_Item) { |
|
| 456 | 456 | return false; |
| 457 | 457 | } |
| 458 | - if ( $cancellation_line_item->quantity() > $qty ) { |
|
| 458 | + if ($cancellation_line_item->quantity() > $qty) { |
|
| 459 | 459 | // decrement cancelled quantity |
| 460 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
| 461 | - } else if ( $cancellation_line_item->quantity() == $qty ) { |
|
| 460 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
| 461 | + } else if ($cancellation_line_item->quantity() == $qty) { |
|
| 462 | 462 | // decrement cancelled quantity in case anyone still has the object kicking around |
| 463 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
| 463 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
| 464 | 464 | // delete because quantity will end up as 0 |
| 465 | 465 | $cancellation_line_item->delete(); |
| 466 | 466 | // and attempt to destroy the object, |
| 467 | 467 | // even though PHP won't actually destroy it until it needs the memory |
| 468 | - unset( $cancellation_line_item ); |
|
| 468 | + unset($cancellation_line_item); |
|
| 469 | 469 | } else { |
| 470 | 470 | // what ?!?! negative quantity ?!?! |
| 471 | 471 | throw new EE_Error( |
| 472 | 472 | sprintf( |
| 473 | - __( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
| 474 | - 'event_espresso' ), |
|
| 473 | + __('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
| 474 | + 'event_espresso'), |
|
| 475 | 475 | $qty, |
| 476 | 476 | $cancellation_line_item->quantity() |
| 477 | 477 | ) |
| 478 | 478 | ); |
| 479 | 479 | } |
| 480 | 480 | // increment ticket quantity |
| 481 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty ); |
|
| 482 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
| 481 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
| 482 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
| 483 | 483 | // increment parent line item quantity |
| 484 | 484 | $event_line_item = $ticket_line_item->parent(); |
| 485 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
| 486 | - $event_line_item->set_quantity( $event_line_item->quantity() + $qty ); |
|
| 485 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
| 486 | + $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
| 487 | 487 | } |
| 488 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
| 488 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
| 489 | 489 | return true; |
| 490 | 490 | } |
| 491 | 491 | return false; |
@@ -500,8 +500,8 @@ discard block |
||
| 500 | 500 | * @param EE_Line_Item $line_item |
| 501 | 501 | * @return \EE_Line_Item |
| 502 | 502 | */ |
| 503 | - public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){ |
|
| 504 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item ); |
|
| 503 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) { |
|
| 504 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
| 505 | 505 | return $grand_total_line_item->recalculate_total_including_taxes(); |
| 506 | 506 | } |
| 507 | 507 | |
@@ -514,11 +514,11 @@ discard block |
||
| 514 | 514 | * @return \EE_Line_Item |
| 515 | 515 | * @throws \EE_Error |
| 516 | 516 | */ |
| 517 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
| 518 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
| 517 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
| 518 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
| 519 | 519 | return $pre_tax_subtotal instanceof EE_Line_Item |
| 520 | 520 | ? $pre_tax_subtotal |
| 521 | - : self::create_pre_tax_subtotal( $total_line_item ); |
|
| 521 | + : self::create_pre_tax_subtotal($total_line_item); |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | |
@@ -530,9 +530,9 @@ discard block |
||
| 530 | 530 | * @return \EE_Line_Item |
| 531 | 531 | * @throws \EE_Error |
| 532 | 532 | */ |
| 533 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
| 534 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
| 535 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
| 533 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
| 534 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
| 535 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | |
@@ -545,12 +545,12 @@ discard block |
||
| 545 | 545 | * @return void |
| 546 | 546 | * @throws \EE_Error |
| 547 | 547 | */ |
| 548 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
| 549 | - if( $transaction ){ |
|
| 548 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
| 549 | + if ($transaction) { |
|
| 550 | 550 | /** @type EEM_Transaction $EEM_Transaction */ |
| 551 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
| 552 | - $TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
| 553 | - $line_item->set_TXN_ID( $TXN_ID ); |
|
| 551 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
| 552 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
| 553 | + $line_item->set_TXN_ID($TXN_ID); |
|
| 554 | 554 | } |
| 555 | 555 | } |
| 556 | 556 | |
@@ -565,8 +565,8 @@ discard block |
||
| 565 | 565 | * @return \EE_Line_Item of type total |
| 566 | 566 | * @throws \EE_Error |
| 567 | 567 | */ |
| 568 | - public static function create_total_line_item( $transaction = NULL ){ |
|
| 569 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
| 568 | + public static function create_total_line_item($transaction = NULL) { |
|
| 569 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
| 570 | 570 | 'LIN_code' => 'total', |
| 571 | 571 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
| 572 | 572 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -576,9 +576,9 @@ discard block |
||
| 576 | 576 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
| 577 | 577 | $total_line_item |
| 578 | 578 | ); |
| 579 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
| 580 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
| 581 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
| 579 | + self::set_TXN_ID($total_line_item, $transaction); |
|
| 580 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 581 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 582 | 582 | return $total_line_item; |
| 583 | 583 | } |
| 584 | 584 | |
@@ -592,19 +592,19 @@ discard block |
||
| 592 | 592 | * @return EE_Line_Item |
| 593 | 593 | * @throws \EE_Error |
| 594 | 594 | */ |
| 595 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
| 596 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
| 595 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 596 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
| 597 | 597 | 'LIN_code' => 'pre-tax-subtotal', |
| 598 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
| 598 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
| 599 | 599 | 'LIN_type' => EEM_Line_Item::type_sub_total |
| 600 | - ) ); |
|
| 600 | + )); |
|
| 601 | 601 | $pre_tax_line_item = apply_filters( |
| 602 | 602 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
| 603 | 603 | $pre_tax_line_item |
| 604 | 604 | ); |
| 605 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
| 606 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
| 607 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
| 605 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
| 606 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
| 607 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
| 608 | 608 | return $pre_tax_line_item; |
| 609 | 609 | } |
| 610 | 610 | |
@@ -619,21 +619,21 @@ discard block |
||
| 619 | 619 | * @return EE_Line_Item |
| 620 | 620 | * @throws \EE_Error |
| 621 | 621 | */ |
| 622 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
| 622 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 623 | 623 | $tax_line_item = EE_Line_Item::new_instance(array( |
| 624 | 624 | 'LIN_code' => 'taxes', |
| 625 | 625 | 'LIN_name' => __('Taxes', 'event_espresso'), |
| 626 | 626 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
| 627 | - 'LIN_order' => 1000,//this should always come last |
|
| 627 | + 'LIN_order' => 1000, //this should always come last |
|
| 628 | 628 | )); |
| 629 | 629 | $tax_line_item = apply_filters( |
| 630 | 630 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
| 631 | 631 | $tax_line_item |
| 632 | 632 | ); |
| 633 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
| 634 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
| 633 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
| 634 | + $total_line_item->add_child_line_item($tax_line_item); |
|
| 635 | 635 | //and lastly, add the actual taxes |
| 636 | - self::apply_taxes( $total_line_item ); |
|
| 636 | + self::apply_taxes($total_line_item); |
|
| 637 | 637 | return $tax_line_item; |
| 638 | 638 | } |
| 639 | 639 | |
@@ -648,11 +648,11 @@ discard block |
||
| 648 | 648 | * @return EE_Line_Item |
| 649 | 649 | * @throws \EE_Error |
| 650 | 650 | */ |
| 651 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
| 651 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
| 652 | 652 | $event_line_item = EE_Line_Item::new_instance(array( |
| 653 | - 'LIN_code' => self::get_event_code( $event ), |
|
| 654 | - 'LIN_name' => self::get_event_name( $event ), |
|
| 655 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
| 653 | + 'LIN_code' => self::get_event_code($event), |
|
| 654 | + 'LIN_name' => self::get_event_name($event), |
|
| 655 | + 'LIN_desc' => self::get_event_desc($event), |
|
| 656 | 656 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
| 657 | 657 | 'OBJ_type' => 'Event', |
| 658 | 658 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -661,8 +661,8 @@ discard block |
||
| 661 | 661 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
| 662 | 662 | $event_line_item |
| 663 | 663 | ); |
| 664 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
| 665 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
| 664 | + self::set_TXN_ID($event_line_item, $transaction); |
|
| 665 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
| 666 | 666 | return $event_line_item; |
| 667 | 667 | } |
| 668 | 668 | |
@@ -675,8 +675,8 @@ discard block |
||
| 675 | 675 | * @return string |
| 676 | 676 | * @throws \EE_Error |
| 677 | 677 | */ |
| 678 | - public static function get_event_code( $event ) { |
|
| 679 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
| 678 | + public static function get_event_code($event) { |
|
| 679 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | /** |
@@ -684,8 +684,8 @@ discard block |
||
| 684 | 684 | * @param EE_Event $event |
| 685 | 685 | * @return string |
| 686 | 686 | */ |
| 687 | - public static function get_event_name( $event ) { |
|
| 688 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
| 687 | + public static function get_event_name($event) { |
|
| 688 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | * @param EE_Event $event |
| 694 | 694 | * @return string |
| 695 | 695 | */ |
| 696 | - public static function get_event_desc( $event ) { |
|
| 696 | + public static function get_event_desc($event) { |
|
| 697 | 697 | return $event instanceof EE_Event ? $event->short_description() : ''; |
| 698 | 698 | } |
| 699 | 699 | |
@@ -707,27 +707,27 @@ discard block |
||
| 707 | 707 | * @throws \EE_Error |
| 708 | 708 | * @return EE_Line_Item |
| 709 | 709 | */ |
| 710 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
| 710 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
| 711 | 711 | $first_datetime = $ticket->first_datetime(); |
| 712 | - if ( ! $first_datetime instanceof EE_Datetime ) { |
|
| 712 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
| 713 | 713 | throw new EE_Error( |
| 714 | - sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) |
|
| 714 | + sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()) |
|
| 715 | 715 | ); |
| 716 | 716 | } |
| 717 | 717 | $event = $first_datetime->event(); |
| 718 | - if ( ! $event instanceof EE_Event ) { |
|
| 718 | + if ( ! $event instanceof EE_Event) { |
|
| 719 | 719 | throw new EE_Error( |
| 720 | 720 | sprintf( |
| 721 | - __( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ), |
|
| 721 | + __('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), |
|
| 722 | 722 | $ticket->ID() |
| 723 | 723 | ) |
| 724 | 724 | ); |
| 725 | 725 | } |
| 726 | - $events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
| 727 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
| 726 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
| 727 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
| 728 | 728 | throw new EE_Error( |
| 729 | 729 | sprintf( |
| 730 | - __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), |
|
| 730 | + __('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), |
|
| 731 | 731 | $ticket->ID(), |
| 732 | 732 | $grand_total->ID() |
| 733 | 733 | ) |
@@ -746,31 +746,31 @@ discard block |
||
| 746 | 746 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
| 747 | 747 | * @throws \EE_Error |
| 748 | 748 | */ |
| 749 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
| 749 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
| 750 | 750 | /** @type EE_Event $event */ |
| 751 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
| 751 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
| 752 | 752 | $event_line_item = NULL; |
| 753 | 753 | $found = false; |
| 754 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
| 754 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
| 755 | 755 | // default event subtotal, we should only ever find this the first time this method is called |
| 756 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
| 756 | + if ( ! $event_line_item->OBJ_ID()) { |
|
| 757 | 757 | // let's use this! but first... set the event details |
| 758 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
| 758 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 759 | 759 | $found = true; |
| 760 | 760 | break; |
| 761 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
| 761 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
| 762 | 762 | // found existing line item for this event in the cart, so break out of loop and use this one |
| 763 | 763 | $found = true; |
| 764 | 764 | break; |
| 765 | 765 | } |
| 766 | 766 | } |
| 767 | - if ( ! $found ) { |
|
| 767 | + if ( ! $found) { |
|
| 768 | 768 | //there is no event sub-total yet, so add it |
| 769 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
| 769 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
| 770 | 770 | // create a new "event" subtotal below that |
| 771 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
| 771 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
| 772 | 772 | // and set the event details |
| 773 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
| 773 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 774 | 774 | } |
| 775 | 775 | return $event_line_item; |
| 776 | 776 | } |
@@ -791,13 +791,13 @@ discard block |
||
| 791 | 791 | EE_Event $event, |
| 792 | 792 | $transaction = null |
| 793 | 793 | ) { |
| 794 | - if ( $event instanceof EE_Event ) { |
|
| 795 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
| 796 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
| 797 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
| 798 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
| 794 | + if ($event instanceof EE_Event) { |
|
| 795 | + $event_line_item->set_code(self::get_event_code($event)); |
|
| 796 | + $event_line_item->set_name(self::get_event_name($event)); |
|
| 797 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
| 798 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
| 799 | 799 | } |
| 800 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
| 800 | + self::set_TXN_ID($event_line_item, $transaction); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | |
@@ -810,19 +810,19 @@ discard block |
||
| 810 | 810 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
| 811 | 811 | * @throws \EE_Error |
| 812 | 812 | */ |
| 813 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
| 813 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
| 814 | 814 | /** @type EEM_Price $EEM_Price */ |
| 815 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
| 815 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
| 816 | 816 | // get array of taxes via Price Model |
| 817 | 817 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
| 818 | - ksort( $ordered_taxes ); |
|
| 819 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
| 818 | + ksort($ordered_taxes); |
|
| 819 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
| 820 | 820 | //just to be safe, remove its old tax line items |
| 821 | 821 | $taxes_line_item->delete_children_line_items(); |
| 822 | 822 | //loop thru taxes |
| 823 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
| 824 | - foreach ( $taxes as $tax ) { |
|
| 825 | - if ( $tax instanceof EE_Price ) { |
|
| 823 | + foreach ($ordered_taxes as $order => $taxes) { |
|
| 824 | + foreach ($taxes as $tax) { |
|
| 825 | + if ($tax instanceof EE_Price) { |
|
| 826 | 826 | $tax_line_item = EE_Line_Item::new_instance( |
| 827 | 827 | array( |
| 828 | 828 | 'LIN_name' => $tax->name(), |
@@ -840,7 +840,7 @@ discard block |
||
| 840 | 840 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
| 841 | 841 | $tax_line_item |
| 842 | 842 | ); |
| 843 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
| 843 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
| 844 | 844 | } |
| 845 | 845 | } |
| 846 | 846 | } |
@@ -857,10 +857,10 @@ discard block |
||
| 857 | 857 | * @return float |
| 858 | 858 | * @throws \EE_Error |
| 859 | 859 | */ |
| 860 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
| 861 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
| 862 | - if( ! $taxes_subtotal->children()){ |
|
| 863 | - self::apply_taxes( $total_line_item ); |
|
| 860 | + public static function ensure_taxes_applied($total_line_item) { |
|
| 861 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 862 | + if ( ! $taxes_subtotal->children()) { |
|
| 863 | + self::apply_taxes($total_line_item); |
|
| 864 | 864 | } |
| 865 | 865 | return $taxes_subtotal->total(); |
| 866 | 866 | } |
@@ -874,16 +874,16 @@ discard block |
||
| 874 | 874 | * @return bool |
| 875 | 875 | * @throws \EE_Error |
| 876 | 876 | */ |
| 877 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
| 877 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
| 878 | 878 | $deleted = 0; |
| 879 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
| 880 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 881 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
| 882 | - if ( $child_line_item->ID() ) { |
|
| 879 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 880 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 881 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
| 882 | + if ($child_line_item->ID()) { |
|
| 883 | 883 | $child_line_item->delete(); |
| 884 | - unset( $child_line_item ); |
|
| 884 | + unset($child_line_item); |
|
| 885 | 885 | } else { |
| 886 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
| 886 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
| 887 | 887 | } |
| 888 | 888 | $deleted++; |
| 889 | 889 | } |
@@ -905,9 +905,9 @@ discard block |
||
| 905 | 905 | * @param array|bool|string $line_item_codes |
| 906 | 906 | * @return int number of items successfully removed |
| 907 | 907 | */ |
| 908 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
| 908 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
| 909 | 909 | |
| 910 | - if( $total_line_item->type() !== EEM_Line_Item::type_total ){ |
|
| 910 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
| 911 | 911 | EE_Error::doing_it_wrong( |
| 912 | 912 | 'EEH_Line_Item::delete_items', |
| 913 | 913 | __( |
@@ -917,20 +917,20 @@ discard block |
||
| 917 | 917 | '4.6.18' |
| 918 | 918 | ); |
| 919 | 919 | } |
| 920 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 920 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 921 | 921 | |
| 922 | 922 | // check if only a single line_item_id was passed |
| 923 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
| 923 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
| 924 | 924 | // place single line_item_id in an array to appear as multiple line_item_ids |
| 925 | - $line_item_codes = array ( $line_item_codes ); |
|
| 925 | + $line_item_codes = array($line_item_codes); |
|
| 926 | 926 | } |
| 927 | 927 | $removals = 0; |
| 928 | 928 | // cycle thru line_item_ids |
| 929 | - foreach ( $line_item_codes as $line_item_id ) { |
|
| 929 | + foreach ($line_item_codes as $line_item_id) { |
|
| 930 | 930 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
| 931 | 931 | } |
| 932 | 932 | |
| 933 | - if ( $removals > 0 ) { |
|
| 933 | + if ($removals > 0) { |
|
| 934 | 934 | $total_line_item->recalculate_taxes_and_tax_total(); |
| 935 | 935 | return $removals; |
| 936 | 936 | } else { |
@@ -963,33 +963,33 @@ discard block |
||
| 963 | 963 | $code = null, |
| 964 | 964 | $add_to_existing_line_item = false |
| 965 | 965 | ) { |
| 966 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
| 966 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 967 | 967 | $taxable_total = $total_line_item->taxable_total(); |
| 968 | 968 | |
| 969 | - if( $add_to_existing_line_item ) { |
|
| 970 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
| 969 | + if ($add_to_existing_line_item) { |
|
| 970 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
| 971 | 971 | EEM_Line_Item::instance()->delete( |
| 972 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
| 972 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
| 973 | 973 | ); |
| 974 | 974 | } else { |
| 975 | 975 | $new_tax = null; |
| 976 | 976 | $tax_subtotal->delete_children_line_items(); |
| 977 | 977 | } |
| 978 | - if( $new_tax ) { |
|
| 979 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
| 980 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
| 978 | + if ($new_tax) { |
|
| 979 | + $new_tax->set_total($new_tax->total() + $amount); |
|
| 980 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
| 981 | 981 | } else { |
| 982 | 982 | //no existing tax item. Create it |
| 983 | - $new_tax = EE_Line_Item::new_instance( array( |
|
| 983 | + $new_tax = EE_Line_Item::new_instance(array( |
|
| 984 | 984 | 'TXN_ID' => $total_line_item->TXN_ID(), |
| 985 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
| 985 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
| 986 | 986 | 'LIN_desc' => $description ? $description : '', |
| 987 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
| 987 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
| 988 | 988 | 'LIN_total' => $amount, |
| 989 | 989 | 'LIN_parent' => $tax_subtotal->ID(), |
| 990 | 990 | 'LIN_type' => EEM_Line_Item::type_tax, |
| 991 | 991 | 'LIN_code' => $code |
| 992 | - ) ); |
|
| 992 | + )); |
|
| 993 | 993 | } |
| 994 | 994 | |
| 995 | 995 | $new_tax = apply_filters( |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | $total_line_item |
| 999 | 999 | ); |
| 1000 | 1000 | $new_tax->save(); |
| 1001 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
| 1001 | + $tax_subtotal->set_total($new_tax->total()); |
|
| 1002 | 1002 | $tax_subtotal->save(); |
| 1003 | 1003 | $total_line_item->recalculate_total_including_taxes(); |
| 1004 | 1004 | return $new_tax; |
@@ -1020,14 +1020,14 @@ discard block |
||
| 1020 | 1020 | $code_substring_for_whitelist = null |
| 1021 | 1021 | ) { |
| 1022 | 1022 | $whitelisted = false; |
| 1023 | - if( $code_substring_for_whitelist !== null ) { |
|
| 1024 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
| 1023 | + if ($code_substring_for_whitelist !== null) { |
|
| 1024 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
| 1025 | 1025 | } |
| 1026 | - if( ! $whitelisted && $line_item->is_line_item() ) { |
|
| 1027 | - $line_item->set_is_taxable( $taxable ); |
|
| 1026 | + if ( ! $whitelisted && $line_item->is_line_item()) { |
|
| 1027 | + $line_item->set_is_taxable($taxable); |
|
| 1028 | 1028 | } |
| 1029 | - foreach( $line_item->children() as $child_line_item ) { |
|
| 1030 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
| 1029 | + foreach ($line_item->children() as $child_line_item) { |
|
| 1030 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
| 1031 | 1031 | } |
| 1032 | 1032 | } |
| 1033 | 1033 | |
@@ -1040,8 +1040,8 @@ discard block |
||
| 1040 | 1040 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 1041 | 1041 | * @return EE_Line_Item[] |
| 1042 | 1042 | */ |
| 1043 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
| 1044 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
| 1043 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
| 1044 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | * @param string $obj_type |
| 1055 | 1055 | * @return EE_Line_Item[] |
| 1056 | 1056 | */ |
| 1057 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
| 1057 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
| 1058 | 1058 | return self::_get_descendants_by_type_and_object_type( |
| 1059 | 1059 | $parent_line_item, |
| 1060 | 1060 | EEM_Line_Item::type_sub_total, |
@@ -1071,8 +1071,8 @@ discard block |
||
| 1071 | 1071 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 1072 | 1072 | * @return EE_Line_Item[] |
| 1073 | 1073 | */ |
| 1074 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
| 1075 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
| 1074 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
| 1075 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | |
@@ -1085,8 +1085,8 @@ discard block |
||
| 1085 | 1085 | * @param string $obj_type |
| 1086 | 1086 | * @return EE_Line_Item[] |
| 1087 | 1087 | */ |
| 1088 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
| 1089 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
| 1088 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
| 1089 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | |
@@ -1097,8 +1097,8 @@ discard block |
||
| 1097 | 1097 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 1098 | 1098 | * @return EE_Line_Item[] |
| 1099 | 1099 | */ |
| 1100 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
| 1101 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
| 1100 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
| 1101 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | |
@@ -1109,8 +1109,8 @@ discard block |
||
| 1109 | 1109 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 1110 | 1110 | * @return EE_Line_Item[] |
| 1111 | 1111 | */ |
| 1112 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
| 1113 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
| 1112 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
| 1113 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | |
@@ -1123,8 +1123,8 @@ discard block |
||
| 1123 | 1123 | * @param string $line_item_type one of the EEM_Line_Item constants |
| 1124 | 1124 | * @return EE_Line_Item[] |
| 1125 | 1125 | */ |
| 1126 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
| 1127 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
| 1126 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
| 1127 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | 1130 | |
@@ -1143,8 +1143,8 @@ discard block |
||
| 1143 | 1143 | $obj_type = null |
| 1144 | 1144 | ) { |
| 1145 | 1145 | $objects = array(); |
| 1146 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
| 1147 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 1146 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1147 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 1148 | 1148 | if ( |
| 1149 | 1149 | $child_line_item->type() === $line_item_type |
| 1150 | 1150 | && ( |
@@ -1184,7 +1184,7 @@ discard block |
||
| 1184 | 1184 | $OBJ_type = '', |
| 1185 | 1185 | $OBJ_IDs = array() |
| 1186 | 1186 | ) { |
| 1187 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
| 1187 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | |
@@ -1203,12 +1203,12 @@ discard block |
||
| 1203 | 1203 | $OBJ_IDs |
| 1204 | 1204 | ) { |
| 1205 | 1205 | $objects = array(); |
| 1206 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
| 1207 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 1206 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 1207 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 1208 | 1208 | if ( |
| 1209 | 1209 | $child_line_item->OBJ_type() === $OBJ_type |
| 1210 | - && is_array( $OBJ_IDs ) |
|
| 1211 | - && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs ) |
|
| 1210 | + && is_array($OBJ_IDs) |
|
| 1211 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
| 1212 | 1212 | ) { |
| 1213 | 1213 | $objects[] = $child_line_item; |
| 1214 | 1214 | } else { |
@@ -1238,8 +1238,8 @@ discard block |
||
| 1238 | 1238 | * @param string $type like one of the EEM_Line_Item::type_* |
| 1239 | 1239 | * @return EE_Line_Item |
| 1240 | 1240 | */ |
| 1241 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
| 1242 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
| 1241 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
| 1242 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | 1245 | |
@@ -1253,8 +1253,8 @@ discard block |
||
| 1253 | 1253 | * @param string $code any value used for LIN_code |
| 1254 | 1254 | * @return EE_Line_Item |
| 1255 | 1255 | */ |
| 1256 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
| 1257 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
| 1256 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
| 1257 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | |
@@ -1268,15 +1268,15 @@ discard block |
||
| 1268 | 1268 | * @param string $value any value stored in $search_field |
| 1269 | 1269 | * @return EE_Line_Item |
| 1270 | 1270 | */ |
| 1271 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
| 1272 | - foreach( $parent_line_item->children() as $child ){ |
|
| 1273 | - if ( $child->get( $search_field ) == $value ){ |
|
| 1271 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
| 1272 | + foreach ($parent_line_item->children() as $child) { |
|
| 1273 | + if ($child->get($search_field) == $value) { |
|
| 1274 | 1274 | return $child; |
| 1275 | 1275 | } |
| 1276 | 1276 | } |
| 1277 | - foreach( $parent_line_item->children() as $child ){ |
|
| 1278 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
| 1279 | - if ( $descendant_found ){ |
|
| 1277 | + foreach ($parent_line_item->children() as $child) { |
|
| 1278 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
| 1279 | + if ($descendant_found) { |
|
| 1280 | 1280 | return $descendant_found; |
| 1281 | 1281 | } |
| 1282 | 1282 | } |
@@ -1293,24 +1293,24 @@ discard block |
||
| 1293 | 1293 | * @return \EE_Line_Item |
| 1294 | 1294 | * @throws \EE_Error |
| 1295 | 1295 | */ |
| 1296 | - public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){ |
|
| 1297 | - if ( $line_item->TXN_ID() ) { |
|
| 1298 | - $total_line_item = $line_item->transaction()->total_line_item( false ); |
|
| 1299 | - if ( $total_line_item instanceof EE_Line_Item ) { |
|
| 1296 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) { |
|
| 1297 | + if ($line_item->TXN_ID()) { |
|
| 1298 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
| 1299 | + if ($total_line_item instanceof EE_Line_Item) { |
|
| 1300 | 1300 | return $total_line_item; |
| 1301 | 1301 | } |
| 1302 | 1302 | } else { |
| 1303 | 1303 | $line_item_parent = $line_item->parent(); |
| 1304 | - if ( $line_item_parent instanceof EE_Line_Item ) { |
|
| 1305 | - if ( $line_item_parent->is_total() ) { |
|
| 1304 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
| 1305 | + if ($line_item_parent->is_total()) { |
|
| 1306 | 1306 | return $line_item_parent; |
| 1307 | 1307 | } |
| 1308 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent ); |
|
| 1308 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
| 1309 | 1309 | } |
| 1310 | 1310 | } |
| 1311 | 1311 | throw new EE_Error( |
| 1312 | 1312 | sprintf( |
| 1313 | - __( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ), |
|
| 1313 | + __('A valid grand total for line item %1$d was not found.', 'event_espresso'), |
|
| 1314 | 1314 | $line_item->ID() |
| 1315 | 1315 | ) |
| 1316 | 1316 | ); |
@@ -1327,31 +1327,31 @@ discard block |
||
| 1327 | 1327 | * @return void |
| 1328 | 1328 | * @throws \EE_Error |
| 1329 | 1329 | */ |
| 1330 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
| 1330 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
| 1331 | 1331 | echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
| 1332 | - if ( ! $indentation ) { |
|
| 1333 | - echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />'; |
|
| 1332 | + if ( ! $indentation) { |
|
| 1333 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
| 1334 | 1334 | } |
| 1335 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
| 1335 | + for ($i = 0; $i < $indentation; $i++) { |
|
| 1336 | 1336 | echo ". "; |
| 1337 | 1337 | } |
| 1338 | 1338 | $breakdown = ''; |
| 1339 | - if ( $line_item->is_line_item()){ |
|
| 1340 | - if ( $line_item->is_percent() ) { |
|
| 1339 | + if ($line_item->is_line_item()) { |
|
| 1340 | + if ($line_item->is_percent()) { |
|
| 1341 | 1341 | $breakdown = "{$line_item->percent()}%"; |
| 1342 | 1342 | } else { |
| 1343 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
| 1343 | + $breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
| 1344 | 1344 | } |
| 1345 | 1345 | } |
| 1346 | - echo $line_item->name() . " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : " . '$' . "{$line_item->total()}"; |
|
| 1347 | - if ( $breakdown ) { |
|
| 1346 | + echo $line_item->name()." [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ".'$'."{$line_item->total()}"; |
|
| 1347 | + if ($breakdown) { |
|
| 1348 | 1348 | echo " ( {$breakdown} )"; |
| 1349 | 1349 | } |
| 1350 | - if( $line_item->is_taxable() ){ |
|
| 1350 | + if ($line_item->is_taxable()) { |
|
| 1351 | 1351 | echo " * taxable"; |
| 1352 | 1352 | } |
| 1353 | - if( $line_item->children() ){ |
|
| 1354 | - foreach($line_item->children() as $child){ |
|
| 1353 | + if ($line_item->children()) { |
|
| 1354 | + foreach ($line_item->children() as $child) { |
|
| 1355 | 1355 | self::visualize($child, $indentation + 1); |
| 1356 | 1356 | } |
| 1357 | 1357 | } |
@@ -1392,97 +1392,97 @@ discard block |
||
| 1392 | 1392 | * is theirs, which can be done with |
| 1393 | 1393 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
| 1394 | 1394 | */ |
| 1395 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
| 1395 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
| 1396 | 1396 | //init running grand total if not already |
| 1397 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
| 1398 | - $running_totals[ 'total' ] = 0; |
|
| 1397 | + if ( ! isset($running_totals['total'])) { |
|
| 1398 | + $running_totals['total'] = 0; |
|
| 1399 | 1399 | } |
| 1400 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
| 1401 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
| 1400 | + if ( ! isset($running_totals['taxable'])) { |
|
| 1401 | + $running_totals['taxable'] = array('total' => 0); |
|
| 1402 | 1402 | } |
| 1403 | - foreach ( $line_item->children() as $child_line_item ) { |
|
| 1404 | - switch ( $child_line_item->type() ) { |
|
| 1403 | + foreach ($line_item->children() as $child_line_item) { |
|
| 1404 | + switch ($child_line_item->type()) { |
|
| 1405 | 1405 | |
| 1406 | 1406 | case EEM_Line_Item::type_sub_total : |
| 1407 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
| 1407 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
| 1408 | 1408 | //combine arrays but preserve numeric keys |
| 1409 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
| 1410 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
| 1411 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
| 1409 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
| 1410 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
| 1411 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
| 1412 | 1412 | break; |
| 1413 | 1413 | |
| 1414 | 1414 | case EEM_Line_Item::type_tax_sub_total : |
| 1415 | 1415 | |
| 1416 | 1416 | //find how much the taxes percentage is |
| 1417 | - if ( $child_line_item->percent() !== 0 ) { |
|
| 1417 | + if ($child_line_item->percent() !== 0) { |
|
| 1418 | 1418 | $tax_percent_decimal = $child_line_item->percent() / 100; |
| 1419 | 1419 | } else { |
| 1420 | 1420 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
| 1421 | 1421 | } |
| 1422 | 1422 | //and apply to all the taxable totals, and add to the pretax totals |
| 1423 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
| 1423 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1424 | 1424 | //"total" and "taxable" array key is an exception |
| 1425 | - if ( $line_item_id === 'taxable' ) { |
|
| 1425 | + if ($line_item_id === 'taxable') { |
|
| 1426 | 1426 | continue; |
| 1427 | 1427 | } |
| 1428 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
| 1429 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
| 1428 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
| 1429 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
| 1430 | 1430 | } |
| 1431 | 1431 | break; |
| 1432 | 1432 | |
| 1433 | 1433 | case EEM_Line_Item::type_line_item : |
| 1434 | 1434 | |
| 1435 | 1435 | // ticket line items or ???? |
| 1436 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
| 1436 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
| 1437 | 1437 | // kk it's a ticket |
| 1438 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
| 1438 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
| 1439 | 1439 | //huh? that shouldn't happen. |
| 1440 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
| 1440 | + $running_totals['total'] += $child_line_item->total(); |
|
| 1441 | 1441 | } else { |
| 1442 | 1442 | //its not in our running totals yet. great. |
| 1443 | - if ( $child_line_item->is_taxable() ) { |
|
| 1443 | + if ($child_line_item->is_taxable()) { |
|
| 1444 | 1444 | $taxable_amount = $child_line_item->unit_price(); |
| 1445 | 1445 | } else { |
| 1446 | 1446 | $taxable_amount = 0; |
| 1447 | 1447 | } |
| 1448 | 1448 | // are we only calculating totals for some tickets? |
| 1449 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
| 1450 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
| 1451 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
| 1449 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
| 1450 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
| 1451 | + $running_totals[$child_line_item->ID()] = $quantity |
|
| 1452 | 1452 | ? $child_line_item->unit_price() |
| 1453 | 1453 | : 0; |
| 1454 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity |
|
| 1454 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity |
|
| 1455 | 1455 | ? $taxable_amount |
| 1456 | 1456 | : 0; |
| 1457 | 1457 | } else { |
| 1458 | 1458 | $quantity = $child_line_item->quantity(); |
| 1459 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
| 1460 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
| 1459 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
| 1460 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
| 1461 | 1461 | } |
| 1462 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
| 1463 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
| 1462 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
| 1463 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
| 1464 | 1464 | } |
| 1465 | 1465 | } else { |
| 1466 | 1466 | // it's some other type of item added to the cart |
| 1467 | 1467 | // it should affect the running totals |
| 1468 | 1468 | // basically we want to convert it into a PERCENT modifier. Because |
| 1469 | 1469 | // more clearly affect all registration's final price equally |
| 1470 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 |
|
| 1471 | - ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 |
|
| 1470 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
| 1471 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
| 1472 | 1472 | : 1; |
| 1473 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
| 1473 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1474 | 1474 | //the "taxable" array key is an exception |
| 1475 | - if ( $line_item_id === 'taxable' ) { |
|
| 1475 | + if ($line_item_id === 'taxable') { |
|
| 1476 | 1476 | continue; |
| 1477 | 1477 | } |
| 1478 | 1478 | // update the running totals |
| 1479 | 1479 | // yes this actually even works for the running grand total! |
| 1480 | - $running_totals[ $line_item_id ] = |
|
| 1480 | + $running_totals[$line_item_id] = |
|
| 1481 | 1481 | $line_items_percent_of_running_total * $this_running_total; |
| 1482 | 1482 | |
| 1483 | - if ( $child_line_item->is_taxable() ) { |
|
| 1484 | - $running_totals[ 'taxable' ][ $line_item_id ] = |
|
| 1485 | - $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
| 1483 | + if ($child_line_item->is_taxable()) { |
|
| 1484 | + $running_totals['taxable'][$line_item_id] = |
|
| 1485 | + $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
| 1486 | 1486 | } |
| 1487 | 1487 | } |
| 1488 | 1488 | } |
@@ -1500,16 +1500,16 @@ discard block |
||
| 1500 | 1500 | * @return float | null |
| 1501 | 1501 | * @throws \OutOfRangeException |
| 1502 | 1502 | */ |
| 1503 | - public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) { |
|
| 1503 | + public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) { |
|
| 1504 | 1504 | static $final_prices_per_ticket_line_item = array(); |
| 1505 | - if ( empty( $final_prices_per_ticket_line_item ) ) { |
|
| 1505 | + if (empty($final_prices_per_ticket_line_item)) { |
|
| 1506 | 1506 | $final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
| 1507 | 1507 | $total_line_item |
| 1508 | 1508 | ); |
| 1509 | 1509 | } |
| 1510 | 1510 | //ok now find this new registration's final price |
| 1511 | - if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) { |
|
| 1512 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
| 1511 | + if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) { |
|
| 1512 | + return $final_prices_per_ticket_line_item[$ticket_line_item->ID()]; |
|
| 1513 | 1513 | } |
| 1514 | 1514 | $message = sprintf( |
| 1515 | 1515 | __( |
@@ -1518,11 +1518,11 @@ discard block |
||
| 1518 | 1518 | ), |
| 1519 | 1519 | $ticket_line_item->ID() |
| 1520 | 1520 | ); |
| 1521 | - if ( WP_DEBUG ) { |
|
| 1522 | - $message .= '<br>' . print_r( $final_prices_per_ticket_line_item, true ); |
|
| 1523 | - throw new \OutOfRangeException( $message ); |
|
| 1521 | + if (WP_DEBUG) { |
|
| 1522 | + $message .= '<br>'.print_r($final_prices_per_ticket_line_item, true); |
|
| 1523 | + throw new \OutOfRangeException($message); |
|
| 1524 | 1524 | } else { |
| 1525 | - EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message ); |
|
| 1525 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
| 1526 | 1526 | } |
| 1527 | 1527 | return null; |
| 1528 | 1528 | } |
@@ -1538,15 +1538,15 @@ discard block |
||
| 1538 | 1538 | * @return \EE_Line_Item |
| 1539 | 1539 | * @throws \EE_Error |
| 1540 | 1540 | */ |
| 1541 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
| 1542 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
| 1543 | - foreach ( $line_item->children() as $child_li ) { |
|
| 1544 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
| 1541 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
| 1542 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
| 1543 | + foreach ($line_item->children() as $child_li) { |
|
| 1544 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
| 1545 | 1545 | } |
| 1546 | 1546 | //if this is the grand total line item, make sure the totals all add up |
| 1547 | 1547 | //(we could have duplicated this logic AS we copied the line items, but |
| 1548 | 1548 | //it seems DRYer this way) |
| 1549 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
| 1549 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
| 1550 | 1550 | $copy_li->recalculate_total_including_taxes(); |
| 1551 | 1551 | } |
| 1552 | 1552 | return $copy_li; |
@@ -1563,24 +1563,24 @@ discard block |
||
| 1563 | 1563 | * @throws \EE_Error |
| 1564 | 1564 | * @param EE_Registration[] $registrations |
| 1565 | 1565 | */ |
| 1566 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
| 1566 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
| 1567 | 1567 | $new_li_fields = $line_item->model_field_array(); |
| 1568 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1568 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1569 | 1569 | $line_item->OBJ_type() === 'Ticket' |
| 1570 | 1570 | ) { |
| 1571 | 1571 | $count = 0; |
| 1572 | - foreach ( $registrations as $registration ) { |
|
| 1573 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
| 1574 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
| 1572 | + foreach ($registrations as $registration) { |
|
| 1573 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
| 1574 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
| 1575 | 1575 | ) { |
| 1576 | 1576 | $count++; |
| 1577 | 1577 | } |
| 1578 | 1578 | } |
| 1579 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
| 1579 | + $new_li_fields['LIN_quantity'] = $count; |
|
| 1580 | 1580 | } |
| 1581 | 1581 | //don't set the total. We'll leave that up to the code that calculates it |
| 1582 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] ); |
|
| 1583 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
| 1582 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
| 1583 | + return EE_Line_Item::new_instance($new_li_fields); |
|
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | 1586 | |
@@ -1593,19 +1593,19 @@ discard block |
||
| 1593 | 1593 | * @return \EE_Line_Item|null |
| 1594 | 1594 | * @throws \EE_Error |
| 1595 | 1595 | */ |
| 1596 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
| 1597 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
| 1598 | - if ( $copied_li === null ) { |
|
| 1596 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
| 1597 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
| 1598 | + if ($copied_li === null) { |
|
| 1599 | 1599 | return null; |
| 1600 | 1600 | } |
| 1601 | 1601 | //if this is an event subtotal, we want to only include it if it |
| 1602 | 1602 | //has a non-zero total and at least one ticket line item child |
| 1603 | 1603 | $ticket_children = 0; |
| 1604 | - foreach ( $line_item->children() as $child_li ) { |
|
| 1605 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
| 1606 | - if ( $child_li_copy !== null ) { |
|
| 1607 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
| 1608 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
| 1604 | + foreach ($line_item->children() as $child_li) { |
|
| 1605 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
| 1606 | + if ($child_li_copy !== null) { |
|
| 1607 | + $copied_li->add_child_line_item($child_li_copy); |
|
| 1608 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
| 1609 | 1609 | $child_li_copy->OBJ_type() === 'Ticket' |
| 1610 | 1610 | ) { |
| 1611 | 1611 | $ticket_children++; |
@@ -1635,8 +1635,8 @@ discard block |
||
| 1635 | 1635 | * @return EE_Line_Item |
| 1636 | 1636 | * @throws \EE_Error |
| 1637 | 1637 | */ |
| 1638 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
| 1639 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1638 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
| 1639 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1640 | 1640 | $line_item->OBJ_type() === 'Ticket' && |
| 1641 | 1641 | $line_item->quantity() === 0 |
| 1642 | 1642 | ) { |
@@ -1644,8 +1644,8 @@ discard block |
||
| 1644 | 1644 | } |
| 1645 | 1645 | $new_li_fields = $line_item->model_field_array(); |
| 1646 | 1646 | //don't set the total. We'll leave that up to the code that calculates it |
| 1647 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] ); |
|
| 1648 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
| 1647 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
| 1648 | + return EE_Line_Item::new_instance($new_li_fields); |
|
| 1649 | 1649 | } |
| 1650 | 1650 | |
| 1651 | 1651 | |
@@ -1657,9 +1657,9 @@ discard block |
||
| 1657 | 1657 | * @return \EE_Line_Item |
| 1658 | 1658 | * @throws \EE_Error |
| 1659 | 1659 | */ |
| 1660 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
| 1661 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
| 1662 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
| 1660 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
| 1661 | + EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
| 1662 | + return self::get_pre_tax_subtotal($total_line_item); |
|
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | |
@@ -1670,9 +1670,9 @@ discard block |
||
| 1670 | 1670 | * @return \EE_Line_Item |
| 1671 | 1671 | * @throws \EE_Error |
| 1672 | 1672 | */ |
| 1673 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
| 1674 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' ); |
|
| 1675 | - return self::create_total_line_item( $transaction ); |
|
| 1673 | + public static function create_default_total_line_item($transaction = NULL) { |
|
| 1674 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0'); |
|
| 1675 | + return self::create_total_line_item($transaction); |
|
| 1676 | 1676 | } |
| 1677 | 1677 | |
| 1678 | 1678 | |
@@ -1684,9 +1684,9 @@ discard block |
||
| 1684 | 1684 | * @return \EE_Line_Item |
| 1685 | 1685 | * @throws \EE_Error |
| 1686 | 1686 | */ |
| 1687 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1688 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
| 1689 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
| 1687 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1688 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
| 1689 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | 1692 | |
@@ -1698,9 +1698,9 @@ discard block |
||
| 1698 | 1698 | * @return \EE_Line_Item |
| 1699 | 1699 | * @throws \EE_Error |
| 1700 | 1700 | */ |
| 1701 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1702 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' ); |
|
| 1703 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
| 1701 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1702 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0'); |
|
| 1703 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | |
@@ -1712,9 +1712,9 @@ discard block |
||
| 1712 | 1712 | * @return \EE_Line_Item |
| 1713 | 1713 | * @throws \EE_Error |
| 1714 | 1714 | */ |
| 1715 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1716 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' ); |
|
| 1717 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
| 1715 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1716 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0'); |
|
| 1717 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
| 1718 | 1718 | } |
| 1719 | 1719 | |
| 1720 | 1720 | |
@@ -210,8 +210,8 @@ discard block |
||
| 210 | 210 | |
| 211 | 211 | default : |
| 212 | 212 | return $pretty |
| 213 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 214 | - : $this->_date_format . ' ' . $this->_time_format; |
|
| 213 | + ? $this->_pretty_date_format.' '.$this->_pretty_time_format |
|
| 214 | + : $this->_date_format.' '.$this->_time_format; |
|
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | |
@@ -467,7 +467,7 @@ discard block |
||
| 467 | 467 | */ |
| 468 | 468 | protected function _prepare_for_display($DateTime, $schema = false) |
| 469 | 469 | { |
| 470 | - if (! $DateTime instanceof DateTime) { |
|
| 470 | + if ( ! $DateTime instanceof DateTime) { |
|
| 471 | 471 | if ($this->_nullable) { |
| 472 | 472 | return ''; |
| 473 | 473 | } else { |
@@ -502,15 +502,15 @@ discard block |
||
| 502 | 502 | if ($this->_display_timezone()) { |
| 503 | 503 | //must be explicit because schema could equal true. |
| 504 | 504 | if ($schema === 'no_html') { |
| 505 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 505 | + $timezone_string = ' ('.$DateTime->format('T').')'; |
|
| 506 | 506 | } else { |
| 507 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 507 | + $timezone_string = ' <span class="ee_dtt_timezone_string">('.$DateTime->format('T').')</span>'; |
|
| 508 | 508 | } |
| 509 | 509 | } else { |
| 510 | 510 | $timezone_string = ''; |
| 511 | 511 | } |
| 512 | 512 | |
| 513 | - return $DateTime->format($format_string) . $timezone_string; |
|
| 513 | + return $DateTime->format($format_string).$timezone_string; |
|
| 514 | 514 | } else { |
| 515 | 515 | return $DateTime->format($format_string); |
| 516 | 516 | } |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | public function prepare_for_use_in_db($datetime_value) |
| 529 | 529 | { |
| 530 | 530 | //we allow an empty value or DateTime object, but nothing else. |
| 531 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 531 | + if ( ! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 532 | 532 | throw new EE_Error( |
| 533 | 533 | sprintf( |
| 534 | 534 | __( |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | } |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 591 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
| 592 | 592 | // if still no datetime object, then let's just use now |
| 593 | 593 | $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
| 594 | 594 | } |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | } |
| 668 | 668 | //not a unix timestamp. So we will use the set format on this object and set timezone to |
| 669 | 669 | //create the DateTime object. |
| 670 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 670 | + $format = $this->_date_format.' '.$this->_time_format; |
|
| 671 | 671 | try { |
| 672 | 672 | $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
| 673 | 673 | if ($DateTime instanceof DateTime) { |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | $this->_DateTimeZone |
| 677 | 677 | ); |
| 678 | 678 | } |
| 679 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 679 | + if ( ! $DateTime instanceof DbSafeDateTime) { |
|
| 680 | 680 | throw new EE_Error( |
| 681 | 681 | sprintf( |
| 682 | 682 | __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
@@ -15,760 +15,760 @@ |
||
| 15 | 15 | class EE_Datetime_Field extends EE_Model_Field_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 20 | - * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 21 | - * |
|
| 22 | - * @type string unix_timestamp_regex |
|
| 23 | - */ |
|
| 24 | - const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @type string mysql_timestamp_format |
|
| 28 | - */ |
|
| 29 | - const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @type string mysql_date_format |
|
| 33 | - */ |
|
| 34 | - const mysql_date_format = 'Y-m-d'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @type string mysql_time_format |
|
| 38 | - */ |
|
| 39 | - const mysql_time_format = 'H:i:s'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Const for using in the default value. If the field's default is set to this, |
|
| 43 | - * then we will return the time of calling `get_default_value()`, not |
|
| 44 | - * just the current time at construction |
|
| 45 | - */ |
|
| 46 | - const now = 'now'; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * The following properties hold the default formats for date and time. |
|
| 50 | - * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 51 | - * However they can also be overridden later by the set_format() method |
|
| 52 | - * (and corresponding set_date_format, set_time_format methods); |
|
| 53 | - */ |
|
| 54 | - /** |
|
| 55 | - * @type string $_date_format |
|
| 56 | - */ |
|
| 57 | - protected $_date_format = ''; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @type string $_time_format |
|
| 61 | - */ |
|
| 62 | - protected $_time_format = ''; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @type string $_pretty_date_format |
|
| 66 | - */ |
|
| 67 | - protected $_pretty_date_format = ''; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @type string $_pretty_time_format |
|
| 71 | - */ |
|
| 72 | - protected $_pretty_time_format = ''; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @type DateTimeZone $_DateTimeZone |
|
| 76 | - */ |
|
| 77 | - protected $_DateTimeZone; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @type DateTimeZone $_UTC_DateTimeZone |
|
| 81 | - */ |
|
| 82 | - protected $_UTC_DateTimeZone; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @type DateTimeZone $_blog_DateTimeZone |
|
| 86 | - */ |
|
| 87 | - protected $_blog_DateTimeZone; |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 92 | - * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 93 | - * and time returned via getters. |
|
| 94 | - * |
|
| 95 | - * @var mixed (null|string) |
|
| 96 | - */ |
|
| 97 | - protected $_date_time_output; |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * timezone string |
|
| 102 | - * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 103 | - * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 104 | - * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 105 | - * |
|
| 106 | - * @var string |
|
| 107 | - */ |
|
| 108 | - protected $_timezone_string; |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 113 | - * offsets for comparison purposes). |
|
| 114 | - * |
|
| 115 | - * @var int |
|
| 116 | - */ |
|
| 117 | - protected $_blog_offset; |
|
| 118 | - |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param string $table_column |
|
| 123 | - * @param string $nice_name |
|
| 124 | - * @param bool $nullable |
|
| 125 | - * @param string $default_value |
|
| 126 | - * @param string $timezone_string |
|
| 127 | - * @param string $date_format |
|
| 128 | - * @param string $time_format |
|
| 129 | - * @param string $pretty_date_format |
|
| 130 | - * @param string $pretty_time_format |
|
| 131 | - * @throws EE_Error |
|
| 132 | - * @throws InvalidArgumentException |
|
| 133 | - */ |
|
| 134 | - public function __construct( |
|
| 135 | - $table_column, |
|
| 136 | - $nice_name, |
|
| 137 | - $nullable, |
|
| 138 | - $default_value, |
|
| 139 | - $timezone_string = '', |
|
| 140 | - $date_format = '', |
|
| 141 | - $time_format = '', |
|
| 142 | - $pretty_date_format = '', |
|
| 143 | - $pretty_time_format = '' |
|
| 144 | - ) { |
|
| 145 | - |
|
| 146 | - $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 147 | - $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 148 | - $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 149 | - $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 150 | - |
|
| 151 | - parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 152 | - $this->set_timezone($timezone_string); |
|
| 153 | - $this->setSchemaFormat('date-time'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @return DateTimeZone |
|
| 159 | - * @throws \EE_Error |
|
| 160 | - */ |
|
| 161 | - public function get_UTC_DateTimeZone() |
|
| 162 | - { |
|
| 163 | - return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 164 | - ? $this->_UTC_DateTimeZone |
|
| 165 | - : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * @return DateTimeZone |
|
| 171 | - * @throws \EE_Error |
|
| 172 | - */ |
|
| 173 | - public function get_blog_DateTimeZone() |
|
| 174 | - { |
|
| 175 | - return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 176 | - ? $this->_blog_DateTimeZone |
|
| 177 | - : $this->_create_timezone_object_from_timezone_string(''); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 183 | - * |
|
| 184 | - * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 185 | - * timestamp |
|
| 186 | - * @return DateTime |
|
| 187 | - */ |
|
| 188 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 189 | - { |
|
| 190 | - return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 196 | - * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 197 | - * |
|
| 198 | - * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 199 | - * @return string The final assembled format string. |
|
| 200 | - */ |
|
| 201 | - protected function _get_date_time_output($pretty = false) |
|
| 202 | - { |
|
| 203 | - |
|
| 204 | - switch ($this->_date_time_output) { |
|
| 205 | - case 'time' : |
|
| 206 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 207 | - break; |
|
| 208 | - |
|
| 209 | - case 'date' : |
|
| 210 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 211 | - break; |
|
| 212 | - |
|
| 213 | - default : |
|
| 214 | - return $pretty |
|
| 215 | - ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 216 | - : $this->_date_format . ' ' . $this->_time_format; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 223 | - * returned (using the format properties) |
|
| 224 | - * |
|
| 225 | - * @param string $what acceptable values are 'time' or 'date'. |
|
| 226 | - * Any other value will be set but will always result |
|
| 227 | - * in both 'date' and 'time' being returned. |
|
| 228 | - * @return void |
|
| 229 | - */ |
|
| 230 | - public function set_date_time_output($what = null) |
|
| 231 | - { |
|
| 232 | - $this->_date_time_output = $what; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 238 | - * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 239 | - * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
| 240 | - * We also set some other properties in this method. |
|
| 241 | - * |
|
| 242 | - * @param string $timezone_string A valid timezone string as described by @link |
|
| 243 | - * http://www.php.net/manual/en/timezones.php |
|
| 244 | - * @return void |
|
| 245 | - * @throws \EE_Error |
|
| 246 | - */ |
|
| 247 | - public function set_timezone($timezone_string) |
|
| 248 | - { |
|
| 249 | - if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 250 | - // leave the timezone AS-IS if we already have one and |
|
| 251 | - // the function arg didn't provide one |
|
| 252 | - return; |
|
| 253 | - } |
|
| 254 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 255 | - $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 256 | - $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * _create_timezone_object_from_timezone_name |
|
| 262 | - * |
|
| 263 | - * @access protected |
|
| 264 | - * @param string $timezone_string |
|
| 265 | - * @return \DateTimeZone |
|
| 266 | - * @throws \EE_Error |
|
| 267 | - */ |
|
| 268 | - protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 269 | - { |
|
| 270 | - return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * This just returns whatever is set for the current timezone. |
|
| 276 | - * |
|
| 277 | - * @access public |
|
| 278 | - * @return string timezone string |
|
| 279 | - */ |
|
| 280 | - public function get_timezone() |
|
| 281 | - { |
|
| 282 | - return $this->_timezone_string; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * set the $_date_format property |
|
| 288 | - * |
|
| 289 | - * @access public |
|
| 290 | - * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 291 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 292 | - * @return void |
|
| 293 | - */ |
|
| 294 | - public function set_date_format($format, $pretty = false) |
|
| 295 | - { |
|
| 296 | - if ($pretty) { |
|
| 297 | - $this->_pretty_date_format = $format; |
|
| 298 | - } else { |
|
| 299 | - $this->_date_format = $format; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * return the $_date_format property value. |
|
| 306 | - * |
|
| 307 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 308 | - * @return string |
|
| 309 | - */ |
|
| 310 | - public function get_date_format($pretty = false) |
|
| 311 | - { |
|
| 312 | - return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * set the $_time_format property |
|
| 318 | - * |
|
| 319 | - * @access public |
|
| 320 | - * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 321 | - * @param bool $pretty Whether to set pretty format or not. |
|
| 322 | - * @return void |
|
| 323 | - */ |
|
| 324 | - public function set_time_format($format, $pretty = false) |
|
| 325 | - { |
|
| 326 | - if ($pretty) { |
|
| 327 | - $this->_pretty_time_format = $format; |
|
| 328 | - } else { |
|
| 329 | - $this->_time_format = $format; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * return the $_time_format property value. |
|
| 336 | - * |
|
| 337 | - * @param bool $pretty Whether to get pretty format or not. |
|
| 338 | - * @return string |
|
| 339 | - */ |
|
| 340 | - public function get_time_format($pretty = false) |
|
| 341 | - { |
|
| 342 | - return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * set the $_pretty_date_format property |
|
| 348 | - * |
|
| 349 | - * @access public |
|
| 350 | - * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 351 | - * @return void |
|
| 352 | - */ |
|
| 353 | - public function set_pretty_date_format($format) |
|
| 354 | - { |
|
| 355 | - $this->_pretty_date_format = $format; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * set the $_pretty_time_format property |
|
| 361 | - * |
|
| 362 | - * @access public |
|
| 363 | - * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 364 | - * @return void |
|
| 365 | - */ |
|
| 366 | - public function set_pretty_time_format($format) |
|
| 367 | - { |
|
| 368 | - $this->_pretty_time_format = $format; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Only sets the time portion of the datetime. |
|
| 374 | - * |
|
| 375 | - * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 376 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 377 | - * @return DateTime |
|
| 378 | - */ |
|
| 379 | - public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 380 | - { |
|
| 381 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 382 | - // Otherwise parse the string. |
|
| 383 | - if ($time_to_set_string instanceof DateTime) { |
|
| 384 | - $parsed = array( |
|
| 385 | - 'hour' => $time_to_set_string->format('H'), |
|
| 386 | - 'minute' => $time_to_set_string->format('i'), |
|
| 387 | - 'second' => $time_to_set_string->format('s'), |
|
| 388 | - ); |
|
| 389 | - } else { |
|
| 390 | - //parse incoming string |
|
| 391 | - $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - //make sure $current is in the correct timezone. |
|
| 395 | - $current->setTimezone($this->_DateTimeZone); |
|
| 396 | - |
|
| 397 | - return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * Only sets the date portion of the datetime. |
|
| 403 | - * |
|
| 404 | - * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 405 | - * @param DateTime $current current DateTime object for the datetime field |
|
| 406 | - * @return DateTime |
|
| 407 | - */ |
|
| 408 | - public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 409 | - { |
|
| 410 | - // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 411 | - // Otherwise parse the string. |
|
| 412 | - if ($date_to_set_string instanceof DateTime) { |
|
| 413 | - $parsed = array( |
|
| 414 | - 'year' => $date_to_set_string->format('Y'), |
|
| 415 | - 'month' => $date_to_set_string->format('m'), |
|
| 416 | - 'day' => $date_to_set_string->format('d'), |
|
| 417 | - ); |
|
| 418 | - } else { |
|
| 419 | - //parse incoming string |
|
| 420 | - $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - //make sure $current is in the correct timezone |
|
| 424 | - $current->setTimezone($this->_DateTimeZone); |
|
| 425 | - |
|
| 426 | - return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
| 432 | - * datetime gets to this stage it should ALREADY be in UTC time |
|
| 433 | - * |
|
| 434 | - * @param DateTime $DateTime |
|
| 435 | - * @return string formatted date time for given timezone |
|
| 436 | - * @throws \EE_Error |
|
| 437 | - */ |
|
| 438 | - public function prepare_for_get($DateTime) |
|
| 439 | - { |
|
| 440 | - return $this->_prepare_for_display($DateTime); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
| 446 | - * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
| 447 | - * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
| 448 | - * abbreviation to the date_string. |
|
| 449 | - * |
|
| 450 | - * @param mixed $DateTime |
|
| 451 | - * @param null $schema |
|
| 452 | - * @return string |
|
| 453 | - * @throws \EE_Error |
|
| 454 | - */ |
|
| 455 | - public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 456 | - { |
|
| 457 | - return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 463 | - * timezone). |
|
| 464 | - * |
|
| 465 | - * @param DateTime $DateTime |
|
| 466 | - * @param bool|string $schema |
|
| 467 | - * @return string |
|
| 468 | - * @throws \EE_Error |
|
| 469 | - */ |
|
| 470 | - protected function _prepare_for_display($DateTime, $schema = false) |
|
| 471 | - { |
|
| 472 | - if (! $DateTime instanceof DateTime) { |
|
| 473 | - if ($this->_nullable) { |
|
| 474 | - return ''; |
|
| 475 | - } else { |
|
| 476 | - if (WP_DEBUG) { |
|
| 477 | - throw new EE_Error( |
|
| 478 | - sprintf( |
|
| 479 | - __( |
|
| 480 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 481 | - 'event_espresso' |
|
| 482 | - ), |
|
| 483 | - $this->_nicename |
|
| 484 | - ) |
|
| 485 | - ); |
|
| 486 | - } else { |
|
| 487 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 488 | - EE_Error::add_error( |
|
| 489 | - sprintf( |
|
| 490 | - __( |
|
| 491 | - 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 492 | - 'event_espresso' |
|
| 493 | - ), |
|
| 494 | - $this->_nicename |
|
| 495 | - ) |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - $format_string = $this->_get_date_time_output($schema); |
|
| 501 | - //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 502 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 503 | - if ($schema) { |
|
| 504 | - if ($this->_display_timezone()) { |
|
| 505 | - //must be explicit because schema could equal true. |
|
| 506 | - if ($schema === 'no_html') { |
|
| 507 | - $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 508 | - } else { |
|
| 509 | - $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 510 | - } |
|
| 511 | - } else { |
|
| 512 | - $timezone_string = ''; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - return $DateTime->format($format_string) . $timezone_string; |
|
| 516 | - } else { |
|
| 517 | - return $DateTime->format($format_string); |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 524 | - * timezone). |
|
| 525 | - * |
|
| 526 | - * @param mixed $datetime_value u |
|
| 527 | - * @return string mysql timestamp in UTC |
|
| 528 | - * @throws \EE_Error |
|
| 529 | - */ |
|
| 530 | - public function prepare_for_use_in_db($datetime_value) |
|
| 531 | - { |
|
| 532 | - //we allow an empty value or DateTime object, but nothing else. |
|
| 533 | - if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 534 | - throw new EE_Error( |
|
| 535 | - sprintf( |
|
| 536 | - __( |
|
| 537 | - 'The incoming value being prepared for setting in the database must either be empty or a php |
|
| 18 | + /** |
|
| 19 | + * The pattern we're looking for is if only the characters 0-9 are found and there are only |
|
| 20 | + * 10 or more numbers (because 9 numbers even with all 9's would be sometime in 2001 ) |
|
| 21 | + * |
|
| 22 | + * @type string unix_timestamp_regex |
|
| 23 | + */ |
|
| 24 | + const unix_timestamp_regex = '/[0-9]{10,}/'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @type string mysql_timestamp_format |
|
| 28 | + */ |
|
| 29 | + const mysql_timestamp_format = 'Y-m-d H:i:s'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @type string mysql_date_format |
|
| 33 | + */ |
|
| 34 | + const mysql_date_format = 'Y-m-d'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @type string mysql_time_format |
|
| 38 | + */ |
|
| 39 | + const mysql_time_format = 'H:i:s'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Const for using in the default value. If the field's default is set to this, |
|
| 43 | + * then we will return the time of calling `get_default_value()`, not |
|
| 44 | + * just the current time at construction |
|
| 45 | + */ |
|
| 46 | + const now = 'now'; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * The following properties hold the default formats for date and time. |
|
| 50 | + * Defaults are set via the constructor and can be overridden on class instantiation. |
|
| 51 | + * However they can also be overridden later by the set_format() method |
|
| 52 | + * (and corresponding set_date_format, set_time_format methods); |
|
| 53 | + */ |
|
| 54 | + /** |
|
| 55 | + * @type string $_date_format |
|
| 56 | + */ |
|
| 57 | + protected $_date_format = ''; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @type string $_time_format |
|
| 61 | + */ |
|
| 62 | + protected $_time_format = ''; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @type string $_pretty_date_format |
|
| 66 | + */ |
|
| 67 | + protected $_pretty_date_format = ''; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @type string $_pretty_time_format |
|
| 71 | + */ |
|
| 72 | + protected $_pretty_time_format = ''; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @type DateTimeZone $_DateTimeZone |
|
| 76 | + */ |
|
| 77 | + protected $_DateTimeZone; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @type DateTimeZone $_UTC_DateTimeZone |
|
| 81 | + */ |
|
| 82 | + protected $_UTC_DateTimeZone; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @type DateTimeZone $_blog_DateTimeZone |
|
| 86 | + */ |
|
| 87 | + protected $_blog_DateTimeZone; |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * This property holds how we want the output returned when getting a datetime string. It is set for the |
|
| 92 | + * set_date_time_output() method. By default this is empty. When empty, we are assuming that we want both date |
|
| 93 | + * and time returned via getters. |
|
| 94 | + * |
|
| 95 | + * @var mixed (null|string) |
|
| 96 | + */ |
|
| 97 | + protected $_date_time_output; |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * timezone string |
|
| 102 | + * This gets set by the constructor and can be changed by the "set_timezone()" method so that we know what timezone |
|
| 103 | + * incoming strings|timestamps are in. This can also be used before a get to set what timezone you want strings |
|
| 104 | + * coming out of the object to be in. Default timezone is the current WP timezone option setting |
|
| 105 | + * |
|
| 106 | + * @var string |
|
| 107 | + */ |
|
| 108 | + protected $_timezone_string; |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * This holds whatever UTC offset for the blog (we automatically convert timezone strings into their related |
|
| 113 | + * offsets for comparison purposes). |
|
| 114 | + * |
|
| 115 | + * @var int |
|
| 116 | + */ |
|
| 117 | + protected $_blog_offset; |
|
| 118 | + |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param string $table_column |
|
| 123 | + * @param string $nice_name |
|
| 124 | + * @param bool $nullable |
|
| 125 | + * @param string $default_value |
|
| 126 | + * @param string $timezone_string |
|
| 127 | + * @param string $date_format |
|
| 128 | + * @param string $time_format |
|
| 129 | + * @param string $pretty_date_format |
|
| 130 | + * @param string $pretty_time_format |
|
| 131 | + * @throws EE_Error |
|
| 132 | + * @throws InvalidArgumentException |
|
| 133 | + */ |
|
| 134 | + public function __construct( |
|
| 135 | + $table_column, |
|
| 136 | + $nice_name, |
|
| 137 | + $nullable, |
|
| 138 | + $default_value, |
|
| 139 | + $timezone_string = '', |
|
| 140 | + $date_format = '', |
|
| 141 | + $time_format = '', |
|
| 142 | + $pretty_date_format = '', |
|
| 143 | + $pretty_time_format = '' |
|
| 144 | + ) { |
|
| 145 | + |
|
| 146 | + $this->_date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 147 | + $this->_time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 148 | + $this->_pretty_date_format = ! empty($pretty_date_format) ? $pretty_date_format : get_option('date_format'); |
|
| 149 | + $this->_pretty_time_format = ! empty($pretty_time_format) ? $pretty_time_format : get_option('time_format'); |
|
| 150 | + |
|
| 151 | + parent::__construct($table_column, $nice_name, $nullable, $default_value); |
|
| 152 | + $this->set_timezone($timezone_string); |
|
| 153 | + $this->setSchemaFormat('date-time'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @return DateTimeZone |
|
| 159 | + * @throws \EE_Error |
|
| 160 | + */ |
|
| 161 | + public function get_UTC_DateTimeZone() |
|
| 162 | + { |
|
| 163 | + return $this->_UTC_DateTimeZone instanceof DateTimeZone |
|
| 164 | + ? $this->_UTC_DateTimeZone |
|
| 165 | + : $this->_create_timezone_object_from_timezone_string('UTC'); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * @return DateTimeZone |
|
| 171 | + * @throws \EE_Error |
|
| 172 | + */ |
|
| 173 | + public function get_blog_DateTimeZone() |
|
| 174 | + { |
|
| 175 | + return $this->_blog_DateTimeZone instanceof DateTimeZone |
|
| 176 | + ? $this->_blog_DateTimeZone |
|
| 177 | + : $this->_create_timezone_object_from_timezone_string(''); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * this prepares any incoming date data and make sure its converted to a utc unix timestamp |
|
| 183 | + * |
|
| 184 | + * @param string|int $value_inputted_for_field_on_model_object could be a string formatted date time or int unix |
|
| 185 | + * timestamp |
|
| 186 | + * @return DateTime |
|
| 187 | + */ |
|
| 188 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 189 | + { |
|
| 190 | + return $this->_get_date_object($value_inputted_for_field_on_model_object); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * This returns the format string to be used by getters depending on what the $_date_time_output property is set at. |
|
| 196 | + * getters need to know whether we're just returning the date or the time or both. By default we return both. |
|
| 197 | + * |
|
| 198 | + * @param bool $pretty If we're returning the pretty formats or standard format string. |
|
| 199 | + * @return string The final assembled format string. |
|
| 200 | + */ |
|
| 201 | + protected function _get_date_time_output($pretty = false) |
|
| 202 | + { |
|
| 203 | + |
|
| 204 | + switch ($this->_date_time_output) { |
|
| 205 | + case 'time' : |
|
| 206 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 207 | + break; |
|
| 208 | + |
|
| 209 | + case 'date' : |
|
| 210 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 211 | + break; |
|
| 212 | + |
|
| 213 | + default : |
|
| 214 | + return $pretty |
|
| 215 | + ? $this->_pretty_date_format . ' ' . $this->_pretty_time_format |
|
| 216 | + : $this->_date_format . ' ' . $this->_time_format; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * This just sets the $_date_time_output property so we can flag how date and times are formatted before being |
|
| 223 | + * returned (using the format properties) |
|
| 224 | + * |
|
| 225 | + * @param string $what acceptable values are 'time' or 'date'. |
|
| 226 | + * Any other value will be set but will always result |
|
| 227 | + * in both 'date' and 'time' being returned. |
|
| 228 | + * @return void |
|
| 229 | + */ |
|
| 230 | + public function set_date_time_output($what = null) |
|
| 231 | + { |
|
| 232 | + $this->_date_time_output = $what; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * See $_timezone property for description of what the timezone property is for. This SETS the timezone internally |
|
| 238 | + * for being able to reference what timezone we are running conversions on when converting TO the internal timezone |
|
| 239 | + * (UTC Unix Timestamp) for the object OR when converting FROM the internal timezone (UTC Unix Timestamp). |
|
| 240 | + * We also set some other properties in this method. |
|
| 241 | + * |
|
| 242 | + * @param string $timezone_string A valid timezone string as described by @link |
|
| 243 | + * http://www.php.net/manual/en/timezones.php |
|
| 244 | + * @return void |
|
| 245 | + * @throws \EE_Error |
|
| 246 | + */ |
|
| 247 | + public function set_timezone($timezone_string) |
|
| 248 | + { |
|
| 249 | + if (empty($timezone_string) && $this->_timezone_string !== null) { |
|
| 250 | + // leave the timezone AS-IS if we already have one and |
|
| 251 | + // the function arg didn't provide one |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 255 | + $this->_timezone_string = ! empty($timezone_string) ? $timezone_string : 'UTC'; |
|
| 256 | + $this->_DateTimeZone = $this->_create_timezone_object_from_timezone_string($this->_timezone_string); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * _create_timezone_object_from_timezone_name |
|
| 262 | + * |
|
| 263 | + * @access protected |
|
| 264 | + * @param string $timezone_string |
|
| 265 | + * @return \DateTimeZone |
|
| 266 | + * @throws \EE_Error |
|
| 267 | + */ |
|
| 268 | + protected function _create_timezone_object_from_timezone_string($timezone_string = '') |
|
| 269 | + { |
|
| 270 | + return new DateTimeZone(EEH_DTT_Helper::get_valid_timezone_string($timezone_string)); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * This just returns whatever is set for the current timezone. |
|
| 276 | + * |
|
| 277 | + * @access public |
|
| 278 | + * @return string timezone string |
|
| 279 | + */ |
|
| 280 | + public function get_timezone() |
|
| 281 | + { |
|
| 282 | + return $this->_timezone_string; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * set the $_date_format property |
|
| 288 | + * |
|
| 289 | + * @access public |
|
| 290 | + * @param string $format a new date format (corresponding to formats accepted by PHP date() function) |
|
| 291 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 292 | + * @return void |
|
| 293 | + */ |
|
| 294 | + public function set_date_format($format, $pretty = false) |
|
| 295 | + { |
|
| 296 | + if ($pretty) { |
|
| 297 | + $this->_pretty_date_format = $format; |
|
| 298 | + } else { |
|
| 299 | + $this->_date_format = $format; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * return the $_date_format property value. |
|
| 306 | + * |
|
| 307 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 308 | + * @return string |
|
| 309 | + */ |
|
| 310 | + public function get_date_format($pretty = false) |
|
| 311 | + { |
|
| 312 | + return $pretty ? $this->_pretty_date_format : $this->_date_format; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * set the $_time_format property |
|
| 318 | + * |
|
| 319 | + * @access public |
|
| 320 | + * @param string $format a new time format (corresponding to formats accepted by PHP date() function) |
|
| 321 | + * @param bool $pretty Whether to set pretty format or not. |
|
| 322 | + * @return void |
|
| 323 | + */ |
|
| 324 | + public function set_time_format($format, $pretty = false) |
|
| 325 | + { |
|
| 326 | + if ($pretty) { |
|
| 327 | + $this->_pretty_time_format = $format; |
|
| 328 | + } else { |
|
| 329 | + $this->_time_format = $format; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * return the $_time_format property value. |
|
| 336 | + * |
|
| 337 | + * @param bool $pretty Whether to get pretty format or not. |
|
| 338 | + * @return string |
|
| 339 | + */ |
|
| 340 | + public function get_time_format($pretty = false) |
|
| 341 | + { |
|
| 342 | + return $pretty ? $this->_pretty_time_format : $this->_time_format; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * set the $_pretty_date_format property |
|
| 348 | + * |
|
| 349 | + * @access public |
|
| 350 | + * @param string $format a new pretty date format (corresponding to formats accepted by PHP date() function) |
|
| 351 | + * @return void |
|
| 352 | + */ |
|
| 353 | + public function set_pretty_date_format($format) |
|
| 354 | + { |
|
| 355 | + $this->_pretty_date_format = $format; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * set the $_pretty_time_format property |
|
| 361 | + * |
|
| 362 | + * @access public |
|
| 363 | + * @param string $format a new pretty time format (corresponding to formats accepted by PHP date() function) |
|
| 364 | + * @return void |
|
| 365 | + */ |
|
| 366 | + public function set_pretty_time_format($format) |
|
| 367 | + { |
|
| 368 | + $this->_pretty_time_format = $format; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Only sets the time portion of the datetime. |
|
| 374 | + * |
|
| 375 | + * @param string|DateTime $time_to_set_string like 8am OR a DateTime object. |
|
| 376 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 377 | + * @return DateTime |
|
| 378 | + */ |
|
| 379 | + public function prepare_for_set_with_new_time($time_to_set_string, DateTime $current) |
|
| 380 | + { |
|
| 381 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 382 | + // Otherwise parse the string. |
|
| 383 | + if ($time_to_set_string instanceof DateTime) { |
|
| 384 | + $parsed = array( |
|
| 385 | + 'hour' => $time_to_set_string->format('H'), |
|
| 386 | + 'minute' => $time_to_set_string->format('i'), |
|
| 387 | + 'second' => $time_to_set_string->format('s'), |
|
| 388 | + ); |
|
| 389 | + } else { |
|
| 390 | + //parse incoming string |
|
| 391 | + $parsed = date_parse_from_format($this->_time_format, $time_to_set_string); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + //make sure $current is in the correct timezone. |
|
| 395 | + $current->setTimezone($this->_DateTimeZone); |
|
| 396 | + |
|
| 397 | + return $current->setTime($parsed['hour'], $parsed['minute'], $parsed['second']); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * Only sets the date portion of the datetime. |
|
| 403 | + * |
|
| 404 | + * @param string|DateTime $date_to_set_string like Friday, January 8th or a DateTime object. |
|
| 405 | + * @param DateTime $current current DateTime object for the datetime field |
|
| 406 | + * @return DateTime |
|
| 407 | + */ |
|
| 408 | + public function prepare_for_set_with_new_date($date_to_set_string, DateTime $current) |
|
| 409 | + { |
|
| 410 | + // if $time_to_set_string is datetime object, then let's use it to set the parse array. |
|
| 411 | + // Otherwise parse the string. |
|
| 412 | + if ($date_to_set_string instanceof DateTime) { |
|
| 413 | + $parsed = array( |
|
| 414 | + 'year' => $date_to_set_string->format('Y'), |
|
| 415 | + 'month' => $date_to_set_string->format('m'), |
|
| 416 | + 'day' => $date_to_set_string->format('d'), |
|
| 417 | + ); |
|
| 418 | + } else { |
|
| 419 | + //parse incoming string |
|
| 420 | + $parsed = date_parse_from_format($this->_date_format, $date_to_set_string); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + //make sure $current is in the correct timezone |
|
| 424 | + $current->setTimezone($this->_DateTimeZone); |
|
| 425 | + |
|
| 426 | + return $current->setDate($parsed['year'], $parsed['month'], $parsed['day']); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 timezone). When the |
|
| 432 | + * datetime gets to this stage it should ALREADY be in UTC time |
|
| 433 | + * |
|
| 434 | + * @param DateTime $DateTime |
|
| 435 | + * @return string formatted date time for given timezone |
|
| 436 | + * @throws \EE_Error |
|
| 437 | + */ |
|
| 438 | + public function prepare_for_get($DateTime) |
|
| 439 | + { |
|
| 440 | + return $this->_prepare_for_display($DateTime); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * This differs from prepare_for_get in that it considers whether the internal $_timezone differs |
|
| 446 | + * from the set wp timezone. If so, then it returns the datetime string formatted via |
|
| 447 | + * _pretty_date_format, and _pretty_time_format. However, it also appends a timezone |
|
| 448 | + * abbreviation to the date_string. |
|
| 449 | + * |
|
| 450 | + * @param mixed $DateTime |
|
| 451 | + * @param null $schema |
|
| 452 | + * @return string |
|
| 453 | + * @throws \EE_Error |
|
| 454 | + */ |
|
| 455 | + public function prepare_for_pretty_echoing($DateTime, $schema = null) |
|
| 456 | + { |
|
| 457 | + return $this->_prepare_for_display($DateTime, $schema ? $schema : true); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 463 | + * timezone). |
|
| 464 | + * |
|
| 465 | + * @param DateTime $DateTime |
|
| 466 | + * @param bool|string $schema |
|
| 467 | + * @return string |
|
| 468 | + * @throws \EE_Error |
|
| 469 | + */ |
|
| 470 | + protected function _prepare_for_display($DateTime, $schema = false) |
|
| 471 | + { |
|
| 472 | + if (! $DateTime instanceof DateTime) { |
|
| 473 | + if ($this->_nullable) { |
|
| 474 | + return ''; |
|
| 475 | + } else { |
|
| 476 | + if (WP_DEBUG) { |
|
| 477 | + throw new EE_Error( |
|
| 478 | + sprintf( |
|
| 479 | + __( |
|
| 480 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable.', |
|
| 481 | + 'event_espresso' |
|
| 482 | + ), |
|
| 483 | + $this->_nicename |
|
| 484 | + ) |
|
| 485 | + ); |
|
| 486 | + } else { |
|
| 487 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now); |
|
| 488 | + EE_Error::add_error( |
|
| 489 | + sprintf( |
|
| 490 | + __( |
|
| 491 | + 'EE_Datetime_Field::_prepare_for_display requires a DateTime class to be the value for the $DateTime argument because the %s field is not nullable. When WP_DEBUG is false, the value is set to "now" instead of throwing an exception.', |
|
| 492 | + 'event_espresso' |
|
| 493 | + ), |
|
| 494 | + $this->_nicename |
|
| 495 | + ) |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + $format_string = $this->_get_date_time_output($schema); |
|
| 501 | + //make sure datetime_value is in the correct timezone (in case that's been updated). |
|
| 502 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 503 | + if ($schema) { |
|
| 504 | + if ($this->_display_timezone()) { |
|
| 505 | + //must be explicit because schema could equal true. |
|
| 506 | + if ($schema === 'no_html') { |
|
| 507 | + $timezone_string = ' (' . $DateTime->format('T') . ')'; |
|
| 508 | + } else { |
|
| 509 | + $timezone_string = ' <span class="ee_dtt_timezone_string">(' . $DateTime->format('T') . ')</span>'; |
|
| 510 | + } |
|
| 511 | + } else { |
|
| 512 | + $timezone_string = ''; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + return $DateTime->format($format_string) . $timezone_string; |
|
| 516 | + } else { |
|
| 517 | + return $DateTime->format($format_string); |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * This prepares the EE_DateTime value to be saved to the db as mysql timestamp (UTC +0 |
|
| 524 | + * timezone). |
|
| 525 | + * |
|
| 526 | + * @param mixed $datetime_value u |
|
| 527 | + * @return string mysql timestamp in UTC |
|
| 528 | + * @throws \EE_Error |
|
| 529 | + */ |
|
| 530 | + public function prepare_for_use_in_db($datetime_value) |
|
| 531 | + { |
|
| 532 | + //we allow an empty value or DateTime object, but nothing else. |
|
| 533 | + if (! empty($datetime_value) && ! $datetime_value instanceof DateTime) { |
|
| 534 | + throw new EE_Error( |
|
| 535 | + sprintf( |
|
| 536 | + __( |
|
| 537 | + 'The incoming value being prepared for setting in the database must either be empty or a php |
|
| 538 | 538 | DateTime object, instead of: %1$s %2$s', |
| 539 | - 'event_espresso' |
|
| 540 | - ), |
|
| 541 | - '<br />', |
|
| 542 | - print_r($datetime_value, true) |
|
| 543 | - ) |
|
| 544 | - ); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - if ($datetime_value instanceof DateTime) { |
|
| 548 | - if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 549 | - $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 553 | - EE_Datetime_Field::mysql_timestamp_format |
|
| 554 | - ); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 558 | - return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
| 564 | - * allowed) |
|
| 565 | - * |
|
| 566 | - * @param string $datetime_string mysql timestamp in UTC |
|
| 567 | - * @return mixed null | DateTime |
|
| 568 | - * @throws \EE_Error |
|
| 569 | - */ |
|
| 570 | - public function prepare_for_set_from_db($datetime_string) |
|
| 571 | - { |
|
| 572 | - //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 573 | - if (empty($datetime_string) && $this->_nullable) { |
|
| 574 | - return null; |
|
| 575 | - } |
|
| 576 | - // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 577 | - if (empty($datetime_string)) { |
|
| 578 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 579 | - } else { |
|
| 580 | - $DateTime = DateTime::createFromFormat( |
|
| 581 | - EE_Datetime_Field::mysql_timestamp_format, |
|
| 582 | - $datetime_string, |
|
| 583 | - $this->get_UTC_DateTimeZone() |
|
| 584 | - ); |
|
| 585 | - if ($DateTime instanceof \DateTime) { |
|
| 586 | - $DateTime = new DbSafeDateTime( |
|
| 587 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 588 | - $this->get_UTC_DateTimeZone() |
|
| 589 | - ); |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 594 | - // if still no datetime object, then let's just use now |
|
| 595 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 596 | - } |
|
| 597 | - // THEN apply the field's set DateTimeZone |
|
| 598 | - $DateTime->setTimezone($this->_DateTimeZone); |
|
| 599 | - |
|
| 600 | - return $DateTime; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * All this method does is determine if we're going to display the timezone string or not on any output. |
|
| 606 | - * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
| 607 | - * If so, then true. |
|
| 608 | - * |
|
| 609 | - * @return bool true for yes false for no |
|
| 610 | - * @throws \EE_Error |
|
| 611 | - */ |
|
| 612 | - protected function _display_timezone() |
|
| 613 | - { |
|
| 614 | - |
|
| 615 | - // first let's do a comparison of timezone strings. |
|
| 616 | - // If they match then we can get out without any further calculations |
|
| 617 | - $blog_string = get_option('timezone_string'); |
|
| 618 | - if ($blog_string === $this->_timezone_string) { |
|
| 619 | - return false; |
|
| 620 | - } |
|
| 621 | - // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 622 | - $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 623 | - $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 624 | - // now compare |
|
| 625 | - return $blog_offset !== $this_offset; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 631 | - * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 632 | - * with. |
|
| 633 | - * |
|
| 634 | - * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 635 | - * in the format that is set on the date_field (or DateTime |
|
| 636 | - * object)! |
|
| 637 | - * @return DateTime |
|
| 638 | - */ |
|
| 639 | - protected function _get_date_object($date_string) |
|
| 640 | - { |
|
| 641 | - //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 642 | - if ($this->_nullable && empty($date_string)) { |
|
| 643 | - return null; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - // if incoming date |
|
| 647 | - if ($date_string instanceof DateTime) { |
|
| 648 | - $date_string->setTimezone($this->_DateTimeZone); |
|
| 649 | - |
|
| 650 | - return $date_string; |
|
| 651 | - } |
|
| 652 | - // if empty date_string and made it here. |
|
| 653 | - // Return a datetime object for now in the given timezone. |
|
| 654 | - if (empty($date_string)) { |
|
| 655 | - return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 656 | - } |
|
| 657 | - // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 658 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 659 | - try { |
|
| 660 | - // This is operating under the assumption that the incoming Unix timestamp |
|
| 661 | - // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 662 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 663 | - $DateTime->setTimestamp($date_string); |
|
| 664 | - |
|
| 665 | - return $DateTime; |
|
| 666 | - } catch (Exception $e) { |
|
| 667 | - // should be rare, but if things got fooled then let's just continue |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 671 | - //create the DateTime object. |
|
| 672 | - $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 673 | - try { |
|
| 674 | - $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 675 | - if ($DateTime instanceof DateTime) { |
|
| 676 | - $DateTime = new DbSafeDateTime( |
|
| 677 | - $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 678 | - $this->_DateTimeZone |
|
| 679 | - ); |
|
| 680 | - } |
|
| 681 | - if (! $DateTime instanceof DbSafeDateTime) { |
|
| 682 | - throw new EE_Error( |
|
| 683 | - sprintf( |
|
| 684 | - __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 685 | - $date_string, |
|
| 686 | - $format |
|
| 687 | - ) |
|
| 688 | - ); |
|
| 689 | - } |
|
| 690 | - } catch (Exception $e) { |
|
| 691 | - // if we made it here then likely then something went really wrong. |
|
| 692 | - // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 693 | - $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $DateTime; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * get_timezone_transitions |
|
| 703 | - * |
|
| 704 | - * @param \DateTimeZone $DateTimeZone |
|
| 705 | - * @param int $time |
|
| 706 | - * @param bool $first_only |
|
| 707 | - * @return mixed |
|
| 708 | - */ |
|
| 709 | - public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
| 710 | - { |
|
| 711 | - $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 712 | - $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 713 | - $transitions = $DateTimeZone->getTransitions($time); |
|
| 714 | - return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * get_timezone_offset |
|
| 721 | - * |
|
| 722 | - * @param \DateTimeZone $DateTimeZone |
|
| 723 | - * @param int $time |
|
| 724 | - * @return mixed |
|
| 725 | - * @throws \DomainException |
|
| 726 | - */ |
|
| 727 | - public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 728 | - { |
|
| 729 | - $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
| 730 | - if ( ! isset($transitions['offset'])) { |
|
| 731 | - throw new DomainException(); |
|
| 732 | - } |
|
| 733 | - return $transitions['offset']; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * This will take an incoming timezone string and return the abbreviation for that timezone |
|
| 739 | - * |
|
| 740 | - * @param string $timezone_string |
|
| 741 | - * @return string abbreviation |
|
| 742 | - * @throws \EE_Error |
|
| 743 | - */ |
|
| 744 | - public function get_timezone_abbrev($timezone_string) |
|
| 745 | - { |
|
| 746 | - $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 747 | - $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 748 | - |
|
| 749 | - return $dateTime->format('T'); |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - /** |
|
| 753 | - * Overrides the parent to allow for having a dynamic "now" value |
|
| 754 | - * |
|
| 755 | - * @return mixed |
|
| 756 | - */ |
|
| 757 | - public function get_default_value() |
|
| 758 | - { |
|
| 759 | - if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 760 | - return time(); |
|
| 761 | - } else { |
|
| 762 | - return parent::get_default_value(); |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - |
|
| 767 | - public function getSchemaDescription() |
|
| 768 | - { |
|
| 769 | - return sprintf( |
|
| 770 | - esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
| 771 | - $this->get_nicename() |
|
| 772 | - ); |
|
| 773 | - } |
|
| 539 | + 'event_espresso' |
|
| 540 | + ), |
|
| 541 | + '<br />', |
|
| 542 | + print_r($datetime_value, true) |
|
| 543 | + ) |
|
| 544 | + ); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + if ($datetime_value instanceof DateTime) { |
|
| 548 | + if ( ! $datetime_value instanceof DbSafeDateTime) { |
|
| 549 | + $datetime_value = DbSafeDateTime::createFromDateTime($datetime_value); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return $datetime_value->setTimezone($this->get_UTC_DateTimeZone())->format( |
|
| 553 | + EE_Datetime_Field::mysql_timestamp_format |
|
| 554 | + ); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + // if $datetime_value is empty, and ! $this->_nullable, use current_time() but set the GMT flag to true |
|
| 558 | + return ! $this->_nullable && empty($datetime_value) ? current_time('mysql', true) : null; |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * This prepares the datetime for internal usage as a PHP DateTime object OR null (if nullable is |
|
| 564 | + * allowed) |
|
| 565 | + * |
|
| 566 | + * @param string $datetime_string mysql timestamp in UTC |
|
| 567 | + * @return mixed null | DateTime |
|
| 568 | + * @throws \EE_Error |
|
| 569 | + */ |
|
| 570 | + public function prepare_for_set_from_db($datetime_string) |
|
| 571 | + { |
|
| 572 | + //if $datetime_value is empty, and ! $this->_nullable, just use time() |
|
| 573 | + if (empty($datetime_string) && $this->_nullable) { |
|
| 574 | + return null; |
|
| 575 | + } |
|
| 576 | + // datetime strings from the db should ALWAYS be in UTC+0, so use UTC_DateTimeZone when creating |
|
| 577 | + if (empty($datetime_string)) { |
|
| 578 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 579 | + } else { |
|
| 580 | + $DateTime = DateTime::createFromFormat( |
|
| 581 | + EE_Datetime_Field::mysql_timestamp_format, |
|
| 582 | + $datetime_string, |
|
| 583 | + $this->get_UTC_DateTimeZone() |
|
| 584 | + ); |
|
| 585 | + if ($DateTime instanceof \DateTime) { |
|
| 586 | + $DateTime = new DbSafeDateTime( |
|
| 587 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 588 | + $this->get_UTC_DateTimeZone() |
|
| 589 | + ); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
| 594 | + // if still no datetime object, then let's just use now |
|
| 595 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->get_UTC_DateTimeZone()); |
|
| 596 | + } |
|
| 597 | + // THEN apply the field's set DateTimeZone |
|
| 598 | + $DateTime->setTimezone($this->_DateTimeZone); |
|
| 599 | + |
|
| 600 | + return $DateTime; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * All this method does is determine if we're going to display the timezone string or not on any output. |
|
| 606 | + * To determine this we check if the set timezone offset is different than the blog's set timezone offset. |
|
| 607 | + * If so, then true. |
|
| 608 | + * |
|
| 609 | + * @return bool true for yes false for no |
|
| 610 | + * @throws \EE_Error |
|
| 611 | + */ |
|
| 612 | + protected function _display_timezone() |
|
| 613 | + { |
|
| 614 | + |
|
| 615 | + // first let's do a comparison of timezone strings. |
|
| 616 | + // If they match then we can get out without any further calculations |
|
| 617 | + $blog_string = get_option('timezone_string'); |
|
| 618 | + if ($blog_string === $this->_timezone_string) { |
|
| 619 | + return false; |
|
| 620 | + } |
|
| 621 | + // now we need to calc the offset for the timezone string so we can compare with the blog offset. |
|
| 622 | + $this_offset = $this->get_timezone_offset($this->_DateTimeZone); |
|
| 623 | + $blog_offset = $this->get_timezone_offset($this->get_blog_DateTimeZone()); |
|
| 624 | + // now compare |
|
| 625 | + return $blog_offset !== $this_offset; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * This method returns a php DateTime object for setting on the EE_Base_Class model. |
|
| 631 | + * EE passes around DateTime objects because they are MUCH easier to manipulate and deal |
|
| 632 | + * with. |
|
| 633 | + * |
|
| 634 | + * @param int|string|DateTime $date_string This should be the incoming date string. It's assumed to be |
|
| 635 | + * in the format that is set on the date_field (or DateTime |
|
| 636 | + * object)! |
|
| 637 | + * @return DateTime |
|
| 638 | + */ |
|
| 639 | + protected function _get_date_object($date_string) |
|
| 640 | + { |
|
| 641 | + //first if this is an empty date_string and nullable is allowed, just return null. |
|
| 642 | + if ($this->_nullable && empty($date_string)) { |
|
| 643 | + return null; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + // if incoming date |
|
| 647 | + if ($date_string instanceof DateTime) { |
|
| 648 | + $date_string->setTimezone($this->_DateTimeZone); |
|
| 649 | + |
|
| 650 | + return $date_string; |
|
| 651 | + } |
|
| 652 | + // if empty date_string and made it here. |
|
| 653 | + // Return a datetime object for now in the given timezone. |
|
| 654 | + if (empty($date_string)) { |
|
| 655 | + return new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 656 | + } |
|
| 657 | + // if $date_string is matches something that looks like a Unix timestamp let's just use it. |
|
| 658 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $date_string)) { |
|
| 659 | + try { |
|
| 660 | + // This is operating under the assumption that the incoming Unix timestamp |
|
| 661 | + // is an ACTUAL Unix timestamp and not the calculated one output by current_time('timestamp'); |
|
| 662 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 663 | + $DateTime->setTimestamp($date_string); |
|
| 664 | + |
|
| 665 | + return $DateTime; |
|
| 666 | + } catch (Exception $e) { |
|
| 667 | + // should be rare, but if things got fooled then let's just continue |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + //not a unix timestamp. So we will use the set format on this object and set timezone to |
|
| 671 | + //create the DateTime object. |
|
| 672 | + $format = $this->_date_format . ' ' . $this->_time_format; |
|
| 673 | + try { |
|
| 674 | + $DateTime = DateTime::createFromFormat($format, $date_string, $this->_DateTimeZone); |
|
| 675 | + if ($DateTime instanceof DateTime) { |
|
| 676 | + $DateTime = new DbSafeDateTime( |
|
| 677 | + $DateTime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
| 678 | + $this->_DateTimeZone |
|
| 679 | + ); |
|
| 680 | + } |
|
| 681 | + if (! $DateTime instanceof DbSafeDateTime) { |
|
| 682 | + throw new EE_Error( |
|
| 683 | + sprintf( |
|
| 684 | + __('"%1$s" does not represent a valid Date Time in the format "%2$s".', 'event_espresso'), |
|
| 685 | + $date_string, |
|
| 686 | + $format |
|
| 687 | + ) |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | + } catch (Exception $e) { |
|
| 691 | + // if we made it here then likely then something went really wrong. |
|
| 692 | + // Instead of throwing an exception, let's just return a DateTime object for now, in the set timezone. |
|
| 693 | + $DateTime = new DbSafeDateTime(\EE_Datetime_Field::now, $this->_DateTimeZone); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $DateTime; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * get_timezone_transitions |
|
| 703 | + * |
|
| 704 | + * @param \DateTimeZone $DateTimeZone |
|
| 705 | + * @param int $time |
|
| 706 | + * @param bool $first_only |
|
| 707 | + * @return mixed |
|
| 708 | + */ |
|
| 709 | + public function get_timezone_transitions(DateTimeZone $DateTimeZone, $time = null, $first_only = true) |
|
| 710 | + { |
|
| 711 | + $time = is_int($time) || $time === null ? $time : strtotime($time); |
|
| 712 | + $time = preg_match(EE_Datetime_Field::unix_timestamp_regex, $time) ? $time : time(); |
|
| 713 | + $transitions = $DateTimeZone->getTransitions($time); |
|
| 714 | + return $first_only && ! isset($transitions['ts']) ? reset($transitions) : $transitions; |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * get_timezone_offset |
|
| 721 | + * |
|
| 722 | + * @param \DateTimeZone $DateTimeZone |
|
| 723 | + * @param int $time |
|
| 724 | + * @return mixed |
|
| 725 | + * @throws \DomainException |
|
| 726 | + */ |
|
| 727 | + public function get_timezone_offset(DateTimeZone $DateTimeZone, $time = null) |
|
| 728 | + { |
|
| 729 | + $transitions = $this->get_timezone_transitions($DateTimeZone, $time); |
|
| 730 | + if ( ! isset($transitions['offset'])) { |
|
| 731 | + throw new DomainException(); |
|
| 732 | + } |
|
| 733 | + return $transitions['offset']; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * This will take an incoming timezone string and return the abbreviation for that timezone |
|
| 739 | + * |
|
| 740 | + * @param string $timezone_string |
|
| 741 | + * @return string abbreviation |
|
| 742 | + * @throws \EE_Error |
|
| 743 | + */ |
|
| 744 | + public function get_timezone_abbrev($timezone_string) |
|
| 745 | + { |
|
| 746 | + $timezone_string = EEH_DTT_Helper::get_valid_timezone_string($timezone_string); |
|
| 747 | + $dateTime = new DateTime(\EE_Datetime_Field::now, new DateTimeZone($timezone_string)); |
|
| 748 | + |
|
| 749 | + return $dateTime->format('T'); |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + /** |
|
| 753 | + * Overrides the parent to allow for having a dynamic "now" value |
|
| 754 | + * |
|
| 755 | + * @return mixed |
|
| 756 | + */ |
|
| 757 | + public function get_default_value() |
|
| 758 | + { |
|
| 759 | + if ($this->_default_value === EE_Datetime_Field::now) { |
|
| 760 | + return time(); |
|
| 761 | + } else { |
|
| 762 | + return parent::get_default_value(); |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + |
|
| 767 | + public function getSchemaDescription() |
|
| 768 | + { |
|
| 769 | + return sprintf( |
|
| 770 | + esc_html__('%s - the value for this field is in the timezone of the site.', 'event_espresso'), |
|
| 771 | + $this->get_nicename() |
|
| 772 | + ); |
|
| 773 | + } |
|
| 774 | 774 | } |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | use EventEspresso\core\services\commands\CommandInterface; |
| 8 | 8 | use EventEspresso\core\services\commands\CommandRequiresCapCheckInterface; |
| 9 | 9 | |
| 10 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 10 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 11 | 11 | exit('No direct script access allowed'); |
| 12 | 12 | } |
| 13 | 13 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | use EventEspresso\core\services\commands\CommandRequiresCapCheckInterface; |
| 10 | 10 | |
| 11 | 11 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 12 | - exit('No direct script access allowed'); |
|
| 12 | + exit('No direct script access allowed'); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | |
@@ -29,41 +29,41 @@ discard block |
||
| 29 | 29 | class CapChecker implements CommandBusMiddlewareInterface |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @type CapabilitiesCheckerInterface $capabilities_checker |
|
| 34 | - */ |
|
| 35 | - private $capabilities_checker; |
|
| 32 | + /** |
|
| 33 | + * @type CapabilitiesCheckerInterface $capabilities_checker |
|
| 34 | + */ |
|
| 35 | + private $capabilities_checker; |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * CapChecker constructor |
|
| 41 | - * |
|
| 42 | - * @param CapabilitiesCheckerInterface $capabilities_checker |
|
| 43 | - */ |
|
| 44 | - public function __construct(CapabilitiesCheckerInterface $capabilities_checker) |
|
| 45 | - { |
|
| 46 | - $this->capabilities_checker = $capabilities_checker; |
|
| 47 | - } |
|
| 39 | + /** |
|
| 40 | + * CapChecker constructor |
|
| 41 | + * |
|
| 42 | + * @param CapabilitiesCheckerInterface $capabilities_checker |
|
| 43 | + */ |
|
| 44 | + public function __construct(CapabilitiesCheckerInterface $capabilities_checker) |
|
| 45 | + { |
|
| 46 | + $this->capabilities_checker = $capabilities_checker; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param CommandInterface $command |
|
| 53 | - * @param Closure $next |
|
| 54 | - * @return mixed |
|
| 55 | - * @throws InvalidClassException |
|
| 56 | - * @throws InsufficientPermissionsException |
|
| 57 | - */ |
|
| 58 | - public function handle(CommandInterface $command, Closure $next) |
|
| 59 | - { |
|
| 60 | - if ($command instanceof CommandRequiresCapCheckInterface) { |
|
| 61 | - $this->capabilities_checker->processCapCheck( |
|
| 62 | - $command->getCapCheck() |
|
| 63 | - ); |
|
| 64 | - } |
|
| 65 | - return $next($command); |
|
| 66 | - } |
|
| 51 | + /** |
|
| 52 | + * @param CommandInterface $command |
|
| 53 | + * @param Closure $next |
|
| 54 | + * @return mixed |
|
| 55 | + * @throws InvalidClassException |
|
| 56 | + * @throws InsufficientPermissionsException |
|
| 57 | + */ |
|
| 58 | + public function handle(CommandInterface $command, Closure $next) |
|
| 59 | + { |
|
| 60 | + if ($command instanceof CommandRequiresCapCheckInterface) { |
|
| 61 | + $this->capabilities_checker->processCapCheck( |
|
| 62 | + $command->getCapCheck() |
|
| 63 | + ); |
|
| 64 | + } |
|
| 65 | + return $next($command); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | } |
@@ -24,66 +24,66 @@ |
||
| 24 | 24 | class CreateTransactionCommand extends Command implements CommandRequiresCapCheckInterface |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var EE_Checkout $checkout |
|
| 29 | - */ |
|
| 30 | - protected $checkout; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var array $transaction_details |
|
| 34 | - */ |
|
| 35 | - protected $transaction_details; |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * CreateTransactionCommand constructor. |
|
| 41 | - * |
|
| 42 | - * @param EE_Checkout $checkout |
|
| 43 | - * @param array $transaction_details |
|
| 44 | - */ |
|
| 45 | - public function __construct(EE_Checkout $checkout = null, array $transaction_details = array()) |
|
| 46 | - { |
|
| 47 | - $this->checkout = $checkout; |
|
| 48 | - $this->transaction_details = $transaction_details; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @return CapCheckInterface |
|
| 55 | - * @throws InvalidDataTypeException |
|
| 56 | - */ |
|
| 57 | - public function getCapCheck() |
|
| 58 | - { |
|
| 59 | - // need cap for non-AJAX admin requests |
|
| 60 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 61 | - // there's no specific caps for editing/creating transactions, |
|
| 62 | - // so that's why we are using ee_edit_registrations |
|
| 63 | - return new CapCheck('ee_edit_registrations', 'create_new_transaction'); |
|
| 64 | - } |
|
| 65 | - return new PublicCapabilities('', 'create_new_transaction'); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return EE_Checkout |
|
| 72 | - */ |
|
| 73 | - public function checkout() |
|
| 74 | - { |
|
| 75 | - return $this->checkout; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @return array |
|
| 82 | - */ |
|
| 83 | - public function transactionDetails() |
|
| 84 | - { |
|
| 85 | - return $this->transaction_details; |
|
| 86 | - } |
|
| 27 | + /** |
|
| 28 | + * @var EE_Checkout $checkout |
|
| 29 | + */ |
|
| 30 | + protected $checkout; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var array $transaction_details |
|
| 34 | + */ |
|
| 35 | + protected $transaction_details; |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * CreateTransactionCommand constructor. |
|
| 41 | + * |
|
| 42 | + * @param EE_Checkout $checkout |
|
| 43 | + * @param array $transaction_details |
|
| 44 | + */ |
|
| 45 | + public function __construct(EE_Checkout $checkout = null, array $transaction_details = array()) |
|
| 46 | + { |
|
| 47 | + $this->checkout = $checkout; |
|
| 48 | + $this->transaction_details = $transaction_details; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @return CapCheckInterface |
|
| 55 | + * @throws InvalidDataTypeException |
|
| 56 | + */ |
|
| 57 | + public function getCapCheck() |
|
| 58 | + { |
|
| 59 | + // need cap for non-AJAX admin requests |
|
| 60 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 61 | + // there's no specific caps for editing/creating transactions, |
|
| 62 | + // so that's why we are using ee_edit_registrations |
|
| 63 | + return new CapCheck('ee_edit_registrations', 'create_new_transaction'); |
|
| 64 | + } |
|
| 65 | + return new PublicCapabilities('', 'create_new_transaction'); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return EE_Checkout |
|
| 72 | + */ |
|
| 73 | + public function checkout() |
|
| 74 | + { |
|
| 75 | + return $this->checkout; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @return array |
|
| 82 | + */ |
|
| 83 | + public function transactionDetails() |
|
| 84 | + { |
|
| 85 | + return $this->transaction_details; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | 89 | |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | public function getCapCheck() |
| 58 | 58 | { |
| 59 | 59 | // need cap for non-AJAX admin requests |
| 60 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 60 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 61 | 61 | // there's no specific caps for editing/creating transactions, |
| 62 | 62 | // so that's why we are using ee_edit_registrations |
| 63 | 63 | return new CapCheck('ee_edit_registrations', 'create_new_transaction'); |
@@ -26,44 +26,44 @@ |
||
| 26 | 26 | { |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param CommandInterface $command |
|
| 31 | - * @return mixed |
|
| 32 | - * @throws EE_Error |
|
| 33 | - * @throws InvalidEntityException |
|
| 34 | - */ |
|
| 35 | - public function handle(CommandInterface $command) |
|
| 36 | - { |
|
| 37 | - /** @var CreateTransactionCommand $command */ |
|
| 38 | - if (! $command instanceof CreateTransactionCommand) { |
|
| 39 | - throw new InvalidEntityException(get_class($command), 'CreateTransactionCommand'); |
|
| 40 | - } |
|
| 41 | - $transaction_details = $command->transactionDetails(); |
|
| 42 | - $cart_total = null; |
|
| 43 | - if ($command->checkout() instanceof EE_Checkout) { |
|
| 44 | - // ensure cart totals have been calculated |
|
| 45 | - $command->checkout()->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 46 | - // grab the cart grand total |
|
| 47 | - $cart_total = $command->checkout()->cart->get_cart_grand_total(); |
|
| 48 | - $transaction_details['TXN_reg_steps'] = $command->checkout()->initialize_txn_reg_steps_array(); |
|
| 49 | - $transaction_details['TXN_total'] = $cart_total > 0 ? $cart_total : 0; |
|
| 50 | - } |
|
| 51 | - // create new TXN and save it so it has an ID |
|
| 52 | - $transaction = EE_Transaction::new_instance($transaction_details); |
|
| 53 | - if (! $transaction instanceof EE_Transaction) { |
|
| 54 | - throw new InvalidEntityException(get_class($transaction), 'EE_Transaction'); |
|
| 55 | - } |
|
| 56 | - $transaction->save(); |
|
| 57 | - // ensure grand total line item created |
|
| 58 | - $cart_total = $cart_total instanceof EE_Line_Item |
|
| 59 | - ? $cart_total |
|
| 60 | - : EEH_Line_Item::create_total_line_item($transaction); |
|
| 61 | - if (! $cart_total instanceof EE_Line_Item) { |
|
| 62 | - throw new InvalidEntityException(get_class($cart_total), 'EE_Line_Item'); |
|
| 63 | - } |
|
| 64 | - $cart_total->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 65 | - return $transaction; |
|
| 66 | - } |
|
| 29 | + /** |
|
| 30 | + * @param CommandInterface $command |
|
| 31 | + * @return mixed |
|
| 32 | + * @throws EE_Error |
|
| 33 | + * @throws InvalidEntityException |
|
| 34 | + */ |
|
| 35 | + public function handle(CommandInterface $command) |
|
| 36 | + { |
|
| 37 | + /** @var CreateTransactionCommand $command */ |
|
| 38 | + if (! $command instanceof CreateTransactionCommand) { |
|
| 39 | + throw new InvalidEntityException(get_class($command), 'CreateTransactionCommand'); |
|
| 40 | + } |
|
| 41 | + $transaction_details = $command->transactionDetails(); |
|
| 42 | + $cart_total = null; |
|
| 43 | + if ($command->checkout() instanceof EE_Checkout) { |
|
| 44 | + // ensure cart totals have been calculated |
|
| 45 | + $command->checkout()->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
| 46 | + // grab the cart grand total |
|
| 47 | + $cart_total = $command->checkout()->cart->get_cart_grand_total(); |
|
| 48 | + $transaction_details['TXN_reg_steps'] = $command->checkout()->initialize_txn_reg_steps_array(); |
|
| 49 | + $transaction_details['TXN_total'] = $cart_total > 0 ? $cart_total : 0; |
|
| 50 | + } |
|
| 51 | + // create new TXN and save it so it has an ID |
|
| 52 | + $transaction = EE_Transaction::new_instance($transaction_details); |
|
| 53 | + if (! $transaction instanceof EE_Transaction) { |
|
| 54 | + throw new InvalidEntityException(get_class($transaction), 'EE_Transaction'); |
|
| 55 | + } |
|
| 56 | + $transaction->save(); |
|
| 57 | + // ensure grand total line item created |
|
| 58 | + $cart_total = $cart_total instanceof EE_Line_Item |
|
| 59 | + ? $cart_total |
|
| 60 | + : EEH_Line_Item::create_total_line_item($transaction); |
|
| 61 | + if (! $cart_total instanceof EE_Line_Item) { |
|
| 62 | + throw new InvalidEntityException(get_class($cart_total), 'EE_Line_Item'); |
|
| 63 | + } |
|
| 64 | + $cart_total->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 65 | + return $transaction; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public function handle(CommandInterface $command) |
| 36 | 36 | { |
| 37 | 37 | /** @var CreateTransactionCommand $command */ |
| 38 | - if (! $command instanceof CreateTransactionCommand) { |
|
| 38 | + if ( ! $command instanceof CreateTransactionCommand) { |
|
| 39 | 39 | throw new InvalidEntityException(get_class($command), 'CreateTransactionCommand'); |
| 40 | 40 | } |
| 41 | 41 | $transaction_details = $command->transactionDetails(); |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | } |
| 51 | 51 | // create new TXN and save it so it has an ID |
| 52 | 52 | $transaction = EE_Transaction::new_instance($transaction_details); |
| 53 | - if (! $transaction instanceof EE_Transaction) { |
|
| 53 | + if ( ! $transaction instanceof EE_Transaction) { |
|
| 54 | 54 | throw new InvalidEntityException(get_class($transaction), 'EE_Transaction'); |
| 55 | 55 | } |
| 56 | 56 | $transaction->save(); |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $cart_total = $cart_total instanceof EE_Line_Item |
| 59 | 59 | ? $cart_total |
| 60 | 60 | : EEH_Line_Item::create_total_line_item($transaction); |
| 61 | - if (! $cart_total instanceof EE_Line_Item) { |
|
| 61 | + if ( ! $cart_total instanceof EE_Line_Item) { |
|
| 62 | 62 | throw new InvalidEntityException(get_class($cart_total), 'EE_Line_Item'); |
| 63 | 63 | } |
| 64 | 64 | $cart_total->save_this_and_descendants_to_txn($transaction->ID()); |
@@ -24,68 +24,68 @@ |
||
| 24 | 24 | class CreateAttendeeCommand extends Command implements CommandRequiresCapCheckInterface |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * array of details where keys are names of EEM_Attendee model fields |
|
| 29 | - * |
|
| 30 | - * @var array $attendee_details |
|
| 31 | - */ |
|
| 32 | - protected $attendee_details; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * an existing registration to associate this attendee with |
|
| 36 | - * |
|
| 37 | - * @var EE_Registration $registration |
|
| 38 | - */ |
|
| 39 | - protected $registration; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * CreateAttendeeCommand constructor. |
|
| 45 | - * |
|
| 46 | - * @param array $attendee_details |
|
| 47 | - * @param EE_Registration $registration |
|
| 48 | - */ |
|
| 49 | - public function __construct(array $attendee_details, EE_Registration $registration) |
|
| 50 | - { |
|
| 51 | - $this->attendee_details = $attendee_details; |
|
| 52 | - $this->registration = $registration; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @return array |
|
| 59 | - */ |
|
| 60 | - public function attendeeDetails() |
|
| 61 | - { |
|
| 62 | - return $this->attendee_details; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @return EE_Registration |
|
| 69 | - */ |
|
| 70 | - public function registration() |
|
| 71 | - { |
|
| 72 | - return $this->registration; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @return CapCheckInterface |
|
| 79 | - * @throws InvalidDataTypeException |
|
| 80 | - */ |
|
| 81 | - public function getCapCheck() |
|
| 82 | - { |
|
| 83 | - // need cap for non-AJAX admin requests |
|
| 84 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 85 | - return new CapCheck('ee_edit_contacts', 'create_new_contact'); |
|
| 86 | - } |
|
| 87 | - return new PublicCapabilities('', 'create_new_contact'); |
|
| 88 | - } |
|
| 27 | + /** |
|
| 28 | + * array of details where keys are names of EEM_Attendee model fields |
|
| 29 | + * |
|
| 30 | + * @var array $attendee_details |
|
| 31 | + */ |
|
| 32 | + protected $attendee_details; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * an existing registration to associate this attendee with |
|
| 36 | + * |
|
| 37 | + * @var EE_Registration $registration |
|
| 38 | + */ |
|
| 39 | + protected $registration; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * CreateAttendeeCommand constructor. |
|
| 45 | + * |
|
| 46 | + * @param array $attendee_details |
|
| 47 | + * @param EE_Registration $registration |
|
| 48 | + */ |
|
| 49 | + public function __construct(array $attendee_details, EE_Registration $registration) |
|
| 50 | + { |
|
| 51 | + $this->attendee_details = $attendee_details; |
|
| 52 | + $this->registration = $registration; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @return array |
|
| 59 | + */ |
|
| 60 | + public function attendeeDetails() |
|
| 61 | + { |
|
| 62 | + return $this->attendee_details; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @return EE_Registration |
|
| 69 | + */ |
|
| 70 | + public function registration() |
|
| 71 | + { |
|
| 72 | + return $this->registration; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @return CapCheckInterface |
|
| 79 | + * @throws InvalidDataTypeException |
|
| 80 | + */ |
|
| 81 | + public function getCapCheck() |
|
| 82 | + { |
|
| 83 | + // need cap for non-AJAX admin requests |
|
| 84 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 85 | + return new CapCheck('ee_edit_contacts', 'create_new_contact'); |
|
| 86 | + } |
|
| 87 | + return new PublicCapabilities('', 'create_new_contact'); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | |
| 91 | 91 | |
@@ -81,7 +81,7 @@ |
||
| 81 | 81 | public function getCapCheck() |
| 82 | 82 | { |
| 83 | 83 | // need cap for non-AJAX admin requests |
| 84 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 84 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 85 | 85 | return new CapCheck('ee_edit_contacts', 'create_new_contact'); |
| 86 | 86 | } |
| 87 | 87 | return new PublicCapabilities('', 'create_new_contact'); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @param EEM_Attendee $attendee_model |
| 36 | 36 | */ |
| 37 | 37 | public function __construct(EEM_Attendee $attendee_model ) { |
| 38 | - $this->attendee_model = $attendee_model; |
|
| 38 | + $this->attendee_model = $attendee_model; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | private function findExistingAttendee( EE_Registration $registration, array $attendee_data ) { |
| 84 | 84 | $existing_attendee = null; |
| 85 | 85 | // does this attendee already exist in the db ? |
| 86 | - // we're searching using a combination of first name, last name, AND email address |
|
| 86 | + // we're searching using a combination of first name, last name, AND email address |
|
| 87 | 87 | $ATT_fname = ! empty( $attendee_data['ATT_fname'] ) |
| 88 | 88 | ? $attendee_data['ATT_fname'] |
| 89 | 89 | : ''; |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | private function updateExistingAttendeeData( EE_Attendee $existing_attendee, array $attendee_data ) { |
| 126 | 126 | // first remove fname, lname, and email from attendee data |
| 127 | - // because these properties will be exactly the same as the returned attendee object, |
|
| 128 | - // since they were used in the query to get the attendee object in the first place |
|
| 127 | + // because these properties will be exactly the same as the returned attendee object, |
|
| 128 | + // since they were used in the query to get the attendee object in the first place |
|
| 129 | 129 | $dont_set = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
| 130 | 130 | // now loop thru what's left and add to attendee CPT |
| 131 | 131 | foreach ( $attendee_data as $property_name => $property_value ) { |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | use EventEspresso\core\services\commands\CommandHandler; |
| 10 | 10 | use EventEspresso\core\services\commands\CommandInterface; |
| 11 | 11 | |
| 12 | -defined( 'EVENT_ESPRESSO_VERSION' ) || exit; |
|
| 12 | +defined('EVENT_ESPRESSO_VERSION') || exit; |
|
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | /** |
| 35 | 35 | * @param EEM_Attendee $attendee_model |
| 36 | 36 | */ |
| 37 | - public function __construct(EEM_Attendee $attendee_model ) { |
|
| 37 | + public function __construct(EEM_Attendee $attendee_model) { |
|
| 38 | 38 | $this->attendee_model = $attendee_model; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -46,10 +46,10 @@ discard block |
||
| 46 | 46 | * @throws EE_Error |
| 47 | 47 | * @throws InvalidEntityException |
| 48 | 48 | */ |
| 49 | - public function handle( CommandInterface $command ) { |
|
| 49 | + public function handle(CommandInterface $command) { |
|
| 50 | 50 | /** @var CreateAttendeeCommand $command */ |
| 51 | - if ( ! $command instanceof CreateAttendeeCommand ) { |
|
| 52 | - throw new InvalidEntityException( get_class( $command ), 'CreateAttendeeCommand' ); |
|
| 51 | + if ( ! $command instanceof CreateAttendeeCommand) { |
|
| 52 | + throw new InvalidEntityException(get_class($command), 'CreateAttendeeCommand'); |
|
| 53 | 53 | } |
| 54 | 54 | // have we met before? |
| 55 | 55 | $attendee = $this->findExistingAttendee( |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | $command->attendeeDetails() |
| 58 | 58 | ); |
| 59 | 59 | // did we find an already existing record for this attendee ? |
| 60 | - if ( $attendee instanceof EE_Attendee ) { |
|
| 60 | + if ($attendee instanceof EE_Attendee) { |
|
| 61 | 61 | $attendee = $this->updateExistingAttendeeData( |
| 62 | 62 | $attendee, |
| 63 | 63 | $command->attendeeDetails() |
@@ -80,21 +80,21 @@ discard block |
||
| 80 | 80 | * @param array $attendee_data |
| 81 | 81 | * @return EE_Attendee |
| 82 | 82 | */ |
| 83 | - private function findExistingAttendee( EE_Registration $registration, array $attendee_data ) { |
|
| 83 | + private function findExistingAttendee(EE_Registration $registration, array $attendee_data) { |
|
| 84 | 84 | $existing_attendee = null; |
| 85 | 85 | // does this attendee already exist in the db ? |
| 86 | 86 | // we're searching using a combination of first name, last name, AND email address |
| 87 | - $ATT_fname = ! empty( $attendee_data['ATT_fname'] ) |
|
| 87 | + $ATT_fname = ! empty($attendee_data['ATT_fname']) |
|
| 88 | 88 | ? $attendee_data['ATT_fname'] |
| 89 | 89 | : ''; |
| 90 | - $ATT_lname = ! empty( $attendee_data['ATT_lname'] ) |
|
| 90 | + $ATT_lname = ! empty($attendee_data['ATT_lname']) |
|
| 91 | 91 | ? $attendee_data['ATT_lname'] |
| 92 | 92 | : ''; |
| 93 | - $ATT_email = ! empty( $attendee_data['ATT_email'] ) |
|
| 93 | + $ATT_email = ! empty($attendee_data['ATT_email']) |
|
| 94 | 94 | ? $attendee_data['ATT_email'] |
| 95 | 95 | : ''; |
| 96 | 96 | // but only if those have values |
| 97 | - if ( $ATT_fname && $ATT_lname && $ATT_email ) { |
|
| 97 | + if ($ATT_fname && $ATT_lname && $ATT_email) { |
|
| 98 | 98 | $existing_attendee = $this->attendee_model->find_existing_attendee( |
| 99 | 99 | array( |
| 100 | 100 | 'ATT_fname' => $ATT_fname, |
@@ -122,18 +122,18 @@ discard block |
||
| 122 | 122 | * @return EE_Attendee |
| 123 | 123 | * @throws EE_Error |
| 124 | 124 | */ |
| 125 | - private function updateExistingAttendeeData( EE_Attendee $existing_attendee, array $attendee_data ) { |
|
| 125 | + private function updateExistingAttendeeData(EE_Attendee $existing_attendee, array $attendee_data) { |
|
| 126 | 126 | // first remove fname, lname, and email from attendee data |
| 127 | 127 | // because these properties will be exactly the same as the returned attendee object, |
| 128 | 128 | // since they were used in the query to get the attendee object in the first place |
| 129 | - $dont_set = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
| 129 | + $dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
| 130 | 130 | // now loop thru what's left and add to attendee CPT |
| 131 | - foreach ( $attendee_data as $property_name => $property_value ) { |
|
| 131 | + foreach ($attendee_data as $property_name => $property_value) { |
|
| 132 | 132 | if ( |
| 133 | - ! in_array( $property_name, $dont_set, true ) |
|
| 134 | - && $this->attendee_model->has_field( $property_name ) |
|
| 133 | + ! in_array($property_name, $dont_set, true) |
|
| 134 | + && $this->attendee_model->has_field($property_name) |
|
| 135 | 135 | ) { |
| 136 | - $existing_attendee->set( $property_name, $property_value ); |
|
| 136 | + $existing_attendee->set($property_name, $property_value); |
|
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | // better save that now |
@@ -151,11 +151,11 @@ discard block |
||
| 151 | 151 | * @return EE_Attendee |
| 152 | 152 | * @throws EE_Error |
| 153 | 153 | */ |
| 154 | - private function createNewAttendee( EE_Registration $registration, array $attendee_data ) { |
|
| 154 | + private function createNewAttendee(EE_Registration $registration, array $attendee_data) { |
|
| 155 | 155 | // create new attendee object |
| 156 | - $new_attendee = EE_Attendee::new_instance( $attendee_data ); |
|
| 156 | + $new_attendee = EE_Attendee::new_instance($attendee_data); |
|
| 157 | 157 | // set author to event creator |
| 158 | - $new_attendee->set( 'ATT_author', $registration->event()->wp_user() ); |
|
| 158 | + $new_attendee->set('ATT_author', $registration->event()->wp_user()); |
|
| 159 | 159 | $new_attendee->save(); |
| 160 | 160 | return $new_attendee; |
| 161 | 161 | } |
@@ -39,8 +39,8 @@ |
||
| 39 | 39 | * @param EE_Transaction $transaction |
| 40 | 40 | * @param EE_Ticket $ticket |
| 41 | 41 | * @param EE_Line_Item $ticket_line_item |
| 42 | - * @param $reg_count |
|
| 43 | - * @param $reg_group_size |
|
| 42 | + * @param integer $reg_count |
|
| 43 | + * @param integer $reg_group_size |
|
| 44 | 44 | * @param string $reg_status |
| 45 | 45 | * @return EE_Registration |
| 46 | 46 | * @throws OutOfRangeException |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | use OutOfRangeException; |
| 18 | 18 | |
| 19 | 19 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 20 | - exit('No direct script access allowed'); |
|
| 20 | + exit('No direct script access allowed'); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -41,54 +41,54 @@ discard block |
||
| 41 | 41 | * @param EE_Line_Item $ticket_line_item |
| 42 | 42 | * @param $reg_count |
| 43 | 43 | * @param $reg_group_size |
| 44 | - * @param string $reg_status |
|
| 45 | - * @return EE_Registration |
|
| 44 | + * @param string $reg_status |
|
| 45 | + * @return EE_Registration |
|
| 46 | 46 | * @throws OutOfRangeException |
| 47 | 47 | * @throws EE_Error |
| 48 | 48 | * @throws UnexpectedEntityException |
| 49 | 49 | */ |
| 50 | - public function create( |
|
| 51 | - EE_Event $event, |
|
| 52 | - EE_Transaction $transaction, |
|
| 53 | - EE_Ticket $ticket, |
|
| 54 | - EE_Line_Item $ticket_line_item, |
|
| 55 | - $reg_count, |
|
| 56 | - $reg_group_size, |
|
| 57 | - $reg_status = EEM_Registration::status_id_incomplete |
|
| 58 | - ) { |
|
| 59 | - $registrations = $transaction->registrations(); |
|
| 60 | - $reg_count = $reg_count ? $reg_count : count($registrations) + 1; |
|
| 61 | - $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item); |
|
| 62 | - $reg_code = new RegCode($reg_url_link, $transaction, $ticket); |
|
| 63 | - // generate new EE_Registration |
|
| 64 | - $registration = EE_Registration::new_instance( |
|
| 65 | - array( |
|
| 66 | - 'EVT_ID' => $event->ID(), |
|
| 67 | - 'TXN_ID' => $transaction->ID(), |
|
| 68 | - 'TKT_ID' => $ticket->ID(), |
|
| 69 | - 'STS_ID' => $reg_status, |
|
| 70 | - 'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item), |
|
| 71 | - 'REG_session' => EE_Registry::instance()->SSN->id(), |
|
| 72 | - 'REG_count' => $reg_count, |
|
| 73 | - 'REG_group_size' => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations), |
|
| 74 | - 'REG_url_link' => $reg_url_link, |
|
| 75 | - 'REG_code' => $reg_code, |
|
| 76 | - ) |
|
| 77 | - ); |
|
| 78 | - if ( ! $registration instanceof EE_Registration) { |
|
| 79 | - throw new UnexpectedEntityException($registration, 'EE_Registration'); |
|
| 80 | - } |
|
| 81 | - // save registration so that we have an ID |
|
| 82 | - $registration->save(); |
|
| 83 | - // track reservation on reg but don't adjust ticket and datetime reserved counts |
|
| 84 | - // because that is done as soon as the tickets are added/removed from the cart |
|
| 85 | - $registration->reserve_ticket(); |
|
| 86 | - $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
|
| 87 | - $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
|
| 88 | - $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
|
| 89 | - $registration->save(); |
|
| 90 | - return $registration; |
|
| 91 | - } |
|
| 50 | + public function create( |
|
| 51 | + EE_Event $event, |
|
| 52 | + EE_Transaction $transaction, |
|
| 53 | + EE_Ticket $ticket, |
|
| 54 | + EE_Line_Item $ticket_line_item, |
|
| 55 | + $reg_count, |
|
| 56 | + $reg_group_size, |
|
| 57 | + $reg_status = EEM_Registration::status_id_incomplete |
|
| 58 | + ) { |
|
| 59 | + $registrations = $transaction->registrations(); |
|
| 60 | + $reg_count = $reg_count ? $reg_count : count($registrations) + 1; |
|
| 61 | + $reg_url_link = new RegUrlLink($reg_count, $ticket_line_item); |
|
| 62 | + $reg_code = new RegCode($reg_url_link, $transaction, $ticket); |
|
| 63 | + // generate new EE_Registration |
|
| 64 | + $registration = EE_Registration::new_instance( |
|
| 65 | + array( |
|
| 66 | + 'EVT_ID' => $event->ID(), |
|
| 67 | + 'TXN_ID' => $transaction->ID(), |
|
| 68 | + 'TKT_ID' => $ticket->ID(), |
|
| 69 | + 'STS_ID' => $reg_status, |
|
| 70 | + 'REG_final_price' => $this->resolveFinalPrice($transaction, $ticket, $ticket_line_item), |
|
| 71 | + 'REG_session' => EE_Registry::instance()->SSN->id(), |
|
| 72 | + 'REG_count' => $reg_count, |
|
| 73 | + 'REG_group_size' => $reg_group_size ? $reg_group_size : $this->incrementRegCount($registrations), |
|
| 74 | + 'REG_url_link' => $reg_url_link, |
|
| 75 | + 'REG_code' => $reg_code, |
|
| 76 | + ) |
|
| 77 | + ); |
|
| 78 | + if ( ! $registration instanceof EE_Registration) { |
|
| 79 | + throw new UnexpectedEntityException($registration, 'EE_Registration'); |
|
| 80 | + } |
|
| 81 | + // save registration so that we have an ID |
|
| 82 | + $registration->save(); |
|
| 83 | + // track reservation on reg but don't adjust ticket and datetime reserved counts |
|
| 84 | + // because that is done as soon as the tickets are added/removed from the cart |
|
| 85 | + $registration->reserve_ticket(); |
|
| 86 | + $registration->_add_relation_to($event, 'Event', array(), $event->ID()); |
|
| 87 | + $registration->_add_relation_to($ticket, 'Ticket', array(), $ticket->ID()); |
|
| 88 | + $transaction->_add_relation_to($registration, 'Registration', array(), $registration->ID()); |
|
| 89 | + $registration->save(); |
|
| 90 | + return $registration; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | |
@@ -100,40 +100,40 @@ discard block |
||
| 100 | 100 | * @throws EE_Error |
| 101 | 101 | * @throws OutOfRangeException |
| 102 | 102 | */ |
| 103 | - protected function resolveFinalPrice( |
|
| 104 | - EE_Transaction $transaction, |
|
| 105 | - EE_Ticket $ticket, |
|
| 106 | - EE_Line_Item $ticket_line_item |
|
| 107 | - ) { |
|
| 108 | - $final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item( |
|
| 109 | - $transaction->total_line_item(), |
|
| 110 | - $ticket_line_item |
|
| 111 | - ); |
|
| 112 | - $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes(); |
|
| 113 | - return (float)$final_price; |
|
| 114 | - } |
|
| 103 | + protected function resolveFinalPrice( |
|
| 104 | + EE_Transaction $transaction, |
|
| 105 | + EE_Ticket $ticket, |
|
| 106 | + EE_Line_Item $ticket_line_item |
|
| 107 | + ) { |
|
| 108 | + $final_price = EEH_Line_Item::calculate_final_price_for_ticket_line_item( |
|
| 109 | + $transaction->total_line_item(), |
|
| 110 | + $ticket_line_item |
|
| 111 | + ); |
|
| 112 | + $final_price = $final_price !== null ? $final_price : $ticket->get_ticket_total_with_taxes(); |
|
| 113 | + return (float)$final_price; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * @param EE_Registration[] $registrations |
|
| 120 | - * @param boolean $update_existing_registrations |
|
| 121 | - * @return int |
|
| 122 | - * @throws EE_Error |
|
| 123 | - */ |
|
| 124 | - protected function incrementRegCount(array $registrations, $update_existing_registrations = true) |
|
| 125 | - { |
|
| 126 | - $new_reg_count = count($registrations) + 1; |
|
| 127 | - if ($update_existing_registrations) { |
|
| 128 | - foreach ($registrations as $registration) { |
|
| 129 | - if ($registration instanceof EE_Registration) { |
|
| 130 | - $registration->set_count($new_reg_count); |
|
| 131 | - $registration->save(); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - return $new_reg_count; |
|
| 136 | - } |
|
| 118 | + /** |
|
| 119 | + * @param EE_Registration[] $registrations |
|
| 120 | + * @param boolean $update_existing_registrations |
|
| 121 | + * @return int |
|
| 122 | + * @throws EE_Error |
|
| 123 | + */ |
|
| 124 | + protected function incrementRegCount(array $registrations, $update_existing_registrations = true) |
|
| 125 | + { |
|
| 126 | + $new_reg_count = count($registrations) + 1; |
|
| 127 | + if ($update_existing_registrations) { |
|
| 128 | + foreach ($registrations as $registration) { |
|
| 129 | + if ($registration instanceof EE_Registration) { |
|
| 130 | + $registration->set_count($new_reg_count); |
|
| 131 | + $registration->save(); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + return $new_reg_count; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | 139 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
| 6 | 6 | |
| 7 | 7 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 8 | - exit('No direct script access allowed'); |
|
| 8 | + exit('No direct script access allowed'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | |
@@ -21,44 +21,44 @@ discard block |
||
| 21 | 21 | class CreateTicketLineItemService extends DomainService |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param \EE_Transaction $transaction |
|
| 26 | - * @param \EE_Ticket $ticket |
|
| 27 | - * @param int $quantity |
|
| 28 | - * @return \EE_Line_Item |
|
| 29 | - * @throws \EE_Error |
|
| 30 | - * @throws UnexpectedEntityException |
|
| 31 | - */ |
|
| 32 | - public function create( |
|
| 33 | - \EE_Transaction $transaction, |
|
| 34 | - \EE_Ticket $ticket, |
|
| 35 | - $quantity = 1 |
|
| 36 | - ) |
|
| 37 | - { |
|
| 38 | - $total_line_item = $transaction->total_line_item(); |
|
| 39 | - if (! $total_line_item instanceof \EE_Line_Item) { |
|
| 40 | - throw new UnexpectedEntityException($total_line_item, 'EE_Line_Item'); |
|
| 41 | - } |
|
| 42 | - // create new line item for ticket |
|
| 43 | - $ticket_line_item = \EEH_Line_Item::add_ticket_purchase( |
|
| 44 | - $total_line_item, |
|
| 45 | - $ticket, |
|
| 46 | - $quantity |
|
| 47 | - ); |
|
| 48 | - if ( ! $ticket_line_item instanceof \EE_Line_Item) { |
|
| 49 | - throw new UnexpectedEntityException($ticket_line_item, 'EE_Line_Item'); |
|
| 50 | - } |
|
| 51 | - $total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 52 | - // apply any applicable promotions that were initially used during registration to new line items |
|
| 53 | - do_action( |
|
| 54 | - 'AHEE__\EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler__handle__new_ticket_line_item_added', |
|
| 55 | - $total_line_item, |
|
| 56 | - $ticket, |
|
| 57 | - $transaction, |
|
| 58 | - $quantity |
|
| 59 | - ); |
|
| 60 | - return $ticket_line_item; |
|
| 61 | - } |
|
| 24 | + /** |
|
| 25 | + * @param \EE_Transaction $transaction |
|
| 26 | + * @param \EE_Ticket $ticket |
|
| 27 | + * @param int $quantity |
|
| 28 | + * @return \EE_Line_Item |
|
| 29 | + * @throws \EE_Error |
|
| 30 | + * @throws UnexpectedEntityException |
|
| 31 | + */ |
|
| 32 | + public function create( |
|
| 33 | + \EE_Transaction $transaction, |
|
| 34 | + \EE_Ticket $ticket, |
|
| 35 | + $quantity = 1 |
|
| 36 | + ) |
|
| 37 | + { |
|
| 38 | + $total_line_item = $transaction->total_line_item(); |
|
| 39 | + if (! $total_line_item instanceof \EE_Line_Item) { |
|
| 40 | + throw new UnexpectedEntityException($total_line_item, 'EE_Line_Item'); |
|
| 41 | + } |
|
| 42 | + // create new line item for ticket |
|
| 43 | + $ticket_line_item = \EEH_Line_Item::add_ticket_purchase( |
|
| 44 | + $total_line_item, |
|
| 45 | + $ticket, |
|
| 46 | + $quantity |
|
| 47 | + ); |
|
| 48 | + if ( ! $ticket_line_item instanceof \EE_Line_Item) { |
|
| 49 | + throw new UnexpectedEntityException($ticket_line_item, 'EE_Line_Item'); |
|
| 50 | + } |
|
| 51 | + $total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
| 52 | + // apply any applicable promotions that were initially used during registration to new line items |
|
| 53 | + do_action( |
|
| 54 | + 'AHEE__\EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler__handle__new_ticket_line_item_added', |
|
| 55 | + $total_line_item, |
|
| 56 | + $ticket, |
|
| 57 | + $transaction, |
|
| 58 | + $quantity |
|
| 59 | + ); |
|
| 60 | + return $ticket_line_item; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | 63 | |
| 64 | 64 | |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | ) |
| 37 | 37 | { |
| 38 | 38 | $total_line_item = $transaction->total_line_item(); |
| 39 | - if (! $total_line_item instanceof \EE_Line_Item) { |
|
| 39 | + if ( ! $total_line_item instanceof \EE_Line_Item) { |
|
| 40 | 40 | throw new UnexpectedEntityException($total_line_item, 'EE_Line_Item'); |
| 41 | 41 | } |
| 42 | 42 | // create new line item for ticket |