@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * Ensures that taxes have been applied to the order, if not applies them. |
| 575 | 575 | * Returns the total amount of tax |
| 576 | 576 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
| 577 | - * @return float |
|
| 577 | + * @return boolean |
|
| 578 | 578 | */ |
| 579 | 579 | public static function ensure_taxes_applied( $total_line_item ){ |
| 580 | 580 | $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
@@ -590,7 +590,7 @@ discard block |
||
| 590 | 590 | * Deletes ALL children of the passed line item |
| 591 | 591 | * |
| 592 | 592 | * @param EE_Line_Item $parent_line_item |
| 593 | - * @return bool |
|
| 593 | + * @return integer |
|
| 594 | 594 | */ |
| 595 | 595 | public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
| 596 | 596 | $deleted = 0; |
@@ -620,7 +620,7 @@ discard block |
||
| 620 | 620 | * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
| 621 | 621 | * after using this, to keep the registration final prices in-sync with the transaction's total. |
| 622 | 622 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
| 623 | - * @param array|bool|string $line_item_codes |
|
| 623 | + * @param boolean $line_item_codes |
|
| 624 | 624 | * @return int number of items successfully removed |
| 625 | 625 | */ |
| 626 | 626 | public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
@@ -784,6 +784,7 @@ discard block |
||
| 784 | 784 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 785 | 785 | * @param string $line_item_type one of the EEM_Line_Item constants |
| 786 | 786 | * @param string | NULL $obj_type object model class name (minus prefix) or NULL to ignore object type when searching |
| 787 | + * @param string $obj_type |
|
| 787 | 788 | * @return EE_Line_Item[] |
| 788 | 789 | */ |
| 789 | 790 | protected static function _get_descendants_by_type_and_object_type( EE_Line_Item $parent_line_item, $line_item_type, $obj_type = NULL ) { |
@@ -809,7 +810,7 @@ discard block |
||
| 809 | 810 | * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
| 810 | 811 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 811 | 812 | * @param string $OBJ_type object type (like Event) |
| 812 | - * @param array $OBJ_IDs array of OBJ_IDs |
|
| 813 | + * @param boolean[] $OBJ_IDs array of OBJ_IDs |
|
| 813 | 814 | * @return EE_Line_Item[] |
| 814 | 815 | */ |
| 815 | 816 | public static function get_line_items_by_object_type_and_IDs( EE_Line_Item $parent_line_item, $OBJ_type = '', $OBJ_IDs = array() ) { |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | //so in case teh IPN is arriving later, let's try to process an IPN! |
| 91 | 91 | if($_SERVER['REQUEST_METHOD'] == 'POST'){ |
| 92 | 92 | return $this->handle_ipn($_POST, $transaction ); |
| 93 | - }else{ |
|
| 93 | + } else{ |
|
| 94 | 94 | return parent::finalize_payment_for( $transaction ); |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -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 |
@@ -40,8 +40,8 @@ discard block |
||
| 40 | 40 | * @param boolean $code if set to a value, ensures there is only one line item with that code |
| 41 | 41 | * @return boolean success |
| 42 | 42 | */ |
| 43 | - public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
|
| 44 | - $items_subtotal = self::get_pre_tax_subtotal( $parent_line_item ); |
|
| 43 | + public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) { |
|
| 44 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
| 45 | 45 | $line_item = EE_Line_Item::new_instance(array( |
| 46 | 46 | 'LIN_name' => $name, |
| 47 | 47 | 'LIN_desc' => $description, |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | 'LIN_quantity' => $quantity, |
| 50 | 50 | 'LIN_percent' => null, |
| 51 | 51 | 'LIN_is_taxable' => $taxable, |
| 52 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0, |
|
| 53 | - 'LIN_total' => floatval( $unit_price ) * intval( $quantity ), |
|
| 52 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
| 53 | + 'LIN_total' => floatval($unit_price) * intval($quantity), |
|
| 54 | 54 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
| 55 | 55 | 'LIN_code' => $code, |
| 56 | 56 | )); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $line_item, |
| 60 | 60 | $parent_line_item |
| 61 | 61 | ); |
| 62 | - return self::add_item( $parent_line_item, $line_item ); |
|
| 62 | + return self::add_item($parent_line_item, $line_item); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @param boolean $taxable |
| 81 | 81 | * @return boolean success |
| 82 | 82 | */ |
| 83 | - public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
|
| 83 | + public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) { |
|
| 84 | 84 | $line_item = EE_Line_Item::new_instance(array( |
| 85 | 85 | 'LIN_name' => $name, |
| 86 | 86 | 'LIN_desc' => $description, |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | 'LIN_percent' => $percentage_amount, |
| 89 | 89 | 'LIN_quantity' => NULL, |
| 90 | 90 | 'LIN_is_taxable' => $taxable, |
| 91 | - 'LIN_total' => floatval( $percentage_amount * ( $parent_line_item->total() / 100 )), |
|
| 91 | + 'LIN_total' => floatval($percentage_amount * ($parent_line_item->total() / 100)), |
|
| 92 | 92 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
| 93 | 93 | 'LIN_parent' => $parent_line_item->ID() |
| 94 | 94 | )); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
| 97 | 97 | $line_item |
| 98 | 98 | ); |
| 99 | - return self::add_item( $parent_line_item, $line_item ); |
|
| 99 | + return self::add_item($parent_line_item, $line_item); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | * @return \EE_Line_Item |
| 118 | 118 | * @throws \EE_Error |
| 119 | 119 | */ |
| 120 | - public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
|
| 121 | - if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) { |
|
| 122 | - 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() ) ); |
|
| 120 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
| 121 | + if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
| 122 | + throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID())); |
|
| 123 | 123 | } |
| 124 | 124 | // either increment the qty for an existing ticket |
| 125 | - $line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty ); |
|
| 125 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
| 126 | 126 | // or add a new one |
| 127 | - if ( ! $line_item instanceof EE_Line_Item ) { |
|
| 128 | - $line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty ); |
|
| 127 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
| 128 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
| 129 | 129 | } |
| 130 | 130 | $total_line_item->recalculate_total_including_taxes(); |
| 131 | 131 | return $line_item; |
@@ -141,19 +141,19 @@ discard block |
||
| 141 | 141 | * @return \EE_Line_Item |
| 142 | 142 | * @throws \EE_Error |
| 143 | 143 | */ |
| 144 | - public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
| 144 | + public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
| 145 | 145 | $line_item = null; |
| 146 | - if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) { |
|
| 147 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item ); |
|
| 148 | - foreach ( (array)$ticket_line_items as $ticket_line_item ) { |
|
| 149 | - if ( $ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_ID() == $ticket->ID() ) { |
|
| 146 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
| 147 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 148 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
| 149 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_ID() == $ticket->ID()) { |
|
| 150 | 150 | $line_item = $ticket_line_item; |
| 151 | 151 | break; |
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | - if ( $line_item instanceof EE_Line_Item ) { |
|
| 156 | - EEH_Line_Item::increment_quantity( $line_item, $qty ); |
|
| 155 | + if ($line_item instanceof EE_Line_Item) { |
|
| 156 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
| 157 | 157 | return $line_item; |
| 158 | 158 | } |
| 159 | 159 | return null; |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | * @param int $qty |
| 167 | 167 | * @return void |
| 168 | 168 | */ |
| 169 | - public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
| 170 | - if( ! $line_item->is_percent() ) { |
|
| 169 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
| 170 | + if ( ! $line_item->is_percent()) { |
|
| 171 | 171 | $qty += $line_item->quantity(); |
| 172 | - $line_item->set_quantity( $qty ); |
|
| 173 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
| 172 | + $line_item->set_quantity($qty); |
|
| 173 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
| 174 | 174 | } |
| 175 | - foreach( $line_item->children() as $child ) { |
|
| 176 | - if( $child->is_sub_line_item() ) { |
|
| 177 | - EEH_Line_Item::update_quantity( $child, $line_item->quantity() ); |
|
| 175 | + foreach ($line_item->children() as $child) { |
|
| 176 | + if ($child->is_sub_line_item()) { |
|
| 177 | + EEH_Line_Item::update_quantity($child, $line_item->quantity()); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -185,14 +185,14 @@ discard block |
||
| 185 | 185 | * @param EE_Line_Item $line_item |
| 186 | 186 | * @param int $new_quantity |
| 187 | 187 | */ |
| 188 | - public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
|
| 189 | - if( ! $line_item->is_percent() ) { |
|
| 190 | - $line_item->set_quantity( $new_quantity ); |
|
| 191 | - $line_item->set_total( $line_item->unit_price() * $new_quantity ); |
|
| 188 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) { |
|
| 189 | + if ( ! $line_item->is_percent()) { |
|
| 190 | + $line_item->set_quantity($new_quantity); |
|
| 191 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
| 192 | 192 | } |
| 193 | - foreach( $line_item->children() as $child ) { |
|
| 194 | - if( $child->is_sub_line_item() ) { |
|
| 195 | - EEH_Line_Item::update_quantity( $child, $new_quantity ); |
|
| 193 | + foreach ($line_item->children() as $child) { |
|
| 194 | + if ($child->is_sub_line_item()) { |
|
| 195 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
| 196 | 196 | } |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -207,45 +207,45 @@ discard block |
||
| 207 | 207 | * @return \EE_Line_Item |
| 208 | 208 | * @throws \EE_Error |
| 209 | 209 | */ |
| 210 | - public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
| 210 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
| 211 | 211 | $datetimes = $ticket->datetimes(); |
| 212 | - $first_datetime = reset( $datetimes ); |
|
| 213 | - if( $first_datetime instanceof EE_Datetime && |
|
| 214 | - $first_datetime->event() instanceof EE_Event ) { |
|
| 212 | + $first_datetime = reset($datetimes); |
|
| 213 | + if ($first_datetime instanceof EE_Datetime && |
|
| 214 | + $first_datetime->event() instanceof EE_Event) { |
|
| 215 | 215 | $first_datetime_name = $first_datetime->event()->name(); |
| 216 | 216 | } else { |
| 217 | - $first_datetime_name = __( 'Event', 'event_espresso' ); |
|
| 217 | + $first_datetime_name = __('Event', 'event_espresso'); |
|
| 218 | 218 | } |
| 219 | - $event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name ); |
|
| 219 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
| 220 | 220 | // get event subtotal line |
| 221 | - $events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket ); |
|
| 222 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
| 223 | - throw new EE_Error( sprintf( __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) ); |
|
| 221 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
| 222 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
| 223 | + throw new EE_Error(sprintf(__('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), $ticket->ID(), $total_line_item->ID())); |
|
| 224 | 224 | } |
| 225 | 225 | // add $ticket to cart |
| 226 | - $line_item = EE_Line_Item::new_instance( array( |
|
| 226 | + $line_item = EE_Line_Item::new_instance(array( |
|
| 227 | 227 | 'LIN_name' => $ticket->name(), |
| 228 | - 'LIN_desc' => $ticket->description() != '' ? $ticket->description() . ' ' . $event : $event, |
|
| 228 | + 'LIN_desc' => $ticket->description() != '' ? $ticket->description().' '.$event : $event, |
|
| 229 | 229 | 'LIN_unit_price' => $ticket->price(), |
| 230 | 230 | 'LIN_quantity' => $qty, |
| 231 | 231 | 'LIN_is_taxable' => $ticket->taxable(), |
| 232 | - 'LIN_order' => count( $events_sub_total->children() ), |
|
| 232 | + 'LIN_order' => count($events_sub_total->children()), |
|
| 233 | 233 | 'LIN_total' => $ticket->price() * $qty, |
| 234 | 234 | 'LIN_type' => EEM_Line_Item::type_line_item, |
| 235 | 235 | 'OBJ_ID' => $ticket->ID(), |
| 236 | 236 | 'OBJ_type' => 'Ticket' |
| 237 | - ) ); |
|
| 237 | + )); |
|
| 238 | 238 | $line_item = apply_filters( |
| 239 | 239 | 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
| 240 | 240 | $line_item |
| 241 | 241 | ); |
| 242 | - $events_sub_total->add_child_line_item( $line_item ); |
|
| 242 | + $events_sub_total->add_child_line_item($line_item); |
|
| 243 | 243 | //now add the sub-line items |
| 244 | 244 | $running_total_for_ticket = 0; |
| 245 | - foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) { |
|
| 245 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
| 246 | 246 | $sign = $price->is_discount() ? -1 : 1; |
| 247 | 247 | $price_total = $price->is_percent() ? $running_total_for_ticket * $price->amount() / 100 : $price->amount() * $qty; |
| 248 | - $sub_line_item = EE_Line_Item::new_instance( array( |
|
| 248 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
| 249 | 249 | 'LIN_name' => $price->name(), |
| 250 | 250 | 'LIN_desc' => $price->desc(), |
| 251 | 251 | 'LIN_quantity' => $price->is_percent() ? null : $qty, |
@@ -255,18 +255,18 @@ discard block |
||
| 255 | 255 | 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
| 256 | 256 | 'OBJ_ID' => $price->ID(), |
| 257 | 257 | 'OBJ_type' => 'Price' |
| 258 | - ) ); |
|
| 258 | + )); |
|
| 259 | 259 | $sub_line_item = apply_filters( |
| 260 | 260 | 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
| 261 | 261 | $sub_line_item |
| 262 | 262 | ); |
| 263 | - if ( $price->is_percent() ) { |
|
| 264 | - $sub_line_item->set_percent( $sign * $price->amount() ); |
|
| 263 | + if ($price->is_percent()) { |
|
| 264 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
| 265 | 265 | } else { |
| 266 | - $sub_line_item->set_unit_price( $sign * $price->amount() ); |
|
| 266 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
| 267 | 267 | } |
| 268 | 268 | $running_total_for_ticket += $price_total; |
| 269 | - $line_item->add_child_line_item( $sub_line_item ); |
|
| 269 | + $line_item->add_child_line_item($sub_line_item); |
|
| 270 | 270 | } |
| 271 | 271 | return $line_item; |
| 272 | 272 | } |
@@ -284,11 +284,11 @@ discard block |
||
| 284 | 284 | * @param EE_Line_Item $item to be added |
| 285 | 285 | * @return boolean |
| 286 | 286 | */ |
| 287 | - public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
|
| 288 | - $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
|
| 289 | - if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
|
| 287 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) { |
|
| 288 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
| 289 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
| 290 | 290 | $success = $pre_tax_subtotal->add_child_line_item($item); |
| 291 | - }else{ |
|
| 291 | + } else { |
|
| 292 | 292 | return FALSE; |
| 293 | 293 | } |
| 294 | 294 | $total_line_item->recalculate_total_including_taxes(); |
@@ -302,9 +302,9 @@ discard block |
||
| 302 | 302 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
| 303 | 303 | * @return \EE_Line_Item |
| 304 | 304 | */ |
| 305 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
| 306 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
| 307 | - return $pre_tax_subtotal instanceof EE_Line_Item ? $pre_tax_subtotal : self::create_pre_tax_subtotal( $total_line_item ); |
|
| 305 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
| 306 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
| 307 | + return $pre_tax_subtotal instanceof EE_Line_Item ? $pre_tax_subtotal : self::create_pre_tax_subtotal($total_line_item); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | |
@@ -314,9 +314,9 @@ discard block |
||
| 314 | 314 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
| 315 | 315 | * @return \EE_Line_Item |
| 316 | 316 | */ |
| 317 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
| 318 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
| 319 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
| 317 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
| 318 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
| 319 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -327,12 +327,12 @@ discard block |
||
| 327 | 327 | * @param EE_Transaction $transaction |
| 328 | 328 | * @return void |
| 329 | 329 | */ |
| 330 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
| 331 | - if( $transaction ){ |
|
| 330 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
| 331 | + if ($transaction) { |
|
| 332 | 332 | /** @type EEM_Transaction $EEM_Transaction */ |
| 333 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
| 334 | - $transaction = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
| 335 | - $line_item->set_TXN_ID( $transaction ); |
|
| 333 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
| 334 | + $transaction = $EEM_Transaction->ensure_is_ID($transaction); |
|
| 335 | + $line_item->set_TXN_ID($transaction); |
|
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @param EE_Transaction $transaction |
| 346 | 346 | * @return \EE_Line_Item of type total |
| 347 | 347 | */ |
| 348 | - public static function create_total_line_item( $transaction = NULL ){ |
|
| 349 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
| 348 | + public static function create_total_line_item($transaction = NULL) { |
|
| 349 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
| 350 | 350 | 'LIN_code' => 'total', |
| 351 | 351 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
| 352 | 352 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -356,9 +356,9 @@ discard block |
||
| 356 | 356 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
| 357 | 357 | $total_line_item |
| 358 | 358 | ); |
| 359 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
| 360 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
| 361 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
| 359 | + self::set_TXN_ID($total_line_item, $transaction); |
|
| 360 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 361 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 362 | 362 | return $total_line_item; |
| 363 | 363 | } |
| 364 | 364 | |
@@ -370,19 +370,19 @@ discard block |
||
| 370 | 370 | * @param EE_Transaction $transaction |
| 371 | 371 | * @return EE_Line_Item |
| 372 | 372 | */ |
| 373 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
| 374 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
| 373 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 374 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
| 375 | 375 | 'LIN_code' => 'pre-tax-subtotal', |
| 376 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
| 376 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
| 377 | 377 | 'LIN_type' => EEM_Line_Item::type_sub_total |
| 378 | - ) ); |
|
| 378 | + )); |
|
| 379 | 379 | $pre_tax_line_item = apply_filters( |
| 380 | 380 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
| 381 | 381 | $pre_tax_line_item |
| 382 | 382 | ); |
| 383 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
| 384 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
| 385 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
| 383 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
| 384 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
| 385 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
| 386 | 386 | return $pre_tax_line_item; |
| 387 | 387 | } |
| 388 | 388 | |
@@ -395,21 +395,21 @@ discard block |
||
| 395 | 395 | * @param EE_Transaction $transaction |
| 396 | 396 | * @return EE_Line_Item |
| 397 | 397 | */ |
| 398 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
| 398 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 399 | 399 | $tax_line_item = EE_Line_Item::new_instance(array( |
| 400 | 400 | 'LIN_code' => 'taxes', |
| 401 | 401 | 'LIN_name' => __('Taxes', 'event_espresso'), |
| 402 | 402 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
| 403 | - 'LIN_order' => 1000,//this should always come last |
|
| 403 | + 'LIN_order' => 1000, //this should always come last |
|
| 404 | 404 | )); |
| 405 | 405 | $tax_line_item = apply_filters( |
| 406 | 406 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
| 407 | 407 | $tax_line_item |
| 408 | 408 | ); |
| 409 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
| 410 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
| 409 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
| 410 | + $total_line_item->add_child_line_item($tax_line_item); |
|
| 411 | 411 | //and lastly, add the actual taxes |
| 412 | - self::apply_taxes( $total_line_item ); |
|
| 412 | + self::apply_taxes($total_line_item); |
|
| 413 | 413 | return $tax_line_item; |
| 414 | 414 | } |
| 415 | 415 | |
@@ -422,11 +422,11 @@ discard block |
||
| 422 | 422 | * @param EE_Event $event |
| 423 | 423 | * @return EE_Line_Item |
| 424 | 424 | */ |
| 425 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
| 425 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
| 426 | 426 | $event_line_item = EE_Line_Item::new_instance(array( |
| 427 | - 'LIN_code' => self::get_event_code( $event ), |
|
| 428 | - 'LIN_name' => self::get_event_name( $event ), |
|
| 429 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
| 427 | + 'LIN_code' => self::get_event_code($event), |
|
| 428 | + 'LIN_name' => self::get_event_name($event), |
|
| 429 | + 'LIN_desc' => self::get_event_desc($event), |
|
| 430 | 430 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
| 431 | 431 | 'OBJ_type' => 'Event', |
| 432 | 432 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
| 436 | 436 | $event_line_item |
| 437 | 437 | ); |
| 438 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
| 439 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
| 438 | + self::set_TXN_ID($event_line_item, $transaction); |
|
| 439 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
| 440 | 440 | return $event_line_item; |
| 441 | 441 | } |
| 442 | 442 | |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | * @param EE_Event $event |
| 446 | 446 | * @return string |
| 447 | 447 | */ |
| 448 | - public static function get_event_code( $event ) { |
|
| 449 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
| 448 | + public static function get_event_code($event) { |
|
| 449 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -454,8 +454,8 @@ discard block |
||
| 454 | 454 | * @param EE_Event $event |
| 455 | 455 | * @return string |
| 456 | 456 | */ |
| 457 | - public static function get_event_name( $event ) { |
|
| 458 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
| 457 | + public static function get_event_name($event) { |
|
| 458 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | * @param EE_Event $event |
| 464 | 464 | * @return string |
| 465 | 465 | */ |
| 466 | - public static function get_event_desc( $event ) { |
|
| 466 | + public static function get_event_desc($event) { |
|
| 467 | 467 | return $event instanceof EE_Event ? $event->short_description() : ''; |
| 468 | 468 | } |
| 469 | 469 | |
@@ -477,16 +477,16 @@ discard block |
||
| 477 | 477 | * @throws \EE_Error |
| 478 | 478 | * @return EE_Line_Item |
| 479 | 479 | */ |
| 480 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
| 480 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
| 481 | 481 | $first_datetime = $ticket->first_datetime(); |
| 482 | - if( ! $first_datetime instanceof EE_Datetime ){ |
|
| 483 | - throw new EE_Error( sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) ); |
|
| 482 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
| 483 | + throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID())); |
|
| 484 | 484 | } |
| 485 | 485 | $event = $first_datetime->event(); |
| 486 | - if ( ! $event instanceof EE_Event ) { |
|
| 487 | - throw new EE_Error( sprintf( __( 'The supplied ticket (ID %d) has no event data associated with it.','event_espresso' ), $ticket->ID() ) ); |
|
| 486 | + if ( ! $event instanceof EE_Event) { |
|
| 487 | + throw new EE_Error(sprintf(__('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), $ticket->ID())); |
|
| 488 | 488 | } |
| 489 | - return EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
| 489 | + return EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /** |
@@ -495,31 +495,31 @@ discard block |
||
| 495 | 495 | * @param EE_Event $event |
| 496 | 496 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
| 497 | 497 | */ |
| 498 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
| 498 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
| 499 | 499 | /** @type EE_Event $event */ |
| 500 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
| 500 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
| 501 | 501 | $event_line_item = NULL; |
| 502 | 502 | $found = false; |
| 503 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
| 503 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
| 504 | 504 | // default event subtotal, we should only ever find this the first time this method is called |
| 505 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
| 505 | + if ( ! $event_line_item->OBJ_ID()) { |
|
| 506 | 506 | // let's use this! but first... set the event details |
| 507 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
| 507 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 508 | 508 | $found = true; |
| 509 | 509 | break; |
| 510 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
| 510 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
| 511 | 511 | // found existing line item for this event in the cart, so break out of loop and use this one |
| 512 | 512 | $found = true; |
| 513 | 513 | break; |
| 514 | 514 | } |
| 515 | 515 | } |
| 516 | - if ( ! $found ) { |
|
| 516 | + if ( ! $found) { |
|
| 517 | 517 | //there is no event sub-total yet, so add it |
| 518 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
| 518 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
| 519 | 519 | // create a new "event" subtotal below that |
| 520 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
| 520 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
| 521 | 521 | // and set the event details |
| 522 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
| 522 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
| 523 | 523 | } |
| 524 | 524 | return $event_line_item; |
| 525 | 525 | } |
@@ -533,14 +533,14 @@ discard block |
||
| 533 | 533 | * @param EE_Transaction $transaction |
| 534 | 534 | * @return EE_Line_Item |
| 535 | 535 | */ |
| 536 | - public static function set_event_subtotal_details( EE_Line_Item $event_line_item, EE_Event $event, $transaction = NULL ){ |
|
| 537 | - if ( $event instanceof EE_Event ) { |
|
| 538 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
| 539 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
| 540 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
| 541 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
| 536 | + public static function set_event_subtotal_details(EE_Line_Item $event_line_item, EE_Event $event, $transaction = NULL) { |
|
| 537 | + if ($event instanceof EE_Event) { |
|
| 538 | + $event_line_item->set_code(self::get_event_code($event)); |
|
| 539 | + $event_line_item->set_name(self::get_event_name($event)); |
|
| 540 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
| 541 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
| 542 | 542 | } |
| 543 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
| 543 | + self::set_TXN_ID($event_line_item, $transaction); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | |
@@ -551,19 +551,19 @@ discard block |
||
| 551 | 551 | * any old taxes are removed |
| 552 | 552 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
| 553 | 553 | */ |
| 554 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
| 554 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
| 555 | 555 | /** @type EEM_Price $EEM_Price */ |
| 556 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
| 556 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
| 557 | 557 | // get array of taxes via Price Model |
| 558 | 558 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
| 559 | - ksort( $ordered_taxes ); |
|
| 560 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
| 559 | + ksort($ordered_taxes); |
|
| 560 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
| 561 | 561 | //just to be safe, remove its old tax line items |
| 562 | 562 | $taxes_line_item->delete_children_line_items(); |
| 563 | 563 | //loop thru taxes |
| 564 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
| 565 | - foreach ( $taxes as $tax ) { |
|
| 566 | - if ( $tax instanceof EE_Price ) { |
|
| 564 | + foreach ($ordered_taxes as $order => $taxes) { |
|
| 565 | + foreach ($taxes as $tax) { |
|
| 566 | + if ($tax instanceof EE_Price) { |
|
| 567 | 567 | $tax_line_item = EE_Line_Item::new_instance( |
| 568 | 568 | array( |
| 569 | 569 | 'LIN_name' => $tax->name(), |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
| 582 | 582 | $tax_line_item |
| 583 | 583 | ); |
| 584 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
| 584 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
| 585 | 585 | } |
| 586 | 586 | } |
| 587 | 587 | } |
@@ -596,10 +596,10 @@ discard block |
||
| 596 | 596 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
| 597 | 597 | * @return float |
| 598 | 598 | */ |
| 599 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
| 600 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
| 601 | - if( ! $taxes_subtotal->children()){ |
|
| 602 | - self::apply_taxes( $total_line_item ); |
|
| 599 | + public static function ensure_taxes_applied($total_line_item) { |
|
| 600 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 601 | + if ( ! $taxes_subtotal->children()) { |
|
| 602 | + self::apply_taxes($total_line_item); |
|
| 603 | 603 | } |
| 604 | 604 | return $taxes_subtotal->total(); |
| 605 | 605 | } |
@@ -612,16 +612,16 @@ discard block |
||
| 612 | 612 | * @param EE_Line_Item $parent_line_item |
| 613 | 613 | * @return bool |
| 614 | 614 | */ |
| 615 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
| 615 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
| 616 | 616 | $deleted = 0; |
| 617 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
| 618 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 619 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
| 620 | - if ( $child_line_item->ID() ) { |
|
| 617 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 618 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 619 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
| 620 | + if ($child_line_item->ID()) { |
|
| 621 | 621 | $child_line_item->delete(); |
| 622 | - unset( $child_line_item ); |
|
| 622 | + unset($child_line_item); |
|
| 623 | 623 | } else { |
| 624 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
| 624 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
| 625 | 625 | } |
| 626 | 626 | $deleted++; |
| 627 | 627 | } |
@@ -643,25 +643,25 @@ discard block |
||
| 643 | 643 | * @param array|bool|string $line_item_codes |
| 644 | 644 | * @return int number of items successfully removed |
| 645 | 645 | */ |
| 646 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
| 646 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
| 647 | 647 | |
| 648 | - if( $total_line_item->type() != EEM_Line_Item::type_total ){ |
|
| 649 | - EE_Error::doing_it_wrong('EEH_Line_Item::delete_items', __( 'This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly', 'event_espresso' ), '4.6.18' ); |
|
| 648 | + if ($total_line_item->type() != EEM_Line_Item::type_total) { |
|
| 649 | + EE_Error::doing_it_wrong('EEH_Line_Item::delete_items', __('This static method should only be called with a TOTAL line item, otherwise we won\'t recalculate the totals correctly', 'event_espresso'), '4.6.18'); |
|
| 650 | 650 | } |
| 651 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 651 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 652 | 652 | |
| 653 | 653 | // check if only a single line_item_id was passed |
| 654 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
| 654 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
| 655 | 655 | // place single line_item_id in an array to appear as multiple line_item_ids |
| 656 | - $line_item_codes = array ( $line_item_codes ); |
|
| 656 | + $line_item_codes = array($line_item_codes); |
|
| 657 | 657 | } |
| 658 | 658 | $removals = 0; |
| 659 | 659 | // cycle thru line_item_ids |
| 660 | - foreach ( $line_item_codes as $line_item_id ) { |
|
| 660 | + foreach ($line_item_codes as $line_item_id) { |
|
| 661 | 661 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | - if ( $removals > 0 ) { |
|
| 664 | + if ($removals > 0) { |
|
| 665 | 665 | $total_line_item->recalculate_taxes_and_tax_total(); |
| 666 | 666 | return $removals; |
| 667 | 667 | } else { |
@@ -684,32 +684,32 @@ discard block |
||
| 684 | 684 | * $amount will be added onto it; otherwise will simply set the taxes to match $amount |
| 685 | 685 | * @return EE_Line_Item the new tax line item created |
| 686 | 686 | */ |
| 687 | - public static function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false ){ |
|
| 688 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
| 687 | + public static function set_total_tax_to(EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false) { |
|
| 688 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
| 689 | 689 | $taxable_total = $total_line_item->taxable_total(); |
| 690 | 690 | |
| 691 | - if( $add_to_existing_line_item ) { |
|
| 692 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
| 693 | - EEM_Line_Item::instance()->delete( array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) ); |
|
| 691 | + if ($add_to_existing_line_item) { |
|
| 692 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
| 693 | + EEM_Line_Item::instance()->delete(array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID()))); |
|
| 694 | 694 | } else { |
| 695 | 695 | $new_tax = null; |
| 696 | 696 | $tax_subtotal->delete_children_line_items(); |
| 697 | 697 | } |
| 698 | - if( $new_tax ) { |
|
| 699 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
| 700 | - $new_tax->set_percent( $taxable_total ? ( $new_tax->total() ) / $taxable_total * 100 : 0 ); |
|
| 698 | + if ($new_tax) { |
|
| 699 | + $new_tax->set_total($new_tax->total() + $amount); |
|
| 700 | + $new_tax->set_percent($taxable_total ? ($new_tax->total()) / $taxable_total * 100 : 0); |
|
| 701 | 701 | } else { |
| 702 | 702 | //no existing tax item. Create it |
| 703 | - $new_tax = EE_Line_Item::new_instance( array( |
|
| 703 | + $new_tax = EE_Line_Item::new_instance(array( |
|
| 704 | 704 | 'TXN_ID' => $total_line_item->TXN_ID(), |
| 705 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
| 705 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
| 706 | 706 | 'LIN_desc' => $description ? $description : '', |
| 707 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
| 707 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
| 708 | 708 | 'LIN_total' => $amount, |
| 709 | 709 | 'LIN_parent' => $tax_subtotal->ID(), |
| 710 | 710 | 'LIN_type' => EEM_Line_Item::type_tax, |
| 711 | 711 | 'LIN_code' => $code |
| 712 | - ) ); |
|
| 712 | + )); |
|
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | $new_tax = apply_filters( |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | $total_line_item |
| 719 | 719 | ); |
| 720 | 720 | $new_tax->save(); |
| 721 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
| 721 | + $tax_subtotal->set_total($new_tax->total()); |
|
| 722 | 722 | $tax_subtotal->save(); |
| 723 | 723 | $total_line_item->recalculate_total_including_taxes(); |
| 724 | 724 | return $new_tax; |
@@ -734,17 +734,17 @@ discard block |
||
| 734 | 734 | * it will be whitelisted (ie, except from becoming taxable) |
| 735 | 735 | * @param boolean $taxable |
| 736 | 736 | */ |
| 737 | - public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null ) { |
|
| 738 | - if( $code_substring_for_whitelist !== null ) { |
|
| 739 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
| 737 | + public static function set_line_items_taxable(EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null) { |
|
| 738 | + if ($code_substring_for_whitelist !== null) { |
|
| 739 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
| 740 | 740 | } else { |
| 741 | 741 | $whitelisted = false; |
| 742 | 742 | } |
| 743 | - if( $line_item->is_line_item() && ! $whitelisted ) { |
|
| 744 | - $line_item->set_is_taxable( $taxable ); |
|
| 743 | + if ($line_item->is_line_item() && ! $whitelisted) { |
|
| 744 | + $line_item->set_is_taxable($taxable); |
|
| 745 | 745 | } |
| 746 | - foreach( $line_item->children() as $child_line_item ) { |
|
| 747 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
| 746 | + foreach ($line_item->children() as $child_line_item) { |
|
| 747 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
| 748 | 748 | } |
| 749 | 749 | } |
| 750 | 750 | |
@@ -757,8 +757,8 @@ discard block |
||
| 757 | 757 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 758 | 758 | * @return EE_Line_Item[] |
| 759 | 759 | */ |
| 760 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
| 761 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
| 760 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
| 761 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | |
@@ -771,8 +771,8 @@ discard block |
||
| 771 | 771 | * @param string $obj_type |
| 772 | 772 | * @return EE_Line_Item[] |
| 773 | 773 | */ |
| 774 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
| 775 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_sub_total, $obj_type ); |
|
| 774 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
| 775 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_sub_total, $obj_type); |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | |
@@ -784,8 +784,8 @@ discard block |
||
| 784 | 784 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 785 | 785 | * @return EE_Line_Item[] |
| 786 | 786 | */ |
| 787 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
| 788 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
| 787 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
| 788 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | |
@@ -798,8 +798,8 @@ discard block |
||
| 798 | 798 | * @param string $obj_type |
| 799 | 799 | * @return EE_Line_Item[] |
| 800 | 800 | */ |
| 801 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
| 802 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
| 801 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
| 802 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
| 803 | 803 | } |
| 804 | 804 | |
| 805 | 805 | |
@@ -810,8 +810,8 @@ discard block |
||
| 810 | 810 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 811 | 811 | * @return EE_Line_Item[] |
| 812 | 812 | */ |
| 813 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
| 814 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
| 813 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
| 814 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | |
@@ -822,8 +822,8 @@ discard block |
||
| 822 | 822 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
| 823 | 823 | * @return EE_Line_Item[] |
| 824 | 824 | */ |
| 825 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
| 826 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
| 825 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
| 826 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | |
@@ -836,8 +836,8 @@ discard block |
||
| 836 | 836 | * @param string $line_item_type one of the EEM_Line_Item constants |
| 837 | 837 | * @return EE_Line_Item[] |
| 838 | 838 | */ |
| 839 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
| 840 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
| 839 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
| 840 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | |
@@ -850,15 +850,15 @@ discard block |
||
| 850 | 850 | * @param string | NULL $obj_type object model class name (minus prefix) or NULL to ignore object type when searching |
| 851 | 851 | * @return EE_Line_Item[] |
| 852 | 852 | */ |
| 853 | - protected static function _get_descendants_by_type_and_object_type( EE_Line_Item $parent_line_item, $line_item_type, $obj_type = NULL ) { |
|
| 853 | + protected static function _get_descendants_by_type_and_object_type(EE_Line_Item $parent_line_item, $line_item_type, $obj_type = NULL) { |
|
| 854 | 854 | $objects = array(); |
| 855 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
| 856 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 857 | - if ( $child_line_item->type() == $line_item_type && ( $child_line_item->OBJ_type() == $obj_type || $obj_type === NULL )) { |
|
| 855 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 856 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 857 | + if ($child_line_item->type() == $line_item_type && ($child_line_item->OBJ_type() == $obj_type || $obj_type === NULL)) { |
|
| 858 | 858 | $objects[] = $child_line_item; |
| 859 | 859 | } else { |
| 860 | 860 | //go-through-all-its children looking for more matches |
| 861 | - $objects = array_merge( $objects, self::_get_descendants_by_type_and_object_type( $child_line_item, $line_item_type, $obj_type )); |
|
| 861 | + $objects = array_merge($objects, self::_get_descendants_by_type_and_object_type($child_line_item, $line_item_type, $obj_type)); |
|
| 862 | 862 | } |
| 863 | 863 | } |
| 864 | 864 | } |
@@ -876,8 +876,8 @@ discard block |
||
| 876 | 876 | * @param array $OBJ_IDs array of OBJ_IDs |
| 877 | 877 | * @return EE_Line_Item[] |
| 878 | 878 | */ |
| 879 | - public static function get_line_items_by_object_type_and_IDs( EE_Line_Item $parent_line_item, $OBJ_type = '', $OBJ_IDs = array() ) { |
|
| 880 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
| 879 | + public static function get_line_items_by_object_type_and_IDs(EE_Line_Item $parent_line_item, $OBJ_type = '', $OBJ_IDs = array()) { |
|
| 880 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | |
@@ -890,15 +890,15 @@ discard block |
||
| 890 | 890 | * @param array $OBJ_IDs array of OBJ_IDs |
| 891 | 891 | * @return EE_Line_Item[] |
| 892 | 892 | */ |
| 893 | - protected static function _get_descendants_by_object_type_and_object_ID( EE_Line_Item $parent_line_item, $OBJ_type, $OBJ_IDs ) { |
|
| 893 | + protected static function _get_descendants_by_object_type_and_object_ID(EE_Line_Item $parent_line_item, $OBJ_type, $OBJ_IDs) { |
|
| 894 | 894 | $objects = array(); |
| 895 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
| 896 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
| 897 | - if ( is_array( $OBJ_IDs ) && $child_line_item->OBJ_type() == $OBJ_type && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs )) { |
|
| 895 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
| 896 | + if ($child_line_item instanceof EE_Line_Item) { |
|
| 897 | + if (is_array($OBJ_IDs) && $child_line_item->OBJ_type() == $OBJ_type && in_array($child_line_item->OBJ_ID(), $OBJ_IDs)) { |
|
| 898 | 898 | $objects[] = $child_line_item; |
| 899 | 899 | } else { |
| 900 | 900 | //go-through-all-its children looking for more matches |
| 901 | - $objects = array_merge( $objects, self::_get_descendants_by_object_type_and_object_ID( $child_line_item, $OBJ_type, $OBJ_IDs )); |
|
| 901 | + $objects = array_merge($objects, self::_get_descendants_by_object_type_and_object_ID($child_line_item, $OBJ_type, $OBJ_IDs)); |
|
| 902 | 902 | } |
| 903 | 903 | } |
| 904 | 904 | } |
@@ -916,8 +916,8 @@ discard block |
||
| 916 | 916 | * @param string $type like one of the EEM_Line_Item::type_* |
| 917 | 917 | * @return EE_Line_Item |
| 918 | 918 | */ |
| 919 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
| 920 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
| 919 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
| 920 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
| 921 | 921 | } |
| 922 | 922 | |
| 923 | 923 | |
@@ -930,8 +930,8 @@ discard block |
||
| 930 | 930 | * @param string $code any value used for LIN_code |
| 931 | 931 | * @return EE_Line_Item |
| 932 | 932 | */ |
| 933 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
| 934 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
| 933 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
| 934 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | |
@@ -944,15 +944,15 @@ discard block |
||
| 944 | 944 | * @param string $value any value stored in $search_field |
| 945 | 945 | * @return EE_Line_Item |
| 946 | 946 | */ |
| 947 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
| 948 | - foreach( $parent_line_item->children() as $child ){ |
|
| 949 | - if ( $child->get( $search_field ) == $value ){ |
|
| 947 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
| 948 | + foreach ($parent_line_item->children() as $child) { |
|
| 949 | + if ($child->get($search_field) == $value) { |
|
| 950 | 950 | return $child; |
| 951 | 951 | } |
| 952 | 952 | } |
| 953 | - foreach( $parent_line_item->children() as $child ){ |
|
| 954 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
| 955 | - if ( $descendant_found ){ |
|
| 953 | + foreach ($parent_line_item->children() as $child) { |
|
| 954 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
| 955 | + if ($descendant_found) { |
|
| 956 | 956 | return $descendant_found; |
| 957 | 957 | } |
| 958 | 958 | } |
@@ -968,22 +968,22 @@ discard block |
||
| 968 | 968 | * @param int $indentation |
| 969 | 969 | * @return void |
| 970 | 970 | */ |
| 971 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
| 971 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
| 972 | 972 | echo "\n<br />"; |
| 973 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
| 973 | + for ($i = 0; $i < $indentation; $i++) { |
|
| 974 | 974 | echo " - "; |
| 975 | 975 | } |
| 976 | - if( $line_item->is_percent() ) { |
|
| 977 | - $breakdown = $line_item->percent() . '%'; |
|
| 976 | + if ($line_item->is_percent()) { |
|
| 977 | + $breakdown = $line_item->percent().'%'; |
|
| 978 | 978 | } else { |
| 979 | - $breakdown = '$' . $line_item->unit_price() . "x" . $line_item->quantity(); |
|
| 979 | + $breakdown = '$'.$line_item->unit_price()."x".$line_item->quantity(); |
|
| 980 | 980 | } |
| 981 | - echo $line_item->name() . "( " . $line_item->ID() . " ) : " . $line_item->type() . " $" . $line_item->total() . "(" . $breakdown . ")"; |
|
| 982 | - if( $line_item->is_taxable() ){ |
|
| 981 | + echo $line_item->name()."( ".$line_item->ID()." ) : ".$line_item->type()." $".$line_item->total()."(".$breakdown.")"; |
|
| 982 | + if ($line_item->is_taxable()) { |
|
| 983 | 983 | echo " * taxable"; |
| 984 | 984 | } |
| 985 | - if( $line_item->children() ){ |
|
| 986 | - foreach($line_item->children() as $child){ |
|
| 985 | + if ($line_item->children()) { |
|
| 986 | + foreach ($line_item->children() as $child) { |
|
| 987 | 987 | self::visualize($child, $indentation + 1); |
| 988 | 988 | } |
| 989 | 989 | } |
@@ -1024,88 +1024,88 @@ discard block |
||
| 1024 | 1024 | * is theirs, which can be done with |
| 1025 | 1025 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
| 1026 | 1026 | */ |
| 1027 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
| 1027 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
| 1028 | 1028 | //init running grand total if not already |
| 1029 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
| 1030 | - $running_totals[ 'total' ] = 0; |
|
| 1029 | + if ( ! isset($running_totals['total'])) { |
|
| 1030 | + $running_totals['total'] = 0; |
|
| 1031 | 1031 | } |
| 1032 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
| 1033 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
| 1032 | + if ( ! isset($running_totals['taxable'])) { |
|
| 1033 | + $running_totals['taxable'] = array('total' => 0); |
|
| 1034 | 1034 | } |
| 1035 | - foreach ( $line_item->children() as $child_line_item ) { |
|
| 1036 | - switch ( $child_line_item->type() ) { |
|
| 1035 | + foreach ($line_item->children() as $child_line_item) { |
|
| 1036 | + switch ($child_line_item->type()) { |
|
| 1037 | 1037 | |
| 1038 | 1038 | case EEM_Line_Item::type_sub_total : |
| 1039 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
| 1039 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
| 1040 | 1040 | //combine arrays but preserve numeric keys |
| 1041 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
| 1042 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
| 1043 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
| 1041 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
| 1042 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
| 1043 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
| 1044 | 1044 | break; |
| 1045 | 1045 | |
| 1046 | 1046 | case EEM_Line_Item::type_tax_sub_total : |
| 1047 | 1047 | |
| 1048 | 1048 | //find how much the taxes percentage is |
| 1049 | - if ( $child_line_item->percent() != 0 ) { |
|
| 1049 | + if ($child_line_item->percent() != 0) { |
|
| 1050 | 1050 | $tax_percent_decimal = $child_line_item->percent() / 100; |
| 1051 | 1051 | } else { |
| 1052 | 1052 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
| 1053 | 1053 | } |
| 1054 | 1054 | //and apply to all the taxable totals, and add to the pretax totals |
| 1055 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
| 1055 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1056 | 1056 | //"total" and "taxable" array key is an exception |
| 1057 | - if ( $line_item_id === 'taxable' ) { |
|
| 1057 | + if ($line_item_id === 'taxable') { |
|
| 1058 | 1058 | continue; |
| 1059 | 1059 | } |
| 1060 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
| 1061 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
| 1060 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
| 1061 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
| 1062 | 1062 | } |
| 1063 | 1063 | break; |
| 1064 | 1064 | |
| 1065 | 1065 | case EEM_Line_Item::type_line_item : |
| 1066 | 1066 | |
| 1067 | 1067 | // ticket line items or ???? |
| 1068 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
| 1068 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
| 1069 | 1069 | // kk it's a ticket |
| 1070 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
| 1070 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
| 1071 | 1071 | //huh? that shouldn't happen. |
| 1072 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
| 1072 | + $running_totals['total'] += $child_line_item->total(); |
|
| 1073 | 1073 | } else { |
| 1074 | 1074 | //its not in our running totals yet. great. |
| 1075 | - if ( $child_line_item->is_taxable() ) { |
|
| 1075 | + if ($child_line_item->is_taxable()) { |
|
| 1076 | 1076 | $taxable_amount = $child_line_item->unit_price(); |
| 1077 | 1077 | } else { |
| 1078 | 1078 | $taxable_amount = 0; |
| 1079 | 1079 | } |
| 1080 | 1080 | // are we only calculating totals for some tickets? |
| 1081 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
| 1082 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
| 1083 | - $running_totals[ $child_line_item->ID() ] = $quantity ? $child_line_item->unit_price() : 0; |
|
| 1084 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity ? $taxable_amount : 0; |
|
| 1081 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
| 1082 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
| 1083 | + $running_totals[$child_line_item->ID()] = $quantity ? $child_line_item->unit_price() : 0; |
|
| 1084 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity ? $taxable_amount : 0; |
|
| 1085 | 1085 | } else { |
| 1086 | 1086 | $quantity = $child_line_item->quantity(); |
| 1087 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
| 1088 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
| 1087 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
| 1088 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
| 1089 | 1089 | } |
| 1090 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
| 1091 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
| 1090 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
| 1091 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
| 1092 | 1092 | } |
| 1093 | 1093 | } else { |
| 1094 | 1094 | // it's some other type of item added to the cart |
| 1095 | 1095 | // it should affect the running totals |
| 1096 | 1096 | // basically we want to convert it into a PERCENT modifier. Because |
| 1097 | 1097 | // more clearly affect all registration's final price equally |
| 1098 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 : 1; |
|
| 1099 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
| 1098 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 ? ($child_line_item->total() / $running_totals['total']) + 1 : 1; |
|
| 1099 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
| 1100 | 1100 | //the "taxable" array key is an exception |
| 1101 | - if ( $line_item_id === 'taxable' ) { |
|
| 1101 | + if ($line_item_id === 'taxable') { |
|
| 1102 | 1102 | continue; |
| 1103 | 1103 | } |
| 1104 | 1104 | // update the running totals |
| 1105 | 1105 | // yes this actually even works for the running grand total! |
| 1106 | - $running_totals[ $line_item_id ] = $line_items_percent_of_running_total * $this_running_total; |
|
| 1107 | - if ( $child_line_item->is_taxable() ) { |
|
| 1108 | - $running_totals[ 'taxable' ][ $line_item_id ] = $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
| 1106 | + $running_totals[$line_item_id] = $line_items_percent_of_running_total * $this_running_total; |
|
| 1107 | + if ($child_line_item->is_taxable()) { |
|
| 1108 | + $running_totals['taxable'][$line_item_id] = $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
| 1109 | 1109 | } |
| 1110 | 1110 | } |
| 1111 | 1111 | } |
@@ -1124,15 +1124,15 @@ discard block |
||
| 1124 | 1124 | * @param EE_Registration[] $registrations |
| 1125 | 1125 | * @return \EE_Line_Item |
| 1126 | 1126 | */ |
| 1127 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
| 1128 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
| 1129 | - foreach ( $line_item->children() as $child_li ) { |
|
| 1130 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
| 1127 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
| 1128 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
| 1129 | + foreach ($line_item->children() as $child_li) { |
|
| 1130 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | //if this is the grand total line item, make sure the totals all add up |
| 1133 | 1133 | //(we could have duplicated this logic AS we copied the line items, but |
| 1134 | 1134 | //it seems DRYer this way) |
| 1135 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
| 1135 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
| 1136 | 1136 | $copy_li->recalculate_total_including_taxes(); |
| 1137 | 1137 | } |
| 1138 | 1138 | return $copy_li; |
@@ -1147,26 +1147,26 @@ discard block |
||
| 1147 | 1147 | * @return EE_Line_Item |
| 1148 | 1148 | * @param EE_Registration[] $registrations |
| 1149 | 1149 | */ |
| 1150 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
| 1150 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
| 1151 | 1151 | $new_li_fields = $line_item->model_field_array(); |
| 1152 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1152 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1153 | 1153 | $line_item->OBJ_type() === 'Ticket' |
| 1154 | 1154 | ) { |
| 1155 | 1155 | $count = 0; |
| 1156 | - foreach ( $registrations as $registration ) { |
|
| 1157 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
| 1158 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
| 1156 | + foreach ($registrations as $registration) { |
|
| 1157 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
| 1158 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
| 1159 | 1159 | ) { |
| 1160 | 1160 | $count++; |
| 1161 | 1161 | } |
| 1162 | 1162 | } |
| 1163 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
| 1163 | + $new_li_fields['LIN_quantity'] = $count; |
|
| 1164 | 1164 | } |
| 1165 | 1165 | //don't set the total. We'll leave that up to the code that calculates it |
| 1166 | - unset( $new_li_fields[ 'LIN_ID' ] ); |
|
| 1167 | - unset( $new_li_fields[ 'LIN_parent' ] ); |
|
| 1168 | - unset( $new_li_fields[ 'LIN_total' ] ); |
|
| 1169 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
| 1166 | + unset($new_li_fields['LIN_ID']); |
|
| 1167 | + unset($new_li_fields['LIN_parent']); |
|
| 1168 | + unset($new_li_fields['LIN_total']); |
|
| 1169 | + return EE_Line_Item::new_instance($new_li_fields); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | |
@@ -1178,19 +1178,19 @@ discard block |
||
| 1178 | 1178 | * @param EE_Line_Item $line_item |null |
| 1179 | 1179 | * @return \EE_Line_Item|null |
| 1180 | 1180 | */ |
| 1181 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
| 1182 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
| 1183 | - if ( $copied_li === null ) { |
|
| 1181 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
| 1182 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
| 1183 | + if ($copied_li === null) { |
|
| 1184 | 1184 | return null; |
| 1185 | 1185 | } |
| 1186 | 1186 | //if this is an event subtotal, we want to only include it if it |
| 1187 | 1187 | //has a non-zero total and at least one ticket line item child |
| 1188 | 1188 | $ticket_children = 0; |
| 1189 | - foreach ( $line_item->children() as $child_li ) { |
|
| 1190 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
| 1191 | - if ( $child_li_copy !== null ) { |
|
| 1192 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
| 1193 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
| 1189 | + foreach ($line_item->children() as $child_li) { |
|
| 1190 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
| 1191 | + if ($child_li_copy !== null) { |
|
| 1192 | + $copied_li->add_child_line_item($child_li_copy); |
|
| 1193 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
| 1194 | 1194 | $child_li_copy->OBJ_type() === 'Ticket' |
| 1195 | 1195 | ) { |
| 1196 | 1196 | $ticket_children++; |
@@ -1199,7 +1199,7 @@ discard block |
||
| 1199 | 1199 | } |
| 1200 | 1200 | //if this is an event subtotal with NO ticket children |
| 1201 | 1201 | //we basically want to ignore it |
| 1202 | - if ( $line_item->type() === EEM_Line_Item::type_sub_total && |
|
| 1202 | + if ($line_item->type() === EEM_Line_Item::type_sub_total && |
|
| 1203 | 1203 | $line_item->OBJ_type() === 'Event' && |
| 1204 | 1204 | $ticket_children === 0 && |
| 1205 | 1205 | $line_item->total() === 0 |
@@ -1217,8 +1217,8 @@ discard block |
||
| 1217 | 1217 | * @param EE_Line_Item $line_item |
| 1218 | 1218 | * @return EE_Line_Item |
| 1219 | 1219 | */ |
| 1220 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
| 1221 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1220 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
| 1221 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
| 1222 | 1222 | $line_item->OBJ_type() === 'Ticket' && |
| 1223 | 1223 | $line_item->quantity() == 0 |
| 1224 | 1224 | ) { |
@@ -1226,9 +1226,9 @@ discard block |
||
| 1226 | 1226 | } |
| 1227 | 1227 | $new_li_fields = $line_item->model_field_array(); |
| 1228 | 1228 | //don't set the total. We'll leave that up to the code that calculates it |
| 1229 | - unset( $new_li_fields[ 'LIN_ID' ] ); |
|
| 1230 | - unset( $new_li_fields[ 'LIN_parent' ] ); |
|
| 1231 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
| 1229 | + unset($new_li_fields['LIN_ID']); |
|
| 1230 | + unset($new_li_fields['LIN_parent']); |
|
| 1231 | + return EE_Line_Item::new_instance($new_li_fields); |
|
| 1232 | 1232 | } |
| 1233 | 1233 | |
| 1234 | 1234 | |
@@ -1242,9 +1242,9 @@ discard block |
||
| 1242 | 1242 | * @param EE_Line_Item $total_line_item |
| 1243 | 1243 | * @return \EE_Line_Item |
| 1244 | 1244 | */ |
| 1245 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
| 1246 | - 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' ); |
|
| 1247 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
| 1245 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
| 1246 | + 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'); |
|
| 1247 | + return self::get_pre_tax_subtotal($total_line_item); |
|
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | |
@@ -1254,9 +1254,9 @@ discard block |
||
| 1254 | 1254 | * @param EE_Transaction $transaction |
| 1255 | 1255 | * @return \EE_Line_Item |
| 1256 | 1256 | */ |
| 1257 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
| 1258 | - 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' ); |
|
| 1259 | - return self::create_total_line_item( $transaction ); |
|
| 1257 | + public static function create_default_total_line_item($transaction = NULL) { |
|
| 1258 | + 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'); |
|
| 1259 | + return self::create_total_line_item($transaction); |
|
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | 1262 | |
@@ -1267,9 +1267,9 @@ discard block |
||
| 1267 | 1267 | * @param EE_Transaction $transaction |
| 1268 | 1268 | * @return \EE_Line_Item |
| 1269 | 1269 | */ |
| 1270 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1271 | - 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' ); |
|
| 1272 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
| 1270 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1271 | + 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'); |
|
| 1272 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | |
@@ -1280,9 +1280,9 @@ discard block |
||
| 1280 | 1280 | * @param EE_Transaction $transaction |
| 1281 | 1281 | * @return \EE_Line_Item |
| 1282 | 1282 | */ |
| 1283 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1284 | - 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' ); |
|
| 1285 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
| 1283 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1284 | + 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'); |
|
| 1285 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | |
@@ -1293,9 +1293,9 @@ discard block |
||
| 1293 | 1293 | * @param EE_Transaction $transaction |
| 1294 | 1294 | * @return \EE_Line_Item |
| 1295 | 1295 | */ |
| 1296 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1297 | - 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' ); |
|
| 1298 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
| 1296 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
| 1297 | + 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'); |
|
| 1298 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | 1301 | |
@@ -468,15 +468,15 @@ discard block |
||
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
| 471 | - * Given the grand total line item and a ticket, finds the event sub-total |
|
| 472 | - * line item the ticket's purchase should be added onto |
|
| 473 | - * |
|
| 474 | - * @access public |
|
| 475 | - * @param EE_Line_Item $grand_total the grand total line item |
|
| 476 | - * @param EE_Ticket $ticket |
|
| 477 | - * @throws \EE_Error |
|
| 478 | - * @return EE_Line_Item |
|
| 479 | - */ |
|
| 471 | + * Given the grand total line item and a ticket, finds the event sub-total |
|
| 472 | + * line item the ticket's purchase should be added onto |
|
| 473 | + * |
|
| 474 | + * @access public |
|
| 475 | + * @param EE_Line_Item $grand_total the grand total line item |
|
| 476 | + * @param EE_Ticket $ticket |
|
| 477 | + * @throws \EE_Error |
|
| 478 | + * @return EE_Line_Item |
|
| 479 | + */ |
|
| 480 | 480 | public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
| 481 | 481 | $first_datetime = $ticket->first_datetime(); |
| 482 | 482 | if( ! $first_datetime instanceof EE_Datetime ){ |
@@ -685,21 +685,21 @@ discard block |
||
| 685 | 685 | * @return EE_Line_Item the new tax line item created |
| 686 | 686 | */ |
| 687 | 687 | public static function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false ){ |
| 688 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
| 689 | - $taxable_total = $total_line_item->taxable_total(); |
|
| 690 | - |
|
| 691 | - if( $add_to_existing_line_item ) { |
|
| 692 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
| 693 | - EEM_Line_Item::instance()->delete( array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) ); |
|
| 694 | - } else { |
|
| 695 | - $new_tax = null; |
|
| 696 | - $tax_subtotal->delete_children_line_items(); |
|
| 697 | - } |
|
| 698 | - if( $new_tax ) { |
|
| 699 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
| 700 | - $new_tax->set_percent( $taxable_total ? ( $new_tax->total() ) / $taxable_total * 100 : 0 ); |
|
| 701 | - } else { |
|
| 702 | - //no existing tax item. Create it |
|
| 688 | + $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
| 689 | + $taxable_total = $total_line_item->taxable_total(); |
|
| 690 | + |
|
| 691 | + if( $add_to_existing_line_item ) { |
|
| 692 | + $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
| 693 | + EEM_Line_Item::instance()->delete( array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) ); |
|
| 694 | + } else { |
|
| 695 | + $new_tax = null; |
|
| 696 | + $tax_subtotal->delete_children_line_items(); |
|
| 697 | + } |
|
| 698 | + if( $new_tax ) { |
|
| 699 | + $new_tax->set_total( $new_tax->total() + $amount ); |
|
| 700 | + $new_tax->set_percent( $taxable_total ? ( $new_tax->total() ) / $taxable_total * 100 : 0 ); |
|
| 701 | + } else { |
|
| 702 | + //no existing tax item. Create it |
|
| 703 | 703 | $new_tax = EE_Line_Item::new_instance( array( |
| 704 | 704 | 'TXN_ID' => $total_line_item->TXN_ID(), |
| 705 | 705 | 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
@@ -712,16 +712,16 @@ discard block |
||
| 712 | 712 | ) ); |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | - $new_tax = apply_filters( |
|
| 715 | + $new_tax = apply_filters( |
|
| 716 | 716 | 'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal', |
| 717 | 717 | $new_tax, |
| 718 | 718 | $total_line_item |
| 719 | - ); |
|
| 720 | - $new_tax->save(); |
|
| 721 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
| 722 | - $tax_subtotal->save(); |
|
| 723 | - $total_line_item->recalculate_total_including_taxes(); |
|
| 724 | - return $new_tax; |
|
| 719 | + ); |
|
| 720 | + $new_tax->save(); |
|
| 721 | + $tax_subtotal->set_total( $new_tax->total() ); |
|
| 722 | + $tax_subtotal->save(); |
|
| 723 | + $total_line_item->recalculate_total_including_taxes(); |
|
| 724 | + return $new_tax; |
|
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | |
@@ -31,7 +31,6 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * google_map - creates a Google Map Link |
| 34 | - * @param array $atts aray of attributes required for the map link generation |
|
| 35 | 34 | * @return string (link to map!) |
| 36 | 35 | */ |
| 37 | 36 | public static function google_map( $ee_gmaps_opts ){ |
@@ -116,7 +115,6 @@ discard block |
||
| 116 | 115 | |
| 117 | 116 | /** |
| 118 | 117 | * creates a Google Map Link |
| 119 | - * @param array $atts aray of attributes required for the map link generation |
|
| 120 | 118 | * @return string (link to map!) |
| 121 | 119 | */ |
| 122 | 120 | public static function espresso_google_map_js() { |
@@ -34,20 +34,20 @@ discard block |
||
| 34 | 34 | * @param array $atts aray of attributes required for the map link generation |
| 35 | 35 | * @return string (link to map!) |
| 36 | 36 | */ |
| 37 | - public static function google_map( $ee_gmaps_opts ){ |
|
| 37 | + public static function google_map($ee_gmaps_opts) { |
|
| 38 | 38 | |
| 39 | 39 | //d( $ee_gmaps_opts ); |
| 40 | 40 | |
| 41 | - $ee_map_width = isset( $ee_gmaps_opts['ee_map_width'] ) && ! empty( $ee_gmaps_opts['ee_map_width'] ) ? $ee_gmaps_opts['ee_map_width'] : '300'; |
|
| 42 | - $ee_map_height = isset( $ee_gmaps_opts['ee_map_height'] ) && ! empty( $ee_gmaps_opts['ee_map_height'] ) ? $ee_gmaps_opts['ee_map_height'] : '185'; |
|
| 43 | - $ee_map_zoom = isset( $ee_gmaps_opts['ee_map_zoom'] ) && ! empty( $ee_gmaps_opts['ee_map_zoom'] ) ? $ee_gmaps_opts['ee_map_zoom'] : '12'; |
|
| 44 | - $ee_map_nav_display = isset( $ee_gmaps_opts['ee_map_nav_display'] ) && ! empty( $ee_gmaps_opts['ee_map_nav_display'] ) ? 'true' : 'false'; |
|
| 45 | - $ee_map_nav_size = isset( $ee_gmaps_opts['ee_map_nav_size'] ) && ! empty( $ee_gmaps_opts['ee_map_nav_size'] )? $ee_gmaps_opts['ee_map_nav_size'] : 'default'; |
|
| 46 | - $ee_map_type_control = isset( $ee_gmaps_opts['ee_map_type_control'] ) && ! empty( $ee_gmaps_opts['ee_map_type_control'] )? $ee_gmaps_opts['ee_map_type_control'] : 'default'; |
|
| 47 | - $static_url = isset( $ee_gmaps_opts['ee_static_url'] ) && ! empty( $ee_gmaps_opts['ee_static_url'] )? $ee_gmaps_opts['ee_static_url'] : FALSE; |
|
| 41 | + $ee_map_width = isset($ee_gmaps_opts['ee_map_width']) && ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300'; |
|
| 42 | + $ee_map_height = isset($ee_gmaps_opts['ee_map_height']) && ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185'; |
|
| 43 | + $ee_map_zoom = isset($ee_gmaps_opts['ee_map_zoom']) && ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12'; |
|
| 44 | + $ee_map_nav_display = isset($ee_gmaps_opts['ee_map_nav_display']) && ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false'; |
|
| 45 | + $ee_map_nav_size = isset($ee_gmaps_opts['ee_map_nav_size']) && ! empty($ee_gmaps_opts['ee_map_nav_size']) ? $ee_gmaps_opts['ee_map_nav_size'] : 'default'; |
|
| 46 | + $ee_map_type_control = isset($ee_gmaps_opts['ee_map_type_control']) && ! empty($ee_gmaps_opts['ee_map_type_control']) ? $ee_gmaps_opts['ee_map_type_control'] : 'default'; |
|
| 47 | + $static_url = isset($ee_gmaps_opts['ee_static_url']) && ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : FALSE; |
|
| 48 | 48 | |
| 49 | - if( isset( $ee_gmaps_opts['ee_map_align'] ) && ! empty( $ee_gmaps_opts['ee_map_align'] )){ |
|
| 50 | - switch( $ee_gmaps_opts['ee_map_align'] ){ |
|
| 49 | + if (isset($ee_gmaps_opts['ee_map_align']) && ! empty($ee_gmaps_opts['ee_map_align'])) { |
|
| 50 | + switch ($ee_gmaps_opts['ee_map_align']) { |
|
| 51 | 51 | case "left": |
| 52 | 52 | $map_align = 'ee-gmap-align-left left'; |
| 53 | 53 | break; |
@@ -68,18 +68,18 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | // Determine whether user has set a hardoded url to use and |
| 70 | 70 | // if so display a Google static iframe map else run V3 api |
| 71 | - if( $static_url ) { |
|
| 71 | + if ($static_url) { |
|
| 72 | 72 | |
| 73 | - $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">'; |
|
| 74 | - $html .= '<iframe src="' . $static_url . '&output=embed" style="width: ' . $ee_map_width .'px; height: ' . $ee_map_height . 'px;" frameborder="0" scrolling="no">'; |
|
| 73 | + $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper '.$map_align.'">'; |
|
| 74 | + $html .= '<iframe src="'.$static_url.'&output=embed" style="width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;" frameborder="0" scrolling="no">'; |
|
| 75 | 75 | $html .= '</iframe>'; |
| 76 | - $html .= '<a href="' . $static_url . '">View Large map</a>'; |
|
| 76 | + $html .= '<a href="'.$static_url.'">View Large map</a>'; |
|
| 77 | 77 | $html .= '</div>'; |
| 78 | 78 | return $html; |
| 79 | 79 | |
| 80 | 80 | } else { |
| 81 | 81 | |
| 82 | - EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = array( |
|
| 82 | + EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = array( |
|
| 83 | 83 | 'map_ID' => $ee_gmaps_opts['map_ID'], |
| 84 | 84 | 'ee_map_zoom' => $ee_map_zoom, |
| 85 | 85 | 'ee_map_nav_display' => $ee_map_nav_display, |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | 91 | $html = '<div class="ee-gmap-wrapper '.$map_align.';">'; |
| 92 | - $html .= '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] .'" style="width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;"></div>'; // |
|
| 92 | + $html .= '<div class="ee-gmap" id="map_canvas_'.$ee_gmaps_opts['map_ID'].'" style="width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;"></div>'; // |
|
| 93 | 93 | $html .= '</div>'; |
| 94 | 94 | |
| 95 | - wp_enqueue_script( 'gmap_api' ); |
|
| 96 | - wp_enqueue_script( 'ee_gmap' ); |
|
| 97 | - add_action( 'wp_footer', array( 'EEH_Maps', 'footer_enqueue_script' )); |
|
| 95 | + wp_enqueue_script('gmap_api'); |
|
| 96 | + wp_enqueue_script('ee_gmap'); |
|
| 97 | + add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script')); |
|
| 98 | 98 | |
| 99 | 99 | return $html; |
| 100 | 100 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * @return void |
| 110 | 110 | */ |
| 111 | 111 | public static function footer_enqueue_script() { |
| 112 | - wp_localize_script( 'ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars ); |
|
| 112 | + wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public static function espresso_google_map_js() { |
| 123 | 123 | $scheme = is_ssl() ? 'https://' : 'http://'; |
| 124 | - wp_register_script( 'gmap_api', $scheme . 'maps.google.com/maps/api/js?sensor=false', array('jquery'), NULL, TRUE ); |
|
| 125 | - wp_register_script( 'ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', TRUE ); |
|
| 124 | + wp_register_script('gmap_api', $scheme.'maps.google.com/maps/api/js?sensor=false', array('jquery'), NULL, TRUE); |
|
| 125 | + wp_register_script('ee_gmap', plugin_dir_url(__FILE__).'assets/ee_gmap.js', array('gmap_api'), '1.0', TRUE); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @return string (link to map!) |
| 132 | 132 | */ |
| 133 | 133 | public static function google_map_link($atts) { |
| 134 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
| 134 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 135 | 135 | extract($atts); |
| 136 | 136 | |
| 137 | 137 | $address = "{$address}"; |
@@ -146,9 +146,9 @@ discard block |
||
| 146 | 146 | $id = isset($id) ? $id : 'not_set'; |
| 147 | 147 | $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
| 148 | 148 | |
| 149 | - $address_string = ($address != '' ? $address : '') . ($city != '' ? ',' . $city : '') . ($state != '' ? ',' . $state : '') . ($zip != '' ? ',' . $zip : '') . ($country != '' ? ',' . $country : ''); |
|
| 149 | + $address_string = ($address != '' ? $address : '').($city != '' ? ','.$city : '').($state != '' ? ','.$state : '').($zip != '' ? ','.$zip : '').($country != '' ? ','.$country : ''); |
|
| 150 | 150 | |
| 151 | - $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode( $address_string )); |
|
| 151 | + $google_map = htmlentities2('http://maps.google.com/maps?q='.urlencode($address_string)); |
|
| 152 | 152 | |
| 153 | 153 | switch ($type) { |
| 154 | 154 | case 'text': |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | case 'map': |
| 164 | 164 | $scheme = is_ssl() ? 'https://' : 'http://'; |
| 165 | - return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2( $scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode( $address_string ) . '&zoom=14&size=' . $map_w . 'x' . $map_h . '&markers=color:green|label:|' . urlencode( $address_string ) . '&sensor=false' ) . '" /></a>'; |
|
| 165 | + return '<a class="a_map_image_link" href="'.$google_map.'" target="_blank">'.'<img class="map_image_link" id="venue_map_'.$id.'" '.$map_image_class.' src="'.htmlentities2($scheme.'maps.googleapis.com/maps/api/staticmap?center='.urlencode($address_string).'&zoom=14&size='.$map_w.'x'.$map_h.'&markers=color:green|label:|'.urlencode($address_string).'&sensor=false').'" /></a>'; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - return '<a href="' . $google_map . '" target="_blank">' . $text . '</a>'; |
|
| 168 | + return '<a href="'.$google_map.'" target="_blank">'.$text.'</a>'; |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | |
@@ -109,7 +109,7 @@ |
||
| 109 | 109 | * - registers and enqueues the qtip scripts and styles. |
| 110 | 110 | * |
| 111 | 111 | * @access public |
| 112 | - * @param array $paths Array of paths to check for the EE_Qtip class. If present we check these path(s) first. If not present (empty array), then it's assumed it's either in core/libraries/qtips OR the file is already loaded. |
|
| 112 | + * @param string[] $paths Array of paths to check for the EE_Qtip class. If present we check these path(s) first. If not present (empty array), then it's assumed it's either in core/libraries/qtips OR the file is already loaded. |
|
| 113 | 113 | * @param string|array $configname name of the Qtip class (full class name is expected and will be used for looking for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array, then we loop through the array to instantiate and setup the qtips] |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public static function instance() { |
| 34 | 34 | // check if class object is instantiated |
| 35 | - if ( self::$_instance === NULL or ! is_object( self::$_instance ) or ! ( self::$_instance instanceof EEH_Qtip_Loader )) { |
|
| 35 | + if (self::$_instance === NULL or ! is_object(self::$_instance) or ! (self::$_instance instanceof EEH_Qtip_Loader)) { |
|
| 36 | 36 | self::$_instance = new self(); |
| 37 | 37 | } |
| 38 | 38 | return self::$_instance; |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | private function __construct() { |
| 50 | 50 | //let's just make sure this is instantiated in the right place. |
| 51 | - if ( did_action( 'wp_print_styles' ) || did_action( 'admin_head' )) { |
|
| 52 | - EE_Error::doing_it_wrong( 'EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso' ), '4.1' ); |
|
| 51 | + if (did_action('wp_print_styles') || did_action('admin_head')) { |
|
| 52 | + EE_Error::doing_it_wrong('EEH_Qtip_Loader', __('This helper must be instantiated before or within a callback for the WordPress wp_enqueue_scripts hook action hook.', 'event_espresso'), '4.1'); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
@@ -61,27 +61,27 @@ discard block |
||
| 61 | 61 | * @return void |
| 62 | 62 | */ |
| 63 | 63 | public function register_and_enqueue() { |
| 64 | - $qtips_js = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.js'; |
|
| 65 | - $qtip_images_loaded = EE_THIRD_PARTY_URL . 'qtip/imagesloaded.pkg.min.js'; |
|
| 66 | - $qtip_map = EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.map'; |
|
| 67 | - $qtipcss = !defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL . 'qtip/jquery.qtip.css'; |
|
| 64 | + $qtips_js = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.js' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.js'; |
|
| 65 | + $qtip_images_loaded = EE_THIRD_PARTY_URL.'qtip/imagesloaded.pkg.min.js'; |
|
| 66 | + $qtip_map = EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.map'; |
|
| 67 | + $qtipcss = ! defined('SCRIPT_DEBUG') ? EE_THIRD_PARTY_URL.'qtip/jquery.qtip.min.css' : EE_THIRD_PARTY_URL.'qtip/jquery.qtip.css'; |
|
| 68 | 68 | |
| 69 | - wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE ); |
|
| 70 | - wp_register_script('qtip-images-loaded', $qtip_images_loaded, array(), '2.2.0', TRUE ); |
|
| 71 | - wp_register_script('qtip', $qtips_js, array('jquery'), '2.2.0', TRUE ); |
|
| 72 | - wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS . 'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE ); |
|
| 69 | + wp_register_script('qtip-map', $qtip_map, array(), '3', TRUE); |
|
| 70 | + wp_register_script('qtip-images-loaded', $qtip_images_loaded, array(), '2.2.0', TRUE); |
|
| 71 | + wp_register_script('qtip', $qtips_js, array('jquery'), '2.2.0', TRUE); |
|
| 72 | + wp_register_script('ee-qtip-helper', EE_HELPERS_ASSETS.'ee-qtip-helper.js', array('qtip', 'jquery-cookie'), EVENT_ESPRESSO_VERSION, TRUE); |
|
| 73 | 73 | |
| 74 | - wp_register_style('qtip-css', $qtipcss, array(), '2.2' ); |
|
| 74 | + wp_register_style('qtip-css', $qtipcss, array(), '2.2'); |
|
| 75 | 75 | |
| 76 | 76 | //k now let's see if there are any registered qtips. If there are, then we need to setup the localized script for ee-qtip-helper.js (and enqueue ee-qtip-helper.js of course!) |
| 77 | - if ( !empty( $this->_qtips ) ) { |
|
| 77 | + if ( ! empty($this->_qtips)) { |
|
| 78 | 78 | wp_enqueue_script('ee-qtip-helper'); |
| 79 | 79 | wp_enqueue_style('qtip-css'); |
| 80 | 80 | $qtips = array(); |
| 81 | - foreach ( $this->_qtips as $qtip ) { |
|
| 81 | + foreach ($this->_qtips as $qtip) { |
|
| 82 | 82 | $qts = $qtip->get_tips(); |
| 83 | - foreach ( $qts as $qt ) { |
|
| 84 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 83 | + foreach ($qts as $qt) { |
|
| 84 | + if ( ! $qt instanceof EE_Qtip) |
|
| 85 | 85 | continue; |
| 86 | 86 | $qtips[] = array( |
| 87 | 87 | 'content_id' => $qt->content_id, |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | ); |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | - if ( !empty($qtips) ) |
|
| 94 | - wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ) ); |
|
| 93 | + if ( ! empty($qtips)) |
|
| 94 | + wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array('qtips' => $qtips)); |
|
| 95 | 95 | |
| 96 | 96 | } else { |
| 97 | 97 | //qtips has been requested without any registration (so assuming its just directly used in the admin). |
@@ -113,24 +113,24 @@ discard block |
||
| 113 | 113 | * @param string|array $configname name of the Qtip class (full class name is expected and will be used for looking for file, Qtip config classes must extend EE_Qtip_Config) [if this is an array, then we loop through the array to instantiate and setup the qtips] |
| 114 | 114 | * @return void |
| 115 | 115 | */ |
| 116 | - public function register( $configname, $paths = array() ) { |
|
| 116 | + public function register($configname, $paths = array()) { |
|
| 117 | 117 | |
| 118 | 118 | //let's just make sure this is instantiated in the right place. |
| 119 | - if ( did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts') ) { |
|
| 120 | - EE_Error::doing_it_wrong( 'EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso' ), '4.1' ); |
|
| 119 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
| 120 | + EE_Error::doing_it_wrong('EEH_Qtip_Loader->register()', __('EE_Qtip_Config objects must be registered before wp_enqueue_scripts is called.', 'event_espresso'), '4.1'); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $configname = (array) $configname; //typecast to array |
| 124 | - foreach ( $configname as $config ) { |
|
| 125 | - $this->_register( $config, $paths ); |
|
| 124 | + foreach ($configname as $config) { |
|
| 125 | + $this->_register($config, $paths); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | //hook into appropriate footer |
| 129 | 129 | $footer_action = is_admin() ? 'admin_footer' : 'wp_footer'; |
| 130 | - add_action($footer_action, array($this, 'setup_qtip'), 10 ); |
|
| 130 | + add_action($footer_action, array($this, 'setup_qtip'), 10); |
|
| 131 | 131 | |
| 132 | 132 | //make sure we "turn on" qtip js. |
| 133 | - add_filter('FHEE_load_qtip', '__return_true' ); |
|
| 133 | + add_filter('FHEE_load_qtip', '__return_true'); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | |
@@ -144,15 +144,15 @@ discard block |
||
| 144 | 144 | * @throws EE_Error |
| 145 | 145 | * @return void |
| 146 | 146 | */ |
| 147 | - private function _register( $config, $paths ) { |
|
| 147 | + private function _register($config, $paths) { |
|
| 148 | 148 | //before doing anything we have to make sure that EE_Qtip_Config parent is required. |
| 149 | - EE_Registry::instance()->load_lib( 'Qtip_Config', array(), TRUE ); |
|
| 149 | + EE_Registry::instance()->load_lib('Qtip_Config', array(), TRUE); |
|
| 150 | 150 | |
| 151 | - if ( !empty( $paths ) ) { |
|
| 151 | + if ( ! empty($paths)) { |
|
| 152 | 152 | $paths = (array) $paths; |
| 153 | - foreach ( $paths as $path ) { |
|
| 154 | - $path = $path . $config . '.lib.php'; |
|
| 155 | - if ( !is_readable($path ) ) { |
|
| 153 | + foreach ($paths as $path) { |
|
| 154 | + $path = $path.$config.'.lib.php'; |
|
| 155 | + if ( ! is_readable($path)) { |
|
| 156 | 156 | continue; |
| 157 | 157 | } else { |
| 158 | 158 | require_once $path; |
@@ -161,26 +161,26 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | //does class exist at this point? If it does then let's instantiate. If it doesn't then let's continue with other paths. |
| 164 | - if ( !class_exists($config) ) { |
|
| 165 | - $path = EE_LIBRARIES . 'qtips/' . $config . '.lib.php'; |
|
| 166 | - if ( !is_readable($path ) ) { |
|
| 167 | - throw new EE_Error( sprintf( __('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable. Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config ) ); |
|
| 164 | + if ( ! class_exists($config)) { |
|
| 165 | + $path = EE_LIBRARIES.'qtips/'.$config.'.lib.php'; |
|
| 166 | + if ( ! is_readable($path)) { |
|
| 167 | + throw new EE_Error(sprintf(__('Unable to load the Qtip Config registered for this page (%s) because none of the file paths attempted are readable. Please check the spelling of the paths you\'ve used in the registration', 'event_espresso'), $config)); |
|
| 168 | 168 | } else { |
| 169 | 169 | require_once $path; |
| 170 | 170 | } |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | //now we attempt a class_exists one more time. |
| 174 | - if ( !class_exists( $config ) ) |
|
| 175 | - throw new EE_Error( sprintf( __('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config ) ); |
|
| 174 | + if ( ! class_exists($config)) |
|
| 175 | + throw new EE_Error(sprintf(__('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config)); |
|
| 176 | 176 | |
| 177 | 177 | //made it HERE? FINALLY, let's get things setup. |
| 178 | 178 | $a = new ReflectionClass($config); |
| 179 | 179 | $qtip = $a->newInstance(); |
| 180 | 180 | |
| 181 | 181 | //verify that $qtip is a valid object |
| 182 | - if ( ! $qtip instanceof EE_Qtip_Config ) |
|
| 183 | - throw new EE_Error( sprintf( __( 'The class given for the Qtip loader (%s) is not a child of the <strong>EE_Qtip_Config</strong> class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config ) ); |
|
| 182 | + if ( ! $qtip instanceof EE_Qtip_Config) |
|
| 183 | + throw new EE_Error(sprintf(__('The class given for the Qtip loader (%s) is not a child of the <strong>EE_Qtip_Config</strong> class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config)); |
|
| 184 | 184 | |
| 185 | 185 | $this->_qtips[] = $a->newInstance(); |
| 186 | 186 | |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | * @return void |
| 197 | 197 | */ |
| 198 | 198 | public function setup_qtip() { |
| 199 | - if ( empty( $this->_qtips ) ) |
|
| 199 | + if (empty($this->_qtips)) |
|
| 200 | 200 | return; //no qtips! |
| 201 | 201 | |
| 202 | 202 | $content = array(); |
| 203 | 203 | |
| 204 | - foreach ( $this->_qtips as $qtip ) { |
|
| 204 | + foreach ($this->_qtips as $qtip) { |
|
| 205 | 205 | $content[] = $this->_generate_content_container($qtip); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -218,10 +218,10 @@ discard block |
||
| 218 | 218 | private function _generate_content_container($qtip) { |
| 219 | 219 | $qts = $qtip->get_tips(); |
| 220 | 220 | $content = array(); |
| 221 | - foreach ( $qts as $qt ) { |
|
| 222 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 221 | + foreach ($qts as $qt) { |
|
| 222 | + if ( ! $qt instanceof EE_Qtip) |
|
| 223 | 223 | continue; |
| 224 | - $content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>'; |
|
| 224 | + $content[] = '<div class="ee-qtip-helper-content hidden" id="'.$qt->content_id.'">'.$qt->content.'</div>'; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | return implode('<br />', $content); |
@@ -81,8 +81,9 @@ discard block |
||
| 81 | 81 | foreach ( $this->_qtips as $qtip ) { |
| 82 | 82 | $qts = $qtip->get_tips(); |
| 83 | 83 | foreach ( $qts as $qt ) { |
| 84 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 85 | - continue; |
|
| 84 | + if ( ! $qt instanceof EE_Qtip ) { |
|
| 85 | + continue; |
|
| 86 | + } |
|
| 86 | 87 | $qtips[] = array( |
| 87 | 88 | 'content_id' => $qt->content_id, |
| 88 | 89 | 'options' => $qt->options, |
@@ -90,8 +91,9 @@ discard block |
||
| 90 | 91 | ); |
| 91 | 92 | } |
| 92 | 93 | } |
| 93 | - if ( !empty($qtips) ) |
|
| 94 | - wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ) ); |
|
| 94 | + if ( !empty($qtips) ) { |
|
| 95 | + wp_localize_script('ee-qtip-helper', 'EE_QTIP_HELPER', array( 'qtips' => $qtips ) ); |
|
| 96 | + } |
|
| 95 | 97 | |
| 96 | 98 | } else { |
| 97 | 99 | //qtips has been requested without any registration (so assuming its just directly used in the admin). |
@@ -171,16 +173,18 @@ discard block |
||
| 171 | 173 | } |
| 172 | 174 | |
| 173 | 175 | //now we attempt a class_exists one more time. |
| 174 | - if ( !class_exists( $config ) ) |
|
| 175 | - throw new EE_Error( sprintf( __('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config ) ); |
|
| 176 | + if ( !class_exists( $config ) ) { |
|
| 177 | + throw new EE_Error( sprintf( __('The Qtip_Config class being registered (%s) does not exist, please check the spelling.', 'event_espresso'), $config ) ); |
|
| 178 | + } |
|
| 176 | 179 | |
| 177 | 180 | //made it HERE? FINALLY, let's get things setup. |
| 178 | 181 | $a = new ReflectionClass($config); |
| 179 | 182 | $qtip = $a->newInstance(); |
| 180 | 183 | |
| 181 | 184 | //verify that $qtip is a valid object |
| 182 | - if ( ! $qtip instanceof EE_Qtip_Config ) |
|
| 183 | - throw new EE_Error( sprintf( __( 'The class given for the Qtip loader (%s) is not a child of the <strong>EE_Qtip_Config</strong> class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config ) ); |
|
| 185 | + if ( ! $qtip instanceof EE_Qtip_Config ) { |
|
| 186 | + throw new EE_Error( sprintf( __( 'The class given for the Qtip loader (%s) is not a child of the <strong>EE_Qtip_Config</strong> class. Please make sure you are extending EE_Qtip_Config.', 'event_espresso'), $config ) ); |
|
| 187 | + } |
|
| 184 | 188 | |
| 185 | 189 | $this->_qtips[] = $a->newInstance(); |
| 186 | 190 | |
@@ -196,8 +200,10 @@ discard block |
||
| 196 | 200 | * @return void |
| 197 | 201 | */ |
| 198 | 202 | public function setup_qtip() { |
| 199 | - if ( empty( $this->_qtips ) ) |
|
| 200 | - return; //no qtips! |
|
| 203 | + if ( empty( $this->_qtips ) ) { |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + //no qtips! |
|
| 201 | 207 | |
| 202 | 208 | $content = array(); |
| 203 | 209 | |
@@ -219,8 +225,9 @@ discard block |
||
| 219 | 225 | $qts = $qtip->get_tips(); |
| 220 | 226 | $content = array(); |
| 221 | 227 | foreach ( $qts as $qt ) { |
| 222 | - if ( ! $qt instanceof EE_Qtip ) |
|
| 223 | - continue; |
|
| 228 | + if ( ! $qt instanceof EE_Qtip ) { |
|
| 229 | + continue; |
|
| 230 | + } |
|
| 224 | 231 | $content[] = '<div class="ee-qtip-helper-content hidden" id="' . $qt->content_id . '">' . $qt->content . '</div>'; |
| 225 | 232 | } |
| 226 | 233 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | /** |
| 132 | 132 | * For verifying that a variable is indeed an array, else throw an EE_Error |
| 133 | 133 | * @param type $variable_to_test |
| 134 | - * @param type $variable_name |
|
| 134 | + * @param string $variable_name |
|
| 135 | 135 | * @param type $allow_empty one of 'allow_empty' or 'do_not_allow_empty' |
| 136 | 136 | * @return void |
| 137 | 137 | * @throws EE_Error |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * for verifying that a variable is one of the string optiosn supplied |
| 160 | 160 | * @param mixed $variable_to_test |
| 161 | 161 | * @param mixed $variable_name the name you've given the variable. Eg, '$foo'. THis helps in producing better error messages |
| 162 | - * @param array $string_options an array of acceptable values |
|
| 162 | + * @param string[] $string_options an array of acceptable values |
|
| 163 | 163 | * @return void |
| 164 | 164 | * @throws EE_Error |
| 165 | 165 | */ |
@@ -50,14 +50,14 @@ discard block |
||
| 50 | 50 | * @return void |
| 51 | 51 | * @throws EE_Error (indirectly) |
| 52 | 52 | */ |
| 53 | - static function verify_is_array_of($variable_to_test,$name_of_variable,$class_name,$allow_null='allow_null'){ |
|
| 54 | - if(!WP_DEBUG)return; |
|
| 55 | - self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null')); |
|
| 56 | - if('allow_null' == $allow_null && is_null($variable_to_test)){ |
|
| 53 | + static function verify_is_array_of($variable_to_test, $name_of_variable, $class_name, $allow_null = 'allow_null') { |
|
| 54 | + if ( ! WP_DEBUG)return; |
|
| 55 | + self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null')); |
|
| 56 | + if ('allow_null' == $allow_null && is_null($variable_to_test)) { |
|
| 57 | 57 | return; |
| 58 | 58 | } |
| 59 | 59 | self::verify_is_array($variable_to_test, $name_of_variable); |
| 60 | - foreach($variable_to_test as $key=>$array_element){ |
|
| 60 | + foreach ($variable_to_test as $key=>$array_element) { |
|
| 61 | 61 | self::verify_instanceof($array_element, $key, $class_name); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | * @return void |
| 74 | 74 | * @throws EE_Error |
| 75 | 75 | */ |
| 76 | - static function verify_isnt_null($variable_to_test,$name_of_variable){ |
|
| 77 | - if(!WP_DEBUG)return; |
|
| 78 | - if($variable_to_test==null && $variable_to_test!=0 && $variable_to_test!=FALSE){ |
|
| 79 | - $error[]=__('Variable named %s is null.','event_espresso'); |
|
| 80 | - $error[]=__("Consider looking at the stack trace to see why it wasn't set.",'event_espresso'); |
|
| 81 | - throw new EE_Error(sprintf(implode(",",$error),$name_of_variable,$name_of_variable)); |
|
| 76 | + static function verify_isnt_null($variable_to_test, $name_of_variable) { |
|
| 77 | + if ( ! WP_DEBUG)return; |
|
| 78 | + if ($variable_to_test == null && $variable_to_test != 0 && $variable_to_test != FALSE) { |
|
| 79 | + $error[] = __('Variable named %s is null.', 'event_espresso'); |
|
| 80 | + $error[] = __("Consider looking at the stack trace to see why it wasn't set.", 'event_espresso'); |
|
| 81 | + throw new EE_Error(sprintf(implode(",", $error), $name_of_variable, $name_of_variable)); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | * @return void |
| 91 | 91 | * @throws EE_Error |
| 92 | 92 | */ |
| 93 | - static function verify_is_true($expression_to_test,$expression_string_representation){ |
|
| 94 | - if(!WP_DEBUG)return; |
|
| 95 | - if(!$expression_to_test){ |
|
| 96 | - $error[]=__('Template error.','event_espresso'); |
|
| 97 | - $error[]=__("%s evaluated to false, but it must be true!",'event_espresso'); |
|
| 98 | - throw new EE_Error(sprintf(implode(",",$error),$expression_string_representation)); |
|
| 93 | + static function verify_is_true($expression_to_test, $expression_string_representation) { |
|
| 94 | + if ( ! WP_DEBUG)return; |
|
| 95 | + if ( ! $expression_to_test) { |
|
| 96 | + $error[] = __('Template error.', 'event_espresso'); |
|
| 97 | + $error[] = __("%s evaluated to false, but it must be true!", 'event_espresso'); |
|
| 98 | + throw new EE_Error(sprintf(implode(",", $error), $expression_string_representation)); |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
@@ -111,16 +111,16 @@ discard block |
||
| 111 | 111 | * @return void |
| 112 | 112 | * @throws EE_Error |
| 113 | 113 | */ |
| 114 | - static function verify_instanceof($variable_to_test,$name_of_variable,$class_name, $allow_null = 'do_not_allow_null'){ |
|
| 115 | - if(!WP_DEBUG)return; |
|
| 116 | - self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null')); |
|
| 117 | - if($allow_null == 'allow_null' && is_null($variable_to_test)){ |
|
| 114 | + static function verify_instanceof($variable_to_test, $name_of_variable, $class_name, $allow_null = 'do_not_allow_null') { |
|
| 115 | + if ( ! WP_DEBUG)return; |
|
| 116 | + self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null', 'do_not_allow_null')); |
|
| 117 | + if ($allow_null == 'allow_null' && is_null($variable_to_test)) { |
|
| 118 | 118 | return; |
| 119 | 119 | } |
| 120 | - if( $variable_to_test == NULL || ! ( $variable_to_test instanceof $class_name )){ |
|
| 121 | - $msg[]=__('Variable %s is not of the correct type.','event_espresso'); |
|
| 122 | - $msg[]=__("It should be of type %s",'event_espresso'); |
|
| 123 | - throw new EE_Error(sprintf(implode(",",$msg),$name_of_variable,$name_of_variable,$class_name)); |
|
| 120 | + if ($variable_to_test == NULL || ! ($variable_to_test instanceof $class_name)) { |
|
| 121 | + $msg[] = __('Variable %s is not of the correct type.', 'event_espresso'); |
|
| 122 | + $msg[] = __("It should be of type %s", 'event_espresso'); |
|
| 123 | + throw new EE_Error(sprintf(implode(",", $msg), $name_of_variable, $name_of_variable, $class_name)); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -136,16 +136,16 @@ discard block |
||
| 136 | 136 | * @return void |
| 137 | 137 | * @throws EE_Error |
| 138 | 138 | */ |
| 139 | - static function verify_is_array($variable_to_test,$variable_name,$allow_empty='allow_empty'){ |
|
| 140 | - if(!WP_DEBUG)return; |
|
| 141 | - self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty')); |
|
| 142 | - if(empty($variable_to_test) && 'allow_empty'==$allow_empty){ |
|
| 139 | + static function verify_is_array($variable_to_test, $variable_name, $allow_empty = 'allow_empty') { |
|
| 140 | + if ( ! WP_DEBUG)return; |
|
| 141 | + self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty', 'do_not_allow_empty')); |
|
| 142 | + if (empty($variable_to_test) && 'allow_empty' == $allow_empty) { |
|
| 143 | 143 | return; |
| 144 | 144 | } |
| 145 | - if(!is_array($variable_to_test)){ |
|
| 146 | - $error[]=__('Variable %s should be an array, but it is not.'); |
|
| 147 | - $error[]=__("Its value is, instead '%s'",'event_espresso'); |
|
| 148 | - throw new EE_Error(sprintf(implode(",",$error),$variable_name,$variable_name,$variable_to_test)); |
|
| 145 | + if ( ! is_array($variable_to_test)) { |
|
| 146 | + $error[] = __('Variable %s should be an array, but it is not.'); |
|
| 147 | + $error[] = __("Its value is, instead '%s'", 'event_espresso'); |
|
| 148 | + throw new EE_Error(sprintf(implode(",", $error), $variable_name, $variable_name, $variable_to_test)); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
@@ -163,12 +163,12 @@ discard block |
||
| 163 | 163 | * @return void |
| 164 | 164 | * @throws EE_Error |
| 165 | 165 | */ |
| 166 | - static function verify_argument_is_one_of($variable_to_test,$variable_name,$string_options){ |
|
| 167 | - if(!WP_DEBUG)return; |
|
| 168 | - if(!in_array($variable_to_test,$string_options)){ |
|
| 169 | - $msg[0]=__('Malconfigured template.','event_espresso'); |
|
| 170 | - $msg[1]=__("Variable named '%s' was set to '%s'. It can only be one of '%s'",'event_espresso'); |
|
| 171 | - throw new EE_Error(sprintf(implode("||",$msg),$variable_name,$variable_to_test, implode("', '",$string_options))); |
|
| 166 | + static function verify_argument_is_one_of($variable_to_test, $variable_name, $string_options) { |
|
| 167 | + if ( ! WP_DEBUG)return; |
|
| 168 | + if ( ! in_array($variable_to_test, $string_options)) { |
|
| 169 | + $msg[0] = __('Malconfigured template.', 'event_espresso'); |
|
| 170 | + $msg[1] = __("Variable named '%s' was set to '%s'. It can only be one of '%s'", 'event_espresso'); |
|
| 171 | + throw new EE_Error(sprintf(implode("||", $msg), $variable_name, $variable_to_test, implode("', '", $string_options))); |
|
| 172 | 172 | } |
| 173 | 173 | } |
| 174 | 174 | |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | |
| 3 | 5 | /** |
| 4 | 6 | * Event Espresso |
@@ -51,7 +53,9 @@ discard block |
||
| 51 | 53 | * @throws EE_Error (indirectly) |
| 52 | 54 | */ |
| 53 | 55 | static function verify_is_array_of($variable_to_test,$name_of_variable,$class_name,$allow_null='allow_null'){ |
| 54 | - if(!WP_DEBUG)return; |
|
| 56 | + if(!WP_DEBUG) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 55 | 59 | self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null')); |
| 56 | 60 | if('allow_null' == $allow_null && is_null($variable_to_test)){ |
| 57 | 61 | return; |
@@ -74,7 +78,9 @@ discard block |
||
| 74 | 78 | * @throws EE_Error |
| 75 | 79 | */ |
| 76 | 80 | static function verify_isnt_null($variable_to_test,$name_of_variable){ |
| 77 | - if(!WP_DEBUG)return; |
|
| 81 | + if(!WP_DEBUG) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 78 | 84 | if($variable_to_test==null && $variable_to_test!=0 && $variable_to_test!=FALSE){ |
| 79 | 85 | $error[]=__('Variable named %s is null.','event_espresso'); |
| 80 | 86 | $error[]=__("Consider looking at the stack trace to see why it wasn't set.",'event_espresso'); |
@@ -91,7 +97,9 @@ discard block |
||
| 91 | 97 | * @throws EE_Error |
| 92 | 98 | */ |
| 93 | 99 | static function verify_is_true($expression_to_test,$expression_string_representation){ |
| 94 | - if(!WP_DEBUG)return; |
|
| 100 | + if(!WP_DEBUG) { |
|
| 101 | + return; |
|
| 102 | + } |
|
| 95 | 103 | if(!$expression_to_test){ |
| 96 | 104 | $error[]=__('Template error.','event_espresso'); |
| 97 | 105 | $error[]=__("%s evaluated to false, but it must be true!",'event_espresso'); |
@@ -112,7 +120,9 @@ discard block |
||
| 112 | 120 | * @throws EE_Error |
| 113 | 121 | */ |
| 114 | 122 | static function verify_instanceof($variable_to_test,$name_of_variable,$class_name, $allow_null = 'do_not_allow_null'){ |
| 115 | - if(!WP_DEBUG)return; |
|
| 123 | + if(!WP_DEBUG) { |
|
| 124 | + return; |
|
| 125 | + } |
|
| 116 | 126 | self::verify_argument_is_one_of($allow_null, 'allow_null', array('allow_null','do_not_allow_null')); |
| 117 | 127 | if($allow_null == 'allow_null' && is_null($variable_to_test)){ |
| 118 | 128 | return; |
@@ -137,7 +147,9 @@ discard block |
||
| 137 | 147 | * @throws EE_Error |
| 138 | 148 | */ |
| 139 | 149 | static function verify_is_array($variable_to_test,$variable_name,$allow_empty='allow_empty'){ |
| 140 | - if(!WP_DEBUG)return; |
|
| 150 | + if(!WP_DEBUG) { |
|
| 151 | + return; |
|
| 152 | + } |
|
| 141 | 153 | self::verify_argument_is_one_of($allow_empty, $variable_name, array('allow_empty','do_not_allow_empty')); |
| 142 | 154 | if(empty($variable_to_test) && 'allow_empty'==$allow_empty){ |
| 143 | 155 | return; |
@@ -164,7 +176,9 @@ discard block |
||
| 164 | 176 | * @throws EE_Error |
| 165 | 177 | */ |
| 166 | 178 | static function verify_argument_is_one_of($variable_to_test,$variable_name,$string_options){ |
| 167 | - if(!WP_DEBUG)return; |
|
| 179 | + if(!WP_DEBUG) { |
|
| 180 | + return; |
|
| 181 | + } |
|
| 168 | 182 | if(!in_array($variable_to_test,$string_options)){ |
| 169 | 183 | $msg[0]=__('Malconfigured template.','event_espresso'); |
| 170 | 184 | $msg[1]=__("Variable named '%s' was set to '%s'. It can only be one of '%s'",'event_espresso'); |
@@ -49,7 +49,6 @@ |
||
| 49 | 49 | * Returns whether not the remote file exists. |
| 50 | 50 | * Checking via GET because HEAD requests are blocked on some server configurations. |
| 51 | 51 | * @param string $url |
| 52 | - * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly |
|
| 53 | 52 | * @return boolean |
| 54 | 53 | */ |
| 55 | 54 | public static function remote_file_exists( $url, $args = array() ){ |
@@ -1,4 +1,6 @@ discard block |
||
| 1 | -<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | +} |
|
| 2 | 4 | /** |
| 3 | 5 | * EEH_URL helper |
| 4 | 6 | * Helper class for URL-related PHP functions |
@@ -62,7 +64,7 @@ discard block |
||
| 62 | 64 | isset($results['response']['code']) && |
| 63 | 65 | $results['response']['code'] == '200'){ |
| 64 | 66 | return true; |
| 65 | - }else{ |
|
| 67 | + } else{ |
|
| 66 | 68 | return false; |
| 67 | 69 | } |
| 68 | 70 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * |
| 10 | 10 | * ------------------------------------------------------------------------ |
| 11 | 11 | */ |
| 12 | -class EEH_URL{ |
|
| 12 | +class EEH_URL { |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * _add_query_arg |
@@ -21,28 +21,28 @@ discard block |
||
| 21 | 21 | * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
| 22 | 22 | * @return string |
| 23 | 23 | */ |
| 24 | - public static function add_query_args_and_nonce( $args = array(), $url = '', $exclude_nonce = false ) { |
|
| 25 | - if ( empty( $url ) ) { |
|
| 26 | - $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', 'event_espresso' ); |
|
| 27 | - $dev_msg = $user_msg . "\n" . sprintf( |
|
| 28 | - __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.', 'event_espresso' ), |
|
| 24 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) { |
|
| 25 | + if (empty($url)) { |
|
| 26 | + $user_msg = __('An error occurred. A URL is a required parameter for the add_query_args_and_nonce method.', 'event_espresso'); |
|
| 27 | + $dev_msg = $user_msg."\n".sprintf( |
|
| 28 | + __('In order to dynamically generate nonces for your actions, you need to supply a valid URL as a second parameter for the %s::add_query_args_and_nonce method.', 'event_espresso'), |
|
| 29 | 29 | __CLASS__ |
| 30 | 30 | ); |
| 31 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 31 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 32 | 32 | } |
| 33 | 33 | // check that an action exists and add nonce |
| 34 | - if ( ! $exclude_nonce ) { |
|
| 35 | - if ( isset( $args['action'] ) && ! empty( $args['action'] ) ) { |
|
| 36 | - $args = array_merge( $args, array( $args['action'] . '_nonce' => wp_create_nonce( $args['action'] . '_nonce' ) ) ); |
|
| 34 | + if ( ! $exclude_nonce) { |
|
| 35 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
| 36 | + $args = array_merge($args, array($args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce'))); |
|
| 37 | 37 | } else { |
| 38 | - $args = array_merge( $args, array( 'action' => 'default', 'default_nonce' => wp_create_nonce( 'default_nonce' ) ) ); |
|
| 38 | + $args = array_merge($args, array('action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce'))); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | //finally, let's always add a return address (if present) :) |
| 43 | - $args = ! empty( $_REQUEST['action'] ) ? array_merge( $args, array( 'return' => $_REQUEST['action'] ) ) : $args; |
|
| 43 | + $args = ! empty($_REQUEST['action']) ? array_merge($args, array('return' => $_REQUEST['action'])) : $args; |
|
| 44 | 44 | |
| 45 | - return add_query_arg( $args, $url ); |
|
| 45 | + return add_query_arg($args, $url); |
|
| 46 | 46 | |
| 47 | 47 | } |
| 48 | 48 | |
@@ -55,17 +55,17 @@ discard block |
||
| 55 | 55 | * @param boolean $sslverify whether we care if the SSL certificate for the requested site is setup properly |
| 56 | 56 | * @return boolean |
| 57 | 57 | */ |
| 58 | - public static function remote_file_exists( $url, $args = array() ){ |
|
| 59 | - $results = wp_remote_request($url,array_merge( array( |
|
| 58 | + public static function remote_file_exists($url, $args = array()) { |
|
| 59 | + $results = wp_remote_request($url, array_merge(array( |
|
| 60 | 60 | 'method'=>'GET', |
| 61 | 61 | 'redirection'=>1 |
| 62 | - ), $args ) ); |
|
| 63 | - if( ! $results instanceof WP_Error && |
|
| 62 | + ), $args)); |
|
| 63 | + if ( ! $results instanceof WP_Error && |
|
| 64 | 64 | isset($results['response']) && |
| 65 | 65 | isset($results['response']['code']) && |
| 66 | - $results['response']['code'] == '200'){ |
|
| 66 | + $results['response']['code'] == '200') { |
|
| 67 | 67 | return true; |
| 68 | - }else{ |
|
| 68 | + } else { |
|
| 69 | 69 | return false; |
| 70 | 70 | } |
| 71 | 71 | } |
@@ -81,29 +81,29 @@ discard block |
||
| 81 | 81 | * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
| 82 | 82 | * @return string |
| 83 | 83 | */ |
| 84 | - public static function refactor_url( $url = '', $remove_query = TRUE, $base_url_only = FALSE ) { |
|
| 84 | + public static function refactor_url($url = '', $remove_query = TRUE, $base_url_only = FALSE) { |
|
| 85 | 85 | // break apart incoming URL |
| 86 | - $url_bits = parse_url( $url ); |
|
| 86 | + $url_bits = parse_url($url); |
|
| 87 | 87 | // HTTP or HTTPS ? |
| 88 | - $scheme = isset( $url_bits[ 'scheme' ] ) ? $url_bits[ 'scheme' ] . '://' : 'http://'; |
|
| 88 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://'; |
|
| 89 | 89 | // domain |
| 90 | - $host = isset( $url_bits[ 'host' ] ) ? $url_bits[ 'host' ] : ''; |
|
| 90 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 91 | 91 | // if only the base URL is requested, then return that now |
| 92 | - if ( $base_url_only ) { |
|
| 93 | - return $scheme . $host; |
|
| 92 | + if ($base_url_only) { |
|
| 93 | + return $scheme.$host; |
|
| 94 | 94 | } |
| 95 | - $port = isset( $url_bits[ 'port' ] ) ? ':' . $url_bits[ 'port' ] : ''; |
|
| 96 | - $user = isset( $url_bits[ 'user' ] ) ? $url_bits[ 'user' ] : ''; |
|
| 97 | - $pass = isset( $url_bits[ 'pass' ] ) ? ':' . $url_bits[ 'pass' ] : ''; |
|
| 98 | - $pass = ( $user || $pass ) ? $pass . '@' : ''; |
|
| 99 | - $path = isset( $url_bits[ 'path' ] ) ? $url_bits[ 'path' ] : ''; |
|
| 95 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
| 96 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 97 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
| 98 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
| 99 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 100 | 100 | // if the query string is not required, then return what we have so far |
| 101 | - if ( $remove_query ) { |
|
| 102 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 101 | + if ($remove_query) { |
|
| 102 | + return $scheme.$user.$pass.$host.$port.$path; |
|
| 103 | 103 | } |
| 104 | - $query = isset( $url_bits[ 'query' ] ) ? '?' . $url_bits[ 'query' ] : ''; |
|
| 105 | - $fragment = isset( $url_bits[ 'fragment' ] ) ? '#' . $url_bits[ 'fragment' ] : ''; |
|
| 106 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 104 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
| 105 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
| 106 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
@@ -116,29 +116,29 @@ discard block |
||
| 116 | 116 | * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will simply return the query string |
| 117 | 117 | * @return string|array |
| 118 | 118 | */ |
| 119 | - public static function get_query_string( $url = '', $as_array = TRUE ) { |
|
| 119 | + public static function get_query_string($url = '', $as_array = TRUE) { |
|
| 120 | 120 | // break apart incoming URL |
| 121 | - $url_bits = parse_url( $url ); |
|
| 121 | + $url_bits = parse_url($url); |
|
| 122 | 122 | // grab query string from URL |
| 123 | - $query = isset( $url_bits[ 'query' ] ) ? $url_bits[ 'query' ] : ''; |
|
| 123 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 124 | 124 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
| 125 | - if ( ! $as_array ) { |
|
| 125 | + if ( ! $as_array) { |
|
| 126 | 126 | return $query; |
| 127 | 127 | } |
| 128 | 128 | // if no query string exists then just return an empty array now |
| 129 | - if ( empty( $query )) { |
|
| 129 | + if (empty($query)) { |
|
| 130 | 130 | return array(); |
| 131 | 131 | } |
| 132 | 132 | // empty array to hold results |
| 133 | 133 | $query_params = array(); |
| 134 | 134 | // now break apart the query string into separate params |
| 135 | - $query = explode( '&', $query ); |
|
| 135 | + $query = explode('&', $query); |
|
| 136 | 136 | // loop thru our query params |
| 137 | - foreach ( $query as $query_args ) { |
|
| 137 | + foreach ($query as $query_args) { |
|
| 138 | 138 | // break apart the key value pairs |
| 139 | - $query_args = explode( '=', $query_args ); |
|
| 139 | + $query_args = explode('=', $query_args); |
|
| 140 | 140 | // and add to our results array |
| 141 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
| 141 | + $query_params[$query_args[0]] = $query_args[1]; |
|
| 142 | 142 | } |
| 143 | 143 | return $query_params; |
| 144 | 144 | } |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * prevent_prefetching |
| 150 | 150 | * @return void |
| 151 | 151 | */ |
| 152 | - public static function prevent_prefetching(){ |
|
| 152 | + public static function prevent_prefetching() { |
|
| 153 | 153 | // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
| 154 | 154 | remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
| 155 | 155 | } |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | * @param string $prefix Use this to prefix the string with something. |
| 165 | 165 | * @return string |
| 166 | 166 | */ |
| 167 | - public static function generate_unique_token( $prefix = '' ) { |
|
| 168 | - $token = md5( uniqid() . mt_rand() ); |
|
| 169 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 167 | + public static function generate_unique_token($prefix = '') { |
|
| 168 | + $token = md5(uniqid().mt_rand()); |
|
| 169 | + return $prefix ? $prefix.'_'.$token : $token; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * add_nocache_headers |
| 176 | 176 | * @return void |
| 177 | 177 | */ |
| 178 | - public static function add_nocache_headers(){ |
|
| 178 | + public static function add_nocache_headers() { |
|
| 179 | 179 | // add no cache headers |
| 180 | 180 | // add_action( 'wp_head' , array( 'EED_Single_Page_Checkout', 'nocache_headers' ), 10 ); |
| 181 | 181 | // plus a little extra for nginx |
@@ -192,19 +192,19 @@ discard block |
||
| 192 | 192 | * @param string $server_variable |
| 193 | 193 | * @return string |
| 194 | 194 | */ |
| 195 | - public static function filter_input_server_url( $server_variable = 'REQUEST_URI' ){ |
|
| 195 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') { |
|
| 196 | 196 | $URL = ''; |
| 197 | 197 | $server_variables = array( |
| 198 | 198 | 'REQUEST_URI' => 1, |
| 199 | 199 | 'HTTP_HOST' => 1, |
| 200 | 200 | 'PHP_SELF' => 1, |
| 201 | 201 | ); |
| 202 | - $server_variable = strtoupper( $server_variable ); |
|
| 202 | + $server_variable = strtoupper($server_variable); |
|
| 203 | 203 | // whitelist INPUT_SERVER var |
| 204 | - if ( isset( $server_variables[ $server_variable ] ) ) { |
|
| 205 | - $URL = filter_input( INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE ); |
|
| 206 | - if ( empty( $URL ) ) { |
|
| 207 | - $URL = esc_url( $_SERVER[ $server_variable ] ); |
|
| 204 | + if (isset($server_variables[$server_variable])) { |
|
| 205 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 206 | + if (empty($URL)) { |
|
| 207 | + $URL = esc_url($_SERVER[$server_variable]); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | return $URL; |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | /** |
| 187 | 187 | * _prep_name_for_html_id |
| 188 | - * @param $name |
|
| 188 | + * @param string $name |
|
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | 191 | private function _prep_name_for_html_id( $name ) { |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | - * @param mixed $html_class |
|
| 234 | + * @param string $html_class |
|
| 235 | 235 | */ |
| 236 | 236 | public function set_html_class( $html_class ) { |
| 237 | 237 | $this->_html_class = $html_class; |
@@ -1,7 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | +if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | +} |
|
| 5 | 6 | |
| 6 | 7 | /** |
| 7 | 8 | * Event Espresso |
@@ -69,7 +70,7 @@ discard block |
||
| 69 | 70 | $default_address .= $state ? $state->name() . '<br />' : ''; |
| 70 | 71 | $default_address .= $country ? $country->name(). '<br />' : ''; |
| 71 | 72 | $default_address .= $organization->zip != '' ? $organization->get_pretty( 'zip' ) : ''; |
| 72 | - }else{ |
|
| 73 | + } else{ |
|
| 73 | 74 | $default_address = 'unknown'; |
| 74 | 75 | $organization_name = 'unknown'; |
| 75 | 76 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
| 4 | 4 | exit('No direct script access allowed'); |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -95,13 +95,13 @@ discard block |
||
| 95 | 95 | * @type $name string the name for this form section, if you want to explicitly define it |
| 96 | 96 | * } |
| 97 | 97 | */ |
| 98 | - function __construct( $options_array = array() ) { |
|
| 98 | + function __construct($options_array = array()) { |
|
| 99 | 99 | // used by display strategies |
| 100 | 100 | EE_Registry::instance()->load_helper('HTML'); |
| 101 | 101 | // assign incoming values to properties |
| 102 | - foreach( $options_array as $key => $value ) { |
|
| 103 | - $key = '_' . $key; |
|
| 104 | - if ( property_exists( $this, $key ) && empty( $this->{$key} )) { |
|
| 102 | + foreach ($options_array as $key => $value) { |
|
| 103 | + $key = '_'.$key; |
|
| 104 | + if (property_exists($this, $key) && empty($this->{$key} )) { |
|
| 105 | 105 | $this->{$key} = $value; |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | * @param $parent_form_section |
| 114 | 114 | * @param $name |
| 115 | 115 | */ |
| 116 | - protected function _construct_finalize( $parent_form_section, $name ){ |
|
| 116 | + protected function _construct_finalize($parent_form_section, $name) { |
|
| 117 | 117 | $this->_construction_finalized = TRUE; |
| 118 | 118 | $this->_parent_section = $parent_form_section; |
| 119 | 119 | $this->_name = $name; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | /** |
| 135 | 135 | * @param string $action |
| 136 | 136 | */ |
| 137 | - public function set_action( $action ) { |
|
| 137 | + public function set_action($action) { |
|
| 138 | 138 | $this->_action = $action; |
| 139 | 139 | } |
| 140 | 140 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | 146 | public function method() { |
| 147 | - return ! empty( $this->_method ) ? $this->_method : 'POST'; |
|
| 147 | + return ! empty($this->_method) ? $this->_method : 'POST'; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | /** |
| 153 | 153 | * @param string $method |
| 154 | 154 | */ |
| 155 | - public function set_method( $method ) { |
|
| 156 | - switch ( $method ) { |
|
| 155 | + public function set_method($method) { |
|
| 156 | + switch ($method) { |
|
| 157 | 157 | case 'get' : |
| 158 | 158 | case 'GET' : |
| 159 | 159 | $this->_method = 'GET'; |
@@ -171,12 +171,12 @@ discard block |
||
| 171 | 171 | * Calculation involves using the name and the parent's html id |
| 172 | 172 | * return void |
| 173 | 173 | */ |
| 174 | - protected function _set_default_html_id_if_empty(){ |
|
| 175 | - if( ! $this->_html_id ){ |
|
| 176 | - if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper ){ |
|
| 177 | - $this->_html_id = $this->_parent_section->html_id() . '-' . $this->_prep_name_for_html_id( $this->name() ); |
|
| 178 | - }else{ |
|
| 179 | - $this->_html_id = $this->_prep_name_for_html_id( $this->name() ); |
|
| 174 | + protected function _set_default_html_id_if_empty() { |
|
| 175 | + if ( ! $this->_html_id) { |
|
| 176 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
| 177 | + $this->_html_id = $this->_parent_section->html_id().'-'.$this->_prep_name_for_html_id($this->name()); |
|
| 178 | + } else { |
|
| 179 | + $this->_html_id = $this->_prep_name_for_html_id($this->name()); |
|
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | } |
@@ -188,8 +188,8 @@ discard block |
||
| 188 | 188 | * @param $name |
| 189 | 189 | * @return string |
| 190 | 190 | */ |
| 191 | - private function _prep_name_for_html_id( $name ) { |
|
| 192 | - return sanitize_key( str_replace( array( ' ', ' ', '_' ), '-', $name )); |
|
| 191 | + private function _prep_name_for_html_id($name) { |
|
| 192 | + return sanitize_key(str_replace(array(' ', ' ', '_'), '-', $name)); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | * @param bool $add_pound_sign |
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | - public function html_id( $add_pound_sign = FALSE ){ |
|
| 210 | - return $add_pound_sign ? '#' . $this->_html_id : $this->_html_id; |
|
| 209 | + public function html_id($add_pound_sign = FALSE) { |
|
| 210 | + return $add_pound_sign ? '#'.$this->_html_id : $this->_html_id; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | /** |
| 216 | 216 | * @return string |
| 217 | 217 | */ |
| 218 | - public function html_class(){ |
|
| 218 | + public function html_class() { |
|
| 219 | 219 | return $this->_html_class; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | /** |
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | - public function html_style(){ |
|
| 227 | + public function html_style() { |
|
| 228 | 228 | return $this->_html_style; |
| 229 | 229 | } |
| 230 | 230 | |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | /** |
| 234 | 234 | * @param mixed $html_class |
| 235 | 235 | */ |
| 236 | - public function set_html_class( $html_class ) { |
|
| 236 | + public function set_html_class($html_class) { |
|
| 237 | 237 | $this->_html_class = $html_class; |
| 238 | 238 | } |
| 239 | 239 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | /** |
| 243 | 243 | * @param mixed $html_id |
| 244 | 244 | */ |
| 245 | - public function set_html_id( $html_id ) { |
|
| 245 | + public function set_html_id($html_id) { |
|
| 246 | 246 | $this->_html_id = $html_id; |
| 247 | 247 | } |
| 248 | 248 | |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | /** |
| 252 | 252 | * @param mixed $html_style |
| 253 | 253 | */ |
| 254 | - public function set_html_style( $html_style ) { |
|
| 254 | + public function set_html_style($html_style) { |
|
| 255 | 255 | $this->_html_style = $html_style; |
| 256 | 256 | } |
| 257 | 257 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | /** |
| 261 | 261 | * @param string $other_html_attributes |
| 262 | 262 | */ |
| 263 | - public function set_other_html_attributes( $other_html_attributes ) { |
|
| 263 | + public function set_other_html_attributes($other_html_attributes) { |
|
| 264 | 264 | $this->_other_html_attributes = $other_html_attributes; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | * @throws EE_Error |
| 281 | 281 | * @return string |
| 282 | 282 | */ |
| 283 | - function name(){ |
|
| 284 | - if( ! $this->_construction_finalized ){ |
|
| 285 | - throw new EE_Error(sprintf( __( 'You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', 'event_espresso' ), get_class($this) ) ); |
|
| 283 | + function name() { |
|
| 284 | + if ( ! $this->_construction_finalized) { |
|
| 285 | + throw new EE_Error(sprintf(__('You cannot use the form section\s name until _construct_finalize has been called on it (when we set the name). It was called on a form section of type \'s\'', 'event_espresso'), get_class($this))); |
|
| 286 | 286 | } |
| 287 | 287 | return $this->_name; |
| 288 | 288 | } |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * Gets the parent section |
| 294 | 294 | * @return EE_Form_Section_Proper |
| 295 | 295 | */ |
| 296 | - function parent_section(){ |
|
| 296 | + function parent_section() { |
|
| 297 | 297 | return $this->_parent_section; |
| 298 | 298 | } |
| 299 | 299 | |
@@ -306,18 +306,18 @@ discard block |
||
| 306 | 306 | * @param string $other_attributes anything else added to the form open tag, MUST BE VALID HTML |
| 307 | 307 | * @return string |
| 308 | 308 | */ |
| 309 | - public function form_open( $action = '', $method = '', $other_attributes = '' ) { |
|
| 310 | - if ( ! empty( $action )) { |
|
| 311 | - $this->set_action( $action ); |
|
| 309 | + public function form_open($action = '', $method = '', $other_attributes = '') { |
|
| 310 | + if ( ! empty($action)) { |
|
| 311 | + $this->set_action($action); |
|
| 312 | 312 | } |
| 313 | - if ( ! empty( $method )) { |
|
| 314 | - $this->set_method( $method ); |
|
| 313 | + if ( ! empty($method)) { |
|
| 314 | + $this->set_method($method); |
|
| 315 | 315 | } |
| 316 | - $html = EEH_HTML::nl( 1, 'form' ) . '<form'; |
|
| 317 | - $html .= $this->html_id() !== '' ? ' id="' . $this->html_id() . '"' : ''; |
|
| 318 | - $html .= ' action="' . $this->action() . '"'; |
|
| 319 | - $html .= ' method="' . $this->method() . '"'; |
|
| 320 | - $html .= $other_attributes . '>'; |
|
| 316 | + $html = EEH_HTML::nl(1, 'form').'<form'; |
|
| 317 | + $html .= $this->html_id() !== '' ? ' id="'.$this->html_id().'"' : ''; |
|
| 318 | + $html .= ' action="'.$this->action().'"'; |
|
| 319 | + $html .= ' method="'.$this->method().'"'; |
|
| 320 | + $html .= $other_attributes.'>'; |
|
| 321 | 321 | return $html; |
| 322 | 322 | } |
| 323 | 323 | |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | * @return string |
| 329 | 329 | */ |
| 330 | 330 | public function form_close() { |
| 331 | - return EEH_HTML::nl( -1, 'form' ) . '</form>' . EEH_HTML::nl() . '<!-- end of ee-' . $this->html_id() . '-form -->' . EEH_HTML::nl(); |
|
| 331 | + return EEH_HTML::nl( -1, 'form' ).'</form>'.EEH_HTML::nl().'<!-- end of ee-'.$this->html_id().'-form -->'.EEH_HTML::nl(); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | |
@@ -348,6 +348,7 @@ |
||
| 348 | 348 | * Automatically finds the related model info from the form, if present, and |
| 349 | 349 | * save the relations indicated |
| 350 | 350 | * @type string $relation_name |
| 351 | + * @param integer $relation_name |
|
| 351 | 352 | * @return bool |
| 352 | 353 | * @throws EE_Error |
| 353 | 354 | */ |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @since 4.5.0 |
| 12 | 12 | * |
| 13 | 13 | */ |
| 14 | -class EE_Model_Form_Section extends EE_Form_Section_Proper{ |
|
| 14 | +class EE_Model_Form_Section extends EE_Form_Section_Proper { |
|
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | 17 | * |
@@ -36,36 +36,36 @@ discard block |
||
| 36 | 36 | * } |
| 37 | 37 | * @throws EE_Error |
| 38 | 38 | */ |
| 39 | - public function __construct($options_array = array()){ |
|
| 40 | - if(isset($options_array['model']) && $options_array['model'] instanceof EEM_Base){ |
|
| 39 | + public function __construct($options_array = array()) { |
|
| 40 | + if (isset($options_array['model']) && $options_array['model'] instanceof EEM_Base) { |
|
| 41 | 41 | $this->_model = $options_array['model']; |
| 42 | 42 | } |
| 43 | - if( ! $this->_model || ! $this->_model instanceof EEM_Base ){ |
|
| 43 | + if ( ! $this->_model || ! $this->_model instanceof EEM_Base) { |
|
| 44 | 44 | throw new EE_Error(sprintf(__("Model Form Sections must first specify the _model property to be a subclass of EEM_Base", "event_espresso"))); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - if(isset($options_array['subsection_args'])){ |
|
| 47 | + if (isset($options_array['subsection_args'])) { |
|
| 48 | 48 | $subsection_args = $options_array['subsection_args']; |
| 49 | - }else{ |
|
| 49 | + } else { |
|
| 50 | 50 | $subsection_args = array(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | //gather fields and relations to convert to inputs |
| 54 | 54 | //but if they're just going to exclude a field anyways, don't bother converting it to an input |
| 55 | 55 | $exclude = $this->_subsections; |
| 56 | - if(isset($options_array['exclude'])){ |
|
| 57 | - $exclude = array_merge($exclude,array_flip($options_array['exclude'])); |
|
| 56 | + if (isset($options_array['exclude'])) { |
|
| 57 | + $exclude = array_merge($exclude, array_flip($options_array['exclude'])); |
|
| 58 | 58 | } |
| 59 | 59 | $model_fields = array_diff_key($this->_model->field_settings(), $exclude); |
| 60 | 60 | $model_relations = array_diff_key($this->_model->relation_settings(), $exclude); |
| 61 | 61 | //convert fields and relations to inputs |
| 62 | 62 | $this->_subsections = array_merge( |
| 63 | 63 | $this->_convert_model_fields_to_inputs($model_fields), |
| 64 | - $this->_convert_model_relations_to_inputs($model_relations,$subsection_args), |
|
| 64 | + $this->_convert_model_relations_to_inputs($model_relations, $subsection_args), |
|
| 65 | 65 | $this->_subsections |
| 66 | 66 | ); |
| 67 | 67 | parent::__construct($options_array); |
| 68 | - if(isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class){ |
|
| 68 | + if (isset($options_array['model_object']) && $options_array['model_object'] instanceof EE_Base_Class) { |
|
| 69 | 69 | $this->populate_model_obj($options_array['model_object']); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | * } |
| 84 | 84 | * @return array |
| 85 | 85 | */ |
| 86 | - protected function _convert_model_relations_to_inputs($relations,$subsection_args = array()){ |
|
| 86 | + protected function _convert_model_relations_to_inputs($relations, $subsection_args = array()) { |
|
| 87 | 87 | $inputs = array(); |
| 88 | - foreach( $relations as $relation_name => $relation_obj ) { |
|
| 88 | + foreach ($relations as $relation_name => $relation_obj) { |
|
| 89 | 89 | $input_constructor_args = array( |
| 90 | 90 | array_merge( |
| 91 | 91 | array( |
@@ -96,19 +96,19 @@ discard block |
||
| 96 | 96 | ) |
| 97 | 97 | ); |
| 98 | 98 | $input = NULL; |
| 99 | - switch(get_class($relation_obj)){ |
|
| 99 | + switch (get_class($relation_obj)) { |
|
| 100 | 100 | case 'EE_HABTM_Relation': |
| 101 | - if(isset($subsection_args[$relation_name]) && |
|
| 102 | - isset($subsection_args[$relation_name]['model_objects'])){ |
|
| 101 | + if (isset($subsection_args[$relation_name]) && |
|
| 102 | + isset($subsection_args[$relation_name]['model_objects'])) { |
|
| 103 | 103 | $model_objects = $subsection_args[$relation_name]['model_objects']; |
| 104 | - }else{ |
|
| 104 | + } else { |
|
| 105 | 105 | $model_objects = $relation_obj->get_other_model()->get_all(); |
| 106 | 106 | } |
| 107 | - $input = new EE_Select_Multi_Model_Input($model_objects,$input_constructor_args); |
|
| 107 | + $input = new EE_Select_Multi_Model_Input($model_objects, $input_constructor_args); |
|
| 108 | 108 | break; |
| 109 | 109 | default: |
| 110 | 110 | } |
| 111 | - if($input){ |
|
| 111 | + if ($input) { |
|
| 112 | 112 | $inputs[$relation_name] = $input; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -123,10 +123,10 @@ discard block |
||
| 123 | 123 | * @throws EE_Error |
| 124 | 124 | * @return EE_Form_Input_Base[] |
| 125 | 125 | */ |
| 126 | - protected function _convert_model_fields_to_inputs( $model_fields = array() ){ |
|
| 126 | + protected function _convert_model_fields_to_inputs($model_fields = array()) { |
|
| 127 | 127 | $inputs = array(); |
| 128 | - foreach( $model_fields as $field_name=>$model_field ){ |
|
| 129 | - if ( $model_field instanceof EE_Model_Field_Base ) { |
|
| 128 | + foreach ($model_fields as $field_name=>$model_field) { |
|
| 129 | + if ($model_field instanceof EE_Model_Field_Base) { |
|
| 130 | 130 | $input_constructor_args = array( |
| 131 | 131 | array( |
| 132 | 132 | 'required'=> ! $model_field->is_nullable() && $model_field->get_default_value() === NULL, |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | 'default'=>$model_field->get_default_value(), |
| 135 | 135 | ) |
| 136 | 136 | ); |
| 137 | - switch(get_class($model_field)){ |
|
| 137 | + switch (get_class($model_field)) { |
|
| 138 | 138 | case 'EE_All_Caps_Text_Field': |
| 139 | 139 | case 'EE_Any_Foreign_Model_Name_Field': |
| 140 | 140 | $input_class = 'EE_Text_Input'; |
@@ -143,16 +143,16 @@ discard block |
||
| 143 | 143 | $input_class = 'EE_Yes_No_Input'; |
| 144 | 144 | break; |
| 145 | 145 | case 'EE_Datetime_Field': |
| 146 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 146 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 147 | 147 | break; |
| 148 | 148 | case 'EE_Email_Field': |
| 149 | 149 | $input_class = 'EE_Email_Input'; |
| 150 | 150 | break; |
| 151 | 151 | case 'EE_Enum_Integer_Field': |
| 152 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 152 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 153 | 153 | break; |
| 154 | 154 | case 'EE_Enum_Text_Field': |
| 155 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 155 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 156 | 156 | break; |
| 157 | 157 | case 'EE_Float_Field': |
| 158 | 158 | $input_class = 'EE_Float_Input'; |
@@ -161,15 +161,15 @@ discard block |
||
| 161 | 161 | case 'EE_Foreign_Key_String_Field': |
| 162 | 162 | case 'EE_WP_User_Field': |
| 163 | 163 | $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name ? $model_field->get_model_class_names_pointed_to() : array(); |
| 164 | - if(true || is_array($models_pointed_to) && count($models_pointed_to) > 1){ |
|
| 164 | + if (true || is_array($models_pointed_to) && count($models_pointed_to) > 1) { |
|
| 165 | 165 | $input_class = 'EE_Text_Input'; |
| 166 | - }else{ |
|
| 166 | + } else { |
|
| 167 | 167 | //so its just one model |
| 168 | 168 | $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
| 169 | 169 | $model = EE_Registry::instance()->load_model($model_name); |
| 170 | 170 | $model_names = $model->get_all_names(array('limit'=>10)); |
| 171 | - if($model_field->is_nullable()){ |
|
| 172 | - array_unshift( $model_names, __( "Please Select", 'event_espresso' )); |
|
| 171 | + if ($model_field->is_nullable()) { |
|
| 172 | + array_unshift($model_names, __("Please Select", 'event_espresso')); |
|
| 173 | 173 | } |
| 174 | 174 | $input_constructor_args[1] = $input_constructor_args[0]; |
| 175 | 175 | $input_constructor_args[0] = $model_names; |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | break; |
| 179 | 179 | case 'EE_Full_HTML_Field': |
| 180 | 180 | $input_class = 'EE_Text_Area_Input'; |
| 181 | - $input_constructor_args[ 0 ]['validation_strategies'] = array( new EE_Full_HTML_Validation_Strategy() ); |
|
| 181 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
| 182 | 182 | break; |
| 183 | 183 | case 'EE_Infinite_Integer': |
| 184 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 184 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 185 | 185 | break; |
| 186 | 186 | case 'EE_Integer_Field': |
| 187 | 187 | $input_class = 'EE_Text_Input'; |
@@ -190,11 +190,11 @@ discard block |
||
| 190 | 190 | $input_class = 'EE_Text_Area_Input'; |
| 191 | 191 | break; |
| 192 | 192 | case 'EE_Money_Field': |
| 193 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 193 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 194 | 194 | break; |
| 195 | 195 | case 'EE_Post_Content_Field': |
| 196 | 196 | $input_class = 'EE_Text_Area_Input'; |
| 197 | - $input_constructor_args[ 0 ][ 'validation_strategies' ] = array( new EE_Full_HTML_Validation_Strategy() ); |
|
| 197 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Full_HTML_Validation_Strategy()); |
|
| 198 | 198 | break; |
| 199 | 199 | case 'EE_Plain_Text_Field': |
| 200 | 200 | $input_class = 'EE_Text_Input'; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | break; |
| 212 | 212 | case 'EE_Simple_HTML_Field': |
| 213 | 213 | $input_class = 'EE_Text_Area_Input'; |
| 214 | - $input_constructor_args[ 0 ][ 'validation_strategies' ] = array( new EE_Simple_HTML_Validation_Strategy() ); |
|
| 214 | + $input_constructor_args[0]['validation_strategies'] = array(new EE_Simple_HTML_Validation_Strategy()); |
|
| 215 | 215 | break; |
| 216 | 216 | case 'EE_Slug_Field': |
| 217 | 217 | $input_class = 'EE_Text_Input'; |
@@ -220,13 +220,13 @@ discard block |
||
| 220 | 220 | $input_class = 'EE_Yes_No_Input'; |
| 221 | 221 | break; |
| 222 | 222 | case 'EE_WP_Post_Status_Field': |
| 223 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 223 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 224 | 224 | break; |
| 225 | 225 | case 'EE_WP_Post_Type_Field': |
| 226 | - throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"),get_class($model_field))); |
|
| 226 | + throw new EE_Error(sprintf(__("Model field '%s' does not yet have a known conversion to form input", "event_espresso"), get_class($model_field))); |
|
| 227 | 227 | break; |
| 228 | 228 | default: |
| 229 | - throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", "event_espresso"),get_class($model_field))); |
|
| 229 | + throw new EE_Error(sprintf(__("Model field of type '%s' does not convert to any known Form Input. Please add a case to EE_Model_Form_section's _convert_model_fields_to_inputs switch statement", "event_espresso"), get_class($model_field))); |
|
| 230 | 230 | } |
| 231 | 231 | $reflection = new ReflectionClass($input_class); |
| 232 | 232 | $input = $reflection->newInstanceArgs($input_constructor_args); |
@@ -244,21 +244,21 @@ discard block |
||
| 244 | 244 | * @param EE_Base_Class $model_obj |
| 245 | 245 | * @return void |
| 246 | 246 | */ |
| 247 | - public function populate_model_obj($model_obj){ |
|
| 247 | + public function populate_model_obj($model_obj) { |
|
| 248 | 248 | $model_obj = $this->_model->ensure_is_obj($model_obj); |
| 249 | 249 | $this->_model_object = $model_obj; |
| 250 | 250 | $defaults = $model_obj->model_field_array(); |
| 251 | - foreach($this->_model->relation_settings() as $relation_name => $relation_obj){ |
|
| 251 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
| 252 | 252 | $form_inputs = $this->inputs(); |
| 253 | - if(isset($form_inputs[$relation_name])){ |
|
| 254 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
| 253 | + if (isset($form_inputs[$relation_name])) { |
|
| 254 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 255 | 255 | //then we only expect there to be one |
| 256 | 256 | $related_item = $this->_model_object->get_first_related($relation_name); |
| 257 | 257 | $defaults[$relation_name] = $related_item->ID(); |
| 258 | - }else{ |
|
| 258 | + } else { |
|
| 259 | 259 | $related_items = $this->_model_object->get_many_related($relation_name); |
| 260 | 260 | $ids = array(); |
| 261 | - foreach($related_items as $related_item){ |
|
| 261 | + foreach ($related_items as $related_item) { |
|
| 262 | 262 | $ids[] = $related_item->ID(); |
| 263 | 263 | } |
| 264 | 264 | $defaults[$relation_name] = $ids; |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | * values are their normalized values |
| 276 | 276 | * @return array |
| 277 | 277 | */ |
| 278 | - public function inputs_values_corresponding_to_model_fields(){ |
|
| 279 | - return array_intersect_key($this->input_values(),$this->_model->field_settings()); |
|
| 278 | + public function inputs_values_corresponding_to_model_fields() { |
|
| 279 | + return array_intersect_key($this->input_values(), $this->_model->field_settings()); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | |
@@ -299,21 +299,21 @@ discard block |
||
| 299 | 299 | public function receive_form_submission($req_data = NULL, $validate = TRUE) { |
| 300 | 300 | parent::receive_form_submission($req_data, $validate); |
| 301 | 301 | //create or set the model object, if it isn't already |
| 302 | - if( ! $this->_model_object ){ |
|
| 302 | + if ( ! $this->_model_object) { |
|
| 303 | 303 | //check to see if the form indicates a PK, in which case we want to only retrieve it and update it |
| 304 | 304 | $pk_name = $this->_model->primary_key_name(); |
| 305 | 305 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
| 306 | - if($model_obj){ |
|
| 306 | + if ($model_obj) { |
|
| 307 | 307 | $this->_model_object = $model_obj; |
| 308 | - }else{ |
|
| 309 | - $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name() ); |
|
| 308 | + } else { |
|
| 309 | + $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name()); |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | //ok so the model object is set. Just set it with the submitted form data (don't save yet though) |
| 313 | - foreach($this->inputs_values_corresponding_to_model_fields() as $field_name=>$field_value){ |
|
| 313 | + foreach ($this->inputs_values_corresponding_to_model_fields() as $field_name=>$field_value) { |
|
| 314 | 314 | //only set the non-primary key |
| 315 | - if($field_name != $this->_model->primary_key_name()){ |
|
| 316 | - $this->_model_object->set($field_name,$field_value); |
|
| 315 | + if ($field_name != $this->_model->primary_key_name()) { |
|
| 316 | + $this->_model_object->set($field_name, $field_value); |
|
| 317 | 317 | } |
| 318 | 318 | } |
| 319 | 319 | |
@@ -329,13 +329,13 @@ discard block |
||
| 329 | 329 | * @return int, 1 on a successful update, the ID of |
| 330 | 330 | * the new entry on insert; 0 on failure |
| 331 | 331 | */ |
| 332 | - public function save(){ |
|
| 333 | - if( ! $this->_model_object){ |
|
| 334 | - throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", "event_espresso"),get_class($this->_model))); |
|
| 332 | + public function save() { |
|
| 333 | + if ( ! $this->_model_object) { |
|
| 334 | + throw new EE_Error(sprintf(__("Cannot save the model form's model object (model is '%s') because there is no model object set. You must either set it, or call receive_form_submission where it is set automatically", "event_espresso"), get_class($this->_model))); |
|
| 335 | 335 | } |
| 336 | - $success = $this->_model_object->save(); |
|
| 337 | - foreach($this->_model->relation_settings() as $relation_name => $relation_obj){ |
|
| 338 | - if(isset($this->_subsections[$relation_name])){ |
|
| 336 | + $success = $this->_model_object->save(); |
|
| 337 | + foreach ($this->_model->relation_settings() as $relation_name => $relation_obj) { |
|
| 338 | + if (isset($this->_subsections[$relation_name])) { |
|
| 339 | 339 | $success = $this->_save_related_info($relation_name); |
| 340 | 340 | } |
| 341 | 341 | } |
@@ -351,29 +351,29 @@ discard block |
||
| 351 | 351 | * @return bool |
| 352 | 352 | * @throws EE_Error |
| 353 | 353 | */ |
| 354 | - protected function _save_related_info($relation_name){ |
|
| 354 | + protected function _save_related_info($relation_name) { |
|
| 355 | 355 | $relation_obj = $this->_model->related_settings_for($relation_name); |
| 356 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
| 356 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
| 357 | 357 | //there is just a foreign key on this model pointing to that one |
| 358 | 358 | $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
| 359 | - }elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
| 359 | + }elseif ($relation_obj instanceof EE_Has_Many_Relation) { |
|
| 360 | 360 | //then we want to consider all of its currently-related things. |
| 361 | 361 | //if they're in this list, keep them |
| 362 | 362 | //if they're not in this list, remove them |
| 363 | 363 | //and lastly add all the new items |
| 364 | 364 | throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso"))); |
| 365 | - }elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
| 365 | + }elseif ($relation_obj instanceof EE_HABTM_Relation) { |
|
| 366 | 366 | //delete everything NOT in this list |
| 367 | 367 | $normalized_input_value = $this->get_input_value($relation_name); |
| 368 | - if($normalized_input_value && is_array($normalized_input_value)){ |
|
| 368 | + if ($normalized_input_value && is_array($normalized_input_value)) { |
|
| 369 | 369 | $where_query_params = array( |
| 370 | - $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN',$normalized_input_value)); |
|
| 371 | - }else{ |
|
| 370 | + $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN', $normalized_input_value)); |
|
| 371 | + } else { |
|
| 372 | 372 | $where_query_params = array(); |
| 373 | 373 | } |
| 374 | - $this->_model_object->_remove_relations( $relation_name, $where_query_params ); |
|
| 375 | - foreach($normalized_input_value as $id){ |
|
| 376 | - $this->_model_object->_add_relation_to( $id, $relation_name ); |
|
| 374 | + $this->_model_object->_remove_relations($relation_name, $where_query_params); |
|
| 375 | + foreach ($normalized_input_value as $id) { |
|
| 376 | + $this->_model_object->_add_relation_to($id, $relation_name); |
|
| 377 | 377 | } |
| 378 | 378 | } |
| 379 | 379 | return TRUE; |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | * Gets the model of this model form |
| 386 | 386 | * @return EEM_Base |
| 387 | 387 | */ |
| 388 | - public function get_model(){ |
|
| 388 | + public function get_model() { |
|
| 389 | 389 | return $this->_model; |
| 390 | 390 | } |
| 391 | 391 | |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * when receive_form_submission($req_data) was called. |
| 399 | 399 | * @return EE_Base_Class |
| 400 | 400 | */ |
| 401 | - public function get_model_object(){ |
|
| 401 | + public function get_model_object() { |
|
| 402 | 402 | return $this->_model_object; |
| 403 | 403 | } |
| 404 | 404 | |
@@ -408,10 +408,10 @@ discard block |
||
| 408 | 408 | * gets teh default name of this form section if none is specified |
| 409 | 409 | * @return string |
| 410 | 410 | */ |
| 411 | - protected function _set_default_name_if_empty(){ |
|
| 412 | - if( ! $this->_name ){ |
|
| 413 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
| 414 | - $this->_name = $default_name; |
|
| 411 | + protected function _set_default_name_if_empty() { |
|
| 412 | + if ( ! $this->_name) { |
|
| 413 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
| 414 | + $this->_name = $default_name; |
|
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | 417 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | if(isset($options_array['subsection_args'])){ |
| 48 | 48 | $subsection_args = $options_array['subsection_args']; |
| 49 | - }else{ |
|
| 49 | + } else{ |
|
| 50 | 50 | $subsection_args = array(); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | if(isset($subsection_args[$relation_name]) && |
| 102 | 102 | isset($subsection_args[$relation_name]['model_objects'])){ |
| 103 | 103 | $model_objects = $subsection_args[$relation_name]['model_objects']; |
| 104 | - }else{ |
|
| 104 | + } else{ |
|
| 105 | 105 | $model_objects = $relation_obj->get_other_model()->get_all(); |
| 106 | 106 | } |
| 107 | 107 | $input = new EE_Select_Multi_Model_Input($model_objects,$input_constructor_args); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $models_pointed_to = $model_field instanceof EE_Field_With_Model_Name ? $model_field->get_model_class_names_pointed_to() : array(); |
| 164 | 164 | if(true || is_array($models_pointed_to) && count($models_pointed_to) > 1){ |
| 165 | 165 | $input_class = 'EE_Text_Input'; |
| 166 | - }else{ |
|
| 166 | + } else{ |
|
| 167 | 167 | //so its just one model |
| 168 | 168 | $model_name = is_array($models_pointed_to) ? reset($models_pointed_to) : $models_pointed_to; |
| 169 | 169 | $model = EE_Registry::instance()->load_model($model_name); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | //then we only expect there to be one |
| 256 | 256 | $related_item = $this->_model_object->get_first_related($relation_name); |
| 257 | 257 | $defaults[$relation_name] = $related_item->ID(); |
| 258 | - }else{ |
|
| 258 | + } else{ |
|
| 259 | 259 | $related_items = $this->_model_object->get_many_related($relation_name); |
| 260 | 260 | $ids = array(); |
| 261 | 261 | foreach($related_items as $related_item){ |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | $model_obj = $this->_model->get_one_by_ID($this->get_input_value($pk_name)); |
| 306 | 306 | if($model_obj){ |
| 307 | 307 | $this->_model_object = $model_obj; |
| 308 | - }else{ |
|
| 308 | + } else{ |
|
| 309 | 309 | $this->_model_object = EE_Registry::instance()->load_class($this->_model->get_this_model_name() ); |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -356,19 +356,19 @@ discard block |
||
| 356 | 356 | if($relation_obj instanceof EE_Belongs_To_Relation){ |
| 357 | 357 | //there is just a foreign key on this model pointing to that one |
| 358 | 358 | $this->_model_object->_add_relation_to($this->get_input_value($relation_name), $relation_name); |
| 359 | - }elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
| 359 | + } elseif($relation_obj instanceof EE_Has_Many_Relation){ |
|
| 360 | 360 | //then we want to consider all of its currently-related things. |
| 361 | 361 | //if they're in this list, keep them |
| 362 | 362 | //if they're not in this list, remove them |
| 363 | 363 | //and lastly add all the new items |
| 364 | 364 | throw new EE_Error(sprintf(__('Automatic saving of related info across a "has many" relation is not yet supported', "event_espresso"))); |
| 365 | - }elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
| 365 | + } elseif($relation_obj instanceof EE_HABTM_Relation){ |
|
| 366 | 366 | //delete everything NOT in this list |
| 367 | 367 | $normalized_input_value = $this->get_input_value($relation_name); |
| 368 | 368 | if($normalized_input_value && is_array($normalized_input_value)){ |
| 369 | 369 | $where_query_params = array( |
| 370 | 370 | $relation_obj->get_other_model()->primary_key_name() => array('NOT_IN',$normalized_input_value)); |
| 371 | - }else{ |
|
| 371 | + } else{ |
|
| 372 | 372 | $where_query_params = array(); |
| 373 | 373 | } |
| 374 | 374 | $this->_model_object->_remove_relations( $relation_name, $where_query_params ); |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | /** |
| 262 | 262 | * Sets sensitive_data_removal_strategy |
| 263 | 263 | * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
| 264 | - * @return boolean |
|
| 264 | + * @return boolean|null |
|
| 265 | 265 | */ |
| 266 | 266 | public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) { |
| 267 | 267 | $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | * Returns whether or not any validation errors occurred |
| 446 | 446 | * |
| 447 | 447 | * @param array $req_data like $_POST |
| 448 | - * @return boolean whether or not there was an error |
|
| 448 | + * @return boolean|null whether or not there was an error |
|
| 449 | 449 | */ |
| 450 | 450 | protected function _normalize( $req_data ) { |
| 451 | 451 | //any existing validation errors don't apply so clear them |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | if( ! $this->_html_name){ |
| 201 | 201 | if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper){ |
| 202 | 202 | $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
| 203 | - }else{ |
|
| 203 | + } else{ |
|
| 204 | 204 | $this->_html_name = $this->name(); |
| 205 | 205 | } |
| 206 | 206 | } |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | protected function _get_display_strategy(){ |
| 231 | 231 | if( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base){ |
| 232 | 232 | throw new EE_Error(sprintf(__("Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", "event_espresso"),$this->html_name(),$this->html_id())); |
| 233 | - }else{ |
|
| 233 | + } else{ |
|
| 234 | 234 | return $this->_display_strategy; |
| 235 | 235 | } |
| 236 | 236 | } |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | public function get_validation_strategies(){ |
| 307 | 307 | if(is_array($this->_validation_strategies)){ |
| 308 | 308 | return $this->_validation_strategies; |
| 309 | - }else{ |
|
| 309 | + } else{ |
|
| 310 | 310 | return array(); |
| 311 | 311 | } |
| 312 | 312 | |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
| 414 | 414 | try{ |
| 415 | 415 | $validation_strategy->validate($this->normalized_value()); |
| 416 | - }catch(EE_Validation_Error $e){ |
|
| 416 | + } catch(EE_Validation_Error $e){ |
|
| 417 | 417 | $this->add_validation_error($e); |
| 418 | 418 | } |
| 419 | 419 | } |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | } |
| 422 | 422 | if( $this->get_validation_errors()){ |
| 423 | 423 | return false; |
| 424 | - }else{ |
|
| 424 | + } else{ |
|
| 425 | 425 | return true; |
| 426 | 426 | } |
| 427 | 427 | } |
@@ -602,7 +602,7 @@ discard block |
||
| 602 | 602 | |
| 603 | 603 | if(! empty($jquery_validation_rules)){ |
| 604 | 604 | $jquery_validation_js[ $this->html_id( TRUE ) ] = $jquery_validation_rules; |
| 605 | - }else{ |
|
| 605 | + } else{ |
|
| 606 | 606 | return array(); |
| 607 | 607 | } |
| 608 | 608 | return $jquery_validation_js; |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | if( isset( $matches[ 1 ] ) && is_array( $matches[ 1 ] ) ){ |
| 770 | 770 | $name_parts = $matches[ 1 ]; |
| 771 | 771 | array_unshift($name_parts, $before_any_brackets); |
| 772 | - }else{ |
|
| 772 | + } else{ |
|
| 773 | 773 | $name_parts = array( $before_any_brackets ); |
| 774 | 774 | } |
| 775 | 775 | // now get the value for the input |
@@ -796,10 +796,10 @@ discard block |
||
| 796 | 796 | if( isset( $req_data[ $first_part_to_consider ] ) ){ |
| 797 | 797 | if( empty($html_name_parts ) ){ |
| 798 | 798 | return $req_data[ $first_part_to_consider ]; |
| 799 | - }else{ |
|
| 799 | + } else{ |
|
| 800 | 800 | return $this->_find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data[ $first_part_to_consider ] ); |
| 801 | 801 | } |
| 802 | - }else{ |
|
| 802 | + } else{ |
|
| 803 | 803 | return NULL; |
| 804 | 804 | } |
| 805 | 805 | } |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | $checked_value = $this->find_form_data_for_this_section( $req_data ); |
| 819 | 819 | if( $checked_value !== null ){ |
| 820 | 820 | return TRUE; |
| 821 | - }else{ |
|
| 821 | + } else{ |
|
| 822 | 822 | return FALSE; |
| 823 | 823 | } |
| 824 | 824 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * @subpackage |
| 9 | 9 | * @author Mike Nelson |
| 10 | 10 | */ |
| 11 | -abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable{ |
|
| 11 | +abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable { |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * the input's name attribute |
@@ -141,67 +141,67 @@ discard block |
||
| 141 | 141 | * @type EE_Validation_Strategy_Base[] $validation_strategies |
| 142 | 142 | * } |
| 143 | 143 | */ |
| 144 | - public function __construct( $input_args = array() ){ |
|
| 145 | - $input_args = apply_filters( 'FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this ); |
|
| 144 | + public function __construct($input_args = array()) { |
|
| 145 | + $input_args = apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
| 146 | 146 | // the following properties must be cast as arrays |
| 147 | 147 | $set_as_array = array( |
| 148 | 148 | 'validation_strategies' |
| 149 | 149 | ); |
| 150 | 150 | // loop thru incoming options |
| 151 | - foreach( $input_args as $key => $value ) { |
|
| 151 | + foreach ($input_args as $key => $value) { |
|
| 152 | 152 | // add underscore to $key to match property names |
| 153 | - $_key = '_' . $key; |
|
| 154 | - if ( property_exists( $this, $_key )) { |
|
| 153 | + $_key = '_'.$key; |
|
| 154 | + if (property_exists($this, $_key)) { |
|
| 155 | 155 | // first check if this property needs to be set as an array |
| 156 | - if ( isset( $set_as_array[ $key ] )) { |
|
| 156 | + if (isset($set_as_array[$key])) { |
|
| 157 | 157 | // ensure value is an array |
| 158 | - $value = is_array( $value ) ? $value : array( $value ); |
|
| 158 | + $value = is_array($value) ? $value : array($value); |
|
| 159 | 159 | // and merge with existing values |
| 160 | - $this->{$_key} = array_merge( $this->{$_key}, $value ); |
|
| 160 | + $this->{$_key} = array_merge($this->{$_key}, $value); |
|
| 161 | 161 | } else { |
| 162 | 162 | $this->{$_key} = $value; |
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | // ensure that "required" is set correctly |
| 167 | - $this->set_required( $this->_required, isset( $input_args[ 'required_validation_error_message' ] ) ? $input_args[ 'required_validation_error_message' ] : NULL ); |
|
| 167 | + $this->set_required($this->_required, isset($input_args['required_validation_error_message']) ? $input_args['required_validation_error_message'] : NULL); |
|
| 168 | 168 | |
| 169 | - $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
| 169 | + $this->_html_name_specified = isset($input_args['html_name']) ? TRUE : FALSE; |
|
| 170 | 170 | |
| 171 | 171 | $this->_display_strategy->_construct_finalize($this); |
| 172 | 172 | |
| 173 | - if ( $this->_validation_strategies ){ |
|
| 174 | - foreach( $this->_validation_strategies as $validation_strategy ){ |
|
| 173 | + if ($this->_validation_strategies) { |
|
| 174 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
| 175 | 175 | $validation_strategy->_construct_finalize($this); |
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - if( ! $this->_normalization_strategy){ |
|
| 179 | + if ( ! $this->_normalization_strategy) { |
|
| 180 | 180 | $this->_normalization_strategy = new EE_Text_Normalization(); |
| 181 | 181 | } |
| 182 | 182 | $this->_normalization_strategy->_construct_finalize($this); |
| 183 | 183 | |
| 184 | 184 | //at least we can use the normalization strategy to populate the default |
| 185 | - if( isset( $input_args[ 'default' ] ) ) { |
|
| 186 | - $this->set_default( $input_args[ 'default' ] ); |
|
| 185 | + if (isset($input_args['default'])) { |
|
| 186 | + $this->set_default($input_args['default']); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if( ! $this->_sensitive_data_removal_strategy){ |
|
| 189 | + if ( ! $this->_sensitive_data_removal_strategy) { |
|
| 190 | 190 | $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
| 191 | 191 | } |
| 192 | 192 | $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
| 193 | - parent::__construct( $input_args ); |
|
| 193 | + parent::__construct($input_args); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
| 197 | 197 | * Sets the html_name to its default value, if none was specified in teh constructor. |
| 198 | 198 | * Calculation involves using the name and the parent's html_name |
| 199 | 199 | */ |
| 200 | - protected function _set_default_html_name_if_empty(){ |
|
| 201 | - if( ! $this->_html_name){ |
|
| 202 | - if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper){ |
|
| 203 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
| 204 | - }else{ |
|
| 200 | + protected function _set_default_html_name_if_empty() { |
|
| 201 | + if ( ! $this->_html_name) { |
|
| 202 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
| 203 | + $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]"; |
|
| 204 | + } else { |
|
| 205 | 205 | $this->_html_name = $this->name(); |
| 206 | 206 | } |
| 207 | 207 | } |
@@ -216,12 +216,12 @@ discard block |
||
| 216 | 216 | function _construct_finalize($parent_form_section, $name) { |
| 217 | 217 | parent::_construct_finalize($parent_form_section, $name); |
| 218 | 218 | $this->_set_default_html_name_if_empty(); |
| 219 | - if( ! $this->_html_label ){ |
|
| 220 | - if( ! $this->_html_label_text){ |
|
| 221 | - $this->_html_label_text = ucwords( str_replace("_"," ",$name)); |
|
| 219 | + if ( ! $this->_html_label) { |
|
| 220 | + if ( ! $this->_html_label_text) { |
|
| 221 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | - do_action( 'AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name ); |
|
| 224 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -229,10 +229,10 @@ discard block |
||
| 229 | 229 | * @return EE_Display_Strategy_Base |
| 230 | 230 | * @throws EE_Error |
| 231 | 231 | */ |
| 232 | - protected function _get_display_strategy(){ |
|
| 233 | - if( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base){ |
|
| 234 | - throw new EE_Error(sprintf(__("Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", "event_espresso"),$this->html_name(),$this->html_id())); |
|
| 235 | - }else{ |
|
| 232 | + protected function _get_display_strategy() { |
|
| 233 | + if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
| 234 | + throw new EE_Error(sprintf(__("Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", "event_espresso"), $this->html_name(), $this->html_id())); |
|
| 235 | + } else { |
|
| 236 | 236 | return $this->_display_strategy; |
| 237 | 237 | } |
| 238 | 238 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * Sets the display strategy. |
| 241 | 241 | * @param EE_Display_Strategy_Base $strategy |
| 242 | 242 | */ |
| 243 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy){ |
|
| 243 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) { |
|
| 244 | 244 | $this->_display_strategy = $strategy; |
| 245 | 245 | } |
| 246 | 246 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | * Sets the sanitization strategy |
| 249 | 249 | * @param EE_Normalization_Strategy_Base $strategy |
| 250 | 250 | */ |
| 251 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy){ |
|
| 251 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) { |
|
| 252 | 252 | $this->_normalization_strategy = $strategy; |
| 253 | 253 | } |
| 254 | 254 | |
@@ -274,14 +274,14 @@ discard block |
||
| 274 | 274 | * Gets the display strategy for this input |
| 275 | 275 | * @return EE_Display_Strategy_Base |
| 276 | 276 | */ |
| 277 | - public function get_display_strategy(){ |
|
| 277 | + public function get_display_strategy() { |
|
| 278 | 278 | return $this->_display_strategy; |
| 279 | 279 | } |
| 280 | 280 | /** |
| 281 | 281 | * Overwrites the display strategy |
| 282 | 282 | * @param EE_Display_Strategy_Base $display_strategy |
| 283 | 283 | */ |
| 284 | - public function set_display_strategy($display_strategy){ |
|
| 284 | + public function set_display_strategy($display_strategy) { |
|
| 285 | 285 | $this->_display_strategy = $display_strategy; |
| 286 | 286 | $this->_display_strategy->_construct_finalize($this); |
| 287 | 287 | } |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | * Gets the normalization strategy set on this input |
| 290 | 290 | * @return EE_Normalization_Strategy_Base |
| 291 | 291 | */ |
| 292 | - public function get_normalization_strategy(){ |
|
| 292 | + public function get_normalization_strategy() { |
|
| 293 | 293 | return $this->_normalization_strategy; |
| 294 | 294 | } |
| 295 | 295 | /** |
| 296 | 296 | * Overwrites the normalization strategy |
| 297 | 297 | * @param EE_Normalization_Strategy_Base $normalization_strategy |
| 298 | 298 | */ |
| 299 | - public function set_normalization_strategy($normalization_strategy){ |
|
| 299 | + public function set_normalization_strategy($normalization_strategy) { |
|
| 300 | 300 | $this->_normalization_strategy = $normalization_strategy; |
| 301 | 301 | $this->_normalization_strategy->_construct_finalize($this); |
| 302 | 302 | } |
@@ -305,10 +305,10 @@ discard block |
||
| 305 | 305 | * Returns all teh validation strategies which apply to this field, numerically indexed |
| 306 | 306 | * @return EE_Validation_Strategy_Base[] |
| 307 | 307 | */ |
| 308 | - public function get_validation_strategies(){ |
|
| 309 | - if(is_array($this->_validation_strategies)){ |
|
| 308 | + public function get_validation_strategies() { |
|
| 309 | + if (is_array($this->_validation_strategies)) { |
|
| 310 | 310 | return $this->_validation_strategies; |
| 311 | - }else{ |
|
| 311 | + } else { |
|
| 312 | 312 | return array(); |
| 313 | 313 | } |
| 314 | 314 | |
@@ -318,9 +318,9 @@ discard block |
||
| 318 | 318 | * @param EE_Validation_Strategy_Base $validation_strategy |
| 319 | 319 | * @return void |
| 320 | 320 | */ |
| 321 | - protected function _add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ){ |
|
| 322 | - $validation_strategy->_construct_finalize( $this ); |
|
| 323 | - $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy; |
|
| 321 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
| 322 | + $validation_strategy->_construct_finalize($this); |
|
| 323 | + $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
| 324 | 324 | |
| 325 | 325 | } |
| 326 | 326 | |
@@ -329,18 +329,18 @@ discard block |
||
| 329 | 329 | * @param EE_Validation_Strategy_Base $validation_strategy |
| 330 | 330 | * @return void |
| 331 | 331 | */ |
| 332 | - public function add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ) { |
|
| 333 | - $this->_add_validation_strategy( $validation_strategy ); |
|
| 332 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
| 333 | + $this->_add_validation_strategy($validation_strategy); |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
| 337 | 337 | * The classname of the validation strategy to remove |
| 338 | 338 | * @param string $validation_strategy_classname |
| 339 | 339 | */ |
| 340 | - public function remove_validation_strategy( $validation_strategy_classname ) { |
|
| 341 | - foreach( $this->_validation_strategies as $key => $validation_strategy ){ |
|
| 342 | - if( is_subclass_of( $validation_strategy, $validation_strategy_classname ) ){ |
|
| 343 | - unset( $this->_validation_strategies[ $key ] ); |
|
| 340 | + public function remove_validation_strategy($validation_strategy_classname) { |
|
| 341 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
| 342 | + if (is_subclass_of($validation_strategy, $validation_strategy_classname)) { |
|
| 343 | + unset($this->_validation_strategies[$key]); |
|
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | 346 | } |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | * to the parent form's layout strategy |
| 350 | 350 | * @return string |
| 351 | 351 | */ |
| 352 | - public function get_html_and_js(){ |
|
| 352 | + public function get_html_and_js() { |
|
| 353 | 353 | return $this->_parent_section->get_html_for_input($this); |
| 354 | 354 | } |
| 355 | 355 | /** |
@@ -358,7 +358,7 @@ discard block |
||
| 358 | 358 | * Makes sure the JS and CSS are enqueued for it |
| 359 | 359 | * @return string |
| 360 | 360 | */ |
| 361 | - public function get_html_for_input(){ |
|
| 361 | + public function get_html_for_input() { |
|
| 362 | 362 | return $this->_get_display_strategy()->display(); |
| 363 | 363 | } |
| 364 | 364 | |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | 370 | public function html_other_attributes() { |
| 371 | - return ! empty( $this->_html_other_attributes ) ? ' ' . $this->_html_other_attributes : ''; |
|
| 371 | + return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : ''; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | /** |
| 377 | 377 | * @param string $html_other_attributes |
| 378 | 378 | */ |
| 379 | - public function set_html_other_attributes( $html_other_attributes ) { |
|
| 379 | + public function set_html_other_attributes($html_other_attributes) { |
|
| 380 | 380 | $this->_html_other_attributes = $html_other_attributes; |
| 381 | 381 | } |
| 382 | 382 | |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | * according to the form section's layout strategy |
| 386 | 386 | * @return string |
| 387 | 387 | */ |
| 388 | - public function get_html_for_label(){ |
|
| 388 | + public function get_html_for_label() { |
|
| 389 | 389 | return $this->_parent_section->get_layout_strategy()->display_label($this); |
| 390 | 390 | } |
| 391 | 391 | /** |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | * according to the form section's layout strategy |
| 394 | 394 | * @return string |
| 395 | 395 | */ |
| 396 | - public function get_html_for_errors(){ |
|
| 396 | + public function get_html_for_errors() { |
|
| 397 | 397 | return $this->_parent_section->get_layout_strategy()->display_errors($this); |
| 398 | 398 | } |
| 399 | 399 | /** |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | * according to the form section's layout strategy |
| 402 | 402 | * @return string |
| 403 | 403 | */ |
| 404 | - public function get_html_for_help(){ |
|
| 404 | + public function get_html_for_help() { |
|
| 405 | 405 | return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
| 406 | 406 | } |
| 407 | 407 | /** |
@@ -410,20 +410,20 @@ discard block |
||
| 410 | 410 | * @return boolean |
| 411 | 411 | */ |
| 412 | 412 | protected function _validate() { |
| 413 | - if(is_array($this->_validation_strategies)){ |
|
| 414 | - foreach($this->_validation_strategies as $validation_strategy){ |
|
| 415 | - if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
|
| 416 | - try{ |
|
| 413 | + if (is_array($this->_validation_strategies)) { |
|
| 414 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
| 415 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
| 416 | + try { |
|
| 417 | 417 | $validation_strategy->validate($this->normalized_value()); |
| 418 | - }catch(EE_Validation_Error $e){ |
|
| 418 | + } catch (EE_Validation_Error $e) { |
|
| 419 | 419 | $this->add_validation_error($e); |
| 420 | 420 | } |
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | - if( $this->get_validation_errors()){ |
|
| 424 | + if ($this->get_validation_errors()) { |
|
| 425 | 425 | return false; |
| 426 | - }else{ |
|
| 426 | + } else { |
|
| 427 | 427 | return true; |
| 428 | 428 | } |
| 429 | 429 | } |
@@ -436,8 +436,8 @@ discard block |
||
| 436 | 436 | * @param string $value |
| 437 | 437 | * @return null|string |
| 438 | 438 | */ |
| 439 | - private function _sanitize($value){ |
|
| 440 | - return $value !== NULL ?stripslashes(html_entity_decode($value)) : NULL;//don't sanitize_text_field |
|
| 439 | + private function _sanitize($value) { |
|
| 440 | + return $value !== NULL ? stripslashes(html_entity_decode($value)) : NULL; //don't sanitize_text_field |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | |
@@ -449,24 +449,24 @@ discard block |
||
| 449 | 449 | * @param array $req_data like $_POST |
| 450 | 450 | * @return boolean whether or not there was an error |
| 451 | 451 | */ |
| 452 | - protected function _normalize( $req_data ) { |
|
| 452 | + protected function _normalize($req_data) { |
|
| 453 | 453 | //any existing validation errors don't apply so clear them |
| 454 | 454 | $this->_validation_errors = array(); |
| 455 | 455 | try { |
| 456 | - $raw_input = $this->find_form_data_for_this_section( $req_data ); |
|
| 456 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
| 457 | 457 | //super simple sanitization for now |
| 458 | - if ( is_array( $raw_input )) { |
|
| 458 | + if (is_array($raw_input)) { |
|
| 459 | 459 | $this->_raw_value = array(); |
| 460 | - foreach( $raw_input as $key => $value ) { |
|
| 461 | - $this->_raw_value[ $key ] = $this->_sanitize( $value ); |
|
| 460 | + foreach ($raw_input as $key => $value) { |
|
| 461 | + $this->_raw_value[$key] = $this->_sanitize($value); |
|
| 462 | 462 | } |
| 463 | 463 | } else { |
| 464 | - $this->_raw_value = $this->_sanitize( $raw_input ); |
|
| 464 | + $this->_raw_value = $this->_sanitize($raw_input); |
|
| 465 | 465 | } |
| 466 | 466 | //we want ot mostly leave the input alone in case we need to re-display it to the user |
| 467 | - $this->_normalized_value = $this->_normalization_strategy->normalize( $this->raw_value() ); |
|
| 468 | - } catch ( EE_Validation_Error $e ) { |
|
| 469 | - $this->add_validation_error( $e ); |
|
| 467 | + $this->_normalized_value = $this->_normalization_strategy->normalize($this->raw_value()); |
|
| 468 | + } catch (EE_Validation_Error $e) { |
|
| 469 | + $this->add_validation_error($e); |
|
| 470 | 470 | } |
| 471 | 471 | } |
| 472 | 472 | |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | /** |
| 476 | 476 | * @return string |
| 477 | 477 | */ |
| 478 | - public function html_name(){ |
|
| 478 | + public function html_name() { |
|
| 479 | 479 | return $this->_html_name; |
| 480 | 480 | } |
| 481 | 481 | |
@@ -484,8 +484,8 @@ discard block |
||
| 484 | 484 | /** |
| 485 | 485 | * @return string |
| 486 | 486 | */ |
| 487 | - function html_label_id(){ |
|
| 488 | - return ! empty( $this->_html_label_id ) ? $this->_html_label_id : $this->_html_id . '-lbl'; |
|
| 487 | + function html_label_id() { |
|
| 488 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id.'-lbl'; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | /** |
| 494 | 494 | * @return string |
| 495 | 495 | */ |
| 496 | - function html_label_class(){ |
|
| 496 | + function html_label_class() { |
|
| 497 | 497 | return $this->_html_label_class; |
| 498 | 498 | } |
| 499 | 499 | |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | /** |
| 503 | 503 | * @return string |
| 504 | 504 | */ |
| 505 | - function html_label_style(){ |
|
| 505 | + function html_label_style() { |
|
| 506 | 506 | return $this->_html_label_style; |
| 507 | 507 | } |
| 508 | 508 | |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | /** |
| 512 | 512 | * @return string |
| 513 | 513 | */ |
| 514 | - function html_label_text(){ |
|
| 514 | + function html_label_text() { |
|
| 515 | 515 | return $this->_html_label_text; |
| 516 | 516 | } |
| 517 | 517 | |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | /** |
| 521 | 521 | * @return string |
| 522 | 522 | */ |
| 523 | - function html_help_text(){ |
|
| 523 | + function html_help_text() { |
|
| 524 | 524 | return $this->_html_help_text; |
| 525 | 525 | } |
| 526 | 526 | |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | /** |
| 530 | 530 | * @return string |
| 531 | 531 | */ |
| 532 | - function html_help_class(){ |
|
| 532 | + function html_help_class() { |
|
| 533 | 533 | return $this->_html_help_class; |
| 534 | 534 | } |
| 535 | 535 | |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | /** |
| 539 | 539 | * @return string |
| 540 | 540 | */ |
| 541 | - function html_help_style(){ |
|
| 541 | + function html_help_style() { |
|
| 542 | 542 | return $this->_html_style; |
| 543 | 543 | } |
| 544 | 544 | /** |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | * in which case, we would have stored the malicious content to our database. |
| 552 | 552 | * @return string |
| 553 | 553 | */ |
| 554 | - function raw_value(){ |
|
| 554 | + function raw_value() { |
|
| 555 | 555 | return $this->_raw_value; |
| 556 | 556 | } |
| 557 | 557 | /** |
@@ -559,15 +559,15 @@ discard block |
||
| 559 | 559 | * it escapes all html entities |
| 560 | 560 | * @return string |
| 561 | 561 | */ |
| 562 | - function raw_value_in_form(){ |
|
| 563 | - return htmlentities($this->raw_value(),ENT_QUOTES, 'UTF-8'); |
|
| 562 | + function raw_value_in_form() { |
|
| 563 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
| 564 | 564 | } |
| 565 | 565 | /** |
| 566 | 566 | * returns the value after it's been sanitized, and then converted into it's proper type |
| 567 | 567 | * in PHP. Eg, a string, an int, an array, |
| 568 | 568 | * @return mixed |
| 569 | 569 | */ |
| 570 | - function normalized_value(){ |
|
| 570 | + function normalized_value() { |
|
| 571 | 571 | return $this->_normalized_value; |
| 572 | 572 | } |
| 573 | 573 | |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | * the best thing to display |
| 578 | 578 | * @return string |
| 579 | 579 | */ |
| 580 | - function pretty_value(){ |
|
| 580 | + function pretty_value() { |
|
| 581 | 581 | return $this->_normalized_value; |
| 582 | 582 | } |
| 583 | 583 | /** |
@@ -596,15 +596,15 @@ discard block |
||
| 596 | 596 | }</code> |
| 597 | 597 | * @return array |
| 598 | 598 | */ |
| 599 | - function get_jquery_validation_rules(){ |
|
| 599 | + function get_jquery_validation_rules() { |
|
| 600 | 600 | $jquery_validation_rules = array(); |
| 601 | - foreach($this->get_validation_strategies() as $validation_strategy){ |
|
| 602 | - $jquery_validation_rules = array_replace_recursive( $jquery_validation_rules, $validation_strategy->get_jquery_validation_rule_array()); |
|
| 601 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
| 602 | + $jquery_validation_rules = array_replace_recursive($jquery_validation_rules, $validation_strategy->get_jquery_validation_rule_array()); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | - if(! empty($jquery_validation_rules)){ |
|
| 606 | - $jquery_validation_js[ $this->html_id( TRUE ) ] = $jquery_validation_rules; |
|
| 607 | - }else{ |
|
| 605 | + if ( ! empty($jquery_validation_rules)) { |
|
| 606 | + $jquery_validation_js[$this->html_id(TRUE)] = $jquery_validation_rules; |
|
| 607 | + } else { |
|
| 608 | 608 | return array(); |
| 609 | 609 | } |
| 610 | 610 | return $jquery_validation_js; |
@@ -616,9 +616,9 @@ discard block |
||
| 616 | 616 | * @param mixed $value |
| 617 | 617 | * @return void |
| 618 | 618 | */ |
| 619 | - function set_default($value){ |
|
| 619 | + function set_default($value) { |
|
| 620 | 620 | $this->_normalized_value = $value; |
| 621 | - $this->_raw_value = $this->_normalization_strategy->unnormalize( $value ); |
|
| 621 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | /** |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | * @param string $label |
| 627 | 627 | * @return void |
| 628 | 628 | */ |
| 629 | - function set_html_label_text($label){ |
|
| 629 | + function set_html_label_text($label) { |
|
| 630 | 630 | $this->_html_label_text = $label; |
| 631 | 631 | } |
| 632 | 632 | |
@@ -638,12 +638,12 @@ discard block |
||
| 638 | 638 | * @param boolean $required |
| 639 | 639 | * @param null $required_text |
| 640 | 640 | */ |
| 641 | - function set_required($required = true, $required_text = NULL ){ |
|
| 642 | - $required = filter_var( $required, FILTER_VALIDATE_BOOLEAN ); |
|
| 643 | - if ( $required ) { |
|
| 644 | - $this->_add_validation_strategy( new EE_Required_Validation_Strategy( $required_text ) ); |
|
| 641 | + function set_required($required = true, $required_text = NULL) { |
|
| 642 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
| 643 | + if ($required) { |
|
| 644 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
| 645 | 645 | } else { |
| 646 | - unset( $this->_validation_strategies[ get_class( new EE_Required_Validation_Strategy() ) ] ); |
|
| 646 | + unset($this->_validation_strategies[get_class(new EE_Required_Validation_Strategy())]); |
|
| 647 | 647 | } |
| 648 | 648 | $this->_required = $required; |
| 649 | 649 | } |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | * Returns whether or not this field is required |
| 652 | 652 | * @return boolean |
| 653 | 653 | */ |
| 654 | - public function required(){ |
|
| 654 | + public function required() { |
|
| 655 | 655 | return $this->_required; |
| 656 | 656 | } |
| 657 | 657 | |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | /** |
| 661 | 661 | * @param string $required_css_class |
| 662 | 662 | */ |
| 663 | - public function set_required_css_class( $required_css_class ) { |
|
| 663 | + public function set_required_css_class($required_css_class) { |
|
| 664 | 664 | $this->_required_css_class = $required_css_class; |
| 665 | 665 | } |
| 666 | 666 | |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | * Sets the help text, in case |
| 680 | 680 | * @param string $text |
| 681 | 681 | */ |
| 682 | - public function set_html_help_text($text){ |
|
| 682 | + public function set_html_help_text($text) { |
|
| 683 | 683 | $this->_html_help_text = $text; |
| 684 | 684 | } |
| 685 | 685 | /** |
@@ -691,8 +691,8 @@ discard block |
||
| 691 | 691 | public function clean_sensitive_data() { |
| 692 | 692 | //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
| 693 | 693 | //if we need more logic than this we'll make a strategy for it |
| 694 | - if( $this->_sensitive_data_removal_strategy && |
|
| 695 | - ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal ){ |
|
| 694 | + if ($this->_sensitive_data_removal_strategy && |
|
| 695 | + ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal) { |
|
| 696 | 696 | $this->_raw_value = NULL; |
| 697 | 697 | } |
| 698 | 698 | //and clean the normalized value according to the appropriate strategy |
@@ -706,10 +706,10 @@ discard block |
||
| 706 | 706 | * @param string $button_size |
| 707 | 707 | * @param string $other_attributes |
| 708 | 708 | */ |
| 709 | - public function set_button_css_attributes( $primary = TRUE, $button_size = '', $other_attributes = '' ) { |
|
| 709 | + public function set_button_css_attributes($primary = TRUE, $button_size = '', $other_attributes = '') { |
|
| 710 | 710 | $button_css_attributes = 'button'; |
| 711 | 711 | $button_css_attributes .= $primary === TRUE ? ' button-primary' : ' button-secondary'; |
| 712 | - switch ( $button_size ) { |
|
| 712 | + switch ($button_size) { |
|
| 713 | 713 | case 'xs' : |
| 714 | 714 | case 'extra-small' : |
| 715 | 715 | $button_css_attributes .= ' button-xs'; |
@@ -730,7 +730,7 @@ discard block |
||
| 730 | 730 | default : |
| 731 | 731 | $button_css_attributes .= ''; |
| 732 | 732 | } |
| 733 | - $this->_button_css_attributes .= ! empty( $other_attributes ) ? $button_css_attributes . ' ' . $other_attributes : $button_css_attributes; |
|
| 733 | + $this->_button_css_attributes .= ! empty($other_attributes) ? $button_css_attributes.' '.$other_attributes : $button_css_attributes; |
|
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | |
@@ -739,7 +739,7 @@ discard block |
||
| 739 | 739 | * @return string |
| 740 | 740 | */ |
| 741 | 741 | public function button_css_attributes() { |
| 742 | - if ( empty( $this->_button_css_attributes )) { |
|
| 742 | + if (empty($this->_button_css_attributes)) { |
|
| 743 | 743 | $this->set_button_css_attributes(); |
| 744 | 744 | } |
| 745 | 745 | return $this->_button_css_attributes; |
@@ -759,27 +759,27 @@ discard block |
||
| 759 | 759 | * @param array $req_data |
| 760 | 760 | * @return mixed whatever the raw value of this form section is in the request data |
| 761 | 761 | */ |
| 762 | - public function find_form_data_for_this_section( $req_data ){ |
|
| 762 | + public function find_form_data_for_this_section($req_data) { |
|
| 763 | 763 | // break up the html name by "[]" |
| 764 | - if ( strpos( $this->html_name(), '[' ) !== FALSE ) { |
|
| 765 | - $before_any_brackets = substr( $this->html_name(), 0, strpos($this->html_name(), '[') ); |
|
| 764 | + if (strpos($this->html_name(), '[') !== FALSE) { |
|
| 765 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
| 766 | 766 | } else { |
| 767 | 767 | $before_any_brackets = $this->html_name(); |
| 768 | 768 | } |
| 769 | 769 | // grab all of the segments |
| 770 | - preg_match_all('~\[([^]]*)\]~',$this->html_name(), $matches); |
|
| 771 | - if( isset( $matches[ 1 ] ) && is_array( $matches[ 1 ] ) ){ |
|
| 772 | - $name_parts = $matches[ 1 ]; |
|
| 770 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
| 771 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
| 772 | + $name_parts = $matches[1]; |
|
| 773 | 773 | array_unshift($name_parts, $before_any_brackets); |
| 774 | - }else{ |
|
| 775 | - $name_parts = array( $before_any_brackets ); |
|
| 774 | + } else { |
|
| 775 | + $name_parts = array($before_any_brackets); |
|
| 776 | 776 | } |
| 777 | 777 | // now get the value for the input |
| 778 | 778 | $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
| 779 | - if( $value === NULL ){ |
|
| 779 | + if ($value === NULL) { |
|
| 780 | 780 | //check if this thing's name is at the TOP level of the request data |
| 781 | - if( isset( $req_data[ $this->name() ] ) ){ |
|
| 782 | - $value = $req_data[ $this->name() ]; |
|
| 781 | + if (isset($req_data[$this->name()])) { |
|
| 782 | + $value = $req_data[$this->name()]; |
|
| 783 | 783 | } |
| 784 | 784 | } |
| 785 | 785 | return $value; |
@@ -793,15 +793,15 @@ discard block |
||
| 793 | 793 | * @param array $req_data |
| 794 | 794 | * @return array | NULL |
| 795 | 795 | */ |
| 796 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data){ |
|
| 797 | - $first_part_to_consider = array_shift( $html_name_parts ); |
|
| 798 | - if( isset( $req_data[ $first_part_to_consider ] ) ){ |
|
| 799 | - if( empty($html_name_parts ) ){ |
|
| 800 | - return $req_data[ $first_part_to_consider ]; |
|
| 801 | - }else{ |
|
| 802 | - return $this->_find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data[ $first_part_to_consider ] ); |
|
| 796 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) { |
|
| 797 | + $first_part_to_consider = array_shift($html_name_parts); |
|
| 798 | + if (isset($req_data[$first_part_to_consider])) { |
|
| 799 | + if (empty($html_name_parts)) { |
|
| 800 | + return $req_data[$first_part_to_consider]; |
|
| 801 | + } else { |
|
| 802 | + return $this->_find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data[$first_part_to_consider]); |
|
| 803 | 803 | } |
| 804 | - }else{ |
|
| 804 | + } else { |
|
| 805 | 805 | return NULL; |
| 806 | 806 | } |
| 807 | 807 | } |
@@ -813,14 +813,14 @@ discard block |
||
| 813 | 813 | * @param array $req_data like $_POST |
| 814 | 814 | * @return boolean |
| 815 | 815 | */ |
| 816 | - public function form_data_present_in($req_data = NULL){ |
|
| 817 | - if( $req_data === NULL ){ |
|
| 816 | + public function form_data_present_in($req_data = NULL) { |
|
| 817 | + if ($req_data === NULL) { |
|
| 818 | 818 | $req_data = $_POST; |
| 819 | 819 | } |
| 820 | - $checked_value = $this->find_form_data_for_this_section( $req_data ); |
|
| 821 | - if( $checked_value !== null ){ |
|
| 820 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
| 821 | + if ($checked_value !== null) { |
|
| 822 | 822 | return TRUE; |
| 823 | - }else{ |
|
| 823 | + } else { |
|
| 824 | 824 | return FALSE; |
| 825 | 825 | } |
| 826 | 826 | } |
@@ -101,7 +101,7 @@ |
||
| 101 | 101 | |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | - * @param $payment_method_type |
|
| 104 | + * @param EE_PMT_Base $payment_method_type |
|
| 105 | 105 | * @throws EE_Error |
| 106 | 106 | */ |
| 107 | 107 | public function set_payment_method_type( $payment_method_type ){ |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * Specialized form for payment methods, allowing for easy setting and retrieving of meta fields. |
| 5 | 5 | * Uses EEM_Payment_Method as the model |
| 6 | 6 | */ |
| 7 | -class EE_Payment_Method_Form extends EE_Model_Form_Section{ |
|
| 7 | +class EE_Payment_Method_Form extends EE_Model_Form_Section { |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * All the subsection inputs that correspond ot extra meta rows |
@@ -39,37 +39,37 @@ discard block |
||
| 39 | 39 | * @see EE_Model_Form_Section::__construct() for more |
| 40 | 40 | * } |
| 41 | 41 | */ |
| 42 | - public function __construct($options_array = array()){ |
|
| 42 | + public function __construct($options_array = array()) { |
|
| 43 | 43 | $this->_model = EEM_Payment_Method::instance(); |
| 44 | 44 | $this->_options_array = $options_array; |
| 45 | - if(isset($options_array['payment_method_type'])){ |
|
| 45 | + if (isset($options_array['payment_method_type'])) { |
|
| 46 | 46 | $this->_payment_method_type = $options_array['payment_method_type']; |
| 47 | 47 | } |
| 48 | 48 | $options_array = $this->_options_array; |
| 49 | - if(isset($options_array['extra_meta_inputs'])){ |
|
| 50 | - $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs,$options_array['extra_meta_inputs']); |
|
| 49 | + if (isset($options_array['extra_meta_inputs'])) { |
|
| 50 | + $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $options_array['extra_meta_inputs']); |
|
| 51 | 51 | } |
| 52 | - if($this->_extra_meta_inputs){ |
|
| 53 | - $this->_subsections = array_merge($this->_subsections,$this->_extra_meta_inputs); |
|
| 52 | + if ($this->_extra_meta_inputs) { |
|
| 53 | + $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs); |
|
| 54 | 54 | } |
| 55 | 55 | $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input( |
| 56 | - array( 'html_label_text'=> __( 'Button URL', 'event_espresso' )) |
|
| 56 | + array('html_label_text'=> __('Button URL', 'event_espresso')) |
|
| 57 | 57 | ); |
| 58 | 58 | $this->_subsections['PMD_scope'] = new EE_Checkbox_Multi_Input( |
| 59 | 59 | EEM_Payment_Method::instance()->scopes(), |
| 60 | - array( 'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename() . EEH_Template::get_help_tab_link( 'payment_methods_overview' )) |
|
| 60 | + array('html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename().EEH_Template::get_help_tab_link('payment_methods_overview')) |
|
| 61 | 61 | ); |
| 62 | 62 | //setup the currency options |
| 63 | 63 | $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input( |
| 64 | - EEM_Currency::instance()->get_all_currencies_usable_by( $this->_payment_method_type ), |
|
| 64 | + EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type), |
|
| 65 | 65 | array( |
| 66 | - 'html_label_text'=> __( 'Currencies Supported', 'event_espresso' ), |
|
| 66 | + 'html_label_text'=> __('Currencies Supported', 'event_espresso'), |
|
| 67 | 67 | 'required'=>TRUE |
| 68 | 68 | ) |
| 69 | 69 | ); |
| 70 | - $this->_subsections['PMD_order'] = new EE_Text_Input( array( |
|
| 71 | - 'html_label_text' => __( 'Order', 'event_espresso' ), |
|
| 72 | - 'html_help_text' => __( 'Lowest numbers will be shown first', 'event_espresso' ), |
|
| 70 | + $this->_subsections['PMD_order'] = new EE_Text_Input(array( |
|
| 71 | + 'html_label_text' => __('Order', 'event_espresso'), |
|
| 72 | + 'html_help_text' => __('Lowest numbers will be shown first', 'event_espresso'), |
|
| 73 | 73 | 'normalization_strategy' => new EE_Int_Normalization(), |
| 74 | 74 | 'validation_strategies' => array( |
| 75 | 75 | new EE_Int_Validation_Strategy() |
@@ -88,15 +88,15 @@ discard block |
||
| 88 | 88 | * @param string $name |
| 89 | 89 | * @throws EE_Error |
| 90 | 90 | */ |
| 91 | - public function _construct_finalize( $parent_form_section, $name ) { |
|
| 92 | - if( ! $this->_payment_method_type instanceof EE_PMT_Base ){ |
|
| 93 | - throw new EE_Error( sprintf( __( 'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', 'event_espresso' ))); |
|
| 91 | + public function _construct_finalize($parent_form_section, $name) { |
|
| 92 | + if ( ! $this->_payment_method_type instanceof EE_PMT_Base) { |
|
| 93 | + throw new EE_Error(sprintf(__('Payment Method forms must have set their payment method type BEFORE calling _construct_finalize', 'event_espresso'))); |
|
| 94 | 94 | } |
| 95 | 95 | //set the name of this form based on the payment method type |
| 96 | - if( ! $this->_name && ! $name ){ |
|
| 97 | - $name = str_replace(" ","_",ucwords(str_replace("_"," ",($this->_payment_method_type->system_name()))))."_Settings_Form"; |
|
| 96 | + if ( ! $this->_name && ! $name) { |
|
| 97 | + $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))."_Settings_Form"; |
|
| 98 | 98 | } |
| 99 | - parent::_construct_finalize( $parent_form_section, $name ); |
|
| 99 | + parent::_construct_finalize($parent_form_section, $name); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | * @param $payment_method_type |
| 106 | 106 | * @throws EE_Error |
| 107 | 107 | */ |
| 108 | - public function set_payment_method_type( $payment_method_type ){ |
|
| 109 | - if( ! $payment_method_type instanceof EE_PMT_Base){ |
|
| 108 | + public function set_payment_method_type($payment_method_type) { |
|
| 109 | + if ( ! $payment_method_type instanceof EE_PMT_Base) { |
|
| 110 | 110 | throw new EE_Error(sprintf(__("Payment Method forms MUST set a payment method type by using _set_payment_method_type", "event_espresso"))); |
| 111 | 111 | } |
| 112 | 112 | $this->_payment_method_type = $payment_method_type; |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | * extends the model form section's save method to also save the extra meta field values |
| 119 | 119 | * @return int ID of the payment method inserted, or true on update |
| 120 | 120 | */ |
| 121 | - public function save(){ |
|
| 121 | + public function save() { |
|
| 122 | 122 | $parent_save_val = parent::save(); |
| 123 | - if( $this->_model_object && $this->_model_object->ID()){ |
|
| 124 | - foreach($this->_extra_meta_inputs as $input_name => $input){ |
|
| 123 | + if ($this->_model_object && $this->_model_object->ID()) { |
|
| 124 | + foreach ($this->_extra_meta_inputs as $input_name => $input) { |
|
| 125 | 125 | $this->_model_object->update_extra_meta($input_name, $input->normalized_value()); |
| 126 | 126 | } |
| 127 | 127 | } |
@@ -138,8 +138,8 @@ discard block |
||
| 138 | 138 | $model_obj = $this->_model->ensure_is_obj($model_obj); |
| 139 | 139 | parent::populate_model_obj($model_obj); |
| 140 | 140 | $extra_meta = $model_obj->all_extra_meta_array(); |
| 141 | - foreach($this->_extra_meta_inputs as $input_name => $extra_meta_input){ |
|
| 142 | - if(isset($extra_meta[$input_name])){ |
|
| 141 | + foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) { |
|
| 142 | + if (isset($extra_meta[$input_name])) { |
|
| 143 | 143 | $extra_meta_input->set_default($extra_meta[$input_name]); |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -151,10 +151,10 @@ discard block |
||
| 151 | 151 | * gets the default name of this form section if none is specified |
| 152 | 152 | * @return string |
| 153 | 153 | */ |
| 154 | - protected function _set_default_name_if_empty(){ |
|
| 155 | - if( ! $this->_name ){ |
|
| 156 | - $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form"; |
|
| 157 | - $this->_name = $default_name; |
|
| 154 | + protected function _set_default_name_if_empty() { |
|
| 155 | + if ( ! $this->_name) { |
|
| 156 | + $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form"; |
|
| 157 | + $this->_name = $default_name; |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * Gets all the extra meta inputs in this form |
| 165 | 165 | * @return EE_Form_Input_Base[] |
| 166 | 166 | */ |
| 167 | - public function extra_meta_inputs(){ |
|
| 167 | + public function extra_meta_inputs() { |
|
| 168 | 168 | return $this->_extra_meta_inputs; |
| 169 | 169 | } |
| 170 | 170 | } |