@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | { |
72 | 72 | $this->_validate_list_requirements(); |
73 | 73 | |
74 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
74 | + if ( ! $this->_data['data'] instanceof EE_Ticket) { |
|
75 | 75 | return ''; |
76 | 76 | } |
77 | 77 | |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | $addressee_obj = $this->_extra_data['data']; |
83 | 83 | |
84 | 84 | // made it here so we have an EE_Ticket, so we should have what we need. |
85 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
86 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
87 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
88 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
85 | + $ticket_line_item = isset($addressee_obj->tickets[$ticket->ID()]['line_item']) |
|
86 | + ? $addressee_obj->tickets[$ticket->ID()]['line_item'] : null; |
|
87 | + $sub_line_items = isset($addressee_obj->tickets[$ticket->ID()]['sub_line_items']) |
|
88 | + ? $addressee_obj->tickets[$ticket->ID()]['sub_line_items'] : array(); |
|
89 | 89 | |
90 | 90 | $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
91 | 91 | : $templates['ticket_line_item_pms']; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | } |
121 | 121 | $this->_validate_list_requirements(); |
122 | 122 | |
123 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
123 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
124 | 124 | return ''; |
125 | 125 | } |
126 | 126 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | $this->_validate_list_requirements(); |
156 | 156 | |
157 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
157 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
158 | 158 | return ''; |
159 | 159 | } |
160 | 160 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | { |
191 | 191 | $this->_validate_list_requirements(); |
192 | 192 | |
193 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
193 | + if ( ! $this->_data['data'] instanceof EE_Line_Item) { |
|
194 | 194 | return ''; |
195 | 195 | } |
196 | 196 | |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | |
204 | 204 | $main_line_item_id = $main_line_item->ID(); |
205 | 205 | |
206 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
207 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
206 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[$main_line_item_id]['children']) |
|
207 | + ? $addressee_obj->line_items_with_children[$main_line_item_id]['children'] : array(); |
|
208 | 208 | |
209 | 209 | $line_item_list = ''; |
210 | 210 |
@@ -20,204 +20,204 @@ |
||
20 | 20 | */ |
21 | 21 | class EE_Line_Item_List_Shortcodes extends EE_Shortcodes |
22 | 22 | { |
23 | - protected function _init_props() |
|
24 | - { |
|
25 | - $this->label = esc_html__('Line Item List Shortcodes', 'event_espresso'); |
|
26 | - $this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso'); |
|
27 | - $this->_shortcodes = array( |
|
28 | - '[TICKET_LINE_ITEM_LIST]' => esc_html__('Outputs a list of ticket line items.', 'event_espresso'), |
|
29 | - '[TAX_LINE_ITEM_LIST]' => esc_html__('Outputs a list of tax line items.', 'event_espresso'), |
|
30 | - '[ADDITIONAL_LINE_ITEM_LIST]' => esc_html__( |
|
31 | - 'Outputs a list of additional line items (other charges or discounts)', |
|
32 | - 'event_espresso' |
|
33 | - ), |
|
34 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'), |
|
35 | - ); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @param string $shortcode |
|
41 | - * @throws EE_Error |
|
42 | - */ |
|
43 | - protected function _parser($shortcode) |
|
44 | - { |
|
45 | - switch ($shortcode) { |
|
46 | - case '[TICKET_LINE_ITEM_LIST]': |
|
47 | - return $this->_get_ticket_line_item_list(); |
|
48 | - |
|
49 | - case '[TAX_LINE_ITEM_LIST]': |
|
50 | - return $this->_get_tax_line_item_list(); |
|
51 | - |
|
52 | - case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
53 | - return $this->_get_price_mod_line_item_list(); |
|
54 | - |
|
55 | - case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
56 | - return $this->_get_additional_line_item_list(); |
|
57 | - |
|
58 | - default: |
|
59 | - return ''; |
|
60 | - } |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
66 | - * |
|
67 | - * @since 4.5.0 |
|
68 | - * |
|
69 | - * @return string parsed ticket line item list. |
|
70 | - */ |
|
71 | - private function _get_ticket_line_item_list() |
|
72 | - { |
|
73 | - $this->_validate_list_requirements(); |
|
74 | - |
|
75 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
76 | - return ''; |
|
77 | - } |
|
78 | - |
|
79 | - $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
80 | - |
|
81 | - $ticket = $this->_data['data']; |
|
82 | - $templates = $this->_extra_data['template']; |
|
83 | - $addressee_obj = $this->_extra_data['data']; |
|
84 | - |
|
85 | - // made it here so we have an EE_Ticket, so we should have what we need. |
|
86 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
87 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
88 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
89 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
90 | - |
|
91 | - $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
92 | - : $templates['ticket_line_item_pms']; |
|
93 | - |
|
94 | - if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
95 | - return ''; |
|
96 | - } |
|
97 | - |
|
98 | - // now we just return the appropriate template parsed for each ticket. |
|
99 | - return $this->_shortcode_helper->parse_line_item_list_template( |
|
100 | - $template, |
|
101 | - $ticket_line_item, |
|
102 | - $valid_shortcodes, |
|
103 | - $this->_extra_data |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
110 | - * |
|
111 | - * @return string parsed tax line item list. |
|
112 | - * @throws EE_Error |
|
113 | - * @since 4.5.0 |
|
114 | - */ |
|
115 | - private function _get_tax_line_item_list() |
|
116 | - { |
|
117 | - /** @var EE_Admin_Config $admin_config */ |
|
118 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
119 | - if ($admin_config->useAdvancedEditor()) { |
|
120 | - return ''; |
|
121 | - } |
|
122 | - $this->_validate_list_requirements(); |
|
123 | - |
|
124 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
125 | - return ''; |
|
126 | - } |
|
127 | - |
|
128 | - // made it here so we're good to go. |
|
129 | - $valid_shortcodes = array('line_item'); |
|
130 | - $templates = $this->_data['template']; |
|
131 | - |
|
132 | - $tax_line_items = $this->_data['data']->tax_line_items; |
|
133 | - $line_item_list = ''; |
|
134 | - foreach ($tax_line_items as $line_item) { |
|
135 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
136 | - $templates['tax_line_item_list'], |
|
137 | - $line_item, |
|
138 | - $valid_shortcodes, |
|
139 | - $this->_extra_data |
|
140 | - ); |
|
141 | - } |
|
142 | - |
|
143 | - return $line_item_list; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
148 | - * |
|
149 | - * @since 4.5.0 |
|
150 | - * |
|
151 | - * @return string parsed other line item list. |
|
152 | - */ |
|
153 | - private function _get_additional_line_item_list() |
|
154 | - { |
|
155 | - |
|
156 | - $this->_validate_list_requirements(); |
|
157 | - |
|
158 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
159 | - return ''; |
|
160 | - } |
|
161 | - |
|
162 | - // made it here so we're good to go. |
|
163 | - $valid_shortcodes = array('line_item'); |
|
164 | - $templates = $this->_data['template']; |
|
165 | - |
|
166 | - $additional_line_items = $this->_data['data']->additional_line_items; |
|
167 | - $line_item_list = ''; |
|
168 | - foreach ($additional_line_items as $line_item) { |
|
169 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
170 | - $templates['additional_line_item_list'], |
|
171 | - $line_item, |
|
172 | - $valid_shortcodes, |
|
173 | - $this->_extra_data |
|
174 | - ); |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - return $line_item_list; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
184 | - * parent ticket line item. |
|
185 | - * |
|
186 | - * @since 4.5.0 |
|
187 | - * |
|
188 | - * @return string parsed price modifier line item list. |
|
189 | - */ |
|
190 | - private function _get_price_mod_line_item_list() |
|
191 | - { |
|
192 | - $this->_validate_list_requirements(); |
|
193 | - |
|
194 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
195 | - return ''; |
|
196 | - } |
|
197 | - |
|
198 | - // made it here so we're good to go. |
|
199 | - $main_line_item = $this->_data['data']; |
|
200 | - $templates = $this->_extra_data['template']; |
|
201 | - $addressee_obj = $this->_extra_data['data']; |
|
202 | - |
|
203 | - $valid_shortcodes = array('line_item'); |
|
204 | - |
|
205 | - $main_line_item_id = $main_line_item->ID(); |
|
206 | - |
|
207 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
208 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
209 | - |
|
210 | - $line_item_list = ''; |
|
211 | - |
|
212 | - foreach ($price_mod_line_items as $line_item) { |
|
213 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
214 | - $templates['price_modifier_line_item_list'], |
|
215 | - $line_item, |
|
216 | - $valid_shortcodes, |
|
217 | - $this->_extra_data |
|
218 | - ); |
|
219 | - } |
|
220 | - |
|
221 | - return $line_item_list; |
|
222 | - } |
|
23 | + protected function _init_props() |
|
24 | + { |
|
25 | + $this->label = esc_html__('Line Item List Shortcodes', 'event_espresso'); |
|
26 | + $this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso'); |
|
27 | + $this->_shortcodes = array( |
|
28 | + '[TICKET_LINE_ITEM_LIST]' => esc_html__('Outputs a list of ticket line items.', 'event_espresso'), |
|
29 | + '[TAX_LINE_ITEM_LIST]' => esc_html__('Outputs a list of tax line items.', 'event_espresso'), |
|
30 | + '[ADDITIONAL_LINE_ITEM_LIST]' => esc_html__( |
|
31 | + 'Outputs a list of additional line items (other charges or discounts)', |
|
32 | + 'event_espresso' |
|
33 | + ), |
|
34 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'), |
|
35 | + ); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @param string $shortcode |
|
41 | + * @throws EE_Error |
|
42 | + */ |
|
43 | + protected function _parser($shortcode) |
|
44 | + { |
|
45 | + switch ($shortcode) { |
|
46 | + case '[TICKET_LINE_ITEM_LIST]': |
|
47 | + return $this->_get_ticket_line_item_list(); |
|
48 | + |
|
49 | + case '[TAX_LINE_ITEM_LIST]': |
|
50 | + return $this->_get_tax_line_item_list(); |
|
51 | + |
|
52 | + case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
53 | + return $this->_get_price_mod_line_item_list(); |
|
54 | + |
|
55 | + case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
56 | + return $this->_get_additional_line_item_list(); |
|
57 | + |
|
58 | + default: |
|
59 | + return ''; |
|
60 | + } |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
66 | + * |
|
67 | + * @since 4.5.0 |
|
68 | + * |
|
69 | + * @return string parsed ticket line item list. |
|
70 | + */ |
|
71 | + private function _get_ticket_line_item_list() |
|
72 | + { |
|
73 | + $this->_validate_list_requirements(); |
|
74 | + |
|
75 | + if (! $this->_data['data'] instanceof EE_Ticket) { |
|
76 | + return ''; |
|
77 | + } |
|
78 | + |
|
79 | + $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
80 | + |
|
81 | + $ticket = $this->_data['data']; |
|
82 | + $templates = $this->_extra_data['template']; |
|
83 | + $addressee_obj = $this->_extra_data['data']; |
|
84 | + |
|
85 | + // made it here so we have an EE_Ticket, so we should have what we need. |
|
86 | + $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
87 | + ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
88 | + $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
89 | + ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
90 | + |
|
91 | + $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
92 | + : $templates['ticket_line_item_pms']; |
|
93 | + |
|
94 | + if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
95 | + return ''; |
|
96 | + } |
|
97 | + |
|
98 | + // now we just return the appropriate template parsed for each ticket. |
|
99 | + return $this->_shortcode_helper->parse_line_item_list_template( |
|
100 | + $template, |
|
101 | + $ticket_line_item, |
|
102 | + $valid_shortcodes, |
|
103 | + $this->_extra_data |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
110 | + * |
|
111 | + * @return string parsed tax line item list. |
|
112 | + * @throws EE_Error |
|
113 | + * @since 4.5.0 |
|
114 | + */ |
|
115 | + private function _get_tax_line_item_list() |
|
116 | + { |
|
117 | + /** @var EE_Admin_Config $admin_config */ |
|
118 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
119 | + if ($admin_config->useAdvancedEditor()) { |
|
120 | + return ''; |
|
121 | + } |
|
122 | + $this->_validate_list_requirements(); |
|
123 | + |
|
124 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
125 | + return ''; |
|
126 | + } |
|
127 | + |
|
128 | + // made it here so we're good to go. |
|
129 | + $valid_shortcodes = array('line_item'); |
|
130 | + $templates = $this->_data['template']; |
|
131 | + |
|
132 | + $tax_line_items = $this->_data['data']->tax_line_items; |
|
133 | + $line_item_list = ''; |
|
134 | + foreach ($tax_line_items as $line_item) { |
|
135 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
136 | + $templates['tax_line_item_list'], |
|
137 | + $line_item, |
|
138 | + $valid_shortcodes, |
|
139 | + $this->_extra_data |
|
140 | + ); |
|
141 | + } |
|
142 | + |
|
143 | + return $line_item_list; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
148 | + * |
|
149 | + * @since 4.5.0 |
|
150 | + * |
|
151 | + * @return string parsed other line item list. |
|
152 | + */ |
|
153 | + private function _get_additional_line_item_list() |
|
154 | + { |
|
155 | + |
|
156 | + $this->_validate_list_requirements(); |
|
157 | + |
|
158 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
159 | + return ''; |
|
160 | + } |
|
161 | + |
|
162 | + // made it here so we're good to go. |
|
163 | + $valid_shortcodes = array('line_item'); |
|
164 | + $templates = $this->_data['template']; |
|
165 | + |
|
166 | + $additional_line_items = $this->_data['data']->additional_line_items; |
|
167 | + $line_item_list = ''; |
|
168 | + foreach ($additional_line_items as $line_item) { |
|
169 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
170 | + $templates['additional_line_item_list'], |
|
171 | + $line_item, |
|
172 | + $valid_shortcodes, |
|
173 | + $this->_extra_data |
|
174 | + ); |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + return $line_item_list; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
184 | + * parent ticket line item. |
|
185 | + * |
|
186 | + * @since 4.5.0 |
|
187 | + * |
|
188 | + * @return string parsed price modifier line item list. |
|
189 | + */ |
|
190 | + private function _get_price_mod_line_item_list() |
|
191 | + { |
|
192 | + $this->_validate_list_requirements(); |
|
193 | + |
|
194 | + if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
195 | + return ''; |
|
196 | + } |
|
197 | + |
|
198 | + // made it here so we're good to go. |
|
199 | + $main_line_item = $this->_data['data']; |
|
200 | + $templates = $this->_extra_data['template']; |
|
201 | + $addressee_obj = $this->_extra_data['data']; |
|
202 | + |
|
203 | + $valid_shortcodes = array('line_item'); |
|
204 | + |
|
205 | + $main_line_item_id = $main_line_item->ID(); |
|
206 | + |
|
207 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
208 | + ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
209 | + |
|
210 | + $line_item_list = ''; |
|
211 | + |
|
212 | + foreach ($price_mod_line_items as $line_item) { |
|
213 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
214 | + $templates['price_modifier_line_item_list'], |
|
215 | + $line_item, |
|
216 | + $valid_shortcodes, |
|
217 | + $this->_extra_data |
|
218 | + ); |
|
219 | + } |
|
220 | + |
|
221 | + return $line_item_list; |
|
222 | + } |
|
223 | 223 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | */ |
16 | 16 | interface EE_Line_Item_Filter |
17 | 17 | { |
18 | - /** |
|
19 | - * process |
|
20 | - * |
|
21 | - * @param EE_Line_Item $line_item |
|
22 | - * @return EE_Line_Item |
|
23 | - */ |
|
24 | - public function process(EE_Line_Item $line_item): ?EE_Line_Item; |
|
18 | + /** |
|
19 | + * process |
|
20 | + * |
|
21 | + * @param EE_Line_Item $line_item |
|
22 | + * @return EE_Line_Item |
|
23 | + */ |
|
24 | + public function process(EE_Line_Item $line_item): ?EE_Line_Item; |
|
25 | 25 | } |
@@ -20,234 +20,234 @@ |
||
20 | 20 | */ |
21 | 21 | class TicketPriceModifiers |
22 | 22 | { |
23 | - /** |
|
24 | - * @var EE_Ticket |
|
25 | - */ |
|
26 | - private $ticket; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @var EE_Price[] |
|
31 | - */ |
|
32 | - private $ticket_prices; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @param EE_Ticket $ticket |
|
37 | - * @throws EE_Error |
|
38 | - * @throws ReflectionException |
|
39 | - */ |
|
40 | - public function __construct(EE_Ticket $ticket) |
|
41 | - { |
|
42 | - $this->ticket = $ticket; |
|
43 | - // run a query to retrieve ALL of this ticket's related prices before doing anything else |
|
44 | - $this->ticket_prices = $this->ticket->prices(); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param callable $filter |
|
50 | - * @return array |
|
51 | - * @throws EE_Error |
|
52 | - * @throws ReflectionException |
|
53 | - */ |
|
54 | - private function filterModifiersForTicket(callable $filter): array |
|
55 | - { |
|
56 | - $ticket_modifiers = $this->ticket->get_all_from_cache('Price'); |
|
57 | - if (empty($ticket_modifiers)) { |
|
58 | - $ticket_modifiers = $this->ticket_prices; |
|
59 | - } |
|
60 | - return array_filter($ticket_modifiers, $filter); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * retrieve all price modifiers for the this ticket |
|
66 | - * |
|
67 | - * @return array |
|
68 | - * @throws EE_Error |
|
69 | - * @throws ReflectionException |
|
70 | - */ |
|
71 | - public function getAllModifiersForTicket(): array |
|
72 | - { |
|
73 | - return $this->filterModifiersForTicket([$this, 'allModifiersFilter']); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket |
|
79 | - * |
|
80 | - * @param EE_Price $price_modifier |
|
81 | - * @return bool |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - */ |
|
85 | - public function allModifiersFilter(EE_Price $price_modifier): bool |
|
86 | - { |
|
87 | - return ! $price_modifier->is_base_price(); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * retrieve all discounts for the this ticket |
|
93 | - * |
|
94 | - * @return array |
|
95 | - * @throws EE_Error |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - public function getAllDiscountModifiersForTicket(): array |
|
99 | - { |
|
100 | - return $this->filterModifiersForTicket([$this, 'discountModifierFilter']); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket |
|
106 | - * |
|
107 | - * @param EE_Price $price_modifier |
|
108 | - * @return bool |
|
109 | - * @throws EE_Error |
|
110 | - * @throws ReflectionException |
|
111 | - */ |
|
112 | - public function discountModifierFilter(EE_Price $price_modifier): bool |
|
113 | - { |
|
114 | - return $price_modifier->is_discount(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * retrieve all surcharges for the this ticket |
|
120 | - * |
|
121 | - * @return array |
|
122 | - * @throws EE_Error |
|
123 | - * @throws ReflectionException |
|
124 | - */ |
|
125 | - public function getAllSurchargeModifiersForTicket(): array |
|
126 | - { |
|
127 | - return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket |
|
133 | - * |
|
134 | - * @param EE_Price $price_modifier |
|
135 | - * @return bool |
|
136 | - * @throws EE_Error |
|
137 | - * @throws ReflectionException |
|
138 | - */ |
|
139 | - public function surchargeModifierFilter(EE_Price $price_modifier): bool |
|
140 | - { |
|
141 | - return $price_modifier->is_surcharge(); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * retrieve all discounts AND surcharges for the this ticket |
|
147 | - * |
|
148 | - * @return array |
|
149 | - * @throws EE_Error |
|
150 | - * @throws ReflectionException |
|
151 | - */ |
|
152 | - public function getAllDiscountAndSurchargeModifiersForTicket(): array |
|
153 | - { |
|
154 | - return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket |
|
160 | - * |
|
161 | - * @param EE_Price $price_modifier |
|
162 | - * @return bool |
|
163 | - * @throws EE_Error |
|
164 | - * @throws ReflectionException |
|
165 | - */ |
|
166 | - public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool |
|
167 | - { |
|
168 | - return $price_modifier->is_discount() || $price_modifier->is_surcharge(); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * retrieve all taxes for the this ticket |
|
174 | - * |
|
175 | - * @return array |
|
176 | - * @throws EE_Error |
|
177 | - * @throws ReflectionException |
|
178 | - */ |
|
179 | - public function getAllTaxesForTicket(): array |
|
180 | - { |
|
181 | - return $this->filterModifiersForTicket([$this, 'taxModifierFilter']); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket |
|
187 | - * |
|
188 | - * @param EE_Price $price_modifier |
|
189 | - * @return bool |
|
190 | - * @throws EE_Error |
|
191 | - * @throws ReflectionException |
|
192 | - */ |
|
193 | - public function taxModifierFilter(EE_Price $price_modifier): bool |
|
194 | - { |
|
195 | - return $price_modifier->is_tax(); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * retrieve ALL PRICES that are NOT taxes for the this ticket |
|
201 | - * |
|
202 | - * @return array |
|
203 | - * @throws EE_Error |
|
204 | - * @throws ReflectionException |
|
205 | - */ |
|
206 | - public function getAllNonTaxPricesForTicket(): array |
|
207 | - { |
|
208 | - return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * pass to filterModifiersForTicket() with a ticket |
|
214 | - * to retrieve ALL PRICES that are NOT taxes for the this ticket |
|
215 | - * |
|
216 | - * @param EE_Price $price_modifier |
|
217 | - * @return bool |
|
218 | - * @throws EE_Error |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - public function nonTaxPriceFilter(EE_Price $price_modifier): bool |
|
222 | - { |
|
223 | - return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax(); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * retrieve the base price for the this ticket |
|
229 | - * |
|
230 | - * @return array |
|
231 | - * @throws EE_Error |
|
232 | - * @throws ReflectionException |
|
233 | - */ |
|
234 | - public function getBasePrice(): array |
|
235 | - { |
|
236 | - return $this->filterModifiersForTicket([$this, 'basePriceFilter']); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * pass to filterModifiersForTicket() |
|
242 | - * to retrieve the base price for the this ticket |
|
243 | - * |
|
244 | - * @param EE_Price $price_modifier |
|
245 | - * @return bool |
|
246 | - * @throws EE_Error |
|
247 | - * @throws ReflectionException |
|
248 | - */ |
|
249 | - public function basePriceFilter(EE_Price $price_modifier): bool |
|
250 | - { |
|
251 | - return $price_modifier->is_base_price(); |
|
252 | - } |
|
23 | + /** |
|
24 | + * @var EE_Ticket |
|
25 | + */ |
|
26 | + private $ticket; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @var EE_Price[] |
|
31 | + */ |
|
32 | + private $ticket_prices; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @param EE_Ticket $ticket |
|
37 | + * @throws EE_Error |
|
38 | + * @throws ReflectionException |
|
39 | + */ |
|
40 | + public function __construct(EE_Ticket $ticket) |
|
41 | + { |
|
42 | + $this->ticket = $ticket; |
|
43 | + // run a query to retrieve ALL of this ticket's related prices before doing anything else |
|
44 | + $this->ticket_prices = $this->ticket->prices(); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param callable $filter |
|
50 | + * @return array |
|
51 | + * @throws EE_Error |
|
52 | + * @throws ReflectionException |
|
53 | + */ |
|
54 | + private function filterModifiersForTicket(callable $filter): array |
|
55 | + { |
|
56 | + $ticket_modifiers = $this->ticket->get_all_from_cache('Price'); |
|
57 | + if (empty($ticket_modifiers)) { |
|
58 | + $ticket_modifiers = $this->ticket_prices; |
|
59 | + } |
|
60 | + return array_filter($ticket_modifiers, $filter); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * retrieve all price modifiers for the this ticket |
|
66 | + * |
|
67 | + * @return array |
|
68 | + * @throws EE_Error |
|
69 | + * @throws ReflectionException |
|
70 | + */ |
|
71 | + public function getAllModifiersForTicket(): array |
|
72 | + { |
|
73 | + return $this->filterModifiersForTicket([$this, 'allModifiersFilter']); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket |
|
79 | + * |
|
80 | + * @param EE_Price $price_modifier |
|
81 | + * @return bool |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + */ |
|
85 | + public function allModifiersFilter(EE_Price $price_modifier): bool |
|
86 | + { |
|
87 | + return ! $price_modifier->is_base_price(); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * retrieve all discounts for the this ticket |
|
93 | + * |
|
94 | + * @return array |
|
95 | + * @throws EE_Error |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + public function getAllDiscountModifiersForTicket(): array |
|
99 | + { |
|
100 | + return $this->filterModifiersForTicket([$this, 'discountModifierFilter']); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket |
|
106 | + * |
|
107 | + * @param EE_Price $price_modifier |
|
108 | + * @return bool |
|
109 | + * @throws EE_Error |
|
110 | + * @throws ReflectionException |
|
111 | + */ |
|
112 | + public function discountModifierFilter(EE_Price $price_modifier): bool |
|
113 | + { |
|
114 | + return $price_modifier->is_discount(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * retrieve all surcharges for the this ticket |
|
120 | + * |
|
121 | + * @return array |
|
122 | + * @throws EE_Error |
|
123 | + * @throws ReflectionException |
|
124 | + */ |
|
125 | + public function getAllSurchargeModifiersForTicket(): array |
|
126 | + { |
|
127 | + return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket |
|
133 | + * |
|
134 | + * @param EE_Price $price_modifier |
|
135 | + * @return bool |
|
136 | + * @throws EE_Error |
|
137 | + * @throws ReflectionException |
|
138 | + */ |
|
139 | + public function surchargeModifierFilter(EE_Price $price_modifier): bool |
|
140 | + { |
|
141 | + return $price_modifier->is_surcharge(); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * retrieve all discounts AND surcharges for the this ticket |
|
147 | + * |
|
148 | + * @return array |
|
149 | + * @throws EE_Error |
|
150 | + * @throws ReflectionException |
|
151 | + */ |
|
152 | + public function getAllDiscountAndSurchargeModifiersForTicket(): array |
|
153 | + { |
|
154 | + return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket |
|
160 | + * |
|
161 | + * @param EE_Price $price_modifier |
|
162 | + * @return bool |
|
163 | + * @throws EE_Error |
|
164 | + * @throws ReflectionException |
|
165 | + */ |
|
166 | + public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool |
|
167 | + { |
|
168 | + return $price_modifier->is_discount() || $price_modifier->is_surcharge(); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * retrieve all taxes for the this ticket |
|
174 | + * |
|
175 | + * @return array |
|
176 | + * @throws EE_Error |
|
177 | + * @throws ReflectionException |
|
178 | + */ |
|
179 | + public function getAllTaxesForTicket(): array |
|
180 | + { |
|
181 | + return $this->filterModifiersForTicket([$this, 'taxModifierFilter']); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket |
|
187 | + * |
|
188 | + * @param EE_Price $price_modifier |
|
189 | + * @return bool |
|
190 | + * @throws EE_Error |
|
191 | + * @throws ReflectionException |
|
192 | + */ |
|
193 | + public function taxModifierFilter(EE_Price $price_modifier): bool |
|
194 | + { |
|
195 | + return $price_modifier->is_tax(); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * retrieve ALL PRICES that are NOT taxes for the this ticket |
|
201 | + * |
|
202 | + * @return array |
|
203 | + * @throws EE_Error |
|
204 | + * @throws ReflectionException |
|
205 | + */ |
|
206 | + public function getAllNonTaxPricesForTicket(): array |
|
207 | + { |
|
208 | + return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * pass to filterModifiersForTicket() with a ticket |
|
214 | + * to retrieve ALL PRICES that are NOT taxes for the this ticket |
|
215 | + * |
|
216 | + * @param EE_Price $price_modifier |
|
217 | + * @return bool |
|
218 | + * @throws EE_Error |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + public function nonTaxPriceFilter(EE_Price $price_modifier): bool |
|
222 | + { |
|
223 | + return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax(); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * retrieve the base price for the this ticket |
|
229 | + * |
|
230 | + * @return array |
|
231 | + * @throws EE_Error |
|
232 | + * @throws ReflectionException |
|
233 | + */ |
|
234 | + public function getBasePrice(): array |
|
235 | + { |
|
236 | + return $this->filterModifiersForTicket([$this, 'basePriceFilter']); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * pass to filterModifiersForTicket() |
|
242 | + * to retrieve the base price for the this ticket |
|
243 | + * |
|
244 | + * @param EE_Price $price_modifier |
|
245 | + * @return bool |
|
246 | + * @throws EE_Error |
|
247 | + * @throws ReflectionException |
|
248 | + */ |
|
249 | + public function basePriceFilter(EE_Price $price_modifier): bool |
|
250 | + { |
|
251 | + return $price_modifier->is_base_price(); |
|
252 | + } |
|
253 | 253 | } |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | 'LIN_code' |
76 | 76 | ); |
77 | 77 | if ($line_item_code) { |
78 | - if (! isset($this->_line_item_registrations[ $line_item_code ])) { |
|
79 | - $this->_line_item_registrations[ $line_item_code ] = array(); |
|
78 | + if ( ! isset($this->_line_item_registrations[$line_item_code])) { |
|
79 | + $this->_line_item_registrations[$line_item_code] = array(); |
|
80 | 80 | } |
81 | - $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration; |
|
81 | + $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration; |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | public function process(EE_Line_Item $line_item): ?EE_Line_Item |
97 | 97 | { |
98 | 98 | $this->_adjust_line_item_quantity($line_item); |
99 | - if (! $line_item->children()) { |
|
99 | + if ( ! $line_item->children()) { |
|
100 | 100 | return $line_item; |
101 | 101 | } |
102 | 102 | // the original running total (taking ALL tickets into account) |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $child_line_item->set_total( |
124 | 124 | $running_total_of_children_under_consideration * $percent_of_running_total |
125 | 125 | ); |
126 | - if (! $child_line_item->is_percent()) { |
|
126 | + if ( ! $child_line_item->is_percent()) { |
|
127 | 127 | $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
128 | 128 | } |
129 | 129 | } elseif ( |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | $quantity = 0; |
187 | 187 | // if this ticket is billable at this moment, then we should have a positive quantity |
188 | 188 | if ( |
189 | - isset($this->_line_item_registrations[ $line_item->code() ]) |
|
190 | - && is_array($this->_line_item_registrations[ $line_item->code() ]) |
|
189 | + isset($this->_line_item_registrations[$line_item->code()]) |
|
190 | + && is_array($this->_line_item_registrations[$line_item->code()]) |
|
191 | 191 | ) { |
192 | 192 | // set quantity based on number of open registrations for this ticket |
193 | - foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) { |
|
193 | + foreach ($this->_line_item_registrations[$line_item->code()] as $registration) { |
|
194 | 194 | if ( |
195 | 195 | $registration instanceof EE_Registration |
196 | 196 | ) { |
@@ -12,195 +12,195 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base |
14 | 14 | { |
15 | - /** |
|
16 | - * array of line item codes and their corresponding quantities for registrations |
|
17 | - * |
|
18 | - * @type array $_line_item_registrations |
|
19 | - */ |
|
20 | - protected $_line_item_registrations = array(); |
|
15 | + /** |
|
16 | + * array of line item codes and their corresponding quantities for registrations |
|
17 | + * |
|
18 | + * @type array $_line_item_registrations |
|
19 | + */ |
|
20 | + protected $_line_item_registrations = array(); |
|
21 | 21 | |
22 | - /** |
|
23 | - * Just kept in case we want it someday. Currently unused |
|
24 | - * |
|
25 | - * @var EE_Registration[] |
|
26 | - */ |
|
27 | - protected $_registrations = array(); |
|
22 | + /** |
|
23 | + * Just kept in case we want it someday. Currently unused |
|
24 | + * |
|
25 | + * @var EE_Registration[] |
|
26 | + */ |
|
27 | + protected $_registrations = array(); |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var EE_Registration |
|
31 | - */ |
|
32 | - protected $_current_registration; |
|
29 | + /** |
|
30 | + * @var EE_Registration |
|
31 | + */ |
|
32 | + protected $_current_registration; |
|
33 | 33 | |
34 | - /** |
|
35 | - * these reg statuses should NOT increment the line item quantity |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $_closed_reg_statuses = array(); |
|
34 | + /** |
|
35 | + * these reg statuses should NOT increment the line item quantity |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $_closed_reg_statuses = array(); |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * EE_Billable_Line_Item_Filter constructor. |
|
44 | - * |
|
45 | - * @param EE_Registration[] $registrations |
|
46 | - * @throws EE_Error |
|
47 | - * @throws ReflectionException |
|
48 | - */ |
|
49 | - public function __construct(array $registrations) |
|
50 | - { |
|
51 | - $this->_registrations = $registrations; |
|
52 | - $this->_calculate_registrations_per_line_item_code($registrations); |
|
53 | - // these reg statuses should NOT increment the line item quantity |
|
54 | - $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
55 | - } |
|
42 | + /** |
|
43 | + * EE_Billable_Line_Item_Filter constructor. |
|
44 | + * |
|
45 | + * @param EE_Registration[] $registrations |
|
46 | + * @throws EE_Error |
|
47 | + * @throws ReflectionException |
|
48 | + */ |
|
49 | + public function __construct(array $registrations) |
|
50 | + { |
|
51 | + $this->_registrations = $registrations; |
|
52 | + $this->_calculate_registrations_per_line_item_code($registrations); |
|
53 | + // these reg statuses should NOT increment the line item quantity |
|
54 | + $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * sets the _line_item_registrations from the provided registrations |
|
60 | - * |
|
61 | - * @param EE_Registration[] $registrations |
|
62 | - * @return void |
|
63 | - * @throws EE_Error |
|
64 | - * @throws ReflectionException |
|
65 | - */ |
|
66 | - protected function _calculate_registrations_per_line_item_code(array $registrations) |
|
67 | - { |
|
68 | - foreach ($registrations as $registration) { |
|
69 | - $line_item_code = EEM_Line_Item::instance()->get_var( |
|
70 | - EEM_Line_Item::instance()->line_item_for_registration_query_params( |
|
71 | - $registration, |
|
72 | - array('limit' => 1) |
|
73 | - ), |
|
74 | - 'LIN_code' |
|
75 | - ); |
|
76 | - if ($line_item_code) { |
|
77 | - if (! isset($this->_line_item_registrations[ $line_item_code ])) { |
|
78 | - $this->_line_item_registrations[ $line_item_code ] = array(); |
|
79 | - } |
|
80 | - $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration; |
|
81 | - } |
|
82 | - } |
|
83 | - } |
|
58 | + /** |
|
59 | + * sets the _line_item_registrations from the provided registrations |
|
60 | + * |
|
61 | + * @param EE_Registration[] $registrations |
|
62 | + * @return void |
|
63 | + * @throws EE_Error |
|
64 | + * @throws ReflectionException |
|
65 | + */ |
|
66 | + protected function _calculate_registrations_per_line_item_code(array $registrations) |
|
67 | + { |
|
68 | + foreach ($registrations as $registration) { |
|
69 | + $line_item_code = EEM_Line_Item::instance()->get_var( |
|
70 | + EEM_Line_Item::instance()->line_item_for_registration_query_params( |
|
71 | + $registration, |
|
72 | + array('limit' => 1) |
|
73 | + ), |
|
74 | + 'LIN_code' |
|
75 | + ); |
|
76 | + if ($line_item_code) { |
|
77 | + if (! isset($this->_line_item_registrations[ $line_item_code ])) { |
|
78 | + $this->_line_item_registrations[ $line_item_code ] = array(); |
|
79 | + } |
|
80 | + $this->_line_item_registrations[ $line_item_code ][ $registration->ID() ] = $registration; |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | - /** |
|
87 | - * Creates a duplicate of the line item tree, except only includes billable items |
|
88 | - * and the portion of line items attributed to billable things |
|
89 | - * |
|
90 | - * @param EE_Line_Item $line_item |
|
91 | - * @return EE_Line_Item |
|
92 | - * @throws EE_Error |
|
93 | - * @throws ReflectionException |
|
94 | - */ |
|
95 | - public function process(EE_Line_Item $line_item): ?EE_Line_Item |
|
96 | - { |
|
97 | - $this->_adjust_line_item_quantity($line_item); |
|
98 | - if (! $line_item->children()) { |
|
99 | - return $line_item; |
|
100 | - } |
|
101 | - // the original running total (taking ALL tickets into account) |
|
102 | - $running_total_of_children = 0; |
|
103 | - // the new running total (only taking the specified ticket quantities into account) |
|
104 | - $running_total_of_children_under_consideration = 0; |
|
105 | - // let's also track the quantity of tickets that pertain to the registrations |
|
106 | - $total_child_ticket_quantity = 0; |
|
107 | - foreach ($line_item->children() as $child_line_item) { |
|
108 | - $original_li_total = $child_line_item->is_percent() |
|
109 | - ? $running_total_of_children * $child_line_item->percent() / 100 |
|
110 | - : $child_line_item->unit_price() * $child_line_item->quantity(); |
|
111 | - $this->process($child_line_item); |
|
112 | - // If this line item is a normal line item that isn't for a ticket, |
|
113 | - // we want to modify its total (and unit price if not a percentage line item) |
|
114 | - // so it reflects only that portion of the surcharge/discount shared by these registrations |
|
115 | - if ( |
|
116 | - $child_line_item->type() === EEM_Line_Item::type_line_item |
|
117 | - && $child_line_item->OBJ_type() !== 'Ticket' |
|
118 | - ) { |
|
119 | - $percent_of_running_total = $running_total_of_children |
|
120 | - ? $original_li_total / $running_total_of_children |
|
121 | - : 0; |
|
122 | - $child_line_item->set_total( |
|
123 | - $running_total_of_children_under_consideration * $percent_of_running_total |
|
124 | - ); |
|
125 | - if (! $child_line_item->is_percent()) { |
|
126 | - $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
|
127 | - } |
|
128 | - } elseif ( |
|
129 | - // make sure this item's quantity and total matches its parent |
|
130 | - $line_item->type() === EEM_Line_Item::type_line_item |
|
131 | - && $line_item->OBJ_type() === 'Ticket' |
|
132 | - // but not if it's a percentage modifier |
|
133 | - && ! $child_line_item->is_percent() |
|
134 | - && ! ( |
|
135 | - // or a cancellation |
|
136 | - $child_line_item->is_cancelled() |
|
137 | - && ! ( |
|
138 | - // unless it IS a cancellation and the current registration is cancelled |
|
139 | - $child_line_item->is_cancelled() |
|
140 | - && $this->_current_registration instanceof EE_Registration |
|
141 | - && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true) |
|
142 | - ) |
|
143 | - ) |
|
144 | - ) { |
|
145 | - $child_line_item->set_quantity($line_item->quantity()); |
|
146 | - $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity()); |
|
147 | - } elseif ($child_line_item->type() === EEM_Line_Item::type_sub_tax) { |
|
148 | - // add this line item's portion of any directly applied taxes |
|
149 | - $child_line_item->set_quantity($line_item->quantity()); |
|
150 | - $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity()); |
|
151 | - } |
|
152 | - $running_total_of_children += $original_li_total; |
|
153 | - $running_total_of_children_under_consideration += $child_line_item->total(); |
|
154 | - if ($child_line_item->OBJ_type() === 'Ticket') { |
|
155 | - $total_child_ticket_quantity += $child_line_item->quantity(); |
|
156 | - } |
|
157 | - } |
|
158 | - $line_item->set_total($running_total_of_children_under_consideration); |
|
159 | - if ($line_item->quantity()) { |
|
160 | - $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity()); |
|
161 | - } else { |
|
162 | - $line_item->set_unit_price(0); |
|
163 | - } |
|
164 | - if ($line_item->OBJ_type() === 'Event') { |
|
165 | - $line_item->set_quantity($total_child_ticket_quantity); |
|
166 | - } |
|
167 | - return $line_item; |
|
168 | - } |
|
86 | + /** |
|
87 | + * Creates a duplicate of the line item tree, except only includes billable items |
|
88 | + * and the portion of line items attributed to billable things |
|
89 | + * |
|
90 | + * @param EE_Line_Item $line_item |
|
91 | + * @return EE_Line_Item |
|
92 | + * @throws EE_Error |
|
93 | + * @throws ReflectionException |
|
94 | + */ |
|
95 | + public function process(EE_Line_Item $line_item): ?EE_Line_Item |
|
96 | + { |
|
97 | + $this->_adjust_line_item_quantity($line_item); |
|
98 | + if (! $line_item->children()) { |
|
99 | + return $line_item; |
|
100 | + } |
|
101 | + // the original running total (taking ALL tickets into account) |
|
102 | + $running_total_of_children = 0; |
|
103 | + // the new running total (only taking the specified ticket quantities into account) |
|
104 | + $running_total_of_children_under_consideration = 0; |
|
105 | + // let's also track the quantity of tickets that pertain to the registrations |
|
106 | + $total_child_ticket_quantity = 0; |
|
107 | + foreach ($line_item->children() as $child_line_item) { |
|
108 | + $original_li_total = $child_line_item->is_percent() |
|
109 | + ? $running_total_of_children * $child_line_item->percent() / 100 |
|
110 | + : $child_line_item->unit_price() * $child_line_item->quantity(); |
|
111 | + $this->process($child_line_item); |
|
112 | + // If this line item is a normal line item that isn't for a ticket, |
|
113 | + // we want to modify its total (and unit price if not a percentage line item) |
|
114 | + // so it reflects only that portion of the surcharge/discount shared by these registrations |
|
115 | + if ( |
|
116 | + $child_line_item->type() === EEM_Line_Item::type_line_item |
|
117 | + && $child_line_item->OBJ_type() !== 'Ticket' |
|
118 | + ) { |
|
119 | + $percent_of_running_total = $running_total_of_children |
|
120 | + ? $original_li_total / $running_total_of_children |
|
121 | + : 0; |
|
122 | + $child_line_item->set_total( |
|
123 | + $running_total_of_children_under_consideration * $percent_of_running_total |
|
124 | + ); |
|
125 | + if (! $child_line_item->is_percent()) { |
|
126 | + $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity()); |
|
127 | + } |
|
128 | + } elseif ( |
|
129 | + // make sure this item's quantity and total matches its parent |
|
130 | + $line_item->type() === EEM_Line_Item::type_line_item |
|
131 | + && $line_item->OBJ_type() === 'Ticket' |
|
132 | + // but not if it's a percentage modifier |
|
133 | + && ! $child_line_item->is_percent() |
|
134 | + && ! ( |
|
135 | + // or a cancellation |
|
136 | + $child_line_item->is_cancelled() |
|
137 | + && ! ( |
|
138 | + // unless it IS a cancellation and the current registration is cancelled |
|
139 | + $child_line_item->is_cancelled() |
|
140 | + && $this->_current_registration instanceof EE_Registration |
|
141 | + && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true) |
|
142 | + ) |
|
143 | + ) |
|
144 | + ) { |
|
145 | + $child_line_item->set_quantity($line_item->quantity()); |
|
146 | + $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity()); |
|
147 | + } elseif ($child_line_item->type() === EEM_Line_Item::type_sub_tax) { |
|
148 | + // add this line item's portion of any directly applied taxes |
|
149 | + $child_line_item->set_quantity($line_item->quantity()); |
|
150 | + $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity()); |
|
151 | + } |
|
152 | + $running_total_of_children += $original_li_total; |
|
153 | + $running_total_of_children_under_consideration += $child_line_item->total(); |
|
154 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
155 | + $total_child_ticket_quantity += $child_line_item->quantity(); |
|
156 | + } |
|
157 | + } |
|
158 | + $line_item->set_total($running_total_of_children_under_consideration); |
|
159 | + if ($line_item->quantity()) { |
|
160 | + $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity()); |
|
161 | + } else { |
|
162 | + $line_item->set_unit_price(0); |
|
163 | + } |
|
164 | + if ($line_item->OBJ_type() === 'Event') { |
|
165 | + $line_item->set_quantity($total_child_ticket_quantity); |
|
166 | + } |
|
167 | + return $line_item; |
|
168 | + } |
|
169 | 169 | |
170 | 170 | |
171 | - /** |
|
172 | - * Adjusts quantities for line items for tickets according to the registrations provided |
|
173 | - * in the constructor |
|
174 | - * |
|
175 | - * @param EE_Line_Item $line_item |
|
176 | - * @return EE_Line_Item |
|
177 | - * @throws EE_Error |
|
178 | - * @throws ReflectionException |
|
179 | - */ |
|
180 | - protected function _adjust_line_item_quantity(EE_Line_Item $line_item): EE_Line_Item |
|
181 | - { |
|
182 | - // is this a ticket ? |
|
183 | - if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') { |
|
184 | - $this->_current_registration = null; |
|
185 | - $quantity = 0; |
|
186 | - // if this ticket is billable at this moment, then we should have a positive quantity |
|
187 | - if ( |
|
188 | - isset($this->_line_item_registrations[ $line_item->code() ]) |
|
189 | - && is_array($this->_line_item_registrations[ $line_item->code() ]) |
|
190 | - ) { |
|
191 | - // set quantity based on number of open registrations for this ticket |
|
192 | - foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) { |
|
193 | - if ( |
|
194 | - $registration instanceof EE_Registration |
|
195 | - ) { |
|
196 | - $quantity++; |
|
197 | - $this->_current_registration = $registration; |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - $line_item->set_quantity($quantity); |
|
202 | - $line_item->set_total($line_item->unit_price() * $line_item->quantity()); |
|
203 | - } |
|
204 | - return $line_item; |
|
205 | - } |
|
171 | + /** |
|
172 | + * Adjusts quantities for line items for tickets according to the registrations provided |
|
173 | + * in the constructor |
|
174 | + * |
|
175 | + * @param EE_Line_Item $line_item |
|
176 | + * @return EE_Line_Item |
|
177 | + * @throws EE_Error |
|
178 | + * @throws ReflectionException |
|
179 | + */ |
|
180 | + protected function _adjust_line_item_quantity(EE_Line_Item $line_item): EE_Line_Item |
|
181 | + { |
|
182 | + // is this a ticket ? |
|
183 | + if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') { |
|
184 | + $this->_current_registration = null; |
|
185 | + $quantity = 0; |
|
186 | + // if this ticket is billable at this moment, then we should have a positive quantity |
|
187 | + if ( |
|
188 | + isset($this->_line_item_registrations[ $line_item->code() ]) |
|
189 | + && is_array($this->_line_item_registrations[ $line_item->code() ]) |
|
190 | + ) { |
|
191 | + // set quantity based on number of open registrations for this ticket |
|
192 | + foreach ($this->_line_item_registrations[ $line_item->code() ] as $registration) { |
|
193 | + if ( |
|
194 | + $registration instanceof EE_Registration |
|
195 | + ) { |
|
196 | + $quantity++; |
|
197 | + $this->_current_registration = $registration; |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + $line_item->set_quantity($quantity); |
|
202 | + $line_item->set_total($line_item->unit_price() * $line_item->quantity()); |
|
203 | + } |
|
204 | + return $line_item; |
|
205 | + } |
|
206 | 206 | } |
@@ -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 EE_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 EE_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 | } |
@@ -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 5.0.0.p |
|
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 5.0.0.p |
|
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 5.0.0.p |
|
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 5.0.0.p |
|
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 5.0.0.p |
|
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 5.0.0.p |
|
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 |