@@ -43,17 +43,16 @@ discard block |
||
43 | 43 | */ |
44 | 44 | protected function _remove_unbillable_registrations(array $registrations = array()): array |
45 | 45 | { |
46 | - if (! empty($registrations)) { |
|
46 | + if ( ! empty($registrations)) { |
|
47 | 47 | // these reg statuses require payment (if event is not free) |
48 | 48 | $requires_payment = EEM_Registration::reg_statuses_that_allow_payment(); |
49 | 49 | foreach ($registrations as $key => $registration) { |
50 | - if (! $registration instanceof EE_Registration) { |
|
50 | + if ( ! $registration instanceof EE_Registration) { |
|
51 | 51 | continue; |
52 | 52 | } |
53 | 53 | // are we billing for this registration at this moment ? |
54 | 54 | if ( |
55 | - ! |
|
56 | - $registration->owes_monies_and_can_pay($requires_payment) && |
|
55 | + ! $registration->owes_monies_and_can_pay($requires_payment) && |
|
57 | 56 | ! ( |
58 | 57 | // free registration with valid reg status |
59 | 58 | $registration->final_price() == 0 && |
@@ -61,7 +60,7 @@ discard block |
||
61 | 60 | ) |
62 | 61 | ) { |
63 | 62 | // not billable. remove it |
64 | - unset($registrations[ $key ]); |
|
63 | + unset($registrations[$key]); |
|
65 | 64 | } |
66 | 65 | } |
67 | 66 | } |
@@ -16,53 +16,53 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Billable_Line_Item_Filter extends EE_Specific_Registrations_Line_Item_Filter |
18 | 18 | { |
19 | - /** |
|
20 | - * EE_Billable_Line_Item_Filter constructor. |
|
21 | - * |
|
22 | - * @param EE_Registration[] $registrations |
|
23 | - * @throws EE_Error |
|
24 | - * @throws EE_Error |
|
25 | - */ |
|
26 | - public function __construct($registrations) |
|
27 | - { |
|
28 | - parent::__construct($this->_remove_unbillable_registrations($registrations)); |
|
29 | - } |
|
19 | + /** |
|
20 | + * EE_Billable_Line_Item_Filter constructor. |
|
21 | + * |
|
22 | + * @param EE_Registration[] $registrations |
|
23 | + * @throws EE_Error |
|
24 | + * @throws EE_Error |
|
25 | + */ |
|
26 | + public function __construct($registrations) |
|
27 | + { |
|
28 | + parent::__construct($this->_remove_unbillable_registrations($registrations)); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * _calculate_billable_ticket_quantities_from_registrations |
|
34 | - * compiles a list of EE_Tickets for each event in the passed array |
|
35 | - * |
|
36 | - * @access protected |
|
37 | - * @param EE_Registration[] $registrations |
|
38 | - * @return EE_Registration[] |
|
39 | - * @throws EE_Error |
|
40 | - * @throws EE_Error |
|
41 | - */ |
|
42 | - protected function _remove_unbillable_registrations(array $registrations = array()): array |
|
43 | - { |
|
44 | - if (! empty($registrations)) { |
|
45 | - // these reg statuses require payment (if event is not free) |
|
46 | - $requires_payment = EEM_Registration::reg_statuses_that_allow_payment(); |
|
47 | - foreach ($registrations as $key => $registration) { |
|
48 | - if (! $registration instanceof EE_Registration) { |
|
49 | - continue; |
|
50 | - } |
|
51 | - // are we billing for this registration at this moment ? |
|
52 | - if ( |
|
53 | - ! |
|
54 | - $registration->owes_monies_and_can_pay($requires_payment) && |
|
55 | - ! ( |
|
56 | - // free registration with valid reg status |
|
57 | - $registration->final_price() == 0 && |
|
58 | - in_array($registration->status_ID(), $requires_payment) |
|
59 | - ) |
|
60 | - ) { |
|
61 | - // not billable. remove it |
|
62 | - unset($registrations[ $key ]); |
|
63 | - } |
|
64 | - } |
|
65 | - } |
|
66 | - return $registrations; |
|
67 | - } |
|
32 | + /** |
|
33 | + * _calculate_billable_ticket_quantities_from_registrations |
|
34 | + * compiles a list of EE_Tickets for each event in the passed array |
|
35 | + * |
|
36 | + * @access protected |
|
37 | + * @param EE_Registration[] $registrations |
|
38 | + * @return EE_Registration[] |
|
39 | + * @throws EE_Error |
|
40 | + * @throws EE_Error |
|
41 | + */ |
|
42 | + protected function _remove_unbillable_registrations(array $registrations = array()): array |
|
43 | + { |
|
44 | + if (! empty($registrations)) { |
|
45 | + // these reg statuses require payment (if event is not free) |
|
46 | + $requires_payment = EEM_Registration::reg_statuses_that_allow_payment(); |
|
47 | + foreach ($registrations as $key => $registration) { |
|
48 | + if (! $registration instanceof EE_Registration) { |
|
49 | + continue; |
|
50 | + } |
|
51 | + // are we billing for this registration at this moment ? |
|
52 | + if ( |
|
53 | + ! |
|
54 | + $registration->owes_monies_and_can_pay($requires_payment) && |
|
55 | + ! ( |
|
56 | + // free registration with valid reg status |
|
57 | + $registration->final_price() == 0 && |
|
58 | + in_array($registration->status_ID(), $requires_payment) |
|
59 | + ) |
|
60 | + ) { |
|
61 | + // not billable. remove it |
|
62 | + unset($registrations[ $key ]); |
|
63 | + } |
|
64 | + } |
|
65 | + } |
|
66 | + return $registrations; |
|
67 | + } |
|
68 | 68 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public function process(EE_Line_Item $line_item): ?EE_Line_Item |
35 | 35 | { |
36 | 36 | $non_zero_line_item = $this->_filter_zero_line_item($line_item); |
37 | - if (! $non_zero_line_item instanceof EE_Line_Item) { |
|
37 | + if ( ! $non_zero_line_item instanceof EE_Line_Item) { |
|
38 | 38 | return null; |
39 | 39 | } |
40 | 40 | // if this is an event subtotal, we want to only include it if it |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | foreach ($line_item->children() as $child_line_item) { |
45 | 45 | $code = $child_line_item->code(); |
46 | 46 | $child_line_item = $this->process($child_line_item); |
47 | - if (! $child_line_item instanceof EE_Line_Item) { |
|
47 | + if ( ! $child_line_item instanceof EE_Line_Item) { |
|
48 | 48 | $line_item->delete_child_line_item($code); |
49 | 49 | continue; |
50 | 50 | } |
@@ -13,104 +13,104 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Non_Zero_Line_Item_Filter extends EE_Line_Item_Filter_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * EE_Non_Zero_Line_Item_Filter constructor. |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - } |
|
16 | + /** |
|
17 | + * EE_Non_Zero_Line_Item_Filter constructor. |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * Creates a duplicate of the line item tree, except only includes billable items |
|
26 | - * and the portion of line items attributed to billable things |
|
27 | - * |
|
28 | - * @param EE_Line_Item $line_item |
|
29 | - * @return EE_Line_Item |
|
30 | - * @throws EE_Error |
|
31 | - * @throws ReflectionException |
|
32 | - */ |
|
33 | - public function process(EE_Line_Item $line_item): ?EE_Line_Item |
|
34 | - { |
|
35 | - $non_zero_line_item = $this->_filter_zero_line_item($line_item); |
|
36 | - if (! $non_zero_line_item instanceof EE_Line_Item) { |
|
37 | - return null; |
|
38 | - } |
|
39 | - // if this is an event subtotal, we want to only include it if it |
|
40 | - // has a non-zero total and at least one ticket line item child |
|
41 | - if ($line_item->children()) { |
|
42 | - $ticket_or_subtotals_with_tkt_children_count = 0; |
|
43 | - foreach ($line_item->children() as $child_line_item) { |
|
44 | - $code = $child_line_item->code(); |
|
45 | - $child_line_item = $this->process($child_line_item); |
|
46 | - if (! $child_line_item instanceof EE_Line_Item) { |
|
47 | - $line_item->delete_child_line_item($code); |
|
48 | - continue; |
|
49 | - } |
|
50 | - if ( |
|
51 | - ( |
|
52 | - $child_line_item instanceof EEI_Line_Item |
|
53 | - && $child_line_item->type() === EEM_Line_Item::type_sub_total |
|
54 | - ) |
|
55 | - || ( |
|
56 | - $child_line_item->type() === EEM_Line_Item::type_line_item |
|
57 | - && $child_line_item->OBJ_type() === 'Ticket' |
|
58 | - ) |
|
59 | - ) { |
|
60 | - $ticket_or_subtotals_with_tkt_children_count++; |
|
61 | - } |
|
62 | - } |
|
63 | - // if this is an event subtotal with NO ticket children |
|
64 | - // we basically want to ignore it |
|
65 | - return $this->_filter_zero_subtotal_line_item( |
|
66 | - $non_zero_line_item, |
|
67 | - $ticket_or_subtotals_with_tkt_children_count |
|
68 | - ); |
|
69 | - } |
|
70 | - return $non_zero_line_item; |
|
71 | - } |
|
24 | + /** |
|
25 | + * Creates a duplicate of the line item tree, except only includes billable items |
|
26 | + * and the portion of line items attributed to billable things |
|
27 | + * |
|
28 | + * @param EE_Line_Item $line_item |
|
29 | + * @return EE_Line_Item |
|
30 | + * @throws EE_Error |
|
31 | + * @throws ReflectionException |
|
32 | + */ |
|
33 | + public function process(EE_Line_Item $line_item): ?EE_Line_Item |
|
34 | + { |
|
35 | + $non_zero_line_item = $this->_filter_zero_line_item($line_item); |
|
36 | + if (! $non_zero_line_item instanceof EE_Line_Item) { |
|
37 | + return null; |
|
38 | + } |
|
39 | + // if this is an event subtotal, we want to only include it if it |
|
40 | + // has a non-zero total and at least one ticket line item child |
|
41 | + if ($line_item->children()) { |
|
42 | + $ticket_or_subtotals_with_tkt_children_count = 0; |
|
43 | + foreach ($line_item->children() as $child_line_item) { |
|
44 | + $code = $child_line_item->code(); |
|
45 | + $child_line_item = $this->process($child_line_item); |
|
46 | + if (! $child_line_item instanceof EE_Line_Item) { |
|
47 | + $line_item->delete_child_line_item($code); |
|
48 | + continue; |
|
49 | + } |
|
50 | + if ( |
|
51 | + ( |
|
52 | + $child_line_item instanceof EEI_Line_Item |
|
53 | + && $child_line_item->type() === EEM_Line_Item::type_sub_total |
|
54 | + ) |
|
55 | + || ( |
|
56 | + $child_line_item->type() === EEM_Line_Item::type_line_item |
|
57 | + && $child_line_item->OBJ_type() === 'Ticket' |
|
58 | + ) |
|
59 | + ) { |
|
60 | + $ticket_or_subtotals_with_tkt_children_count++; |
|
61 | + } |
|
62 | + } |
|
63 | + // if this is an event subtotal with NO ticket children |
|
64 | + // we basically want to ignore it |
|
65 | + return $this->_filter_zero_subtotal_line_item( |
|
66 | + $non_zero_line_item, |
|
67 | + $ticket_or_subtotals_with_tkt_children_count |
|
68 | + ); |
|
69 | + } |
|
70 | + return $non_zero_line_item; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * Creates a new, unsaved line item, but if it's a ticket line item |
|
76 | - * with a total of 0, or a subtotal of 0, returns null instead |
|
77 | - * |
|
78 | - * @param EE_Line_Item $line_item |
|
79 | - * @return EE_Line_Item |
|
80 | - * @throws EE_Error |
|
81 | - * @throws ReflectionException |
|
82 | - */ |
|
83 | - protected function _filter_zero_line_item(EE_Line_Item $line_item): ?EE_Line_Item |
|
84 | - { |
|
85 | - if ( |
|
86 | - $line_item->type() === EEM_Line_Item::type_line_item |
|
87 | - && $line_item->OBJ_type() === 'Ticket' |
|
88 | - && $line_item->quantity() === 0 |
|
89 | - ) { |
|
90 | - return null; |
|
91 | - } |
|
92 | - return $line_item; |
|
93 | - } |
|
74 | + /** |
|
75 | + * Creates a new, unsaved line item, but if it's a ticket line item |
|
76 | + * with a total of 0, or a subtotal of 0, returns null instead |
|
77 | + * |
|
78 | + * @param EE_Line_Item $line_item |
|
79 | + * @return EE_Line_Item |
|
80 | + * @throws EE_Error |
|
81 | + * @throws ReflectionException |
|
82 | + */ |
|
83 | + protected function _filter_zero_line_item(EE_Line_Item $line_item): ?EE_Line_Item |
|
84 | + { |
|
85 | + if ( |
|
86 | + $line_item->type() === EEM_Line_Item::type_line_item |
|
87 | + && $line_item->OBJ_type() === 'Ticket' |
|
88 | + && $line_item->quantity() === 0 |
|
89 | + ) { |
|
90 | + return null; |
|
91 | + } |
|
92 | + return $line_item; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * Creates a new, unsaved line item, but if it's a ticket line item |
|
98 | - * with a total of 0, or a subtotal of 0, returns null instead |
|
99 | - * |
|
100 | - * @param EE_Line_Item $line_item |
|
101 | - * @param int $ticket_children |
|
102 | - * @return EE_Line_Item |
|
103 | - * @throws EE_Error |
|
104 | - * @throws ReflectionException |
|
105 | - */ |
|
106 | - protected function _filter_zero_subtotal_line_item(EE_Line_Item $line_item, int $ticket_children = 0): ?EE_Line_Item |
|
107 | - { |
|
108 | - if ( |
|
109 | - (int) $ticket_children === 0 |
|
110 | - && $line_item->type() === EEM_Line_Item::type_sub_total |
|
111 | - ) { |
|
112 | - return null; |
|
113 | - } |
|
114 | - return $line_item; |
|
115 | - } |
|
96 | + /** |
|
97 | + * Creates a new, unsaved line item, but if it's a ticket line item |
|
98 | + * with a total of 0, or a subtotal of 0, returns null instead |
|
99 | + * |
|
100 | + * @param EE_Line_Item $line_item |
|
101 | + * @param int $ticket_children |
|
102 | + * @return EE_Line_Item |
|
103 | + * @throws EE_Error |
|
104 | + * @throws ReflectionException |
|
105 | + */ |
|
106 | + protected function _filter_zero_subtotal_line_item(EE_Line_Item $line_item, int $ticket_children = 0): ?EE_Line_Item |
|
107 | + { |
|
108 | + if ( |
|
109 | + (int) $ticket_children === 0 |
|
110 | + && $line_item->type() === EEM_Line_Item::type_sub_total |
|
111 | + ) { |
|
112 | + return null; |
|
113 | + } |
|
114 | + return $line_item; |
|
115 | + } |
|
116 | 116 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $html = ''; |
77 | 77 | // set some default options and merge with incoming |
78 | 78 | $default_options = array( |
79 | - 'show_desc' => true, // TRUE FALSE |
|
79 | + 'show_desc' => true, // TRUE FALSE |
|
80 | 80 | 'odd' => false |
81 | 81 | ); |
82 | 82 | $options = array_merge($default_options, (array) $options); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | ); |
164 | 164 | $name_and_desc .= apply_filters( |
165 | 165 | 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc', |
166 | - ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ), |
|
166 | + ($options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : ''), |
|
167 | 167 | $line_item, |
168 | 168 | $options |
169 | 169 | ); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $includes_taxes = $this->prices_include_taxes |
172 | 172 | ? esc_html__('* price includes taxes', 'event_espresso') |
173 | 173 | : esc_html__('* price does not include taxes', 'event_espresso'); |
174 | - $name_and_desc .= '<br /><span class="smaller-text grey-text">' . $includes_taxes . '</span>'; |
|
174 | + $name_and_desc .= '<br /><span class="smaller-text grey-text">'.$includes_taxes.'</span>'; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | // name td |
@@ -228,12 +228,12 @@ discard block |
||
228 | 228 | $html = EEH_HTML::tr('', 'item sub-item-row'); |
229 | 229 | // name && desc |
230 | 230 | $name_and_desc = $line_item->name(); |
231 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : ''; |
|
231 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' : ''; |
|
232 | 232 | // name td |
233 | 233 | $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item'); |
234 | 234 | // discount/surcharge td |
235 | 235 | if ($line_item->is_percent()) { |
236 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c'); |
|
236 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c'); |
|
237 | 237 | } else { |
238 | 238 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
239 | 239 | } |
@@ -1,248 +1,248 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** |
4 | - * |
|
5 | - * Class EE_Default_Line_Item_Display_Strategy |
|
6 | - * |
|
7 | - * Description |
|
8 | - * |
|
9 | - * @package Event Espresso |
|
10 | - * @subpackage core |
|
11 | - * @author Brent Christensen |
|
12 | - * |
|
13 | - * |
|
14 | - */ |
|
4 | + * |
|
5 | + * Class EE_Default_Line_Item_Display_Strategy |
|
6 | + * |
|
7 | + * Description |
|
8 | + * |
|
9 | + * @package Event Espresso |
|
10 | + * @subpackage core |
|
11 | + * @author Brent Christensen |
|
12 | + * |
|
13 | + * |
|
14 | + */ |
|
15 | 15 | |
16 | 16 | class EE_Default_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
17 | 17 | { |
18 | - /** |
|
19 | - * @var bool |
|
20 | - */ |
|
21 | - protected $prices_include_taxes = false; |
|
22 | - |
|
23 | - /** |
|
24 | - * total amount of tax to apply |
|
25 | - * @type float $_tax_rate |
|
26 | - */ |
|
27 | - private $_tax_rate = 0; |
|
28 | - |
|
29 | - /** |
|
30 | - * total amount including tax we can bill for at this time |
|
31 | - * @type float $_grand_total |
|
32 | - */ |
|
33 | - private $_grand_total = 0.00; |
|
34 | - |
|
35 | - /** |
|
36 | - * total number of items being billed for |
|
37 | - * @type int $_total_items |
|
38 | - */ |
|
39 | - private $_total_items = 0; |
|
40 | - |
|
41 | - |
|
42 | - public function __construct() |
|
43 | - { |
|
44 | - $this->prices_include_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @return float |
|
50 | - */ |
|
51 | - public function grand_total() |
|
52 | - { |
|
53 | - return $this->_grand_total; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @return int |
|
60 | - */ |
|
61 | - public function total_items() |
|
62 | - { |
|
63 | - return $this->_total_items; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @param EE_Line_Item $line_item |
|
70 | - * @param array $options |
|
71 | - * @return mixed |
|
72 | - */ |
|
73 | - public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
74 | - { |
|
75 | - |
|
76 | - $html = ''; |
|
77 | - // set some default options and merge with incoming |
|
78 | - $default_options = array( |
|
79 | - 'show_desc' => true, // TRUE FALSE |
|
80 | - 'odd' => false |
|
81 | - ); |
|
82 | - $options = array_merge($default_options, (array) $options); |
|
83 | - |
|
84 | - switch ($line_item->type()) { |
|
85 | - case EEM_Line_Item::type_line_item: |
|
86 | - // item row |
|
87 | - $html .= $this->_item_row($line_item, $options); |
|
88 | - // got any kids? |
|
89 | - foreach ($line_item->children() as $child_line_item) { |
|
90 | - $this->display_line_item($child_line_item, $options); |
|
91 | - } |
|
92 | - break; |
|
93 | - |
|
94 | - case EEM_Line_Item::type_sub_line_item: |
|
95 | - $html .= $this->_sub_item_row($line_item, $options); |
|
96 | - break; |
|
97 | - |
|
98 | - case EEM_Line_Item::type_sub_total: |
|
99 | - break; |
|
100 | - |
|
101 | - case EEM_Line_Item::type_tax: |
|
102 | - $this->_tax_rate += $line_item->percent(); |
|
103 | - break; |
|
104 | - |
|
105 | - case EEM_Line_Item::type_tax_sub_total: |
|
106 | - foreach ($line_item->children() as $child_line_item) { |
|
107 | - if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
108 | - // recursively feed children back into this method |
|
109 | - $this->display_line_item($child_line_item, $options); |
|
110 | - } |
|
111 | - } |
|
112 | - break; |
|
113 | - |
|
114 | - case EEM_Line_Item::type_total: |
|
115 | - // get all child line items |
|
116 | - $children = $line_item->children(); |
|
117 | - if ($options['set_tax_rate'] === true) { |
|
118 | - // loop thru tax child line items just to determine tax rate |
|
119 | - foreach ($children as $child_line_item) { |
|
120 | - if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) { |
|
121 | - // recursively feed children back into this method |
|
122 | - $this->display_line_item($child_line_item, $options); |
|
123 | - } |
|
124 | - } |
|
125 | - } else { |
|
126 | - // now loop thru all non-tax child line items |
|
127 | - foreach ($children as $child_line_item) { |
|
128 | - if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) { |
|
129 | - // recursively feed children back into this method |
|
130 | - $html .= $this->display_line_item($child_line_item, $options); |
|
131 | - } |
|
132 | - } |
|
133 | - } |
|
134 | - break; |
|
135 | - } |
|
136 | - |
|
137 | - return $html; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * _total_row |
|
143 | - * |
|
144 | - * @param EE_Line_Item $line_item |
|
145 | - * @param array $options |
|
146 | - * @return string |
|
147 | - * @throws EE_Error |
|
148 | - * @throws ReflectionException |
|
149 | - */ |
|
150 | - private function _item_row(EE_Line_Item $line_item, array $options = array()): string |
|
151 | - { |
|
152 | - $sub_taxes = $line_item->getSubTaxes(); |
|
153 | - $has_sub_taxes = ! empty($sub_taxes); |
|
154 | - $is_taxable = $line_item->is_taxable(); |
|
155 | - |
|
156 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
157 | - $html = EEH_HTML::tr('', '', $row_class); |
|
158 | - // name && desc |
|
159 | - $name_and_desc = apply_filters( |
|
160 | - 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name', |
|
161 | - $line_item->name(), |
|
162 | - $line_item |
|
163 | - ); |
|
164 | - $name_and_desc .= apply_filters( |
|
165 | - 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc', |
|
166 | - ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ), |
|
167 | - $line_item, |
|
168 | - $options |
|
169 | - ); |
|
170 | - if ($is_taxable || $has_sub_taxes) { |
|
171 | - $includes_taxes = $this->prices_include_taxes |
|
172 | - ? esc_html__('* price includes taxes', 'event_espresso') |
|
173 | - : esc_html__('* price does not include taxes', 'event_espresso'); |
|
174 | - $name_and_desc .= '<br /><span class="smaller-text grey-text">' . $includes_taxes . '</span>'; |
|
175 | - } |
|
176 | - |
|
177 | - // name td |
|
178 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
179 | - // quantity td |
|
180 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
181 | - $tax_rate = 1; |
|
182 | - if ($this->prices_include_taxes) { |
|
183 | - if ($has_sub_taxes) { |
|
184 | - $tax_rate = 0; |
|
185 | - foreach ($sub_taxes as $sub_tax) { |
|
186 | - if ($sub_tax instanceof EE_Line_Item && $sub_tax->isSubTax()) { |
|
187 | - $tax_rate += $sub_tax->percent(); |
|
188 | - } |
|
189 | - } |
|
190 | - $tax_rate = 1 + $tax_rate / 100; |
|
191 | - } elseif ($is_taxable && $this->prices_include_taxes) { |
|
192 | - $tax_rate = 1 + ($this->_tax_rate / 100); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - // price td |
|
197 | - $unit_price = apply_filters( |
|
198 | - 'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__unit_price', |
|
199 | - EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false), |
|
200 | - $line_item, |
|
201 | - $tax_rate |
|
202 | - ); |
|
203 | - $html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght'); |
|
204 | - // total td |
|
205 | - $total = apply_filters( |
|
206 | - 'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__total', |
|
207 | - EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false), |
|
208 | - $line_item, |
|
209 | - $tax_rate |
|
210 | - ); |
|
211 | - $html .= EEH_HTML::td($total, '', 'item_r jst-rght'); |
|
212 | - // end of row |
|
213 | - $html .= EEH_HTML::trx(); |
|
214 | - |
|
215 | - return $html; |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * _sub_item_row |
|
222 | - * |
|
223 | - * @param EE_Line_Item $line_item |
|
224 | - * @param array $options |
|
225 | - * @return mixed |
|
226 | - */ |
|
227 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
228 | - { |
|
229 | - // start of row |
|
230 | - $html = EEH_HTML::tr('', 'item sub-item-row'); |
|
231 | - // name && desc |
|
232 | - $name_and_desc = $line_item->name(); |
|
233 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : ''; |
|
234 | - // name td |
|
235 | - $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item'); |
|
236 | - // discount/surcharge td |
|
237 | - if ($line_item->is_percent()) { |
|
238 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c'); |
|
239 | - } else { |
|
240 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
241 | - } |
|
242 | - // total td |
|
243 | - $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght'); |
|
244 | - // end of row |
|
245 | - $html .= EEH_HTML::trx(); |
|
246 | - return $html; |
|
247 | - } |
|
18 | + /** |
|
19 | + * @var bool |
|
20 | + */ |
|
21 | + protected $prices_include_taxes = false; |
|
22 | + |
|
23 | + /** |
|
24 | + * total amount of tax to apply |
|
25 | + * @type float $_tax_rate |
|
26 | + */ |
|
27 | + private $_tax_rate = 0; |
|
28 | + |
|
29 | + /** |
|
30 | + * total amount including tax we can bill for at this time |
|
31 | + * @type float $_grand_total |
|
32 | + */ |
|
33 | + private $_grand_total = 0.00; |
|
34 | + |
|
35 | + /** |
|
36 | + * total number of items being billed for |
|
37 | + * @type int $_total_items |
|
38 | + */ |
|
39 | + private $_total_items = 0; |
|
40 | + |
|
41 | + |
|
42 | + public function __construct() |
|
43 | + { |
|
44 | + $this->prices_include_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @return float |
|
50 | + */ |
|
51 | + public function grand_total() |
|
52 | + { |
|
53 | + return $this->_grand_total; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @return int |
|
60 | + */ |
|
61 | + public function total_items() |
|
62 | + { |
|
63 | + return $this->_total_items; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @param EE_Line_Item $line_item |
|
70 | + * @param array $options |
|
71 | + * @return mixed |
|
72 | + */ |
|
73 | + public function display_line_item(EE_Line_Item $line_item, $options = array()) |
|
74 | + { |
|
75 | + |
|
76 | + $html = ''; |
|
77 | + // set some default options and merge with incoming |
|
78 | + $default_options = array( |
|
79 | + 'show_desc' => true, // TRUE FALSE |
|
80 | + 'odd' => false |
|
81 | + ); |
|
82 | + $options = array_merge($default_options, (array) $options); |
|
83 | + |
|
84 | + switch ($line_item->type()) { |
|
85 | + case EEM_Line_Item::type_line_item: |
|
86 | + // item row |
|
87 | + $html .= $this->_item_row($line_item, $options); |
|
88 | + // got any kids? |
|
89 | + foreach ($line_item->children() as $child_line_item) { |
|
90 | + $this->display_line_item($child_line_item, $options); |
|
91 | + } |
|
92 | + break; |
|
93 | + |
|
94 | + case EEM_Line_Item::type_sub_line_item: |
|
95 | + $html .= $this->_sub_item_row($line_item, $options); |
|
96 | + break; |
|
97 | + |
|
98 | + case EEM_Line_Item::type_sub_total: |
|
99 | + break; |
|
100 | + |
|
101 | + case EEM_Line_Item::type_tax: |
|
102 | + $this->_tax_rate += $line_item->percent(); |
|
103 | + break; |
|
104 | + |
|
105 | + case EEM_Line_Item::type_tax_sub_total: |
|
106 | + foreach ($line_item->children() as $child_line_item) { |
|
107 | + if ($child_line_item->type() == EEM_Line_Item::type_tax) { |
|
108 | + // recursively feed children back into this method |
|
109 | + $this->display_line_item($child_line_item, $options); |
|
110 | + } |
|
111 | + } |
|
112 | + break; |
|
113 | + |
|
114 | + case EEM_Line_Item::type_total: |
|
115 | + // get all child line items |
|
116 | + $children = $line_item->children(); |
|
117 | + if ($options['set_tax_rate'] === true) { |
|
118 | + // loop thru tax child line items just to determine tax rate |
|
119 | + foreach ($children as $child_line_item) { |
|
120 | + if ($child_line_item->type() == EEM_Line_Item::type_tax_sub_total) { |
|
121 | + // recursively feed children back into this method |
|
122 | + $this->display_line_item($child_line_item, $options); |
|
123 | + } |
|
124 | + } |
|
125 | + } else { |
|
126 | + // now loop thru all non-tax child line items |
|
127 | + foreach ($children as $child_line_item) { |
|
128 | + if ($child_line_item->type() != EEM_Line_Item::type_tax_sub_total) { |
|
129 | + // recursively feed children back into this method |
|
130 | + $html .= $this->display_line_item($child_line_item, $options); |
|
131 | + } |
|
132 | + } |
|
133 | + } |
|
134 | + break; |
|
135 | + } |
|
136 | + |
|
137 | + return $html; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * _total_row |
|
143 | + * |
|
144 | + * @param EE_Line_Item $line_item |
|
145 | + * @param array $options |
|
146 | + * @return string |
|
147 | + * @throws EE_Error |
|
148 | + * @throws ReflectionException |
|
149 | + */ |
|
150 | + private function _item_row(EE_Line_Item $line_item, array $options = array()): string |
|
151 | + { |
|
152 | + $sub_taxes = $line_item->getSubTaxes(); |
|
153 | + $has_sub_taxes = ! empty($sub_taxes); |
|
154 | + $is_taxable = $line_item->is_taxable(); |
|
155 | + |
|
156 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
157 | + $html = EEH_HTML::tr('', '', $row_class); |
|
158 | + // name && desc |
|
159 | + $name_and_desc = apply_filters( |
|
160 | + 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__name', |
|
161 | + $line_item->name(), |
|
162 | + $line_item |
|
163 | + ); |
|
164 | + $name_and_desc .= apply_filters( |
|
165 | + 'FHEE__EE_Default_Line_Item_Display_Strategy__item_row__desc', |
|
166 | + ( $options['show_desc'] ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : '' ), |
|
167 | + $line_item, |
|
168 | + $options |
|
169 | + ); |
|
170 | + if ($is_taxable || $has_sub_taxes) { |
|
171 | + $includes_taxes = $this->prices_include_taxes |
|
172 | + ? esc_html__('* price includes taxes', 'event_espresso') |
|
173 | + : esc_html__('* price does not include taxes', 'event_espresso'); |
|
174 | + $name_and_desc .= '<br /><span class="smaller-text grey-text">' . $includes_taxes . '</span>'; |
|
175 | + } |
|
176 | + |
|
177 | + // name td |
|
178 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
179 | + // quantity td |
|
180 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
181 | + $tax_rate = 1; |
|
182 | + if ($this->prices_include_taxes) { |
|
183 | + if ($has_sub_taxes) { |
|
184 | + $tax_rate = 0; |
|
185 | + foreach ($sub_taxes as $sub_tax) { |
|
186 | + if ($sub_tax instanceof EE_Line_Item && $sub_tax->isSubTax()) { |
|
187 | + $tax_rate += $sub_tax->percent(); |
|
188 | + } |
|
189 | + } |
|
190 | + $tax_rate = 1 + $tax_rate / 100; |
|
191 | + } elseif ($is_taxable && $this->prices_include_taxes) { |
|
192 | + $tax_rate = 1 + ($this->_tax_rate / 100); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + // price td |
|
197 | + $unit_price = apply_filters( |
|
198 | + 'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__unit_price', |
|
199 | + EEH_Template::format_currency($line_item->unit_price() * $tax_rate, false, false), |
|
200 | + $line_item, |
|
201 | + $tax_rate |
|
202 | + ); |
|
203 | + $html .= EEH_HTML::td($unit_price, '', 'item_c jst-rght'); |
|
204 | + // total td |
|
205 | + $total = apply_filters( |
|
206 | + 'FHEE__EE_Default_Line_Item_Display_Strategy___item_row__total', |
|
207 | + EEH_Template::format_currency($line_item->unit_price() * $line_item->quantity() * $tax_rate, false, false), |
|
208 | + $line_item, |
|
209 | + $tax_rate |
|
210 | + ); |
|
211 | + $html .= EEH_HTML::td($total, '', 'item_r jst-rght'); |
|
212 | + // end of row |
|
213 | + $html .= EEH_HTML::trx(); |
|
214 | + |
|
215 | + return $html; |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * _sub_item_row |
|
222 | + * |
|
223 | + * @param EE_Line_Item $line_item |
|
224 | + * @param array $options |
|
225 | + * @return mixed |
|
226 | + */ |
|
227 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array()) |
|
228 | + { |
|
229 | + // start of row |
|
230 | + $html = EEH_HTML::tr('', 'item sub-item-row'); |
|
231 | + // name && desc |
|
232 | + $name_and_desc = $line_item->name(); |
|
233 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' : ''; |
|
234 | + // name td |
|
235 | + $html .= EEH_HTML::td(/*__FUNCTION__ .*/ $name_and_desc, '', 'item_l sub-item'); |
|
236 | + // discount/surcharge td |
|
237 | + if ($line_item->is_percent()) { |
|
238 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c'); |
|
239 | + } else { |
|
240 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
241 | + } |
|
242 | + // total td |
|
243 | + $html .= EEH_HTML::td(EEH_Template::format_currency($line_item->total(), false, false), '', 'item_r jst-rght'); |
|
244 | + // end of row |
|
245 | + $html .= EEH_HTML::trx(); |
|
246 | + return $html; |
|
247 | + } |
|
248 | 248 | } |
@@ -11,684 +11,684 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
13 | 13 | { |
14 | - /** |
|
15 | - * @var bool |
|
16 | - */ |
|
17 | - protected $prices_include_taxes = false; |
|
18 | - |
|
19 | - /** |
|
20 | - * array of events |
|
21 | - * |
|
22 | - * @type EE_Line_Item[] $_events |
|
23 | - */ |
|
24 | - private $_events = array(); |
|
25 | - |
|
26 | - /** |
|
27 | - * whether to display the taxes row or not |
|
28 | - * |
|
29 | - * @type bool $_show_taxes |
|
30 | - */ |
|
31 | - private $_show_taxes = false; |
|
32 | - |
|
33 | - /** |
|
34 | - * html for any tax rows |
|
35 | - * |
|
36 | - * @type string $_show_taxes |
|
37 | - */ |
|
38 | - private $_taxes_html = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * total amount including tax we can bill for at this time |
|
42 | - * |
|
43 | - * @type float $_grand_total |
|
44 | - */ |
|
45 | - private $_grand_total = 0.00; |
|
46 | - |
|
47 | - /** |
|
48 | - * total number of items being billed for |
|
49 | - * |
|
50 | - * @type int $_total_items |
|
51 | - */ |
|
52 | - private $_total_items = 0; |
|
53 | - |
|
54 | - |
|
55 | - public function __construct() |
|
56 | - { |
|
57 | - $this->prices_include_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return float |
|
64 | - */ |
|
65 | - public function grand_total() |
|
66 | - { |
|
67 | - return $this->_grand_total; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return int |
|
74 | - */ |
|
75 | - public function total_items() |
|
76 | - { |
|
77 | - return $this->_total_items; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param EE_Line_Item $line_item |
|
84 | - * @param array $options |
|
85 | - * @param EE_Line_Item $parent_line_item |
|
86 | - * @return mixed |
|
87 | - * @throws EE_Error |
|
88 | - */ |
|
89 | - public function display_line_item( |
|
90 | - EE_Line_Item $line_item, |
|
91 | - $options = array(), |
|
92 | - EE_Line_Item $parent_line_item = null |
|
93 | - ) { |
|
94 | - $html = ''; |
|
95 | - // set some default options and merge with incoming |
|
96 | - $default_options = array( |
|
97 | - 'show_desc' => true, // true false |
|
98 | - 'odd' => false, |
|
99 | - ); |
|
100 | - $options = array_merge($default_options, (array) $options); |
|
101 | - |
|
102 | - switch ($line_item->type()) { |
|
103 | - case EEM_Line_Item::type_line_item: |
|
104 | - $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
105 | - if ($line_item->OBJ_type() === 'Ticket') { |
|
106 | - // item row |
|
107 | - $html .= $this->_ticket_row($line_item, $options); |
|
108 | - } else { |
|
109 | - // item row |
|
110 | - $html .= $this->_item_row($line_item, $options); |
|
111 | - } |
|
112 | - if ( |
|
113 | - apply_filters( |
|
114 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
115 | - true |
|
116 | - ) |
|
117 | - ) { |
|
118 | - // got any kids? |
|
119 | - foreach ($line_item->children() as $child_line_item) { |
|
120 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
121 | - } |
|
122 | - } |
|
123 | - break; |
|
124 | - |
|
125 | - case EEM_Line_Item::type_sub_line_item: |
|
126 | - $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
127 | - break; |
|
128 | - |
|
129 | - case EEM_Line_Item::type_sub_tax: |
|
130 | - $this->_show_taxes = true; |
|
131 | - break; |
|
132 | - |
|
133 | - case EEM_Line_Item::type_sub_total: |
|
134 | - static $sub_total = 0; |
|
135 | - $event_sub_total = 0; |
|
136 | - $text = esc_html__('Sub-Total', 'event_espresso'); |
|
137 | - if ($line_item->OBJ_type() === 'Event') { |
|
138 | - $options['event_id'] = $line_item->OBJ_ID(); |
|
139 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
140 | - $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
141 | - // if event has default reg status of Not Approved, then don't display info on it |
|
142 | - if ( |
|
143 | - $event instanceof EE_Event |
|
144 | - && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
145 | - ) { |
|
146 | - $display_event = false; |
|
147 | - // unless there are registrations for it that are returning to pay |
|
148 | - if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
149 | - foreach ($options['registrations'] as $registration) { |
|
150 | - if (! $registration instanceof EE_Registration) { |
|
151 | - continue; |
|
152 | - } |
|
153 | - $display_event = $registration->event_ID() === $options['event_id'] |
|
154 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
155 | - ? true |
|
156 | - : $display_event; |
|
157 | - } |
|
158 | - } |
|
159 | - if (! $display_event) { |
|
160 | - return ''; |
|
161 | - } |
|
162 | - } |
|
163 | - $this->_events[ $options['event_id'] ] = 0; |
|
164 | - $html .= $this->_event_row($line_item); |
|
165 | - $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
166 | - } |
|
167 | - } |
|
168 | - $child_line_items = $line_item->children(); |
|
169 | - // loop thru children |
|
170 | - foreach ($child_line_items as $child_line_item) { |
|
171 | - // recursively feed children back into this method |
|
172 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
173 | - } |
|
174 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
175 | - $sub_total += $event_sub_total; |
|
176 | - if ( |
|
177 | - ( |
|
178 | - // event subtotals |
|
179 | - $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
180 | - ) |
|
181 | - || ( |
|
182 | - // pre-tax subtotals |
|
183 | - $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
184 | - ) |
|
185 | - ) { |
|
186 | - $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
187 | - $html .= $this->_sub_total_row($line_item, $text, $options); |
|
188 | - } |
|
189 | - break; |
|
190 | - |
|
191 | - case EEM_Line_Item::type_tax: |
|
192 | - if ($this->_show_taxes) { |
|
193 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
194 | - } |
|
195 | - break; |
|
196 | - |
|
197 | - case EEM_Line_Item::type_tax_sub_total: |
|
198 | - if ($this->_show_taxes) { |
|
199 | - $child_line_items = $line_item->children(); |
|
200 | - // loop thru children |
|
201 | - foreach ($child_line_items as $child_line_item) { |
|
202 | - // recursively feed children back into this method |
|
203 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
204 | - } |
|
205 | - if (count($child_line_items) > 1) { |
|
206 | - $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
207 | - } |
|
208 | - } |
|
209 | - break; |
|
210 | - |
|
211 | - case EEM_Line_Item::type_total: |
|
212 | - // get all child line items |
|
213 | - $children = $line_item->children(); |
|
214 | - // loop thru all non-tax child line items |
|
215 | - foreach ($children as $child_line_item) { |
|
216 | - if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
217 | - // recursively feed children back into this method |
|
218 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
219 | - } |
|
220 | - } |
|
221 | - // now loop thru tax child line items |
|
222 | - foreach ($children as $child_line_item) { |
|
223 | - if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
224 | - // recursively feed children back into this method |
|
225 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
226 | - } |
|
227 | - } |
|
228 | - $html .= $this->_taxes_html; |
|
229 | - $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
230 | - $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
231 | - break; |
|
232 | - } |
|
233 | - return $html; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
240 | - * |
|
241 | - * @param EE_Line_Item $line_item |
|
242 | - * @return mixed |
|
243 | - */ |
|
244 | - private function _event_row(EE_Line_Item $line_item) |
|
245 | - { |
|
246 | - // start of row |
|
247 | - $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
248 | - // event name td |
|
249 | - $html .= EEH_HTML::td( |
|
250 | - EEH_HTML::strong($line_item->name()), |
|
251 | - '', |
|
252 | - 'event-header', |
|
253 | - '', |
|
254 | - ' colspan="4"' |
|
255 | - ); |
|
256 | - // end of row |
|
257 | - $html .= EEH_HTML::trx(); |
|
258 | - return $html; |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * _ticket_row |
|
265 | - * |
|
266 | - * @param EE_Line_Item $line_item |
|
267 | - * @param array $options |
|
268 | - * @return mixed |
|
269 | - * @throws EE_Error |
|
270 | - */ |
|
271 | - private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
272 | - { |
|
273 | - // start of row |
|
274 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
275 | - $html = EEH_HTML::tr('', '', $row_class); |
|
276 | - // name && desc |
|
277 | - $name_and_desc = apply_filters( |
|
278 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
279 | - $line_item->name(), |
|
280 | - $line_item |
|
281 | - ); |
|
282 | - $name_and_desc .= apply_filters( |
|
283 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
284 | - ( |
|
285 | - $options['show_desc'] |
|
286 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
287 | - : '' |
|
288 | - ), |
|
289 | - $line_item, |
|
290 | - $options |
|
291 | - ); |
|
292 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
293 | - $name_and_desc = apply_filters( |
|
294 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc', |
|
295 | - $name_and_desc, |
|
296 | - $line_item, |
|
297 | - $options |
|
298 | - ); |
|
299 | - |
|
300 | - // name td |
|
301 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
302 | - $name_and_desc, |
|
303 | - '', |
|
304 | - 'item_l' |
|
305 | - ); |
|
306 | - // price td |
|
307 | - $price = apply_filters( |
|
308 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
309 | - $line_item->unit_price_no_code(), |
|
310 | - $line_item |
|
311 | - ); |
|
312 | - $html .= EEH_HTML::td($price, '', 'spco-nowrap item_c jst-rght'); |
|
313 | - // quantity td |
|
314 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
315 | - $this->_total_items += $line_item->quantity(); |
|
316 | - // determine total for line item |
|
317 | - $total = apply_filters( |
|
318 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
319 | - $line_item->pretaxTotal(), |
|
320 | - $line_item |
|
321 | - ); |
|
322 | - $this->_events[ $options['event_id'] ] += $total; |
|
323 | - // total td |
|
324 | - $html .= EEH_HTML::td( |
|
325 | - EEH_Template::format_currency($total, false, false), |
|
326 | - '', |
|
327 | - 'spco-nowrap item_r jst-rght' |
|
328 | - ); |
|
329 | - // end of row |
|
330 | - $html .= EEH_HTML::trx(); |
|
331 | - return $html; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * _item_row |
|
338 | - * |
|
339 | - * @param EE_Line_Item $line_item |
|
340 | - * @param array $options |
|
341 | - * @return mixed |
|
342 | - * @throws EE_Error |
|
343 | - */ |
|
344 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
345 | - { |
|
346 | - // start of row |
|
347 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
348 | - $html = EEH_HTML::tr('', '', $row_class); |
|
349 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
350 | - // name && desc |
|
351 | - $name_and_desc = apply_filters( |
|
352 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
353 | - $obj_name . $line_item->name(), |
|
354 | - $line_item |
|
355 | - ); |
|
356 | - $name_and_desc .= apply_filters( |
|
357 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
358 | - ( |
|
359 | - $options['show_desc'] |
|
360 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
361 | - : '' |
|
362 | - ), |
|
363 | - $line_item, |
|
364 | - $options |
|
365 | - ); |
|
366 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
367 | - $name_and_desc = apply_filters( |
|
368 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc', |
|
369 | - $name_and_desc, |
|
370 | - $line_item, |
|
371 | - $options |
|
372 | - ); |
|
373 | - |
|
374 | - // name td |
|
375 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
376 | - // price td |
|
377 | - if ($line_item->is_percent()) { |
|
378 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght'); |
|
379 | - } else { |
|
380 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
381 | - } |
|
382 | - // quantity td |
|
383 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
384 | - // $total = $line_item->total() * $line_item->quantity(); |
|
385 | - $total = $line_item->total(); |
|
386 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
387 | - $this->_events[ $options['event_id'] ] += $total; |
|
388 | - } |
|
389 | - // total td |
|
390 | - $html .= EEH_HTML::td( |
|
391 | - EEH_Template::format_currency($total, false, false), |
|
392 | - '', |
|
393 | - 'spco-nowrap item_r jst-rght' |
|
394 | - ); |
|
395 | - // end of row |
|
396 | - $html .= EEH_HTML::trx(); |
|
397 | - return $html; |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * _sub_item_row |
|
404 | - * |
|
405 | - * @param EE_Line_Item $line_item |
|
406 | - * @param array $options |
|
407 | - * @param EE_Line_Item $parent_line_item |
|
408 | - * @return mixed |
|
409 | - * @throws EE_Error |
|
410 | - */ |
|
411 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
412 | - { |
|
413 | - if ( |
|
414 | - $parent_line_item instanceof EE_Line_Item |
|
415 | - && $line_item->children() === array() |
|
416 | - && $line_item->name() === $parent_line_item->name() |
|
417 | - && apply_filters( |
|
418 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
419 | - true |
|
420 | - ) |
|
421 | - ) { |
|
422 | - return ''; |
|
423 | - } |
|
424 | - // start of row |
|
425 | - $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
426 | - // name && desc |
|
427 | - $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
428 | - . $line_item->name(); |
|
429 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
430 | - . $line_item->desc() |
|
431 | - . '</span>' : ''; |
|
432 | - // name td |
|
433 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
434 | - $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
435 | - // discount/surcharge td |
|
436 | - if ($line_item->is_percent()) { |
|
437 | - $html .= EEH_HTML::td( |
|
438 | - EEH_Template::format_currency( |
|
439 | - $line_item->total() / $qty, |
|
440 | - false, |
|
441 | - false |
|
442 | - ), |
|
443 | - '', |
|
444 | - 'spco-nowrap item_c jst-rght' |
|
445 | - ); |
|
446 | - } else { |
|
447 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
448 | - } |
|
449 | - // no quantity td |
|
450 | - $html .= EEH_HTML::td(); |
|
451 | - // no total td |
|
452 | - $html .= EEH_HTML::td(); |
|
453 | - // end of row |
|
454 | - $html .= EEH_HTML::trx(); |
|
455 | - $html = apply_filters( |
|
456 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
457 | - $html, |
|
458 | - $line_item, |
|
459 | - $options, |
|
460 | - $parent_line_item |
|
461 | - ); |
|
462 | - return $html; |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * _tax_row |
|
469 | - * |
|
470 | - * @param EE_Line_Item $line_item |
|
471 | - * @param array $options |
|
472 | - * @return mixed |
|
473 | - * @throws EE_Error |
|
474 | - */ |
|
475 | - private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
476 | - { |
|
477 | - // start of row |
|
478 | - $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
479 | - // name && desc |
|
480 | - $name_and_desc = $line_item->name(); |
|
481 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
482 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
483 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
484 | - // name td |
|
485 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
486 | - $name_and_desc, |
|
487 | - '', |
|
488 | - 'item_l sub-item' |
|
489 | - ); |
|
490 | - // percent td |
|
491 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', ''); |
|
492 | - // empty td (price) |
|
493 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
494 | - // total td |
|
495 | - $html .= EEH_HTML::td( |
|
496 | - EEH_Template::format_currency( |
|
497 | - $line_item->total(), |
|
498 | - false, |
|
499 | - false |
|
500 | - ), |
|
501 | - '', |
|
502 | - 'spco-nowrap item_r jst-rght' |
|
503 | - ); |
|
504 | - // end of row |
|
505 | - $html .= EEH_HTML::trx(); |
|
506 | - return $html; |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * _total_row |
|
513 | - * |
|
514 | - * @param EE_Line_Item $line_item |
|
515 | - * @param string $text |
|
516 | - * @return mixed |
|
517 | - * @throws EE_Error |
|
518 | - */ |
|
519 | - private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
520 | - { |
|
521 | - $html = ''; |
|
522 | - if ($line_item->total()) { |
|
523 | - // start of row |
|
524 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
525 | - // total td |
|
526 | - $html .= EEH_HTML::td( |
|
527 | - $text, |
|
528 | - '', |
|
529 | - 'total_currency total jst-rght', |
|
530 | - '', |
|
531 | - ' colspan="2"' |
|
532 | - ); |
|
533 | - // empty td (price) |
|
534 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
535 | - // total td |
|
536 | - $html .= EEH_HTML::td( |
|
537 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
538 | - '', |
|
539 | - 'spco-nowrap total jst-rght' |
|
540 | - ); |
|
541 | - // end of row |
|
542 | - $html .= EEH_HTML::trx(); |
|
543 | - } |
|
544 | - return $html; |
|
545 | - } |
|
546 | - |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * _total_row |
|
551 | - * |
|
552 | - * @param EE_Line_Item $line_item |
|
553 | - * @param string $text |
|
554 | - * @param array $options |
|
555 | - * @return mixed |
|
556 | - * @throws EE_Error |
|
557 | - */ |
|
558 | - private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
559 | - { |
|
560 | - $html = ''; |
|
561 | - if ($line_item->total()) { |
|
562 | - // start of row |
|
563 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
564 | - // total td |
|
565 | - $html .= EEH_HTML::td( |
|
566 | - $text, |
|
567 | - '', |
|
568 | - 'total_currency total jst-rght', |
|
569 | - '', |
|
570 | - ' colspan="3"' |
|
571 | - ); |
|
572 | - // total td |
|
573 | - $html .= EEH_HTML::td( |
|
574 | - EEH_Template::format_currency($options['sub_total'], false, false), |
|
575 | - '', |
|
576 | - 'spco-nowrap total jst-rght' |
|
577 | - ); |
|
578 | - // end of row |
|
579 | - $html .= EEH_HTML::trx(); |
|
580 | - } |
|
581 | - return $html; |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * _total_row |
|
588 | - * |
|
589 | - * @param EE_Line_Item $line_item |
|
590 | - * @param string $text |
|
591 | - * @return mixed |
|
592 | - * @throws EE_Error |
|
593 | - */ |
|
594 | - private function _total_row(EE_Line_Item $line_item, $text = '') |
|
595 | - { |
|
596 | - // start of row |
|
597 | - $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
598 | - // total td |
|
599 | - $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
600 | - // total td |
|
601 | - $html .= EEH_HTML::td( |
|
602 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
603 | - '', |
|
604 | - 'spco-nowrap total jst-rght' |
|
605 | - ); |
|
606 | - // end of row |
|
607 | - $html .= EEH_HTML::trx(); |
|
608 | - return $html; |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * _payments_and_amount_owing_rows |
|
615 | - * |
|
616 | - * @param EE_Line_Item $line_item |
|
617 | - * @param array $options |
|
618 | - * @return mixed |
|
619 | - * @throws EE_Error |
|
620 | - */ |
|
621 | - private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
622 | - { |
|
623 | - $html = ''; |
|
624 | - $owing = $line_item->total(); |
|
625 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
626 | - if ($transaction instanceof EE_Transaction) { |
|
627 | - $registration_payments = array(); |
|
628 | - $registrations = ! empty($options['registrations']) |
|
629 | - ? $options['registrations'] |
|
630 | - : $transaction->registrations(); |
|
631 | - foreach ($registrations as $registration) { |
|
632 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
633 | - $registration_payments += $registration->registration_payments(); |
|
634 | - } |
|
635 | - } |
|
636 | - if (! empty($registration_payments)) { |
|
637 | - foreach ($registration_payments as $registration_payment) { |
|
638 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
639 | - $owing -= $registration_payment->amount(); |
|
640 | - $payment = $registration_payment->payment(); |
|
641 | - $payment_desc = ''; |
|
642 | - if ($payment instanceof EE_Payment) { |
|
643 | - $payment_desc = sprintf( |
|
644 | - esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
645 | - $payment->txn_id_chq_nmbr() !== '' |
|
646 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
647 | - : '', |
|
648 | - $payment->timestamp() |
|
649 | - ); |
|
650 | - } |
|
651 | - // start of row |
|
652 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
653 | - // payment desc |
|
654 | - $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
655 | - // total td |
|
656 | - $html .= EEH_HTML::td( |
|
657 | - EEH_Template::format_currency( |
|
658 | - $registration_payment->amount(), |
|
659 | - false, |
|
660 | - false |
|
661 | - ), |
|
662 | - '', |
|
663 | - 'spco-nowrap total jst-rght' |
|
664 | - ); |
|
665 | - // end of row |
|
666 | - $html .= EEH_HTML::trx(); |
|
667 | - } |
|
668 | - } |
|
669 | - if ($line_item->total()) { |
|
670 | - // start of row |
|
671 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
672 | - // total td |
|
673 | - $html .= EEH_HTML::td( |
|
674 | - esc_html__('Amount Owing', 'event_espresso'), |
|
675 | - '', |
|
676 | - 'total_currency total jst-rght', |
|
677 | - '', |
|
678 | - ' colspan="3"' |
|
679 | - ); |
|
680 | - // total td |
|
681 | - $html .= EEH_HTML::td( |
|
682 | - EEH_Template::format_currency($owing, false, false), |
|
683 | - '', |
|
684 | - 'spco-nowrap total jst-rght' |
|
685 | - ); |
|
686 | - // end of row |
|
687 | - $html .= EEH_HTML::trx(); |
|
688 | - } |
|
689 | - } |
|
690 | - } |
|
691 | - $this->_grand_total = $owing; |
|
692 | - return $html; |
|
693 | - } |
|
14 | + /** |
|
15 | + * @var bool |
|
16 | + */ |
|
17 | + protected $prices_include_taxes = false; |
|
18 | + |
|
19 | + /** |
|
20 | + * array of events |
|
21 | + * |
|
22 | + * @type EE_Line_Item[] $_events |
|
23 | + */ |
|
24 | + private $_events = array(); |
|
25 | + |
|
26 | + /** |
|
27 | + * whether to display the taxes row or not |
|
28 | + * |
|
29 | + * @type bool $_show_taxes |
|
30 | + */ |
|
31 | + private $_show_taxes = false; |
|
32 | + |
|
33 | + /** |
|
34 | + * html for any tax rows |
|
35 | + * |
|
36 | + * @type string $_show_taxes |
|
37 | + */ |
|
38 | + private $_taxes_html = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * total amount including tax we can bill for at this time |
|
42 | + * |
|
43 | + * @type float $_grand_total |
|
44 | + */ |
|
45 | + private $_grand_total = 0.00; |
|
46 | + |
|
47 | + /** |
|
48 | + * total number of items being billed for |
|
49 | + * |
|
50 | + * @type int $_total_items |
|
51 | + */ |
|
52 | + private $_total_items = 0; |
|
53 | + |
|
54 | + |
|
55 | + public function __construct() |
|
56 | + { |
|
57 | + $this->prices_include_taxes = EE_Registry::instance()->CFG->tax_settings->prices_displayed_including_taxes; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return float |
|
64 | + */ |
|
65 | + public function grand_total() |
|
66 | + { |
|
67 | + return $this->_grand_total; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return int |
|
74 | + */ |
|
75 | + public function total_items() |
|
76 | + { |
|
77 | + return $this->_total_items; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param EE_Line_Item $line_item |
|
84 | + * @param array $options |
|
85 | + * @param EE_Line_Item $parent_line_item |
|
86 | + * @return mixed |
|
87 | + * @throws EE_Error |
|
88 | + */ |
|
89 | + public function display_line_item( |
|
90 | + EE_Line_Item $line_item, |
|
91 | + $options = array(), |
|
92 | + EE_Line_Item $parent_line_item = null |
|
93 | + ) { |
|
94 | + $html = ''; |
|
95 | + // set some default options and merge with incoming |
|
96 | + $default_options = array( |
|
97 | + 'show_desc' => true, // true false |
|
98 | + 'odd' => false, |
|
99 | + ); |
|
100 | + $options = array_merge($default_options, (array) $options); |
|
101 | + |
|
102 | + switch ($line_item->type()) { |
|
103 | + case EEM_Line_Item::type_line_item: |
|
104 | + $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
105 | + if ($line_item->OBJ_type() === 'Ticket') { |
|
106 | + // item row |
|
107 | + $html .= $this->_ticket_row($line_item, $options); |
|
108 | + } else { |
|
109 | + // item row |
|
110 | + $html .= $this->_item_row($line_item, $options); |
|
111 | + } |
|
112 | + if ( |
|
113 | + apply_filters( |
|
114 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
115 | + true |
|
116 | + ) |
|
117 | + ) { |
|
118 | + // got any kids? |
|
119 | + foreach ($line_item->children() as $child_line_item) { |
|
120 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
121 | + } |
|
122 | + } |
|
123 | + break; |
|
124 | + |
|
125 | + case EEM_Line_Item::type_sub_line_item: |
|
126 | + $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
127 | + break; |
|
128 | + |
|
129 | + case EEM_Line_Item::type_sub_tax: |
|
130 | + $this->_show_taxes = true; |
|
131 | + break; |
|
132 | + |
|
133 | + case EEM_Line_Item::type_sub_total: |
|
134 | + static $sub_total = 0; |
|
135 | + $event_sub_total = 0; |
|
136 | + $text = esc_html__('Sub-Total', 'event_espresso'); |
|
137 | + if ($line_item->OBJ_type() === 'Event') { |
|
138 | + $options['event_id'] = $line_item->OBJ_ID(); |
|
139 | + if (! isset($this->_events[ $options['event_id'] ])) { |
|
140 | + $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
141 | + // if event has default reg status of Not Approved, then don't display info on it |
|
142 | + if ( |
|
143 | + $event instanceof EE_Event |
|
144 | + && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
145 | + ) { |
|
146 | + $display_event = false; |
|
147 | + // unless there are registrations for it that are returning to pay |
|
148 | + if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
149 | + foreach ($options['registrations'] as $registration) { |
|
150 | + if (! $registration instanceof EE_Registration) { |
|
151 | + continue; |
|
152 | + } |
|
153 | + $display_event = $registration->event_ID() === $options['event_id'] |
|
154 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
155 | + ? true |
|
156 | + : $display_event; |
|
157 | + } |
|
158 | + } |
|
159 | + if (! $display_event) { |
|
160 | + return ''; |
|
161 | + } |
|
162 | + } |
|
163 | + $this->_events[ $options['event_id'] ] = 0; |
|
164 | + $html .= $this->_event_row($line_item); |
|
165 | + $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
166 | + } |
|
167 | + } |
|
168 | + $child_line_items = $line_item->children(); |
|
169 | + // loop thru children |
|
170 | + foreach ($child_line_items as $child_line_item) { |
|
171 | + // recursively feed children back into this method |
|
172 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
173 | + } |
|
174 | + $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
175 | + $sub_total += $event_sub_total; |
|
176 | + if ( |
|
177 | + ( |
|
178 | + // event subtotals |
|
179 | + $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
180 | + ) |
|
181 | + || ( |
|
182 | + // pre-tax subtotals |
|
183 | + $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
184 | + ) |
|
185 | + ) { |
|
186 | + $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
187 | + $html .= $this->_sub_total_row($line_item, $text, $options); |
|
188 | + } |
|
189 | + break; |
|
190 | + |
|
191 | + case EEM_Line_Item::type_tax: |
|
192 | + if ($this->_show_taxes) { |
|
193 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
194 | + } |
|
195 | + break; |
|
196 | + |
|
197 | + case EEM_Line_Item::type_tax_sub_total: |
|
198 | + if ($this->_show_taxes) { |
|
199 | + $child_line_items = $line_item->children(); |
|
200 | + // loop thru children |
|
201 | + foreach ($child_line_items as $child_line_item) { |
|
202 | + // recursively feed children back into this method |
|
203 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
204 | + } |
|
205 | + if (count($child_line_items) > 1) { |
|
206 | + $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
207 | + } |
|
208 | + } |
|
209 | + break; |
|
210 | + |
|
211 | + case EEM_Line_Item::type_total: |
|
212 | + // get all child line items |
|
213 | + $children = $line_item->children(); |
|
214 | + // loop thru all non-tax child line items |
|
215 | + foreach ($children as $child_line_item) { |
|
216 | + if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
217 | + // recursively feed children back into this method |
|
218 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
219 | + } |
|
220 | + } |
|
221 | + // now loop thru tax child line items |
|
222 | + foreach ($children as $child_line_item) { |
|
223 | + if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
224 | + // recursively feed children back into this method |
|
225 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
226 | + } |
|
227 | + } |
|
228 | + $html .= $this->_taxes_html; |
|
229 | + $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
230 | + $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
231 | + break; |
|
232 | + } |
|
233 | + return $html; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
240 | + * |
|
241 | + * @param EE_Line_Item $line_item |
|
242 | + * @return mixed |
|
243 | + */ |
|
244 | + private function _event_row(EE_Line_Item $line_item) |
|
245 | + { |
|
246 | + // start of row |
|
247 | + $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
248 | + // event name td |
|
249 | + $html .= EEH_HTML::td( |
|
250 | + EEH_HTML::strong($line_item->name()), |
|
251 | + '', |
|
252 | + 'event-header', |
|
253 | + '', |
|
254 | + ' colspan="4"' |
|
255 | + ); |
|
256 | + // end of row |
|
257 | + $html .= EEH_HTML::trx(); |
|
258 | + return $html; |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * _ticket_row |
|
265 | + * |
|
266 | + * @param EE_Line_Item $line_item |
|
267 | + * @param array $options |
|
268 | + * @return mixed |
|
269 | + * @throws EE_Error |
|
270 | + */ |
|
271 | + private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
272 | + { |
|
273 | + // start of row |
|
274 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
275 | + $html = EEH_HTML::tr('', '', $row_class); |
|
276 | + // name && desc |
|
277 | + $name_and_desc = apply_filters( |
|
278 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
279 | + $line_item->name(), |
|
280 | + $line_item |
|
281 | + ); |
|
282 | + $name_and_desc .= apply_filters( |
|
283 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
284 | + ( |
|
285 | + $options['show_desc'] |
|
286 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
287 | + : '' |
|
288 | + ), |
|
289 | + $line_item, |
|
290 | + $options |
|
291 | + ); |
|
292 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
293 | + $name_and_desc = apply_filters( |
|
294 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc', |
|
295 | + $name_and_desc, |
|
296 | + $line_item, |
|
297 | + $options |
|
298 | + ); |
|
299 | + |
|
300 | + // name td |
|
301 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
302 | + $name_and_desc, |
|
303 | + '', |
|
304 | + 'item_l' |
|
305 | + ); |
|
306 | + // price td |
|
307 | + $price = apply_filters( |
|
308 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price', |
|
309 | + $line_item->unit_price_no_code(), |
|
310 | + $line_item |
|
311 | + ); |
|
312 | + $html .= EEH_HTML::td($price, '', 'spco-nowrap item_c jst-rght'); |
|
313 | + // quantity td |
|
314 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
315 | + $this->_total_items += $line_item->quantity(); |
|
316 | + // determine total for line item |
|
317 | + $total = apply_filters( |
|
318 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total', |
|
319 | + $line_item->pretaxTotal(), |
|
320 | + $line_item |
|
321 | + ); |
|
322 | + $this->_events[ $options['event_id'] ] += $total; |
|
323 | + // total td |
|
324 | + $html .= EEH_HTML::td( |
|
325 | + EEH_Template::format_currency($total, false, false), |
|
326 | + '', |
|
327 | + 'spco-nowrap item_r jst-rght' |
|
328 | + ); |
|
329 | + // end of row |
|
330 | + $html .= EEH_HTML::trx(); |
|
331 | + return $html; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * _item_row |
|
338 | + * |
|
339 | + * @param EE_Line_Item $line_item |
|
340 | + * @param array $options |
|
341 | + * @return mixed |
|
342 | + * @throws EE_Error |
|
343 | + */ |
|
344 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
345 | + { |
|
346 | + // start of row |
|
347 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
348 | + $html = EEH_HTML::tr('', '', $row_class); |
|
349 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
350 | + // name && desc |
|
351 | + $name_and_desc = apply_filters( |
|
352 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
353 | + $obj_name . $line_item->name(), |
|
354 | + $line_item |
|
355 | + ); |
|
356 | + $name_and_desc .= apply_filters( |
|
357 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
358 | + ( |
|
359 | + $options['show_desc'] |
|
360 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
361 | + : '' |
|
362 | + ), |
|
363 | + $line_item, |
|
364 | + $options |
|
365 | + ); |
|
366 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
367 | + $name_and_desc = apply_filters( |
|
368 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc', |
|
369 | + $name_and_desc, |
|
370 | + $line_item, |
|
371 | + $options |
|
372 | + ); |
|
373 | + |
|
374 | + // name td |
|
375 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
376 | + // price td |
|
377 | + if ($line_item->is_percent()) { |
|
378 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght'); |
|
379 | + } else { |
|
380 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
381 | + } |
|
382 | + // quantity td |
|
383 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
|
384 | + // $total = $line_item->total() * $line_item->quantity(); |
|
385 | + $total = $line_item->total(); |
|
386 | + if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
387 | + $this->_events[ $options['event_id'] ] += $total; |
|
388 | + } |
|
389 | + // total td |
|
390 | + $html .= EEH_HTML::td( |
|
391 | + EEH_Template::format_currency($total, false, false), |
|
392 | + '', |
|
393 | + 'spco-nowrap item_r jst-rght' |
|
394 | + ); |
|
395 | + // end of row |
|
396 | + $html .= EEH_HTML::trx(); |
|
397 | + return $html; |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * _sub_item_row |
|
404 | + * |
|
405 | + * @param EE_Line_Item $line_item |
|
406 | + * @param array $options |
|
407 | + * @param EE_Line_Item $parent_line_item |
|
408 | + * @return mixed |
|
409 | + * @throws EE_Error |
|
410 | + */ |
|
411 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
412 | + { |
|
413 | + if ( |
|
414 | + $parent_line_item instanceof EE_Line_Item |
|
415 | + && $line_item->children() === array() |
|
416 | + && $line_item->name() === $parent_line_item->name() |
|
417 | + && apply_filters( |
|
418 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
419 | + true |
|
420 | + ) |
|
421 | + ) { |
|
422 | + return ''; |
|
423 | + } |
|
424 | + // start of row |
|
425 | + $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
426 | + // name && desc |
|
427 | + $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
428 | + . $line_item->name(); |
|
429 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
430 | + . $line_item->desc() |
|
431 | + . '</span>' : ''; |
|
432 | + // name td |
|
433 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
434 | + $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
435 | + // discount/surcharge td |
|
436 | + if ($line_item->is_percent()) { |
|
437 | + $html .= EEH_HTML::td( |
|
438 | + EEH_Template::format_currency( |
|
439 | + $line_item->total() / $qty, |
|
440 | + false, |
|
441 | + false |
|
442 | + ), |
|
443 | + '', |
|
444 | + 'spco-nowrap item_c jst-rght' |
|
445 | + ); |
|
446 | + } else { |
|
447 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
|
448 | + } |
|
449 | + // no quantity td |
|
450 | + $html .= EEH_HTML::td(); |
|
451 | + // no total td |
|
452 | + $html .= EEH_HTML::td(); |
|
453 | + // end of row |
|
454 | + $html .= EEH_HTML::trx(); |
|
455 | + $html = apply_filters( |
|
456 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
457 | + $html, |
|
458 | + $line_item, |
|
459 | + $options, |
|
460 | + $parent_line_item |
|
461 | + ); |
|
462 | + return $html; |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * _tax_row |
|
469 | + * |
|
470 | + * @param EE_Line_Item $line_item |
|
471 | + * @param array $options |
|
472 | + * @return mixed |
|
473 | + * @throws EE_Error |
|
474 | + */ |
|
475 | + private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
476 | + { |
|
477 | + // start of row |
|
478 | + $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
479 | + // name && desc |
|
480 | + $name_and_desc = $line_item->name(); |
|
481 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
482 | + . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
483 | + $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
484 | + // name td |
|
485 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
486 | + $name_and_desc, |
|
487 | + '', |
|
488 | + 'item_l sub-item' |
|
489 | + ); |
|
490 | + // percent td |
|
491 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', ''); |
|
492 | + // empty td (price) |
|
493 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
494 | + // total td |
|
495 | + $html .= EEH_HTML::td( |
|
496 | + EEH_Template::format_currency( |
|
497 | + $line_item->total(), |
|
498 | + false, |
|
499 | + false |
|
500 | + ), |
|
501 | + '', |
|
502 | + 'spco-nowrap item_r jst-rght' |
|
503 | + ); |
|
504 | + // end of row |
|
505 | + $html .= EEH_HTML::trx(); |
|
506 | + return $html; |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * _total_row |
|
513 | + * |
|
514 | + * @param EE_Line_Item $line_item |
|
515 | + * @param string $text |
|
516 | + * @return mixed |
|
517 | + * @throws EE_Error |
|
518 | + */ |
|
519 | + private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
520 | + { |
|
521 | + $html = ''; |
|
522 | + if ($line_item->total()) { |
|
523 | + // start of row |
|
524 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
525 | + // total td |
|
526 | + $html .= EEH_HTML::td( |
|
527 | + $text, |
|
528 | + '', |
|
529 | + 'total_currency total jst-rght', |
|
530 | + '', |
|
531 | + ' colspan="2"' |
|
532 | + ); |
|
533 | + // empty td (price) |
|
534 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
535 | + // total td |
|
536 | + $html .= EEH_HTML::td( |
|
537 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
538 | + '', |
|
539 | + 'spco-nowrap total jst-rght' |
|
540 | + ); |
|
541 | + // end of row |
|
542 | + $html .= EEH_HTML::trx(); |
|
543 | + } |
|
544 | + return $html; |
|
545 | + } |
|
546 | + |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * _total_row |
|
551 | + * |
|
552 | + * @param EE_Line_Item $line_item |
|
553 | + * @param string $text |
|
554 | + * @param array $options |
|
555 | + * @return mixed |
|
556 | + * @throws EE_Error |
|
557 | + */ |
|
558 | + private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
559 | + { |
|
560 | + $html = ''; |
|
561 | + if ($line_item->total()) { |
|
562 | + // start of row |
|
563 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
564 | + // total td |
|
565 | + $html .= EEH_HTML::td( |
|
566 | + $text, |
|
567 | + '', |
|
568 | + 'total_currency total jst-rght', |
|
569 | + '', |
|
570 | + ' colspan="3"' |
|
571 | + ); |
|
572 | + // total td |
|
573 | + $html .= EEH_HTML::td( |
|
574 | + EEH_Template::format_currency($options['sub_total'], false, false), |
|
575 | + '', |
|
576 | + 'spco-nowrap total jst-rght' |
|
577 | + ); |
|
578 | + // end of row |
|
579 | + $html .= EEH_HTML::trx(); |
|
580 | + } |
|
581 | + return $html; |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * _total_row |
|
588 | + * |
|
589 | + * @param EE_Line_Item $line_item |
|
590 | + * @param string $text |
|
591 | + * @return mixed |
|
592 | + * @throws EE_Error |
|
593 | + */ |
|
594 | + private function _total_row(EE_Line_Item $line_item, $text = '') |
|
595 | + { |
|
596 | + // start of row |
|
597 | + $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
598 | + // total td |
|
599 | + $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
600 | + // total td |
|
601 | + $html .= EEH_HTML::td( |
|
602 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
603 | + '', |
|
604 | + 'spco-nowrap total jst-rght' |
|
605 | + ); |
|
606 | + // end of row |
|
607 | + $html .= EEH_HTML::trx(); |
|
608 | + return $html; |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * _payments_and_amount_owing_rows |
|
615 | + * |
|
616 | + * @param EE_Line_Item $line_item |
|
617 | + * @param array $options |
|
618 | + * @return mixed |
|
619 | + * @throws EE_Error |
|
620 | + */ |
|
621 | + private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
622 | + { |
|
623 | + $html = ''; |
|
624 | + $owing = $line_item->total(); |
|
625 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
626 | + if ($transaction instanceof EE_Transaction) { |
|
627 | + $registration_payments = array(); |
|
628 | + $registrations = ! empty($options['registrations']) |
|
629 | + ? $options['registrations'] |
|
630 | + : $transaction->registrations(); |
|
631 | + foreach ($registrations as $registration) { |
|
632 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
633 | + $registration_payments += $registration->registration_payments(); |
|
634 | + } |
|
635 | + } |
|
636 | + if (! empty($registration_payments)) { |
|
637 | + foreach ($registration_payments as $registration_payment) { |
|
638 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
639 | + $owing -= $registration_payment->amount(); |
|
640 | + $payment = $registration_payment->payment(); |
|
641 | + $payment_desc = ''; |
|
642 | + if ($payment instanceof EE_Payment) { |
|
643 | + $payment_desc = sprintf( |
|
644 | + esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
645 | + $payment->txn_id_chq_nmbr() !== '' |
|
646 | + ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
647 | + : '', |
|
648 | + $payment->timestamp() |
|
649 | + ); |
|
650 | + } |
|
651 | + // start of row |
|
652 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
653 | + // payment desc |
|
654 | + $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
655 | + // total td |
|
656 | + $html .= EEH_HTML::td( |
|
657 | + EEH_Template::format_currency( |
|
658 | + $registration_payment->amount(), |
|
659 | + false, |
|
660 | + false |
|
661 | + ), |
|
662 | + '', |
|
663 | + 'spco-nowrap total jst-rght' |
|
664 | + ); |
|
665 | + // end of row |
|
666 | + $html .= EEH_HTML::trx(); |
|
667 | + } |
|
668 | + } |
|
669 | + if ($line_item->total()) { |
|
670 | + // start of row |
|
671 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
672 | + // total td |
|
673 | + $html .= EEH_HTML::td( |
|
674 | + esc_html__('Amount Owing', 'event_espresso'), |
|
675 | + '', |
|
676 | + 'total_currency total jst-rght', |
|
677 | + '', |
|
678 | + ' colspan="3"' |
|
679 | + ); |
|
680 | + // total td |
|
681 | + $html .= EEH_HTML::td( |
|
682 | + EEH_Template::format_currency($owing, false, false), |
|
683 | + '', |
|
684 | + 'spco-nowrap total jst-rght' |
|
685 | + ); |
|
686 | + // end of row |
|
687 | + $html .= EEH_HTML::trx(); |
|
688 | + } |
|
689 | + } |
|
690 | + } |
|
691 | + $this->_grand_total = $owing; |
|
692 | + return $html; |
|
693 | + } |
|
694 | 694 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | $html = ''; |
95 | 95 | // set some default options and merge with incoming |
96 | 96 | $default_options = array( |
97 | - 'show_desc' => true, // true false |
|
97 | + 'show_desc' => true, // true false |
|
98 | 98 | 'odd' => false, |
99 | 99 | ); |
100 | 100 | $options = array_merge($default_options, (array) $options); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $text = esc_html__('Sub-Total', 'event_espresso'); |
137 | 137 | if ($line_item->OBJ_type() === 'Event') { |
138 | 138 | $options['event_id'] = $line_item->OBJ_ID(); |
139 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
139 | + if ( ! isset($this->_events[$options['event_id']])) { |
|
140 | 140 | $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
141 | 141 | // if event has default reg status of Not Approved, then don't display info on it |
142 | 142 | if ( |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | // unless there are registrations for it that are returning to pay |
148 | 148 | if (isset($options['registrations']) && is_array($options['registrations'])) { |
149 | 149 | foreach ($options['registrations'] as $registration) { |
150 | - if (! $registration instanceof EE_Registration) { |
|
150 | + if ( ! $registration instanceof EE_Registration) { |
|
151 | 151 | continue; |
152 | 152 | } |
153 | 153 | $display_event = $registration->event_ID() === $options['event_id'] |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | : $display_event; |
157 | 157 | } |
158 | 158 | } |
159 | - if (! $display_event) { |
|
159 | + if ( ! $display_event) { |
|
160 | 160 | return ''; |
161 | 161 | } |
162 | 162 | } |
163 | - $this->_events[ $options['event_id'] ] = 0; |
|
163 | + $this->_events[$options['event_id']] = 0; |
|
164 | 164 | $html .= $this->_event_row($line_item); |
165 | 165 | $text = esc_html__('Event Sub-Total', 'event_espresso'); |
166 | 166 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | // recursively feed children back into this method |
172 | 172 | $html .= $this->display_line_item($child_line_item, $options, $line_item); |
173 | 173 | } |
174 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
174 | + $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0; |
|
175 | 175 | $sub_total += $event_sub_total; |
176 | 176 | if ( |
177 | 177 | ( |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
284 | 284 | ( |
285 | 285 | $options['show_desc'] |
286 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
286 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
287 | 287 | : '' |
288 | 288 | ), |
289 | 289 | $line_item, |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | $line_item->pretaxTotal(), |
320 | 320 | $line_item |
321 | 321 | ); |
322 | - $this->_events[ $options['event_id'] ] += $total; |
|
322 | + $this->_events[$options['event_id']] += $total; |
|
323 | 323 | // total td |
324 | 324 | $html .= EEH_HTML::td( |
325 | 325 | EEH_Template::format_currency($total, false, false), |
@@ -346,18 +346,18 @@ discard block |
||
346 | 346 | // start of row |
347 | 347 | $row_class = $options['odd'] ? 'item odd' : 'item'; |
348 | 348 | $html = EEH_HTML::tr('', '', $row_class); |
349 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
349 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : ''; |
|
350 | 350 | // name && desc |
351 | 351 | $name_and_desc = apply_filters( |
352 | 352 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
353 | - $obj_name . $line_item->name(), |
|
353 | + $obj_name.$line_item->name(), |
|
354 | 354 | $line_item |
355 | 355 | ); |
356 | 356 | $name_and_desc .= apply_filters( |
357 | 357 | 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
358 | 358 | ( |
359 | 359 | $options['show_desc'] |
360 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
360 | + ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>' |
|
361 | 361 | : '' |
362 | 362 | ), |
363 | 363 | $line_item, |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
376 | 376 | // price td |
377 | 377 | if ($line_item->is_percent()) { |
378 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap item_c jst-rght'); |
|
378 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'spco-nowrap item_c jst-rght'); |
|
379 | 379 | } else { |
380 | 380 | $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'spco-nowrap item_c jst-rght'); |
381 | 381 | } |
@@ -383,8 +383,8 @@ discard block |
||
383 | 383 | $html .= EEH_HTML::td($line_item->quantity(), '', 'spco-nowrap item_l jst-rght'); |
384 | 384 | // $total = $line_item->total() * $line_item->quantity(); |
385 | 385 | $total = $line_item->total(); |
386 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
387 | - $this->_events[ $options['event_id'] ] += $total; |
|
386 | + if (isset($options['event_id'], $this->_events[$options['event_id']])) { |
|
387 | + $this->_events[$options['event_id']] += $total; |
|
388 | 388 | } |
389 | 389 | // total td |
390 | 390 | $html .= EEH_HTML::td( |
@@ -479,8 +479,8 @@ discard block |
||
479 | 479 | // name && desc |
480 | 480 | $name_and_desc = $line_item->name(); |
481 | 481 | $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
482 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
483 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
482 | + . esc_html__(' * taxable items', 'event_espresso').'</span>'; |
|
483 | + $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : ''; |
|
484 | 484 | // name td |
485 | 485 | $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
486 | 486 | $name_and_desc, |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | 'item_l sub-item' |
489 | 489 | ); |
490 | 490 | // percent td |
491 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'spco-nowrap jst-rght', ''); |
|
491 | + $html .= EEH_HTML::td($line_item->percent().'%', '', 'spco-nowrap jst-rght', ''); |
|
492 | 492 | // empty td (price) |
493 | 493 | $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
494 | 494 | // total td |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | $registration_payments += $registration->registration_payments(); |
634 | 634 | } |
635 | 635 | } |
636 | - if (! empty($registration_payments)) { |
|
636 | + if ( ! empty($registration_payments)) { |
|
637 | 637 | foreach ($registration_payments as $registration_payment) { |
638 | 638 | if ($registration_payment instanceof EE_Registration_Payment) { |
639 | 639 | $owing -= $registration_payment->amount(); |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | $payment_desc = sprintf( |
644 | 644 | esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
645 | 645 | $payment->txn_id_chq_nmbr() !== '' |
646 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
646 | + ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> ' |
|
647 | 647 | : '', |
648 | 648 | $payment->timestamp() |
649 | 649 | ); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | { |
97 | 97 | $this->calculator = LoaderFactory::getShared(LineItemCalculator::class); |
98 | 98 | parent::__construct($fieldValues, $bydb, $timezone); |
99 | - if (! $this->get('LIN_code')) { |
|
99 | + if ( ! $this->get('LIN_code')) { |
|
100 | 100 | $this->set_code($this->generate_code()); |
101 | 101 | } |
102 | 102 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | public function name() |
164 | 164 | { |
165 | 165 | $name = $this->get('LIN_name'); |
166 | - if (! $name) { |
|
166 | + if ( ! $name) { |
|
167 | 167 | $name = ucwords(str_replace('-', ' ', $this->type())); |
168 | 168 | } |
169 | 169 | return $name; |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | $query_params += ['order_by' => ['LIN_order' => 'ASC']]; |
656 | 656 | return $this->get_model()->get_all($query_params); |
657 | 657 | } |
658 | - if (! is_array($this->_children)) { |
|
658 | + if ( ! is_array($this->_children)) { |
|
659 | 659 | $this->_children = array(); |
660 | 660 | } |
661 | 661 | return $this->_children; |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | } |
897 | 897 | return $line_item->save(); |
898 | 898 | } |
899 | - $this->_children[ $line_item->code() ] = $line_item; |
|
899 | + $this->_children[$line_item->code()] = $line_item; |
|
900 | 900 | if ($line_item->parent() !== $this) { |
901 | 901 | $line_item->set_parent($this); |
902 | 902 | } |
@@ -920,7 +920,7 @@ discard block |
||
920 | 920 | public function set_parent($line_item) |
921 | 921 | { |
922 | 922 | if ($this->ID()) { |
923 | - if (! $line_item->ID()) { |
|
923 | + if ( ! $line_item->ID()) { |
|
924 | 924 | $line_item->save(); |
925 | 925 | } |
926 | 926 | $this->set_parent_ID($line_item->ID()); |
@@ -952,8 +952,8 @@ discard block |
||
952 | 952 | array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code)) |
953 | 953 | ); |
954 | 954 | } |
955 | - return isset($this->_children[ $code ]) |
|
956 | - ? $this->_children[ $code ] |
|
955 | + return isset($this->_children[$code]) |
|
956 | + ? $this->_children[$code] |
|
957 | 957 | : null; |
958 | 958 | } |
959 | 959 | |
@@ -1013,8 +1013,8 @@ discard block |
||
1013 | 1013 | } |
1014 | 1014 | return $items_deleted; |
1015 | 1015 | } |
1016 | - if (isset($this->_children[ $code ])) { |
|
1017 | - unset($this->_children[ $code ]); |
|
1016 | + if (isset($this->_children[$code])) { |
|
1017 | + unset($this->_children[$code]); |
|
1018 | 1018 | return 1; |
1019 | 1019 | } |
1020 | 1020 | return 0; |
@@ -1055,7 +1055,7 @@ discard block |
||
1055 | 1055 | public function generate_code() |
1056 | 1056 | { |
1057 | 1057 | // each line item in the cart requires a unique identifier |
1058 | - return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime()); |
|
1058 | + return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime()); |
|
1059 | 1059 | } |
1060 | 1060 | |
1061 | 1061 | |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | */ |
1100 | 1100 | public function getSubTaxes(): array |
1101 | 1101 | { |
1102 | - if (! $this->is_line_item()) { |
|
1102 | + if ( ! $this->is_line_item()) { |
|
1103 | 1103 | return []; |
1104 | 1104 | } |
1105 | 1105 | return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_sub_tax); |
@@ -1118,7 +1118,7 @@ discard block |
||
1118 | 1118 | */ |
1119 | 1119 | public function hasSubTaxes(): bool |
1120 | 1120 | { |
1121 | - if (! $this->is_line_item()) { |
|
1121 | + if ( ! $this->is_line_item()) { |
|
1122 | 1122 | return false; |
1123 | 1123 | } |
1124 | 1124 | $sub_taxes = $this->getSubTaxes(); |
@@ -1450,7 +1450,7 @@ discard block |
||
1450 | 1450 | public function save_this_and_descendants_to_txn($txn_id = null) |
1451 | 1451 | { |
1452 | 1452 | $count = 0; |
1453 | - if (! $txn_id) { |
|
1453 | + if ( ! $txn_id) { |
|
1454 | 1454 | $txn_id = $this->TXN_ID(); |
1455 | 1455 | } |
1456 | 1456 | $this->set_TXN_ID($txn_id); |
@@ -15,1663 +15,1663 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Line_Item extends EE_Base_Class implements EEI_Line_Item |
17 | 17 | { |
18 | - /** |
|
19 | - * for children line items (currently not a normal relation) |
|
20 | - * |
|
21 | - * @type EE_Line_Item[] |
|
22 | - */ |
|
23 | - protected $_children = array(); |
|
24 | - |
|
25 | - /** |
|
26 | - * for the parent line item |
|
27 | - * |
|
28 | - * @var EE_Line_Item |
|
29 | - */ |
|
30 | - protected $_parent; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var LineItemCalculator |
|
34 | - */ |
|
35 | - protected $calculator; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @param array $props_n_values incoming values |
|
40 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
41 | - * used.) |
|
42 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
43 | - * date_format and the second value is the time format |
|
44 | - * @return EE_Line_Item |
|
45 | - * @throws EE_Error |
|
46 | - * @throws InvalidArgumentException |
|
47 | - * @throws InvalidDataTypeException |
|
48 | - * @throws InvalidInterfaceException |
|
49 | - * @throws ReflectionException |
|
50 | - */ |
|
51 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
52 | - { |
|
53 | - $has_object = parent::_check_for_object( |
|
54 | - $props_n_values, |
|
55 | - __CLASS__, |
|
56 | - $timezone, |
|
57 | - $date_formats |
|
58 | - ); |
|
59 | - return $has_object |
|
60 | - ? $has_object |
|
61 | - : new self($props_n_values, false, $timezone); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @param array $props_n_values incoming values from the database |
|
67 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
68 | - * the website will be used. |
|
69 | - * @return EE_Line_Item |
|
70 | - * @throws EE_Error |
|
71 | - * @throws InvalidArgumentException |
|
72 | - * @throws InvalidDataTypeException |
|
73 | - * @throws InvalidInterfaceException |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
77 | - { |
|
78 | - return new self($props_n_values, true, $timezone); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Adds some defaults if they're not specified |
|
84 | - * |
|
85 | - * @param array $fieldValues |
|
86 | - * @param bool $bydb |
|
87 | - * @param string $timezone |
|
88 | - * @throws EE_Error |
|
89 | - * @throws InvalidArgumentException |
|
90 | - * @throws InvalidDataTypeException |
|
91 | - * @throws InvalidInterfaceException |
|
92 | - * @throws ReflectionException |
|
93 | - */ |
|
94 | - protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
|
95 | - { |
|
96 | - $this->calculator = LoaderFactory::getShared(LineItemCalculator::class); |
|
97 | - parent::__construct($fieldValues, $bydb, $timezone); |
|
98 | - if (! $this->get('LIN_code')) { |
|
99 | - $this->set_code($this->generate_code()); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - public function __wakeup() |
|
105 | - { |
|
106 | - $this->calculator = LoaderFactory::getShared(LineItemCalculator::class); |
|
107 | - parent::__wakeup(); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Gets ID |
|
113 | - * |
|
114 | - * @return int |
|
115 | - * @throws EE_Error |
|
116 | - * @throws InvalidArgumentException |
|
117 | - * @throws InvalidDataTypeException |
|
118 | - * @throws InvalidInterfaceException |
|
119 | - * @throws ReflectionException |
|
120 | - */ |
|
121 | - public function ID() |
|
122 | - { |
|
123 | - return $this->get('LIN_ID'); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Gets TXN_ID |
|
129 | - * |
|
130 | - * @return int |
|
131 | - * @throws EE_Error |
|
132 | - * @throws InvalidArgumentException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidInterfaceException |
|
135 | - * @throws ReflectionException |
|
136 | - */ |
|
137 | - public function TXN_ID() |
|
138 | - { |
|
139 | - return $this->get('TXN_ID'); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * Sets TXN_ID |
|
145 | - * |
|
146 | - * @param int $TXN_ID |
|
147 | - * @throws EE_Error |
|
148 | - * @throws InvalidArgumentException |
|
149 | - * @throws InvalidDataTypeException |
|
150 | - * @throws InvalidInterfaceException |
|
151 | - * @throws ReflectionException |
|
152 | - */ |
|
153 | - public function set_TXN_ID($TXN_ID) |
|
154 | - { |
|
155 | - $this->set('TXN_ID', $TXN_ID); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Gets name |
|
161 | - * |
|
162 | - * @return string |
|
163 | - * @throws EE_Error |
|
164 | - * @throws InvalidArgumentException |
|
165 | - * @throws InvalidDataTypeException |
|
166 | - * @throws InvalidInterfaceException |
|
167 | - * @throws ReflectionException |
|
168 | - */ |
|
169 | - public function name() |
|
170 | - { |
|
171 | - $name = $this->get('LIN_name'); |
|
172 | - if (! $name) { |
|
173 | - $name = ucwords(str_replace('-', ' ', $this->type())); |
|
174 | - } |
|
175 | - return $name; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Sets name |
|
181 | - * |
|
182 | - * @param string $name |
|
183 | - * @throws EE_Error |
|
184 | - * @throws InvalidArgumentException |
|
185 | - * @throws InvalidDataTypeException |
|
186 | - * @throws InvalidInterfaceException |
|
187 | - * @throws ReflectionException |
|
188 | - */ |
|
189 | - public function set_name($name) |
|
190 | - { |
|
191 | - $this->set('LIN_name', $name); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Gets desc |
|
197 | - * |
|
198 | - * @return string |
|
199 | - * @throws EE_Error |
|
200 | - * @throws InvalidArgumentException |
|
201 | - * @throws InvalidDataTypeException |
|
202 | - * @throws InvalidInterfaceException |
|
203 | - * @throws ReflectionException |
|
204 | - */ |
|
205 | - public function desc() |
|
206 | - { |
|
207 | - return $this->get('LIN_desc'); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Sets desc |
|
213 | - * |
|
214 | - * @param string $desc |
|
215 | - * @throws EE_Error |
|
216 | - * @throws InvalidArgumentException |
|
217 | - * @throws InvalidDataTypeException |
|
218 | - * @throws InvalidInterfaceException |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - public function set_desc($desc) |
|
222 | - { |
|
223 | - $this->set('LIN_desc', $desc); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * Gets quantity |
|
229 | - * |
|
230 | - * @return int |
|
231 | - * @throws EE_Error |
|
232 | - * @throws InvalidArgumentException |
|
233 | - * @throws InvalidDataTypeException |
|
234 | - * @throws InvalidInterfaceException |
|
235 | - * @throws ReflectionException |
|
236 | - */ |
|
237 | - public function quantity(): int |
|
238 | - { |
|
239 | - return (int) $this->get('LIN_quantity'); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Sets quantity |
|
245 | - * |
|
246 | - * @param int $quantity |
|
247 | - * @throws EE_Error |
|
248 | - * @throws InvalidArgumentException |
|
249 | - * @throws InvalidDataTypeException |
|
250 | - * @throws InvalidInterfaceException |
|
251 | - * @throws ReflectionException |
|
252 | - */ |
|
253 | - public function set_quantity($quantity) |
|
254 | - { |
|
255 | - $this->set('LIN_quantity', max($quantity, 0)); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Gets item_id |
|
261 | - * |
|
262 | - * @return int |
|
263 | - * @throws EE_Error |
|
264 | - * @throws InvalidArgumentException |
|
265 | - * @throws InvalidDataTypeException |
|
266 | - * @throws InvalidInterfaceException |
|
267 | - * @throws ReflectionException |
|
268 | - */ |
|
269 | - public function OBJ_ID() |
|
270 | - { |
|
271 | - return $this->get('OBJ_ID'); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * Sets item_id |
|
277 | - * |
|
278 | - * @param int $item_id |
|
279 | - * @throws EE_Error |
|
280 | - * @throws InvalidArgumentException |
|
281 | - * @throws InvalidDataTypeException |
|
282 | - * @throws InvalidInterfaceException |
|
283 | - * @throws ReflectionException |
|
284 | - */ |
|
285 | - public function set_OBJ_ID($item_id) |
|
286 | - { |
|
287 | - $this->set('OBJ_ID', $item_id); |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * Gets item_type |
|
293 | - * |
|
294 | - * @return string |
|
295 | - * @throws EE_Error |
|
296 | - * @throws InvalidArgumentException |
|
297 | - * @throws InvalidDataTypeException |
|
298 | - * @throws InvalidInterfaceException |
|
299 | - * @throws ReflectionException |
|
300 | - */ |
|
301 | - public function OBJ_type() |
|
302 | - { |
|
303 | - return $this->get('OBJ_type'); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Gets item_type |
|
309 | - * |
|
310 | - * @return string |
|
311 | - * @throws EE_Error |
|
312 | - * @throws InvalidArgumentException |
|
313 | - * @throws InvalidDataTypeException |
|
314 | - * @throws InvalidInterfaceException |
|
315 | - * @throws ReflectionException |
|
316 | - */ |
|
317 | - public function OBJ_type_i18n() |
|
318 | - { |
|
319 | - $obj_type = $this->OBJ_type(); |
|
320 | - switch ($obj_type) { |
|
321 | - case EEM_Line_Item::OBJ_TYPE_EVENT: |
|
322 | - $obj_type = esc_html__('Event', 'event_espresso'); |
|
323 | - break; |
|
324 | - case EEM_Line_Item::OBJ_TYPE_PRICE: |
|
325 | - $obj_type = esc_html__('Price', 'event_espresso'); |
|
326 | - break; |
|
327 | - case EEM_Line_Item::OBJ_TYPE_PROMOTION: |
|
328 | - $obj_type = esc_html__('Promotion', 'event_espresso'); |
|
329 | - break; |
|
330 | - case EEM_Line_Item::OBJ_TYPE_TICKET: |
|
331 | - $obj_type = esc_html__('Ticket', 'event_espresso'); |
|
332 | - break; |
|
333 | - case EEM_Line_Item::OBJ_TYPE_TRANSACTION: |
|
334 | - $obj_type = esc_html__('Transaction', 'event_espresso'); |
|
335 | - break; |
|
336 | - } |
|
337 | - return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * Sets item_type |
|
343 | - * |
|
344 | - * @param string $OBJ_type |
|
345 | - * @throws EE_Error |
|
346 | - * @throws InvalidArgumentException |
|
347 | - * @throws InvalidDataTypeException |
|
348 | - * @throws InvalidInterfaceException |
|
349 | - * @throws ReflectionException |
|
350 | - */ |
|
351 | - public function set_OBJ_type($OBJ_type) |
|
352 | - { |
|
353 | - $this->set('OBJ_type', $OBJ_type); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * Gets unit_price |
|
359 | - * |
|
360 | - * @return float |
|
361 | - * @throws EE_Error |
|
362 | - * @throws InvalidArgumentException |
|
363 | - * @throws InvalidDataTypeException |
|
364 | - * @throws InvalidInterfaceException |
|
365 | - * @throws ReflectionException |
|
366 | - */ |
|
367 | - public function unit_price() |
|
368 | - { |
|
369 | - return $this->get('LIN_unit_price'); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Sets unit_price |
|
375 | - * |
|
376 | - * @param float $unit_price |
|
377 | - * @throws EE_Error |
|
378 | - * @throws InvalidArgumentException |
|
379 | - * @throws InvalidDataTypeException |
|
380 | - * @throws InvalidInterfaceException |
|
381 | - * @throws ReflectionException |
|
382 | - */ |
|
383 | - public function set_unit_price($unit_price) |
|
384 | - { |
|
385 | - $this->set('LIN_unit_price', $unit_price); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Checks if this item is a percentage modifier or not |
|
391 | - * |
|
392 | - * @return boolean |
|
393 | - * @throws EE_Error |
|
394 | - * @throws InvalidArgumentException |
|
395 | - * @throws InvalidDataTypeException |
|
396 | - * @throws InvalidInterfaceException |
|
397 | - * @throws ReflectionException |
|
398 | - */ |
|
399 | - public function is_percent() |
|
400 | - { |
|
401 | - if ($this->is_tax_sub_total()) { |
|
402 | - // tax subtotals HAVE a percent on them, that percentage only applies |
|
403 | - // to taxable items, so its' an exception. Treat it like a flat line item |
|
404 | - return false; |
|
405 | - } |
|
406 | - $unit_price = abs($this->get('LIN_unit_price')); |
|
407 | - $percent = abs($this->get('LIN_percent')); |
|
408 | - if ($unit_price < .001 && $percent) { |
|
409 | - return true; |
|
410 | - } |
|
411 | - if ($unit_price >= .001 && ! $percent) { |
|
412 | - return false; |
|
413 | - } |
|
414 | - if ($unit_price >= .001 && $percent) { |
|
415 | - throw new EE_Error( |
|
416 | - sprintf( |
|
417 | - esc_html__( |
|
418 | - 'A Line Item can not have a unit price of (%s) AND a percent (%s)!', |
|
419 | - 'event_espresso' |
|
420 | - ), |
|
421 | - $unit_price, |
|
422 | - $percent |
|
423 | - ) |
|
424 | - ); |
|
425 | - } |
|
426 | - // if they're both 0, assume its not a percent item |
|
427 | - return false; |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Gets percent (between 100-.001) |
|
433 | - * |
|
434 | - * @return float |
|
435 | - * @throws EE_Error |
|
436 | - * @throws InvalidArgumentException |
|
437 | - * @throws InvalidDataTypeException |
|
438 | - * @throws InvalidInterfaceException |
|
439 | - * @throws ReflectionException |
|
440 | - */ |
|
441 | - public function percent() |
|
442 | - { |
|
443 | - return $this->get('LIN_percent'); |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * @return string |
|
449 | - * @throws EE_Error |
|
450 | - * @throws ReflectionException |
|
451 | - * @since $VID:$ |
|
452 | - */ |
|
453 | - public function prettyPercent(): string |
|
454 | - { |
|
455 | - return $this->get_pretty('LIN_percent'); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Sets percent (between 100-0.01) |
|
461 | - * |
|
462 | - * @param float $percent |
|
463 | - * @throws EE_Error |
|
464 | - * @throws InvalidArgumentException |
|
465 | - * @throws InvalidDataTypeException |
|
466 | - * @throws InvalidInterfaceException |
|
467 | - * @throws ReflectionException |
|
468 | - */ |
|
469 | - public function set_percent($percent) |
|
470 | - { |
|
471 | - $this->set('LIN_percent', $percent); |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * Gets total |
|
477 | - * |
|
478 | - * @return float |
|
479 | - * @throws EE_Error |
|
480 | - * @throws InvalidArgumentException |
|
481 | - * @throws InvalidDataTypeException |
|
482 | - * @throws InvalidInterfaceException |
|
483 | - * @throws ReflectionException |
|
484 | - */ |
|
485 | - public function pretaxTotal(): float |
|
486 | - { |
|
487 | - return (float) $this->get('LIN_pretax'); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * Sets total |
|
493 | - * |
|
494 | - * @param float $pretax_total |
|
495 | - * @throws EE_Error |
|
496 | - * @throws InvalidArgumentException |
|
497 | - * @throws InvalidDataTypeException |
|
498 | - * @throws InvalidInterfaceException |
|
499 | - * @throws ReflectionException |
|
500 | - */ |
|
501 | - public function setPretaxTotal(float $pretax_total) |
|
502 | - { |
|
503 | - $this->set('LIN_pretax', $pretax_total); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * @return float |
|
509 | - * @throws EE_Error |
|
510 | - * @throws ReflectionException |
|
511 | - * @since $VID:$ |
|
512 | - */ |
|
513 | - public function totalWithTax(): float |
|
514 | - { |
|
515 | - return (float) $this->get('LIN_total'); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * Sets total |
|
521 | - * |
|
522 | - * @param float $total |
|
523 | - * @throws EE_Error |
|
524 | - * @throws ReflectionException |
|
525 | - * @since $VID:$ |
|
526 | - */ |
|
527 | - public function setTotalWithTax(float $total) |
|
528 | - { |
|
529 | - $this->set('LIN_total', $total); |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - /** |
|
534 | - * Gets total |
|
535 | - * |
|
536 | - * @return float |
|
537 | - * @throws EE_Error |
|
538 | - * @throws ReflectionException |
|
539 | - * @deprecatd $VID:$ |
|
540 | - */ |
|
541 | - public function total(): float |
|
542 | - { |
|
543 | - return $this->totalWithTax(); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * Sets total |
|
549 | - * |
|
550 | - * @param float $total |
|
551 | - * @throws EE_Error |
|
552 | - * @throws ReflectionException |
|
553 | - * @deprecatd $VID:$ |
|
554 | - */ |
|
555 | - public function set_total($total) |
|
556 | - { |
|
557 | - $this->setTotalWithTax($total); |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * Gets order |
|
563 | - * |
|
564 | - * @return int |
|
565 | - * @throws EE_Error |
|
566 | - * @throws InvalidArgumentException |
|
567 | - * @throws InvalidDataTypeException |
|
568 | - * @throws InvalidInterfaceException |
|
569 | - * @throws ReflectionException |
|
570 | - */ |
|
571 | - public function order() |
|
572 | - { |
|
573 | - return $this->get('LIN_order'); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Sets order |
|
579 | - * |
|
580 | - * @param int $order |
|
581 | - * @throws EE_Error |
|
582 | - * @throws InvalidArgumentException |
|
583 | - * @throws InvalidDataTypeException |
|
584 | - * @throws InvalidInterfaceException |
|
585 | - * @throws ReflectionException |
|
586 | - */ |
|
587 | - public function set_order($order) |
|
588 | - { |
|
589 | - $this->set('LIN_order', $order); |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * Gets parent |
|
595 | - * |
|
596 | - * @return int |
|
597 | - * @throws EE_Error |
|
598 | - * @throws InvalidArgumentException |
|
599 | - * @throws InvalidDataTypeException |
|
600 | - * @throws InvalidInterfaceException |
|
601 | - * @throws ReflectionException |
|
602 | - */ |
|
603 | - public function parent_ID() |
|
604 | - { |
|
605 | - return $this->get('LIN_parent'); |
|
606 | - } |
|
607 | - |
|
608 | - |
|
609 | - /** |
|
610 | - * Sets parent |
|
611 | - * |
|
612 | - * @param int $parent |
|
613 | - * @throws EE_Error |
|
614 | - * @throws InvalidArgumentException |
|
615 | - * @throws InvalidDataTypeException |
|
616 | - * @throws InvalidInterfaceException |
|
617 | - * @throws ReflectionException |
|
618 | - */ |
|
619 | - public function set_parent_ID($parent) |
|
620 | - { |
|
621 | - $this->set('LIN_parent', $parent); |
|
622 | - } |
|
623 | - |
|
624 | - |
|
625 | - /** |
|
626 | - * Gets type |
|
627 | - * |
|
628 | - * @return string |
|
629 | - * @throws EE_Error |
|
630 | - * @throws InvalidArgumentException |
|
631 | - * @throws InvalidDataTypeException |
|
632 | - * @throws InvalidInterfaceException |
|
633 | - * @throws ReflectionException |
|
634 | - */ |
|
635 | - public function type() |
|
636 | - { |
|
637 | - return $this->get('LIN_type'); |
|
638 | - } |
|
639 | - |
|
640 | - |
|
641 | - /** |
|
642 | - * Sets type |
|
643 | - * |
|
644 | - * @param string $type |
|
645 | - * @throws EE_Error |
|
646 | - * @throws InvalidArgumentException |
|
647 | - * @throws InvalidDataTypeException |
|
648 | - * @throws InvalidInterfaceException |
|
649 | - * @throws ReflectionException |
|
650 | - */ |
|
651 | - public function set_type($type) |
|
652 | - { |
|
653 | - $this->set('LIN_type', $type); |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - /** |
|
658 | - * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\ |
|
659 | - * If this line item is saved to the DB, fetches the parent from the DB. However, if this line item isn't in the DB |
|
660 | - * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()` |
|
661 | - * or indirectly by `EE_Line_item::add_child_line_item()`) |
|
662 | - * |
|
663 | - * @return EE_Base_Class|EE_Line_Item |
|
664 | - * @throws EE_Error |
|
665 | - * @throws InvalidArgumentException |
|
666 | - * @throws InvalidDataTypeException |
|
667 | - * @throws InvalidInterfaceException |
|
668 | - * @throws ReflectionException |
|
669 | - */ |
|
670 | - public function parent() |
|
671 | - { |
|
672 | - return $this->ID() |
|
673 | - ? $this->get_model()->get_one_by_ID($this->parent_ID()) |
|
674 | - : $this->_parent; |
|
675 | - } |
|
676 | - |
|
677 | - |
|
678 | - /** |
|
679 | - * Gets ALL the children of this line item (ie, all the parts that contribute towards this total). |
|
680 | - * |
|
681 | - * @return EE_Line_Item[] |
|
682 | - * @throws EE_Error |
|
683 | - * @throws InvalidArgumentException |
|
684 | - * @throws InvalidDataTypeException |
|
685 | - * @throws InvalidInterfaceException |
|
686 | - * @throws ReflectionException |
|
687 | - */ |
|
688 | - public function children(array $query_params = []): array |
|
689 | - { |
|
690 | - if ($this->ID()) { |
|
691 | - // ensure where params are an array |
|
692 | - $query_params[0] = $query_params[0] ?? []; |
|
693 | - // add defaults for line item parent and orderby |
|
694 | - $query_params[0] += ['LIN_parent' => $this->ID()]; |
|
695 | - $query_params += ['order_by' => ['LIN_order' => 'ASC']]; |
|
696 | - return $this->get_model()->get_all($query_params); |
|
697 | - } |
|
698 | - if (! is_array($this->_children)) { |
|
699 | - $this->_children = array(); |
|
700 | - } |
|
701 | - return $this->_children; |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - /** |
|
706 | - * Gets code |
|
707 | - * |
|
708 | - * @return string |
|
709 | - * @throws EE_Error |
|
710 | - * @throws InvalidArgumentException |
|
711 | - * @throws InvalidDataTypeException |
|
712 | - * @throws InvalidInterfaceException |
|
713 | - * @throws ReflectionException |
|
714 | - */ |
|
715 | - public function code() |
|
716 | - { |
|
717 | - return $this->get('LIN_code'); |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - /** |
|
722 | - * Sets code |
|
723 | - * |
|
724 | - * @param string $code |
|
725 | - * @throws EE_Error |
|
726 | - * @throws InvalidArgumentException |
|
727 | - * @throws InvalidDataTypeException |
|
728 | - * @throws InvalidInterfaceException |
|
729 | - * @throws ReflectionException |
|
730 | - */ |
|
731 | - public function set_code($code) |
|
732 | - { |
|
733 | - $this->set('LIN_code', $code); |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - /** |
|
738 | - * Gets is_taxable |
|
739 | - * |
|
740 | - * @return boolean |
|
741 | - * @throws EE_Error |
|
742 | - * @throws InvalidArgumentException |
|
743 | - * @throws InvalidDataTypeException |
|
744 | - * @throws InvalidInterfaceException |
|
745 | - * @throws ReflectionException |
|
746 | - */ |
|
747 | - public function is_taxable() |
|
748 | - { |
|
749 | - return $this->get('LIN_is_taxable'); |
|
750 | - } |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * Sets is_taxable |
|
755 | - * |
|
756 | - * @param boolean $is_taxable |
|
757 | - * @throws EE_Error |
|
758 | - * @throws InvalidArgumentException |
|
759 | - * @throws InvalidDataTypeException |
|
760 | - * @throws InvalidInterfaceException |
|
761 | - * @throws ReflectionException |
|
762 | - */ |
|
763 | - public function set_is_taxable($is_taxable) |
|
764 | - { |
|
765 | - $this->set('LIN_is_taxable', $is_taxable); |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * @param int $timestamp |
|
771 | - * @throws EE_Error |
|
772 | - * @throws ReflectionException |
|
773 | - * @since $VID:$ |
|
774 | - */ |
|
775 | - public function setTimestamp(int $timestamp) |
|
776 | - { |
|
777 | - $this->set('LIN_timestamp', $timestamp); |
|
778 | - } |
|
779 | - |
|
780 | - |
|
781 | - /** |
|
782 | - * Gets the object that this model-joins-to. |
|
783 | - * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on |
|
784 | - * EEM_Promotion_Object |
|
785 | - * Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object |
|
786 | - * |
|
787 | - * @return EE_Base_Class | NULL |
|
788 | - * @throws EE_Error |
|
789 | - * @throws InvalidArgumentException |
|
790 | - * @throws InvalidDataTypeException |
|
791 | - * @throws InvalidInterfaceException |
|
792 | - * @throws ReflectionException |
|
793 | - */ |
|
794 | - public function get_object() |
|
795 | - { |
|
796 | - $model_name_of_related_obj = $this->OBJ_type(); |
|
797 | - return $this->get_model()->has_relation($model_name_of_related_obj) |
|
798 | - ? $this->get_first_related($model_name_of_related_obj) |
|
799 | - : null; |
|
800 | - } |
|
801 | - |
|
802 | - |
|
803 | - /** |
|
804 | - * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket. |
|
805 | - * (IE, if this line item is for a price or something else, will return NULL) |
|
806 | - * |
|
807 | - * @param array $query_params |
|
808 | - * @return EE_Base_Class|EE_Ticket |
|
809 | - * @throws EE_Error |
|
810 | - * @throws InvalidArgumentException |
|
811 | - * @throws InvalidDataTypeException |
|
812 | - * @throws InvalidInterfaceException |
|
813 | - * @throws ReflectionException |
|
814 | - */ |
|
815 | - public function ticket($query_params = array()) |
|
816 | - { |
|
817 | - // we're going to assume that when this method is called |
|
818 | - // we always want to receive the attached ticket EVEN if that ticket is archived. |
|
819 | - // This can be overridden via the incoming $query_params argument |
|
820 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
821 | - $query_params = array_merge($remove_defaults, $query_params); |
|
822 | - return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TICKET, $query_params); |
|
823 | - } |
|
824 | - |
|
825 | - |
|
826 | - /** |
|
827 | - * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket |
|
828 | - * |
|
829 | - * @return EE_Datetime | NULL |
|
830 | - * @throws EE_Error |
|
831 | - * @throws InvalidArgumentException |
|
832 | - * @throws InvalidDataTypeException |
|
833 | - * @throws InvalidInterfaceException |
|
834 | - * @throws ReflectionException |
|
835 | - */ |
|
836 | - public function get_ticket_datetime() |
|
837 | - { |
|
838 | - if ($this->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
839 | - $ticket = $this->ticket(); |
|
840 | - if ($ticket instanceof EE_Ticket) { |
|
841 | - $datetime = $ticket->first_datetime(); |
|
842 | - if ($datetime instanceof EE_Datetime) { |
|
843 | - return $datetime; |
|
844 | - } |
|
845 | - } |
|
846 | - } |
|
847 | - return null; |
|
848 | - } |
|
849 | - |
|
850 | - |
|
851 | - /** |
|
852 | - * Gets the event's name that's related to the ticket, if this is for |
|
853 | - * a ticket |
|
854 | - * |
|
855 | - * @return string |
|
856 | - * @throws EE_Error |
|
857 | - * @throws InvalidArgumentException |
|
858 | - * @throws InvalidDataTypeException |
|
859 | - * @throws InvalidInterfaceException |
|
860 | - * @throws ReflectionException |
|
861 | - */ |
|
862 | - public function ticket_event_name() |
|
863 | - { |
|
864 | - $event_name = esc_html__('Unknown', 'event_espresso'); |
|
865 | - $event = $this->ticket_event(); |
|
866 | - if ($event instanceof EE_Event) { |
|
867 | - $event_name = $event->name(); |
|
868 | - } |
|
869 | - return $event_name; |
|
870 | - } |
|
871 | - |
|
872 | - |
|
873 | - /** |
|
874 | - * Gets the event that's related to the ticket, if this line item represents a ticket. |
|
875 | - * |
|
876 | - * @return EE_Event|null |
|
877 | - * @throws EE_Error |
|
878 | - * @throws InvalidArgumentException |
|
879 | - * @throws InvalidDataTypeException |
|
880 | - * @throws InvalidInterfaceException |
|
881 | - * @throws ReflectionException |
|
882 | - */ |
|
883 | - public function ticket_event() |
|
884 | - { |
|
885 | - $event = null; |
|
886 | - $ticket = $this->ticket(); |
|
887 | - if ($ticket instanceof EE_Ticket) { |
|
888 | - $datetime = $ticket->first_datetime(); |
|
889 | - if ($datetime instanceof EE_Datetime) { |
|
890 | - $event = $datetime->event(); |
|
891 | - } |
|
892 | - } |
|
893 | - return $event; |
|
894 | - } |
|
895 | - |
|
896 | - |
|
897 | - /** |
|
898 | - * Gets the first datetime for this lien item, assuming it's for a ticket |
|
899 | - * |
|
900 | - * @param string $date_format |
|
901 | - * @param string $time_format |
|
902 | - * @return string |
|
903 | - * @throws EE_Error |
|
904 | - * @throws InvalidArgumentException |
|
905 | - * @throws InvalidDataTypeException |
|
906 | - * @throws InvalidInterfaceException |
|
907 | - * @throws ReflectionException |
|
908 | - */ |
|
909 | - public function ticket_datetime_start($date_format = '', $time_format = '') |
|
910 | - { |
|
911 | - $first_datetime_string = esc_html__('Unknown', 'event_espresso'); |
|
912 | - $datetime = $this->get_ticket_datetime(); |
|
913 | - if ($datetime) { |
|
914 | - $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
915 | - } |
|
916 | - return $first_datetime_string; |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * Adds the line item as a child to this line item. If there is another child line |
|
922 | - * item with the same LIN_code, it is overwritten by this new one |
|
923 | - * |
|
924 | - * @param EE_Line_Item $line_item |
|
925 | - * @param bool $set_order |
|
926 | - * @return bool success |
|
927 | - * @throws EE_Error |
|
928 | - * @throws InvalidArgumentException |
|
929 | - * @throws InvalidDataTypeException |
|
930 | - * @throws InvalidInterfaceException |
|
931 | - * @throws ReflectionException |
|
932 | - */ |
|
933 | - public function add_child_line_item(EE_Line_Item $line_item, $set_order = true) |
|
934 | - { |
|
935 | - // should we calculate the LIN_order for this line item ? |
|
936 | - if ($set_order || $line_item->order() === null) { |
|
937 | - $line_item->set_order(count($this->children())); |
|
938 | - } |
|
939 | - if ($this->ID()) { |
|
940 | - // check for any duplicate line items (with the same code), if so, this replaces it |
|
941 | - $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
942 | - if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
943 | - $this->delete_child_line_item($line_item_with_same_code->code()); |
|
944 | - } |
|
945 | - $line_item->set_parent_ID($this->ID()); |
|
946 | - if ($this->TXN_ID()) { |
|
947 | - $line_item->set_TXN_ID($this->TXN_ID()); |
|
948 | - } |
|
949 | - return $line_item->save(); |
|
950 | - } |
|
951 | - $this->_children[ $line_item->code() ] = $line_item; |
|
952 | - if ($line_item->parent() !== $this) { |
|
953 | - $line_item->set_parent($this); |
|
954 | - } |
|
955 | - return true; |
|
956 | - } |
|
957 | - |
|
958 | - |
|
959 | - /** |
|
960 | - * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation. |
|
961 | - * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save() |
|
962 | - * However, if this line item is NOT saved to the DB, this just caches the parent on |
|
963 | - * the EE_Line_Item::_parent property. |
|
964 | - * |
|
965 | - * @param EE_Line_Item $line_item |
|
966 | - * @throws EE_Error |
|
967 | - * @throws InvalidArgumentException |
|
968 | - * @throws InvalidDataTypeException |
|
969 | - * @throws InvalidInterfaceException |
|
970 | - * @throws ReflectionException |
|
971 | - */ |
|
972 | - public function set_parent($line_item) |
|
973 | - { |
|
974 | - if ($this->ID()) { |
|
975 | - if (! $line_item->ID()) { |
|
976 | - $line_item->save(); |
|
977 | - } |
|
978 | - $this->set_parent_ID($line_item->ID()); |
|
979 | - $this->save(); |
|
980 | - } else { |
|
981 | - $this->_parent = $line_item; |
|
982 | - $this->set_parent_ID($line_item->ID()); |
|
983 | - } |
|
984 | - } |
|
985 | - |
|
986 | - |
|
987 | - /** |
|
988 | - * Gets the child line item as specified by its code. Because this returns an object (by reference) |
|
989 | - * you can modify this child line item and the parent (this object) can know about them |
|
990 | - * because it also has a reference to that line item |
|
991 | - * |
|
992 | - * @param string $code |
|
993 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
994 | - * @throws EE_Error |
|
995 | - * @throws InvalidArgumentException |
|
996 | - * @throws InvalidDataTypeException |
|
997 | - * @throws InvalidInterfaceException |
|
998 | - * @throws ReflectionException |
|
999 | - */ |
|
1000 | - public function get_child_line_item($code) |
|
1001 | - { |
|
1002 | - if ($this->ID()) { |
|
1003 | - return $this->get_model()->get_one( |
|
1004 | - array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code)) |
|
1005 | - ); |
|
1006 | - } |
|
1007 | - return isset($this->_children[ $code ]) |
|
1008 | - ? $this->_children[ $code ] |
|
1009 | - : null; |
|
1010 | - } |
|
1011 | - |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD |
|
1015 | - * cached on it) |
|
1016 | - * |
|
1017 | - * @return int |
|
1018 | - * @throws EE_Error |
|
1019 | - * @throws InvalidArgumentException |
|
1020 | - * @throws InvalidDataTypeException |
|
1021 | - * @throws InvalidInterfaceException |
|
1022 | - * @throws ReflectionException |
|
1023 | - */ |
|
1024 | - public function delete_children_line_items() |
|
1025 | - { |
|
1026 | - if ($this->ID()) { |
|
1027 | - return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
1028 | - } |
|
1029 | - $count = count($this->_children); |
|
1030 | - $this->_children = array(); |
|
1031 | - return $count; |
|
1032 | - } |
|
1033 | - |
|
1034 | - |
|
1035 | - /** |
|
1036 | - * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
|
1037 | - * HAS NOT been saved to the DB, removes the child line item with index $code. |
|
1038 | - * Also searches through the child's children for a matching line item. However, once a line item has been found |
|
1039 | - * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be |
|
1040 | - * deleted) |
|
1041 | - * |
|
1042 | - * @param string $code |
|
1043 | - * @param bool $stop_search_once_found |
|
1044 | - * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to |
|
1045 | - * the DB yet) |
|
1046 | - * @throws EE_Error |
|
1047 | - * @throws InvalidArgumentException |
|
1048 | - * @throws InvalidDataTypeException |
|
1049 | - * @throws InvalidInterfaceException |
|
1050 | - * @throws ReflectionException |
|
1051 | - */ |
|
1052 | - public function delete_child_line_item($code, $stop_search_once_found = true) |
|
1053 | - { |
|
1054 | - if ($this->ID()) { |
|
1055 | - $items_deleted = 0; |
|
1056 | - if ($this->code() === $code) { |
|
1057 | - $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
1058 | - $items_deleted += (int) $this->delete(); |
|
1059 | - if ($stop_search_once_found) { |
|
1060 | - return $items_deleted; |
|
1061 | - } |
|
1062 | - } |
|
1063 | - foreach ($this->children() as $child_line_item) { |
|
1064 | - $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
1065 | - } |
|
1066 | - return $items_deleted; |
|
1067 | - } |
|
1068 | - if (isset($this->_children[ $code ])) { |
|
1069 | - unset($this->_children[ $code ]); |
|
1070 | - return 1; |
|
1071 | - } |
|
1072 | - return 0; |
|
1073 | - } |
|
1074 | - |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * If this line item is in the database, is of the type subtotal, and |
|
1078 | - * has no children, why do we have it? It should be deleted so this function |
|
1079 | - * does that |
|
1080 | - * |
|
1081 | - * @return boolean |
|
1082 | - * @throws EE_Error |
|
1083 | - * @throws InvalidArgumentException |
|
1084 | - * @throws InvalidDataTypeException |
|
1085 | - * @throws InvalidInterfaceException |
|
1086 | - * @throws ReflectionException |
|
1087 | - */ |
|
1088 | - public function delete_if_childless_subtotal() |
|
1089 | - { |
|
1090 | - if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) { |
|
1091 | - return $this->delete(); |
|
1092 | - } |
|
1093 | - return false; |
|
1094 | - } |
|
1095 | - |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * Creates a code and returns a string. doesn't assign the code to this model object |
|
1099 | - * |
|
1100 | - * @return string |
|
1101 | - * @throws EE_Error |
|
1102 | - * @throws InvalidArgumentException |
|
1103 | - * @throws InvalidDataTypeException |
|
1104 | - * @throws InvalidInterfaceException |
|
1105 | - * @throws ReflectionException |
|
1106 | - */ |
|
1107 | - public function generate_code() |
|
1108 | - { |
|
1109 | - // each line item in the cart requires a unique identifier |
|
1110 | - return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime()); |
|
1111 | - } |
|
1112 | - |
|
1113 | - |
|
1114 | - /** |
|
1115 | - * @return bool |
|
1116 | - * @throws EE_Error |
|
1117 | - * @throws InvalidArgumentException |
|
1118 | - * @throws InvalidDataTypeException |
|
1119 | - * @throws InvalidInterfaceException |
|
1120 | - * @throws ReflectionException |
|
1121 | - */ |
|
1122 | - public function isGlobalTax(): bool |
|
1123 | - { |
|
1124 | - return $this->type() === EEM_Line_Item::type_tax; |
|
1125 | - } |
|
1126 | - |
|
1127 | - |
|
1128 | - /** |
|
1129 | - * @return bool |
|
1130 | - * @throws EE_Error |
|
1131 | - * @throws InvalidArgumentException |
|
1132 | - * @throws InvalidDataTypeException |
|
1133 | - * @throws InvalidInterfaceException |
|
1134 | - * @throws ReflectionException |
|
1135 | - */ |
|
1136 | - public function isSubTax(): bool |
|
1137 | - { |
|
1138 | - return $this->type() === EEM_Line_Item::type_sub_tax; |
|
1139 | - } |
|
1140 | - |
|
1141 | - |
|
1142 | - /** |
|
1143 | - * returns true if this is a line item with a direct descendent of the type sub-tax |
|
1144 | - * |
|
1145 | - * @return array |
|
1146 | - * @throws EE_Error |
|
1147 | - * @throws InvalidArgumentException |
|
1148 | - * @throws InvalidDataTypeException |
|
1149 | - * @throws InvalidInterfaceException |
|
1150 | - * @throws ReflectionException |
|
1151 | - */ |
|
1152 | - public function getSubTaxes(): array |
|
1153 | - { |
|
1154 | - if (! $this->is_line_item()) { |
|
1155 | - return []; |
|
1156 | - } |
|
1157 | - return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_sub_tax); |
|
1158 | - } |
|
1159 | - |
|
1160 | - |
|
1161 | - /** |
|
1162 | - * returns true if this is a line item with a direct descendent of the type sub-tax |
|
1163 | - * |
|
1164 | - * @return bool |
|
1165 | - * @throws EE_Error |
|
1166 | - * @throws InvalidArgumentException |
|
1167 | - * @throws InvalidDataTypeException |
|
1168 | - * @throws InvalidInterfaceException |
|
1169 | - * @throws ReflectionException |
|
1170 | - */ |
|
1171 | - public function hasSubTaxes(): bool |
|
1172 | - { |
|
1173 | - if (! $this->is_line_item()) { |
|
1174 | - return false; |
|
1175 | - } |
|
1176 | - $sub_taxes = $this->getSubTaxes(); |
|
1177 | - return ! empty($sub_taxes); |
|
1178 | - } |
|
1179 | - |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * @return bool |
|
1183 | - * @throws EE_Error |
|
1184 | - * @throws ReflectionException |
|
1185 | - * @deprecated $VID:$ |
|
1186 | - */ |
|
1187 | - public function is_tax(): bool |
|
1188 | - { |
|
1189 | - return $this->isGlobalTax(); |
|
1190 | - } |
|
1191 | - |
|
1192 | - |
|
1193 | - /** |
|
1194 | - * @return bool |
|
1195 | - * @throws EE_Error |
|
1196 | - * @throws InvalidArgumentException |
|
1197 | - * @throws InvalidDataTypeException |
|
1198 | - * @throws InvalidInterfaceException |
|
1199 | - * @throws ReflectionException |
|
1200 | - */ |
|
1201 | - public function is_tax_sub_total() |
|
1202 | - { |
|
1203 | - return $this->type() === EEM_Line_Item::type_tax_sub_total; |
|
1204 | - } |
|
1205 | - |
|
1206 | - |
|
1207 | - /** |
|
1208 | - * @return bool |
|
1209 | - * @throws EE_Error |
|
1210 | - * @throws InvalidArgumentException |
|
1211 | - * @throws InvalidDataTypeException |
|
1212 | - * @throws InvalidInterfaceException |
|
1213 | - * @throws ReflectionException |
|
1214 | - */ |
|
1215 | - public function is_line_item() |
|
1216 | - { |
|
1217 | - return $this->type() === EEM_Line_Item::type_line_item; |
|
1218 | - } |
|
1219 | - |
|
1220 | - |
|
1221 | - /** |
|
1222 | - * @return bool |
|
1223 | - * @throws EE_Error |
|
1224 | - * @throws InvalidArgumentException |
|
1225 | - * @throws InvalidDataTypeException |
|
1226 | - * @throws InvalidInterfaceException |
|
1227 | - * @throws ReflectionException |
|
1228 | - */ |
|
1229 | - public function is_sub_line_item() |
|
1230 | - { |
|
1231 | - return $this->type() === EEM_Line_Item::type_sub_line_item; |
|
1232 | - } |
|
1233 | - |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * @return bool |
|
1237 | - * @throws EE_Error |
|
1238 | - * @throws InvalidArgumentException |
|
1239 | - * @throws InvalidDataTypeException |
|
1240 | - * @throws InvalidInterfaceException |
|
1241 | - * @throws ReflectionException |
|
1242 | - */ |
|
1243 | - public function is_sub_total() |
|
1244 | - { |
|
1245 | - return $this->type() === EEM_Line_Item::type_sub_total; |
|
1246 | - } |
|
1247 | - |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * Whether or not this line item is a cancellation line item |
|
1251 | - * |
|
1252 | - * @return boolean |
|
1253 | - * @throws EE_Error |
|
1254 | - * @throws InvalidArgumentException |
|
1255 | - * @throws InvalidDataTypeException |
|
1256 | - * @throws InvalidInterfaceException |
|
1257 | - * @throws ReflectionException |
|
1258 | - */ |
|
1259 | - public function is_cancellation() |
|
1260 | - { |
|
1261 | - return EEM_Line_Item::type_cancellation === $this->type(); |
|
1262 | - } |
|
1263 | - |
|
1264 | - |
|
1265 | - /** |
|
1266 | - * @return bool |
|
1267 | - * @throws EE_Error |
|
1268 | - * @throws InvalidArgumentException |
|
1269 | - * @throws InvalidDataTypeException |
|
1270 | - * @throws InvalidInterfaceException |
|
1271 | - * @throws ReflectionException |
|
1272 | - */ |
|
1273 | - public function is_total() |
|
1274 | - { |
|
1275 | - return $this->type() === EEM_Line_Item::type_total; |
|
1276 | - } |
|
1277 | - |
|
1278 | - |
|
1279 | - /** |
|
1280 | - * @return bool |
|
1281 | - * @throws EE_Error |
|
1282 | - * @throws InvalidArgumentException |
|
1283 | - * @throws InvalidDataTypeException |
|
1284 | - * @throws InvalidInterfaceException |
|
1285 | - * @throws ReflectionException |
|
1286 | - */ |
|
1287 | - public function is_cancelled() |
|
1288 | - { |
|
1289 | - return $this->type() === EEM_Line_Item::type_cancellation; |
|
1290 | - } |
|
1291 | - |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * @return string like '2, 004.00', formatted according to the localized currency |
|
1295 | - * @throws EE_Error |
|
1296 | - * @throws ReflectionException |
|
1297 | - */ |
|
1298 | - public function unit_price_no_code(): string |
|
1299 | - { |
|
1300 | - return $this->prettyUnitPrice(); |
|
1301 | - } |
|
1302 | - |
|
1303 | - |
|
1304 | - /** |
|
1305 | - * @return string like '2, 004.00', formatted according to the localized currency |
|
1306 | - * @throws EE_Error |
|
1307 | - * @throws ReflectionException |
|
1308 | - * @since $VID:$ |
|
1309 | - */ |
|
1310 | - public function prettyUnitPrice(): string |
|
1311 | - { |
|
1312 | - return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
1313 | - } |
|
1314 | - |
|
1315 | - |
|
1316 | - /** |
|
1317 | - * @return string like '2, 004.00', formatted according to the localized currency |
|
1318 | - * @throws EE_Error |
|
1319 | - * @throws ReflectionException |
|
1320 | - */ |
|
1321 | - public function total_no_code(): string |
|
1322 | - { |
|
1323 | - return $this->prettyTotal(); |
|
1324 | - } |
|
1325 | - |
|
1326 | - |
|
1327 | - /** |
|
1328 | - * @return string like '2, 004.00', formatted according to the localized currency |
|
1329 | - * @throws EE_Error |
|
1330 | - * @throws ReflectionException |
|
1331 | - * @since $VID:$ |
|
1332 | - */ |
|
1333 | - public function prettyTotal(): string |
|
1334 | - { |
|
1335 | - return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
1336 | - } |
|
1337 | - |
|
1338 | - |
|
1339 | - /** |
|
1340 | - * Gets the final total on this item, taking taxes into account. |
|
1341 | - * Has the side-effect of setting the sub-total as it was just calculated. |
|
1342 | - * If this is used on a grand-total line item, also updates the transaction's |
|
1343 | - * TXN_total (provided this line item is allowed to persist, otherwise we don't |
|
1344 | - * want to change a persistable transaction with info from a non-persistent line item) |
|
1345 | - * |
|
1346 | - * @param bool $update_txn_status |
|
1347 | - * @return float |
|
1348 | - * @throws EE_Error |
|
1349 | - * @throws InvalidArgumentException |
|
1350 | - * @throws InvalidDataTypeException |
|
1351 | - * @throws InvalidInterfaceException |
|
1352 | - * @throws ReflectionException |
|
1353 | - * @throws RuntimeException |
|
1354 | - */ |
|
1355 | - public function recalculate_total_including_taxes(bool $update_txn_status = false): float |
|
1356 | - { |
|
1357 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($this); |
|
1358 | - return $this->calculator->recalculateTotalIncludingTaxes($grand_total_line_item, $update_txn_status); |
|
1359 | - } |
|
1360 | - |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * Recursively goes through all the children and recalculates sub-totals EXCEPT for |
|
1364 | - * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its |
|
1365 | - * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and |
|
1366 | - * when this is called on the grand total |
|
1367 | - * |
|
1368 | - * @return float |
|
1369 | - * @throws EE_Error |
|
1370 | - * @throws InvalidArgumentException |
|
1371 | - * @throws InvalidDataTypeException |
|
1372 | - * @throws InvalidInterfaceException |
|
1373 | - * @throws ReflectionException |
|
1374 | - */ |
|
1375 | - public function recalculate_pre_tax_total(): float |
|
1376 | - { |
|
1377 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($this); |
|
1378 | - [$total] = $this->calculator->recalculateLineItemTotals($grand_total_line_item); |
|
1379 | - return (float) $total; |
|
1380 | - } |
|
1381 | - |
|
1382 | - |
|
1383 | - /** |
|
1384 | - * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets |
|
1385 | - * the totals on each tax calculated, and returns the final tax total. Re-saves tax line items |
|
1386 | - * and tax sub-total if already in the DB |
|
1387 | - * |
|
1388 | - * @return float |
|
1389 | - * @throws EE_Error |
|
1390 | - * @throws InvalidArgumentException |
|
1391 | - * @throws InvalidDataTypeException |
|
1392 | - * @throws InvalidInterfaceException |
|
1393 | - * @throws ReflectionException |
|
1394 | - */ |
|
1395 | - public function recalculate_taxes_and_tax_total(): float |
|
1396 | - { |
|
1397 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($this); |
|
1398 | - return $this->calculator->recalculateTaxesAndTaxTotal($grand_total_line_item); |
|
1399 | - } |
|
1400 | - |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * Gets the total tax on this line item. Assumes taxes have already been calculated using |
|
1404 | - * recalculate_taxes_and_total |
|
1405 | - * |
|
1406 | - * @return float |
|
1407 | - * @throws EE_Error |
|
1408 | - * @throws InvalidArgumentException |
|
1409 | - * @throws InvalidDataTypeException |
|
1410 | - * @throws InvalidInterfaceException |
|
1411 | - * @throws ReflectionException |
|
1412 | - */ |
|
1413 | - public function get_total_tax() |
|
1414 | - { |
|
1415 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($this); |
|
1416 | - return $this->calculator->recalculateTaxesAndTaxTotal($grand_total_line_item); |
|
1417 | - } |
|
1418 | - |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * Gets the total for all the items purchased only |
|
1422 | - * |
|
1423 | - * @return float |
|
1424 | - * @throws EE_Error |
|
1425 | - * @throws InvalidArgumentException |
|
1426 | - * @throws InvalidDataTypeException |
|
1427 | - * @throws InvalidInterfaceException |
|
1428 | - * @throws ReflectionException |
|
1429 | - */ |
|
1430 | - public function get_items_total() |
|
1431 | - { |
|
1432 | - // by default, let's make sure we're consistent with the existing line item |
|
1433 | - if ($this->is_total()) { |
|
1434 | - return $this->pretaxTotal(); |
|
1435 | - } |
|
1436 | - $total = 0; |
|
1437 | - foreach ($this->get_items() as $item) { |
|
1438 | - if ($item instanceof EE_Line_Item) { |
|
1439 | - $total += $item->pretaxTotal(); |
|
1440 | - } |
|
1441 | - } |
|
1442 | - return $total; |
|
1443 | - } |
|
1444 | - |
|
1445 | - |
|
1446 | - /** |
|
1447 | - * Gets all the descendants (ie, children or children of children etc) that |
|
1448 | - * are of the type 'tax' |
|
1449 | - * |
|
1450 | - * @return EE_Line_Item[] |
|
1451 | - * @throws EE_Error |
|
1452 | - */ |
|
1453 | - public function tax_descendants() |
|
1454 | - { |
|
1455 | - return EEH_Line_Item::get_tax_descendants($this); |
|
1456 | - } |
|
1457 | - |
|
1458 | - |
|
1459 | - /** |
|
1460 | - * Gets all the real items purchased which are children of this item |
|
1461 | - * |
|
1462 | - * @return EE_Line_Item[] |
|
1463 | - * @throws EE_Error |
|
1464 | - */ |
|
1465 | - public function get_items() |
|
1466 | - { |
|
1467 | - return EEH_Line_Item::get_line_item_descendants($this); |
|
1468 | - } |
|
1469 | - |
|
1470 | - |
|
1471 | - /** |
|
1472 | - * Returns the amount taxable among this line item's children (or if it has no children, |
|
1473 | - * how much of it is taxable). Does not recalculate totals or subtotals. |
|
1474 | - * If the taxable total is negative, (eg, if none of the tickets were taxable, |
|
1475 | - * but there is a "Taxable" discount), returns 0. |
|
1476 | - * |
|
1477 | - * @return float |
|
1478 | - * @throws EE_Error |
|
1479 | - * @throws InvalidArgumentException |
|
1480 | - * @throws InvalidDataTypeException |
|
1481 | - * @throws InvalidInterfaceException |
|
1482 | - * @throws ReflectionException |
|
1483 | - */ |
|
1484 | - public function taxable_total(): float |
|
1485 | - { |
|
1486 | - return $this->calculator->taxableAmountForGlobalTaxes($this); |
|
1487 | - } |
|
1488 | - |
|
1489 | - |
|
1490 | - /** |
|
1491 | - * Gets the transaction for this line item |
|
1492 | - * |
|
1493 | - * @return EE_Base_Class|EE_Transaction |
|
1494 | - * @throws EE_Error |
|
1495 | - * @throws InvalidArgumentException |
|
1496 | - * @throws InvalidDataTypeException |
|
1497 | - * @throws InvalidInterfaceException |
|
1498 | - * @throws ReflectionException |
|
1499 | - */ |
|
1500 | - public function transaction() |
|
1501 | - { |
|
1502 | - return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TRANSACTION); |
|
1503 | - } |
|
1504 | - |
|
1505 | - |
|
1506 | - /** |
|
1507 | - * Saves this line item to the DB, and recursively saves its descendants. |
|
1508 | - * Because there currently is no proper parent-child relation on the model, |
|
1509 | - * save_this_and_cached() will NOT save the descendants. |
|
1510 | - * Also sets the transaction on this line item and all its descendants before saving |
|
1511 | - * |
|
1512 | - * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
|
1513 | - * @return int count of items saved |
|
1514 | - * @throws EE_Error |
|
1515 | - * @throws InvalidArgumentException |
|
1516 | - * @throws InvalidDataTypeException |
|
1517 | - * @throws InvalidInterfaceException |
|
1518 | - * @throws ReflectionException |
|
1519 | - */ |
|
1520 | - public function save_this_and_descendants_to_txn($txn_id = null) |
|
1521 | - { |
|
1522 | - $count = 0; |
|
1523 | - if (! $txn_id) { |
|
1524 | - $txn_id = $this->TXN_ID(); |
|
1525 | - } |
|
1526 | - $this->set_TXN_ID($txn_id); |
|
1527 | - $children = $this->children(); |
|
1528 | - $count += $this->save() |
|
1529 | - ? 1 |
|
1530 | - : 0; |
|
1531 | - foreach ($children as $child_line_item) { |
|
1532 | - if ($child_line_item instanceof EE_Line_Item) { |
|
1533 | - $child_line_item->set_parent_ID($this->ID()); |
|
1534 | - $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1535 | - } |
|
1536 | - } |
|
1537 | - return $count; |
|
1538 | - } |
|
1539 | - |
|
1540 | - |
|
1541 | - /** |
|
1542 | - * Saves this line item to the DB, and recursively saves its descendants. |
|
1543 | - * |
|
1544 | - * @return int count of items saved |
|
1545 | - * @throws EE_Error |
|
1546 | - * @throws InvalidArgumentException |
|
1547 | - * @throws InvalidDataTypeException |
|
1548 | - * @throws InvalidInterfaceException |
|
1549 | - * @throws ReflectionException |
|
1550 | - */ |
|
1551 | - public function save_this_and_descendants() |
|
1552 | - { |
|
1553 | - $count = 0; |
|
1554 | - $children = $this->children(); |
|
1555 | - $count += $this->save() |
|
1556 | - ? 1 |
|
1557 | - : 0; |
|
1558 | - foreach ($children as $child_line_item) { |
|
1559 | - if ($child_line_item instanceof EE_Line_Item) { |
|
1560 | - $child_line_item->set_parent_ID($this->ID()); |
|
1561 | - $count += $child_line_item->save_this_and_descendants(); |
|
1562 | - } |
|
1563 | - } |
|
1564 | - return $count; |
|
1565 | - } |
|
1566 | - |
|
1567 | - |
|
1568 | - /** |
|
1569 | - * returns the cancellation line item if this item was cancelled |
|
1570 | - * |
|
1571 | - * @return EE_Line_Item[] |
|
1572 | - * @throws InvalidArgumentException |
|
1573 | - * @throws InvalidInterfaceException |
|
1574 | - * @throws InvalidDataTypeException |
|
1575 | - * @throws ReflectionException |
|
1576 | - * @throws EE_Error |
|
1577 | - */ |
|
1578 | - public function get_cancellations() |
|
1579 | - { |
|
1580 | - return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1581 | - } |
|
1582 | - |
|
1583 | - |
|
1584 | - /** |
|
1585 | - * If this item has an ID, then this saves it again to update the db |
|
1586 | - * |
|
1587 | - * @return int count of items saved |
|
1588 | - * @throws EE_Error |
|
1589 | - * @throws InvalidArgumentException |
|
1590 | - * @throws InvalidDataTypeException |
|
1591 | - * @throws InvalidInterfaceException |
|
1592 | - * @throws ReflectionException |
|
1593 | - */ |
|
1594 | - public function maybe_save() |
|
1595 | - { |
|
1596 | - if ($this->ID()) { |
|
1597 | - return $this->save(); |
|
1598 | - } |
|
1599 | - return false; |
|
1600 | - } |
|
1601 | - |
|
1602 | - |
|
1603 | - /** |
|
1604 | - * clears the cached children and parent from the line item |
|
1605 | - * |
|
1606 | - * @return void |
|
1607 | - */ |
|
1608 | - public function clear_related_line_item_cache() |
|
1609 | - { |
|
1610 | - $this->_children = array(); |
|
1611 | - $this->_parent = null; |
|
1612 | - } |
|
1613 | - |
|
1614 | - |
|
1615 | - /** |
|
1616 | - * @param bool $raw |
|
1617 | - * @return int |
|
1618 | - * @throws EE_Error |
|
1619 | - * @throws InvalidArgumentException |
|
1620 | - * @throws InvalidDataTypeException |
|
1621 | - * @throws InvalidInterfaceException |
|
1622 | - * @throws ReflectionException |
|
1623 | - */ |
|
1624 | - public function timestamp($raw = false) |
|
1625 | - { |
|
1626 | - return $raw |
|
1627 | - ? $this->get_raw('LIN_timestamp') |
|
1628 | - : $this->get('LIN_timestamp'); |
|
1629 | - } |
|
1630 | - |
|
1631 | - |
|
1632 | - |
|
1633 | - |
|
1634 | - /************************* DEPRECATED *************************/ |
|
1635 | - /** |
|
1636 | - * @deprecated 4.6.0 |
|
1637 | - * @param string $type one of the constants on EEM_Line_Item |
|
1638 | - * @return EE_Line_Item[] |
|
1639 | - * @throws EE_Error |
|
1640 | - */ |
|
1641 | - protected function _get_descendants_of_type($type) |
|
1642 | - { |
|
1643 | - EE_Error::doing_it_wrong( |
|
1644 | - 'EE_Line_Item::_get_descendants_of_type()', |
|
1645 | - sprintf( |
|
1646 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1647 | - 'EEH_Line_Item::get_descendants_of_type()' |
|
1648 | - ), |
|
1649 | - '4.6.0' |
|
1650 | - ); |
|
1651 | - return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1652 | - } |
|
1653 | - |
|
1654 | - |
|
1655 | - /** |
|
1656 | - * @deprecated 4.6.0 |
|
1657 | - * @param string $type like one of the EEM_Line_Item::type_* |
|
1658 | - * @return EE_Line_Item |
|
1659 | - * @throws EE_Error |
|
1660 | - * @throws InvalidArgumentException |
|
1661 | - * @throws InvalidDataTypeException |
|
1662 | - * @throws InvalidInterfaceException |
|
1663 | - * @throws ReflectionException |
|
1664 | - */ |
|
1665 | - public function get_nearest_descendant_of_type(string $type): EE_Line_Item |
|
1666 | - { |
|
1667 | - EE_Error::doing_it_wrong( |
|
1668 | - 'EE_Line_Item::get_nearest_descendant_of_type()', |
|
1669 | - sprintf( |
|
1670 | - esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1671 | - 'EEH_Line_Item::get_nearest_descendant_of_type()' |
|
1672 | - ), |
|
1673 | - '4.6.0' |
|
1674 | - ); |
|
1675 | - return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1676 | - } |
|
18 | + /** |
|
19 | + * for children line items (currently not a normal relation) |
|
20 | + * |
|
21 | + * @type EE_Line_Item[] |
|
22 | + */ |
|
23 | + protected $_children = array(); |
|
24 | + |
|
25 | + /** |
|
26 | + * for the parent line item |
|
27 | + * |
|
28 | + * @var EE_Line_Item |
|
29 | + */ |
|
30 | + protected $_parent; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var LineItemCalculator |
|
34 | + */ |
|
35 | + protected $calculator; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @param array $props_n_values incoming values |
|
40 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
41 | + * used.) |
|
42 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
43 | + * date_format and the second value is the time format |
|
44 | + * @return EE_Line_Item |
|
45 | + * @throws EE_Error |
|
46 | + * @throws InvalidArgumentException |
|
47 | + * @throws InvalidDataTypeException |
|
48 | + * @throws InvalidInterfaceException |
|
49 | + * @throws ReflectionException |
|
50 | + */ |
|
51 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
52 | + { |
|
53 | + $has_object = parent::_check_for_object( |
|
54 | + $props_n_values, |
|
55 | + __CLASS__, |
|
56 | + $timezone, |
|
57 | + $date_formats |
|
58 | + ); |
|
59 | + return $has_object |
|
60 | + ? $has_object |
|
61 | + : new self($props_n_values, false, $timezone); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @param array $props_n_values incoming values from the database |
|
67 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
68 | + * the website will be used. |
|
69 | + * @return EE_Line_Item |
|
70 | + * @throws EE_Error |
|
71 | + * @throws InvalidArgumentException |
|
72 | + * @throws InvalidDataTypeException |
|
73 | + * @throws InvalidInterfaceException |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
77 | + { |
|
78 | + return new self($props_n_values, true, $timezone); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Adds some defaults if they're not specified |
|
84 | + * |
|
85 | + * @param array $fieldValues |
|
86 | + * @param bool $bydb |
|
87 | + * @param string $timezone |
|
88 | + * @throws EE_Error |
|
89 | + * @throws InvalidArgumentException |
|
90 | + * @throws InvalidDataTypeException |
|
91 | + * @throws InvalidInterfaceException |
|
92 | + * @throws ReflectionException |
|
93 | + */ |
|
94 | + protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
|
95 | + { |
|
96 | + $this->calculator = LoaderFactory::getShared(LineItemCalculator::class); |
|
97 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
98 | + if (! $this->get('LIN_code')) { |
|
99 | + $this->set_code($this->generate_code()); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + public function __wakeup() |
|
105 | + { |
|
106 | + $this->calculator = LoaderFactory::getShared(LineItemCalculator::class); |
|
107 | + parent::__wakeup(); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Gets ID |
|
113 | + * |
|
114 | + * @return int |
|
115 | + * @throws EE_Error |
|
116 | + * @throws InvalidArgumentException |
|
117 | + * @throws InvalidDataTypeException |
|
118 | + * @throws InvalidInterfaceException |
|
119 | + * @throws ReflectionException |
|
120 | + */ |
|
121 | + public function ID() |
|
122 | + { |
|
123 | + return $this->get('LIN_ID'); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Gets TXN_ID |
|
129 | + * |
|
130 | + * @return int |
|
131 | + * @throws EE_Error |
|
132 | + * @throws InvalidArgumentException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidInterfaceException |
|
135 | + * @throws ReflectionException |
|
136 | + */ |
|
137 | + public function TXN_ID() |
|
138 | + { |
|
139 | + return $this->get('TXN_ID'); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * Sets TXN_ID |
|
145 | + * |
|
146 | + * @param int $TXN_ID |
|
147 | + * @throws EE_Error |
|
148 | + * @throws InvalidArgumentException |
|
149 | + * @throws InvalidDataTypeException |
|
150 | + * @throws InvalidInterfaceException |
|
151 | + * @throws ReflectionException |
|
152 | + */ |
|
153 | + public function set_TXN_ID($TXN_ID) |
|
154 | + { |
|
155 | + $this->set('TXN_ID', $TXN_ID); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Gets name |
|
161 | + * |
|
162 | + * @return string |
|
163 | + * @throws EE_Error |
|
164 | + * @throws InvalidArgumentException |
|
165 | + * @throws InvalidDataTypeException |
|
166 | + * @throws InvalidInterfaceException |
|
167 | + * @throws ReflectionException |
|
168 | + */ |
|
169 | + public function name() |
|
170 | + { |
|
171 | + $name = $this->get('LIN_name'); |
|
172 | + if (! $name) { |
|
173 | + $name = ucwords(str_replace('-', ' ', $this->type())); |
|
174 | + } |
|
175 | + return $name; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Sets name |
|
181 | + * |
|
182 | + * @param string $name |
|
183 | + * @throws EE_Error |
|
184 | + * @throws InvalidArgumentException |
|
185 | + * @throws InvalidDataTypeException |
|
186 | + * @throws InvalidInterfaceException |
|
187 | + * @throws ReflectionException |
|
188 | + */ |
|
189 | + public function set_name($name) |
|
190 | + { |
|
191 | + $this->set('LIN_name', $name); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Gets desc |
|
197 | + * |
|
198 | + * @return string |
|
199 | + * @throws EE_Error |
|
200 | + * @throws InvalidArgumentException |
|
201 | + * @throws InvalidDataTypeException |
|
202 | + * @throws InvalidInterfaceException |
|
203 | + * @throws ReflectionException |
|
204 | + */ |
|
205 | + public function desc() |
|
206 | + { |
|
207 | + return $this->get('LIN_desc'); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Sets desc |
|
213 | + * |
|
214 | + * @param string $desc |
|
215 | + * @throws EE_Error |
|
216 | + * @throws InvalidArgumentException |
|
217 | + * @throws InvalidDataTypeException |
|
218 | + * @throws InvalidInterfaceException |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + public function set_desc($desc) |
|
222 | + { |
|
223 | + $this->set('LIN_desc', $desc); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * Gets quantity |
|
229 | + * |
|
230 | + * @return int |
|
231 | + * @throws EE_Error |
|
232 | + * @throws InvalidArgumentException |
|
233 | + * @throws InvalidDataTypeException |
|
234 | + * @throws InvalidInterfaceException |
|
235 | + * @throws ReflectionException |
|
236 | + */ |
|
237 | + public function quantity(): int |
|
238 | + { |
|
239 | + return (int) $this->get('LIN_quantity'); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Sets quantity |
|
245 | + * |
|
246 | + * @param int $quantity |
|
247 | + * @throws EE_Error |
|
248 | + * @throws InvalidArgumentException |
|
249 | + * @throws InvalidDataTypeException |
|
250 | + * @throws InvalidInterfaceException |
|
251 | + * @throws ReflectionException |
|
252 | + */ |
|
253 | + public function set_quantity($quantity) |
|
254 | + { |
|
255 | + $this->set('LIN_quantity', max($quantity, 0)); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Gets item_id |
|
261 | + * |
|
262 | + * @return int |
|
263 | + * @throws EE_Error |
|
264 | + * @throws InvalidArgumentException |
|
265 | + * @throws InvalidDataTypeException |
|
266 | + * @throws InvalidInterfaceException |
|
267 | + * @throws ReflectionException |
|
268 | + */ |
|
269 | + public function OBJ_ID() |
|
270 | + { |
|
271 | + return $this->get('OBJ_ID'); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * Sets item_id |
|
277 | + * |
|
278 | + * @param int $item_id |
|
279 | + * @throws EE_Error |
|
280 | + * @throws InvalidArgumentException |
|
281 | + * @throws InvalidDataTypeException |
|
282 | + * @throws InvalidInterfaceException |
|
283 | + * @throws ReflectionException |
|
284 | + */ |
|
285 | + public function set_OBJ_ID($item_id) |
|
286 | + { |
|
287 | + $this->set('OBJ_ID', $item_id); |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * Gets item_type |
|
293 | + * |
|
294 | + * @return string |
|
295 | + * @throws EE_Error |
|
296 | + * @throws InvalidArgumentException |
|
297 | + * @throws InvalidDataTypeException |
|
298 | + * @throws InvalidInterfaceException |
|
299 | + * @throws ReflectionException |
|
300 | + */ |
|
301 | + public function OBJ_type() |
|
302 | + { |
|
303 | + return $this->get('OBJ_type'); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Gets item_type |
|
309 | + * |
|
310 | + * @return string |
|
311 | + * @throws EE_Error |
|
312 | + * @throws InvalidArgumentException |
|
313 | + * @throws InvalidDataTypeException |
|
314 | + * @throws InvalidInterfaceException |
|
315 | + * @throws ReflectionException |
|
316 | + */ |
|
317 | + public function OBJ_type_i18n() |
|
318 | + { |
|
319 | + $obj_type = $this->OBJ_type(); |
|
320 | + switch ($obj_type) { |
|
321 | + case EEM_Line_Item::OBJ_TYPE_EVENT: |
|
322 | + $obj_type = esc_html__('Event', 'event_espresso'); |
|
323 | + break; |
|
324 | + case EEM_Line_Item::OBJ_TYPE_PRICE: |
|
325 | + $obj_type = esc_html__('Price', 'event_espresso'); |
|
326 | + break; |
|
327 | + case EEM_Line_Item::OBJ_TYPE_PROMOTION: |
|
328 | + $obj_type = esc_html__('Promotion', 'event_espresso'); |
|
329 | + break; |
|
330 | + case EEM_Line_Item::OBJ_TYPE_TICKET: |
|
331 | + $obj_type = esc_html__('Ticket', 'event_espresso'); |
|
332 | + break; |
|
333 | + case EEM_Line_Item::OBJ_TYPE_TRANSACTION: |
|
334 | + $obj_type = esc_html__('Transaction', 'event_espresso'); |
|
335 | + break; |
|
336 | + } |
|
337 | + return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * Sets item_type |
|
343 | + * |
|
344 | + * @param string $OBJ_type |
|
345 | + * @throws EE_Error |
|
346 | + * @throws InvalidArgumentException |
|
347 | + * @throws InvalidDataTypeException |
|
348 | + * @throws InvalidInterfaceException |
|
349 | + * @throws ReflectionException |
|
350 | + */ |
|
351 | + public function set_OBJ_type($OBJ_type) |
|
352 | + { |
|
353 | + $this->set('OBJ_type', $OBJ_type); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * Gets unit_price |
|
359 | + * |
|
360 | + * @return float |
|
361 | + * @throws EE_Error |
|
362 | + * @throws InvalidArgumentException |
|
363 | + * @throws InvalidDataTypeException |
|
364 | + * @throws InvalidInterfaceException |
|
365 | + * @throws ReflectionException |
|
366 | + */ |
|
367 | + public function unit_price() |
|
368 | + { |
|
369 | + return $this->get('LIN_unit_price'); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Sets unit_price |
|
375 | + * |
|
376 | + * @param float $unit_price |
|
377 | + * @throws EE_Error |
|
378 | + * @throws InvalidArgumentException |
|
379 | + * @throws InvalidDataTypeException |
|
380 | + * @throws InvalidInterfaceException |
|
381 | + * @throws ReflectionException |
|
382 | + */ |
|
383 | + public function set_unit_price($unit_price) |
|
384 | + { |
|
385 | + $this->set('LIN_unit_price', $unit_price); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Checks if this item is a percentage modifier or not |
|
391 | + * |
|
392 | + * @return boolean |
|
393 | + * @throws EE_Error |
|
394 | + * @throws InvalidArgumentException |
|
395 | + * @throws InvalidDataTypeException |
|
396 | + * @throws InvalidInterfaceException |
|
397 | + * @throws ReflectionException |
|
398 | + */ |
|
399 | + public function is_percent() |
|
400 | + { |
|
401 | + if ($this->is_tax_sub_total()) { |
|
402 | + // tax subtotals HAVE a percent on them, that percentage only applies |
|
403 | + // to taxable items, so its' an exception. Treat it like a flat line item |
|
404 | + return false; |
|
405 | + } |
|
406 | + $unit_price = abs($this->get('LIN_unit_price')); |
|
407 | + $percent = abs($this->get('LIN_percent')); |
|
408 | + if ($unit_price < .001 && $percent) { |
|
409 | + return true; |
|
410 | + } |
|
411 | + if ($unit_price >= .001 && ! $percent) { |
|
412 | + return false; |
|
413 | + } |
|
414 | + if ($unit_price >= .001 && $percent) { |
|
415 | + throw new EE_Error( |
|
416 | + sprintf( |
|
417 | + esc_html__( |
|
418 | + 'A Line Item can not have a unit price of (%s) AND a percent (%s)!', |
|
419 | + 'event_espresso' |
|
420 | + ), |
|
421 | + $unit_price, |
|
422 | + $percent |
|
423 | + ) |
|
424 | + ); |
|
425 | + } |
|
426 | + // if they're both 0, assume its not a percent item |
|
427 | + return false; |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Gets percent (between 100-.001) |
|
433 | + * |
|
434 | + * @return float |
|
435 | + * @throws EE_Error |
|
436 | + * @throws InvalidArgumentException |
|
437 | + * @throws InvalidDataTypeException |
|
438 | + * @throws InvalidInterfaceException |
|
439 | + * @throws ReflectionException |
|
440 | + */ |
|
441 | + public function percent() |
|
442 | + { |
|
443 | + return $this->get('LIN_percent'); |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * @return string |
|
449 | + * @throws EE_Error |
|
450 | + * @throws ReflectionException |
|
451 | + * @since $VID:$ |
|
452 | + */ |
|
453 | + public function prettyPercent(): string |
|
454 | + { |
|
455 | + return $this->get_pretty('LIN_percent'); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Sets percent (between 100-0.01) |
|
461 | + * |
|
462 | + * @param float $percent |
|
463 | + * @throws EE_Error |
|
464 | + * @throws InvalidArgumentException |
|
465 | + * @throws InvalidDataTypeException |
|
466 | + * @throws InvalidInterfaceException |
|
467 | + * @throws ReflectionException |
|
468 | + */ |
|
469 | + public function set_percent($percent) |
|
470 | + { |
|
471 | + $this->set('LIN_percent', $percent); |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * Gets total |
|
477 | + * |
|
478 | + * @return float |
|
479 | + * @throws EE_Error |
|
480 | + * @throws InvalidArgumentException |
|
481 | + * @throws InvalidDataTypeException |
|
482 | + * @throws InvalidInterfaceException |
|
483 | + * @throws ReflectionException |
|
484 | + */ |
|
485 | + public function pretaxTotal(): float |
|
486 | + { |
|
487 | + return (float) $this->get('LIN_pretax'); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * Sets total |
|
493 | + * |
|
494 | + * @param float $pretax_total |
|
495 | + * @throws EE_Error |
|
496 | + * @throws InvalidArgumentException |
|
497 | + * @throws InvalidDataTypeException |
|
498 | + * @throws InvalidInterfaceException |
|
499 | + * @throws ReflectionException |
|
500 | + */ |
|
501 | + public function setPretaxTotal(float $pretax_total) |
|
502 | + { |
|
503 | + $this->set('LIN_pretax', $pretax_total); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * @return float |
|
509 | + * @throws EE_Error |
|
510 | + * @throws ReflectionException |
|
511 | + * @since $VID:$ |
|
512 | + */ |
|
513 | + public function totalWithTax(): float |
|
514 | + { |
|
515 | + return (float) $this->get('LIN_total'); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * Sets total |
|
521 | + * |
|
522 | + * @param float $total |
|
523 | + * @throws EE_Error |
|
524 | + * @throws ReflectionException |
|
525 | + * @since $VID:$ |
|
526 | + */ |
|
527 | + public function setTotalWithTax(float $total) |
|
528 | + { |
|
529 | + $this->set('LIN_total', $total); |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + /** |
|
534 | + * Gets total |
|
535 | + * |
|
536 | + * @return float |
|
537 | + * @throws EE_Error |
|
538 | + * @throws ReflectionException |
|
539 | + * @deprecatd $VID:$ |
|
540 | + */ |
|
541 | + public function total(): float |
|
542 | + { |
|
543 | + return $this->totalWithTax(); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * Sets total |
|
549 | + * |
|
550 | + * @param float $total |
|
551 | + * @throws EE_Error |
|
552 | + * @throws ReflectionException |
|
553 | + * @deprecatd $VID:$ |
|
554 | + */ |
|
555 | + public function set_total($total) |
|
556 | + { |
|
557 | + $this->setTotalWithTax($total); |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * Gets order |
|
563 | + * |
|
564 | + * @return int |
|
565 | + * @throws EE_Error |
|
566 | + * @throws InvalidArgumentException |
|
567 | + * @throws InvalidDataTypeException |
|
568 | + * @throws InvalidInterfaceException |
|
569 | + * @throws ReflectionException |
|
570 | + */ |
|
571 | + public function order() |
|
572 | + { |
|
573 | + return $this->get('LIN_order'); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Sets order |
|
579 | + * |
|
580 | + * @param int $order |
|
581 | + * @throws EE_Error |
|
582 | + * @throws InvalidArgumentException |
|
583 | + * @throws InvalidDataTypeException |
|
584 | + * @throws InvalidInterfaceException |
|
585 | + * @throws ReflectionException |
|
586 | + */ |
|
587 | + public function set_order($order) |
|
588 | + { |
|
589 | + $this->set('LIN_order', $order); |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * Gets parent |
|
595 | + * |
|
596 | + * @return int |
|
597 | + * @throws EE_Error |
|
598 | + * @throws InvalidArgumentException |
|
599 | + * @throws InvalidDataTypeException |
|
600 | + * @throws InvalidInterfaceException |
|
601 | + * @throws ReflectionException |
|
602 | + */ |
|
603 | + public function parent_ID() |
|
604 | + { |
|
605 | + return $this->get('LIN_parent'); |
|
606 | + } |
|
607 | + |
|
608 | + |
|
609 | + /** |
|
610 | + * Sets parent |
|
611 | + * |
|
612 | + * @param int $parent |
|
613 | + * @throws EE_Error |
|
614 | + * @throws InvalidArgumentException |
|
615 | + * @throws InvalidDataTypeException |
|
616 | + * @throws InvalidInterfaceException |
|
617 | + * @throws ReflectionException |
|
618 | + */ |
|
619 | + public function set_parent_ID($parent) |
|
620 | + { |
|
621 | + $this->set('LIN_parent', $parent); |
|
622 | + } |
|
623 | + |
|
624 | + |
|
625 | + /** |
|
626 | + * Gets type |
|
627 | + * |
|
628 | + * @return string |
|
629 | + * @throws EE_Error |
|
630 | + * @throws InvalidArgumentException |
|
631 | + * @throws InvalidDataTypeException |
|
632 | + * @throws InvalidInterfaceException |
|
633 | + * @throws ReflectionException |
|
634 | + */ |
|
635 | + public function type() |
|
636 | + { |
|
637 | + return $this->get('LIN_type'); |
|
638 | + } |
|
639 | + |
|
640 | + |
|
641 | + /** |
|
642 | + * Sets type |
|
643 | + * |
|
644 | + * @param string $type |
|
645 | + * @throws EE_Error |
|
646 | + * @throws InvalidArgumentException |
|
647 | + * @throws InvalidDataTypeException |
|
648 | + * @throws InvalidInterfaceException |
|
649 | + * @throws ReflectionException |
|
650 | + */ |
|
651 | + public function set_type($type) |
|
652 | + { |
|
653 | + $this->set('LIN_type', $type); |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + /** |
|
658 | + * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\ |
|
659 | + * If this line item is saved to the DB, fetches the parent from the DB. However, if this line item isn't in the DB |
|
660 | + * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()` |
|
661 | + * or indirectly by `EE_Line_item::add_child_line_item()`) |
|
662 | + * |
|
663 | + * @return EE_Base_Class|EE_Line_Item |
|
664 | + * @throws EE_Error |
|
665 | + * @throws InvalidArgumentException |
|
666 | + * @throws InvalidDataTypeException |
|
667 | + * @throws InvalidInterfaceException |
|
668 | + * @throws ReflectionException |
|
669 | + */ |
|
670 | + public function parent() |
|
671 | + { |
|
672 | + return $this->ID() |
|
673 | + ? $this->get_model()->get_one_by_ID($this->parent_ID()) |
|
674 | + : $this->_parent; |
|
675 | + } |
|
676 | + |
|
677 | + |
|
678 | + /** |
|
679 | + * Gets ALL the children of this line item (ie, all the parts that contribute towards this total). |
|
680 | + * |
|
681 | + * @return EE_Line_Item[] |
|
682 | + * @throws EE_Error |
|
683 | + * @throws InvalidArgumentException |
|
684 | + * @throws InvalidDataTypeException |
|
685 | + * @throws InvalidInterfaceException |
|
686 | + * @throws ReflectionException |
|
687 | + */ |
|
688 | + public function children(array $query_params = []): array |
|
689 | + { |
|
690 | + if ($this->ID()) { |
|
691 | + // ensure where params are an array |
|
692 | + $query_params[0] = $query_params[0] ?? []; |
|
693 | + // add defaults for line item parent and orderby |
|
694 | + $query_params[0] += ['LIN_parent' => $this->ID()]; |
|
695 | + $query_params += ['order_by' => ['LIN_order' => 'ASC']]; |
|
696 | + return $this->get_model()->get_all($query_params); |
|
697 | + } |
|
698 | + if (! is_array($this->_children)) { |
|
699 | + $this->_children = array(); |
|
700 | + } |
|
701 | + return $this->_children; |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + /** |
|
706 | + * Gets code |
|
707 | + * |
|
708 | + * @return string |
|
709 | + * @throws EE_Error |
|
710 | + * @throws InvalidArgumentException |
|
711 | + * @throws InvalidDataTypeException |
|
712 | + * @throws InvalidInterfaceException |
|
713 | + * @throws ReflectionException |
|
714 | + */ |
|
715 | + public function code() |
|
716 | + { |
|
717 | + return $this->get('LIN_code'); |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + /** |
|
722 | + * Sets code |
|
723 | + * |
|
724 | + * @param string $code |
|
725 | + * @throws EE_Error |
|
726 | + * @throws InvalidArgumentException |
|
727 | + * @throws InvalidDataTypeException |
|
728 | + * @throws InvalidInterfaceException |
|
729 | + * @throws ReflectionException |
|
730 | + */ |
|
731 | + public function set_code($code) |
|
732 | + { |
|
733 | + $this->set('LIN_code', $code); |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + /** |
|
738 | + * Gets is_taxable |
|
739 | + * |
|
740 | + * @return boolean |
|
741 | + * @throws EE_Error |
|
742 | + * @throws InvalidArgumentException |
|
743 | + * @throws InvalidDataTypeException |
|
744 | + * @throws InvalidInterfaceException |
|
745 | + * @throws ReflectionException |
|
746 | + */ |
|
747 | + public function is_taxable() |
|
748 | + { |
|
749 | + return $this->get('LIN_is_taxable'); |
|
750 | + } |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * Sets is_taxable |
|
755 | + * |
|
756 | + * @param boolean $is_taxable |
|
757 | + * @throws EE_Error |
|
758 | + * @throws InvalidArgumentException |
|
759 | + * @throws InvalidDataTypeException |
|
760 | + * @throws InvalidInterfaceException |
|
761 | + * @throws ReflectionException |
|
762 | + */ |
|
763 | + public function set_is_taxable($is_taxable) |
|
764 | + { |
|
765 | + $this->set('LIN_is_taxable', $is_taxable); |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * @param int $timestamp |
|
771 | + * @throws EE_Error |
|
772 | + * @throws ReflectionException |
|
773 | + * @since $VID:$ |
|
774 | + */ |
|
775 | + public function setTimestamp(int $timestamp) |
|
776 | + { |
|
777 | + $this->set('LIN_timestamp', $timestamp); |
|
778 | + } |
|
779 | + |
|
780 | + |
|
781 | + /** |
|
782 | + * Gets the object that this model-joins-to. |
|
783 | + * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on |
|
784 | + * EEM_Promotion_Object |
|
785 | + * Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object |
|
786 | + * |
|
787 | + * @return EE_Base_Class | NULL |
|
788 | + * @throws EE_Error |
|
789 | + * @throws InvalidArgumentException |
|
790 | + * @throws InvalidDataTypeException |
|
791 | + * @throws InvalidInterfaceException |
|
792 | + * @throws ReflectionException |
|
793 | + */ |
|
794 | + public function get_object() |
|
795 | + { |
|
796 | + $model_name_of_related_obj = $this->OBJ_type(); |
|
797 | + return $this->get_model()->has_relation($model_name_of_related_obj) |
|
798 | + ? $this->get_first_related($model_name_of_related_obj) |
|
799 | + : null; |
|
800 | + } |
|
801 | + |
|
802 | + |
|
803 | + /** |
|
804 | + * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket. |
|
805 | + * (IE, if this line item is for a price or something else, will return NULL) |
|
806 | + * |
|
807 | + * @param array $query_params |
|
808 | + * @return EE_Base_Class|EE_Ticket |
|
809 | + * @throws EE_Error |
|
810 | + * @throws InvalidArgumentException |
|
811 | + * @throws InvalidDataTypeException |
|
812 | + * @throws InvalidInterfaceException |
|
813 | + * @throws ReflectionException |
|
814 | + */ |
|
815 | + public function ticket($query_params = array()) |
|
816 | + { |
|
817 | + // we're going to assume that when this method is called |
|
818 | + // we always want to receive the attached ticket EVEN if that ticket is archived. |
|
819 | + // This can be overridden via the incoming $query_params argument |
|
820 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
821 | + $query_params = array_merge($remove_defaults, $query_params); |
|
822 | + return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TICKET, $query_params); |
|
823 | + } |
|
824 | + |
|
825 | + |
|
826 | + /** |
|
827 | + * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket |
|
828 | + * |
|
829 | + * @return EE_Datetime | NULL |
|
830 | + * @throws EE_Error |
|
831 | + * @throws InvalidArgumentException |
|
832 | + * @throws InvalidDataTypeException |
|
833 | + * @throws InvalidInterfaceException |
|
834 | + * @throws ReflectionException |
|
835 | + */ |
|
836 | + public function get_ticket_datetime() |
|
837 | + { |
|
838 | + if ($this->OBJ_type() === EEM_Line_Item::OBJ_TYPE_TICKET) { |
|
839 | + $ticket = $this->ticket(); |
|
840 | + if ($ticket instanceof EE_Ticket) { |
|
841 | + $datetime = $ticket->first_datetime(); |
|
842 | + if ($datetime instanceof EE_Datetime) { |
|
843 | + return $datetime; |
|
844 | + } |
|
845 | + } |
|
846 | + } |
|
847 | + return null; |
|
848 | + } |
|
849 | + |
|
850 | + |
|
851 | + /** |
|
852 | + * Gets the event's name that's related to the ticket, if this is for |
|
853 | + * a ticket |
|
854 | + * |
|
855 | + * @return string |
|
856 | + * @throws EE_Error |
|
857 | + * @throws InvalidArgumentException |
|
858 | + * @throws InvalidDataTypeException |
|
859 | + * @throws InvalidInterfaceException |
|
860 | + * @throws ReflectionException |
|
861 | + */ |
|
862 | + public function ticket_event_name() |
|
863 | + { |
|
864 | + $event_name = esc_html__('Unknown', 'event_espresso'); |
|
865 | + $event = $this->ticket_event(); |
|
866 | + if ($event instanceof EE_Event) { |
|
867 | + $event_name = $event->name(); |
|
868 | + } |
|
869 | + return $event_name; |
|
870 | + } |
|
871 | + |
|
872 | + |
|
873 | + /** |
|
874 | + * Gets the event that's related to the ticket, if this line item represents a ticket. |
|
875 | + * |
|
876 | + * @return EE_Event|null |
|
877 | + * @throws EE_Error |
|
878 | + * @throws InvalidArgumentException |
|
879 | + * @throws InvalidDataTypeException |
|
880 | + * @throws InvalidInterfaceException |
|
881 | + * @throws ReflectionException |
|
882 | + */ |
|
883 | + public function ticket_event() |
|
884 | + { |
|
885 | + $event = null; |
|
886 | + $ticket = $this->ticket(); |
|
887 | + if ($ticket instanceof EE_Ticket) { |
|
888 | + $datetime = $ticket->first_datetime(); |
|
889 | + if ($datetime instanceof EE_Datetime) { |
|
890 | + $event = $datetime->event(); |
|
891 | + } |
|
892 | + } |
|
893 | + return $event; |
|
894 | + } |
|
895 | + |
|
896 | + |
|
897 | + /** |
|
898 | + * Gets the first datetime for this lien item, assuming it's for a ticket |
|
899 | + * |
|
900 | + * @param string $date_format |
|
901 | + * @param string $time_format |
|
902 | + * @return string |
|
903 | + * @throws EE_Error |
|
904 | + * @throws InvalidArgumentException |
|
905 | + * @throws InvalidDataTypeException |
|
906 | + * @throws InvalidInterfaceException |
|
907 | + * @throws ReflectionException |
|
908 | + */ |
|
909 | + public function ticket_datetime_start($date_format = '', $time_format = '') |
|
910 | + { |
|
911 | + $first_datetime_string = esc_html__('Unknown', 'event_espresso'); |
|
912 | + $datetime = $this->get_ticket_datetime(); |
|
913 | + if ($datetime) { |
|
914 | + $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
915 | + } |
|
916 | + return $first_datetime_string; |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * Adds the line item as a child to this line item. If there is another child line |
|
922 | + * item with the same LIN_code, it is overwritten by this new one |
|
923 | + * |
|
924 | + * @param EE_Line_Item $line_item |
|
925 | + * @param bool $set_order |
|
926 | + * @return bool success |
|
927 | + * @throws EE_Error |
|
928 | + * @throws InvalidArgumentException |
|
929 | + * @throws InvalidDataTypeException |
|
930 | + * @throws InvalidInterfaceException |
|
931 | + * @throws ReflectionException |
|
932 | + */ |
|
933 | + public function add_child_line_item(EE_Line_Item $line_item, $set_order = true) |
|
934 | + { |
|
935 | + // should we calculate the LIN_order for this line item ? |
|
936 | + if ($set_order || $line_item->order() === null) { |
|
937 | + $line_item->set_order(count($this->children())); |
|
938 | + } |
|
939 | + if ($this->ID()) { |
|
940 | + // check for any duplicate line items (with the same code), if so, this replaces it |
|
941 | + $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
942 | + if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
943 | + $this->delete_child_line_item($line_item_with_same_code->code()); |
|
944 | + } |
|
945 | + $line_item->set_parent_ID($this->ID()); |
|
946 | + if ($this->TXN_ID()) { |
|
947 | + $line_item->set_TXN_ID($this->TXN_ID()); |
|
948 | + } |
|
949 | + return $line_item->save(); |
|
950 | + } |
|
951 | + $this->_children[ $line_item->code() ] = $line_item; |
|
952 | + if ($line_item->parent() !== $this) { |
|
953 | + $line_item->set_parent($this); |
|
954 | + } |
|
955 | + return true; |
|
956 | + } |
|
957 | + |
|
958 | + |
|
959 | + /** |
|
960 | + * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation. |
|
961 | + * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save() |
|
962 | + * However, if this line item is NOT saved to the DB, this just caches the parent on |
|
963 | + * the EE_Line_Item::_parent property. |
|
964 | + * |
|
965 | + * @param EE_Line_Item $line_item |
|
966 | + * @throws EE_Error |
|
967 | + * @throws InvalidArgumentException |
|
968 | + * @throws InvalidDataTypeException |
|
969 | + * @throws InvalidInterfaceException |
|
970 | + * @throws ReflectionException |
|
971 | + */ |
|
972 | + public function set_parent($line_item) |
|
973 | + { |
|
974 | + if ($this->ID()) { |
|
975 | + if (! $line_item->ID()) { |
|
976 | + $line_item->save(); |
|
977 | + } |
|
978 | + $this->set_parent_ID($line_item->ID()); |
|
979 | + $this->save(); |
|
980 | + } else { |
|
981 | + $this->_parent = $line_item; |
|
982 | + $this->set_parent_ID($line_item->ID()); |
|
983 | + } |
|
984 | + } |
|
985 | + |
|
986 | + |
|
987 | + /** |
|
988 | + * Gets the child line item as specified by its code. Because this returns an object (by reference) |
|
989 | + * you can modify this child line item and the parent (this object) can know about them |
|
990 | + * because it also has a reference to that line item |
|
991 | + * |
|
992 | + * @param string $code |
|
993 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
994 | + * @throws EE_Error |
|
995 | + * @throws InvalidArgumentException |
|
996 | + * @throws InvalidDataTypeException |
|
997 | + * @throws InvalidInterfaceException |
|
998 | + * @throws ReflectionException |
|
999 | + */ |
|
1000 | + public function get_child_line_item($code) |
|
1001 | + { |
|
1002 | + if ($this->ID()) { |
|
1003 | + return $this->get_model()->get_one( |
|
1004 | + array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code)) |
|
1005 | + ); |
|
1006 | + } |
|
1007 | + return isset($this->_children[ $code ]) |
|
1008 | + ? $this->_children[ $code ] |
|
1009 | + : null; |
|
1010 | + } |
|
1011 | + |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD |
|
1015 | + * cached on it) |
|
1016 | + * |
|
1017 | + * @return int |
|
1018 | + * @throws EE_Error |
|
1019 | + * @throws InvalidArgumentException |
|
1020 | + * @throws InvalidDataTypeException |
|
1021 | + * @throws InvalidInterfaceException |
|
1022 | + * @throws ReflectionException |
|
1023 | + */ |
|
1024 | + public function delete_children_line_items() |
|
1025 | + { |
|
1026 | + if ($this->ID()) { |
|
1027 | + return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
1028 | + } |
|
1029 | + $count = count($this->_children); |
|
1030 | + $this->_children = array(); |
|
1031 | + return $count; |
|
1032 | + } |
|
1033 | + |
|
1034 | + |
|
1035 | + /** |
|
1036 | + * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
|
1037 | + * HAS NOT been saved to the DB, removes the child line item with index $code. |
|
1038 | + * Also searches through the child's children for a matching line item. However, once a line item has been found |
|
1039 | + * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be |
|
1040 | + * deleted) |
|
1041 | + * |
|
1042 | + * @param string $code |
|
1043 | + * @param bool $stop_search_once_found |
|
1044 | + * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to |
|
1045 | + * the DB yet) |
|
1046 | + * @throws EE_Error |
|
1047 | + * @throws InvalidArgumentException |
|
1048 | + * @throws InvalidDataTypeException |
|
1049 | + * @throws InvalidInterfaceException |
|
1050 | + * @throws ReflectionException |
|
1051 | + */ |
|
1052 | + public function delete_child_line_item($code, $stop_search_once_found = true) |
|
1053 | + { |
|
1054 | + if ($this->ID()) { |
|
1055 | + $items_deleted = 0; |
|
1056 | + if ($this->code() === $code) { |
|
1057 | + $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
1058 | + $items_deleted += (int) $this->delete(); |
|
1059 | + if ($stop_search_once_found) { |
|
1060 | + return $items_deleted; |
|
1061 | + } |
|
1062 | + } |
|
1063 | + foreach ($this->children() as $child_line_item) { |
|
1064 | + $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
1065 | + } |
|
1066 | + return $items_deleted; |
|
1067 | + } |
|
1068 | + if (isset($this->_children[ $code ])) { |
|
1069 | + unset($this->_children[ $code ]); |
|
1070 | + return 1; |
|
1071 | + } |
|
1072 | + return 0; |
|
1073 | + } |
|
1074 | + |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * If this line item is in the database, is of the type subtotal, and |
|
1078 | + * has no children, why do we have it? It should be deleted so this function |
|
1079 | + * does that |
|
1080 | + * |
|
1081 | + * @return boolean |
|
1082 | + * @throws EE_Error |
|
1083 | + * @throws InvalidArgumentException |
|
1084 | + * @throws InvalidDataTypeException |
|
1085 | + * @throws InvalidInterfaceException |
|
1086 | + * @throws ReflectionException |
|
1087 | + */ |
|
1088 | + public function delete_if_childless_subtotal() |
|
1089 | + { |
|
1090 | + if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) { |
|
1091 | + return $this->delete(); |
|
1092 | + } |
|
1093 | + return false; |
|
1094 | + } |
|
1095 | + |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * Creates a code and returns a string. doesn't assign the code to this model object |
|
1099 | + * |
|
1100 | + * @return string |
|
1101 | + * @throws EE_Error |
|
1102 | + * @throws InvalidArgumentException |
|
1103 | + * @throws InvalidDataTypeException |
|
1104 | + * @throws InvalidInterfaceException |
|
1105 | + * @throws ReflectionException |
|
1106 | + */ |
|
1107 | + public function generate_code() |
|
1108 | + { |
|
1109 | + // each line item in the cart requires a unique identifier |
|
1110 | + return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime()); |
|
1111 | + } |
|
1112 | + |
|
1113 | + |
|
1114 | + /** |
|
1115 | + * @return bool |
|
1116 | + * @throws EE_Error |
|
1117 | + * @throws InvalidArgumentException |
|
1118 | + * @throws InvalidDataTypeException |
|
1119 | + * @throws InvalidInterfaceException |
|
1120 | + * @throws ReflectionException |
|
1121 | + */ |
|
1122 | + public function isGlobalTax(): bool |
|
1123 | + { |
|
1124 | + return $this->type() === EEM_Line_Item::type_tax; |
|
1125 | + } |
|
1126 | + |
|
1127 | + |
|
1128 | + /** |
|
1129 | + * @return bool |
|
1130 | + * @throws EE_Error |
|
1131 | + * @throws InvalidArgumentException |
|
1132 | + * @throws InvalidDataTypeException |
|
1133 | + * @throws InvalidInterfaceException |
|
1134 | + * @throws ReflectionException |
|
1135 | + */ |
|
1136 | + public function isSubTax(): bool |
|
1137 | + { |
|
1138 | + return $this->type() === EEM_Line_Item::type_sub_tax; |
|
1139 | + } |
|
1140 | + |
|
1141 | + |
|
1142 | + /** |
|
1143 | + * returns true if this is a line item with a direct descendent of the type sub-tax |
|
1144 | + * |
|
1145 | + * @return array |
|
1146 | + * @throws EE_Error |
|
1147 | + * @throws InvalidArgumentException |
|
1148 | + * @throws InvalidDataTypeException |
|
1149 | + * @throws InvalidInterfaceException |
|
1150 | + * @throws ReflectionException |
|
1151 | + */ |
|
1152 | + public function getSubTaxes(): array |
|
1153 | + { |
|
1154 | + if (! $this->is_line_item()) { |
|
1155 | + return []; |
|
1156 | + } |
|
1157 | + return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_sub_tax); |
|
1158 | + } |
|
1159 | + |
|
1160 | + |
|
1161 | + /** |
|
1162 | + * returns true if this is a line item with a direct descendent of the type sub-tax |
|
1163 | + * |
|
1164 | + * @return bool |
|
1165 | + * @throws EE_Error |
|
1166 | + * @throws InvalidArgumentException |
|
1167 | + * @throws InvalidDataTypeException |
|
1168 | + * @throws InvalidInterfaceException |
|
1169 | + * @throws ReflectionException |
|
1170 | + */ |
|
1171 | + public function hasSubTaxes(): bool |
|
1172 | + { |
|
1173 | + if (! $this->is_line_item()) { |
|
1174 | + return false; |
|
1175 | + } |
|
1176 | + $sub_taxes = $this->getSubTaxes(); |
|
1177 | + return ! empty($sub_taxes); |
|
1178 | + } |
|
1179 | + |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * @return bool |
|
1183 | + * @throws EE_Error |
|
1184 | + * @throws ReflectionException |
|
1185 | + * @deprecated $VID:$ |
|
1186 | + */ |
|
1187 | + public function is_tax(): bool |
|
1188 | + { |
|
1189 | + return $this->isGlobalTax(); |
|
1190 | + } |
|
1191 | + |
|
1192 | + |
|
1193 | + /** |
|
1194 | + * @return bool |
|
1195 | + * @throws EE_Error |
|
1196 | + * @throws InvalidArgumentException |
|
1197 | + * @throws InvalidDataTypeException |
|
1198 | + * @throws InvalidInterfaceException |
|
1199 | + * @throws ReflectionException |
|
1200 | + */ |
|
1201 | + public function is_tax_sub_total() |
|
1202 | + { |
|
1203 | + return $this->type() === EEM_Line_Item::type_tax_sub_total; |
|
1204 | + } |
|
1205 | + |
|
1206 | + |
|
1207 | + /** |
|
1208 | + * @return bool |
|
1209 | + * @throws EE_Error |
|
1210 | + * @throws InvalidArgumentException |
|
1211 | + * @throws InvalidDataTypeException |
|
1212 | + * @throws InvalidInterfaceException |
|
1213 | + * @throws ReflectionException |
|
1214 | + */ |
|
1215 | + public function is_line_item() |
|
1216 | + { |
|
1217 | + return $this->type() === EEM_Line_Item::type_line_item; |
|
1218 | + } |
|
1219 | + |
|
1220 | + |
|
1221 | + /** |
|
1222 | + * @return bool |
|
1223 | + * @throws EE_Error |
|
1224 | + * @throws InvalidArgumentException |
|
1225 | + * @throws InvalidDataTypeException |
|
1226 | + * @throws InvalidInterfaceException |
|
1227 | + * @throws ReflectionException |
|
1228 | + */ |
|
1229 | + public function is_sub_line_item() |
|
1230 | + { |
|
1231 | + return $this->type() === EEM_Line_Item::type_sub_line_item; |
|
1232 | + } |
|
1233 | + |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * @return bool |
|
1237 | + * @throws EE_Error |
|
1238 | + * @throws InvalidArgumentException |
|
1239 | + * @throws InvalidDataTypeException |
|
1240 | + * @throws InvalidInterfaceException |
|
1241 | + * @throws ReflectionException |
|
1242 | + */ |
|
1243 | + public function is_sub_total() |
|
1244 | + { |
|
1245 | + return $this->type() === EEM_Line_Item::type_sub_total; |
|
1246 | + } |
|
1247 | + |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * Whether or not this line item is a cancellation line item |
|
1251 | + * |
|
1252 | + * @return boolean |
|
1253 | + * @throws EE_Error |
|
1254 | + * @throws InvalidArgumentException |
|
1255 | + * @throws InvalidDataTypeException |
|
1256 | + * @throws InvalidInterfaceException |
|
1257 | + * @throws ReflectionException |
|
1258 | + */ |
|
1259 | + public function is_cancellation() |
|
1260 | + { |
|
1261 | + return EEM_Line_Item::type_cancellation === $this->type(); |
|
1262 | + } |
|
1263 | + |
|
1264 | + |
|
1265 | + /** |
|
1266 | + * @return bool |
|
1267 | + * @throws EE_Error |
|
1268 | + * @throws InvalidArgumentException |
|
1269 | + * @throws InvalidDataTypeException |
|
1270 | + * @throws InvalidInterfaceException |
|
1271 | + * @throws ReflectionException |
|
1272 | + */ |
|
1273 | + public function is_total() |
|
1274 | + { |
|
1275 | + return $this->type() === EEM_Line_Item::type_total; |
|
1276 | + } |
|
1277 | + |
|
1278 | + |
|
1279 | + /** |
|
1280 | + * @return bool |
|
1281 | + * @throws EE_Error |
|
1282 | + * @throws InvalidArgumentException |
|
1283 | + * @throws InvalidDataTypeException |
|
1284 | + * @throws InvalidInterfaceException |
|
1285 | + * @throws ReflectionException |
|
1286 | + */ |
|
1287 | + public function is_cancelled() |
|
1288 | + { |
|
1289 | + return $this->type() === EEM_Line_Item::type_cancellation; |
|
1290 | + } |
|
1291 | + |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * @return string like '2, 004.00', formatted according to the localized currency |
|
1295 | + * @throws EE_Error |
|
1296 | + * @throws ReflectionException |
|
1297 | + */ |
|
1298 | + public function unit_price_no_code(): string |
|
1299 | + { |
|
1300 | + return $this->prettyUnitPrice(); |
|
1301 | + } |
|
1302 | + |
|
1303 | + |
|
1304 | + /** |
|
1305 | + * @return string like '2, 004.00', formatted according to the localized currency |
|
1306 | + * @throws EE_Error |
|
1307 | + * @throws ReflectionException |
|
1308 | + * @since $VID:$ |
|
1309 | + */ |
|
1310 | + public function prettyUnitPrice(): string |
|
1311 | + { |
|
1312 | + return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
1313 | + } |
|
1314 | + |
|
1315 | + |
|
1316 | + /** |
|
1317 | + * @return string like '2, 004.00', formatted according to the localized currency |
|
1318 | + * @throws EE_Error |
|
1319 | + * @throws ReflectionException |
|
1320 | + */ |
|
1321 | + public function total_no_code(): string |
|
1322 | + { |
|
1323 | + return $this->prettyTotal(); |
|
1324 | + } |
|
1325 | + |
|
1326 | + |
|
1327 | + /** |
|
1328 | + * @return string like '2, 004.00', formatted according to the localized currency |
|
1329 | + * @throws EE_Error |
|
1330 | + * @throws ReflectionException |
|
1331 | + * @since $VID:$ |
|
1332 | + */ |
|
1333 | + public function prettyTotal(): string |
|
1334 | + { |
|
1335 | + return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
1336 | + } |
|
1337 | + |
|
1338 | + |
|
1339 | + /** |
|
1340 | + * Gets the final total on this item, taking taxes into account. |
|
1341 | + * Has the side-effect of setting the sub-total as it was just calculated. |
|
1342 | + * If this is used on a grand-total line item, also updates the transaction's |
|
1343 | + * TXN_total (provided this line item is allowed to persist, otherwise we don't |
|
1344 | + * want to change a persistable transaction with info from a non-persistent line item) |
|
1345 | + * |
|
1346 | + * @param bool $update_txn_status |
|
1347 | + * @return float |
|
1348 | + * @throws EE_Error |
|
1349 | + * @throws InvalidArgumentException |
|
1350 | + * @throws InvalidDataTypeException |
|
1351 | + * @throws InvalidInterfaceException |
|
1352 | + * @throws ReflectionException |
|
1353 | + * @throws RuntimeException |
|
1354 | + */ |
|
1355 | + public function recalculate_total_including_taxes(bool $update_txn_status = false): float |
|
1356 | + { |
|
1357 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($this); |
|
1358 | + return $this->calculator->recalculateTotalIncludingTaxes($grand_total_line_item, $update_txn_status); |
|
1359 | + } |
|
1360 | + |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * Recursively goes through all the children and recalculates sub-totals EXCEPT for |
|
1364 | + * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its |
|
1365 | + * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and |
|
1366 | + * when this is called on the grand total |
|
1367 | + * |
|
1368 | + * @return float |
|
1369 | + * @throws EE_Error |
|
1370 | + * @throws InvalidArgumentException |
|
1371 | + * @throws InvalidDataTypeException |
|
1372 | + * @throws InvalidInterfaceException |
|
1373 | + * @throws ReflectionException |
|
1374 | + */ |
|
1375 | + public function recalculate_pre_tax_total(): float |
|
1376 | + { |
|
1377 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($this); |
|
1378 | + [$total] = $this->calculator->recalculateLineItemTotals($grand_total_line_item); |
|
1379 | + return (float) $total; |
|
1380 | + } |
|
1381 | + |
|
1382 | + |
|
1383 | + /** |
|
1384 | + * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets |
|
1385 | + * the totals on each tax calculated, and returns the final tax total. Re-saves tax line items |
|
1386 | + * and tax sub-total if already in the DB |
|
1387 | + * |
|
1388 | + * @return float |
|
1389 | + * @throws EE_Error |
|
1390 | + * @throws InvalidArgumentException |
|
1391 | + * @throws InvalidDataTypeException |
|
1392 | + * @throws InvalidInterfaceException |
|
1393 | + * @throws ReflectionException |
|
1394 | + */ |
|
1395 | + public function recalculate_taxes_and_tax_total(): float |
|
1396 | + { |
|
1397 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($this); |
|
1398 | + return $this->calculator->recalculateTaxesAndTaxTotal($grand_total_line_item); |
|
1399 | + } |
|
1400 | + |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * Gets the total tax on this line item. Assumes taxes have already been calculated using |
|
1404 | + * recalculate_taxes_and_total |
|
1405 | + * |
|
1406 | + * @return float |
|
1407 | + * @throws EE_Error |
|
1408 | + * @throws InvalidArgumentException |
|
1409 | + * @throws InvalidDataTypeException |
|
1410 | + * @throws InvalidInterfaceException |
|
1411 | + * @throws ReflectionException |
|
1412 | + */ |
|
1413 | + public function get_total_tax() |
|
1414 | + { |
|
1415 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($this); |
|
1416 | + return $this->calculator->recalculateTaxesAndTaxTotal($grand_total_line_item); |
|
1417 | + } |
|
1418 | + |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * Gets the total for all the items purchased only |
|
1422 | + * |
|
1423 | + * @return float |
|
1424 | + * @throws EE_Error |
|
1425 | + * @throws InvalidArgumentException |
|
1426 | + * @throws InvalidDataTypeException |
|
1427 | + * @throws InvalidInterfaceException |
|
1428 | + * @throws ReflectionException |
|
1429 | + */ |
|
1430 | + public function get_items_total() |
|
1431 | + { |
|
1432 | + // by default, let's make sure we're consistent with the existing line item |
|
1433 | + if ($this->is_total()) { |
|
1434 | + return $this->pretaxTotal(); |
|
1435 | + } |
|
1436 | + $total = 0; |
|
1437 | + foreach ($this->get_items() as $item) { |
|
1438 | + if ($item instanceof EE_Line_Item) { |
|
1439 | + $total += $item->pretaxTotal(); |
|
1440 | + } |
|
1441 | + } |
|
1442 | + return $total; |
|
1443 | + } |
|
1444 | + |
|
1445 | + |
|
1446 | + /** |
|
1447 | + * Gets all the descendants (ie, children or children of children etc) that |
|
1448 | + * are of the type 'tax' |
|
1449 | + * |
|
1450 | + * @return EE_Line_Item[] |
|
1451 | + * @throws EE_Error |
|
1452 | + */ |
|
1453 | + public function tax_descendants() |
|
1454 | + { |
|
1455 | + return EEH_Line_Item::get_tax_descendants($this); |
|
1456 | + } |
|
1457 | + |
|
1458 | + |
|
1459 | + /** |
|
1460 | + * Gets all the real items purchased which are children of this item |
|
1461 | + * |
|
1462 | + * @return EE_Line_Item[] |
|
1463 | + * @throws EE_Error |
|
1464 | + */ |
|
1465 | + public function get_items() |
|
1466 | + { |
|
1467 | + return EEH_Line_Item::get_line_item_descendants($this); |
|
1468 | + } |
|
1469 | + |
|
1470 | + |
|
1471 | + /** |
|
1472 | + * Returns the amount taxable among this line item's children (or if it has no children, |
|
1473 | + * how much of it is taxable). Does not recalculate totals or subtotals. |
|
1474 | + * If the taxable total is negative, (eg, if none of the tickets were taxable, |
|
1475 | + * but there is a "Taxable" discount), returns 0. |
|
1476 | + * |
|
1477 | + * @return float |
|
1478 | + * @throws EE_Error |
|
1479 | + * @throws InvalidArgumentException |
|
1480 | + * @throws InvalidDataTypeException |
|
1481 | + * @throws InvalidInterfaceException |
|
1482 | + * @throws ReflectionException |
|
1483 | + */ |
|
1484 | + public function taxable_total(): float |
|
1485 | + { |
|
1486 | + return $this->calculator->taxableAmountForGlobalTaxes($this); |
|
1487 | + } |
|
1488 | + |
|
1489 | + |
|
1490 | + /** |
|
1491 | + * Gets the transaction for this line item |
|
1492 | + * |
|
1493 | + * @return EE_Base_Class|EE_Transaction |
|
1494 | + * @throws EE_Error |
|
1495 | + * @throws InvalidArgumentException |
|
1496 | + * @throws InvalidDataTypeException |
|
1497 | + * @throws InvalidInterfaceException |
|
1498 | + * @throws ReflectionException |
|
1499 | + */ |
|
1500 | + public function transaction() |
|
1501 | + { |
|
1502 | + return $this->get_first_related(EEM_Line_Item::OBJ_TYPE_TRANSACTION); |
|
1503 | + } |
|
1504 | + |
|
1505 | + |
|
1506 | + /** |
|
1507 | + * Saves this line item to the DB, and recursively saves its descendants. |
|
1508 | + * Because there currently is no proper parent-child relation on the model, |
|
1509 | + * save_this_and_cached() will NOT save the descendants. |
|
1510 | + * Also sets the transaction on this line item and all its descendants before saving |
|
1511 | + * |
|
1512 | + * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
|
1513 | + * @return int count of items saved |
|
1514 | + * @throws EE_Error |
|
1515 | + * @throws InvalidArgumentException |
|
1516 | + * @throws InvalidDataTypeException |
|
1517 | + * @throws InvalidInterfaceException |
|
1518 | + * @throws ReflectionException |
|
1519 | + */ |
|
1520 | + public function save_this_and_descendants_to_txn($txn_id = null) |
|
1521 | + { |
|
1522 | + $count = 0; |
|
1523 | + if (! $txn_id) { |
|
1524 | + $txn_id = $this->TXN_ID(); |
|
1525 | + } |
|
1526 | + $this->set_TXN_ID($txn_id); |
|
1527 | + $children = $this->children(); |
|
1528 | + $count += $this->save() |
|
1529 | + ? 1 |
|
1530 | + : 0; |
|
1531 | + foreach ($children as $child_line_item) { |
|
1532 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1533 | + $child_line_item->set_parent_ID($this->ID()); |
|
1534 | + $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1535 | + } |
|
1536 | + } |
|
1537 | + return $count; |
|
1538 | + } |
|
1539 | + |
|
1540 | + |
|
1541 | + /** |
|
1542 | + * Saves this line item to the DB, and recursively saves its descendants. |
|
1543 | + * |
|
1544 | + * @return int count of items saved |
|
1545 | + * @throws EE_Error |
|
1546 | + * @throws InvalidArgumentException |
|
1547 | + * @throws InvalidDataTypeException |
|
1548 | + * @throws InvalidInterfaceException |
|
1549 | + * @throws ReflectionException |
|
1550 | + */ |
|
1551 | + public function save_this_and_descendants() |
|
1552 | + { |
|
1553 | + $count = 0; |
|
1554 | + $children = $this->children(); |
|
1555 | + $count += $this->save() |
|
1556 | + ? 1 |
|
1557 | + : 0; |
|
1558 | + foreach ($children as $child_line_item) { |
|
1559 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1560 | + $child_line_item->set_parent_ID($this->ID()); |
|
1561 | + $count += $child_line_item->save_this_and_descendants(); |
|
1562 | + } |
|
1563 | + } |
|
1564 | + return $count; |
|
1565 | + } |
|
1566 | + |
|
1567 | + |
|
1568 | + /** |
|
1569 | + * returns the cancellation line item if this item was cancelled |
|
1570 | + * |
|
1571 | + * @return EE_Line_Item[] |
|
1572 | + * @throws InvalidArgumentException |
|
1573 | + * @throws InvalidInterfaceException |
|
1574 | + * @throws InvalidDataTypeException |
|
1575 | + * @throws ReflectionException |
|
1576 | + * @throws EE_Error |
|
1577 | + */ |
|
1578 | + public function get_cancellations() |
|
1579 | + { |
|
1580 | + return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1581 | + } |
|
1582 | + |
|
1583 | + |
|
1584 | + /** |
|
1585 | + * If this item has an ID, then this saves it again to update the db |
|
1586 | + * |
|
1587 | + * @return int count of items saved |
|
1588 | + * @throws EE_Error |
|
1589 | + * @throws InvalidArgumentException |
|
1590 | + * @throws InvalidDataTypeException |
|
1591 | + * @throws InvalidInterfaceException |
|
1592 | + * @throws ReflectionException |
|
1593 | + */ |
|
1594 | + public function maybe_save() |
|
1595 | + { |
|
1596 | + if ($this->ID()) { |
|
1597 | + return $this->save(); |
|
1598 | + } |
|
1599 | + return false; |
|
1600 | + } |
|
1601 | + |
|
1602 | + |
|
1603 | + /** |
|
1604 | + * clears the cached children and parent from the line item |
|
1605 | + * |
|
1606 | + * @return void |
|
1607 | + */ |
|
1608 | + public function clear_related_line_item_cache() |
|
1609 | + { |
|
1610 | + $this->_children = array(); |
|
1611 | + $this->_parent = null; |
|
1612 | + } |
|
1613 | + |
|
1614 | + |
|
1615 | + /** |
|
1616 | + * @param bool $raw |
|
1617 | + * @return int |
|
1618 | + * @throws EE_Error |
|
1619 | + * @throws InvalidArgumentException |
|
1620 | + * @throws InvalidDataTypeException |
|
1621 | + * @throws InvalidInterfaceException |
|
1622 | + * @throws ReflectionException |
|
1623 | + */ |
|
1624 | + public function timestamp($raw = false) |
|
1625 | + { |
|
1626 | + return $raw |
|
1627 | + ? $this->get_raw('LIN_timestamp') |
|
1628 | + : $this->get('LIN_timestamp'); |
|
1629 | + } |
|
1630 | + |
|
1631 | + |
|
1632 | + |
|
1633 | + |
|
1634 | + /************************* DEPRECATED *************************/ |
|
1635 | + /** |
|
1636 | + * @deprecated 4.6.0 |
|
1637 | + * @param string $type one of the constants on EEM_Line_Item |
|
1638 | + * @return EE_Line_Item[] |
|
1639 | + * @throws EE_Error |
|
1640 | + */ |
|
1641 | + protected function _get_descendants_of_type($type) |
|
1642 | + { |
|
1643 | + EE_Error::doing_it_wrong( |
|
1644 | + 'EE_Line_Item::_get_descendants_of_type()', |
|
1645 | + sprintf( |
|
1646 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1647 | + 'EEH_Line_Item::get_descendants_of_type()' |
|
1648 | + ), |
|
1649 | + '4.6.0' |
|
1650 | + ); |
|
1651 | + return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1652 | + } |
|
1653 | + |
|
1654 | + |
|
1655 | + /** |
|
1656 | + * @deprecated 4.6.0 |
|
1657 | + * @param string $type like one of the EEM_Line_Item::type_* |
|
1658 | + * @return EE_Line_Item |
|
1659 | + * @throws EE_Error |
|
1660 | + * @throws InvalidArgumentException |
|
1661 | + * @throws InvalidDataTypeException |
|
1662 | + * @throws InvalidInterfaceException |
|
1663 | + * @throws ReflectionException |
|
1664 | + */ |
|
1665 | + public function get_nearest_descendant_of_type(string $type): EE_Line_Item |
|
1666 | + { |
|
1667 | + EE_Error::doing_it_wrong( |
|
1668 | + 'EE_Line_Item::get_nearest_descendant_of_type()', |
|
1669 | + sprintf( |
|
1670 | + esc_html__('Method replaced with %1$s', 'event_espresso'), |
|
1671 | + 'EEH_Line_Item::get_nearest_descendant_of_type()' |
|
1672 | + ), |
|
1673 | + '4.6.0' |
|
1674 | + ); |
|
1675 | + return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1676 | + } |
|
1677 | 1677 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | { |
51 | 51 | return [ |
52 | 52 | new GraphQLOutputField( |
53 | - lcfirst($this->namespace) . 'EventRelations', |
|
53 | + lcfirst($this->namespace).'EventRelations', |
|
54 | 54 | 'String', |
55 | 55 | null, |
56 | 56 | esc_html__('JSON encoded relational data of the models', 'event_espresso'), |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | ] |
66 | 66 | ), |
67 | 67 | new GraphQLOutputField( |
68 | - lcfirst($this->namespace) . 'Datetime', |
|
69 | - $this->namespace . 'Datetime', |
|
68 | + lcfirst($this->namespace).'Datetime', |
|
69 | + $this->namespace.'Datetime', |
|
70 | 70 | null, |
71 | 71 | esc_html__('A datetime', 'event_espresso'), |
72 | 72 | null, |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | ] |
83 | 83 | ), |
84 | 84 | new GraphQLOutputField( |
85 | - lcfirst($this->namespace) . 'Ticket', |
|
86 | - $this->namespace . 'Ticket', |
|
85 | + lcfirst($this->namespace).'Ticket', |
|
86 | + $this->namespace.'Ticket', |
|
87 | 87 | null, |
88 | 88 | esc_html__('A ticket', 'event_espresso'), |
89 | 89 | null, |
@@ -31,171 +31,171 @@ |
||
31 | 31 | */ |
32 | 32 | class RootQuery extends TypeBase |
33 | 33 | { |
34 | - /** |
|
35 | - * RootQuery constructor. |
|
36 | - */ |
|
37 | - public function __construct() |
|
38 | - { |
|
39 | - $this->setName('RootQuery'); |
|
40 | - $this->setIsCustomPostType(true); |
|
41 | - parent::__construct(); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return GraphQLFieldInterface[] |
|
47 | - */ |
|
48 | - public function getFields(): array |
|
49 | - { |
|
50 | - return [ |
|
51 | - new GraphQLOutputField( |
|
52 | - lcfirst($this->namespace) . 'EventRelations', |
|
53 | - 'String', |
|
54 | - null, |
|
55 | - esc_html__('JSON encoded relational data of the models', 'event_espresso'), |
|
56 | - null, |
|
57 | - [$this, 'getEventRelationalData'], |
|
58 | - [], |
|
59 | - [ |
|
60 | - 'eventId' => [ |
|
61 | - 'type' => ['non_null' => 'Int'], |
|
62 | - 'description' => esc_html__('The event ID to get the relational data for.', 'event_espresso'), |
|
63 | - ], |
|
64 | - ] |
|
65 | - ), |
|
66 | - new GraphQLOutputField( |
|
67 | - lcfirst($this->namespace) . 'Datetime', |
|
68 | - $this->namespace . 'Datetime', |
|
69 | - null, |
|
70 | - esc_html__('A datetime', 'event_espresso'), |
|
71 | - null, |
|
72 | - [$this, 'getDatetime'], |
|
73 | - [], |
|
74 | - [ |
|
75 | - 'id' => [ |
|
76 | - 'type' => [ |
|
77 | - 'non_null' => 'ID', |
|
78 | - ], |
|
79 | - 'description' => esc_html__('The globally unique identifier of the datetime.', 'event_espresso'), |
|
80 | - ], |
|
81 | - ] |
|
82 | - ), |
|
83 | - new GraphQLOutputField( |
|
84 | - lcfirst($this->namespace) . 'Ticket', |
|
85 | - $this->namespace . 'Ticket', |
|
86 | - null, |
|
87 | - esc_html__('A ticket', 'event_espresso'), |
|
88 | - null, |
|
89 | - [$this, 'getTicket'], |
|
90 | - [], |
|
91 | - [ |
|
92 | - 'id' => [ |
|
93 | - 'type' => [ |
|
94 | - 'non_null' => 'ID', |
|
95 | - ], |
|
96 | - 'description' => esc_html__('The globally unique identifier of the ticket.', 'event_espresso'), |
|
97 | - ], |
|
98 | - ] |
|
99 | - ), |
|
100 | - ]; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
106 | - * @param array $args The inputArgs on the field |
|
107 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
108 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
109 | - * @return string |
|
110 | - * @throws Exception |
|
111 | - * @throws InvalidArgumentException |
|
112 | - * @throws InvalidDataTypeException |
|
113 | - * @throws InvalidInterfaceException |
|
114 | - * @throws UserError |
|
115 | - * @throws UnexpectedEntityException |
|
116 | - * @since $VID:$ |
|
117 | - */ |
|
118 | - public function getEventRelationalData($source, array $args, AppContext $context, ResolveInfo $info): string |
|
119 | - { |
|
120 | - /** |
|
121 | - * Throw an exception if there's no event ID |
|
122 | - */ |
|
123 | - if (empty($args['eventId']) || ! absint($args['eventId'])) { |
|
124 | - throw new UserError(esc_html__( |
|
125 | - 'No event ID was provided to get the relational data for', |
|
126 | - 'event_espresso' |
|
127 | - )); |
|
128 | - } |
|
129 | - |
|
130 | - $eventId = absint($args['eventId']); |
|
131 | - /** @var EventEntityRelations $event_entity_relations */ |
|
132 | - $event_entity_relations = LoaderFactory::getLoader()->getShared( |
|
133 | - 'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations' |
|
134 | - ); |
|
135 | - return json_encode($event_entity_relations->getData($eventId)); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
141 | - * @param array $args The inputArgs on the field |
|
142 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
143 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
144 | - * @return string |
|
145 | - * @throws Exception |
|
146 | - * @throws InvalidArgumentException |
|
147 | - * @throws InvalidDataTypeException |
|
148 | - * @throws InvalidInterfaceException |
|
149 | - * @throws UserError |
|
150 | - * @throws UnexpectedEntityException |
|
151 | - * @since $VID:$ |
|
152 | - */ |
|
153 | - public function getDatetime($source, array $args, AppContext $context, ResolveInfo $info): EE_Datetime |
|
154 | - { |
|
155 | - $parts = Relay::fromGlobalId(sanitize_text_field($args['id'])); |
|
156 | - |
|
157 | - /** |
|
158 | - * Throw an exception if there's no ID |
|
159 | - */ |
|
160 | - if (empty($parts['id'])) { |
|
161 | - throw new UserError(esc_html__( |
|
162 | - 'A missing or invalid ID was received.', |
|
163 | - 'event_espresso' |
|
164 | - )); |
|
165 | - } |
|
166 | - |
|
167 | - return EEM_Datetime::instance()->get_one_by_ID(absint($parts['id'])); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
173 | - * @param array $args The inputArgs on the field |
|
174 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
175 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
176 | - * @return string |
|
177 | - * @throws Exception |
|
178 | - * @throws InvalidArgumentException |
|
179 | - * @throws InvalidDataTypeException |
|
180 | - * @throws InvalidInterfaceException |
|
181 | - * @throws UserError |
|
182 | - * @throws UnexpectedEntityException |
|
183 | - * @since $VID:$ |
|
184 | - */ |
|
185 | - public function getTicket($source, array $args, AppContext $context, ResolveInfo $info): EE_Ticket |
|
186 | - { |
|
187 | - $parts = Relay::fromGlobalId(sanitize_text_field($args['id'])); |
|
188 | - |
|
189 | - /** |
|
190 | - * Throw an exception if there's no ID |
|
191 | - */ |
|
192 | - if (empty($parts['id'])) { |
|
193 | - throw new UserError(esc_html__( |
|
194 | - 'A missing or invalid ID was received.', |
|
195 | - 'event_espresso' |
|
196 | - )); |
|
197 | - } |
|
198 | - |
|
199 | - return EEM_Ticket::instance()->get_one_by_ID(absint($parts['id'])); |
|
200 | - } |
|
34 | + /** |
|
35 | + * RootQuery constructor. |
|
36 | + */ |
|
37 | + public function __construct() |
|
38 | + { |
|
39 | + $this->setName('RootQuery'); |
|
40 | + $this->setIsCustomPostType(true); |
|
41 | + parent::__construct(); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return GraphQLFieldInterface[] |
|
47 | + */ |
|
48 | + public function getFields(): array |
|
49 | + { |
|
50 | + return [ |
|
51 | + new GraphQLOutputField( |
|
52 | + lcfirst($this->namespace) . 'EventRelations', |
|
53 | + 'String', |
|
54 | + null, |
|
55 | + esc_html__('JSON encoded relational data of the models', 'event_espresso'), |
|
56 | + null, |
|
57 | + [$this, 'getEventRelationalData'], |
|
58 | + [], |
|
59 | + [ |
|
60 | + 'eventId' => [ |
|
61 | + 'type' => ['non_null' => 'Int'], |
|
62 | + 'description' => esc_html__('The event ID to get the relational data for.', 'event_espresso'), |
|
63 | + ], |
|
64 | + ] |
|
65 | + ), |
|
66 | + new GraphQLOutputField( |
|
67 | + lcfirst($this->namespace) . 'Datetime', |
|
68 | + $this->namespace . 'Datetime', |
|
69 | + null, |
|
70 | + esc_html__('A datetime', 'event_espresso'), |
|
71 | + null, |
|
72 | + [$this, 'getDatetime'], |
|
73 | + [], |
|
74 | + [ |
|
75 | + 'id' => [ |
|
76 | + 'type' => [ |
|
77 | + 'non_null' => 'ID', |
|
78 | + ], |
|
79 | + 'description' => esc_html__('The globally unique identifier of the datetime.', 'event_espresso'), |
|
80 | + ], |
|
81 | + ] |
|
82 | + ), |
|
83 | + new GraphQLOutputField( |
|
84 | + lcfirst($this->namespace) . 'Ticket', |
|
85 | + $this->namespace . 'Ticket', |
|
86 | + null, |
|
87 | + esc_html__('A ticket', 'event_espresso'), |
|
88 | + null, |
|
89 | + [$this, 'getTicket'], |
|
90 | + [], |
|
91 | + [ |
|
92 | + 'id' => [ |
|
93 | + 'type' => [ |
|
94 | + 'non_null' => 'ID', |
|
95 | + ], |
|
96 | + 'description' => esc_html__('The globally unique identifier of the ticket.', 'event_espresso'), |
|
97 | + ], |
|
98 | + ] |
|
99 | + ), |
|
100 | + ]; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
106 | + * @param array $args The inputArgs on the field |
|
107 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
108 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
109 | + * @return string |
|
110 | + * @throws Exception |
|
111 | + * @throws InvalidArgumentException |
|
112 | + * @throws InvalidDataTypeException |
|
113 | + * @throws InvalidInterfaceException |
|
114 | + * @throws UserError |
|
115 | + * @throws UnexpectedEntityException |
|
116 | + * @since $VID:$ |
|
117 | + */ |
|
118 | + public function getEventRelationalData($source, array $args, AppContext $context, ResolveInfo $info): string |
|
119 | + { |
|
120 | + /** |
|
121 | + * Throw an exception if there's no event ID |
|
122 | + */ |
|
123 | + if (empty($args['eventId']) || ! absint($args['eventId'])) { |
|
124 | + throw new UserError(esc_html__( |
|
125 | + 'No event ID was provided to get the relational data for', |
|
126 | + 'event_espresso' |
|
127 | + )); |
|
128 | + } |
|
129 | + |
|
130 | + $eventId = absint($args['eventId']); |
|
131 | + /** @var EventEntityRelations $event_entity_relations */ |
|
132 | + $event_entity_relations = LoaderFactory::getLoader()->getShared( |
|
133 | + 'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations' |
|
134 | + ); |
|
135 | + return json_encode($event_entity_relations->getData($eventId)); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
141 | + * @param array $args The inputArgs on the field |
|
142 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
143 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
144 | + * @return string |
|
145 | + * @throws Exception |
|
146 | + * @throws InvalidArgumentException |
|
147 | + * @throws InvalidDataTypeException |
|
148 | + * @throws InvalidInterfaceException |
|
149 | + * @throws UserError |
|
150 | + * @throws UnexpectedEntityException |
|
151 | + * @since $VID:$ |
|
152 | + */ |
|
153 | + public function getDatetime($source, array $args, AppContext $context, ResolveInfo $info): EE_Datetime |
|
154 | + { |
|
155 | + $parts = Relay::fromGlobalId(sanitize_text_field($args['id'])); |
|
156 | + |
|
157 | + /** |
|
158 | + * Throw an exception if there's no ID |
|
159 | + */ |
|
160 | + if (empty($parts['id'])) { |
|
161 | + throw new UserError(esc_html__( |
|
162 | + 'A missing or invalid ID was received.', |
|
163 | + 'event_espresso' |
|
164 | + )); |
|
165 | + } |
|
166 | + |
|
167 | + return EEM_Datetime::instance()->get_one_by_ID(absint($parts['id'])); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
173 | + * @param array $args The inputArgs on the field |
|
174 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
175 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
176 | + * @return string |
|
177 | + * @throws Exception |
|
178 | + * @throws InvalidArgumentException |
|
179 | + * @throws InvalidDataTypeException |
|
180 | + * @throws InvalidInterfaceException |
|
181 | + * @throws UserError |
|
182 | + * @throws UnexpectedEntityException |
|
183 | + * @since $VID:$ |
|
184 | + */ |
|
185 | + public function getTicket($source, array $args, AppContext $context, ResolveInfo $info): EE_Ticket |
|
186 | + { |
|
187 | + $parts = Relay::fromGlobalId(sanitize_text_field($args['id'])); |
|
188 | + |
|
189 | + /** |
|
190 | + * Throw an exception if there's no ID |
|
191 | + */ |
|
192 | + if (empty($parts['id'])) { |
|
193 | + throw new UserError(esc_html__( |
|
194 | + 'A missing or invalid ID was received.', |
|
195 | + 'event_espresso' |
|
196 | + )); |
|
197 | + } |
|
198 | + |
|
199 | + return EEM_Ticket::instance()->get_one_by_ID(absint($parts['id'])); |
|
200 | + } |
|
201 | 201 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | "endDate": "<?php echo esc_html($event_end); ?>", |
26 | 26 | "description": <?php echo wp_json_encode($event_description); ?>, |
27 | 27 | "url": "<?php echo esc_url_raw($event_permalink); ?>", |
28 | - "eventAttendanceMode": "<?php echo esc_url_raw('https://schema.org/' . $event_attendance_mode); ?>", |
|
28 | + "eventAttendanceMode": "<?php echo esc_url_raw('https://schema.org/'.$event_attendance_mode); ?>", |
|
29 | 29 | "eventStatus": [ "<?php echo esc_url_raw($event_status); ?>" ], |
30 | 30 | "offers": [ |
31 | 31 | <?php |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | "price": "<?php echo esc_html($ticket['price']); ?>", |
40 | 40 | "priceCurrency": "<?php echo esc_html($currency); ?>" |
41 | 41 | <?php if (isset($ticket['availability'])) { |
42 | - ?>,"availability": "<?php echo esc_url_raw('https://schema.org/' . $ticket['availability']); ?>" |
|
42 | + ?>,"availability": "<?php echo esc_url_raw('https://schema.org/'.$ticket['availability']); ?>" |
|
43 | 43 | <?php } ?> |
44 | 44 | }<?php |
45 | 45 | $i++; |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | "eventStatus": [ "<?php echo esc_url_raw($event_status); ?>" ], |
30 | 30 | "offers": [ |
31 | 31 | <?php |
32 | - $i = 0; |
|
33 | - foreach ($event_tickets as $ticket) {?> |
|
32 | + $i = 0; |
|
33 | + foreach ($event_tickets as $ticket) {?> |
|
34 | 34 | { |
35 | 35 | "@type": "Offer", |
36 | 36 | "url": "<?php echo esc_url_raw($event_permalink); ?>", |
@@ -39,18 +39,18 @@ discard block |
||
39 | 39 | "price": "<?php echo esc_html($ticket['price']); ?>", |
40 | 40 | "priceCurrency": "<?php echo esc_html($currency); ?>" |
41 | 41 | <?php if (isset($ticket['availability'])) { |
42 | - ?>,"availability": "<?php echo esc_url_raw('https://schema.org/' . $ticket['availability']); ?>" |
|
42 | + ?>,"availability": "<?php echo esc_url_raw('https://schema.org/' . $ticket['availability']); ?>" |
|
43 | 43 | <?php } ?> |
44 | 44 | }<?php |
45 | - $i++; |
|
46 | - if ($i < count($event_tickets)) { |
|
47 | - echo ','; |
|
48 | - } |
|
49 | - } |
|
50 | - ?> |
|
45 | + $i++; |
|
46 | + if ($i < count($event_tickets)) { |
|
47 | + echo ','; |
|
48 | + } |
|
49 | + } |
|
50 | + ?> |
|
51 | 51 | ]<?php |
52 | - if ($venue_name) { |
|
53 | - ?>, |
|
52 | + if ($venue_name) { |
|
53 | + ?>, |
|
54 | 54 | "location": { |
55 | 55 | "@type": "Place", |
56 | 56 | "name": <?php echo wp_json_encode($venue_name); ?>, |
@@ -63,13 +63,13 @@ discard block |
||
63 | 63 | } |
64 | 64 | } |
65 | 65 | <?php |
66 | - } ?> |
|
66 | + } ?> |
|
67 | 67 | <?php |
68 | - if ($event_image) { |
|
69 | - ?>, |
|
68 | + if ($event_image) { |
|
69 | + ?>, |
|
70 | 70 | "image": "<?php echo esc_url_raw($event_image); ?>" |
71 | 71 | <?php |
72 | - } ?> |
|
72 | + } ?> |
|
73 | 73 | <?php do_action('AHEE__json_linked_data_for_event__template'); ?> |
74 | 74 | } |
75 | 75 |
@@ -25,7 +25,7 @@ |
||
25 | 25 | if ($is_array) { |
26 | 26 | $values = []; |
27 | 27 | foreach ((array) $param as $key => $value) { |
28 | - $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter); |
|
28 | + $values[$key] = $this->clean($value, $type, is_array($value), $delimiter); |
|
29 | 29 | } |
30 | 30 | return $values; |
31 | 31 | } |
@@ -6,67 +6,67 @@ |
||
6 | 6 | |
7 | 7 | class RequestSanitizer |
8 | 8 | { |
9 | - /** |
|
10 | - * Will sanitize the supplied request parameter based on the specified data type |
|
11 | - * |
|
12 | - * @param mixed $param the supplied request parameter |
|
13 | - * @param string $type the specified data type (default: "string") |
|
14 | - * valid values: "bool", "float", "int", "key", "url", or "string" |
|
15 | - * @param bool $is_array if true, then $param will be treated as an array of $type |
|
16 | - * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator |
|
17 | - * @return array|bool|float|int|string |
|
18 | - * @since 4.10.14.p |
|
19 | - */ |
|
20 | - public function clean($param, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
21 | - { |
|
22 | - if ($delimiter !== '' && is_string($param)) { |
|
23 | - $param = explode($delimiter, $param); |
|
24 | - $is_array = is_array($param); |
|
25 | - // unset the delimiter else this function will recurse forever when we loop over the array of results |
|
26 | - $delimiter = ''; |
|
27 | - } |
|
28 | - // check if we are getting an improperly typed array and correct |
|
29 | - $is_array = $is_array && is_array($param); |
|
30 | - if ($is_array) { |
|
31 | - $values = []; |
|
32 | - foreach ((array) $param as $key => $value) { |
|
33 | - $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter); |
|
34 | - } |
|
35 | - return $values; |
|
36 | - } |
|
37 | - return $this->sanitizeParam($param, $type); |
|
38 | - } |
|
9 | + /** |
|
10 | + * Will sanitize the supplied request parameter based on the specified data type |
|
11 | + * |
|
12 | + * @param mixed $param the supplied request parameter |
|
13 | + * @param string $type the specified data type (default: "string") |
|
14 | + * valid values: "bool", "float", "int", "key", "url", or "string" |
|
15 | + * @param bool $is_array if true, then $param will be treated as an array of $type |
|
16 | + * @param string $delimiter if $param is a CSV like value (ex: 1,2,3,4,5...) then this is the value separator |
|
17 | + * @return array|bool|float|int|string |
|
18 | + * @since 4.10.14.p |
|
19 | + */ |
|
20 | + public function clean($param, $type = DataType::STRING, $is_array = false, $delimiter = '') |
|
21 | + { |
|
22 | + if ($delimiter !== '' && is_string($param)) { |
|
23 | + $param = explode($delimiter, $param); |
|
24 | + $is_array = is_array($param); |
|
25 | + // unset the delimiter else this function will recurse forever when we loop over the array of results |
|
26 | + $delimiter = ''; |
|
27 | + } |
|
28 | + // check if we are getting an improperly typed array and correct |
|
29 | + $is_array = $is_array && is_array($param); |
|
30 | + if ($is_array) { |
|
31 | + $values = []; |
|
32 | + foreach ((array) $param as $key => $value) { |
|
33 | + $values[ $key ] = $this->clean($value, $type, is_array($value), $delimiter); |
|
34 | + } |
|
35 | + return $values; |
|
36 | + } |
|
37 | + return $this->sanitizeParam($param, $type); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param mixed $param |
|
43 | - * @param string $type |
|
44 | - * @return array|float|int|mixed|string|string[]|null |
|
45 | - * @since 4.10.20.p |
|
46 | - */ |
|
47 | - public function sanitizeParam($param, $type = DataType::STRING) |
|
48 | - { |
|
49 | - switch ($type) { |
|
50 | - case DataType::BOOL: |
|
51 | - return filter_var($param, FILTER_VALIDATE_BOOLEAN); |
|
52 | - case DataType::FLOAT: |
|
53 | - return (float) $param; |
|
54 | - case DataType::FQCN: |
|
55 | - return preg_replace('[^\\\w\d]', '', $param); |
|
56 | - case DataType::HTML: |
|
57 | - $allowed_tags = AllowedTags::getAllowedTags(); |
|
58 | - return wp_kses($param, $allowed_tags); |
|
59 | - case DataType::INT: |
|
60 | - return (int) $param; |
|
61 | - case DataType::KEY: |
|
62 | - return sanitize_key($param); |
|
63 | - case DataType::TITLE: |
|
64 | - return sanitize_title($param); |
|
65 | - case DataType::URL: |
|
66 | - return esc_url_raw($param); |
|
67 | - case DataType::STRING: |
|
68 | - default: |
|
69 | - return sanitize_text_field($param); |
|
70 | - } |
|
71 | - } |
|
41 | + /** |
|
42 | + * @param mixed $param |
|
43 | + * @param string $type |
|
44 | + * @return array|float|int|mixed|string|string[]|null |
|
45 | + * @since 4.10.20.p |
|
46 | + */ |
|
47 | + public function sanitizeParam($param, $type = DataType::STRING) |
|
48 | + { |
|
49 | + switch ($type) { |
|
50 | + case DataType::BOOL: |
|
51 | + return filter_var($param, FILTER_VALIDATE_BOOLEAN); |
|
52 | + case DataType::FLOAT: |
|
53 | + return (float) $param; |
|
54 | + case DataType::FQCN: |
|
55 | + return preg_replace('[^\\\w\d]', '', $param); |
|
56 | + case DataType::HTML: |
|
57 | + $allowed_tags = AllowedTags::getAllowedTags(); |
|
58 | + return wp_kses($param, $allowed_tags); |
|
59 | + case DataType::INT: |
|
60 | + return (int) $param; |
|
61 | + case DataType::KEY: |
|
62 | + return sanitize_key($param); |
|
63 | + case DataType::TITLE: |
|
64 | + return sanitize_title($param); |
|
65 | + case DataType::URL: |
|
66 | + return esc_url_raw($param); |
|
67 | + case DataType::STRING: |
|
68 | + default: |
|
69 | + return sanitize_text_field($param); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | } |
@@ -73,7 +73,7 @@ |
||
73 | 73 | |
74 | 74 | private function getCurrentPage() |
75 | 75 | { |
76 | - if (! $this->current_page instanceof CurrentPage) { |
|
76 | + if ( ! $this->current_page instanceof CurrentPage) { |
|
77 | 77 | $this->current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
78 | 78 | } |
79 | 79 | return $this->current_page; |
@@ -16,273 +16,273 @@ |
||
16 | 16 | */ |
17 | 17 | final class EE_Request_Handler implements InterminableInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * @var CurrentPage |
|
21 | - */ |
|
22 | - private $current_page; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var RequestInterface |
|
26 | - */ |
|
27 | - private $request; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var ResponseInterface |
|
31 | - */ |
|
32 | - private $response; |
|
33 | - |
|
34 | - /** |
|
35 | - * whether current request is via AJAX |
|
36 | - * |
|
37 | - * @var boolean |
|
38 | - */ |
|
39 | - public $ajax = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * whether current request is via AJAX from the frontend of the site |
|
43 | - * |
|
44 | - * @var boolean |
|
45 | - */ |
|
46 | - public $front_ajax = false; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * @param RequestInterface $request |
|
51 | - * @param ResponseInterface $response |
|
52 | - */ |
|
53 | - public function __construct(RequestInterface $request, ResponseInterface $response) |
|
54 | - { |
|
55 | - $this->request = $request; |
|
56 | - $this->response = $response; |
|
57 | - $this->ajax = $this->request->isAjax(); |
|
58 | - $this->front_ajax = $this->request->isFrontAjax(); |
|
59 | - do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param WP $WP |
|
65 | - * @return void |
|
66 | - * @deprecated 4.10.14.p |
|
67 | - */ |
|
68 | - public function parse_request($WP = null) |
|
69 | - { |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - private function getCurrentPage() |
|
74 | - { |
|
75 | - if (! $this->current_page instanceof CurrentPage) { |
|
76 | - $this->current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
77 | - } |
|
78 | - return $this->current_page; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param WP $WP |
|
84 | - * @return void |
|
85 | - * @deprecated 4.10.14.p |
|
86 | - */ |
|
87 | - public function set_request_vars($WP = null) |
|
88 | - { |
|
89 | - $this->getCurrentPage()->parseQueryVars($WP); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param WP $WP |
|
95 | - * @return int |
|
96 | - * @deprecated 4.10.14.p |
|
97 | - */ |
|
98 | - public function get_post_id_from_request($WP = null) |
|
99 | - { |
|
100 | - return $this->getCurrentPage()->postId(); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param WP $WP |
|
106 | - * @return string |
|
107 | - * @deprecated 4.10.14.p |
|
108 | - */ |
|
109 | - public function get_post_name_from_request($WP = null) |
|
110 | - { |
|
111 | - return $this->getCurrentPage()->postName(); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param WP $WP |
|
117 | - * @return array |
|
118 | - * @deprecated 4.10.14.p |
|
119 | - */ |
|
120 | - public function get_post_type_from_request($WP = null) |
|
121 | - { |
|
122 | - return $this->getCurrentPage()->postType(); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Just a helper method for getting the url for the displayed page. |
|
128 | - * |
|
129 | - * @param WP $WP |
|
130 | - * @return string |
|
131 | - * @deprecated 4.10.14.p |
|
132 | - */ |
|
133 | - public function get_current_page_permalink($WP = null) |
|
134 | - { |
|
135 | - return $this->getCurrentPage()->getPermalink($WP); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return bool |
|
141 | - * @deprecated 4.10.14.p |
|
142 | - */ |
|
143 | - public function test_for_espresso_page() |
|
144 | - { |
|
145 | - return $this->getCurrentPage()->isEspressoPage(); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @param $key |
|
151 | - * @param $value |
|
152 | - * @return void |
|
153 | - * @deprecated 4.10.14.p |
|
154 | - */ |
|
155 | - public function set_notice($key, $value) |
|
156 | - { |
|
157 | - $this->response->setNotice($key, $value); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param $key |
|
163 | - * @return mixed |
|
164 | - * @deprecated 4.10.14.p |
|
165 | - */ |
|
166 | - public function get_notice($key) |
|
167 | - { |
|
168 | - return $this->response->getNotice($key); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * @param $string |
|
174 | - * @return void |
|
175 | - * @deprecated 4.10.14.p |
|
176 | - */ |
|
177 | - public function add_output($string) |
|
178 | - { |
|
179 | - $this->response->addOutput($string); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @return string |
|
185 | - * @deprecated 4.10.14.p |
|
186 | - */ |
|
187 | - public function get_output() |
|
188 | - { |
|
189 | - return $this->response->getOutput(); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @param $item |
|
195 | - * @param $key |
|
196 | - * @deprecated 4.10.14.p |
|
197 | - */ |
|
198 | - public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
199 | - { |
|
200 | - $item = strpos($item, 'email') !== false |
|
201 | - ? sanitize_email($item) |
|
202 | - : sanitize_text_field($item); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @param null|bool $value |
|
208 | - * @return void |
|
209 | - * @deprecated 4.10.14.p |
|
210 | - */ |
|
211 | - public function set_espresso_page($value = null) |
|
212 | - { |
|
213 | - $this->getCurrentPage()->setEspressoPage($value); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * @return bool |
|
219 | - * @deprecated 4.10.14.p |
|
220 | - */ |
|
221 | - public function is_espresso_page() |
|
222 | - { |
|
223 | - return $this->getCurrentPage()->isEspressoPage(); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * returns sanitized contents of $_REQUEST |
|
229 | - * |
|
230 | - * @return array |
|
231 | - * @deprecated 4.10.14.p |
|
232 | - */ |
|
233 | - public function params() |
|
234 | - { |
|
235 | - return $this->request->requestParams(); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * @param $key |
|
241 | - * @param $value |
|
242 | - * @param bool $override_ee |
|
243 | - * @return void |
|
244 | - * @deprecated 4.10.14.p |
|
245 | - */ |
|
246 | - public function set($key, $value, $override_ee = false) |
|
247 | - { |
|
248 | - $this->request->setRequestParam($key, $value, $override_ee); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param $key |
|
254 | - * @param null $default |
|
255 | - * @return mixed |
|
256 | - * @deprecated 4.10.14.p |
|
257 | - */ |
|
258 | - public function get($key, $default = null) |
|
259 | - { |
|
260 | - return $this->request->getRequestParam($key, $default); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * check if param exists |
|
266 | - * |
|
267 | - * @param $key |
|
268 | - * @return boolean |
|
269 | - * @deprecated 4.10.14.p |
|
270 | - */ |
|
271 | - public function is_set($key) |
|
272 | - { |
|
273 | - return $this->request->requestParamIsSet($key); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * remove param |
|
279 | - * |
|
280 | - * @param $key |
|
281 | - * @return void |
|
282 | - * @deprecated 4.10.14.p |
|
283 | - */ |
|
284 | - public function un_set($key) |
|
285 | - { |
|
286 | - $this->request->unSetRequestParam($key); |
|
287 | - } |
|
19 | + /** |
|
20 | + * @var CurrentPage |
|
21 | + */ |
|
22 | + private $current_page; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var RequestInterface |
|
26 | + */ |
|
27 | + private $request; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var ResponseInterface |
|
31 | + */ |
|
32 | + private $response; |
|
33 | + |
|
34 | + /** |
|
35 | + * whether current request is via AJAX |
|
36 | + * |
|
37 | + * @var boolean |
|
38 | + */ |
|
39 | + public $ajax = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * whether current request is via AJAX from the frontend of the site |
|
43 | + * |
|
44 | + * @var boolean |
|
45 | + */ |
|
46 | + public $front_ajax = false; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * @param RequestInterface $request |
|
51 | + * @param ResponseInterface $response |
|
52 | + */ |
|
53 | + public function __construct(RequestInterface $request, ResponseInterface $response) |
|
54 | + { |
|
55 | + $this->request = $request; |
|
56 | + $this->response = $response; |
|
57 | + $this->ajax = $this->request->isAjax(); |
|
58 | + $this->front_ajax = $this->request->isFrontAjax(); |
|
59 | + do_action('AHEE__EE_Request_Handler__construct__complete'); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param WP $WP |
|
65 | + * @return void |
|
66 | + * @deprecated 4.10.14.p |
|
67 | + */ |
|
68 | + public function parse_request($WP = null) |
|
69 | + { |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + private function getCurrentPage() |
|
74 | + { |
|
75 | + if (! $this->current_page instanceof CurrentPage) { |
|
76 | + $this->current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
77 | + } |
|
78 | + return $this->current_page; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param WP $WP |
|
84 | + * @return void |
|
85 | + * @deprecated 4.10.14.p |
|
86 | + */ |
|
87 | + public function set_request_vars($WP = null) |
|
88 | + { |
|
89 | + $this->getCurrentPage()->parseQueryVars($WP); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param WP $WP |
|
95 | + * @return int |
|
96 | + * @deprecated 4.10.14.p |
|
97 | + */ |
|
98 | + public function get_post_id_from_request($WP = null) |
|
99 | + { |
|
100 | + return $this->getCurrentPage()->postId(); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param WP $WP |
|
106 | + * @return string |
|
107 | + * @deprecated 4.10.14.p |
|
108 | + */ |
|
109 | + public function get_post_name_from_request($WP = null) |
|
110 | + { |
|
111 | + return $this->getCurrentPage()->postName(); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param WP $WP |
|
117 | + * @return array |
|
118 | + * @deprecated 4.10.14.p |
|
119 | + */ |
|
120 | + public function get_post_type_from_request($WP = null) |
|
121 | + { |
|
122 | + return $this->getCurrentPage()->postType(); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Just a helper method for getting the url for the displayed page. |
|
128 | + * |
|
129 | + * @param WP $WP |
|
130 | + * @return string |
|
131 | + * @deprecated 4.10.14.p |
|
132 | + */ |
|
133 | + public function get_current_page_permalink($WP = null) |
|
134 | + { |
|
135 | + return $this->getCurrentPage()->getPermalink($WP); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @return bool |
|
141 | + * @deprecated 4.10.14.p |
|
142 | + */ |
|
143 | + public function test_for_espresso_page() |
|
144 | + { |
|
145 | + return $this->getCurrentPage()->isEspressoPage(); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @param $key |
|
151 | + * @param $value |
|
152 | + * @return void |
|
153 | + * @deprecated 4.10.14.p |
|
154 | + */ |
|
155 | + public function set_notice($key, $value) |
|
156 | + { |
|
157 | + $this->response->setNotice($key, $value); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param $key |
|
163 | + * @return mixed |
|
164 | + * @deprecated 4.10.14.p |
|
165 | + */ |
|
166 | + public function get_notice($key) |
|
167 | + { |
|
168 | + return $this->response->getNotice($key); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * @param $string |
|
174 | + * @return void |
|
175 | + * @deprecated 4.10.14.p |
|
176 | + */ |
|
177 | + public function add_output($string) |
|
178 | + { |
|
179 | + $this->response->addOutput($string); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @return string |
|
185 | + * @deprecated 4.10.14.p |
|
186 | + */ |
|
187 | + public function get_output() |
|
188 | + { |
|
189 | + return $this->response->getOutput(); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @param $item |
|
195 | + * @param $key |
|
196 | + * @deprecated 4.10.14.p |
|
197 | + */ |
|
198 | + public function sanitize_text_field_for_array_walk(&$item, &$key) |
|
199 | + { |
|
200 | + $item = strpos($item, 'email') !== false |
|
201 | + ? sanitize_email($item) |
|
202 | + : sanitize_text_field($item); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @param null|bool $value |
|
208 | + * @return void |
|
209 | + * @deprecated 4.10.14.p |
|
210 | + */ |
|
211 | + public function set_espresso_page($value = null) |
|
212 | + { |
|
213 | + $this->getCurrentPage()->setEspressoPage($value); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * @return bool |
|
219 | + * @deprecated 4.10.14.p |
|
220 | + */ |
|
221 | + public function is_espresso_page() |
|
222 | + { |
|
223 | + return $this->getCurrentPage()->isEspressoPage(); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * returns sanitized contents of $_REQUEST |
|
229 | + * |
|
230 | + * @return array |
|
231 | + * @deprecated 4.10.14.p |
|
232 | + */ |
|
233 | + public function params() |
|
234 | + { |
|
235 | + return $this->request->requestParams(); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * @param $key |
|
241 | + * @param $value |
|
242 | + * @param bool $override_ee |
|
243 | + * @return void |
|
244 | + * @deprecated 4.10.14.p |
|
245 | + */ |
|
246 | + public function set($key, $value, $override_ee = false) |
|
247 | + { |
|
248 | + $this->request->setRequestParam($key, $value, $override_ee); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param $key |
|
254 | + * @param null $default |
|
255 | + * @return mixed |
|
256 | + * @deprecated 4.10.14.p |
|
257 | + */ |
|
258 | + public function get($key, $default = null) |
|
259 | + { |
|
260 | + return $this->request->getRequestParam($key, $default); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * check if param exists |
|
266 | + * |
|
267 | + * @param $key |
|
268 | + * @return boolean |
|
269 | + * @deprecated 4.10.14.p |
|
270 | + */ |
|
271 | + public function is_set($key) |
|
272 | + { |
|
273 | + return $this->request->requestParamIsSet($key); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * remove param |
|
279 | + * |
|
280 | + * @param $key |
|
281 | + * @return void |
|
282 | + * @deprecated 4.10.14.p |
|
283 | + */ |
|
284 | + public function un_set($key) |
|
285 | + { |
|
286 | + $this->request->unSetRequestParam($key); |
|
287 | + } |
|
288 | 288 | } |