@@ -362,7 +362,7 @@ |
||
362 | 362 | /** |
363 | 363 | * Posts the request to AuthorizeNet & returns response. |
364 | 364 | * |
365 | - * @param $payment |
|
365 | + * @param EEI_Payment $payment |
|
366 | 366 | * @return \EE_AuthorizeNetAIM_Response |
367 | 367 | */ |
368 | 368 | private function _sendRequest($payment) |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -29,424 +29,424 @@ discard block |
||
29 | 29 | class EEG_Aim extends EE_Onsite_Gateway |
30 | 30 | { |
31 | 31 | |
32 | - const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; //Authnet URL |
|
33 | - |
|
34 | - const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
35 | - |
|
36 | - protected $_login_id; |
|
37 | - |
|
38 | - protected $_transaction_key; |
|
39 | - |
|
40 | - protected $_server; |
|
41 | - |
|
42 | - protected $_currencies_supported = array( |
|
43 | - 'AUD', |
|
44 | - 'USD', |
|
45 | - 'CAD', |
|
46 | - 'EUR', |
|
47 | - 'GBP', |
|
48 | - 'NZD', |
|
49 | - ); |
|
50 | - |
|
51 | - /** |
|
52 | - * Whether to send test transactions (even to live site) |
|
53 | - * |
|
54 | - * @var boolean |
|
55 | - */ |
|
56 | - protected $_test_transactions; |
|
57 | - |
|
58 | - private $VERIFY_PEER = false; |
|
59 | - |
|
60 | - private $_x_post_fields = array( |
|
61 | - "version" => "3.1", |
|
62 | - "delim_char" => ",", |
|
63 | - "delim_data" => "TRUE", |
|
64 | - "relay_response" => "FALSE", |
|
65 | - "encap_char" => "|", |
|
66 | - ); |
|
67 | - |
|
68 | - private $_additional_line_items = array(); |
|
69 | - |
|
70 | - /** |
|
71 | - * A list of all fields in the AIM API. |
|
72 | - * Used to warn user if they try to set a field not offered in the API. |
|
73 | - */ |
|
74 | - private $_all_aim_fields = array( |
|
75 | - "address", |
|
76 | - "allow_partial_auth", |
|
77 | - "amount", |
|
78 | - "auth_code", |
|
79 | - "authentication_indicator", |
|
80 | - "bank_aba_code", |
|
81 | - "bank_acct_name", |
|
82 | - "bank_acct_num", |
|
83 | - "bank_acct_type", |
|
84 | - "bank_check_number", |
|
85 | - "bank_name", |
|
86 | - "card_code", |
|
87 | - "card_num", |
|
88 | - "cardholder_authentication_value", |
|
89 | - "city", |
|
90 | - "company", |
|
91 | - "country", |
|
92 | - "cust_id", |
|
93 | - "customer_ip", |
|
94 | - "delim_char", |
|
95 | - "delim_data", |
|
96 | - "description", |
|
97 | - "duplicate_window", |
|
98 | - "duty", |
|
99 | - "echeck_type", |
|
100 | - "email", |
|
101 | - "email_customer", |
|
102 | - "encap_char", |
|
103 | - "exp_date", |
|
104 | - "fax", |
|
105 | - "first_name", |
|
106 | - "footer_email_receipt", |
|
107 | - "freight", |
|
108 | - "header_email_receipt", |
|
109 | - "invoice_num", |
|
110 | - "last_name", |
|
111 | - "line_item", |
|
112 | - "login", |
|
113 | - "method", |
|
114 | - "phone", |
|
115 | - "po_num", |
|
116 | - "recurring_billing", |
|
117 | - "relay_response", |
|
118 | - "ship_to_address", |
|
119 | - "ship_to_city", |
|
120 | - "ship_to_company", |
|
121 | - "ship_to_country", |
|
122 | - "ship_to_first_name", |
|
123 | - "ship_to_last_name", |
|
124 | - "ship_to_state", |
|
125 | - "ship_to_zip", |
|
126 | - "split_tender_id", |
|
127 | - "state", |
|
128 | - "tax", |
|
129 | - "tax_exempt", |
|
130 | - "test_request", |
|
131 | - "tran_key", |
|
132 | - "trans_id", |
|
133 | - "type", |
|
134 | - "version", |
|
135 | - "zip", |
|
136 | - "solution_id" |
|
137 | - ); |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * Gets the URL where the request should go. This is filterable |
|
142 | - * |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - protected function _get_server_url() |
|
146 | - { |
|
147 | - return apply_filters( |
|
148 | - 'FHEE__EEG_Aim___get_server_url', |
|
149 | - $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
150 | - $this |
|
151 | - ); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * TEMPORARY CALLBACK! Do not use |
|
157 | - * Callback which filters the server url. This is added so site admins can revert to using |
|
158 | - * the old AIM server in case Akamai service breaks their integration. |
|
159 | - * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
160 | - * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
161 | - * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
162 | - * |
|
163 | - * @param string $url |
|
164 | - * @param EEG_Aim $gateway_object |
|
165 | - * @return string |
|
166 | - */ |
|
167 | - public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
168 | - { |
|
169 | - if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
170 | - return 'https://secure.authorize.net/gateway/transact.dll'; |
|
171 | - } else { |
|
172 | - return $url; |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
179 | - * usually send a request directly to the payment provider and update the payment's status based on that; |
|
180 | - * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
181 | - * for sending the request via http_remote_request() |
|
182 | - * |
|
183 | - * @param EEI_Payment $payment |
|
184 | - * @param array $billing_info { |
|
185 | - * @type $credit_card string |
|
186 | - * @type $cvv string |
|
187 | - * @type $exp_month string |
|
188 | - * @type $exp_year string |
|
189 | - * @see parent::do_direct_payment |
|
190 | - * } |
|
191 | - * @return EEI_Payment updated |
|
192 | - */ |
|
193 | - public function do_direct_payment($payment, $billing_info = null) |
|
194 | - { |
|
195 | - add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
196 | - // Enable test mode if needed |
|
197 | - //4007000000027 <-- test successful visa |
|
198 | - //4222222222222 <-- test failure card number |
|
199 | - |
|
200 | - $item_num = 1; |
|
201 | - $transaction = $payment->transaction(); |
|
202 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
203 | - $order_description = $gateway_formatter->formatOrderDescription($payment); |
|
204 | - $primary_registrant = $transaction->primary_registration(); |
|
205 | - //if we're are charging for the full amount, show the normal line items |
|
206 | - //and the itemized total adds up properly |
|
207 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
208 | - $total_line_item = $transaction->total_line_item(); |
|
209 | - foreach ($total_line_item->get_items() as $line_item) { |
|
210 | - if ($line_item->quantity() == 0) { |
|
211 | - continue; |
|
212 | - } |
|
213 | - $this->addLineItem( |
|
214 | - $item_num++, |
|
215 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
216 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
217 | - $line_item->quantity(), |
|
218 | - $line_item->unit_price(), |
|
219 | - 'N' |
|
220 | - ); |
|
221 | - $order_description .= $line_item->desc().', '; |
|
222 | - } |
|
223 | - foreach($total_line_item->tax_descendants() as $tax_line_item) { |
|
224 | - $this->addLineItem( |
|
225 | - $item_num++, |
|
226 | - $tax_line_item->name(), |
|
227 | - $tax_line_item->desc(), |
|
228 | - 1, |
|
229 | - $tax_line_item->total(), |
|
230 | - 'N' |
|
231 | - ); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - //start transaction |
|
236 | - //if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
237 | - $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
238 | - $this->setField('solution_id', $partner_id); |
|
239 | - $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
240 | - $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
241 | - $this->_set_sensitive_billing_data($billing_info); |
|
242 | - $this->setField('first_name', $billing_info['first_name']); |
|
243 | - $this->setField('last_name', $billing_info['last_name']); |
|
244 | - $this->setField('email', $billing_info['email']); |
|
245 | - $this->setField('company', $billing_info['company']); |
|
246 | - $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
247 | - $this->setField('city', $billing_info['city']); |
|
248 | - $this->setField('state', $billing_info['state']); |
|
249 | - $this->setField('country', $billing_info['country']); |
|
250 | - $this->setField('zip', $billing_info['zip']); |
|
251 | - $this->setField('fax', $billing_info['fax']); |
|
252 | - $this->setField('cust_id', $primary_registrant->ID()); |
|
253 | - $this->setField('phone', $billing_info['phone']); |
|
254 | - //invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
255 | - //press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
256 | - //in which case, we need to generate teh invoice num per request right here... |
|
257 | - $this->setField('invoice_num', wp_generate_password(12, false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
258 | - //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
259 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
260 | - |
|
261 | - if ($this->_test_transactions) { |
|
262 | - $this->test_request = "true"; |
|
263 | - } |
|
264 | - |
|
265 | - //Capture response |
|
266 | - $this->type = "AUTH_CAPTURE"; |
|
267 | - $response = $this->_sendRequest($payment); |
|
268 | - if (! empty($response)) { |
|
269 | - if ($response->error_message) { |
|
270 | - $payment->set_status($this->_pay_model->failed_status()); |
|
271 | - $payment->set_gateway_response($response->error_message); |
|
272 | - } else { |
|
273 | - $payment_status = $response->approved |
|
274 | - ? $this->_pay_model->approved_status() |
|
275 | - : $this->_pay_model->declined_status(); |
|
276 | - $payment->set_status($payment_status); |
|
277 | - //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
278 | - $payment->set_amount((float) $response->amount); |
|
279 | - $payment->set_gateway_response( |
|
280 | - sprintf( |
|
281 | - esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
282 | - $response->response_reason_text, |
|
283 | - $response->response_reason_code |
|
284 | - ) |
|
285 | - ); |
|
286 | - if ($this->_debug_mode) { |
|
287 | - $txn_id = $response->invoice_number; |
|
288 | - } else { |
|
289 | - $txn_id = $response->transaction_id; |
|
290 | - } |
|
291 | - $payment->set_txn_id_chq_nmbr($txn_id); |
|
292 | - } |
|
293 | - $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
294 | - $payment->set_details(print_r($response, true)); |
|
295 | - } else { |
|
296 | - $payment->set_status($this->_pay_model->failed_status()); |
|
297 | - $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
298 | - $payment->set_details(print_r($response, true)); |
|
299 | - } |
|
300 | - return $payment; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
306 | - * also this method can be overridden by children classes to easily change |
|
307 | - * what billing data gets sent |
|
308 | - * |
|
309 | - * @param array $billing_info |
|
310 | - */ |
|
311 | - protected function _set_sensitive_billing_data($billing_info) |
|
312 | - { |
|
313 | - $this->setField('card_num', $billing_info['credit_card']); |
|
314 | - $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
315 | - $this->setField('card_code', $billing_info['cvv']); |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * Add a line item. |
|
321 | - * |
|
322 | - * @param string $item_id |
|
323 | - * @param string $item_name |
|
324 | - * @param string $item_description |
|
325 | - * @param string $item_quantity |
|
326 | - * @param string $item_unit_price |
|
327 | - * @param string $item_taxable |
|
328 | - */ |
|
329 | - public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
330 | - { |
|
331 | - $args = array( |
|
332 | - substr($item_id, 0, 31), |
|
333 | - substr($item_name, 0, 31), |
|
334 | - substr($item_description, 0, 255), |
|
335 | - number_format(abs($item_quantity), 2, '.', ''), |
|
336 | - number_format(abs($item_unit_price), 2, '.', ''), |
|
337 | - $item_taxable === 'N' ? 'N' : 'Y' |
|
338 | - ); |
|
339 | - $this->_additional_line_items[] = implode('<|>', $args); |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * Set an individual name/value pair. This will append x_ to the name |
|
345 | - * before posting. |
|
346 | - * |
|
347 | - * @param string $name |
|
348 | - * @param string $value |
|
349 | - * @throws AuthorizeNetException |
|
350 | - */ |
|
351 | - protected function setField($name, $value) |
|
352 | - { |
|
353 | - if (in_array($name, $this->_all_aim_fields)) { |
|
354 | - $this->_x_post_fields[$name] = $value; |
|
355 | - } else { |
|
356 | - throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
32 | + const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; //Authnet URL |
|
33 | + |
|
34 | + const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
35 | + |
|
36 | + protected $_login_id; |
|
37 | + |
|
38 | + protected $_transaction_key; |
|
39 | + |
|
40 | + protected $_server; |
|
41 | + |
|
42 | + protected $_currencies_supported = array( |
|
43 | + 'AUD', |
|
44 | + 'USD', |
|
45 | + 'CAD', |
|
46 | + 'EUR', |
|
47 | + 'GBP', |
|
48 | + 'NZD', |
|
49 | + ); |
|
50 | + |
|
51 | + /** |
|
52 | + * Whether to send test transactions (even to live site) |
|
53 | + * |
|
54 | + * @var boolean |
|
55 | + */ |
|
56 | + protected $_test_transactions; |
|
57 | + |
|
58 | + private $VERIFY_PEER = false; |
|
59 | + |
|
60 | + private $_x_post_fields = array( |
|
61 | + "version" => "3.1", |
|
62 | + "delim_char" => ",", |
|
63 | + "delim_data" => "TRUE", |
|
64 | + "relay_response" => "FALSE", |
|
65 | + "encap_char" => "|", |
|
66 | + ); |
|
67 | + |
|
68 | + private $_additional_line_items = array(); |
|
69 | + |
|
70 | + /** |
|
71 | + * A list of all fields in the AIM API. |
|
72 | + * Used to warn user if they try to set a field not offered in the API. |
|
73 | + */ |
|
74 | + private $_all_aim_fields = array( |
|
75 | + "address", |
|
76 | + "allow_partial_auth", |
|
77 | + "amount", |
|
78 | + "auth_code", |
|
79 | + "authentication_indicator", |
|
80 | + "bank_aba_code", |
|
81 | + "bank_acct_name", |
|
82 | + "bank_acct_num", |
|
83 | + "bank_acct_type", |
|
84 | + "bank_check_number", |
|
85 | + "bank_name", |
|
86 | + "card_code", |
|
87 | + "card_num", |
|
88 | + "cardholder_authentication_value", |
|
89 | + "city", |
|
90 | + "company", |
|
91 | + "country", |
|
92 | + "cust_id", |
|
93 | + "customer_ip", |
|
94 | + "delim_char", |
|
95 | + "delim_data", |
|
96 | + "description", |
|
97 | + "duplicate_window", |
|
98 | + "duty", |
|
99 | + "echeck_type", |
|
100 | + "email", |
|
101 | + "email_customer", |
|
102 | + "encap_char", |
|
103 | + "exp_date", |
|
104 | + "fax", |
|
105 | + "first_name", |
|
106 | + "footer_email_receipt", |
|
107 | + "freight", |
|
108 | + "header_email_receipt", |
|
109 | + "invoice_num", |
|
110 | + "last_name", |
|
111 | + "line_item", |
|
112 | + "login", |
|
113 | + "method", |
|
114 | + "phone", |
|
115 | + "po_num", |
|
116 | + "recurring_billing", |
|
117 | + "relay_response", |
|
118 | + "ship_to_address", |
|
119 | + "ship_to_city", |
|
120 | + "ship_to_company", |
|
121 | + "ship_to_country", |
|
122 | + "ship_to_first_name", |
|
123 | + "ship_to_last_name", |
|
124 | + "ship_to_state", |
|
125 | + "ship_to_zip", |
|
126 | + "split_tender_id", |
|
127 | + "state", |
|
128 | + "tax", |
|
129 | + "tax_exempt", |
|
130 | + "test_request", |
|
131 | + "tran_key", |
|
132 | + "trans_id", |
|
133 | + "type", |
|
134 | + "version", |
|
135 | + "zip", |
|
136 | + "solution_id" |
|
137 | + ); |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * Gets the URL where the request should go. This is filterable |
|
142 | + * |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + protected function _get_server_url() |
|
146 | + { |
|
147 | + return apply_filters( |
|
148 | + 'FHEE__EEG_Aim___get_server_url', |
|
149 | + $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
150 | + $this |
|
151 | + ); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * TEMPORARY CALLBACK! Do not use |
|
157 | + * Callback which filters the server url. This is added so site admins can revert to using |
|
158 | + * the old AIM server in case Akamai service breaks their integration. |
|
159 | + * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
160 | + * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
161 | + * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
162 | + * |
|
163 | + * @param string $url |
|
164 | + * @param EEG_Aim $gateway_object |
|
165 | + * @return string |
|
166 | + */ |
|
167 | + public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
168 | + { |
|
169 | + if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
170 | + return 'https://secure.authorize.net/gateway/transact.dll'; |
|
171 | + } else { |
|
172 | + return $url; |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
179 | + * usually send a request directly to the payment provider and update the payment's status based on that; |
|
180 | + * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
181 | + * for sending the request via http_remote_request() |
|
182 | + * |
|
183 | + * @param EEI_Payment $payment |
|
184 | + * @param array $billing_info { |
|
185 | + * @type $credit_card string |
|
186 | + * @type $cvv string |
|
187 | + * @type $exp_month string |
|
188 | + * @type $exp_year string |
|
189 | + * @see parent::do_direct_payment |
|
190 | + * } |
|
191 | + * @return EEI_Payment updated |
|
192 | + */ |
|
193 | + public function do_direct_payment($payment, $billing_info = null) |
|
194 | + { |
|
195 | + add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
196 | + // Enable test mode if needed |
|
197 | + //4007000000027 <-- test successful visa |
|
198 | + //4222222222222 <-- test failure card number |
|
199 | + |
|
200 | + $item_num = 1; |
|
201 | + $transaction = $payment->transaction(); |
|
202 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
203 | + $order_description = $gateway_formatter->formatOrderDescription($payment); |
|
204 | + $primary_registrant = $transaction->primary_registration(); |
|
205 | + //if we're are charging for the full amount, show the normal line items |
|
206 | + //and the itemized total adds up properly |
|
207 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
208 | + $total_line_item = $transaction->total_line_item(); |
|
209 | + foreach ($total_line_item->get_items() as $line_item) { |
|
210 | + if ($line_item->quantity() == 0) { |
|
211 | + continue; |
|
212 | + } |
|
213 | + $this->addLineItem( |
|
214 | + $item_num++, |
|
215 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
216 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
217 | + $line_item->quantity(), |
|
218 | + $line_item->unit_price(), |
|
219 | + 'N' |
|
220 | + ); |
|
221 | + $order_description .= $line_item->desc().', '; |
|
222 | + } |
|
223 | + foreach($total_line_item->tax_descendants() as $tax_line_item) { |
|
224 | + $this->addLineItem( |
|
225 | + $item_num++, |
|
226 | + $tax_line_item->name(), |
|
227 | + $tax_line_item->desc(), |
|
228 | + 1, |
|
229 | + $tax_line_item->total(), |
|
230 | + 'N' |
|
231 | + ); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + //start transaction |
|
236 | + //if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
237 | + $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
238 | + $this->setField('solution_id', $partner_id); |
|
239 | + $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
240 | + $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
241 | + $this->_set_sensitive_billing_data($billing_info); |
|
242 | + $this->setField('first_name', $billing_info['first_name']); |
|
243 | + $this->setField('last_name', $billing_info['last_name']); |
|
244 | + $this->setField('email', $billing_info['email']); |
|
245 | + $this->setField('company', $billing_info['company']); |
|
246 | + $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
247 | + $this->setField('city', $billing_info['city']); |
|
248 | + $this->setField('state', $billing_info['state']); |
|
249 | + $this->setField('country', $billing_info['country']); |
|
250 | + $this->setField('zip', $billing_info['zip']); |
|
251 | + $this->setField('fax', $billing_info['fax']); |
|
252 | + $this->setField('cust_id', $primary_registrant->ID()); |
|
253 | + $this->setField('phone', $billing_info['phone']); |
|
254 | + //invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
255 | + //press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
256 | + //in which case, we need to generate teh invoice num per request right here... |
|
257 | + $this->setField('invoice_num', wp_generate_password(12, false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
258 | + //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
259 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
260 | + |
|
261 | + if ($this->_test_transactions) { |
|
262 | + $this->test_request = "true"; |
|
263 | + } |
|
264 | + |
|
265 | + //Capture response |
|
266 | + $this->type = "AUTH_CAPTURE"; |
|
267 | + $response = $this->_sendRequest($payment); |
|
268 | + if (! empty($response)) { |
|
269 | + if ($response->error_message) { |
|
270 | + $payment->set_status($this->_pay_model->failed_status()); |
|
271 | + $payment->set_gateway_response($response->error_message); |
|
272 | + } else { |
|
273 | + $payment_status = $response->approved |
|
274 | + ? $this->_pay_model->approved_status() |
|
275 | + : $this->_pay_model->declined_status(); |
|
276 | + $payment->set_status($payment_status); |
|
277 | + //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
278 | + $payment->set_amount((float) $response->amount); |
|
279 | + $payment->set_gateway_response( |
|
280 | + sprintf( |
|
281 | + esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
282 | + $response->response_reason_text, |
|
283 | + $response->response_reason_code |
|
284 | + ) |
|
285 | + ); |
|
286 | + if ($this->_debug_mode) { |
|
287 | + $txn_id = $response->invoice_number; |
|
288 | + } else { |
|
289 | + $txn_id = $response->transaction_id; |
|
290 | + } |
|
291 | + $payment->set_txn_id_chq_nmbr($txn_id); |
|
292 | + } |
|
293 | + $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
294 | + $payment->set_details(print_r($response, true)); |
|
295 | + } else { |
|
296 | + $payment->set_status($this->_pay_model->failed_status()); |
|
297 | + $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
298 | + $payment->set_details(print_r($response, true)); |
|
299 | + } |
|
300 | + return $payment; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
306 | + * also this method can be overridden by children classes to easily change |
|
307 | + * what billing data gets sent |
|
308 | + * |
|
309 | + * @param array $billing_info |
|
310 | + */ |
|
311 | + protected function _set_sensitive_billing_data($billing_info) |
|
312 | + { |
|
313 | + $this->setField('card_num', $billing_info['credit_card']); |
|
314 | + $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
315 | + $this->setField('card_code', $billing_info['cvv']); |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * Add a line item. |
|
321 | + * |
|
322 | + * @param string $item_id |
|
323 | + * @param string $item_name |
|
324 | + * @param string $item_description |
|
325 | + * @param string $item_quantity |
|
326 | + * @param string $item_unit_price |
|
327 | + * @param string $item_taxable |
|
328 | + */ |
|
329 | + public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
330 | + { |
|
331 | + $args = array( |
|
332 | + substr($item_id, 0, 31), |
|
333 | + substr($item_name, 0, 31), |
|
334 | + substr($item_description, 0, 255), |
|
335 | + number_format(abs($item_quantity), 2, '.', ''), |
|
336 | + number_format(abs($item_unit_price), 2, '.', ''), |
|
337 | + $item_taxable === 'N' ? 'N' : 'Y' |
|
338 | + ); |
|
339 | + $this->_additional_line_items[] = implode('<|>', $args); |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * Set an individual name/value pair. This will append x_ to the name |
|
345 | + * before posting. |
|
346 | + * |
|
347 | + * @param string $name |
|
348 | + * @param string $value |
|
349 | + * @throws AuthorizeNetException |
|
350 | + */ |
|
351 | + protected function setField($name, $value) |
|
352 | + { |
|
353 | + if (in_array($name, $this->_all_aim_fields)) { |
|
354 | + $this->_x_post_fields[$name] = $value; |
|
355 | + } else { |
|
356 | + throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
357 | 357 | To set a custom field use setCustomField('field','value') instead."); |
358 | - } |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * Posts the request to AuthorizeNet & returns response. |
|
364 | - * |
|
365 | - * @param $payment |
|
366 | - * @return \EE_AuthorizeNetAIM_Response |
|
367 | - */ |
|
368 | - private function _sendRequest($payment) |
|
369 | - { |
|
370 | - $this->_x_post_fields['login'] = $this->_login_id; |
|
371 | - $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
372 | - $x_keys = array(); |
|
373 | - foreach ($this->_x_post_fields as $key => $value) { |
|
374 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
375 | - } |
|
376 | - // Add line items |
|
377 | - foreach ($this->_additional_line_items as $key => $value) { |
|
378 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
379 | - } |
|
380 | - $this->_log_clean_request($x_keys, $payment); |
|
381 | - $post_url = $this->_get_server_url(); |
|
382 | - $curl_request = curl_init($post_url); |
|
383 | - $post_body = implode("&", $x_keys); |
|
384 | - curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
385 | - curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
386 | - curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
387 | - curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
388 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
389 | - if ($this->VERIFY_PEER) { |
|
390 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
391 | - } else { |
|
392 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
393 | - } |
|
394 | - |
|
395 | - if (preg_match('/xml/', $post_url)) { |
|
396 | - curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
|
397 | - } |
|
398 | - |
|
399 | - $response = curl_exec($curl_request); |
|
400 | - |
|
401 | - curl_close($curl_request); |
|
402 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
403 | - |
|
404 | - return $this->_log_and_clean_response($response_obj, $payment); |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Logs the clean data only |
|
410 | - * |
|
411 | - * @param array $request_array |
|
412 | - * @param EEI_Payment $payment |
|
413 | - */ |
|
414 | - protected function _log_clean_request($request_array, $payment) |
|
415 | - { |
|
416 | - $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
417 | - foreach ($request_array as $index => $keyvaltogether) { |
|
418 | - foreach ($keys_to_filter_out as $key) { |
|
419 | - if (strpos($keyvaltogether, $key) === 0) { |
|
420 | - //found it at the first character |
|
421 | - //so its one of them |
|
422 | - unset($request_array[$index]); |
|
423 | - } |
|
424 | - } |
|
425 | - } |
|
426 | - $this->log( |
|
427 | - array( |
|
428 | - 'AIM Request sent:' => $request_array, |
|
429 | - 'Server URL' => $this->_get_server_url() |
|
430 | - ), |
|
431 | - $payment |
|
432 | - ); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * Logs the response and cleans it |
|
439 | - * |
|
440 | - * @param EE_AuthorizeNetAIM_Response $response_obj |
|
441 | - * @param EE_Payment $payment |
|
442 | - * @return \EE_AuthorizeNetAIM_Response |
|
443 | - */ |
|
444 | - private function _log_and_clean_response($response_obj, $payment) |
|
445 | - { |
|
446 | - $response_obj->account_number = ''; |
|
447 | - $this->log(array('AIM Response received:' => (array)$response_obj), $payment); |
|
448 | - return $response_obj; |
|
449 | - } |
|
358 | + } |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * Posts the request to AuthorizeNet & returns response. |
|
364 | + * |
|
365 | + * @param $payment |
|
366 | + * @return \EE_AuthorizeNetAIM_Response |
|
367 | + */ |
|
368 | + private function _sendRequest($payment) |
|
369 | + { |
|
370 | + $this->_x_post_fields['login'] = $this->_login_id; |
|
371 | + $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
372 | + $x_keys = array(); |
|
373 | + foreach ($this->_x_post_fields as $key => $value) { |
|
374 | + $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
375 | + } |
|
376 | + // Add line items |
|
377 | + foreach ($this->_additional_line_items as $key => $value) { |
|
378 | + $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
379 | + } |
|
380 | + $this->_log_clean_request($x_keys, $payment); |
|
381 | + $post_url = $this->_get_server_url(); |
|
382 | + $curl_request = curl_init($post_url); |
|
383 | + $post_body = implode("&", $x_keys); |
|
384 | + curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
385 | + curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
386 | + curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
387 | + curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
388 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
389 | + if ($this->VERIFY_PEER) { |
|
390 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
391 | + } else { |
|
392 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
393 | + } |
|
394 | + |
|
395 | + if (preg_match('/xml/', $post_url)) { |
|
396 | + curl_setopt($curl_request, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml")); |
|
397 | + } |
|
398 | + |
|
399 | + $response = curl_exec($curl_request); |
|
400 | + |
|
401 | + curl_close($curl_request); |
|
402 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
403 | + |
|
404 | + return $this->_log_and_clean_response($response_obj, $payment); |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Logs the clean data only |
|
410 | + * |
|
411 | + * @param array $request_array |
|
412 | + * @param EEI_Payment $payment |
|
413 | + */ |
|
414 | + protected function _log_clean_request($request_array, $payment) |
|
415 | + { |
|
416 | + $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
417 | + foreach ($request_array as $index => $keyvaltogether) { |
|
418 | + foreach ($keys_to_filter_out as $key) { |
|
419 | + if (strpos($keyvaltogether, $key) === 0) { |
|
420 | + //found it at the first character |
|
421 | + //so its one of them |
|
422 | + unset($request_array[$index]); |
|
423 | + } |
|
424 | + } |
|
425 | + } |
|
426 | + $this->log( |
|
427 | + array( |
|
428 | + 'AIM Request sent:' => $request_array, |
|
429 | + 'Server URL' => $this->_get_server_url() |
|
430 | + ), |
|
431 | + $payment |
|
432 | + ); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * Logs the response and cleans it |
|
439 | + * |
|
440 | + * @param EE_AuthorizeNetAIM_Response $response_obj |
|
441 | + * @param EE_Payment $payment |
|
442 | + * @return \EE_AuthorizeNetAIM_Response |
|
443 | + */ |
|
444 | + private function _log_and_clean_response($response_obj, $payment) |
|
445 | + { |
|
446 | + $response_obj->account_number = ''; |
|
447 | + $this->log(array('AIM Response received:' => (array)$response_obj), $payment); |
|
448 | + return $response_obj; |
|
449 | + } |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | |
@@ -462,193 +462,193 @@ discard block |
||
462 | 462 | class EE_AuthorizeNetAIM_Response |
463 | 463 | { |
464 | 464 | |
465 | - const APPROVED = '1'; |
|
466 | - const DECLINED = '2'; |
|
467 | - const ERROR = '3'; |
|
468 | - const HELD = '4'; |
|
469 | - |
|
470 | - protected $_x_post_fields = array( |
|
471 | - "version" => "3.1", |
|
472 | - "delim_char" => ",", |
|
473 | - "delim_data" => "TRUE", |
|
474 | - "relay_response" => "FALSE", |
|
475 | - "encap_char" => "|", |
|
476 | - ); |
|
477 | - public $approved; |
|
478 | - public $declined; |
|
479 | - public $error; |
|
480 | - public $held; |
|
481 | - public $response_code; |
|
482 | - public $response_subcode; |
|
483 | - public $response_reason_code; |
|
484 | - public $response_reason_text; |
|
485 | - public $authorization_code; |
|
486 | - public $avs_response; |
|
487 | - public $transaction_id; |
|
488 | - public $invoice_number; |
|
489 | - public $description; |
|
490 | - public $amount; |
|
491 | - public $method; |
|
492 | - public $transaction_type; |
|
493 | - public $customer_id; |
|
494 | - public $first_name; |
|
495 | - public $last_name; |
|
496 | - public $company; |
|
497 | - public $address; |
|
498 | - public $city; |
|
499 | - public $state; |
|
500 | - public $zip_code; |
|
501 | - public $country; |
|
502 | - public $phone; |
|
503 | - public $fax; |
|
504 | - public $email_address; |
|
505 | - public $ship_to_first_name; |
|
506 | - public $ship_to_last_name; |
|
507 | - public $ship_to_company; |
|
508 | - public $ship_to_address; |
|
509 | - public $ship_to_city; |
|
510 | - public $ship_to_state; |
|
511 | - public $ship_to_zip_code; |
|
512 | - public $ship_to_country; |
|
513 | - public $tax; |
|
514 | - public $duty; |
|
515 | - public $freight; |
|
516 | - public $tax_exempt; |
|
517 | - public $purchase_order_number; |
|
518 | - public $md5_hash; |
|
519 | - public $card_code_response; |
|
520 | - public $cavv_response; // cardholder_authentication_verification_response |
|
521 | - public $account_number; |
|
522 | - public $card_type; |
|
523 | - public $split_tender_id; |
|
524 | - public $requested_amount; |
|
525 | - public $balance_on_card; |
|
526 | - public $response; // The response string from AuthorizeNet. |
|
527 | - public $error_message; |
|
528 | - private $_response_array = array(); // An array with the split response. |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * Constructor. Parses the AuthorizeNet response string |
|
533 | - * |
|
534 | - * @param string $response The response from the AuthNet server. |
|
535 | - * @var string $delimiter The delimiter used (default is ",") |
|
536 | - * @var string $encap_char The encap_char used (default is "|") |
|
537 | - * @var array $custom_fields Any custom fields set in the request. |
|
538 | - */ |
|
539 | - |
|
540 | - public function __construct($response) |
|
541 | - { |
|
542 | - $encap_char = $this->_x_post_fields['encap_char']; |
|
543 | - $delimiter = $this->_x_post_fields['delim_char']; |
|
544 | - if ($response) { |
|
545 | - // Split Array |
|
546 | - $this->response = $response; |
|
547 | - if ($encap_char) { |
|
548 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
549 | - } else { |
|
550 | - $this->_response_array = explode($delimiter, $response); |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * If AuthorizeNet doesn't return a delimited response. |
|
555 | - */ |
|
556 | - if (count($this->_response_array) < 10) { |
|
557 | - $this->approved = false; |
|
558 | - $this->error = true; |
|
559 | - $this->error_message = sprintf( |
|
560 | - esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
561 | - esc_html($response) |
|
562 | - ); |
|
563 | - return; |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - |
|
568 | - // Set all fields |
|
569 | - $this->response_code = $this->_response_array[0]; |
|
570 | - $this->response_subcode = $this->_response_array[1]; |
|
571 | - $this->response_reason_code = $this->_response_array[2]; |
|
572 | - $this->response_reason_text = $this->_response_array[3]; |
|
573 | - $this->authorization_code = $this->_response_array[4]; |
|
574 | - $this->avs_response = $this->_response_array[5]; |
|
575 | - $this->transaction_id = $this->_response_array[6]; |
|
576 | - $this->invoice_number = $this->_response_array[7]; |
|
577 | - $this->description = $this->_response_array[8]; |
|
578 | - $this->amount = $this->_response_array[9]; |
|
579 | - $this->method = $this->_response_array[10]; |
|
580 | - $this->transaction_type = $this->_response_array[11]; |
|
581 | - $this->customer_id = $this->_response_array[12]; |
|
582 | - $this->first_name = $this->_response_array[13]; |
|
583 | - $this->last_name = $this->_response_array[14]; |
|
584 | - $this->company = $this->_response_array[15]; |
|
585 | - $this->address = $this->_response_array[16]; |
|
586 | - $this->city = $this->_response_array[17]; |
|
587 | - $this->state = $this->_response_array[18]; |
|
588 | - $this->zip_code = $this->_response_array[19]; |
|
589 | - $this->country = $this->_response_array[20]; |
|
590 | - $this->phone = $this->_response_array[21]; |
|
591 | - $this->fax = $this->_response_array[22]; |
|
592 | - $this->email_address = $this->_response_array[23]; |
|
593 | - $this->ship_to_first_name = $this->_response_array[24]; |
|
594 | - $this->ship_to_last_name = $this->_response_array[25]; |
|
595 | - $this->ship_to_company = $this->_response_array[26]; |
|
596 | - $this->ship_to_address = $this->_response_array[27]; |
|
597 | - $this->ship_to_city = $this->_response_array[28]; |
|
598 | - $this->ship_to_state = $this->_response_array[29]; |
|
599 | - $this->ship_to_zip_code = $this->_response_array[30]; |
|
600 | - $this->ship_to_country = $this->_response_array[31]; |
|
601 | - $this->tax = $this->_response_array[32]; |
|
602 | - $this->duty = $this->_response_array[33]; |
|
603 | - $this->freight = $this->_response_array[34]; |
|
604 | - $this->tax_exempt = $this->_response_array[35]; |
|
605 | - $this->purchase_order_number = $this->_response_array[36]; |
|
606 | - $this->md5_hash = $this->_response_array[37]; |
|
607 | - $this->card_code_response = $this->_response_array[38]; |
|
608 | - $this->cavv_response = $this->_response_array[39]; |
|
609 | - $this->account_number = $this->_response_array[50]; |
|
610 | - $this->card_type = $this->_response_array[51]; |
|
611 | - $this->split_tender_id = $this->_response_array[52]; |
|
612 | - $this->requested_amount = $this->_response_array[53]; |
|
613 | - $this->balance_on_card = $this->_response_array[54]; |
|
614 | - |
|
615 | - $this->approved = ($this->response_code === self::APPROVED); |
|
616 | - $this->declined = ($this->response_code === self::DECLINED); |
|
617 | - $this->error = ($this->response_code === self::ERROR); |
|
618 | - $this->held = ($this->response_code === self::HELD); |
|
619 | - } else { |
|
620 | - $this->approved = false; |
|
621 | - $this->error = true; |
|
622 | - $this->error_message = esc_html__( |
|
623 | - 'Error connecting to Authorize.net', |
|
624 | - 'event_espresso' |
|
625 | - ); |
|
626 | - } |
|
627 | - } |
|
465 | + const APPROVED = '1'; |
|
466 | + const DECLINED = '2'; |
|
467 | + const ERROR = '3'; |
|
468 | + const HELD = '4'; |
|
469 | + |
|
470 | + protected $_x_post_fields = array( |
|
471 | + "version" => "3.1", |
|
472 | + "delim_char" => ",", |
|
473 | + "delim_data" => "TRUE", |
|
474 | + "relay_response" => "FALSE", |
|
475 | + "encap_char" => "|", |
|
476 | + ); |
|
477 | + public $approved; |
|
478 | + public $declined; |
|
479 | + public $error; |
|
480 | + public $held; |
|
481 | + public $response_code; |
|
482 | + public $response_subcode; |
|
483 | + public $response_reason_code; |
|
484 | + public $response_reason_text; |
|
485 | + public $authorization_code; |
|
486 | + public $avs_response; |
|
487 | + public $transaction_id; |
|
488 | + public $invoice_number; |
|
489 | + public $description; |
|
490 | + public $amount; |
|
491 | + public $method; |
|
492 | + public $transaction_type; |
|
493 | + public $customer_id; |
|
494 | + public $first_name; |
|
495 | + public $last_name; |
|
496 | + public $company; |
|
497 | + public $address; |
|
498 | + public $city; |
|
499 | + public $state; |
|
500 | + public $zip_code; |
|
501 | + public $country; |
|
502 | + public $phone; |
|
503 | + public $fax; |
|
504 | + public $email_address; |
|
505 | + public $ship_to_first_name; |
|
506 | + public $ship_to_last_name; |
|
507 | + public $ship_to_company; |
|
508 | + public $ship_to_address; |
|
509 | + public $ship_to_city; |
|
510 | + public $ship_to_state; |
|
511 | + public $ship_to_zip_code; |
|
512 | + public $ship_to_country; |
|
513 | + public $tax; |
|
514 | + public $duty; |
|
515 | + public $freight; |
|
516 | + public $tax_exempt; |
|
517 | + public $purchase_order_number; |
|
518 | + public $md5_hash; |
|
519 | + public $card_code_response; |
|
520 | + public $cavv_response; // cardholder_authentication_verification_response |
|
521 | + public $account_number; |
|
522 | + public $card_type; |
|
523 | + public $split_tender_id; |
|
524 | + public $requested_amount; |
|
525 | + public $balance_on_card; |
|
526 | + public $response; // The response string from AuthorizeNet. |
|
527 | + public $error_message; |
|
528 | + private $_response_array = array(); // An array with the split response. |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * Constructor. Parses the AuthorizeNet response string |
|
533 | + * |
|
534 | + * @param string $response The response from the AuthNet server. |
|
535 | + * @var string $delimiter The delimiter used (default is ",") |
|
536 | + * @var string $encap_char The encap_char used (default is "|") |
|
537 | + * @var array $custom_fields Any custom fields set in the request. |
|
538 | + */ |
|
539 | + |
|
540 | + public function __construct($response) |
|
541 | + { |
|
542 | + $encap_char = $this->_x_post_fields['encap_char']; |
|
543 | + $delimiter = $this->_x_post_fields['delim_char']; |
|
544 | + if ($response) { |
|
545 | + // Split Array |
|
546 | + $this->response = $response; |
|
547 | + if ($encap_char) { |
|
548 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
549 | + } else { |
|
550 | + $this->_response_array = explode($delimiter, $response); |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * If AuthorizeNet doesn't return a delimited response. |
|
555 | + */ |
|
556 | + if (count($this->_response_array) < 10) { |
|
557 | + $this->approved = false; |
|
558 | + $this->error = true; |
|
559 | + $this->error_message = sprintf( |
|
560 | + esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
561 | + esc_html($response) |
|
562 | + ); |
|
563 | + return; |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + |
|
568 | + // Set all fields |
|
569 | + $this->response_code = $this->_response_array[0]; |
|
570 | + $this->response_subcode = $this->_response_array[1]; |
|
571 | + $this->response_reason_code = $this->_response_array[2]; |
|
572 | + $this->response_reason_text = $this->_response_array[3]; |
|
573 | + $this->authorization_code = $this->_response_array[4]; |
|
574 | + $this->avs_response = $this->_response_array[5]; |
|
575 | + $this->transaction_id = $this->_response_array[6]; |
|
576 | + $this->invoice_number = $this->_response_array[7]; |
|
577 | + $this->description = $this->_response_array[8]; |
|
578 | + $this->amount = $this->_response_array[9]; |
|
579 | + $this->method = $this->_response_array[10]; |
|
580 | + $this->transaction_type = $this->_response_array[11]; |
|
581 | + $this->customer_id = $this->_response_array[12]; |
|
582 | + $this->first_name = $this->_response_array[13]; |
|
583 | + $this->last_name = $this->_response_array[14]; |
|
584 | + $this->company = $this->_response_array[15]; |
|
585 | + $this->address = $this->_response_array[16]; |
|
586 | + $this->city = $this->_response_array[17]; |
|
587 | + $this->state = $this->_response_array[18]; |
|
588 | + $this->zip_code = $this->_response_array[19]; |
|
589 | + $this->country = $this->_response_array[20]; |
|
590 | + $this->phone = $this->_response_array[21]; |
|
591 | + $this->fax = $this->_response_array[22]; |
|
592 | + $this->email_address = $this->_response_array[23]; |
|
593 | + $this->ship_to_first_name = $this->_response_array[24]; |
|
594 | + $this->ship_to_last_name = $this->_response_array[25]; |
|
595 | + $this->ship_to_company = $this->_response_array[26]; |
|
596 | + $this->ship_to_address = $this->_response_array[27]; |
|
597 | + $this->ship_to_city = $this->_response_array[28]; |
|
598 | + $this->ship_to_state = $this->_response_array[29]; |
|
599 | + $this->ship_to_zip_code = $this->_response_array[30]; |
|
600 | + $this->ship_to_country = $this->_response_array[31]; |
|
601 | + $this->tax = $this->_response_array[32]; |
|
602 | + $this->duty = $this->_response_array[33]; |
|
603 | + $this->freight = $this->_response_array[34]; |
|
604 | + $this->tax_exempt = $this->_response_array[35]; |
|
605 | + $this->purchase_order_number = $this->_response_array[36]; |
|
606 | + $this->md5_hash = $this->_response_array[37]; |
|
607 | + $this->card_code_response = $this->_response_array[38]; |
|
608 | + $this->cavv_response = $this->_response_array[39]; |
|
609 | + $this->account_number = $this->_response_array[50]; |
|
610 | + $this->card_type = $this->_response_array[51]; |
|
611 | + $this->split_tender_id = $this->_response_array[52]; |
|
612 | + $this->requested_amount = $this->_response_array[53]; |
|
613 | + $this->balance_on_card = $this->_response_array[54]; |
|
614 | + |
|
615 | + $this->approved = ($this->response_code === self::APPROVED); |
|
616 | + $this->declined = ($this->response_code === self::DECLINED); |
|
617 | + $this->error = ($this->response_code === self::ERROR); |
|
618 | + $this->held = ($this->response_code === self::HELD); |
|
619 | + } else { |
|
620 | + $this->approved = false; |
|
621 | + $this->error = true; |
|
622 | + $this->error_message = esc_html__( |
|
623 | + 'Error connecting to Authorize.net', |
|
624 | + 'event_espresso' |
|
625 | + ); |
|
626 | + } |
|
627 | + } |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | if (! class_exists('AuthorizeNetException')) { |
631 | - /** |
|
632 | - * Class AuthorizeNetException |
|
633 | - * |
|
634 | - * @package AuthorizeNet |
|
635 | - */ |
|
636 | - class AuthorizeNetException extends Exception |
|
637 | - { |
|
638 | - |
|
639 | - /** |
|
640 | - * Construct the exception. Note: The message is NOT binary safe. |
|
641 | - * |
|
642 | - * @link http://php.net/manual/en/exception.construct.php |
|
643 | - * @param string $message [optional] The Exception message to throw. |
|
644 | - * @param int $code [optional] The Exception code. |
|
645 | - * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
646 | - * @since 5.1.0 |
|
647 | - */ |
|
648 | - public function __construct($message = "", $code = 0, Exception $previous = null) |
|
649 | - { |
|
650 | - parent::__construct($message, $code, $previous); |
|
651 | - } |
|
652 | - } |
|
631 | + /** |
|
632 | + * Class AuthorizeNetException |
|
633 | + * |
|
634 | + * @package AuthorizeNet |
|
635 | + */ |
|
636 | + class AuthorizeNetException extends Exception |
|
637 | + { |
|
638 | + |
|
639 | + /** |
|
640 | + * Construct the exception. Note: The message is NOT binary safe. |
|
641 | + * |
|
642 | + * @link http://php.net/manual/en/exception.construct.php |
|
643 | + * @param string $message [optional] The Exception message to throw. |
|
644 | + * @param int $code [optional] The Exception code. |
|
645 | + * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
646 | + * @since 5.1.0 |
|
647 | + */ |
|
648 | + public function __construct($message = "", $code = 0, Exception $previous = null) |
|
649 | + { |
|
650 | + parent::__construct($message, $code, $previous); |
|
651 | + } |
|
652 | + } |
|
653 | 653 | } |
654 | 654 | // End of file EEG_Aim.gateway.php |
655 | 655 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | ); |
221 | 221 | $order_description .= $line_item->desc().', '; |
222 | 222 | } |
223 | - foreach($total_line_item->tax_descendants() as $tax_line_item) { |
|
223 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
224 | 224 | $this->addLineItem( |
225 | 225 | $item_num++, |
226 | 226 | $tax_line_item->name(), |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | //invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
255 | 255 | //press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
256 | 256 | //in which case, we need to generate teh invoice num per request right here... |
257 | - $this->setField('invoice_num', wp_generate_password(12, false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
257 | + $this->setField('invoice_num', wp_generate_password(12, false)); //$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
258 | 258 | //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
259 | 259 | $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
260 | 260 | |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | //Capture response |
266 | 266 | $this->type = "AUTH_CAPTURE"; |
267 | 267 | $response = $this->_sendRequest($payment); |
268 | - if (! empty($response)) { |
|
268 | + if ( ! empty($response)) { |
|
269 | 269 | if ($response->error_message) { |
270 | 270 | $payment->set_status($this->_pay_model->failed_status()); |
271 | 271 | $payment->set_gateway_response($response->error_message); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | protected function _set_sensitive_billing_data($billing_info) |
312 | 312 | { |
313 | 313 | $this->setField('card_num', $billing_info['credit_card']); |
314 | - $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
314 | + $this->setField('exp_date', $billing_info['exp_month'].$billing_info['exp_year']); |
|
315 | 315 | $this->setField('card_code', $billing_info['cvv']); |
316 | 316 | } |
317 | 317 | |
@@ -371,11 +371,11 @@ discard block |
||
371 | 371 | $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
372 | 372 | $x_keys = array(); |
373 | 373 | foreach ($this->_x_post_fields as $key => $value) { |
374 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
374 | + $x_keys[] = "x_$key=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
375 | 375 | } |
376 | 376 | // Add line items |
377 | 377 | foreach ($this->_additional_line_items as $key => $value) { |
378 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
378 | + $x_keys[] = "x_line_item=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
379 | 379 | } |
380 | 380 | $this->_log_clean_request($x_keys, $payment); |
381 | 381 | $post_url = $this->_get_server_url(); |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
388 | 388 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
389 | 389 | if ($this->VERIFY_PEER) { |
390 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
390 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__).'/ssl/cert.pem'); |
|
391 | 391 | } else { |
392 | 392 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
393 | 393 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | $response = curl_exec($curl_request); |
400 | 400 | |
401 | 401 | curl_close($curl_request); |
402 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
402 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
403 | 403 | |
404 | 404 | return $this->_log_and_clean_response($response_obj, $payment); |
405 | 405 | } |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | private function _log_and_clean_response($response_obj, $payment) |
445 | 445 | { |
446 | 446 | $response_obj->account_number = ''; |
447 | - $this->log(array('AIM Response received:' => (array)$response_obj), $payment); |
|
447 | + $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
448 | 448 | return $response_obj; |
449 | 449 | } |
450 | 450 | } |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | // Split Array |
546 | 546 | $this->response = $response; |
547 | 547 | if ($encap_char) { |
548 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
548 | + $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
549 | 549 | } else { |
550 | 550 | $this->_response_array = explode($delimiter, $response); |
551 | 551 | } |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
630 | -if (! class_exists('AuthorizeNetException')) { |
|
630 | +if ( ! class_exists('AuthorizeNetException')) { |
|
631 | 631 | /** |
632 | 632 | * Class AuthorizeNetException |
633 | 633 | * |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -16,290 +16,290 @@ discard block |
||
16 | 16 | class EEG_Mijireh extends EE_Offsite_Gateway |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Mijreh API access key. |
|
21 | - * |
|
22 | - * @var $_access_key string |
|
23 | - */ |
|
24 | - protected $_access_key; |
|
19 | + /** |
|
20 | + * Mijreh API access key. |
|
21 | + * |
|
22 | + * @var $_access_key string |
|
23 | + */ |
|
24 | + protected $_access_key; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Mijreh supported currencies. |
|
28 | - * |
|
29 | - * @var $_currencies_supported array |
|
30 | - */ |
|
31 | - protected $_currencies_supported = EE_Gateway::all_currencies_supported; |
|
26 | + /** |
|
27 | + * Mijreh supported currencies. |
|
28 | + * |
|
29 | + * @var $_currencies_supported array |
|
30 | + */ |
|
31 | + protected $_currencies_supported = EE_Gateway::all_currencies_supported; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Mijreh API order URL. |
|
35 | - * |
|
36 | - * @var $_mijireh_api_orders_url string |
|
37 | - */ |
|
38 | - protected $_mijireh_api_orders_url = 'https://secure.mijireh.com/api/1/orders'; |
|
33 | + /** |
|
34 | + * Mijreh API order URL. |
|
35 | + * |
|
36 | + * @var $_mijireh_api_orders_url string |
|
37 | + */ |
|
38 | + protected $_mijireh_api_orders_url = 'https://secure.mijireh.com/api/1/orders'; |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param EE_Payment $payment to process |
|
43 | - * @param array $billing_info but should be empty for this gateway |
|
44 | - * @param string $return_url URL to send the user to after a successful payment on the payment provider's website |
|
45 | - * @param string $notify_url URL to send the instant payment notification |
|
46 | - * @param string $cancel_url URL to send the user to after a cancelled payment attempt on teh payment provider's website |
|
47 | - * @throws \EE_Error |
|
48 | - * @return EE_Payment |
|
49 | - */ |
|
50 | - public function set_redirection_info( |
|
51 | - $payment, |
|
52 | - $billing_info = array(), |
|
53 | - $return_url = NULL, |
|
54 | - $notify_url = NULL, |
|
55 | - $cancel_url = NULL |
|
56 | - ) { |
|
57 | - /* @var $transaction EE_Transaction */ |
|
58 | - $transaction = $payment->transaction(); |
|
59 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
41 | + /** |
|
42 | + * @param EE_Payment $payment to process |
|
43 | + * @param array $billing_info but should be empty for this gateway |
|
44 | + * @param string $return_url URL to send the user to after a successful payment on the payment provider's website |
|
45 | + * @param string $notify_url URL to send the instant payment notification |
|
46 | + * @param string $cancel_url URL to send the user to after a cancelled payment attempt on teh payment provider's website |
|
47 | + * @throws \EE_Error |
|
48 | + * @return EE_Payment |
|
49 | + */ |
|
50 | + public function set_redirection_info( |
|
51 | + $payment, |
|
52 | + $billing_info = array(), |
|
53 | + $return_url = NULL, |
|
54 | + $notify_url = NULL, |
|
55 | + $cancel_url = NULL |
|
56 | + ) { |
|
57 | + /* @var $transaction EE_Transaction */ |
|
58 | + $transaction = $payment->transaction(); |
|
59 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
60 | 60 | |
61 | - //get any of the current registrations, |
|
62 | - $primary_registrant = $transaction->primary_registration(); |
|
61 | + //get any of the current registrations, |
|
62 | + $primary_registrant = $transaction->primary_registration(); |
|
63 | 63 | |
64 | - $primary_attendee = $primary_registrant->attendee(); |
|
65 | - $items = array(); |
|
66 | - //if we're are charging for the full amount, show the normal line items |
|
67 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
68 | - $total_line_item = $transaction->total_line_item(); |
|
69 | - $tax_total = $total_line_item->get_total_tax(); |
|
70 | - foreach ($total_line_item->get_items() as $line_item) { |
|
71 | - $items[] = array( |
|
72 | - 'name' => apply_filters( |
|
73 | - 'FHEE__EEG_Mijireh__set_redirection_info__full_amount_line_item_name', |
|
74 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
75 | - $line_item, |
|
76 | - $payment, |
|
77 | - $primary_registrant |
|
78 | - ), |
|
79 | - 'price' => $gateway_formatter->formatCurrency($line_item->unit_price()), |
|
80 | - 'sku' => $line_item->code(), |
|
81 | - 'quantity' => $line_item->quantity() |
|
82 | - ); |
|
83 | - } |
|
84 | - } else {//its a partial payment |
|
85 | - $tax_total = 0; |
|
86 | - //partial payment, so just add 1 item |
|
87 | - $items[] = array( |
|
88 | - 'name' => apply_filters( |
|
89 | - 'FHEE__EEG_Mijireh__set_redirection_info__partial_amount_line_item_name', |
|
90 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
91 | - $payment, |
|
92 | - $primary_registrant |
|
93 | - ), |
|
94 | - 'price' => $gateway_formatter->formatCurrency($payment->amount()), |
|
95 | - 'sku' => $primary_registrant->reg_code(), |
|
96 | - 'quantity' => 1 |
|
97 | - ); |
|
98 | - } |
|
99 | - $order = array( |
|
100 | - 'total' => $gateway_formatter->formatCurrency($payment->amount()), |
|
101 | - 'return_url' => $return_url, |
|
102 | - 'items' => $this->_prepare_for_mijireh($items), |
|
103 | - 'email' => $primary_attendee->email(), |
|
104 | - 'first_name' => $primary_attendee->fname(), |
|
105 | - 'last_name' => $primary_attendee->lname(), |
|
106 | - 'tax' => $gateway_formatter->formatCurrency($tax_total), |
|
107 | - 'partner_id' => 'ee' |
|
108 | - ); |
|
109 | - //setup address? |
|
110 | - if ($primary_attendee->address() |
|
111 | - && $primary_attendee->city() |
|
112 | - && $primary_attendee->state_ID() |
|
113 | - && $primary_attendee->country_ID() |
|
114 | - && $primary_attendee->zip() |
|
115 | - ) { |
|
116 | - $shipping_address = array( |
|
117 | - 'first_name' => $primary_attendee->fname(), |
|
118 | - 'last_name' => $primary_attendee->lname(), |
|
119 | - 'street' => $primary_attendee->address(), |
|
120 | - 'city' => $primary_attendee->city(), |
|
121 | - 'state_province' => $primary_attendee->state_name(), |
|
122 | - 'zip_code' => $primary_attendee->zip(), |
|
123 | - 'country' => $primary_attendee->country_ID() |
|
124 | - ); |
|
125 | - if ($primary_attendee->address2()) { |
|
126 | - $shipping_address['apt_suite'] = $primary_attendee->address2(); |
|
127 | - } |
|
128 | - if ($primary_attendee->phone()) { |
|
129 | - $shipping_address['phone'] = $primary_attendee->phone(); |
|
130 | - } |
|
131 | - $order['shipping_address'] = $shipping_address; |
|
132 | - } |
|
133 | - $order = apply_filters( |
|
134 | - 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', |
|
135 | - $order, |
|
136 | - $payment, |
|
137 | - $primary_registrant |
|
138 | - ); |
|
139 | - do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this))); |
|
140 | - $order = $this->_get_unsupported_character_remover()->formatArray($order); |
|
64 | + $primary_attendee = $primary_registrant->attendee(); |
|
65 | + $items = array(); |
|
66 | + //if we're are charging for the full amount, show the normal line items |
|
67 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
68 | + $total_line_item = $transaction->total_line_item(); |
|
69 | + $tax_total = $total_line_item->get_total_tax(); |
|
70 | + foreach ($total_line_item->get_items() as $line_item) { |
|
71 | + $items[] = array( |
|
72 | + 'name' => apply_filters( |
|
73 | + 'FHEE__EEG_Mijireh__set_redirection_info__full_amount_line_item_name', |
|
74 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
75 | + $line_item, |
|
76 | + $payment, |
|
77 | + $primary_registrant |
|
78 | + ), |
|
79 | + 'price' => $gateway_formatter->formatCurrency($line_item->unit_price()), |
|
80 | + 'sku' => $line_item->code(), |
|
81 | + 'quantity' => $line_item->quantity() |
|
82 | + ); |
|
83 | + } |
|
84 | + } else {//its a partial payment |
|
85 | + $tax_total = 0; |
|
86 | + //partial payment, so just add 1 item |
|
87 | + $items[] = array( |
|
88 | + 'name' => apply_filters( |
|
89 | + 'FHEE__EEG_Mijireh__set_redirection_info__partial_amount_line_item_name', |
|
90 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
91 | + $payment, |
|
92 | + $primary_registrant |
|
93 | + ), |
|
94 | + 'price' => $gateway_formatter->formatCurrency($payment->amount()), |
|
95 | + 'sku' => $primary_registrant->reg_code(), |
|
96 | + 'quantity' => 1 |
|
97 | + ); |
|
98 | + } |
|
99 | + $order = array( |
|
100 | + 'total' => $gateway_formatter->formatCurrency($payment->amount()), |
|
101 | + 'return_url' => $return_url, |
|
102 | + 'items' => $this->_prepare_for_mijireh($items), |
|
103 | + 'email' => $primary_attendee->email(), |
|
104 | + 'first_name' => $primary_attendee->fname(), |
|
105 | + 'last_name' => $primary_attendee->lname(), |
|
106 | + 'tax' => $gateway_formatter->formatCurrency($tax_total), |
|
107 | + 'partner_id' => 'ee' |
|
108 | + ); |
|
109 | + //setup address? |
|
110 | + if ($primary_attendee->address() |
|
111 | + && $primary_attendee->city() |
|
112 | + && $primary_attendee->state_ID() |
|
113 | + && $primary_attendee->country_ID() |
|
114 | + && $primary_attendee->zip() |
|
115 | + ) { |
|
116 | + $shipping_address = array( |
|
117 | + 'first_name' => $primary_attendee->fname(), |
|
118 | + 'last_name' => $primary_attendee->lname(), |
|
119 | + 'street' => $primary_attendee->address(), |
|
120 | + 'city' => $primary_attendee->city(), |
|
121 | + 'state_province' => $primary_attendee->state_name(), |
|
122 | + 'zip_code' => $primary_attendee->zip(), |
|
123 | + 'country' => $primary_attendee->country_ID() |
|
124 | + ); |
|
125 | + if ($primary_attendee->address2()) { |
|
126 | + $shipping_address['apt_suite'] = $primary_attendee->address2(); |
|
127 | + } |
|
128 | + if ($primary_attendee->phone()) { |
|
129 | + $shipping_address['phone'] = $primary_attendee->phone(); |
|
130 | + } |
|
131 | + $order['shipping_address'] = $shipping_address; |
|
132 | + } |
|
133 | + $order = apply_filters( |
|
134 | + 'FHEE__EEG_Mijireh__set_redirection_info__order_arguments', |
|
135 | + $order, |
|
136 | + $payment, |
|
137 | + $primary_registrant |
|
138 | + ); |
|
139 | + do_action('AHEE_log', __FILE__, __FUNCTION__, serialize(get_object_vars($this))); |
|
140 | + $order = $this->_get_unsupported_character_remover()->formatArray($order); |
|
141 | 141 | |
142 | - $args = array( |
|
143 | - 'headers' => array( |
|
144 | - 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
145 | - 'Accept' => 'application/json' |
|
146 | - ), |
|
147 | - 'body' => wp_json_encode($order) |
|
148 | - ); |
|
149 | - $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
|
150 | - $problems_string = false; |
|
151 | - $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
|
152 | - if (! $response instanceof WP_Error) { |
|
153 | - $response_body = json_decode($response['body']); |
|
154 | - if ($response_body && isset($response_body->checkout_url)) { |
|
155 | - $payment->set_redirect_url($response_body->checkout_url); |
|
156 | - $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
157 | - $payment->set_details($response['body']); |
|
158 | - } else { |
|
159 | - if (is_array($response_body) || is_object($response_body)) { |
|
160 | - $response_body_as_array = (array)$response_body; |
|
161 | - foreach ($response_body_as_array as $problem_parameter => $problems) { |
|
162 | - $problems_string .= sprintf( |
|
163 | - __('\nProblems with %s: %s', 'event_espresso'), |
|
164 | - $problem_parameter, |
|
165 | - implode(", ", $problems) |
|
166 | - ); |
|
167 | - } |
|
168 | - } else { |
|
169 | - $problems_string = $response['body']; |
|
170 | - } |
|
171 | - if (! $problems_string) { |
|
172 | - //no message to show? wack |
|
173 | - if (isset($response['headers']['status'])) { |
|
174 | - $problems_string = $response['headers']['status']; |
|
175 | - } else { |
|
176 | - $problems_string = __('No response from Mijireh', 'event_espresso'); |
|
177 | - } |
|
178 | - } |
|
179 | - } |
|
180 | - } else { |
|
181 | - $problems_string = implode(",", $response->get_error_messages()); |
|
182 | - } |
|
183 | - if ($problems_string) { |
|
184 | - $payment->set_gateway_response( |
|
185 | - sprintf( |
|
186 | - __('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), |
|
187 | - $problems_string |
|
188 | - ) |
|
189 | - ); |
|
190 | - $payment->set_details($response); |
|
191 | - $payment->set_redirect_url(null); |
|
192 | - //even though the payment's status is failed at this point anyways, |
|
193 | - //let's be explicit about it. The fact that the redirect url is null |
|
194 | - //should be enough to client code that they can't redirect the user |
|
195 | - $payment->set_status($this->_pay_model->failed_status()); |
|
196 | - } |
|
197 | - return $payment; |
|
198 | - } |
|
142 | + $args = array( |
|
143 | + 'headers' => array( |
|
144 | + 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
145 | + 'Accept' => 'application/json' |
|
146 | + ), |
|
147 | + 'body' => wp_json_encode($order) |
|
148 | + ); |
|
149 | + $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
|
150 | + $problems_string = false; |
|
151 | + $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
|
152 | + if (! $response instanceof WP_Error) { |
|
153 | + $response_body = json_decode($response['body']); |
|
154 | + if ($response_body && isset($response_body->checkout_url)) { |
|
155 | + $payment->set_redirect_url($response_body->checkout_url); |
|
156 | + $payment->set_txn_id_chq_nmbr($response_body->order_number); |
|
157 | + $payment->set_details($response['body']); |
|
158 | + } else { |
|
159 | + if (is_array($response_body) || is_object($response_body)) { |
|
160 | + $response_body_as_array = (array)$response_body; |
|
161 | + foreach ($response_body_as_array as $problem_parameter => $problems) { |
|
162 | + $problems_string .= sprintf( |
|
163 | + __('\nProblems with %s: %s', 'event_espresso'), |
|
164 | + $problem_parameter, |
|
165 | + implode(", ", $problems) |
|
166 | + ); |
|
167 | + } |
|
168 | + } else { |
|
169 | + $problems_string = $response['body']; |
|
170 | + } |
|
171 | + if (! $problems_string) { |
|
172 | + //no message to show? wack |
|
173 | + if (isset($response['headers']['status'])) { |
|
174 | + $problems_string = $response['headers']['status']; |
|
175 | + } else { |
|
176 | + $problems_string = __('No response from Mijireh', 'event_espresso'); |
|
177 | + } |
|
178 | + } |
|
179 | + } |
|
180 | + } else { |
|
181 | + $problems_string = implode(",", $response->get_error_messages()); |
|
182 | + } |
|
183 | + if ($problems_string) { |
|
184 | + $payment->set_gateway_response( |
|
185 | + sprintf( |
|
186 | + __('Errors occurred communicating with Mijireh: %1$s', 'event_espresso'), |
|
187 | + $problems_string |
|
188 | + ) |
|
189 | + ); |
|
190 | + $payment->set_details($response); |
|
191 | + $payment->set_redirect_url(null); |
|
192 | + //even though the payment's status is failed at this point anyways, |
|
193 | + //let's be explicit about it. The fact that the redirect url is null |
|
194 | + //should be enough to client code that they can't redirect the user |
|
195 | + $payment->set_status($this->_pay_model->failed_status()); |
|
196 | + } |
|
197 | + return $payment; |
|
198 | + } |
|
199 | 199 | |
200 | 200 | |
201 | - /** |
|
202 | - * goes through $data and ensures there are no percent signs in it |
|
203 | - * (which, strangely, kill mijireh) |
|
204 | - * |
|
205 | - * @param mixed $data |
|
206 | - * @return mixed same type as $data |
|
207 | - */ |
|
208 | - private function _prepare_for_mijireh($data) |
|
209 | - { |
|
210 | - if (is_array($data)) { |
|
211 | - $prepared_data = array(); |
|
212 | - foreach($data as $key => $datum) { |
|
213 | - $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
|
214 | - } |
|
215 | - return $prepared_data; |
|
216 | - } elseif (is_string($data)) { |
|
217 | - return str_replace('%', 'percent', $data); |
|
218 | - } else { |
|
219 | - return $data; |
|
220 | - } |
|
221 | - } |
|
201 | + /** |
|
202 | + * goes through $data and ensures there are no percent signs in it |
|
203 | + * (which, strangely, kill mijireh) |
|
204 | + * |
|
205 | + * @param mixed $data |
|
206 | + * @return mixed same type as $data |
|
207 | + */ |
|
208 | + private function _prepare_for_mijireh($data) |
|
209 | + { |
|
210 | + if (is_array($data)) { |
|
211 | + $prepared_data = array(); |
|
212 | + foreach($data as $key => $datum) { |
|
213 | + $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
|
214 | + } |
|
215 | + return $prepared_data; |
|
216 | + } elseif (is_string($data)) { |
|
217 | + return str_replace('%', 'percent', $data); |
|
218 | + } else { |
|
219 | + return $data; |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | 223 | |
224 | - /** |
|
225 | - * Handles the payment update (note: mijireh doesn't send an IPN in the usual sense, |
|
226 | - * instead they just redirect the user back to our website and then we need to query them |
|
227 | - * for the payment's status). Also note that the $update_info should be an array with the key |
|
228 | - * 'payment' containing the EEI_Payment to update |
|
229 | - * |
|
230 | - * @param array $update_info unused. We just use the $transaction |
|
231 | - * @param EEI_Transaction $transaction |
|
232 | - * @return \EEI_Payment |
|
233 | - * @throws EE_Error |
|
234 | - */ |
|
235 | - public function handle_payment_update($update_info, $transaction) |
|
236 | - { |
|
237 | - foreach($transaction->pending_payments() as $payment) { |
|
238 | - $payment = $this->check_payment_in_mijireh($payment); |
|
239 | - if ($payment->status() === $this->_pay_model->approved_status()) { |
|
240 | - return $payment; |
|
241 | - } |
|
242 | - } |
|
243 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
224 | + /** |
|
225 | + * Handles the payment update (note: mijireh doesn't send an IPN in the usual sense, |
|
226 | + * instead they just redirect the user back to our website and then we need to query them |
|
227 | + * for the payment's status). Also note that the $update_info should be an array with the key |
|
228 | + * 'payment' containing the EEI_Payment to update |
|
229 | + * |
|
230 | + * @param array $update_info unused. We just use the $transaction |
|
231 | + * @param EEI_Transaction $transaction |
|
232 | + * @return \EEI_Payment |
|
233 | + * @throws EE_Error |
|
234 | + */ |
|
235 | + public function handle_payment_update($update_info, $transaction) |
|
236 | + { |
|
237 | + foreach($transaction->pending_payments() as $payment) { |
|
238 | + $payment = $this->check_payment_in_mijireh($payment); |
|
239 | + if ($payment->status() === $this->_pay_model->approved_status()) { |
|
240 | + return $payment; |
|
241 | + } |
|
242 | + } |
|
243 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
|
244 | 244 | |
245 | - if (! $payment instanceof EEI_Payment) { |
|
246 | - throw new EE_Error( |
|
247 | - sprintf( |
|
248 | - __("Could not find Mijireh payment for transaction %s", 'event_espresso'), |
|
249 | - $transaction->ID() |
|
250 | - ) |
|
251 | - ); |
|
252 | - } |
|
253 | - return $payment; |
|
254 | - } |
|
245 | + if (! $payment instanceof EEI_Payment) { |
|
246 | + throw new EE_Error( |
|
247 | + sprintf( |
|
248 | + __("Could not find Mijireh payment for transaction %s", 'event_espresso'), |
|
249 | + $transaction->ID() |
|
250 | + ) |
|
251 | + ); |
|
252 | + } |
|
253 | + return $payment; |
|
254 | + } |
|
255 | 255 | |
256 | 256 | |
257 | - /** |
|
258 | - * Checks the payment's status in Mijireh for this specific payment |
|
259 | - * |
|
260 | - * @param \EEI_Payment $payment |
|
261 | - * @return \EEI_Payment |
|
262 | - */ |
|
263 | - public function check_payment_in_mijireh(EEI_Payment $payment) |
|
264 | - { |
|
265 | - $request_args = array( |
|
266 | - 'headers' => array( |
|
267 | - 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
268 | - 'Accept' => 'application/json' |
|
269 | - ) |
|
270 | - ); |
|
257 | + /** |
|
258 | + * Checks the payment's status in Mijireh for this specific payment |
|
259 | + * |
|
260 | + * @param \EEI_Payment $payment |
|
261 | + * @return \EEI_Payment |
|
262 | + */ |
|
263 | + public function check_payment_in_mijireh(EEI_Payment $payment) |
|
264 | + { |
|
265 | + $request_args = array( |
|
266 | + 'headers' => array( |
|
267 | + 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
268 | + 'Accept' => 'application/json' |
|
269 | + ) |
|
270 | + ); |
|
271 | 271 | |
272 | - $response = wp_remote_get( |
|
273 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
274 | - $request_args |
|
275 | - ); |
|
272 | + $response = wp_remote_get( |
|
273 | + $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
274 | + $request_args |
|
275 | + ); |
|
276 | 276 | |
277 | - $this->log( |
|
278 | - array('get payment status request_args' => $request_args, 'response' => $response), |
|
279 | - $payment |
|
280 | - ); |
|
281 | - // validate response |
|
282 | - $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
|
283 | - if ($response && $response_body) { |
|
284 | - switch($response_body->status) { |
|
285 | - case 'paid': |
|
286 | - $payment->set_status($this->_pay_model->approved_status()); |
|
287 | - break; |
|
288 | - case 'pending': |
|
289 | - $payment->set_status($this->_pay_model->pending_status()); |
|
290 | - break; |
|
291 | - default: |
|
292 | - $payment->set_status($this->_pay_model->declined_status()); |
|
293 | - } |
|
294 | - } else { |
|
295 | - $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); |
|
296 | - $payment->set_details($response); |
|
297 | - $payment->set_status($this->_pay_model->failed_status()); |
|
298 | - } |
|
299 | - // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
277 | + $this->log( |
|
278 | + array('get payment status request_args' => $request_args, 'response' => $response), |
|
279 | + $payment |
|
280 | + ); |
|
281 | + // validate response |
|
282 | + $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
|
283 | + if ($response && $response_body) { |
|
284 | + switch($response_body->status) { |
|
285 | + case 'paid': |
|
286 | + $payment->set_status($this->_pay_model->approved_status()); |
|
287 | + break; |
|
288 | + case 'pending': |
|
289 | + $payment->set_status($this->_pay_model->pending_status()); |
|
290 | + break; |
|
291 | + default: |
|
292 | + $payment->set_status($this->_pay_model->declined_status()); |
|
293 | + } |
|
294 | + } else { |
|
295 | + $payment->set_gateway_response(__('Response from Mijireh could not be understood.', 'event_espresso')); |
|
296 | + $payment->set_details($response); |
|
297 | + $payment->set_status($this->_pay_model->failed_status()); |
|
298 | + } |
|
299 | + // the following is ONLY for testing the Mijireh IPN and should NEVER be uncommented for real usage |
|
300 | 300 | // $payment->set_status( $this->_pay_model->pending_status() ); |
301 | - return $payment; |
|
302 | - } |
|
301 | + return $payment; |
|
302 | + } |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | // End of file EEG_Mijireh.gateway.php |
306 | 306 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | |
142 | 142 | $args = array( |
143 | 143 | 'headers' => array( |
144 | - 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
144 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
145 | 145 | 'Accept' => 'application/json' |
146 | 146 | ), |
147 | 147 | 'body' => wp_json_encode($order) |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $response = wp_remote_post($this->_mijireh_api_orders_url, $args); |
150 | 150 | $problems_string = false; |
151 | 151 | $this->log(array('get checkout url request_args' => $args, 'response' => $response), $payment); |
152 | - if (! $response instanceof WP_Error) { |
|
152 | + if ( ! $response instanceof WP_Error) { |
|
153 | 153 | $response_body = json_decode($response['body']); |
154 | 154 | if ($response_body && isset($response_body->checkout_url)) { |
155 | 155 | $payment->set_redirect_url($response_body->checkout_url); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $payment->set_details($response['body']); |
158 | 158 | } else { |
159 | 159 | if (is_array($response_body) || is_object($response_body)) { |
160 | - $response_body_as_array = (array)$response_body; |
|
160 | + $response_body_as_array = (array) $response_body; |
|
161 | 161 | foreach ($response_body_as_array as $problem_parameter => $problems) { |
162 | 162 | $problems_string .= sprintf( |
163 | 163 | __('\nProblems with %s: %s', 'event_espresso'), |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } else { |
169 | 169 | $problems_string = $response['body']; |
170 | 170 | } |
171 | - if (! $problems_string) { |
|
171 | + if ( ! $problems_string) { |
|
172 | 172 | //no message to show? wack |
173 | 173 | if (isset($response['headers']['status'])) { |
174 | 174 | $problems_string = $response['headers']['status']; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | { |
210 | 210 | if (is_array($data)) { |
211 | 211 | $prepared_data = array(); |
212 | - foreach($data as $key => $datum) { |
|
212 | + foreach ($data as $key => $datum) { |
|
213 | 213 | $prepared_data[$key] = $this->_prepare_for_mijireh($datum); |
214 | 214 | } |
215 | 215 | return $prepared_data; |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | */ |
235 | 235 | public function handle_payment_update($update_info, $transaction) |
236 | 236 | { |
237 | - foreach($transaction->pending_payments() as $payment) { |
|
237 | + foreach ($transaction->pending_payments() as $payment) { |
|
238 | 238 | $payment = $this->check_payment_in_mijireh($payment); |
239 | 239 | if ($payment->status() === $this->_pay_model->approved_status()) { |
240 | 240 | return $payment; |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | } |
243 | 243 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : NULL; |
244 | 244 | |
245 | - if (! $payment instanceof EEI_Payment) { |
|
245 | + if ( ! $payment instanceof EEI_Payment) { |
|
246 | 246 | throw new EE_Error( |
247 | 247 | sprintf( |
248 | 248 | __("Could not find Mijireh payment for transaction %s", 'event_espresso'), |
@@ -264,13 +264,13 @@ discard block |
||
264 | 264 | { |
265 | 265 | $request_args = array( |
266 | 266 | 'headers' => array( |
267 | - 'Authorization' => 'Basic ' . base64_encode($this->_access_key . ':'), |
|
267 | + 'Authorization' => 'Basic '.base64_encode($this->_access_key.':'), |
|
268 | 268 | 'Accept' => 'application/json' |
269 | 269 | ) |
270 | 270 | ); |
271 | 271 | |
272 | 272 | $response = wp_remote_get( |
273 | - $this->_mijireh_api_orders_url . '/' . $payment->txn_id_chq_nmbr(), |
|
273 | + $this->_mijireh_api_orders_url.'/'.$payment->txn_id_chq_nmbr(), |
|
274 | 274 | $request_args |
275 | 275 | ); |
276 | 276 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | // validate response |
282 | 282 | $response_body = isset($response['body']) ? json_decode($response['body']) : ''; |
283 | 283 | if ($response && $response_body) { |
284 | - switch($response_body->status) { |
|
284 | + switch ($response_body->status) { |
|
285 | 285 | case 'paid': |
286 | 286 | $payment->set_status($this->_pay_model->approved_status()); |
287 | 287 | break; |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\IpnException; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('NO direct script access allowed'); |
|
6 | + exit('NO direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -25,607 +25,607 @@ discard block |
||
25 | 25 | class EEG_Paypal_Standard extends EE_Offsite_Gateway |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Name for the wp option used to save the itemized payment |
|
30 | - */ |
|
31 | - const itemized_payment_option_name = '_itemized_payment'; |
|
32 | - |
|
33 | - protected $_paypal_id; |
|
34 | - |
|
35 | - protected $_image_url; |
|
36 | - |
|
37 | - protected $_shipping_details; |
|
38 | - |
|
39 | - protected $_paypal_shipping; |
|
40 | - |
|
41 | - protected $_paypal_taxes; |
|
42 | - |
|
43 | - protected $_gateway_url; |
|
44 | - |
|
45 | - protected $_currencies_supported = array( |
|
46 | - 'USD', |
|
47 | - 'GBP', |
|
48 | - 'CAD', |
|
49 | - 'AUD', |
|
50 | - 'BRL', |
|
51 | - 'CHF', |
|
52 | - 'CZK', |
|
53 | - 'DKK', |
|
54 | - 'EUR', |
|
55 | - 'HKD', |
|
56 | - 'HUF', |
|
57 | - 'ILS', |
|
58 | - 'JPY', |
|
59 | - 'MXN', |
|
60 | - 'MYR', |
|
61 | - 'NOK', |
|
62 | - 'NZD', |
|
63 | - 'PHP', |
|
64 | - 'PLN', |
|
65 | - 'SEK', |
|
66 | - 'SGD', |
|
67 | - 'THB', |
|
68 | - 'TRY', |
|
69 | - 'TWD', |
|
70 | - 'RUB' |
|
71 | - ); |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * EEG_Paypal_Standard constructor. |
|
76 | - * |
|
77 | - * @return EEG_Paypal_Standard |
|
78 | - */ |
|
79 | - public function __construct() |
|
80 | - { |
|
81 | - $this->set_uses_separate_IPN_request(true); |
|
82 | - parent::__construct(); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
88 | - * |
|
89 | - * @param array $settings_array |
|
90 | - */ |
|
91 | - public function set_settings($settings_array) |
|
92 | - { |
|
93 | - parent::set_settings($settings_array); |
|
94 | - $this->_gateway_url = $this->_debug_mode |
|
95 | - ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
96 | - : 'https://www.paypal.com/cgi-bin/webscr'; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @param EEI_Payment $payment the payment to process |
|
102 | - * @param array $billing_info but should be empty for this gateway |
|
103 | - * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
104 | - * @param string $notify_url URL to send the instant payment notification |
|
105 | - * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
106 | - * on the payment provider's website |
|
107 | - * @return EEI_Payment |
|
108 | - * @throws \EE_Error |
|
109 | - */ |
|
110 | - public function set_redirection_info( |
|
111 | - $payment, |
|
112 | - $billing_info = array(), |
|
113 | - $return_url = null, |
|
114 | - $notify_url = null, |
|
115 | - $cancel_url = null |
|
116 | - ) { |
|
117 | - $redirect_args = array(); |
|
118 | - $transaction = $payment->transaction(); |
|
119 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
120 | - $item_num = 1; |
|
121 | - /** @type EE_Line_Item $total_line_item */ |
|
122 | - $total_line_item = $transaction->total_line_item(); |
|
123 | - |
|
124 | - $total_discounts_to_cart_total = $transaction->paid(); |
|
125 | - //only itemize the order if we're paying for the rest of the order's amount |
|
126 | - if (EEH_Money::compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
127 | - $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
128 | - //this payment is for the remaining transaction amount, |
|
129 | - //keep track of exactly how much the itemized order amount equals |
|
130 | - $itemized_sum = 0; |
|
131 | - $shipping_previously_added = 0; |
|
132 | - //so let's show all the line items |
|
133 | - foreach ($total_line_item->get_items() as $line_item) { |
|
134 | - if ($line_item instanceof EE_Line_Item) { |
|
135 | - //it's some kind of discount |
|
136 | - if ($line_item->total() < 0) { |
|
137 | - $total_discounts_to_cart_total += abs($line_item->total()); |
|
138 | - $itemized_sum += $line_item->total(); |
|
139 | - continue; |
|
140 | - } |
|
141 | - //dont include shipping again. |
|
142 | - if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
143 | - $shipping_previously_added = $line_item->total(); |
|
144 | - continue; |
|
145 | - } |
|
146 | - $redirect_args['item_name_' . $item_num] = substr( |
|
147 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
148 | - 0, 127 |
|
149 | - ); |
|
150 | - $redirect_args['amount_' . $item_num] = $line_item->unit_price(); |
|
151 | - $redirect_args['quantity_' . $item_num] = $line_item->quantity(); |
|
152 | - //if we're not letting PayPal calculate shipping, tell them its 0 |
|
153 | - if (! $this->_paypal_shipping) { |
|
154 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
155 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
156 | - } |
|
157 | - $item_num++; |
|
158 | - $itemized_sum += $line_item->total(); |
|
159 | - } |
|
160 | - } |
|
161 | - $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
162 | - //ideally itemized sum equals the transaction total. but if not (which is weird) |
|
163 | - //and the itemized sum is LESS than the transaction total |
|
164 | - //add another line item |
|
165 | - //if the itemized sum is MORE than the transaction total, |
|
166 | - //add the difference it to the discounts |
|
167 | - $itemized_sum_diff_from_txn_total = round( |
|
168 | - $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
|
169 | - 2 |
|
170 | - ); |
|
171 | - if ($itemized_sum_diff_from_txn_total < 0) { |
|
172 | - //itemized sum is too big |
|
173 | - $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
174 | - } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
175 | - $redirect_args['item_name_' . $item_num] = substr( |
|
176 | - __('Other charges', 'event_espresso' ), 0, 127); |
|
177 | - $redirect_args['amount_' . $item_num] = $gateway_formatter->formatCurrency( |
|
178 | - $itemized_sum_diff_from_txn_total |
|
179 | - ); |
|
180 | - $redirect_args['quantity_' . $item_num] = 1; |
|
181 | - $item_num++; |
|
182 | - } |
|
183 | - if ($total_discounts_to_cart_total > 0) { |
|
184 | - $redirect_args['discount_amount_cart'] = $gateway_formatter->formatCurrency( |
|
185 | - $total_discounts_to_cart_total |
|
186 | - ); |
|
187 | - } |
|
188 | - //add our taxes to the order if we're NOT using PayPal's |
|
189 | - if (! $this->_paypal_taxes) { |
|
190 | - $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
|
191 | - } |
|
192 | - } else { |
|
193 | - $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
194 | - //partial payment that's not for the remaining amount, so we can't send an itemized list |
|
195 | - $redirect_args['item_name_' . $item_num] = substr( |
|
196 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
197 | - 0, |
|
198 | - 127 |
|
199 | - ); |
|
200 | - $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
201 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
202 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
203 | - $redirect_args['tax_cart'] = '0'; |
|
204 | - $item_num++; |
|
205 | - } |
|
206 | - |
|
207 | - if ($this->_debug_mode) { |
|
208 | - $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | - $redirect_args['amount_' . $item_num] = 0; |
|
210 | - $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
|
211 | - $redirect_args['os0_' . $item_num] = $notify_url; |
|
212 | - $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
|
213 | - $redirect_args['os1_' . $item_num] = $return_url; |
|
28 | + /** |
|
29 | + * Name for the wp option used to save the itemized payment |
|
30 | + */ |
|
31 | + const itemized_payment_option_name = '_itemized_payment'; |
|
32 | + |
|
33 | + protected $_paypal_id; |
|
34 | + |
|
35 | + protected $_image_url; |
|
36 | + |
|
37 | + protected $_shipping_details; |
|
38 | + |
|
39 | + protected $_paypal_shipping; |
|
40 | + |
|
41 | + protected $_paypal_taxes; |
|
42 | + |
|
43 | + protected $_gateway_url; |
|
44 | + |
|
45 | + protected $_currencies_supported = array( |
|
46 | + 'USD', |
|
47 | + 'GBP', |
|
48 | + 'CAD', |
|
49 | + 'AUD', |
|
50 | + 'BRL', |
|
51 | + 'CHF', |
|
52 | + 'CZK', |
|
53 | + 'DKK', |
|
54 | + 'EUR', |
|
55 | + 'HKD', |
|
56 | + 'HUF', |
|
57 | + 'ILS', |
|
58 | + 'JPY', |
|
59 | + 'MXN', |
|
60 | + 'MYR', |
|
61 | + 'NOK', |
|
62 | + 'NZD', |
|
63 | + 'PHP', |
|
64 | + 'PLN', |
|
65 | + 'SEK', |
|
66 | + 'SGD', |
|
67 | + 'THB', |
|
68 | + 'TRY', |
|
69 | + 'TWD', |
|
70 | + 'RUB' |
|
71 | + ); |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * EEG_Paypal_Standard constructor. |
|
76 | + * |
|
77 | + * @return EEG_Paypal_Standard |
|
78 | + */ |
|
79 | + public function __construct() |
|
80 | + { |
|
81 | + $this->set_uses_separate_IPN_request(true); |
|
82 | + parent::__construct(); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
88 | + * |
|
89 | + * @param array $settings_array |
|
90 | + */ |
|
91 | + public function set_settings($settings_array) |
|
92 | + { |
|
93 | + parent::set_settings($settings_array); |
|
94 | + $this->_gateway_url = $this->_debug_mode |
|
95 | + ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
96 | + : 'https://www.paypal.com/cgi-bin/webscr'; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @param EEI_Payment $payment the payment to process |
|
102 | + * @param array $billing_info but should be empty for this gateway |
|
103 | + * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
104 | + * @param string $notify_url URL to send the instant payment notification |
|
105 | + * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
106 | + * on the payment provider's website |
|
107 | + * @return EEI_Payment |
|
108 | + * @throws \EE_Error |
|
109 | + */ |
|
110 | + public function set_redirection_info( |
|
111 | + $payment, |
|
112 | + $billing_info = array(), |
|
113 | + $return_url = null, |
|
114 | + $notify_url = null, |
|
115 | + $cancel_url = null |
|
116 | + ) { |
|
117 | + $redirect_args = array(); |
|
118 | + $transaction = $payment->transaction(); |
|
119 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
120 | + $item_num = 1; |
|
121 | + /** @type EE_Line_Item $total_line_item */ |
|
122 | + $total_line_item = $transaction->total_line_item(); |
|
123 | + |
|
124 | + $total_discounts_to_cart_total = $transaction->paid(); |
|
125 | + //only itemize the order if we're paying for the rest of the order's amount |
|
126 | + if (EEH_Money::compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
127 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
128 | + //this payment is for the remaining transaction amount, |
|
129 | + //keep track of exactly how much the itemized order amount equals |
|
130 | + $itemized_sum = 0; |
|
131 | + $shipping_previously_added = 0; |
|
132 | + //so let's show all the line items |
|
133 | + foreach ($total_line_item->get_items() as $line_item) { |
|
134 | + if ($line_item instanceof EE_Line_Item) { |
|
135 | + //it's some kind of discount |
|
136 | + if ($line_item->total() < 0) { |
|
137 | + $total_discounts_to_cart_total += abs($line_item->total()); |
|
138 | + $itemized_sum += $line_item->total(); |
|
139 | + continue; |
|
140 | + } |
|
141 | + //dont include shipping again. |
|
142 | + if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
143 | + $shipping_previously_added = $line_item->total(); |
|
144 | + continue; |
|
145 | + } |
|
146 | + $redirect_args['item_name_' . $item_num] = substr( |
|
147 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
148 | + 0, 127 |
|
149 | + ); |
|
150 | + $redirect_args['amount_' . $item_num] = $line_item->unit_price(); |
|
151 | + $redirect_args['quantity_' . $item_num] = $line_item->quantity(); |
|
152 | + //if we're not letting PayPal calculate shipping, tell them its 0 |
|
153 | + if (! $this->_paypal_shipping) { |
|
154 | + $redirect_args['shipping_' . $item_num] = '0'; |
|
155 | + $redirect_args['shipping2_' . $item_num] = '0'; |
|
156 | + } |
|
157 | + $item_num++; |
|
158 | + $itemized_sum += $line_item->total(); |
|
159 | + } |
|
160 | + } |
|
161 | + $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
162 | + //ideally itemized sum equals the transaction total. but if not (which is weird) |
|
163 | + //and the itemized sum is LESS than the transaction total |
|
164 | + //add another line item |
|
165 | + //if the itemized sum is MORE than the transaction total, |
|
166 | + //add the difference it to the discounts |
|
167 | + $itemized_sum_diff_from_txn_total = round( |
|
168 | + $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
|
169 | + 2 |
|
170 | + ); |
|
171 | + if ($itemized_sum_diff_from_txn_total < 0) { |
|
172 | + //itemized sum is too big |
|
173 | + $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
174 | + } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
175 | + $redirect_args['item_name_' . $item_num] = substr( |
|
176 | + __('Other charges', 'event_espresso' ), 0, 127); |
|
177 | + $redirect_args['amount_' . $item_num] = $gateway_formatter->formatCurrency( |
|
178 | + $itemized_sum_diff_from_txn_total |
|
179 | + ); |
|
180 | + $redirect_args['quantity_' . $item_num] = 1; |
|
181 | + $item_num++; |
|
182 | + } |
|
183 | + if ($total_discounts_to_cart_total > 0) { |
|
184 | + $redirect_args['discount_amount_cart'] = $gateway_formatter->formatCurrency( |
|
185 | + $total_discounts_to_cart_total |
|
186 | + ); |
|
187 | + } |
|
188 | + //add our taxes to the order if we're NOT using PayPal's |
|
189 | + if (! $this->_paypal_taxes) { |
|
190 | + $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
|
191 | + } |
|
192 | + } else { |
|
193 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
194 | + //partial payment that's not for the remaining amount, so we can't send an itemized list |
|
195 | + $redirect_args['item_name_' . $item_num] = substr( |
|
196 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
197 | + 0, |
|
198 | + 127 |
|
199 | + ); |
|
200 | + $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
201 | + $redirect_args['shipping_' . $item_num] = '0'; |
|
202 | + $redirect_args['shipping2_' . $item_num] = '0'; |
|
203 | + $redirect_args['tax_cart'] = '0'; |
|
204 | + $item_num++; |
|
205 | + } |
|
206 | + |
|
207 | + if ($this->_debug_mode) { |
|
208 | + $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | + $redirect_args['amount_' . $item_num] = 0; |
|
210 | + $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
|
211 | + $redirect_args['os0_' . $item_num] = $notify_url; |
|
212 | + $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
|
213 | + $redirect_args['os1_' . $item_num] = $return_url; |
|
214 | 214 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
215 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
216 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
217 | - } |
|
218 | - |
|
219 | - $redirect_args['business'] = $this->_paypal_id; |
|
220 | - $redirect_args['return'] = $return_url; |
|
221 | - $redirect_args['cancel_return'] = $cancel_url; |
|
222 | - $redirect_args['notify_url'] = $notify_url; |
|
223 | - $redirect_args['cmd'] = '_cart'; |
|
224 | - $redirect_args['upload'] = 1; |
|
225 | - $redirect_args['currency_code'] = $payment->currency_code(); |
|
226 | - $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
227 | - if ($this->_image_url) { |
|
228 | - $redirect_args['image_url'] = $this->_image_url; |
|
229 | - } |
|
230 | - $redirect_args['no_shipping'] = $this->_shipping_details; |
|
231 | - $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
232 | - |
|
233 | - $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
234 | - |
|
235 | - $payment->set_redirect_url($this->_gateway_url); |
|
236 | - $payment->set_redirect_args($redirect_args); |
|
237 | - // log the results |
|
238 | - $this->log( |
|
239 | - array( |
|
240 | - 'message' => sprintf( |
|
241 | - __('PayPal payment request initiated.', 'event_espresso') |
|
242 | - ), |
|
243 | - 'transaction' => $transaction->model_field_array(), |
|
244 | - ), |
|
245 | - $payment |
|
246 | - ); |
|
247 | - return $payment; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Often used for IPNs. But applies the info in $update_info to the payment. |
|
253 | - * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
254 | - * the payment method passes in. |
|
255 | - * |
|
256 | - * @param array $update_info like $_POST |
|
257 | - * @param EEI_Transaction $transaction |
|
258 | - * @return \EEI_Payment updated |
|
259 | - * @throws \EE_Error, IpnException |
|
260 | - */ |
|
261 | - public function handle_payment_update($update_info, $transaction) |
|
262 | - { |
|
263 | - // verify there's payment data that's been sent |
|
264 | - if (empty($update_info['payment_status'] ) || empty($update_info['txn_id'])) { |
|
265 | - // log the results |
|
266 | - $this->log( |
|
267 | - array( |
|
268 | - 'message' => sprintf( |
|
269 | - // @codingStandardsIgnoreStart |
|
270 | - __('PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso') |
|
271 | - // @codingStandardsIgnoreEnd |
|
272 | - ), |
|
273 | - 'update_info' => $update_info, |
|
274 | - ), |
|
275 | - $transaction |
|
276 | - ); |
|
277 | - // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
278 | - // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
279 | - if (isset($update_info['tx'])) { |
|
280 | - return $transaction->last_payment(); |
|
281 | - } else { |
|
282 | - return null; |
|
283 | - } |
|
284 | - } |
|
285 | - $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
286 | - if (! $payment instanceof EEI_Payment) { |
|
287 | - $payment = $transaction->last_payment(); |
|
288 | - } |
|
289 | - // ok, then validate the IPN. Even if we've already processed this payment, |
|
290 | - // let PayPal know we don't want to hear from them anymore! |
|
291 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
292 | - return $payment; |
|
293 | - } |
|
294 | - // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
295 | - // registrations, ticket counts, etc) |
|
296 | - if ( |
|
297 | - ( |
|
298 | - $update_info['payment_status'] === 'Refunded' |
|
299 | - || $update_info['payment_status'] === 'Partially_Refunded' |
|
300 | - ) |
|
301 | - && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
302 | - ) { |
|
303 | - throw new EventEspresso\core\exceptions\IpnException( |
|
304 | - sprintf( |
|
305 | - esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
306 | - $update_info['payment_status'] |
|
307 | - ), |
|
308 | - EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
309 | - null, |
|
310 | - $payment, |
|
311 | - $update_info |
|
312 | - ); |
|
313 | - } |
|
314 | - //ok, well let's process this payment then! |
|
315 | - switch ($update_info['payment_status']) { |
|
316 | - |
|
317 | - case 'Completed' : |
|
318 | - $status = $this->_pay_model->approved_status(); |
|
319 | - $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
320 | - break; |
|
321 | - |
|
322 | - case 'Pending' : |
|
323 | - $status = $this->_pay_model->pending_status(); |
|
324 | - $gateway_response = esc_html__( |
|
325 | - 'The payment is in progress. Another message will be sent when payment is approved.', |
|
326 | - 'event_espresso' |
|
327 | - ); |
|
328 | - break; |
|
329 | - |
|
330 | - case 'Denied' : |
|
331 | - $status = $this->_pay_model->declined_status(); |
|
332 | - $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
333 | - break; |
|
334 | - |
|
335 | - case 'Expired' : |
|
336 | - case 'Failed' : |
|
337 | - $status = $this->_pay_model->failed_status(); |
|
338 | - $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
339 | - break; |
|
340 | - |
|
341 | - case 'Refunded' : |
|
342 | - case 'Partially_Refunded' : |
|
343 | - // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
344 | - $status = $this->_pay_model->approved_status(); |
|
345 | - $gateway_response = esc_html__( |
|
346 | - 'The payment has been refunded. Please update registrations accordingly.', |
|
347 | - 'event_espresso' |
|
348 | - ); |
|
349 | - break; |
|
350 | - |
|
351 | - case 'Voided' : |
|
352 | - case 'Reversed' : |
|
353 | - case 'Canceled_Reversal' : |
|
354 | - default : |
|
355 | - $status = $this->_pay_model->cancelled_status(); |
|
356 | - $gateway_response = esc_html__( |
|
357 | - 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
358 | - 'event_espresso' |
|
359 | - ); |
|
360 | - break; |
|
361 | - |
|
362 | - } |
|
363 | - |
|
364 | - //check if we've already processed this payment |
|
365 | - if ($payment instanceof EEI_Payment) { |
|
366 | - //payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
367 | - if ($payment->status() === $status && (float)$payment->amount() === (float)$update_info['mc_gross']) { |
|
368 | - // DUPLICATED IPN! don't bother updating transaction |
|
369 | - throw new IpnException( |
|
370 | - sprintf( |
|
371 | - esc_html__('It appears we have received a duplicate IPN from PayPal for payment %d', |
|
372 | - 'event_espresso' |
|
373 | - ), |
|
374 | - $payment->ID() |
|
375 | - ), |
|
376 | - IpnException::DUPLICATE, |
|
377 | - null, |
|
378 | - $payment, |
|
379 | - $update_info |
|
380 | - ); |
|
381 | - } else { |
|
382 | - // new payment yippee !!! |
|
383 | - $payment->set_status($status); |
|
384 | - $payment->set_amount((float)$update_info['mc_gross']); |
|
385 | - $payment->set_gateway_response($gateway_response); |
|
386 | - $payment->set_details($update_info); |
|
387 | - $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
388 | - $this->log( |
|
389 | - array( |
|
390 | - 'message' => esc_html__( |
|
391 | - 'Updated payment either from IPN or as part of POST from PayPal', |
|
392 | - 'event_espresso' |
|
393 | - ), |
|
394 | - 'url' => $this->_process_response_url(), |
|
395 | - 'payment' => $payment->model_field_array(), |
|
396 | - 'IPN_data' => $update_info |
|
397 | - ), |
|
398 | - $payment |
|
399 | - ); |
|
400 | - } |
|
401 | - |
|
402 | - } |
|
403 | - do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
404 | - return $payment; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Validate the IPN notification. |
|
410 | - * |
|
411 | - * @param array $update_info like $_REQUEST |
|
412 | - * @param EE_Payment|EEI_Payment $payment |
|
413 | - * @return boolean |
|
414 | - * @throws \EE_Error |
|
415 | - */ |
|
416 | - public function validate_ipn($update_info, $payment) |
|
417 | - { |
|
418 | - //allow us to skip validating IPNs with PayPal (useful for testing) |
|
419 | - if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
420 | - return true; |
|
421 | - } |
|
422 | - //...otherwise, we actually don't care what the $update_info is, we need to look |
|
423 | - //at the request directly because we can't use $update_info because it has issues with quotes |
|
424 | - // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
425 | - // Instead, read raw POST data from the input stream. |
|
426 | - // @see https://gist.github.com/xcommerce-gists/3440401 |
|
427 | - $raw_post_data = file_get_contents('php://input'); |
|
428 | - $raw_post_array = explode('&', $raw_post_data); |
|
429 | - $update_info = array(); |
|
430 | - foreach ($raw_post_array as $keyval) { |
|
431 | - $keyval = explode('=', $keyval); |
|
432 | - if (count($keyval) === 2) { |
|
433 | - $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
434 | - } |
|
435 | - } |
|
436 | - // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
437 | - $req = 'cmd=_notify-validate'; |
|
438 | - $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 |
|
439 | - ? true |
|
440 | - : false; |
|
441 | - foreach ($update_info as $key => $value) { |
|
442 | - $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
443 | - $req .= "&$key=$value"; |
|
444 | - } |
|
445 | - // HTTP POST the complete, unaltered IPN back to PayPal |
|
446 | - $response = wp_remote_post( |
|
447 | - $this->_gateway_url, |
|
448 | - array( |
|
449 | - 'body' => $req, |
|
450 | - 'sslverify' => false, |
|
451 | - 'timeout' => 60, |
|
452 | - // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
453 | - // plz see: https://github.com/websharks/s2member/issues/610 |
|
454 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
455 | - 'httpversion' => '1.1' |
|
456 | - ) |
|
457 | - ); |
|
458 | - // then check the response |
|
459 | - if ( |
|
460 | - array_key_exists('body', $response) |
|
461 | - && ! is_wp_error($response) |
|
462 | - && strcmp($response['body'], "VERIFIED") === 0 |
|
463 | - ) { |
|
464 | - return true; |
|
465 | - } |
|
466 | - // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
467 | - // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
468 | - if ($response instanceof WP_Error) { |
|
469 | - $error_msg = sprintf( |
|
470 | - esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
471 | - $response->get_error_code(), |
|
472 | - $response->get_error_message(), |
|
473 | - print_r($response->get_error_data(), true) |
|
474 | - ); |
|
475 | - } elseif(is_array($response) && isset($response['body'])) { |
|
476 | - $error_msg = $response['body']; |
|
477 | - } else { |
|
478 | - $error_msg = print_r($response, true); |
|
479 | - } |
|
480 | - $payment->set_gateway_response( |
|
481 | - sprintf( |
|
482 | - esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
483 | - $error_msg |
|
484 | - ) |
|
485 | - ); |
|
486 | - $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
487 | - $payment->set_status(EEM_Payment::status_id_failed); |
|
488 | - // log the results |
|
489 | - $this->log( |
|
490 | - array( |
|
491 | - 'url' => $this->_process_response_url(), |
|
492 | - 'message' => $payment->gateway_response(), |
|
493 | - 'details' => $payment->details(), |
|
494 | - ), |
|
495 | - $payment |
|
496 | - ); |
|
497 | - return false; |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * _process_response_url |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - protected function _process_response_url() |
|
506 | - { |
|
507 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
508 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
509 | - $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
510 | - $url .= EEH_URL::filter_input_server_url(); |
|
511 | - } else { |
|
512 | - $url = 'unknown'; |
|
513 | - } |
|
514 | - return $url; |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
520 | - * like the taxes or shipping |
|
521 | - * |
|
522 | - * @param EEI_Payment $payment |
|
523 | - * @throws \EE_Error |
|
524 | - */ |
|
525 | - public function update_txn_based_on_payment($payment) |
|
526 | - { |
|
527 | - $update_info = $payment->details(); |
|
528 | - /** @var EE_Transaction $transaction */ |
|
529 | - $transaction = $payment->transaction(); |
|
530 | - $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
531 | - if (! $transaction) { |
|
532 | - $this->log( |
|
533 | - esc_html__( |
|
534 | - // @codingStandardsIgnoreStart |
|
535 | - 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
536 | - // @codingStandardsIgnoreEnd |
|
537 | - 'event_espresso' |
|
538 | - ), |
|
539 | - $payment |
|
540 | - ); |
|
541 | - return; |
|
542 | - } |
|
543 | - if ( |
|
544 | - ! is_array($update_info) |
|
545 | - || ! isset($update_info['mc_shipping']) |
|
546 | - || ! isset($update_info['tax']) |
|
547 | - ) { |
|
548 | - $this->log( |
|
549 | - array( |
|
550 | - 'message' => esc_html__( |
|
551 | - // @codingStandardsIgnoreStart |
|
552 | - 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
553 | - // @codingStandardsIgnoreEnd |
|
554 | - 'event_espresso' |
|
555 | - ), |
|
556 | - 'url' => $this->_process_response_url(), |
|
557 | - 'payment' => $payment->model_field_array() |
|
558 | - ), |
|
559 | - $payment |
|
560 | - ); |
|
561 | - return; |
|
562 | - } |
|
563 | - if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
564 | - $this->log( |
|
565 | - array( |
|
566 | - 'message' => esc_html__( |
|
567 | - 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
568 | - 'event_espresso' |
|
569 | - ), |
|
570 | - 'url' => $this->_process_response_url(), |
|
571 | - 'payment' => $payment->model_field_array() |
|
572 | - ), |
|
573 | - $payment |
|
574 | - ); |
|
575 | - return; |
|
576 | - } |
|
577 | - $grand_total_needs_resaving = false; |
|
578 | - /** @var EE_Line_Item $transaction_total_line_item */ |
|
579 | - $transaction_total_line_item = $transaction->total_line_item(); |
|
580 | - |
|
581 | - //might paypal have changed the taxes? |
|
582 | - if ($this->_paypal_taxes && $payment_was_itemized) { |
|
583 | - // note that we're doing this BEFORE adding shipping; |
|
584 | - // we actually want PayPal's shipping to remain non-taxable |
|
585 | - $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
586 | - $this->_line_item->set_total_tax_to( |
|
587 | - $transaction_total_line_item, |
|
588 | - (float)$update_info['tax'], |
|
589 | - esc_html__('Taxes', 'event_espresso'), |
|
590 | - esc_html__('Calculated by Paypal', 'event_espresso'), |
|
591 | - 'paypal_tax' |
|
592 | - ); |
|
593 | - $grand_total_needs_resaving = TRUE; |
|
594 | - } |
|
595 | - |
|
596 | - $shipping_amount = (float)$update_info['mc_shipping']; |
|
597 | - //might paypal have added shipping? |
|
598 | - if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
599 | - $this->_line_item->add_unrelated_item( |
|
600 | - $transaction_total_line_item, |
|
601 | - sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
602 | - $shipping_amount, |
|
603 | - esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
604 | - 1, |
|
605 | - false, |
|
606 | - 'paypal_shipping_' . $transaction->ID() |
|
607 | - ); |
|
608 | - $grand_total_needs_resaving = true; |
|
609 | - } |
|
610 | - |
|
611 | - if ($grand_total_needs_resaving) { |
|
612 | - $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
613 | - /** @var EE_Registration_Processor $registration_processor */ |
|
614 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
615 | - $registration_processor->update_registration_final_prices($transaction); |
|
616 | - } |
|
617 | - $this->log( |
|
618 | - array( |
|
619 | - 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
620 | - 'url' => $this->_process_response_url(), |
|
621 | - 'transaction (updated)' => $transaction->model_field_array(), |
|
622 | - 'payment (updated)' => $payment->model_field_array(), |
|
623 | - 'use_paypal_shipping' => $this->_paypal_shipping, |
|
624 | - 'use_paypal_tax' => $this->_paypal_taxes, |
|
625 | - 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
626 | - ), |
|
627 | - $payment |
|
628 | - ); |
|
629 | - } |
|
215 | + $redirect_args['shipping_' . $item_num] = '0'; |
|
216 | + $redirect_args['shipping2_' . $item_num] = '0'; |
|
217 | + } |
|
218 | + |
|
219 | + $redirect_args['business'] = $this->_paypal_id; |
|
220 | + $redirect_args['return'] = $return_url; |
|
221 | + $redirect_args['cancel_return'] = $cancel_url; |
|
222 | + $redirect_args['notify_url'] = $notify_url; |
|
223 | + $redirect_args['cmd'] = '_cart'; |
|
224 | + $redirect_args['upload'] = 1; |
|
225 | + $redirect_args['currency_code'] = $payment->currency_code(); |
|
226 | + $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
227 | + if ($this->_image_url) { |
|
228 | + $redirect_args['image_url'] = $this->_image_url; |
|
229 | + } |
|
230 | + $redirect_args['no_shipping'] = $this->_shipping_details; |
|
231 | + $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
232 | + |
|
233 | + $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
234 | + |
|
235 | + $payment->set_redirect_url($this->_gateway_url); |
|
236 | + $payment->set_redirect_args($redirect_args); |
|
237 | + // log the results |
|
238 | + $this->log( |
|
239 | + array( |
|
240 | + 'message' => sprintf( |
|
241 | + __('PayPal payment request initiated.', 'event_espresso') |
|
242 | + ), |
|
243 | + 'transaction' => $transaction->model_field_array(), |
|
244 | + ), |
|
245 | + $payment |
|
246 | + ); |
|
247 | + return $payment; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Often used for IPNs. But applies the info in $update_info to the payment. |
|
253 | + * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
254 | + * the payment method passes in. |
|
255 | + * |
|
256 | + * @param array $update_info like $_POST |
|
257 | + * @param EEI_Transaction $transaction |
|
258 | + * @return \EEI_Payment updated |
|
259 | + * @throws \EE_Error, IpnException |
|
260 | + */ |
|
261 | + public function handle_payment_update($update_info, $transaction) |
|
262 | + { |
|
263 | + // verify there's payment data that's been sent |
|
264 | + if (empty($update_info['payment_status'] ) || empty($update_info['txn_id'])) { |
|
265 | + // log the results |
|
266 | + $this->log( |
|
267 | + array( |
|
268 | + 'message' => sprintf( |
|
269 | + // @codingStandardsIgnoreStart |
|
270 | + __('PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso') |
|
271 | + // @codingStandardsIgnoreEnd |
|
272 | + ), |
|
273 | + 'update_info' => $update_info, |
|
274 | + ), |
|
275 | + $transaction |
|
276 | + ); |
|
277 | + // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
278 | + // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
279 | + if (isset($update_info['tx'])) { |
|
280 | + return $transaction->last_payment(); |
|
281 | + } else { |
|
282 | + return null; |
|
283 | + } |
|
284 | + } |
|
285 | + $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
286 | + if (! $payment instanceof EEI_Payment) { |
|
287 | + $payment = $transaction->last_payment(); |
|
288 | + } |
|
289 | + // ok, then validate the IPN. Even if we've already processed this payment, |
|
290 | + // let PayPal know we don't want to hear from them anymore! |
|
291 | + if (! $this->validate_ipn($update_info, $payment)) { |
|
292 | + return $payment; |
|
293 | + } |
|
294 | + // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
295 | + // registrations, ticket counts, etc) |
|
296 | + if ( |
|
297 | + ( |
|
298 | + $update_info['payment_status'] === 'Refunded' |
|
299 | + || $update_info['payment_status'] === 'Partially_Refunded' |
|
300 | + ) |
|
301 | + && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
302 | + ) { |
|
303 | + throw new EventEspresso\core\exceptions\IpnException( |
|
304 | + sprintf( |
|
305 | + esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
306 | + $update_info['payment_status'] |
|
307 | + ), |
|
308 | + EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
309 | + null, |
|
310 | + $payment, |
|
311 | + $update_info |
|
312 | + ); |
|
313 | + } |
|
314 | + //ok, well let's process this payment then! |
|
315 | + switch ($update_info['payment_status']) { |
|
316 | + |
|
317 | + case 'Completed' : |
|
318 | + $status = $this->_pay_model->approved_status(); |
|
319 | + $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
320 | + break; |
|
321 | + |
|
322 | + case 'Pending' : |
|
323 | + $status = $this->_pay_model->pending_status(); |
|
324 | + $gateway_response = esc_html__( |
|
325 | + 'The payment is in progress. Another message will be sent when payment is approved.', |
|
326 | + 'event_espresso' |
|
327 | + ); |
|
328 | + break; |
|
329 | + |
|
330 | + case 'Denied' : |
|
331 | + $status = $this->_pay_model->declined_status(); |
|
332 | + $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
333 | + break; |
|
334 | + |
|
335 | + case 'Expired' : |
|
336 | + case 'Failed' : |
|
337 | + $status = $this->_pay_model->failed_status(); |
|
338 | + $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
339 | + break; |
|
340 | + |
|
341 | + case 'Refunded' : |
|
342 | + case 'Partially_Refunded' : |
|
343 | + // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
344 | + $status = $this->_pay_model->approved_status(); |
|
345 | + $gateway_response = esc_html__( |
|
346 | + 'The payment has been refunded. Please update registrations accordingly.', |
|
347 | + 'event_espresso' |
|
348 | + ); |
|
349 | + break; |
|
350 | + |
|
351 | + case 'Voided' : |
|
352 | + case 'Reversed' : |
|
353 | + case 'Canceled_Reversal' : |
|
354 | + default : |
|
355 | + $status = $this->_pay_model->cancelled_status(); |
|
356 | + $gateway_response = esc_html__( |
|
357 | + 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
358 | + 'event_espresso' |
|
359 | + ); |
|
360 | + break; |
|
361 | + |
|
362 | + } |
|
363 | + |
|
364 | + //check if we've already processed this payment |
|
365 | + if ($payment instanceof EEI_Payment) { |
|
366 | + //payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
367 | + if ($payment->status() === $status && (float)$payment->amount() === (float)$update_info['mc_gross']) { |
|
368 | + // DUPLICATED IPN! don't bother updating transaction |
|
369 | + throw new IpnException( |
|
370 | + sprintf( |
|
371 | + esc_html__('It appears we have received a duplicate IPN from PayPal for payment %d', |
|
372 | + 'event_espresso' |
|
373 | + ), |
|
374 | + $payment->ID() |
|
375 | + ), |
|
376 | + IpnException::DUPLICATE, |
|
377 | + null, |
|
378 | + $payment, |
|
379 | + $update_info |
|
380 | + ); |
|
381 | + } else { |
|
382 | + // new payment yippee !!! |
|
383 | + $payment->set_status($status); |
|
384 | + $payment->set_amount((float)$update_info['mc_gross']); |
|
385 | + $payment->set_gateway_response($gateway_response); |
|
386 | + $payment->set_details($update_info); |
|
387 | + $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
388 | + $this->log( |
|
389 | + array( |
|
390 | + 'message' => esc_html__( |
|
391 | + 'Updated payment either from IPN or as part of POST from PayPal', |
|
392 | + 'event_espresso' |
|
393 | + ), |
|
394 | + 'url' => $this->_process_response_url(), |
|
395 | + 'payment' => $payment->model_field_array(), |
|
396 | + 'IPN_data' => $update_info |
|
397 | + ), |
|
398 | + $payment |
|
399 | + ); |
|
400 | + } |
|
401 | + |
|
402 | + } |
|
403 | + do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
404 | + return $payment; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Validate the IPN notification. |
|
410 | + * |
|
411 | + * @param array $update_info like $_REQUEST |
|
412 | + * @param EE_Payment|EEI_Payment $payment |
|
413 | + * @return boolean |
|
414 | + * @throws \EE_Error |
|
415 | + */ |
|
416 | + public function validate_ipn($update_info, $payment) |
|
417 | + { |
|
418 | + //allow us to skip validating IPNs with PayPal (useful for testing) |
|
419 | + if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
420 | + return true; |
|
421 | + } |
|
422 | + //...otherwise, we actually don't care what the $update_info is, we need to look |
|
423 | + //at the request directly because we can't use $update_info because it has issues with quotes |
|
424 | + // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
425 | + // Instead, read raw POST data from the input stream. |
|
426 | + // @see https://gist.github.com/xcommerce-gists/3440401 |
|
427 | + $raw_post_data = file_get_contents('php://input'); |
|
428 | + $raw_post_array = explode('&', $raw_post_data); |
|
429 | + $update_info = array(); |
|
430 | + foreach ($raw_post_array as $keyval) { |
|
431 | + $keyval = explode('=', $keyval); |
|
432 | + if (count($keyval) === 2) { |
|
433 | + $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
434 | + } |
|
435 | + } |
|
436 | + // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
437 | + $req = 'cmd=_notify-validate'; |
|
438 | + $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 |
|
439 | + ? true |
|
440 | + : false; |
|
441 | + foreach ($update_info as $key => $value) { |
|
442 | + $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
443 | + $req .= "&$key=$value"; |
|
444 | + } |
|
445 | + // HTTP POST the complete, unaltered IPN back to PayPal |
|
446 | + $response = wp_remote_post( |
|
447 | + $this->_gateway_url, |
|
448 | + array( |
|
449 | + 'body' => $req, |
|
450 | + 'sslverify' => false, |
|
451 | + 'timeout' => 60, |
|
452 | + // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
453 | + // plz see: https://github.com/websharks/s2member/issues/610 |
|
454 | + 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
455 | + 'httpversion' => '1.1' |
|
456 | + ) |
|
457 | + ); |
|
458 | + // then check the response |
|
459 | + if ( |
|
460 | + array_key_exists('body', $response) |
|
461 | + && ! is_wp_error($response) |
|
462 | + && strcmp($response['body'], "VERIFIED") === 0 |
|
463 | + ) { |
|
464 | + return true; |
|
465 | + } |
|
466 | + // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
467 | + // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
468 | + if ($response instanceof WP_Error) { |
|
469 | + $error_msg = sprintf( |
|
470 | + esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
471 | + $response->get_error_code(), |
|
472 | + $response->get_error_message(), |
|
473 | + print_r($response->get_error_data(), true) |
|
474 | + ); |
|
475 | + } elseif(is_array($response) && isset($response['body'])) { |
|
476 | + $error_msg = $response['body']; |
|
477 | + } else { |
|
478 | + $error_msg = print_r($response, true); |
|
479 | + } |
|
480 | + $payment->set_gateway_response( |
|
481 | + sprintf( |
|
482 | + esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
483 | + $error_msg |
|
484 | + ) |
|
485 | + ); |
|
486 | + $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
487 | + $payment->set_status(EEM_Payment::status_id_failed); |
|
488 | + // log the results |
|
489 | + $this->log( |
|
490 | + array( |
|
491 | + 'url' => $this->_process_response_url(), |
|
492 | + 'message' => $payment->gateway_response(), |
|
493 | + 'details' => $payment->details(), |
|
494 | + ), |
|
495 | + $payment |
|
496 | + ); |
|
497 | + return false; |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * _process_response_url |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + protected function _process_response_url() |
|
506 | + { |
|
507 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
508 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
509 | + $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
510 | + $url .= EEH_URL::filter_input_server_url(); |
|
511 | + } else { |
|
512 | + $url = 'unknown'; |
|
513 | + } |
|
514 | + return $url; |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
520 | + * like the taxes or shipping |
|
521 | + * |
|
522 | + * @param EEI_Payment $payment |
|
523 | + * @throws \EE_Error |
|
524 | + */ |
|
525 | + public function update_txn_based_on_payment($payment) |
|
526 | + { |
|
527 | + $update_info = $payment->details(); |
|
528 | + /** @var EE_Transaction $transaction */ |
|
529 | + $transaction = $payment->transaction(); |
|
530 | + $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
531 | + if (! $transaction) { |
|
532 | + $this->log( |
|
533 | + esc_html__( |
|
534 | + // @codingStandardsIgnoreStart |
|
535 | + 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
536 | + // @codingStandardsIgnoreEnd |
|
537 | + 'event_espresso' |
|
538 | + ), |
|
539 | + $payment |
|
540 | + ); |
|
541 | + return; |
|
542 | + } |
|
543 | + if ( |
|
544 | + ! is_array($update_info) |
|
545 | + || ! isset($update_info['mc_shipping']) |
|
546 | + || ! isset($update_info['tax']) |
|
547 | + ) { |
|
548 | + $this->log( |
|
549 | + array( |
|
550 | + 'message' => esc_html__( |
|
551 | + // @codingStandardsIgnoreStart |
|
552 | + 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
553 | + // @codingStandardsIgnoreEnd |
|
554 | + 'event_espresso' |
|
555 | + ), |
|
556 | + 'url' => $this->_process_response_url(), |
|
557 | + 'payment' => $payment->model_field_array() |
|
558 | + ), |
|
559 | + $payment |
|
560 | + ); |
|
561 | + return; |
|
562 | + } |
|
563 | + if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
564 | + $this->log( |
|
565 | + array( |
|
566 | + 'message' => esc_html__( |
|
567 | + 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
568 | + 'event_espresso' |
|
569 | + ), |
|
570 | + 'url' => $this->_process_response_url(), |
|
571 | + 'payment' => $payment->model_field_array() |
|
572 | + ), |
|
573 | + $payment |
|
574 | + ); |
|
575 | + return; |
|
576 | + } |
|
577 | + $grand_total_needs_resaving = false; |
|
578 | + /** @var EE_Line_Item $transaction_total_line_item */ |
|
579 | + $transaction_total_line_item = $transaction->total_line_item(); |
|
580 | + |
|
581 | + //might paypal have changed the taxes? |
|
582 | + if ($this->_paypal_taxes && $payment_was_itemized) { |
|
583 | + // note that we're doing this BEFORE adding shipping; |
|
584 | + // we actually want PayPal's shipping to remain non-taxable |
|
585 | + $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
586 | + $this->_line_item->set_total_tax_to( |
|
587 | + $transaction_total_line_item, |
|
588 | + (float)$update_info['tax'], |
|
589 | + esc_html__('Taxes', 'event_espresso'), |
|
590 | + esc_html__('Calculated by Paypal', 'event_espresso'), |
|
591 | + 'paypal_tax' |
|
592 | + ); |
|
593 | + $grand_total_needs_resaving = TRUE; |
|
594 | + } |
|
595 | + |
|
596 | + $shipping_amount = (float)$update_info['mc_shipping']; |
|
597 | + //might paypal have added shipping? |
|
598 | + if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
599 | + $this->_line_item->add_unrelated_item( |
|
600 | + $transaction_total_line_item, |
|
601 | + sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
602 | + $shipping_amount, |
|
603 | + esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
604 | + 1, |
|
605 | + false, |
|
606 | + 'paypal_shipping_' . $transaction->ID() |
|
607 | + ); |
|
608 | + $grand_total_needs_resaving = true; |
|
609 | + } |
|
610 | + |
|
611 | + if ($grand_total_needs_resaving) { |
|
612 | + $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
613 | + /** @var EE_Registration_Processor $registration_processor */ |
|
614 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
615 | + $registration_processor->update_registration_final_prices($transaction); |
|
616 | + } |
|
617 | + $this->log( |
|
618 | + array( |
|
619 | + 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
620 | + 'url' => $this->_process_response_url(), |
|
621 | + 'transaction (updated)' => $transaction->model_field_array(), |
|
622 | + 'payment (updated)' => $payment->model_field_array(), |
|
623 | + 'use_paypal_shipping' => $this->_paypal_shipping, |
|
624 | + 'use_paypal_tax' => $this->_paypal_taxes, |
|
625 | + 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
626 | + ), |
|
627 | + $payment |
|
628 | + ); |
|
629 | + } |
|
630 | 630 | } |
631 | 631 | // End of file EEG_Paypal_Standard.gateway.php |
632 | 632 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | use EventEspresso\core\exceptions\IpnException; |
4 | 4 | |
5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | 6 | exit('NO direct script access allowed'); |
7 | 7 | } |
8 | 8 | |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | $shipping_previously_added = $line_item->total(); |
144 | 144 | continue; |
145 | 145 | } |
146 | - $redirect_args['item_name_' . $item_num] = substr( |
|
146 | + $redirect_args['item_name_'.$item_num] = substr( |
|
147 | 147 | $gateway_formatter->formatLineItemName($line_item, $payment), |
148 | 148 | 0, 127 |
149 | 149 | ); |
150 | - $redirect_args['amount_' . $item_num] = $line_item->unit_price(); |
|
151 | - $redirect_args['quantity_' . $item_num] = $line_item->quantity(); |
|
150 | + $redirect_args['amount_'.$item_num] = $line_item->unit_price(); |
|
151 | + $redirect_args['quantity_'.$item_num] = $line_item->quantity(); |
|
152 | 152 | //if we're not letting PayPal calculate shipping, tell them its 0 |
153 | - if (! $this->_paypal_shipping) { |
|
154 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
155 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
153 | + if ( ! $this->_paypal_shipping) { |
|
154 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
155 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
156 | 156 | } |
157 | 157 | $item_num++; |
158 | 158 | $itemized_sum += $line_item->total(); |
@@ -172,12 +172,12 @@ discard block |
||
172 | 172 | //itemized sum is too big |
173 | 173 | $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
174 | 174 | } elseif ($itemized_sum_diff_from_txn_total > 0) { |
175 | - $redirect_args['item_name_' . $item_num] = substr( |
|
176 | - __('Other charges', 'event_espresso' ), 0, 127); |
|
177 | - $redirect_args['amount_' . $item_num] = $gateway_formatter->formatCurrency( |
|
175 | + $redirect_args['item_name_'.$item_num] = substr( |
|
176 | + __('Other charges', 'event_espresso'), 0, 127); |
|
177 | + $redirect_args['amount_'.$item_num] = $gateway_formatter->formatCurrency( |
|
178 | 178 | $itemized_sum_diff_from_txn_total |
179 | 179 | ); |
180 | - $redirect_args['quantity_' . $item_num] = 1; |
|
180 | + $redirect_args['quantity_'.$item_num] = 1; |
|
181 | 181 | $item_num++; |
182 | 182 | } |
183 | 183 | if ($total_discounts_to_cart_total > 0) { |
@@ -186,34 +186,34 @@ discard block |
||
186 | 186 | ); |
187 | 187 | } |
188 | 188 | //add our taxes to the order if we're NOT using PayPal's |
189 | - if (! $this->_paypal_taxes) { |
|
189 | + if ( ! $this->_paypal_taxes) { |
|
190 | 190 | $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
191 | 191 | } |
192 | 192 | } else { |
193 | 193 | $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
194 | 194 | //partial payment that's not for the remaining amount, so we can't send an itemized list |
195 | - $redirect_args['item_name_' . $item_num] = substr( |
|
195 | + $redirect_args['item_name_'.$item_num] = substr( |
|
196 | 196 | $gateway_formatter->formatPartialPaymentLineItemName($payment), |
197 | 197 | 0, |
198 | 198 | 127 |
199 | 199 | ); |
200 | - $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
201 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
202 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
200 | + $redirect_args['amount_'.$item_num] = $payment->amount(); |
|
201 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
202 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
203 | 203 | $redirect_args['tax_cart'] = '0'; |
204 | 204 | $item_num++; |
205 | 205 | } |
206 | 206 | |
207 | 207 | if ($this->_debug_mode) { |
208 | - $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | - $redirect_args['amount_' . $item_num] = 0; |
|
208 | + $redirect_args['item_name_'.$item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | + $redirect_args['amount_'.$item_num] = 0; |
|
210 | 210 | $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
211 | - $redirect_args['os0_' . $item_num] = $notify_url; |
|
211 | + $redirect_args['os0_'.$item_num] = $notify_url; |
|
212 | 212 | $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
213 | - $redirect_args['os1_' . $item_num] = $return_url; |
|
213 | + $redirect_args['os1_'.$item_num] = $return_url; |
|
214 | 214 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
215 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
216 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
215 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
216 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | $redirect_args['business'] = $this->_paypal_id; |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | $redirect_args['cmd'] = '_cart'; |
224 | 224 | $redirect_args['upload'] = 1; |
225 | 225 | $redirect_args['currency_code'] = $payment->currency_code(); |
226 | - $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
226 | + $redirect_args['rm'] = 2; //makes the user return with method=POST |
|
227 | 227 | if ($this->_image_url) { |
228 | 228 | $redirect_args['image_url'] = $this->_image_url; |
229 | 229 | } |
230 | 230 | $redirect_args['no_shipping'] = $this->_shipping_details; |
231 | - $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
231 | + $redirect_args['bn'] = 'EventEspresso_SP'; //EE will blow up if you change this |
|
232 | 232 | |
233 | 233 | $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
234 | 234 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | public function handle_payment_update($update_info, $transaction) |
262 | 262 | { |
263 | 263 | // verify there's payment data that's been sent |
264 | - if (empty($update_info['payment_status'] ) || empty($update_info['txn_id'])) { |
|
264 | + if (empty($update_info['payment_status']) || empty($update_info['txn_id'])) { |
|
265 | 265 | // log the results |
266 | 266 | $this->log( |
267 | 267 | array( |
@@ -283,12 +283,12 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
286 | - if (! $payment instanceof EEI_Payment) { |
|
286 | + if ( ! $payment instanceof EEI_Payment) { |
|
287 | 287 | $payment = $transaction->last_payment(); |
288 | 288 | } |
289 | 289 | // ok, then validate the IPN. Even if we've already processed this payment, |
290 | 290 | // let PayPal know we don't want to hear from them anymore! |
291 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
291 | + if ( ! $this->validate_ipn($update_info, $payment)) { |
|
292 | 292 | return $payment; |
293 | 293 | } |
294 | 294 | // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | //check if we've already processed this payment |
365 | 365 | if ($payment instanceof EEI_Payment) { |
366 | 366 | //payment exists. if this has the exact same status and amount, don't bother updating. just return |
367 | - if ($payment->status() === $status && (float)$payment->amount() === (float)$update_info['mc_gross']) { |
|
367 | + if ($payment->status() === $status && (float) $payment->amount() === (float) $update_info['mc_gross']) { |
|
368 | 368 | // DUPLICATED IPN! don't bother updating transaction |
369 | 369 | throw new IpnException( |
370 | 370 | sprintf( |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | } else { |
382 | 382 | // new payment yippee !!! |
383 | 383 | $payment->set_status($status); |
384 | - $payment->set_amount((float)$update_info['mc_gross']); |
|
384 | + $payment->set_amount((float) $update_info['mc_gross']); |
|
385 | 385 | $payment->set_gateway_response($gateway_response); |
386 | 386 | $payment->set_details($update_info); |
387 | 387 | $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | 'timeout' => 60, |
452 | 452 | // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
453 | 453 | // plz see: https://github.com/websharks/s2member/issues/610 |
454 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
454 | + 'user-agent' => 'Event Espresso v'.EVENT_ESPRESSO_VERSION.'; '.home_url(), |
|
455 | 455 | 'httpversion' => '1.1' |
456 | 456 | ) |
457 | 457 | ); |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | $response->get_error_message(), |
473 | 473 | print_r($response->get_error_data(), true) |
474 | 474 | ); |
475 | - } elseif(is_array($response) && isset($response['body'])) { |
|
475 | + } elseif (is_array($response) && isset($response['body'])) { |
|
476 | 476 | $error_msg = $response['body']; |
477 | 477 | } else { |
478 | 478 | $error_msg = print_r($response, true); |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | /** @var EE_Transaction $transaction */ |
529 | 529 | $transaction = $payment->transaction(); |
530 | 530 | $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
531 | - if (! $transaction) { |
|
531 | + if ( ! $transaction) { |
|
532 | 532 | $this->log( |
533 | 533 | esc_html__( |
534 | 534 | // @codingStandardsIgnoreStart |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
586 | 586 | $this->_line_item->set_total_tax_to( |
587 | 587 | $transaction_total_line_item, |
588 | - (float)$update_info['tax'], |
|
588 | + (float) $update_info['tax'], |
|
589 | 589 | esc_html__('Taxes', 'event_espresso'), |
590 | 590 | esc_html__('Calculated by Paypal', 'event_espresso'), |
591 | 591 | 'paypal_tax' |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | $grand_total_needs_resaving = TRUE; |
594 | 594 | } |
595 | 595 | |
596 | - $shipping_amount = (float)$update_info['mc_shipping']; |
|
596 | + $shipping_amount = (float) $update_info['mc_shipping']; |
|
597 | 597 | //might paypal have added shipping? |
598 | 598 | if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
599 | 599 | $this->_line_item->add_unrelated_item( |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
604 | 604 | 1, |
605 | 605 | false, |
606 | - 'paypal_shipping_' . $transaction->ID() |
|
606 | + 'paypal_shipping_'.$transaction->ID() |
|
607 | 607 | ); |
608 | 608 | $grand_total_needs_resaving = true; |
609 | 609 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $this->_columns = array_merge( $columns, $this->_columns ); |
91 | 91 | $this->_primary_column = '_REG_att_checked_in'; |
92 | 92 | if ( ! empty( $evt_id ) |
93 | - && EE_Registry::instance()->CAP->current_user_can( |
|
93 | + && EE_Registry::instance()->CAP->current_user_can( |
|
94 | 94 | 'ee_read_registrations', |
95 | 95 | 'espresso_registrations_registrations_reports', |
96 | 96 | $evt_id |
@@ -107,44 +107,44 @@ discard block |
||
107 | 107 | ), |
108 | 108 | ); |
109 | 109 | } |
110 | - $this->_bottom_buttons['report_filtered'] = array( |
|
111 | - 'route' => 'registrations_checkin_report', |
|
112 | - 'extra_request' => array( |
|
113 | - 'use_filters' => true, |
|
114 | - 'filters' => array_merge( |
|
115 | - array( |
|
116 | - 'EVT_ID' => $evt_id, |
|
117 | - ), |
|
118 | - array_diff_key( |
|
119 | - $this->_req_data, |
|
120 | - array_flip( |
|
121 | - array( |
|
122 | - 'page', |
|
123 | - 'action', |
|
124 | - 'default_nonce', |
|
125 | - ) |
|
126 | - ) |
|
127 | - ) |
|
128 | - ), |
|
129 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
130 | - ), |
|
131 | - ); |
|
110 | + $this->_bottom_buttons['report_filtered'] = array( |
|
111 | + 'route' => 'registrations_checkin_report', |
|
112 | + 'extra_request' => array( |
|
113 | + 'use_filters' => true, |
|
114 | + 'filters' => array_merge( |
|
115 | + array( |
|
116 | + 'EVT_ID' => $evt_id, |
|
117 | + ), |
|
118 | + array_diff_key( |
|
119 | + $this->_req_data, |
|
120 | + array_flip( |
|
121 | + array( |
|
122 | + 'page', |
|
123 | + 'action', |
|
124 | + 'default_nonce', |
|
125 | + ) |
|
126 | + ) |
|
127 | + ) |
|
128 | + ), |
|
129 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
130 | + ), |
|
131 | + ); |
|
132 | 132 | $this->_sortable_columns = array( |
133 | - /** |
|
134 | - * Allows users to change the default sort if they wish. |
|
135 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
136 | - * |
|
137 | - * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
138 | - * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
139 | - * for a specific list table you can use the provided reference to this object instance. |
|
140 | - */ |
|
133 | + /** |
|
134 | + * Allows users to change the default sort if they wish. |
|
135 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
136 | + * |
|
137 | + * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
138 | + * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
139 | + * for a specific list table you can use the provided reference to this object instance. |
|
140 | + */ |
|
141 | 141 | 'ATT_name' => array( |
142 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
143 | - true, |
|
144 | - $this |
|
145 | - ) |
|
146 | - ? array( 'ATT_lname' => true ) |
|
147 | - : array( 'ATT_fname' => true ), |
|
142 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
143 | + true, |
|
144 | + $this |
|
145 | + ) |
|
146 | + ? array( 'ATT_lname' => true ) |
|
147 | + : array( 'ATT_fname' => true ), |
|
148 | 148 | 'Event' => array( 'Event.EVT.Name' => false ), |
149 | 149 | ); |
150 | 150 | $this->_hidden_columns = array(); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | if ( ! $evt->get_count_of_all_registrations() ) { |
204 | 204 | continue; |
205 | 205 | } |
206 | - $evts[] = array( |
|
206 | + $evts[] = array( |
|
207 | 207 | 'id' => $evt->ID(), |
208 | 208 | 'text' => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt), |
209 | 209 | 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
@@ -227,8 +227,8 @@ discard block |
||
227 | 227 | if ( count( $this->_dtts_for_event ) > 1 ) { |
228 | 228 | $dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' ); |
229 | 229 | foreach ( $this->_dtts_for_event as $dtt ) { |
230 | - $datetime_string = $dtt->name(); |
|
231 | - $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : ''; |
|
230 | + $datetime_string = $dtt->name(); |
|
231 | + $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : ''; |
|
232 | 232 | $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
233 | 233 | $dtts[ $dtt->ID() ] = $datetime_string; |
234 | 234 | } |
@@ -301,16 +301,16 @@ discard block |
||
301 | 301 | |
302 | 302 | |
303 | 303 | |
304 | - /** |
|
305 | - * column_REG_att_checked_in |
|
306 | - * |
|
307 | - * @param EE_Registration $item |
|
308 | - * @return string |
|
309 | - * @throws EE_Error |
|
310 | - * @throws InvalidArgumentException |
|
311 | - * @throws InvalidDataTypeException |
|
312 | - * @throws InvalidInterfaceException |
|
313 | - */ |
|
304 | + /** |
|
305 | + * column_REG_att_checked_in |
|
306 | + * |
|
307 | + * @param EE_Registration $item |
|
308 | + * @return string |
|
309 | + * @throws EE_Error |
|
310 | + * @throws InvalidArgumentException |
|
311 | + * @throws InvalidDataTypeException |
|
312 | + * @throws InvalidInterfaceException |
|
313 | + */ |
|
314 | 314 | public function column__REG_att_checked_in( EE_Registration $item ) { |
315 | 315 | $attendee = $item->attendee(); |
316 | 316 | $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
@@ -321,13 +321,13 @@ discard block |
||
321 | 321 | $this->_cur_dtt_id = $latest_related_datetime->ID(); |
322 | 322 | } |
323 | 323 | } |
324 | - $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
325 | - $item, |
|
326 | - $this->_cur_dtt_id |
|
327 | - ); |
|
324 | + $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
325 | + $item, |
|
326 | + $this->_cur_dtt_id |
|
327 | + ); |
|
328 | 328 | $nonce = wp_create_nonce( 'checkin_nonce' ); |
329 | 329 | $toggle_active = ! empty ( $this->_cur_dtt_id ) |
330 | - && EE_Registry::instance()->CAP->current_user_can( |
|
330 | + && EE_Registry::instance()->CAP->current_user_can( |
|
331 | 331 | 'ee_edit_checkin', |
332 | 332 | 'espresso_registrations_toggle_checkin_status', |
333 | 333 | $item->ID() |
@@ -336,11 +336,11 @@ discard block |
||
336 | 336 | : ''; |
337 | 337 | $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
338 | 338 | return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
339 | - . ' data-_regid="' . $item->ID() . '"' |
|
340 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
341 | - . ' data-nonce="' . $nonce . '">' |
|
342 | - . '</span>' |
|
343 | - . $mobile_view_content; |
|
339 | + . ' data-_regid="' . $item->ID() . '"' |
|
340 | + . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
341 | + . ' data-nonce="' . $nonce . '">' |
|
342 | + . '</span>' |
|
343 | + . $mobile_view_content; |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | 'espresso_registrations_edit_attendee' |
366 | 366 | ) |
367 | 367 | ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' |
368 | - . $item->attendee()->full_name() |
|
369 | - . '</a>' |
|
368 | + . $item->attendee()->full_name() |
|
369 | + . '</a>' |
|
370 | 370 | : $item->attendee()->full_name(); |
371 | 371 | $name_link .= $item->count() === 1 |
372 | 372 | ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
@@ -401,14 +401,14 @@ discard block |
||
401 | 401 | ? $latest_related_datetime->ID() |
402 | 402 | : $DTT_ID; |
403 | 403 | if ( ! empty( $DTT_ID ) |
404 | - && EE_Registry::instance()->CAP->current_user_can( |
|
404 | + && EE_Registry::instance()->CAP->current_user_can( |
|
405 | 405 | 'ee_read_checkins', |
406 | 406 | 'espresso_registrations_registration_checkins' |
407 | 407 | ) |
408 | 408 | ) { |
409 | 409 | $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
410 | 410 | array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID ), |
411 | - REG_ADMIN_URL |
|
411 | + REG_ADMIN_URL |
|
412 | 412 | ); |
413 | 413 | // get the timestamps for this registration's checkins, related to the selected datetime |
414 | 414 | $timestamps = $item->get_many_related( 'Checkin', array( array( 'DTT_ID' => $DTT_ID ) ) ); |
@@ -516,15 +516,15 @@ discard block |
||
516 | 516 | ) ? ' |
517 | 517 | <span class="reg-pad-rght"> |
518 | 518 | <a class="status-' |
519 | - . $item->transaction()->status_ID() |
|
520 | - . '" href="' |
|
521 | - . $view_txn_lnk_url |
|
522 | - . '" title="' |
|
523 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
524 | - . '"> |
|
519 | + . $item->transaction()->status_ID() |
|
520 | + . '" href="' |
|
521 | + . $view_txn_lnk_url |
|
522 | + . '" title="' |
|
523 | + . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
524 | + . '"> |
|
525 | 525 | ' |
526 | - . $item->transaction()->pretty_paid() |
|
527 | - . ' |
|
526 | + . $item->transaction()->pretty_paid() |
|
527 | + . ' |
|
528 | 528 | </a> |
529 | 529 | <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
530 | 530 | } |
@@ -557,12 +557,12 @@ discard block |
||
557 | 557 | 'ee_read_transaction', |
558 | 558 | 'espresso_transactions_view_transaction' |
559 | 559 | ) ? '<a href="' |
560 | - . $view_txn_url |
|
561 | - . '" title="' |
|
562 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
563 | - . '"><span class="reg-pad-rght">' |
|
564 | - . $txn_total |
|
565 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
560 | + . $view_txn_url |
|
561 | + . '" title="' |
|
562 | + . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
563 | + . '"><span class="reg-pad-rght">' |
|
564 | + . $txn_total |
|
565 | + . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
566 | 566 | } else { |
567 | 567 | return '<span class="reg-pad-rght"></span>'; |
568 | 568 | } |
@@ -45,51 +45,51 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @param \Registrations_Admin_Page $admin_page |
47 | 47 | */ |
48 | - public function __construct( $admin_page ) { |
|
49 | - parent::__construct( $admin_page ); |
|
48 | + public function __construct($admin_page) { |
|
49 | + parent::__construct($admin_page); |
|
50 | 50 | $this->_status = $this->_admin_page->get_registration_status_array(); |
51 | 51 | } |
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | 55 | protected function _setup_data() { |
56 | - $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( $this->_per_page ) |
|
57 | - : $this->_admin_page->get_event_attendees( $this->_per_page, false, true ); |
|
56 | + $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page) |
|
57 | + : $this->_admin_page->get_event_attendees($this->_per_page, false, true); |
|
58 | 58 | $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( |
59 | 59 | $this->_per_page, |
60 | 60 | true |
61 | - ) : $this->_admin_page->get_event_attendees( $this->_per_page, true, true ); |
|
61 | + ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | 66 | protected function _set_properties() { |
67 | - $evt_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null; |
|
67 | + $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
68 | 68 | $this->_wp_list_args = array( |
69 | - 'singular' => __( 'registrant', 'event_espresso' ), |
|
70 | - 'plural' => __( 'registrants', 'event_espresso' ), |
|
69 | + 'singular' => __('registrant', 'event_espresso'), |
|
70 | + 'plural' => __('registrants', 'event_espresso'), |
|
71 | 71 | 'ajax' => true, |
72 | 72 | 'screen' => $this->_admin_page->get_current_screen()->id, |
73 | 73 | ); |
74 | 74 | $columns = array(); |
75 | 75 | //$columns['_Reg_Status'] = ''; |
76 | - if ( ! empty( $evt_id ) ) { |
|
76 | + if ( ! empty($evt_id)) { |
|
77 | 77 | $columns['cb'] = '<input type="checkbox" />'; //Render a checkbox instead of text |
78 | 78 | $this->_has_checkbox_column = true; |
79 | 79 | } |
80 | 80 | $this->_columns = array( |
81 | 81 | '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>', |
82 | - 'ATT_name' => __( 'Registrant', 'event_espresso' ), |
|
83 | - 'ATT_email' => __( 'Email Address', 'event_espresso' ), |
|
84 | - 'Event' => __( 'Event', 'event_espresso' ), |
|
85 | - 'PRC_name' => __( 'TKT Option', 'event_espresso' ), |
|
86 | - '_REG_final_price' => __( 'Price', 'event_espresso' ), |
|
87 | - 'TXN_paid' => __( 'Paid', 'event_espresso' ), |
|
88 | - 'TXN_total' => __( 'Total', 'event_espresso' ), |
|
82 | + 'ATT_name' => __('Registrant', 'event_espresso'), |
|
83 | + 'ATT_email' => __('Email Address', 'event_espresso'), |
|
84 | + 'Event' => __('Event', 'event_espresso'), |
|
85 | + 'PRC_name' => __('TKT Option', 'event_espresso'), |
|
86 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
87 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
88 | + 'TXN_total' => __('Total', 'event_espresso'), |
|
89 | 89 | ); |
90 | - $this->_columns = array_merge( $columns, $this->_columns ); |
|
90 | + $this->_columns = array_merge($columns, $this->_columns); |
|
91 | 91 | $this->_primary_column = '_REG_att_checked_in'; |
92 | - if ( ! empty( $evt_id ) |
|
92 | + if ( ! empty($evt_id) |
|
93 | 93 | && EE_Registry::instance()->CAP->current_user_can( |
94 | 94 | 'ee_read_registrations', |
95 | 95 | 'espresso_registrations_registrations_reports', |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | 'extra_request' => |
103 | 103 | array( |
104 | 104 | 'EVT_ID' => $evt_id, |
105 | - 'return_url' => urlencode( "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ), |
|
105 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
106 | 106 | ), |
107 | 107 | ), |
108 | 108 | ); |
@@ -143,12 +143,12 @@ discard block |
||
143 | 143 | true, |
144 | 144 | $this |
145 | 145 | ) |
146 | - ? array( 'ATT_lname' => true ) |
|
147 | - : array( 'ATT_fname' => true ), |
|
148 | - 'Event' => array( 'Event.EVT.Name' => false ), |
|
146 | + ? array('ATT_lname' => true) |
|
147 | + : array('ATT_fname' => true), |
|
148 | + 'Event' => array('Event.EVT.Name' => false), |
|
149 | 149 | ); |
150 | 150 | $this->_hidden_columns = array(); |
151 | - $this->_evt = EEM_Event::instance()->get_one_by_ID( $evt_id ); |
|
151 | + $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id); |
|
152 | 152 | $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array(); |
153 | 153 | } |
154 | 154 | |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | * @param \EE_Registration $item |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - protected function _get_row_class( $item ) { |
|
162 | - $class = parent::_get_row_class( $item ); |
|
161 | + protected function _get_row_class($item) { |
|
162 | + $class = parent::_get_row_class($item); |
|
163 | 163 | //add status class |
164 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
165 | - if ( $this->_has_checkbox_column ) { |
|
164 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
165 | + if ($this->_has_checkbox_column) { |
|
166 | 166 | $class .= ' has-checkbox-column'; |
167 | 167 | } |
168 | 168 | return $class; |
@@ -176,61 +176,61 @@ discard block |
||
176 | 176 | */ |
177 | 177 | protected function _get_table_filters() { |
178 | 178 | $filters = $where = array(); |
179 | - $current_EVT_ID = isset( $this->_req_data['event_id'] ) ? (int) $this->_req_data['event_id'] : 0; |
|
180 | - if ( empty( $this->_dtts_for_event ) || count( $this->_dtts_for_event ) === 1 ) { |
|
179 | + $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0; |
|
180 | + if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
|
181 | 181 | //this means we don't have an event so let's setup a filter dropdown for all the events to select |
182 | 182 | //note possible capability restrictions |
183 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) { |
|
184 | - $where['status**'] = array( '!=', 'private' ); |
|
183 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
184 | + $where['status**'] = array('!=', 'private'); |
|
185 | 185 | } |
186 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) { |
|
186 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
187 | 187 | $where['EVT_wp_user'] = get_current_user_id(); |
188 | 188 | } |
189 | 189 | $events = EEM_Event::instance()->get_all( |
190 | 190 | array( |
191 | 191 | $where, |
192 | - 'order_by' => array( 'Datetime.DTT_EVT_start' => 'DESC' ), |
|
192 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'), |
|
193 | 193 | ) |
194 | 194 | ); |
195 | 195 | $evts[] = array( |
196 | 196 | 'id' => 0, |
197 | - 'text' => __( 'To toggle Check-in status, select an event', 'event_espresso' ), |
|
197 | + 'text' => __('To toggle Check-in status, select an event', 'event_espresso'), |
|
198 | 198 | ); |
199 | 199 | $checked = 'checked'; |
200 | 200 | /** @var EE_Event $evt */ |
201 | - foreach ( $events as $evt ) { |
|
201 | + foreach ($events as $evt) { |
|
202 | 202 | //any registrations for this event? |
203 | - if ( ! $evt->get_count_of_all_registrations() ) { |
|
203 | + if ( ! $evt->get_count_of_all_registrations()) { |
|
204 | 204 | continue; |
205 | 205 | } |
206 | 206 | $evts[] = array( |
207 | 207 | 'id' => $evt->ID(), |
208 | - 'text' => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt), |
|
208 | + 'text' => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get('EVT_name'), $evt), |
|
209 | 209 | 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
210 | 210 | ); |
211 | - if ( $evt->ID() === $current_EVT_ID && $evt->is_expired() ) { |
|
211 | + if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) { |
|
212 | 212 | $checked = ''; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | $event_filter = '<div class="ee-event-filter">'; |
216 | - $event_filter .= EEH_Form_Fields::select_input( 'event_id', $evts, $current_EVT_ID ); |
|
216 | + $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
|
217 | 217 | $event_filter .= '<span class="ee-event-filter-toggle">'; |
218 | - $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
219 | - $event_filter .= __( 'Hide Expired Events', 'event_espresso' ); |
|
218 | + $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> '; |
|
219 | + $event_filter .= __('Hide Expired Events', 'event_espresso'); |
|
220 | 220 | $event_filter .= '</span>'; |
221 | 221 | $event_filter .= '</div>'; |
222 | 222 | $filters[] = $event_filter; |
223 | 223 | } |
224 | - if ( ! empty( $this->_dtts_for_event ) ) { |
|
224 | + if ( ! empty($this->_dtts_for_event)) { |
|
225 | 225 | //DTT datetimes filter |
226 | - $this->_cur_dtt_id = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0; |
|
227 | - if ( count( $this->_dtts_for_event ) > 1 ) { |
|
228 | - $dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' ); |
|
229 | - foreach ( $this->_dtts_for_event as $dtt ) { |
|
226 | + $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
|
227 | + if (count($this->_dtts_for_event) > 1) { |
|
228 | + $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso'); |
|
229 | + foreach ($this->_dtts_for_event as $dtt) { |
|
230 | 230 | $datetime_string = $dtt->name(); |
231 | - $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : ''; |
|
232 | - $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
233 | - $dtts[ $dtt->ID() ] = $datetime_string; |
|
231 | + $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : ''; |
|
232 | + $datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string; |
|
233 | + $dtts[$dtt->ID()] = $datetime_string; |
|
234 | 234 | } |
235 | 235 | $input = new EE_Select_Input( |
236 | 236 | $dtts, |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | ) |
242 | 242 | ); |
243 | 243 | $filters[] = $input->get_html_for_input(); |
244 | - $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
244 | + $filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">'; |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | return $filters; |
@@ -260,22 +260,22 @@ discard block |
||
260 | 260 | * @throws \EE_Error |
261 | 261 | */ |
262 | 262 | protected function _get_total_event_attendees() { |
263 | - $EVT_ID = isset( $this->_req_data['event_id'] ) ? absint( $this->_req_data['event_id'] ) : false; |
|
263 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
264 | 264 | $DTT_ID = $this->_cur_dtt_id; |
265 | 265 | $query_params = array(); |
266 | - if ( $EVT_ID ) { |
|
266 | + if ($EVT_ID) { |
|
267 | 267 | $query_params[0]['EVT_ID'] = $EVT_ID; |
268 | 268 | } |
269 | 269 | //if DTT is included we only show for that datetime. Otherwise we're showing for all datetimes (the event). |
270 | - if ( $DTT_ID ) { |
|
270 | + if ($DTT_ID) { |
|
271 | 271 | $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
272 | 272 | } |
273 | 273 | $status_ids_array = apply_filters( |
274 | 274 | 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
275 | - array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved ) |
|
275 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
276 | 276 | ); |
277 | - $query_params[0]['STS_ID'] = array( 'IN', $status_ids_array ); |
|
278 | - return EEM_Registration::instance()->count( $query_params ); |
|
277 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
278 | + return EEM_Registration::instance()->count($query_params); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * @param \EE_Registration $item |
285 | 285 | * @return string |
286 | 286 | */ |
287 | - public function column__Reg_Status( EE_Registration $item ) { |
|
288 | - return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>'; |
|
287 | + public function column__Reg_Status(EE_Registration $item) { |
|
288 | + return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>'; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | |
@@ -295,8 +295,8 @@ discard block |
||
295 | 295 | * @return string |
296 | 296 | * @throws \EE_Error |
297 | 297 | */ |
298 | - public function column_cb( $item ) { |
|
299 | - return sprintf( '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID() ); |
|
298 | + public function column_cb($item) { |
|
299 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID()); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | * @throws InvalidDataTypeException |
312 | 312 | * @throws InvalidInterfaceException |
313 | 313 | */ |
314 | - public function column__REG_att_checked_in( EE_Registration $item ) { |
|
314 | + public function column__REG_att_checked_in(EE_Registration $item) { |
|
315 | 315 | $attendee = $item->attendee(); |
316 | 316 | $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
317 | 317 | |
318 | - if ( $this->_cur_dtt_id === 0 && count( $this->_dtts_for_event ) === 1 ) { |
|
318 | + if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) { |
|
319 | 319 | $latest_related_datetime = $item->get_latest_related_datetime(); |
320 | - if ( $latest_related_datetime instanceof EE_Datetime ) { |
|
320 | + if ($latest_related_datetime instanceof EE_Datetime) { |
|
321 | 321 | $this->_cur_dtt_id = $latest_related_datetime->ID(); |
322 | 322 | } |
323 | 323 | } |
@@ -325,8 +325,8 @@ discard block |
||
325 | 325 | $item, |
326 | 326 | $this->_cur_dtt_id |
327 | 327 | ); |
328 | - $nonce = wp_create_nonce( 'checkin_nonce' ); |
|
329 | - $toggle_active = ! empty ( $this->_cur_dtt_id ) |
|
328 | + $nonce = wp_create_nonce('checkin_nonce'); |
|
329 | + $toggle_active = ! empty ($this->_cur_dtt_id) |
|
330 | 330 | && EE_Registry::instance()->CAP->current_user_can( |
331 | 331 | 'ee_edit_checkin', |
332 | 332 | 'espresso_registrations_toggle_checkin_status', |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | ) |
335 | 335 | ? ' clickable trigger-checkin' |
336 | 336 | : ''; |
337 | - $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
338 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
|
339 | - . ' data-_regid="' . $item->ID() . '"' |
|
340 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
341 | - . ' data-nonce="' . $nonce . '">' |
|
337 | + $mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>'; |
|
338 | + return '<span class="'.$checkin_status_dashicon->cssClasses().$toggle_active.'"' |
|
339 | + . ' data-_regid="'.$item->ID().'"' |
|
340 | + . ' data-dttid="'.$this->_cur_dtt_id.'"' |
|
341 | + . ' data-nonce="'.$nonce.'">' |
|
342 | 342 | . '</span>' |
343 | 343 | . $mobile_view_content; |
344 | 344 | } |
@@ -350,21 +350,21 @@ discard block |
||
350 | 350 | * @return mixed|string|void |
351 | 351 | * @throws \EE_Error |
352 | 352 | */ |
353 | - public function column_ATT_name( EE_Registration $item ) { |
|
353 | + public function column_ATT_name(EE_Registration $item) { |
|
354 | 354 | $attendee = $item->attendee(); |
355 | - if ( ! $attendee instanceof EE_Attendee ) { |
|
356 | - return __( 'No contact record for this registration.', 'event_espresso' ); |
|
355 | + if ( ! $attendee instanceof EE_Attendee) { |
|
356 | + return __('No contact record for this registration.', 'event_espresso'); |
|
357 | 357 | } |
358 | 358 | // edit attendee link |
359 | 359 | $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
360 | - array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ), |
|
360 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
361 | 361 | REG_ADMIN_URL |
362 | 362 | ); |
363 | 363 | $name_link = EE_Registry::instance()->CAP->current_user_can( |
364 | 364 | 'ee_edit_contacts', |
365 | 365 | 'espresso_registrations_edit_attendee' |
366 | 366 | ) |
367 | - ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' |
|
367 | + ? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
368 | 368 | . $item->attendee()->full_name() |
369 | 369 | . '</a>' |
370 | 370 | : $item->attendee()->full_name(); |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
373 | 373 | : ''; |
374 | 374 | //add group details |
375 | - $name_link .= ' ' . sprintf( __( '(%s of %s)', 'event_espresso' ), $item->count(), $item->group_size() ); |
|
375 | + $name_link .= ' '.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
376 | 376 | //add regcode |
377 | 377 | $link = EE_Admin_Page::add_query_args_and_nonce( |
378 | - array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ), |
|
378 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
379 | 379 | REG_ADMIN_URL |
380 | 380 | ); |
381 | 381 | $name_link .= '<br>'; |
@@ -384,51 +384,51 @@ discard block |
||
384 | 384 | 'view_registration', |
385 | 385 | $item->ID() |
386 | 386 | ) |
387 | - ? '<a href="' . $link . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' |
|
387 | + ? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
388 | 388 | . $item->reg_code() |
389 | 389 | . '</a>' |
390 | 390 | : $item->reg_code(); |
391 | 391 | //status |
392 | 392 | $name_link .= '<br><span class="ee-status-text-small">'; |
393 | - $name_link .= EEH_Template::pretty_status( $item->status_ID(), false, 'sentence' ); |
|
393 | + $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence'); |
|
394 | 394 | $name_link .= '</span>'; |
395 | 395 | $actions = array(); |
396 | 396 | $DTT_ID = $this->_cur_dtt_id; |
397 | - $latest_related_datetime = empty( $DTT_ID ) && ! empty( $this->_req_data['event_id'] ) && $item instanceof EE_Registration |
|
397 | + $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration |
|
398 | 398 | ? $item->get_latest_related_datetime() |
399 | 399 | : null; |
400 | 400 | $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
401 | 401 | ? $latest_related_datetime->ID() |
402 | 402 | : $DTT_ID; |
403 | - if ( ! empty( $DTT_ID ) |
|
403 | + if ( ! empty($DTT_ID) |
|
404 | 404 | && EE_Registry::instance()->CAP->current_user_can( |
405 | 405 | 'ee_read_checkins', |
406 | 406 | 'espresso_registrations_registration_checkins' |
407 | 407 | ) |
408 | 408 | ) { |
409 | 409 | $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
410 | - array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID ), |
|
410 | + array('action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID), |
|
411 | 411 | REG_ADMIN_URL |
412 | 412 | ); |
413 | 413 | // get the timestamps for this registration's checkins, related to the selected datetime |
414 | - $timestamps = $item->get_many_related( 'Checkin', array( array( 'DTT_ID' => $DTT_ID ) ) ); |
|
415 | - if( ! empty( $timestamps ) ) { |
|
414 | + $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID))); |
|
415 | + if ( ! empty($timestamps)) { |
|
416 | 416 | // get the last timestamp |
417 | - $last_timestamp = end( $timestamps ); |
|
417 | + $last_timestamp = end($timestamps); |
|
418 | 418 | // checked in or checked out? |
419 | - $checkin_status = $last_timestamp->get( 'CHK_in' ) |
|
420 | - ? esc_html__( 'Checked In', 'event_espresso' ) |
|
421 | - : esc_html__( 'Checked Out', 'event_espresso' ); |
|
419 | + $checkin_status = $last_timestamp->get('CHK_in') |
|
420 | + ? esc_html__('Checked In', 'event_espresso') |
|
421 | + : esc_html__('Checked Out', 'event_espresso'); |
|
422 | 422 | // get timestamp string |
423 | - $timestamp_string = $last_timestamp->get_datetime( 'CHK_timestamp' ); |
|
424 | - $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' . esc_attr__( |
|
423 | + $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
|
424 | + $actions['checkin'] = '<a href="'.$checkin_list_url.'" title="'.esc_attr__( |
|
425 | 425 | 'View this registrant\'s check-ins/checkouts for the datetime', |
426 | 426 | 'event_espresso' |
427 | - ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
427 | + ).'">'.$checkin_status.': '.$timestamp_string.'</a>'; |
|
428 | 428 | } |
429 | 429 | } |
430 | - return ( ! empty( $DTT_ID ) && ! empty( $timestamps ) ) |
|
431 | - ? sprintf( '%1$s %2$s', $name_link, $this->row_actions( $actions, true ) ) |
|
430 | + return ( ! empty($DTT_ID) && ! empty($timestamps)) |
|
431 | + ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
|
432 | 432 | : $name_link; |
433 | 433 | } |
434 | 434 | |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | * @param \EE_Registration $item |
439 | 439 | * @return string |
440 | 440 | */ |
441 | - public function column_ATT_email( EE_Registration $item ) { |
|
441 | + public function column_ATT_email(EE_Registration $item) { |
|
442 | 442 | $attendee = $item->attendee(); |
443 | 443 | return $attendee instanceof EE_Attendee ? $attendee->email() : ''; |
444 | 444 | } |
@@ -450,22 +450,22 @@ discard block |
||
450 | 450 | * @return bool|string |
451 | 451 | * @throws \EE_Error |
452 | 452 | */ |
453 | - public function column_Event( EE_Registration $item ) { |
|
453 | + public function column_Event(EE_Registration $item) { |
|
454 | 454 | try { |
455 | 455 | $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event(); |
456 | 456 | $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
457 | - array( 'action' => 'event_registrations', 'event_id' => $event->ID() ), |
|
457 | + array('action' => 'event_registrations', 'event_id' => $event->ID()), |
|
458 | 458 | REG_ADMIN_URL |
459 | 459 | ); |
460 | 460 | $event_label = EE_Registry::instance()->CAP->current_user_can( |
461 | 461 | 'ee_read_checkins', |
462 | 462 | 'espresso_registrations_registration_checkins' |
463 | - ) ? '<a href="' . $chkin_lnk_url . '" title="' . esc_attr__( |
|
463 | + ) ? '<a href="'.$chkin_lnk_url.'" title="'.esc_attr__( |
|
464 | 464 | 'View Checkins for this Event', |
465 | 465 | 'event_espresso' |
466 | - ) . '">' . $event->name() . '</a>' : $event->name(); |
|
467 | - } catch ( \EventEspresso\core\exceptions\EntityNotFoundException $e ) { |
|
468 | - $event_label = esc_html__( 'Unknown', 'event_espresso' ); |
|
466 | + ).'">'.$event->name().'</a>' : $event->name(); |
|
467 | + } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
468 | + $event_label = esc_html__('Unknown', 'event_espresso'); |
|
469 | 469 | } |
470 | 470 | return $event_label; |
471 | 471 | } |
@@ -476,8 +476,8 @@ discard block |
||
476 | 476 | * @param \EE_Registration $item |
477 | 477 | * @return mixed|string|void |
478 | 478 | */ |
479 | - public function column_PRC_name( EE_Registration $item ) { |
|
480 | - return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __( "Unknown", "event_espresso" ); |
|
479 | + public function column_PRC_name(EE_Registration $item) { |
|
480 | + return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso"); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | |
@@ -488,8 +488,8 @@ discard block |
||
488 | 488 | * @param \EE_Registration $item |
489 | 489 | * @return string |
490 | 490 | */ |
491 | - public function column__REG_final_price( EE_Registration $item ) { |
|
492 | - return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>'; |
|
491 | + public function column__REG_final_price(EE_Registration $item) { |
|
492 | + return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>'; |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | |
@@ -501,13 +501,13 @@ discard block |
||
501 | 501 | * @return string |
502 | 502 | * @throws \EE_Error |
503 | 503 | */ |
504 | - public function column_TXN_paid( EE_Registration $item ) { |
|
505 | - if ( $item->count() === 1 ) { |
|
506 | - if ( $item->transaction()->paid() >= $item->transaction()->total() ) { |
|
504 | + public function column_TXN_paid(EE_Registration $item) { |
|
505 | + if ($item->count() === 1) { |
|
506 | + if ($item->transaction()->paid() >= $item->transaction()->total()) { |
|
507 | 507 | return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
508 | 508 | } else { |
509 | 509 | $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
510 | - array( 'action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID() ), |
|
510 | + array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()), |
|
511 | 511 | TXN_ADMIN_URL |
512 | 512 | ); |
513 | 513 | return EE_Registry::instance()->CAP->current_user_can( |
@@ -520,13 +520,13 @@ discard block |
||
520 | 520 | . '" href="' |
521 | 521 | . $view_txn_lnk_url |
522 | 522 | . '" title="' |
523 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
523 | + . esc_attr__('View Transaction', 'event_espresso') |
|
524 | 524 | . '"> |
525 | 525 | ' |
526 | 526 | . $item->transaction()->pretty_paid() |
527 | 527 | . ' |
528 | 528 | </a> |
529 | - <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
529 | + <span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
530 | 530 | } |
531 | 531 | } else { |
532 | 532 | return '<span class="reg-pad-rght"></span>'; |
@@ -542,13 +542,13 @@ discard block |
||
542 | 542 | * @return string |
543 | 543 | * @throws \EE_Error |
544 | 544 | */ |
545 | - public function column_TXN_total( EE_Registration $item ) { |
|
545 | + public function column_TXN_total(EE_Registration $item) { |
|
546 | 546 | $txn = $item->transaction(); |
547 | - $view_txn_url = add_query_arg( array( 'action' => 'view_transaction', 'TXN_ID' => $txn->ID() ), TXN_ADMIN_URL ); |
|
548 | - if ( $item->get( 'REG_count' ) === 1 ) { |
|
547 | + $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL); |
|
548 | + if ($item->get('REG_count') === 1) { |
|
549 | 549 | $line_total_obj = $txn->total_line_item(); |
550 | 550 | $txn_total = $line_total_obj instanceof EE_Line_Item |
551 | - ? $line_total_obj->get_pretty( 'LIN_total' ) |
|
551 | + ? $line_total_obj->get_pretty('LIN_total') |
|
552 | 552 | : __( |
553 | 553 | 'View Transaction', |
554 | 554 | 'event_espresso' |
@@ -559,10 +559,10 @@ discard block |
||
559 | 559 | ) ? '<a href="' |
560 | 560 | . $view_txn_url |
561 | 561 | . '" title="' |
562 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
562 | + . esc_attr__('View Transaction', 'event_espresso') |
|
563 | 563 | . '"><span class="reg-pad-rght">' |
564 | 564 | . $txn_total |
565 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
565 | + . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>'; |
|
566 | 566 | } else { |
567 | 567 | return '<span class="reg-pad-rght"></span>'; |
568 | 568 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -class EE_Text_Area_Display_Strategy extends EE_Display_Strategy_Base{ |
|
2 | +class EE_Text_Area_Display_Strategy extends EE_Display_Strategy_Base { |
|
3 | 3 | |
4 | 4 | |
5 | 5 | |
@@ -7,32 +7,32 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @return string of html to display the field |
9 | 9 | */ |
10 | - function display(){ |
|
10 | + function display() { |
|
11 | 11 | $input = $this->_input; |
12 | 12 | $raw_value = maybe_serialize($input->raw_value()); |
13 | - if( $input instanceof EE_Text_Area_Input ) { |
|
13 | + if ($input instanceof EE_Text_Area_Input) { |
|
14 | 14 | $rows = $input->get_rows(); |
15 | 15 | $cols = $input->get_cols(); |
16 | - }else{ |
|
16 | + } else { |
|
17 | 17 | $rows = 4; |
18 | 18 | $cols = 20; |
19 | 19 | } |
20 | 20 | $html = '<textarea'; |
21 | - $html .= ' id="' . $input->html_id() . '"'; |
|
22 | - $html .= ' name="' . $input->html_name() . '"'; |
|
23 | - $html .= ' class="' . $input->html_class() . '"' ; |
|
24 | - $html .= ' style="' . $input->html_style() . '"'; |
|
21 | + $html .= ' id="'.$input->html_id().'"'; |
|
22 | + $html .= ' name="'.$input->html_name().'"'; |
|
23 | + $html .= ' class="'.$input->html_class().'"'; |
|
24 | + $html .= ' style="'.$input->html_style().'"'; |
|
25 | 25 | $html .= $input->other_html_attributes(); |
26 | - $html .= ' rows= "' . $rows . '" cols="' . $cols . '">'; |
|
26 | + $html .= ' rows= "'.$rows.'" cols="'.$cols.'">'; |
|
27 | 27 | $html .= esc_textarea($raw_value); |
28 | 28 | $html .= '</textarea>'; |
29 | - foreach ( $this->_input->get_validation_strategies() as $validation_strategy ) { |
|
29 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
30 | 30 | if ( |
31 | 31 | $validation_strategy instanceof EE_Simple_HTML_Validation_Strategy |
32 | 32 | || $validation_strategy instanceof EE_Full_HTML_Validation_Strategy |
33 | 33 | ) { |
34 | 34 | $html .= sprintf( |
35 | - __( '%1$s(allowed tags: %2$s)%3$s', 'event_espresso' ), |
|
35 | + __('%1$s(allowed tags: %2$s)%3$s', 'event_espresso'), |
|
36 | 36 | '<p class="ee-question-desc">', |
37 | 37 | $validation_strategy->get_list_of_allowed_tags(), |
38 | 38 | '</p>' |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | |
63 | 63 | |
64 | 64 | protected function _init_page_props() { |
65 | - require_once( EE_MODELS . 'EEM_Venue.model.php' ); |
|
65 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
66 | 66 | $this->page_slug = EE_VENUES_PG_SLUG; |
67 | 67 | $this->_admin_base_url = EE_VENUES_ADMIN_URL; |
68 | - $this->_admin_base_path = EE_ADMIN_PAGES . 'venues'; |
|
68 | + $this->_admin_base_path = EE_ADMIN_PAGES.'venues'; |
|
69 | 69 | $this->page_label = __('Event Venues', 'event_espresso'); |
70 | 70 | $this->_cpt_model_names = array( |
71 | 71 | 'create_new' => 'EEM_Venue', |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | 'edit' => __('Update Venue', 'event_espresso'), |
109 | 109 | 'add_category' => __('Save New Category', 'event_espresso'), |
110 | 110 | 'edit_category' => __('Update Category', 'event_espresso'), |
111 | - 'google_map_settings' => __( 'Update Settings', 'event_espresso' ) |
|
111 | + 'google_map_settings' => __('Update Settings', 'event_espresso') |
|
112 | 112 | ) |
113 | 113 | ); |
114 | 114 | } |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | //load field generator helper |
124 | 124 | |
125 | 125 | //is there a vnu_id in the request? |
126 | - $vnu_id = ! empty( $this->_req_data['VNU_ID'] ) && ! is_array( $this->_req_data['VNU_ID'] ) ? $this->_req_data['VNU_ID'] : 0; |
|
127 | - $vnu_id = ! empty( $this->_req_data['post'] ) ? $this->_req_data['post'] : $vnu_id; |
|
126 | + $vnu_id = ! empty($this->_req_data['VNU_ID']) && ! is_array($this->_req_data['VNU_ID']) ? $this->_req_data['VNU_ID'] : 0; |
|
127 | + $vnu_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $vnu_id; |
|
128 | 128 | |
129 | 129 | $this->_page_routes = array( |
130 | 130 | 'default' => array( |
@@ -142,27 +142,27 @@ discard block |
||
142 | 142 | ), |
143 | 143 | 'trash_venue' => array( |
144 | 144 | 'func' => '_trash_or_restore_venue', |
145 | - 'args' => array( 'venue_status' => 'trash' ), |
|
145 | + 'args' => array('venue_status' => 'trash'), |
|
146 | 146 | 'noheader' => TRUE, |
147 | 147 | 'capability' => 'ee_delete_venue', |
148 | 148 | 'obj_id' => $vnu_id |
149 | 149 | ), |
150 | 150 | 'trash_venues' => array( |
151 | 151 | 'func' => '_trash_or_restore_venues', |
152 | - 'args' => array( 'venue_status' => 'trash' ), |
|
152 | + 'args' => array('venue_status' => 'trash'), |
|
153 | 153 | 'noheader' => TRUE, |
154 | 154 | 'capability' => 'ee_delete_venues' |
155 | 155 | ), |
156 | 156 | 'restore_venue' => array( |
157 | 157 | 'func' => '_trash_or_restore_venue', |
158 | - 'args' => array( 'venue_status' => 'draft' ), |
|
158 | + 'args' => array('venue_status' => 'draft'), |
|
159 | 159 | 'noheader' => TRUE, |
160 | 160 | 'capability' => 'ee_delete_venue', |
161 | 161 | 'obj_id' => $vnu_id |
162 | 162 | ), |
163 | 163 | 'restore_venues' => array( |
164 | 164 | 'func' => '_trash_or_restore_venues', |
165 | - 'args' => array( 'venue_status' => 'draft' ), |
|
165 | + 'args' => array('venue_status' => 'draft'), |
|
166 | 166 | 'noheader' => TRUE, |
167 | 167 | 'capability' => 'ee_delete_venues' |
168 | 168 | ), |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | 'filename' => 'venues_overview_views_bulk_actions_search' |
265 | 265 | ) |
266 | 266 | ), |
267 | - 'help_tour' => array( 'Venues_Overview_Help_Tour' ), |
|
267 | + 'help_tour' => array('Venues_Overview_Help_Tour'), |
|
268 | 268 | 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
269 | 269 | 'require_nonce' => FALSE |
270 | 270 | ), |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | 'filename' => 'venues_editor_other' |
301 | 301 | ) |
302 | 302 | ), |
303 | - 'help_tour' => array( 'Venues_Add_Venue_Help_Tour' ), |
|
303 | + 'help_tour' => array('Venues_Add_Venue_Help_Tour'), |
|
304 | 304 | 'metaboxes' => array('_venue_editor_metaboxes'), |
305 | 305 | 'require_nonce' => FALSE |
306 | 306 | ), |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | 'label' => __('Edit Venue', 'event_espresso'), |
310 | 310 | 'order' => 5, |
311 | 311 | 'persistent' => FALSE, |
312 | - 'url' => isset($this->_req_data['post']) ? add_query_arg(array('post' => $this->_req_data['post'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
|
312 | + 'url' => isset($this->_req_data['post']) ? add_query_arg(array('post' => $this->_req_data['post']), $this->_current_page_view_url) : $this->_admin_base_url |
|
313 | 313 | ), |
314 | 314 | 'help_tabs' => array( |
315 | 315 | 'venues_editor_help_tab' => array( |
@@ -343,17 +343,17 @@ discard block |
||
343 | 343 | ), |
344 | 344 | 'google_map_settings' => array( |
345 | 345 | 'nav' => array( |
346 | - 'label' => esc_html__('Google Maps', 'event_espresso' ), |
|
346 | + 'label' => esc_html__('Google Maps', 'event_espresso'), |
|
347 | 347 | 'order' => 40 |
348 | 348 | ), |
349 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
|
349 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
350 | 350 | 'help_tabs' => array( |
351 | 351 | 'general_settings_google_maps_help_tab' => array( |
352 | 352 | 'title' => __('Google Maps', 'event_espresso'), |
353 | 353 | 'filename' => 'general_settings_google_maps' |
354 | 354 | ) |
355 | 355 | ), |
356 | - 'help_tour' => array( 'Google_Maps_Help_Tour' ), |
|
356 | + 'help_tour' => array('Google_Maps_Help_Tour'), |
|
357 | 357 | 'require_nonce' => FALSE |
358 | 358 | ), |
359 | 359 | //venue category stuff |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | 'filename' => 'venues_add_category' |
370 | 370 | ) |
371 | 371 | ), |
372 | - 'help_tour' => array( 'Venues_Add_Category_Help_Tour' ), |
|
372 | + 'help_tour' => array('Venues_Add_Category_Help_Tour'), |
|
373 | 373 | 'require_nonce' => FALSE |
374 | 374 | ), |
375 | 375 | 'edit_category' => array( |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | 'label' => __('Edit Category', 'event_espresso'), |
378 | 378 | 'order' => 15, |
379 | 379 | 'persistent' => FALSE, |
380 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
|
380 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), $this->_current_page_view_url) : $this->_admin_base_url |
|
381 | 381 | ), |
382 | 382 | 'metaboxes' => array('_publish_post_box'), |
383 | 383 | 'help_tabs' => array( |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | 'filename' => 'venues_categories_other' |
414 | 414 | ) |
415 | 415 | ), |
416 | - 'help_tour' => array( 'Venues_Categories_Help_Tour' ), |
|
416 | + 'help_tour' => array('Venues_Categories_Help_Tour'), |
|
417 | 417 | 'metaboxes' => $this->_default_espresso_metaboxes, |
418 | 418 | 'require_nonce' => FALSE |
419 | 419 | ) |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | |
471 | 471 | |
472 | 472 | public function load_scripts_styles() { |
473 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
473 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
474 | 474 | wp_enqueue_style('ee-cat-admin'); |
475 | 475 | } |
476 | 476 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | public function load_scripts_styles_edit() { |
494 | 494 | //styles |
495 | 495 | wp_enqueue_style('espresso-ui-theme'); |
496 | - wp_register_style( 'espresso_venues', EE_VENUES_ASSETS_URL . 'ee-venues-admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
496 | + wp_register_style('espresso_venues', EE_VENUES_ASSETS_URL.'ee-venues-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
497 | 497 | wp_enqueue_style('espresso_venues'); |
498 | 498 | } |
499 | 499 | |
@@ -512,13 +512,13 @@ discard block |
||
512 | 512 | ) |
513 | 513 | ); |
514 | 514 | |
515 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_venues', 'espresso_venues_trash_venues' ) ) { |
|
515 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) { |
|
516 | 516 | $this->_views['all']['bulk_action'] = array( |
517 | 517 | 'trash_venues' => __('Move to Trash', 'event_espresso') |
518 | 518 | ); |
519 | 519 | $this->_views['trash'] = array( |
520 | 520 | 'slug' => 'trash', |
521 | - 'label' => __( 'Trash', 'event_espresso' ), |
|
521 | + 'label' => __('Trash', 'event_espresso'), |
|
522 | 522 | 'count' => 0, |
523 | 523 | 'bulk_action' => array( |
524 | 524 | 'restore_venues' => __('Restore from Trash', 'event_espresso'), |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | |
552 | 552 | |
553 | 553 | protected function _overview_list_table() { |
554 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
555 | - $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link( get_post_type_archive_link('espresso_venues'), __("View Venue Archive Page", "event_espresso"), 'button' ); |
|
556 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2'); |
|
554 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
555 | + $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(get_post_type_archive_link('espresso_venues'), __("View Venue Archive Page", "event_espresso"), 'button'); |
|
556 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2'); |
|
557 | 557 | $this->_search_btn_label = __('Venues', 'event_espresso'); |
558 | 558 | $this->display_admin_list_table_page_with_sidebar(); |
559 | 559 | } |
@@ -566,8 +566,8 @@ discard block |
||
566 | 566 | 'vnu_url' => $this->_cpt_model_obj->get_f('VNU_url'), |
567 | 567 | 'vnu_phone' => $this->_cpt_model_obj->get_f('VNU_phone') |
568 | 568 | ); |
569 | - $template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php'; |
|
570 | - EEH_Template::display_template( $template, $extra_rows ); |
|
569 | + $template = EE_VENUES_TEMPLATE_PATH.'venue_publish_box_extras.template.php'; |
|
570 | + EEH_Template::display_template($template, $extra_rows); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | |
@@ -583,31 +583,31 @@ discard block |
||
583 | 583 | $default_map_settings->use_google_maps = TRUE; |
584 | 584 | $default_map_settings->google_map_api_key = ''; |
585 | 585 | // for event details pages (reg page) |
586 | - $default_map_settings->event_details_map_width = 585; // ee_map_width_single |
|
587 | - $default_map_settings->event_details_map_height = 362; // ee_map_height_single |
|
588 | - $default_map_settings->event_details_map_zoom = 14; // ee_map_zoom_single |
|
589 | - $default_map_settings->event_details_display_nav = TRUE; // ee_map_nav_display_single |
|
590 | - $default_map_settings->event_details_nav_size = FALSE; // ee_map_nav_size_single |
|
591 | - $default_map_settings->event_details_control_type = 'default'; // ee_map_type_control_single |
|
592 | - $default_map_settings->event_details_map_align = 'center'; // ee_map_align_single |
|
586 | + $default_map_settings->event_details_map_width = 585; // ee_map_width_single |
|
587 | + $default_map_settings->event_details_map_height = 362; // ee_map_height_single |
|
588 | + $default_map_settings->event_details_map_zoom = 14; // ee_map_zoom_single |
|
589 | + $default_map_settings->event_details_display_nav = TRUE; // ee_map_nav_display_single |
|
590 | + $default_map_settings->event_details_nav_size = FALSE; // ee_map_nav_size_single |
|
591 | + $default_map_settings->event_details_control_type = 'default'; // ee_map_type_control_single |
|
592 | + $default_map_settings->event_details_map_align = 'center'; // ee_map_align_single |
|
593 | 593 | // for event list pages |
594 | - $default_map_settings->event_list_map_width = 300; // ee_map_width |
|
595 | - $default_map_settings->event_list_map_height = 185; // ee_map_height |
|
596 | - $default_map_settings->event_list_map_zoom = 12; // ee_map_zoom |
|
597 | - $default_map_settings->event_list_display_nav = FALSE; // ee_map_nav_display |
|
598 | - $default_map_settings->event_list_nav_size = TRUE; // ee_map_nav_size |
|
599 | - $default_map_settings->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
600 | - $default_map_settings->event_list_map_align = 'center'; // ee_map_align |
|
594 | + $default_map_settings->event_list_map_width = 300; // ee_map_width |
|
595 | + $default_map_settings->event_list_map_height = 185; // ee_map_height |
|
596 | + $default_map_settings->event_list_map_zoom = 12; // ee_map_zoom |
|
597 | + $default_map_settings->event_list_display_nav = FALSE; // ee_map_nav_display |
|
598 | + $default_map_settings->event_list_nav_size = TRUE; // ee_map_nav_size |
|
599 | + $default_map_settings->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
600 | + $default_map_settings->event_list_map_align = 'center'; // ee_map_align |
|
601 | 601 | |
602 | 602 | $this->_template_args['map_settings'] = |
603 | - isset( EE_Registry::instance()->CFG->map_settings ) && ! empty( EE_Registry::instance()->CFG->map_settings ) |
|
604 | - ? (object)array_merge( (array)$default_map_settings, (array)EE_Registry::instance()->CFG->map_settings ) |
|
603 | + isset(EE_Registry::instance()->CFG->map_settings) && ! empty(EE_Registry::instance()->CFG->map_settings) |
|
604 | + ? (object) array_merge((array) $default_map_settings, (array) EE_Registry::instance()->CFG->map_settings) |
|
605 | 605 | : $default_map_settings; |
606 | 606 | |
607 | - $this->_set_add_edit_form_tags( 'update_google_map_settings' ); |
|
608 | - $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
607 | + $this->_set_add_edit_form_tags('update_google_map_settings'); |
|
608 | + $this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE); |
|
609 | 609 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
610 | - EE_VENUES_TEMPLATE_PATH . 'google_map.template.php', |
|
610 | + EE_VENUES_TEMPLATE_PATH.'google_map.template.php', |
|
611 | 611 | $this->_template_args, |
612 | 612 | true |
613 | 613 | ); |
@@ -617,83 +617,83 @@ discard block |
||
617 | 617 | protected function _update_google_map_settings() { |
618 | 618 | |
619 | 619 | EE_Registry::instance()->CFG->map_settings->use_google_maps = |
620 | - isset( $this->_req_data['use_google_maps'] ) |
|
621 | - ? absint( $this->_req_data['use_google_maps'] ) |
|
620 | + isset($this->_req_data['use_google_maps']) |
|
621 | + ? absint($this->_req_data['use_google_maps']) |
|
622 | 622 | : EE_Registry::instance()->CFG->map_settings->use_google_maps; |
623 | 623 | |
624 | 624 | EE_Registry::instance()->CFG->map_settings->google_map_api_key = |
625 | - isset( $this->_req_data['google_map_api_key'] ) |
|
626 | - ? sanitize_text_field( $this->_req_data['google_map_api_key'] ) |
|
625 | + isset($this->_req_data['google_map_api_key']) |
|
626 | + ? sanitize_text_field($this->_req_data['google_map_api_key']) |
|
627 | 627 | : EE_Registry::instance()->CFG->map_settings->google_map_api_key; |
628 | 628 | |
629 | 629 | EE_Registry::instance()->CFG->map_settings->event_details_map_width = |
630 | - isset( $this->_req_data['event_details_map_width'] ) |
|
631 | - ? absint( $this->_req_data['event_details_map_width'] ) |
|
630 | + isset($this->_req_data['event_details_map_width']) |
|
631 | + ? absint($this->_req_data['event_details_map_width']) |
|
632 | 632 | : EE_Registry::instance()->CFG->map_settings->event_details_map_width; |
633 | 633 | |
634 | 634 | EE_Registry::instance()->CFG->map_settings->event_details_map_height = |
635 | - isset( $this->_req_data['event_details_map_height'] ) |
|
636 | - ? absint( $this->_req_data['event_details_map_height'] ) |
|
635 | + isset($this->_req_data['event_details_map_height']) |
|
636 | + ? absint($this->_req_data['event_details_map_height']) |
|
637 | 637 | : EE_Registry::instance()->CFG->map_settings->event_details_map_height; |
638 | 638 | |
639 | 639 | EE_Registry::instance()->CFG->map_settings->event_details_map_zoom = |
640 | - isset( $this->_req_data['event_details_map_zoom'] ) |
|
641 | - ? absint( $this->_req_data['event_details_map_zoom'] ) |
|
640 | + isset($this->_req_data['event_details_map_zoom']) |
|
641 | + ? absint($this->_req_data['event_details_map_zoom']) |
|
642 | 642 | : EE_Registry::instance()->CFG->map_settings->event_details_map_zoom; |
643 | 643 | |
644 | 644 | EE_Registry::instance()->CFG->map_settings->event_details_display_nav = |
645 | - isset( $this->_req_data['event_details_display_nav'] ) |
|
646 | - ? absint( $this->_req_data['event_details_display_nav'] ) |
|
645 | + isset($this->_req_data['event_details_display_nav']) |
|
646 | + ? absint($this->_req_data['event_details_display_nav']) |
|
647 | 647 | : EE_Registry::instance()->CFG->map_settings->event_details_display_nav; |
648 | 648 | |
649 | 649 | EE_Registry::instance()->CFG->map_settings->event_details_nav_size = |
650 | - isset( $this->_req_data['event_details_nav_size'] ) |
|
651 | - ? absint( $this->_req_data['event_details_nav_size'] ) |
|
650 | + isset($this->_req_data['event_details_nav_size']) |
|
651 | + ? absint($this->_req_data['event_details_nav_size']) |
|
652 | 652 | : EE_Registry::instance()->CFG->map_settings->event_details_nav_size; |
653 | 653 | |
654 | 654 | EE_Registry::instance()->CFG->map_settings->event_details_control_type = |
655 | - isset( $this->_req_data['event_details_control_type'] ) |
|
656 | - ? sanitize_text_field( $this->_req_data['event_details_control_type'] ) |
|
655 | + isset($this->_req_data['event_details_control_type']) |
|
656 | + ? sanitize_text_field($this->_req_data['event_details_control_type']) |
|
657 | 657 | : EE_Registry::instance()->CFG->map_settings->event_details_control_type; |
658 | 658 | |
659 | 659 | EE_Registry::instance()->CFG->map_settings->event_details_map_align = |
660 | - isset( $this->_req_data['event_details_map_align'] ) |
|
661 | - ? sanitize_text_field( $this->_req_data['event_details_map_align'] ) |
|
660 | + isset($this->_req_data['event_details_map_align']) |
|
661 | + ? sanitize_text_field($this->_req_data['event_details_map_align']) |
|
662 | 662 | : EE_Registry::instance()->CFG->map_settings->event_details_map_align; |
663 | 663 | |
664 | 664 | EE_Registry::instance()->CFG->map_settings->event_list_map_width = |
665 | - isset( $this->_req_data['event_list_map_width'] ) |
|
666 | - ? absint( $this->_req_data['event_list_map_width'] ) |
|
665 | + isset($this->_req_data['event_list_map_width']) |
|
666 | + ? absint($this->_req_data['event_list_map_width']) |
|
667 | 667 | : EE_Registry::instance()->CFG->map_settings->event_list_map_width; |
668 | 668 | |
669 | 669 | EE_Registry::instance()->CFG->map_settings->event_list_map_height = |
670 | - isset( $this->_req_data['event_list_map_height'] ) |
|
671 | - ? absint( $this->_req_data['event_list_map_height'] ) |
|
670 | + isset($this->_req_data['event_list_map_height']) |
|
671 | + ? absint($this->_req_data['event_list_map_height']) |
|
672 | 672 | : EE_Registry::instance()->CFG->map_settings->event_list_map_height; |
673 | 673 | |
674 | 674 | EE_Registry::instance()->CFG->map_settings->event_list_map_zoom = |
675 | - isset( $this->_req_data['event_list_map_zoom'] ) |
|
676 | - ? absint( $this->_req_data['event_list_map_zoom'] ) |
|
675 | + isset($this->_req_data['event_list_map_zoom']) |
|
676 | + ? absint($this->_req_data['event_list_map_zoom']) |
|
677 | 677 | : EE_Registry::instance()->CFG->map_settings->event_list_map_zoom; |
678 | 678 | |
679 | 679 | EE_Registry::instance()->CFG->map_settings->event_list_display_nav = |
680 | - isset( $this->_req_data['event_list_display_nav'] ) |
|
681 | - ? absint( $this->_req_data['event_list_display_nav'] ) |
|
680 | + isset($this->_req_data['event_list_display_nav']) |
|
681 | + ? absint($this->_req_data['event_list_display_nav']) |
|
682 | 682 | : EE_Registry::instance()->CFG->map_settings->event_list_display_nav; |
683 | 683 | |
684 | 684 | EE_Registry::instance()->CFG->map_settings->event_list_nav_size = |
685 | - isset( $this->_req_data['event_list_nav_size'] ) |
|
686 | - ? absint( $this->_req_data['event_list_nav_size'] ) |
|
685 | + isset($this->_req_data['event_list_nav_size']) |
|
686 | + ? absint($this->_req_data['event_list_nav_size']) |
|
687 | 687 | : EE_Registry::instance()->CFG->map_settings->event_list_nav_size; |
688 | 688 | |
689 | 689 | EE_Registry::instance()->CFG->map_settings->event_list_control_type = |
690 | - isset( $this->_req_data['event_list_control_type'] ) |
|
691 | - ? sanitize_text_field( $this->_req_data['event_list_control_type'] ) |
|
690 | + isset($this->_req_data['event_list_control_type']) |
|
691 | + ? sanitize_text_field($this->_req_data['event_list_control_type']) |
|
692 | 692 | : EE_Registry::instance()->CFG->map_settings->event_list_control_type; |
693 | 693 | |
694 | 694 | EE_Registry::instance()->CFG->map_settings->event_list_map_align = |
695 | - isset( $this->_req_data['event_list_map_align'] ) |
|
696 | - ? sanitize_text_field( $this->_req_data['event_list_map_align'] ) |
|
695 | + isset($this->_req_data['event_list_map_align']) |
|
696 | + ? sanitize_text_field($this->_req_data['event_list_map_align']) |
|
697 | 697 | : EE_Registry::instance()->CFG->map_settings->event_list_map_align; |
698 | 698 | |
699 | 699 | EE_Registry::instance()->CFG->map_settings = apply_filters( |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | EE_Registry::instance()->CFG->map_settings, |
708 | 708 | __FILE__, __FUNCTION__, __LINE__ |
709 | 709 | ); |
710 | - $this->_redirect_after_action( $success, $what, 'updated', array( 'action' => 'google_map_settings' ) ); |
|
710 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'google_map_settings')); |
|
711 | 711 | |
712 | 712 | } |
713 | 713 | |
@@ -716,9 +716,9 @@ discard block |
||
716 | 716 | protected function _venue_editor_metaboxes() { |
717 | 717 | $this->verify_cpt_object(); |
718 | 718 | |
719 | - add_meta_box( 'espresso_venue_address_options', __('Physical Location', 'event_espresso'), array( $this, 'venue_address_metabox'), $this->page_slug, 'side', 'default' ); |
|
720 | - add_meta_box( 'espresso_venue_gmap_options', __('Google Map', 'event_espresso'), array( $this, 'venue_gmap_metabox'), $this->page_slug, 'side', 'default' ); |
|
721 | - add_meta_box( 'espresso_venue_virtual_loc_options', __('Virtual Location', 'event_espresso'), array( $this, 'venue_virtual_loc_metabox'), $this->page_slug, 'side', 'default' ); |
|
719 | + add_meta_box('espresso_venue_address_options', __('Physical Location', 'event_espresso'), array($this, 'venue_address_metabox'), $this->page_slug, 'side', 'default'); |
|
720 | + add_meta_box('espresso_venue_gmap_options', __('Google Map', 'event_espresso'), array($this, 'venue_gmap_metabox'), $this->page_slug, 'side', 'default'); |
|
721 | + add_meta_box('espresso_venue_virtual_loc_options', __('Virtual Location', 'event_espresso'), array($this, 'venue_virtual_loc_metabox'), $this->page_slug, 'side', 'default'); |
|
722 | 722 | |
723 | 723 | } |
724 | 724 | |
@@ -726,23 +726,23 @@ discard block |
||
726 | 726 | |
727 | 727 | public function venue_gmap_metabox() { |
728 | 728 | $template_args = array( |
729 | - 'vnu_enable_for_gmap' => EEH_Form_Fields::select_input('vnu_enable_for_gmap', $this->get_yes_no_values(), $this->_cpt_model_obj->enable_for_gmap() ), |
|
729 | + 'vnu_enable_for_gmap' => EEH_Form_Fields::select_input('vnu_enable_for_gmap', $this->get_yes_no_values(), $this->_cpt_model_obj->enable_for_gmap()), |
|
730 | 730 | 'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(), |
731 | 731 | ); |
732 | - $template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php'; |
|
733 | - EEH_Template::display_template( $template, $template_args ); |
|
732 | + $template = EE_VENUES_TEMPLATE_PATH.'venue_gmap_metabox_content.template.php'; |
|
733 | + EEH_Template::display_template($template, $template_args); |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | |
737 | 737 | |
738 | 738 | public function venue_address_metabox() { |
739 | 739 | |
740 | - $template_args['_venue'] =$this->_cpt_model_obj; |
|
740 | + $template_args['_venue'] = $this->_cpt_model_obj; |
|
741 | 741 | |
742 | 742 | $template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input( |
743 | 743 | $QFI = new EE_Question_Form_Input( |
744 | - EE_Question::new_instance( array( 'QST_display_text' => esc_html__( 'State', 'event_espresso' ), 'QST_system' => 'state' )), |
|
745 | - EE_Answer::new_instance( array( 'ANS_value'=> $this->_cpt_model_obj->state_ID() )), |
|
744 | + EE_Question::new_instance(array('QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state')), |
|
745 | + EE_Answer::new_instance(array('ANS_value'=> $this->_cpt_model_obj->state_ID())), |
|
746 | 746 | array( |
747 | 747 | 'input_name' => 'sta_id', |
748 | 748 | 'input_id' => 'sta_id', |
@@ -754,8 +754,8 @@ discard block |
||
754 | 754 | ); |
755 | 755 | $template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input( |
756 | 756 | $QFI = new EE_Question_Form_Input( |
757 | - EE_Question::new_instance( array( 'QST_display_text' => esc_html__( 'Country', 'event_espresso' ), 'QST_system' => 'country' )), |
|
758 | - EE_Answer::new_instance( array( 'ANS_value'=> $this->_cpt_model_obj->country_ID() )), |
|
757 | + EE_Question::new_instance(array('QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country')), |
|
758 | + EE_Answer::new_instance(array('ANS_value'=> $this->_cpt_model_obj->country_ID())), |
|
759 | 759 | array( |
760 | 760 | 'input_name' => 'cnt_iso', |
761 | 761 | 'input_id' => 'cnt_iso', |
@@ -766,8 +766,8 @@ discard block |
||
766 | 766 | ) |
767 | 767 | ); |
768 | 768 | |
769 | - $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php'; |
|
770 | - EEH_Template::display_template( $template, $template_args ); |
|
769 | + $template = EE_VENUES_TEMPLATE_PATH.'venue_address_metabox_content.template.php'; |
|
770 | + EEH_Template::display_template($template, $template_args); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | |
@@ -779,8 +779,8 @@ discard block |
||
779 | 779 | $template_args = array( |
780 | 780 | '_venue' => $this->_cpt_model_obj |
781 | 781 | ); |
782 | - $template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php'; |
|
783 | - EEH_Template::display_template( $template, $template_args ); |
|
782 | + $template = EE_VENUES_TEMPLATE_PATH.'venue_virtual_location_metabox_content.template.php'; |
|
783 | + EEH_Template::display_template($template, $template_args); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | |
@@ -803,52 +803,52 @@ discard block |
||
803 | 803 | * @param object $post Post object (with "blessed" WP properties) |
804 | 804 | * @return void |
805 | 805 | */ |
806 | - protected function _insert_update_cpt_item( $post_id, $post ) { |
|
806 | + protected function _insert_update_cpt_item($post_id, $post) { |
|
807 | 807 | |
808 | - if ( $post instanceof WP_Post && $post->post_type !== 'espresso_venues' ) { |
|
809 | - return;// get out we're not processing the saving of venues. |
|
808 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') { |
|
809 | + return; // get out we're not processing the saving of venues. |
|
810 | 810 | } |
811 | 811 | |
812 | - $wheres = array( $this->_venue_model->primary_key_name() => $post_id ); |
|
812 | + $wheres = array($this->_venue_model->primary_key_name() => $post_id); |
|
813 | 813 | |
814 | 814 | $venue_values = array( |
815 | - 'VNU_address' => !empty( $this->_req_data['vnu_address'] ) ? $this->_req_data['vnu_address'] : NULL, |
|
816 | - 'VNU_address2' => !empty( $this->_req_data['vnu_address2'] ) ? $this->_req_data['vnu_address2'] : NULL, |
|
817 | - 'VNU_city' => !empty( $this->_req_data['vnu_city'] ) ? $this->_req_data['vnu_city'] : NULL, |
|
818 | - 'STA_ID' => !empty( $this->_req_data['sta_id'] ) ? $this->_req_data['sta_id'] : NULL, |
|
819 | - 'CNT_ISO' => !empty( $this->_req_data['cnt_iso'] ) ? $this->_req_data['cnt_iso'] : NULL, |
|
820 | - 'VNU_zip' => !empty( $this->_req_data['vnu_zip'] ) ? $this->_req_data['vnu_zip'] : NULL, |
|
821 | - 'VNU_phone' => !empty( $this->_req_data['vnu_phone'] ) ? $this->_req_data['vnu_phone'] : NULL, |
|
822 | - 'VNU_capacity' => !empty( $this->_req_data['vnu_capacity'] ) ? str_replace( ',', '', $this->_req_data['vnu_capacity'] ) : EE_INF, |
|
823 | - 'VNU_url' => !empty( $this->_req_data['vnu_url'] ) ? $this->_req_data['vnu_url'] : NULL, |
|
824 | - 'VNU_virtual_phone' => !empty( $this->_req_data['vnu_virtual_phone'] ) ? $this->_req_data['vnu_virtual_phone'] : NULL, |
|
825 | - 'VNU_virtual_url' => !empty( $this->_req_data['vnu_virtual_url'] ) ? $this->_req_data['vnu_virtual_url'] : NULL, |
|
826 | - 'VNU_enable_for_gmap' => !empty( $this->_req_data['vnu_enable_for_gmap'] ) ? TRUE : FALSE, |
|
827 | - 'VNU_google_map_link' => !empty( $this->_req_data['vnu_google_map_link'] ) ? $this->_req_data['vnu_google_map_link'] : NULL |
|
815 | + 'VNU_address' => ! empty($this->_req_data['vnu_address']) ? $this->_req_data['vnu_address'] : NULL, |
|
816 | + 'VNU_address2' => ! empty($this->_req_data['vnu_address2']) ? $this->_req_data['vnu_address2'] : NULL, |
|
817 | + 'VNU_city' => ! empty($this->_req_data['vnu_city']) ? $this->_req_data['vnu_city'] : NULL, |
|
818 | + 'STA_ID' => ! empty($this->_req_data['sta_id']) ? $this->_req_data['sta_id'] : NULL, |
|
819 | + 'CNT_ISO' => ! empty($this->_req_data['cnt_iso']) ? $this->_req_data['cnt_iso'] : NULL, |
|
820 | + 'VNU_zip' => ! empty($this->_req_data['vnu_zip']) ? $this->_req_data['vnu_zip'] : NULL, |
|
821 | + 'VNU_phone' => ! empty($this->_req_data['vnu_phone']) ? $this->_req_data['vnu_phone'] : NULL, |
|
822 | + 'VNU_capacity' => ! empty($this->_req_data['vnu_capacity']) ? str_replace(',', '', $this->_req_data['vnu_capacity']) : EE_INF, |
|
823 | + 'VNU_url' => ! empty($this->_req_data['vnu_url']) ? $this->_req_data['vnu_url'] : NULL, |
|
824 | + 'VNU_virtual_phone' => ! empty($this->_req_data['vnu_virtual_phone']) ? $this->_req_data['vnu_virtual_phone'] : NULL, |
|
825 | + 'VNU_virtual_url' => ! empty($this->_req_data['vnu_virtual_url']) ? $this->_req_data['vnu_virtual_url'] : NULL, |
|
826 | + 'VNU_enable_for_gmap' => ! empty($this->_req_data['vnu_enable_for_gmap']) ? TRUE : FALSE, |
|
827 | + 'VNU_google_map_link' => ! empty($this->_req_data['vnu_google_map_link']) ? $this->_req_data['vnu_google_map_link'] : NULL |
|
828 | 828 | ); |
829 | 829 | |
830 | 830 | //update venue |
831 | - $success = $this->_venue_model->update( $venue_values, array( $wheres ) ); |
|
831 | + $success = $this->_venue_model->update($venue_values, array($wheres)); |
|
832 | 832 | |
833 | 833 | //get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
834 | - $get_one_where = array( $this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status ); |
|
835 | - $venue = $this->_venue_model->get_one( array( $get_one_where ) ); |
|
834 | + $get_one_where = array($this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
835 | + $venue = $this->_venue_model->get_one(array($get_one_where)); |
|
836 | 836 | |
837 | 837 | //notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use. So this is just here for addons to more easily hook into venue saves. |
838 | - $venue_update_callbacks = apply_filters( 'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks', array() ); |
|
838 | + $venue_update_callbacks = apply_filters('FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks', array()); |
|
839 | 839 | |
840 | 840 | $att_success = TRUE; |
841 | 841 | |
842 | - foreach ( $venue_update_callbacks as $v_callback ) { |
|
843 | - $_succ = call_user_func_array( $v_callback, array( $venue, $this->_req_data ) ); |
|
844 | - $att_success = !$att_success ? $att_success : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
842 | + foreach ($venue_update_callbacks as $v_callback) { |
|
843 | + $_succ = call_user_func_array($v_callback, array($venue, $this->_req_data)); |
|
844 | + $att_success = ! $att_success ? $att_success : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | //any errors? |
848 | - if ( $success && !$att_success ) { |
|
849 | - EE_Error::add_error( __('Venue Details saved successfully but something went wrong with saving attachments.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
850 | - } else if ( $success === FALSE ) { |
|
851 | - EE_Error::add_error( __('Venue Details did not save successfully.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
848 | + if ($success && ! $att_success) { |
|
849 | + EE_Error::add_error(__('Venue Details saved successfully but something went wrong with saving attachments.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
850 | + } else if ($success === FALSE) { |
|
851 | + EE_Error::add_error(__('Venue Details did not save successfully.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
852 | 852 | } |
853 | 853 | } |
854 | 854 | |
@@ -856,9 +856,9 @@ discard block |
||
856 | 856 | |
857 | 857 | |
858 | 858 | |
859 | - public function trash_cpt_item( $post_id ) { |
|
859 | + public function trash_cpt_item($post_id) { |
|
860 | 860 | $this->_req_data['VNU_ID'] = $post_id; |
861 | - $this->_trash_or_restore_venue( 'trash', FALSE ); |
|
861 | + $this->_trash_or_restore_venue('trash', FALSE); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | |
@@ -866,18 +866,18 @@ discard block |
||
866 | 866 | |
867 | 867 | |
868 | 868 | |
869 | - public function restore_cpt_item( $post_id ) { |
|
869 | + public function restore_cpt_item($post_id) { |
|
870 | 870 | $this->_req_data['VNU_ID'] = $post_id; |
871 | - $this->_trash_or_restore_venue( 'draft', FALSE ); |
|
871 | + $this->_trash_or_restore_venue('draft', FALSE); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | |
875 | 875 | |
876 | 876 | |
877 | 877 | |
878 | - public function delete_cpt_item( $post_id ) { |
|
878 | + public function delete_cpt_item($post_id) { |
|
879 | 879 | $this->_req_data['VNU_ID'] = $post_id; |
880 | - $this->_delete_venue( FALSE ); |
|
880 | + $this->_delete_venue(FALSE); |
|
881 | 881 | } |
882 | 882 | |
883 | 883 | |
@@ -892,15 +892,15 @@ discard block |
||
892 | 892 | |
893 | 893 | |
894 | 894 | |
895 | - protected function _trash_or_restore_venue( $venue_status = 'trash', $redirect_after = TRUE ) { |
|
896 | - $VNU_ID = isset( $this->_req_data['VNU_ID'] ) ? absint( $this->_req_data['VNU_ID'] ) : FALSE; |
|
895 | + protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = TRUE) { |
|
896 | + $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : FALSE; |
|
897 | 897 | |
898 | 898 | //loop thru venues |
899 | - if ( $VNU_ID ) { |
|
899 | + if ($VNU_ID) { |
|
900 | 900 | //clean status |
901 | - $venue_status = sanitize_key( $venue_status ); |
|
901 | + $venue_status = sanitize_key($venue_status); |
|
902 | 902 | // grab status |
903 | - if (!empty($venue_status)) { |
|
903 | + if ( ! empty($venue_status)) { |
|
904 | 904 | $success = $this->_change_venue_status($VNU_ID, $venue_status); |
905 | 905 | } else { |
906 | 906 | $success = FALSE; |
@@ -914,7 +914,7 @@ discard block |
||
914 | 914 | } |
915 | 915 | $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
916 | 916 | |
917 | - if ( $redirect_after ) |
|
917 | + if ($redirect_after) |
|
918 | 918 | $this->_redirect_after_action($success, 'Venue', $action, array('action' => 'default')); |
919 | 919 | |
920 | 920 | } |
@@ -923,11 +923,11 @@ discard block |
||
923 | 923 | |
924 | 924 | |
925 | 925 | |
926 | - protected function _trash_or_restore_venues( $venue_status = 'trash' ) { |
|
926 | + protected function _trash_or_restore_venues($venue_status = 'trash') { |
|
927 | 927 | // clean status |
928 | 928 | $venue_status = sanitize_key($venue_status); |
929 | 929 | // grab status |
930 | - if (!empty($venue_status)) { |
|
930 | + if ( ! empty($venue_status)) { |
|
931 | 931 | $success = TRUE; |
932 | 932 | //determine the event id and set to array. |
933 | 933 | $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array(); |
@@ -967,20 +967,20 @@ discard block |
||
967 | 967 | * @param string $venue_status |
968 | 968 | * @return void |
969 | 969 | */ |
970 | - private function _change_venue_status( $VNU_ID = 0, $venue_status = '' ) { |
|
970 | + private function _change_venue_status($VNU_ID = 0, $venue_status = '') { |
|
971 | 971 | // grab venue id |
972 | - if (! $VNU_ID) { |
|
972 | + if ( ! $VNU_ID) { |
|
973 | 973 | $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso'); |
974 | 974 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
975 | 975 | return FALSE; |
976 | 976 | } |
977 | 977 | |
978 | - $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
978 | + $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
979 | 979 | |
980 | 980 | // clean status |
981 | 981 | $venue_status = sanitize_key($venue_status); |
982 | 982 | // grab status |
983 | - if ( ! $venue_status ) { |
|
983 | + if ( ! $venue_status) { |
|
984 | 984 | $msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso'); |
985 | 985 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
986 | 986 | return FALSE; |
@@ -1001,7 +1001,7 @@ discard block |
||
1001 | 1001 | $hook = FALSE; |
1002 | 1002 | } |
1003 | 1003 | //use class to change status |
1004 | - $this->_cpt_model_obj->set_status( $venue_status ); |
|
1004 | + $this->_cpt_model_obj->set_status($venue_status); |
|
1005 | 1005 | $success = $this->_cpt_model_obj->save(); |
1006 | 1006 | |
1007 | 1007 | if ($success === FALSE) { |
@@ -1020,21 +1020,21 @@ discard block |
||
1020 | 1020 | * @param bool $redirect_after |
1021 | 1021 | * @return void |
1022 | 1022 | */ |
1023 | - protected function _delete_venue( $redirect_after = true ) { |
|
1023 | + protected function _delete_venue($redirect_after = true) { |
|
1024 | 1024 | //determine the venue id and set to array. |
1025 | 1025 | $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : NULL; |
1026 | - $VNU_ID = isset( $this->_req_data['post'] ) ? absint( $this->_req_data['post'] ) : $VNU_ID; |
|
1026 | + $VNU_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $VNU_ID; |
|
1027 | 1027 | |
1028 | 1028 | |
1029 | 1029 | // loop thru venues |
1030 | 1030 | if ($VNU_ID) { |
1031 | - $success = $this->_delete_or_trash_venue( $VNU_ID ); |
|
1031 | + $success = $this->_delete_or_trash_venue($VNU_ID); |
|
1032 | 1032 | } else { |
1033 | 1033 | $success = FALSE; |
1034 | 1034 | $msg = __('An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.', 'event_espresso'); |
1035 | 1035 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1036 | 1036 | } |
1037 | - if ( $redirect_after ) |
|
1037 | + if ($redirect_after) |
|
1038 | 1038 | $this->_redirect_after_action($success, 'Venue', 'deleted', array('action' => 'default')); |
1039 | 1039 | } |
1040 | 1040 | |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | //todo: put in parent |
1067 | 1067 | private function _delete_or_trash_venue($VNU_ID = FALSE) { |
1068 | 1068 | // grab event id |
1069 | - if (!$VNU_ID = absint($VNU_ID)) { |
|
1069 | + if ( ! $VNU_ID = absint($VNU_ID)) { |
|
1070 | 1070 | $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso'); |
1071 | 1071 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1072 | 1072 | return FALSE; |
@@ -1086,7 +1086,7 @@ discard block |
||
1086 | 1086 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1087 | 1087 | return FALSE; |
1088 | 1088 | } |
1089 | - do_action( 'AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted' ); |
|
1089 | + do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted'); |
|
1090 | 1090 | return TRUE; |
1091 | 1091 | } |
1092 | 1092 | |
@@ -1097,11 +1097,11 @@ discard block |
||
1097 | 1097 | /* QUERIES */ |
1098 | 1098 | |
1099 | 1099 | |
1100 | - public function get_venues( $per_page = 10, $count = FALSE ) { |
|
1100 | + public function get_venues($per_page = 10, $count = FALSE) { |
|
1101 | 1101 | |
1102 | - $_orderby = !empty( $this->_req_data['orderby'] ) ? $this->_req_data['orderby'] : ''; |
|
1102 | + $_orderby = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
1103 | 1103 | |
1104 | - switch ( $_orderby ) { |
|
1104 | + switch ($_orderby) { |
|
1105 | 1105 | case 'id': |
1106 | 1106 | $orderby = 'VNU_ID'; |
1107 | 1107 | break; |
@@ -1119,43 +1119,43 @@ discard block |
||
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | |
1122 | - $sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC'; |
|
1122 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
1123 | 1123 | |
1124 | - $current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1; |
|
1125 | - $per_page = isset( $per_page ) && !empty( $per_page ) ? $per_page : 10; |
|
1126 | - $per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page; |
|
1124 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
1125 | + $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
1126 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
1127 | 1127 | |
1128 | 1128 | |
1129 | - $offset = ($current_page-1)*$per_page; |
|
1129 | + $offset = ($current_page - 1) * $per_page; |
|
1130 | 1130 | $limit = array($offset, $per_page); |
1131 | 1131 | |
1132 | - $category = isset( $this->_req_data['category'] ) && $this->_req_data['category'] > 0 ? $this->_req_data['category'] : NULL; |
|
1132 | + $category = isset($this->_req_data['category']) && $this->_req_data['category'] > 0 ? $this->_req_data['category'] : NULL; |
|
1133 | 1133 | $where = array(); |
1134 | 1134 | |
1135 | 1135 | //only set initial status if it is in the incoming request. Otherwise the "all" view display's all statuses. |
1136 | - if ( isset( $this->_req_data['status'] ) && $this->_req_data['status'] != 'all' ) { |
|
1136 | + if (isset($this->_req_data['status']) && $this->_req_data['status'] != 'all') { |
|
1137 | 1137 | $where['status'] = $this->_req_data['status']; |
1138 | 1138 | } |
1139 | 1139 | |
1140 | - if ( isset( $this->_req_data['venue_status'] ) ) { |
|
1140 | + if (isset($this->_req_data['venue_status'])) { |
|
1141 | 1141 | $where['status'] = $this->_req_data['venue_status']; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | |
1145 | - if ( $category ) { |
|
1145 | + if ($category) { |
|
1146 | 1146 | $where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories'; |
1147 | 1147 | $where['Term_Taxonomy.term_id'] = $category; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | 1150 | |
1151 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_venues', 'get_venues' ) ) { |
|
1152 | - $where['VNU_wp_user'] = get_current_user_id(); |
|
1151 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) { |
|
1152 | + $where['VNU_wp_user'] = get_current_user_id(); |
|
1153 | 1153 | } else { |
1154 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_venues', 'get_venues' ) ) { |
|
1154 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) { |
|
1155 | 1155 | $where['OR'] = array( |
1156 | - 'status*restrict_private' => array( '!=', 'private' ), |
|
1156 | + 'status*restrict_private' => array('!=', 'private'), |
|
1157 | 1157 | 'AND' => array( |
1158 | - 'status*inclusive' => array( '=', 'private' ), |
|
1158 | + 'status*inclusive' => array('=', 'private'), |
|
1159 | 1159 | 'VNU_wp_user' => get_current_user_id() |
1160 | 1160 | ) |
1161 | 1161 | ); |
@@ -1165,30 +1165,30 @@ discard block |
||
1165 | 1165 | |
1166 | 1166 | |
1167 | 1167 | |
1168 | - if ( isset( $this->_req_data['s'] ) ) { |
|
1169 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1168 | + if (isset($this->_req_data['s'])) { |
|
1169 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
1170 | 1170 | $where['OR'] = array( |
1171 | - 'VNU_name' => array('LIKE',$sstr ), |
|
1172 | - 'VNU_desc' => array('LIKE',$sstr ), |
|
1173 | - 'VNU_short_desc' => array( 'LIKE',$sstr ), |
|
1174 | - 'VNU_address' => array( 'LIKE', $sstr ), |
|
1175 | - 'VNU_address2' => array( 'LIKE', $sstr ), |
|
1176 | - 'VNU_city' => array( 'LIKE', $sstr ), |
|
1177 | - 'VNU_zip' => array( 'LIKE', $sstr ), |
|
1178 | - 'VNU_phone' => array( 'LIKE', $sstr ), |
|
1179 | - 'VNU_url' => array( 'LIKE', $sstr ), |
|
1180 | - 'VNU_virtual_phone' => array( 'LIKE', $sstr ), |
|
1181 | - 'VNU_virtual_url' => array( 'LIKE', $sstr ), |
|
1182 | - 'VNU_google_map_link' => array( 'LIKE', $sstr ), |
|
1183 | - 'Event.EVT_name' => array('LIKE', $sstr ), |
|
1184 | - 'Event.EVT_desc' => array('LIKE', $sstr ), |
|
1185 | - 'Event.EVT_phone' => array('LIKE', $sstr ), |
|
1186 | - 'Event.EVT_external_URL' => array('LIKE', $sstr ), |
|
1171 | + 'VNU_name' => array('LIKE', $sstr), |
|
1172 | + 'VNU_desc' => array('LIKE', $sstr), |
|
1173 | + 'VNU_short_desc' => array('LIKE', $sstr), |
|
1174 | + 'VNU_address' => array('LIKE', $sstr), |
|
1175 | + 'VNU_address2' => array('LIKE', $sstr), |
|
1176 | + 'VNU_city' => array('LIKE', $sstr), |
|
1177 | + 'VNU_zip' => array('LIKE', $sstr), |
|
1178 | + 'VNU_phone' => array('LIKE', $sstr), |
|
1179 | + 'VNU_url' => array('LIKE', $sstr), |
|
1180 | + 'VNU_virtual_phone' => array('LIKE', $sstr), |
|
1181 | + 'VNU_virtual_url' => array('LIKE', $sstr), |
|
1182 | + 'VNU_google_map_link' => array('LIKE', $sstr), |
|
1183 | + 'Event.EVT_name' => array('LIKE', $sstr), |
|
1184 | + 'Event.EVT_desc' => array('LIKE', $sstr), |
|
1185 | + 'Event.EVT_phone' => array('LIKE', $sstr), |
|
1186 | + 'Event.EVT_external_URL' => array('LIKE', $sstr), |
|
1187 | 1187 | ); |
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | |
1191 | - $venues = $count ? $this->_venue_model->count( array($where), 'VNU_ID' ) : $this->_venue_model->get_all( array( $where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort ) ); |
|
1191 | + $venues = $count ? $this->_venue_model->count(array($where), 'VNU_ID') : $this->_venue_model->get_all(array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort)); |
|
1192 | 1192 | |
1193 | 1193 | return $venues; |
1194 | 1194 | |
@@ -1206,22 +1206,22 @@ discard block |
||
1206 | 1206 | * @return void |
1207 | 1207 | */ |
1208 | 1208 | private function _set_category_object() { |
1209 | - if ( isset( $this->_category->id ) && !empty( $this->_category->id ) ) |
|
1209 | + if (isset($this->_category->id) && ! empty($this->_category->id)) |
|
1210 | 1210 | return; //already have the category object so get out. |
1211 | 1211 | |
1212 | 1212 | //set default category object |
1213 | 1213 | $this->_set_empty_category_object(); |
1214 | 1214 | |
1215 | 1215 | //only set if we've got an id |
1216 | - if ( !isset($this->_req_data['VEN_CAT_ID'] ) ) { |
|
1216 | + if ( ! isset($this->_req_data['VEN_CAT_ID'])) { |
|
1217 | 1217 | return; |
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 | $category_id = absint($this->_req_data['VEN_CAT_ID']); |
1221 | - $term = get_term( $category_id, 'espresso_venue_categories' ); |
|
1221 | + $term = get_term($category_id, 'espresso_venue_categories'); |
|
1222 | 1222 | |
1223 | 1223 | |
1224 | - if ( !empty( $term ) ) { |
|
1224 | + if ( ! empty($term)) { |
|
1225 | 1225 | $this->_category->category_name = $term->name; |
1226 | 1226 | $this->_category->category_identifier = $term->slug; |
1227 | 1227 | $this->_category->category_desc = $term->description; |
@@ -1235,15 +1235,15 @@ discard block |
||
1235 | 1235 | |
1236 | 1236 | private function _set_empty_category_object() { |
1237 | 1237 | $this->_category = new stdClass(); |
1238 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
1238 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
1239 | 1239 | $this->_category->id = $this->_category->parent = 0; |
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | |
1243 | 1243 | |
1244 | 1244 | protected function _category_list_table() { |
1245 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
1246 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
1245 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1246 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
1247 | 1247 | 'add_category', |
1248 | 1248 | 'add_category', |
1249 | 1249 | array(), |
@@ -1263,13 +1263,13 @@ discard block |
||
1263 | 1263 | $this->_set_add_edit_form_tags($route); |
1264 | 1264 | |
1265 | 1265 | $this->_set_category_object(); |
1266 | - $id = !empty($this->_category->id) ? $this->_category->id : ''; |
|
1266 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
1267 | 1267 | |
1268 | 1268 | $delete_action = 'delete_category'; |
1269 | 1269 | |
1270 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'category_list' ), $this->_admin_base_url ); |
|
1270 | + $redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url); |
|
1271 | 1271 | |
1272 | - $this->_set_publish_post_box_vars( 'VEN_CAT_ID', $id, $delete_action, $redirect ); |
|
1272 | + $this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect); |
|
1273 | 1273 | |
1274 | 1274 | //take care of contents |
1275 | 1275 | $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
@@ -1283,25 +1283,25 @@ discard block |
||
1283 | 1283 | 'type' => 'wp_editor', |
1284 | 1284 | 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
1285 | 1285 | 'class' => 'my_editor_custom', |
1286 | - 'wpeditor_args' => array( 'media_buttons' => FALSE ) |
|
1286 | + 'wpeditor_args' => array('media_buttons' => FALSE) |
|
1287 | 1287 | ); |
1288 | - $_wp_editor = $this->_generate_admin_form_fields( $editor_args, 'array' ); |
|
1288 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
1289 | 1289 | |
1290 | - $all_terms = get_terms( array('espresso_venue_categories' ), array( 'hide_empty' => 0, 'exclude' => array( $this->_category->id ) ) ); |
|
1290 | + $all_terms = get_terms(array('espresso_venue_categories'), array('hide_empty' => 0, 'exclude' => array($this->_category->id))); |
|
1291 | 1291 | |
1292 | 1292 | //setup category select for term parents. |
1293 | 1293 | $category_select_values[] = array( |
1294 | 1294 | 'text' => __('No Parent', 'event_espresso'), |
1295 | 1295 | 'id' => 0 |
1296 | 1296 | ); |
1297 | - foreach ( $all_terms as $term ) { |
|
1297 | + foreach ($all_terms as $term) { |
|
1298 | 1298 | $category_select_values[] = array( |
1299 | 1299 | 'text' => $term->name, |
1300 | 1300 | 'id' => $term->term_id |
1301 | 1301 | ); |
1302 | 1302 | } |
1303 | 1303 | |
1304 | - $category_select = EEH_Form_Fields::select_input( 'category_parent', $category_select_values, $this->_category->parent ); |
|
1304 | + $category_select = EEH_Form_Fields::select_input('category_parent', $category_select_values, $this->_category->parent); |
|
1305 | 1305 | $template_args = array( |
1306 | 1306 | 'category' => $this->_category, |
1307 | 1307 | 'category_select' => $category_select, |
@@ -1310,15 +1310,15 @@ discard block |
||
1310 | 1310 | 'disable' => '', |
1311 | 1311 | 'disabled_message' =>FALSE |
1312 | 1312 | ); |
1313 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
1314 | - return EEH_Template::display_template($template, $template_args, TRUE ); |
|
1313 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
1314 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | |
1318 | 1318 | protected function _delete_categories() { |
1319 | - $cat_ids = isset( $this->_req_data['VEN_CAT_ID'] ) ? (array) $this->_req_data['VEN_CAT_ID'] : (array) $this->_req_data['category_id']; |
|
1319 | + $cat_ids = isset($this->_req_data['VEN_CAT_ID']) ? (array) $this->_req_data['VEN_CAT_ID'] : (array) $this->_req_data['category_id']; |
|
1320 | 1320 | |
1321 | - foreach ( $cat_ids as $cat_id ) { |
|
1321 | + foreach ($cat_ids as $cat_id) { |
|
1322 | 1322 | $this->_delete_category($cat_id); |
1323 | 1323 | } |
1324 | 1324 | |
@@ -1326,7 +1326,7 @@ discard block |
||
1326 | 1326 | $query_args = array( |
1327 | 1327 | 'action' => 'category_list' |
1328 | 1328 | ); |
1329 | - $this->_redirect_after_action(0,'','',$query_args); |
|
1329 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
1330 | 1330 | |
1331 | 1331 | } |
1332 | 1332 | |
@@ -1335,58 +1335,58 @@ discard block |
||
1335 | 1335 | |
1336 | 1336 | |
1337 | 1337 | protected function _delete_category($cat_id) { |
1338 | - $cat_id = absint( $cat_id ); |
|
1339 | - wp_delete_term( $cat_id, 'espresso_venue_categories' ); |
|
1338 | + $cat_id = absint($cat_id); |
|
1339 | + wp_delete_term($cat_id, 'espresso_venue_categories'); |
|
1340 | 1340 | } |
1341 | 1341 | |
1342 | 1342 | |
1343 | 1343 | |
1344 | 1344 | protected function _insert_or_update_category($new_category) { |
1345 | 1345 | |
1346 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category( TRUE ); |
|
1346 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(TRUE); |
|
1347 | 1347 | $success = 0; //we already have a success message so lets not send another. |
1348 | - if ( $cat_id ) { |
|
1348 | + if ($cat_id) { |
|
1349 | 1349 | $query_args = array( |
1350 | 1350 | 'action' => 'edit_category', |
1351 | 1351 | 'VEN_CAT_ID' => $cat_id |
1352 | 1352 | ); |
1353 | 1353 | } else { |
1354 | - $query_args = array( 'action' => 'add_category' ); |
|
1354 | + $query_args = array('action' => 'add_category'); |
|
1355 | 1355 | } |
1356 | - $this->_redirect_after_action( $success, '','', $query_args, TRUE ); |
|
1356 | + $this->_redirect_after_action($success, '', '', $query_args, TRUE); |
|
1357 | 1357 | |
1358 | 1358 | } |
1359 | 1359 | |
1360 | 1360 | |
1361 | 1361 | |
1362 | - private function _insert_category( $update = FALSE ) { |
|
1362 | + private function _insert_category($update = FALSE) { |
|
1363 | 1363 | $cat_id = $update ? $this->_req_data['VEN_CAT_ID'] : ''; |
1364 | - $category_name= isset( $this->_req_data['category_name'] ) ? $this->_req_data['category_name'] : ''; |
|
1365 | - $category_desc= isset( $this->_req_data['category_desc'] ) ? $this->_req_data['category_desc'] : ''; |
|
1366 | - $category_parent = isset( $this->_req_data['category_parent'] ) ? $this->_req_data['category_parent'] : 0; |
|
1364 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
1365 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
1366 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
1367 | 1367 | |
1368 | - if ( empty( $category_name ) ) { |
|
1369 | - $msg = __( 'You must add a name for the category.', 'event_espresso' ); |
|
1370 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
1368 | + if (empty($category_name)) { |
|
1369 | + $msg = __('You must add a name for the category.', 'event_espresso'); |
|
1370 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1371 | 1371 | return false; |
1372 | 1372 | } |
1373 | 1373 | |
1374 | 1374 | |
1375 | - $term_args=array( |
|
1375 | + $term_args = array( |
|
1376 | 1376 | 'name'=>$category_name, |
1377 | 1377 | 'description'=>$category_desc, |
1378 | 1378 | 'parent'=>$category_parent |
1379 | 1379 | ); |
1380 | 1380 | |
1381 | - $insert_ids = $update ? wp_update_term( $cat_id, 'espresso_venue_categories', $term_args ) :wp_insert_term( $category_name, 'espresso_venue_categories', $term_args ); |
|
1381 | + $insert_ids = $update ? wp_update_term($cat_id, 'espresso_venue_categories', $term_args) : wp_insert_term($category_name, 'espresso_venue_categories', $term_args); |
|
1382 | 1382 | |
1383 | - if ( !is_array( $insert_ids ) ) { |
|
1384 | - $msg = __( 'An error occurred and the category has not been saved to the database.', 'event_espresso' ); |
|
1385 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
1383 | + if ( ! is_array($insert_ids)) { |
|
1384 | + $msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso'); |
|
1385 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1386 | 1386 | } else { |
1387 | 1387 | $cat_id = $insert_ids['term_id']; |
1388 | - $msg = sprintf ( __('The category %s was successfully created', 'event_espresso'), $category_name ); |
|
1389 | - EE_Error::add_success( $msg ); |
|
1388 | + $msg = sprintf(__('The category %s was successfully created', 'event_espresso'), $category_name); |
|
1389 | + EE_Error::add_success($msg); |
|
1390 | 1390 | } |
1391 | 1391 | |
1392 | 1392 | return $cat_id; |
@@ -1406,11 +1406,11 @@ discard block |
||
1406 | 1406 | 'category_ids' => $this->_req_data['VEN_CAT_ID'] |
1407 | 1407 | ); |
1408 | 1408 | |
1409 | - $this->_req_data = array_merge( $this->_req_data, $new_request_args ); |
|
1409 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
1410 | 1410 | |
1411 | - if ( is_readable( EE_CLASSES . 'EE_Export.class.php') ) { |
|
1412 | - require_once( EE_CLASSES . 'EE_Export.class.php'); |
|
1413 | - $EE_Export = EE_Export::instance( $this->_req_data ); |
|
1411 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
1412 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
1413 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
1414 | 1414 | $EE_Export->export(); |
1415 | 1415 | } |
1416 | 1416 | |
@@ -1422,7 +1422,7 @@ discard block |
||
1422 | 1422 | |
1423 | 1423 | protected function _import_categories() { |
1424 | 1424 | |
1425 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
1425 | + require_once(EE_CLASSES.'EE_Import.class.php'); |
|
1426 | 1426 | EE_Import::instance()->import(); |
1427 | 1427 | |
1428 | 1428 | } |
@@ -1430,29 +1430,29 @@ discard block |
||
1430 | 1430 | |
1431 | 1431 | |
1432 | 1432 | |
1433 | - public function get_categories( $per_page = 10, $current_page = 1, $count = FALSE ) { |
|
1433 | + public function get_categories($per_page = 10, $current_page = 1, $count = FALSE) { |
|
1434 | 1434 | |
1435 | 1435 | //testing term stuff |
1436 | - $orderby = isset( $this->_req_data['orderby'] ) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
1437 | - $order = isset( $this->_req_data['order'] ) ? $this->_req_data['order'] : 'DESC'; |
|
1438 | - $limit = ($current_page-1)*$per_page; |
|
1439 | - $where = array( 'taxonomy' => 'espresso_venue_categories' ); |
|
1440 | - if ( isset( $this->_req_data['s'] ) ) { |
|
1441 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1436 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
1437 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
1438 | + $limit = ($current_page - 1) * $per_page; |
|
1439 | + $where = array('taxonomy' => 'espresso_venue_categories'); |
|
1440 | + if (isset($this->_req_data['s'])) { |
|
1441 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
1442 | 1442 | $where['OR'] = array( |
1443 | - 'Term.name' => array( 'LIKE', $sstr), |
|
1444 | - 'description' => array( 'LIKE', $sstr ) |
|
1443 | + 'Term.name' => array('LIKE', $sstr), |
|
1444 | + 'description' => array('LIKE', $sstr) |
|
1445 | 1445 | ); |
1446 | 1446 | } |
1447 | 1447 | |
1448 | 1448 | $query_params = array( |
1449 | 1449 | $where, |
1450 | - 'order_by' => array( $orderby => $order ), |
|
1451 | - 'limit' => $limit . ',' . $per_page, |
|
1450 | + 'order_by' => array($orderby => $order), |
|
1451 | + 'limit' => $limit.','.$per_page, |
|
1452 | 1452 | 'force_join' => array('Term') |
1453 | 1453 | ); |
1454 | 1454 | |
1455 | - $categories = $count ? EEM_Term_Taxonomy::instance()->count( $query_params, 'term_id' ) :EEM_Term_Taxonomy::instance()->get_all( $query_params ); |
|
1455 | + $categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
1456 | 1456 | |
1457 | 1457 | return $categories; |
1458 | 1458 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <div class="padding"> |
2 | 2 | <?php |
3 | 3 | //we'll only show site-license keys if this is main_site() (which works for both multi-site and single-site wp installations) |
4 | - if ( is_main_site() ) { ?> |
|
4 | + if (is_main_site()) { ?> |
|
5 | 5 | <h2 class="ee-admin-settings-hdr" style="width:300px;"> |
6 | 6 | <?php _e('Your Event Espresso License Key', 'event_espresso'); ?> |
7 | 7 | </h2> |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | <tr <?php echo isset($_REQUEST['license_key']) && $_REQUEST['license_key'] == true ? 'class="yellow_alert"' : '' ?>> |
12 | 12 | <th> |
13 | 13 | <label for="site_license_key"> |
14 | - <?php _e('Support License Key', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('site_license_key_info');?> |
|
14 | + <?php _e('Support License Key', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('site_license_key_info'); ?> |
|
15 | 15 | </label> |
16 | 16 | </th> |
17 | 17 | <td> |
18 | 18 | <input name="site_license_key" id="site_license_key" size="10" class="regular-text" type="text" value="<?php echo esc_attr($site_license_key); ?>" /><?php echo $site_license_key_verified; ?><br/> |
19 | 19 | <p class="description"> |
20 | - <?php printf( __('Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', 'event_espresso'), '<strong>', '</strong>' ); ?> |
|
20 | + <?php printf(__('Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', 'event_espresso'), '<strong>', '</strong>'); ?> |
|
21 | 21 | </p> |
22 | 22 | </td> |
23 | 23 | </tr> |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | |
32 | 32 | <h2 id="contact_info_h4" class="ee-admin-settings-hdr"> |
33 | - <?php _e('Contact Information', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('contact_info_info');?> |
|
33 | + <?php _e('Contact Information', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('contact_info_info'); ?> |
|
34 | 34 | </h2> |
35 | 35 | |
36 | 36 | <table class="form-table"> |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | <input id="organization_city" class="regular-text" type="text" name="organization_city" value="<?php echo esc_textarea($organization_city); ?>" /> |
79 | 79 | </td> |
80 | 80 | </tr> |
81 | - <?php echo EEH_Form_Fields::generate_form_input( $states ); ?> |
|
82 | - <?php echo EEH_Form_Fields::generate_form_input( $countries ); ?> |
|
81 | + <?php echo EEH_Form_Fields::generate_form_input($states); ?> |
|
82 | + <?php echo EEH_Form_Fields::generate_form_input($countries); ?> |
|
83 | 83 | <tr> |
84 | 84 | <th> |
85 | 85 | <label for="organization_zip"> |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | <td> |
100 | 100 | <input class="regular-text" type="text" name="organization_email" value="<?php echo esc_textarea($organization_email); ?>" /> |
101 | 101 | <p class="description"> |
102 | - <?php echo sprintf( esc_html__('This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', 'event_espresso'), '<code>[CO_FORMATTED_EMAIL]</code>', '<code>[CO_EMAIL]</code>' ); ?> |
|
102 | + <?php echo sprintf(esc_html__('This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', 'event_espresso'), '<code>[CO_FORMATTED_EMAIL]</code>', '<code>[CO_EMAIL]</code>'); ?> |
|
103 | 103 | </p> |
104 | 104 | </td> |
105 | 105 | </tr> |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | </table> |
134 | 134 | |
135 | 135 | <h2 class="ee-admin-settings-hdr"> |
136 | - <?php _e('Company Logo', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('organization_logo_info');?> |
|
136 | + <?php _e('Company Logo', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('organization_logo_info'); ?> |
|
137 | 137 | </h2> |
138 | 138 | |
139 | 139 | <table class="form-table"> |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | </th> |
162 | 162 | <td> |
163 | 163 | <?php |
164 | - if ( $organization_logo_url ) { |
|
164 | + if ($organization_logo_url) { |
|
165 | 165 | ?> |
166 | 166 | <p id="default-logo-thumb"> |
167 | 167 | <img id="current-image-thumb" src="<?php echo esc_url($organization_logo_url) ?>" alt="" /><br /> |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | <br/><br/> |
180 | 180 | |
181 | 181 | <h2 class="ee-admin-settings-hdr"> |
182 | - <?php _e('Social Links', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('social_links_info');?> |
|
182 | + <?php _e('Social Links', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('social_links_info'); ?> |
|
183 | 183 | </h2> |
184 | 184 | <p class="description"><?php _e('Enter any links to social accounts for your organization here', 'event_espresso'); ?></p> |
185 | 185 | |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | <br/><br/> |
257 | 257 | |
258 | 258 | |
259 | - <?php if ( is_main_site() ) : ?> |
|
259 | + <?php if (is_main_site()) : ?> |
|
260 | 260 | <p> |
261 | - <?php echo EE_PUE::espresso_data_collection_optin_text( FALSE ); ?> |
|
261 | + <?php echo EE_PUE::espresso_data_collection_optin_text(FALSE); ?> |
|
262 | 262 | </p> |
263 | 263 | |
264 | 264 | <table class="form-table"> |
@@ -272,11 +272,11 @@ discard block |
||
272 | 272 | </th> |
273 | 273 | <td> |
274 | 274 | <?php |
275 | - $values=array( |
|
276 | - array('id'=>'yes','text'=> __('Yes! I want to help improve Event Espresso!','event_espresso')), |
|
277 | - array('id'=>'no','text'=> __('Not at this time. Maybe later.','event_espresso')) |
|
275 | + $values = array( |
|
276 | + array('id'=>'yes', 'text'=> __('Yes! I want to help improve Event Espresso!', 'event_espresso')), |
|
277 | + array('id'=>'no', 'text'=> __('Not at this time. Maybe later.', 'event_espresso')) |
|
278 | 278 | ); |
279 | - echo EEH_Form_Fields::select_input('ueip_optin', $values, !empty($ee_ueip_optin) ? $ee_ueip_optin : 'yes'); |
|
279 | + echo EEH_Form_Fields::select_input('ueip_optin', $values, ! empty($ee_ueip_optin) ? $ee_ueip_optin : 'yes'); |
|
280 | 280 | ?> |
281 | 281 | </td> |
282 | 282 | </tr> |
@@ -3,9 +3,9 @@ discard block |
||
3 | 3 | <table class="form-table"> |
4 | 4 | <tbody> |
5 | 5 | <tr valign="top"> |
6 | - <th><label for="PRT_ID"><?php _e('Type', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('type_field_info');?></th> |
|
6 | + <th><label for="PRT_ID"><?php _e('Type', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('type_field_info'); ?></th> |
|
7 | 7 | <td> |
8 | - <?php if ( $price->type_obj() && $price->type_obj()->base_type() === 1 ) : ?> |
|
8 | + <?php if ($price->type_obj() && $price->type_obj()->base_type() === 1) : ?> |
|
9 | 9 | <input type="hidden" name="PRT_ID" id="PRT_ID" value="<?php echo $price->type(); ?>" /> |
10 | 10 | <p><strong><?php _e('Price', 'event_espresso'); ?></strong></p> |
11 | 11 | <p class="description"><?php _e('This is the default base price. Every new ticket created will start off with this base price.', 'event_espresso'); ?></p> |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | </td> |
17 | 17 | </tr> |
18 | 18 | <tr valign="top"> |
19 | - <th><label for="PRC_name"><?php _e('Name', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('name_field_info');?></th> |
|
19 | + <th><label for="PRC_name"><?php _e('Name', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('name_field_info'); ?></th> |
|
20 | 20 | <td> |
21 | 21 | <input class="regular-text" type="text" id="PRC_name" name="PRC_name" value="<?php $price->f('PRC_name'); ?>"/> |
22 | 22 | </td> |
23 | 23 | </tr> |
24 | 24 | <tr valign="top"> |
25 | - <th><label for="PRC_desc"><?php _e('Description', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('description_field_info');?></th> |
|
25 | + <th><label for="PRC_desc"><?php _e('Description', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('description_field_info'); ?></th> |
|
26 | 26 | <td> |
27 | 27 | <textarea class="regular-text" id="PRC_desc" name="PRC_desc" rows="5" ><?php |
28 | 28 | $price->f('PRC_desc'); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | </td> |
31 | 31 | </tr> |
32 | 32 | <tr valign="top"> |
33 | - <th><label for="PRC_amount"><?php _e('Amount', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('amount_field_info');?></label></th> |
|
33 | + <th><label for="PRC_amount"><?php _e('Amount', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('amount_field_info'); ?></label></th> |
|
34 | 34 | <td> |
35 | 35 | <input class="small-text ee-numeric" type="text" id="PRC_amount" name="PRC_amount" value="<?php echo $price->amount(); ?>"/> |
36 | 36 | </td> |
@@ -15,2114 +15,2114 @@ |
||
15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This property is just used to hold the status of whether an event is currently being |
|
20 | - * created (true) or edited (false) |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $_is_creating_event; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Used to contain the format strings for date and time that will be used for php date and |
|
30 | - * time. |
|
31 | - * Is set in the _set_hooks_properties() method. |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $_date_format_strings; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string $_date_time_format |
|
40 | - */ |
|
41 | - protected $_date_time_format; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * |
|
47 | - */ |
|
48 | - protected function _set_hooks_properties() |
|
49 | - { |
|
50 | - $this->_name = 'pricing'; |
|
51 | - //capability check |
|
52 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
53 | - 'ee_read_default_prices', |
|
54 | - 'advanced_ticket_datetime_metabox' |
|
55 | - )) { |
|
56 | - return; |
|
57 | - } |
|
58 | - $this->_setup_metaboxes(); |
|
59 | - $this->_set_date_time_formats(); |
|
60 | - $this->_validate_format_strings(); |
|
61 | - $this->_set_scripts_styles(); |
|
62 | - // commented out temporarily until logic is implemented in callback |
|
63 | - // add_action( |
|
64 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
65 | - // array($this, 'autosave_handling') |
|
66 | - // ); |
|
67 | - add_filter( |
|
68 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
69 | - array($this, 'caf_updates') |
|
70 | - ); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - protected function _setup_metaboxes() |
|
79 | - { |
|
80 | - //if we were going to add our own metaboxes we'd use the below. |
|
81 | - $this->_metaboxes = array( |
|
82 | - 0 => array( |
|
83 | - 'page_route' => array('edit', 'create_new'), |
|
84 | - 'func' => 'pricing_metabox', |
|
85 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
86 | - 'priority' => 'high', |
|
87 | - 'context' => 'normal', |
|
88 | - ), |
|
89 | - ); |
|
90 | - $this->_remove_metaboxes = array( |
|
91 | - 0 => array( |
|
92 | - 'page_route' => array('edit', 'create_new'), |
|
93 | - 'id' => 'espresso_event_editor_tickets', |
|
94 | - 'context' => 'normal', |
|
95 | - ), |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - protected function _set_date_time_formats() |
|
105 | - { |
|
106 | - /** |
|
107 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
108 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
109 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
110 | - * |
|
111 | - * @since 4.6.7 |
|
112 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
113 | - */ |
|
114 | - $this->_date_format_strings = apply_filters( |
|
115 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
116 | - array( |
|
117 | - 'date' => 'Y-m-d', |
|
118 | - 'time' => 'h:i a', |
|
119 | - ) |
|
120 | - ); |
|
121 | - //validate |
|
122 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
123 | - ? $this->_date_format_strings['date'] |
|
124 | - : null; |
|
125 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
126 | - ? $this->_date_format_strings['time'] |
|
127 | - : null; |
|
128 | - $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - protected function _validate_format_strings() |
|
137 | - { |
|
138 | - //validate format strings |
|
139 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
140 | - $this->_date_time_format |
|
141 | - ); |
|
142 | - if (is_array($format_validation)) { |
|
143 | - $msg = '<p>'; |
|
144 | - $msg .= sprintf( |
|
145 | - esc_html__( |
|
146 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
147 | - 'event_espresso' |
|
148 | - ), |
|
149 | - $this->_date_time_format |
|
150 | - ); |
|
151 | - $msg .= '</p><ul>'; |
|
152 | - foreach ($format_validation as $error) { |
|
153 | - $msg .= '<li>' . $error . '</li>'; |
|
154 | - } |
|
155 | - $msg .= '</ul><p>'; |
|
156 | - $msg .= sprintf( |
|
157 | - esc_html__( |
|
158 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
159 | - 'event_espresso' |
|
160 | - ), |
|
161 | - '<span style="color:#D54E21;">', |
|
162 | - '</span>' |
|
163 | - ); |
|
164 | - $msg .= '</p>'; |
|
165 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
166 | - $this->_date_format_strings = array( |
|
167 | - 'date' => 'Y-m-d', |
|
168 | - 'time' => 'h:i a', |
|
169 | - ); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @return void |
|
177 | - */ |
|
178 | - protected function _set_scripts_styles() |
|
179 | - { |
|
180 | - $this->_scripts_styles = array( |
|
181 | - 'registers' => array( |
|
182 | - 'ee-tickets-datetimes-css' => array( |
|
183 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
184 | - 'type' => 'css', |
|
185 | - ), |
|
186 | - 'ee-dtt-ticket-metabox' => array( |
|
187 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
188 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
189 | - ), |
|
190 | - ), |
|
191 | - 'deregisters' => array( |
|
192 | - 'event-editor-css' => array('type' => 'css'), |
|
193 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
194 | - ), |
|
195 | - 'enqueues' => array( |
|
196 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
197 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
198 | - ), |
|
199 | - 'localize' => array( |
|
200 | - 'ee-dtt-ticket-metabox' => array( |
|
201 | - 'DTT_TRASH_BLOCK' => array( |
|
202 | - 'main_warning' => esc_html__( |
|
203 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
204 | - 'event_espresso' |
|
205 | - ), |
|
206 | - 'after_warning' => esc_html__( |
|
207 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
208 | - 'event_espresso' |
|
209 | - ), |
|
210 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
211 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
212 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
213 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
214 | - 'single_warning_from_tkt' => esc_html__( |
|
215 | - 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
216 | - 'event_espresso' |
|
217 | - ), |
|
218 | - 'single_warning_from_dtt' => esc_html__( |
|
219 | - 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
220 | - 'event_espresso' |
|
221 | - ), |
|
222 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
223 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
224 | - ), |
|
225 | - 'DTT_ERROR_MSG' => array( |
|
226 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
227 | - 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
228 | - . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
229 | - ), |
|
230 | - 'DTT_OVERSELL_WARNING' => array( |
|
231 | - 'datetime_ticket' => esc_html__( |
|
232 | - 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
233 | - 'event_espresso' |
|
234 | - ), |
|
235 | - 'ticket_datetime' => esc_html__( |
|
236 | - 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
237 | - 'event_espresso' |
|
238 | - ), |
|
239 | - ), |
|
240 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
241 | - $this->_date_format_strings['date'], |
|
242 | - $this->_date_format_strings['time'] |
|
243 | - ), |
|
244 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
245 | - ), |
|
246 | - ), |
|
247 | - ); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param array $update_callbacks |
|
254 | - * @return array |
|
255 | - */ |
|
256 | - public function caf_updates(array $update_callbacks) |
|
257 | - { |
|
258 | - foreach ($update_callbacks as $key => $callback) { |
|
259 | - if ($callback[1] === '_default_tickets_update') { |
|
260 | - unset($update_callbacks[$key]); |
|
261 | - } |
|
262 | - } |
|
263 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
264 | - return $update_callbacks; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
270 | - * |
|
271 | - * @param EE_Event $event The Event object we're attaching data to |
|
272 | - * @param array $data The request data from the form |
|
273 | - * @throws EE_Error |
|
274 | - * @throws InvalidArgumentException |
|
275 | - */ |
|
276 | - public function datetime_and_tickets_caf_update($event, $data) |
|
277 | - { |
|
278 | - //first we need to start with datetimes cause they are the "root" items attached to events. |
|
279 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
280 | - //next tackle the tickets (and prices?) |
|
281 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * update event_datetimes |
|
287 | - * |
|
288 | - * @param EE_Event $event Event being updated |
|
289 | - * @param array $data the request data from the form |
|
290 | - * @return EE_Datetime[] |
|
291 | - * @throws InvalidArgumentException |
|
292 | - * @throws EE_Error |
|
293 | - */ |
|
294 | - protected function _update_datetimes($event, $data) |
|
295 | - { |
|
296 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
297 | - $saved_dtt_ids = array(); |
|
298 | - $saved_dtt_objs = array(); |
|
299 | - if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
300 | - throw new InvalidArgumentException( |
|
301 | - esc_html__( |
|
302 | - 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
303 | - 'event_espresso' |
|
304 | - ) |
|
305 | - ); |
|
306 | - } |
|
307 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
308 | - //trim all values to ensure any excess whitespace is removed. |
|
309 | - $datetime_data = array_map( |
|
310 | - function ($datetime_data) { |
|
311 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
312 | - }, |
|
313 | - $datetime_data |
|
314 | - ); |
|
315 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
316 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
317 | - ? $datetime_data['DTT_EVT_end'] |
|
318 | - : $datetime_data['DTT_EVT_start']; |
|
319 | - $datetime_values = array( |
|
320 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
321 | - ? $datetime_data['DTT_ID'] |
|
322 | - : null, |
|
323 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
324 | - ? $datetime_data['DTT_name'] |
|
325 | - : '', |
|
326 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
327 | - ? $datetime_data['DTT_description'] |
|
328 | - : '', |
|
329 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
330 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
331 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
332 | - ? EE_INF |
|
333 | - : $datetime_data['DTT_reg_limit'], |
|
334 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
335 | - ? $row |
|
336 | - : $datetime_data['DTT_order'], |
|
337 | - ); |
|
338 | - // if we have an id then let's get existing object first and then set the new values. |
|
339 | - // Otherwise we instantiate a new object for save. |
|
340 | - if (! empty($datetime_data['DTT_ID'])) { |
|
341 | - $datetime = EE_Registry::instance() |
|
342 | - ->load_model('Datetime', array($timezone)) |
|
343 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
344 | - //set date and time format according to what is set in this class. |
|
345 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
346 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
347 | - foreach ($datetime_values as $field => $value) { |
|
348 | - $datetime->set($field, $value); |
|
349 | - } |
|
350 | - // make sure the $dtt_id here is saved just in case |
|
351 | - // after the add_relation_to() the autosave replaces it. |
|
352 | - // We need to do this so we dont' TRASH the parent DTT. |
|
353 | - // (save the ID for both key and value to avoid duplications) |
|
354 | - $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
355 | - } else { |
|
356 | - $datetime = EE_Registry::instance()->load_class( |
|
357 | - 'Datetime', |
|
358 | - array( |
|
359 | - $datetime_values, |
|
360 | - $timezone, |
|
361 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
362 | - ), |
|
363 | - false, |
|
364 | - false |
|
365 | - ); |
|
366 | - foreach ($datetime_values as $field => $value) { |
|
367 | - $datetime->set($field, $value); |
|
368 | - } |
|
369 | - } |
|
370 | - $datetime->save(); |
|
371 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
372 | - // before going any further make sure our dates are setup correctly |
|
373 | - // so that the end date is always equal or greater than the start date. |
|
374 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
375 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
376 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
377 | - $datetime->save(); |
|
378 | - } |
|
379 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
380 | - // because it is possible there was a new one created for the autosave. |
|
381 | - // (save the ID for both key and value to avoid duplications) |
|
382 | - $DTT_ID = $datetime->ID(); |
|
383 | - $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
384 | - $saved_dtt_objs[$row] = $datetime; |
|
385 | - //todo if ANY of these updates fail then we want the appropriate global error message. |
|
386 | - } |
|
387 | - $event->save(); |
|
388 | - // now we need to REMOVE any datetimes that got deleted. |
|
389 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
390 | - // So its safe to permanently delete at this point. |
|
391 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
392 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
393 | - if (is_array($old_datetimes)) { |
|
394 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
395 | - foreach ($datetimes_to_delete as $id) { |
|
396 | - $id = absint($id); |
|
397 | - if (empty($id)) { |
|
398 | - continue; |
|
399 | - } |
|
400 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
401 | - //remove tkt relationships. |
|
402 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
403 | - foreach ($related_tickets as $tkt) { |
|
404 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
405 | - } |
|
406 | - $event->_remove_relation_to($id, 'Datetime'); |
|
407 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
408 | - } |
|
409 | - } |
|
410 | - return $saved_dtt_objs; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * update tickets |
|
416 | - * |
|
417 | - * @param EE_Event $event Event object being updated |
|
418 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
419 | - * @param array $data incoming request data |
|
420 | - * @return EE_Ticket[] |
|
421 | - * @throws InvalidArgumentException |
|
422 | - * @throws EE_Error |
|
423 | - */ |
|
424 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
425 | - { |
|
426 | - $new_tkt = null; |
|
427 | - $new_default = null; |
|
428 | - //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
429 | - $data = stripslashes_deep($data); |
|
430 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
431 | - $saved_tickets = $datetimes_on_existing = array(); |
|
432 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
433 | - if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
434 | - throw new InvalidArgumentException( |
|
435 | - esc_html__( |
|
436 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
437 | - 'event_espresso' |
|
438 | - ) |
|
439 | - ); |
|
440 | - } |
|
441 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
442 | - $update_prices = $create_new_TKT = false; |
|
443 | - // figure out what datetimes were added to the ticket |
|
444 | - // and what datetimes were removed from the ticket in the session. |
|
445 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
446 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
447 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
448 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
449 | - // trim inputs to ensure any excess whitespace is removed. |
|
450 | - $tkt = array_map( |
|
451 | - function ($ticket_data) { |
|
452 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
453 | - }, |
|
454 | - $tkt |
|
455 | - ); |
|
456 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
457 | - // because we're doing calculations prior to using the models. |
|
458 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
459 | - $ticket_price = isset($tkt['TKT_price']) |
|
460 | - ? round((float)$tkt['TKT_price'], 3) |
|
461 | - : 0; |
|
462 | - //note incoming base price needs converted from localized value. |
|
463 | - $base_price = isset($tkt['TKT_base_price']) |
|
464 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
465 | - : 0; |
|
466 | - //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
467 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
468 | - ? $base_price |
|
469 | - : $ticket_price; |
|
470 | - $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
471 | - ? $tkt['TKT_base_price_ID'] |
|
472 | - : 0; |
|
473 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
474 | - ? $data['edit_prices'][$row] |
|
475 | - : array(); |
|
476 | - $now = null; |
|
477 | - if (empty($tkt['TKT_start_date'])) { |
|
478 | - //lets' use now in the set timezone. |
|
479 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
480 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
481 | - } |
|
482 | - if (empty($tkt['TKT_end_date'])) { |
|
483 | - /** |
|
484 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
485 | - */ |
|
486 | - $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
487 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
488 | - } |
|
489 | - $TKT_values = array( |
|
490 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
491 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
492 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
493 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
494 | - && $tkt['TKT_description'] !== esc_html__( |
|
495 | - 'You can modify this description', |
|
496 | - 'event_espresso' |
|
497 | - ) |
|
498 | - ? $tkt['TKT_description'] |
|
499 | - : '', |
|
500 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
501 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
502 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
503 | - ? EE_INF |
|
504 | - : $tkt['TKT_qty'], |
|
505 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
506 | - ? EE_INF |
|
507 | - : $tkt['TKT_uses'], |
|
508 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
509 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
510 | - 'TKT_row' => $row, |
|
511 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
512 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
513 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
514 | - 'TKT_price' => $ticket_price, |
|
515 | - ); |
|
516 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
517 | - // which means in turn that the prices will become new prices as well. |
|
518 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
519 | - $TKT_values['TKT_ID'] = 0; |
|
520 | - $TKT_values['TKT_is_default'] = 0; |
|
521 | - $update_prices = true; |
|
522 | - } |
|
523 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
524 | - // we actually do our saves ahead of doing any add_relations to |
|
525 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
526 | - // but DID have it's items modified. |
|
527 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
528 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
529 | - if (absint($TKT_values['TKT_ID'])) { |
|
530 | - $ticket = EE_Registry::instance() |
|
531 | - ->load_model('Ticket', array($timezone)) |
|
532 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
533 | - if ($ticket instanceof EE_Ticket) { |
|
534 | - $ticket = $this->_update_ticket_datetimes( |
|
535 | - $ticket, |
|
536 | - $saved_datetimes, |
|
537 | - $datetimes_added, |
|
538 | - $datetimes_removed |
|
539 | - ); |
|
540 | - // are there any registrations using this ticket ? |
|
541 | - $tickets_sold = $ticket->count_related( |
|
542 | - 'Registration', |
|
543 | - array( |
|
544 | - array( |
|
545 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
546 | - ), |
|
547 | - ) |
|
548 | - ); |
|
549 | - //set ticket formats |
|
550 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
551 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
552 | - // let's just check the total price for the existing ticket |
|
553 | - // and determine if it matches the new total price. |
|
554 | - // if they are different then we create a new ticket (if tickets sold) |
|
555 | - // if they aren't different then we go ahead and modify existing ticket. |
|
556 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
557 | - //set new values |
|
558 | - foreach ($TKT_values as $field => $value) { |
|
559 | - if ($field === 'TKT_qty') { |
|
560 | - $ticket->set_qty($value); |
|
561 | - } else { |
|
562 | - $ticket->set($field, $value); |
|
563 | - } |
|
564 | - } |
|
565 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
566 | - // Otherwise we have to create a new ticket. |
|
567 | - if ($create_new_TKT) { |
|
568 | - $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
569 | - $base_price_id); |
|
570 | - } |
|
571 | - } |
|
572 | - } else { |
|
573 | - // no TKT_id so a new TKT |
|
574 | - $ticket = EE_Ticket::new_instance( |
|
575 | - $TKT_values, |
|
576 | - $timezone, |
|
577 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
578 | - ); |
|
579 | - if ($ticket instanceof EE_Ticket) { |
|
580 | - // make sure ticket has an ID of setting relations won't work |
|
581 | - $ticket->save(); |
|
582 | - $ticket = $this->_update_ticket_datetimes( |
|
583 | - $ticket, |
|
584 | - $saved_datetimes, |
|
585 | - $datetimes_added, |
|
586 | - $datetimes_removed |
|
587 | - ); |
|
588 | - $update_prices = true; |
|
589 | - } |
|
590 | - } |
|
591 | - //make sure any current values have been saved. |
|
592 | - //$ticket->save(); |
|
593 | - // before going any further make sure our dates are setup correctly |
|
594 | - // so that the end date is always equal or greater than the start date. |
|
595 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
596 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
597 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
598 | - } |
|
599 | - //let's make sure the base price is handled |
|
600 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
601 | - $base_price_id) : $ticket; |
|
602 | - //add/update price_modifiers |
|
603 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
604 | - //need to make sue that the TKT_price is accurate after saving the prices. |
|
605 | - $ticket->ensure_TKT_Price_correct(); |
|
606 | - //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
607 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
608 | - $update_prices = true; |
|
609 | - $new_default = clone $ticket; |
|
610 | - $new_default->set('TKT_ID', 0); |
|
611 | - $new_default->set('TKT_is_default', 1); |
|
612 | - $new_default->set('TKT_row', 1); |
|
613 | - $new_default->set('TKT_price', $ticket_price); |
|
614 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
615 | - // (note this is just removing the cached relations in the object) |
|
616 | - $new_default->_remove_relations('Datetime'); |
|
617 | - //todo we need to add the current attached prices as new prices to the new default ticket. |
|
618 | - $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
619 | - //don't forget the base price! |
|
620 | - $new_default = $this->_add_prices_to_ticket( |
|
621 | - array(), |
|
622 | - $new_default, |
|
623 | - $update_prices, |
|
624 | - $base_price, |
|
625 | - $base_price_id |
|
626 | - ); |
|
627 | - $new_default->save(); |
|
628 | - do_action( |
|
629 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
630 | - $new_default, |
|
631 | - $row, |
|
632 | - $ticket, |
|
633 | - $data |
|
634 | - ); |
|
635 | - } |
|
636 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
637 | - // for the given dtt that are related to the current ticket. |
|
638 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
639 | - // what current ticket the archived tickets are related to |
|
640 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
641 | - //let's assign any tickets that have been setup to the saved_tickets tracker |
|
642 | - //save existing TKT |
|
643 | - $ticket->save(); |
|
644 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
645 | - //save new TKT |
|
646 | - $new_tkt->save(); |
|
647 | - //add new ticket to array |
|
648 | - $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
649 | - do_action( |
|
650 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
651 | - $new_tkt, |
|
652 | - $row, |
|
653 | - $tkt, |
|
654 | - $data |
|
655 | - ); |
|
656 | - } else { |
|
657 | - //add tkt to saved tkts |
|
658 | - $saved_tickets[$ticket->ID()] = $ticket; |
|
659 | - do_action( |
|
660 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
661 | - $ticket, |
|
662 | - $row, |
|
663 | - $tkt, |
|
664 | - $data |
|
665 | - ); |
|
666 | - } |
|
667 | - } |
|
668 | - // now we need to handle tickets actually "deleted permanently". |
|
669 | - // There are cases where we'd want this to happen |
|
670 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
671 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
672 | - // No sense in keeping all the related data in the db! |
|
673 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
674 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
675 | - foreach ($tickets_removed as $id) { |
|
676 | - $id = absint($id); |
|
677 | - //get the ticket for this id |
|
678 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
679 | - //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
680 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
681 | - continue; |
|
682 | - } |
|
683 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
684 | - // because we don't actually permanently delete these tickets. |
|
685 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
686 | - $tkt_to_remove->delete(); |
|
687 | - continue; |
|
688 | - } |
|
689 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
690 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
691 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
692 | - foreach ($datetimes as $datetime) { |
|
693 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
694 | - } |
|
695 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
696 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
697 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
698 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
699 | - // finally let's delete this ticket |
|
700 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
701 | - $tkt_to_remove->delete_permanently(); |
|
702 | - } |
|
703 | - return $saved_tickets; |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * @access protected |
|
710 | - * @param \EE_Ticket $ticket |
|
711 | - * @param \EE_Datetime[] $saved_datetimes |
|
712 | - * @param \EE_Datetime[] $added_datetimes |
|
713 | - * @param \EE_Datetime[] $removed_datetimes |
|
714 | - * @return \EE_Ticket |
|
715 | - * @throws \EE_Error |
|
716 | - */ |
|
717 | - protected function _update_ticket_datetimes( |
|
718 | - EE_Ticket $ticket, |
|
719 | - $saved_datetimes = array(), |
|
720 | - $added_datetimes = array(), |
|
721 | - $removed_datetimes = array() |
|
722 | - ) { |
|
723 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
724 | - // and removing the ticket from datetimes it got removed from. |
|
725 | - // first let's add datetimes |
|
726 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
727 | - foreach ($added_datetimes as $row_id) { |
|
728 | - $row_id = (int)$row_id; |
|
729 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
730 | - $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
731 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
732 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
733 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
734 | - $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
735 | - $saved_datetimes[$row_id]->save(); |
|
736 | - } |
|
737 | - } |
|
738 | - } |
|
739 | - } |
|
740 | - // then remove datetimes |
|
741 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
742 | - foreach ($removed_datetimes as $row_id) { |
|
743 | - $row_id = (int)$row_id; |
|
744 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
745 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
746 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
747 | - $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
748 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
749 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
750 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
751 | - $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
752 | - $saved_datetimes[$row_id]->save(); |
|
753 | - } |
|
754 | - } |
|
755 | - } |
|
756 | - } |
|
757 | - // cap ticket qty by datetime reg limits |
|
758 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
759 | - return $ticket; |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - |
|
764 | - /** |
|
765 | - * @access protected |
|
766 | - * @param \EE_Ticket $ticket |
|
767 | - * @param array $price_rows |
|
768 | - * @param int $ticket_price |
|
769 | - * @param int $base_price |
|
770 | - * @param int $base_price_id |
|
771 | - * @return \EE_Ticket |
|
772 | - * @throws \EE_Error |
|
773 | - */ |
|
774 | - protected function _duplicate_ticket( |
|
775 | - EE_Ticket $ticket, |
|
776 | - $price_rows = array(), |
|
777 | - $ticket_price = 0, |
|
778 | - $base_price = 0, |
|
779 | - $base_price_id = 0 |
|
780 | - ) { |
|
781 | - // create new ticket that's a copy of the existing |
|
782 | - // except a new id of course (and not archived) |
|
783 | - // AND has the new TKT_price associated with it. |
|
784 | - $new_ticket = clone $ticket; |
|
785 | - $new_ticket->set('TKT_ID', 0); |
|
786 | - $new_ticket->set_deleted(0); |
|
787 | - $new_ticket->set_price($ticket_price); |
|
788 | - $new_ticket->set_sold(0); |
|
789 | - // let's get a new ID for this ticket |
|
790 | - $new_ticket->save(); |
|
791 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
792 | - $datetimes_on_existing = $ticket->datetimes(); |
|
793 | - $new_ticket = $this->_update_ticket_datetimes( |
|
794 | - $new_ticket, |
|
795 | - $datetimes_on_existing, |
|
796 | - array_keys($datetimes_on_existing) |
|
797 | - ); |
|
798 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
799 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
800 | - // available. |
|
801 | - if ($ticket->sold() > 0) { |
|
802 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
803 | - $new_ticket->set_qty($new_qty); |
|
804 | - } |
|
805 | - //now we update the prices just for this ticket |
|
806 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
807 | - //and we update the base price |
|
808 | - $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
809 | - return $new_ticket; |
|
810 | - } |
|
811 | - |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * This attaches a list of given prices to a ticket. |
|
816 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
817 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
818 | - * price info and prices are automatically "archived" via the ticket. |
|
819 | - * |
|
820 | - * @access private |
|
821 | - * @param array $prices Array of prices from the form. |
|
822 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
823 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
824 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
825 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
826 | - * @return EE_Ticket |
|
827 | - * @throws EE_Error |
|
828 | - */ |
|
829 | - protected function _add_prices_to_ticket( |
|
830 | - $prices = array(), |
|
831 | - EE_Ticket $ticket, |
|
832 | - $new_prices = false, |
|
833 | - $base_price = false, |
|
834 | - $base_price_id = false |
|
835 | - ) { |
|
836 | - // let's just get any current prices that may exist on the given ticket |
|
837 | - // so we can remove any prices that got trashed in this session. |
|
838 | - $current_prices_on_ticket = $base_price !== false |
|
839 | - ? $ticket->base_price(true) |
|
840 | - : $ticket->price_modifiers(); |
|
841 | - $updated_prices = array(); |
|
842 | - // if $base_price ! FALSE then updating a base price. |
|
843 | - if ($base_price !== false) { |
|
844 | - $prices[1] = array( |
|
845 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
846 | - 'PRT_ID' => 1, |
|
847 | - 'PRC_amount' => $base_price, |
|
848 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
849 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
850 | - ); |
|
851 | - } |
|
852 | - //possibly need to save tkt |
|
853 | - if (! $ticket->ID()) { |
|
854 | - $ticket->save(); |
|
855 | - } |
|
856 | - foreach ($prices as $row => $prc) { |
|
857 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
858 | - if (empty($prt_id)) { |
|
859 | - continue; |
|
860 | - } //prices MUST have a price type id. |
|
861 | - $PRC_values = array( |
|
862 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
863 | - 'PRT_ID' => $prt_id, |
|
864 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
865 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
866 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
867 | - 'PRC_is_default' => false, |
|
868 | - //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
869 | - 'PRC_order' => $row, |
|
870 | - ); |
|
871 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
872 | - $PRC_values['PRC_ID'] = 0; |
|
873 | - $price = EE_Registry::instance()->load_class( |
|
874 | - 'Price', |
|
875 | - array($PRC_values), |
|
876 | - false, |
|
877 | - false |
|
878 | - ); |
|
879 | - } else { |
|
880 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
881 | - //update this price with new values |
|
882 | - foreach ($PRC_values as $field => $value) { |
|
883 | - $price->set($field, $value); |
|
884 | - } |
|
885 | - } |
|
886 | - $price->save(); |
|
887 | - $updated_prices[$price->ID()] = $price; |
|
888 | - $ticket->_add_relation_to($price, 'Price'); |
|
889 | - } |
|
890 | - //now let's remove any prices that got removed from the ticket |
|
891 | - if (! empty ($current_prices_on_ticket)) { |
|
892 | - $current = array_keys($current_prices_on_ticket); |
|
893 | - $updated = array_keys($updated_prices); |
|
894 | - $prices_to_remove = array_diff($current, $updated); |
|
895 | - if (! empty($prices_to_remove)) { |
|
896 | - foreach ($prices_to_remove as $prc_id) { |
|
897 | - $p = $current_prices_on_ticket[$prc_id]; |
|
898 | - $ticket->_remove_relation_to($p, 'Price'); |
|
899 | - //delete permanently the price |
|
900 | - $p->delete_permanently(); |
|
901 | - } |
|
902 | - } |
|
903 | - } |
|
904 | - return $ticket; |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * @param Events_Admin_Page $event_admin_obj |
|
911 | - * @return Events_Admin_Page |
|
912 | - */ |
|
913 | - public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
914 | - { |
|
915 | - return $event_admin_obj; |
|
916 | - //doing nothing for the moment. |
|
917 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
918 | - // (use the set_template_args() method) |
|
919 | - /** |
|
920 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
921 | - * 1. TKT_is_default_selector (visible) |
|
922 | - * 2. TKT_is_default (hidden) |
|
923 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
924 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
925 | - * this ticket to be saved as a default. |
|
926 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
927 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
928 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
929 | - * the TKT HAS been saved as a default.. |
|
930 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
931 | - * On Autosave: |
|
932 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
933 | - * then set the TKT_is_default to false. |
|
934 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
935 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
936 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
937 | - */ |
|
938 | - } |
|
939 | - |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * @throws DomainException |
|
944 | - * @throws EE_Error |
|
945 | - */ |
|
946 | - public function pricing_metabox() |
|
947 | - { |
|
948 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
949 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
950 | - //set is_creating_event property. |
|
951 | - $EVT_ID = $event->ID(); |
|
952 | - $this->_is_creating_event = absint($EVT_ID) === 0; |
|
953 | - //default main template args |
|
954 | - $main_template_args = array( |
|
955 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
956 | - 'event_editor_event_datetimes_help_tab', |
|
957 | - $this->_adminpage_obj->page_slug, |
|
958 | - $this->_adminpage_obj->get_req_action(), |
|
959 | - false, |
|
960 | - false |
|
961 | - ), |
|
962 | - // todo need to add a filter to the template for the help text |
|
963 | - // in the Events_Admin_Page core file so we can add further help |
|
964 | - 'existing_datetime_ids' => '', |
|
965 | - 'total_dtt_rows' => 1, |
|
966 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
967 | - 'add_new_dtt_info', |
|
968 | - $this->_adminpage_obj->page_slug, |
|
969 | - $this->_adminpage_obj->get_req_action(), |
|
970 | - false, |
|
971 | - false |
|
972 | - ), |
|
973 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
974 | - 'datetime_rows' => '', |
|
975 | - 'show_tickets_container' => '', |
|
976 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
977 | - 'ticket_rows' => '', |
|
978 | - 'existing_ticket_ids' => '', |
|
979 | - 'total_ticket_rows' => 1, |
|
980 | - 'ticket_js_structure' => '', |
|
981 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
982 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
983 | - ); |
|
984 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
985 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
986 | - /** |
|
987 | - * 1. Start with retrieving Datetimes |
|
988 | - * 2. For each datetime get related tickets |
|
989 | - * 3. For each ticket get related prices |
|
990 | - */ |
|
991 | - /** @var EEM_Datetime $datetime_model */ |
|
992 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
993 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
994 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
995 | - /** |
|
996 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
997 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
998 | - */ |
|
999 | - $datetime_row = 1; |
|
1000 | - foreach ($datetimes as $datetime) { |
|
1001 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
1002 | - $datetime->set('DTT_order', $datetime_row); |
|
1003 | - $existing_datetime_ids[] = $DTT_ID; |
|
1004 | - //tickets attached |
|
1005 | - $related_tickets = $datetime->ID() > 0 |
|
1006 | - ? $datetime->get_many_related( |
|
1007 | - 'Ticket', |
|
1008 | - array( |
|
1009 | - array( |
|
1010 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1011 | - ), |
|
1012 | - 'default_where_conditions' => 'none', |
|
1013 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
1014 | - ) |
|
1015 | - ) |
|
1016 | - : array(); |
|
1017 | - //if there are no related tickets this is likely a new event OR autodraft |
|
1018 | - // event so we need to generate the default tickets because datetimes |
|
1019 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1020 | - // datetime on the event. |
|
1021 | - if (empty ($related_tickets) && count($datetimes) < 2) { |
|
1022 | - /** @var EEM_Ticket $ticket_model */ |
|
1023 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1024 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1025 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1026 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1027 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1028 | - $main_default_ticket = reset($related_tickets); |
|
1029 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
1030 | - foreach ($default_prices as $default_price) { |
|
1031 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1032 | - continue; |
|
1033 | - } |
|
1034 | - $main_default_ticket->cache('Price', $default_price); |
|
1035 | - } |
|
1036 | - } |
|
1037 | - } |
|
1038 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
1039 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1040 | - // So we're going to temporarily cache some of that information. |
|
1041 | - //loop through and setup the ticket rows and make sure the order is set. |
|
1042 | - foreach ($related_tickets as $ticket) { |
|
1043 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
1044 | - $ticket_row = $ticket->get('TKT_row'); |
|
1045 | - //we only want unique tickets in our final display!! |
|
1046 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1047 | - $existing_ticket_ids[] = $TKT_ID; |
|
1048 | - $all_tickets[] = $ticket; |
|
1049 | - } |
|
1050 | - //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1051 | - $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
1052 | - //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1053 | - if ( |
|
1054 | - ! isset($ticket_datetimes[$TKT_ID]) |
|
1055 | - || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
1056 | - ) { |
|
1057 | - $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
1058 | - } |
|
1059 | - } |
|
1060 | - $datetime_row++; |
|
1061 | - } |
|
1062 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1063 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1064 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1065 | - //sort $all_tickets by order |
|
1066 | - usort( |
|
1067 | - $all_tickets, |
|
1068 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1069 | - $a_order = (int)$a->get('TKT_order'); |
|
1070 | - $b_order = (int)$b->get('TKT_order'); |
|
1071 | - if ($a_order === $b_order) { |
|
1072 | - return 0; |
|
1073 | - } |
|
1074 | - return ($a_order < $b_order) ? -1 : 1; |
|
1075 | - } |
|
1076 | - ); |
|
1077 | - // k NOW we have all the data we need for setting up the dtt rows |
|
1078 | - // and ticket rows so we start our dtt loop again. |
|
1079 | - $datetime_row = 1; |
|
1080 | - foreach ($datetimes as $datetime) { |
|
1081 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1082 | - $datetime_row, |
|
1083 | - $datetime, |
|
1084 | - $datetime_tickets, |
|
1085 | - $all_tickets, |
|
1086 | - false, |
|
1087 | - $datetimes |
|
1088 | - ); |
|
1089 | - $datetime_row++; |
|
1090 | - } |
|
1091 | - //then loop through all tickets for the ticket rows. |
|
1092 | - $ticket_row = 1; |
|
1093 | - foreach ($all_tickets as $ticket) { |
|
1094 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1095 | - $ticket_row, |
|
1096 | - $ticket, |
|
1097 | - $ticket_datetimes, |
|
1098 | - $datetimes, |
|
1099 | - false, |
|
1100 | - $all_tickets |
|
1101 | - ); |
|
1102 | - $ticket_row++; |
|
1103 | - } |
|
1104 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1105 | - EEH_Template::display_template( |
|
1106 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1107 | - $main_template_args |
|
1108 | - ); |
|
1109 | - } |
|
1110 | - |
|
1111 | - |
|
1112 | - |
|
1113 | - /** |
|
1114 | - * @param int $datetime_row |
|
1115 | - * @param EE_Datetime $datetime |
|
1116 | - * @param array $datetime_tickets |
|
1117 | - * @param array $all_tickets |
|
1118 | - * @param bool $default |
|
1119 | - * @param array $all_datetimes |
|
1120 | - * @return mixed |
|
1121 | - * @throws DomainException |
|
1122 | - * @throws EE_Error |
|
1123 | - */ |
|
1124 | - protected function _get_datetime_row( |
|
1125 | - $datetime_row, |
|
1126 | - EE_Datetime $datetime, |
|
1127 | - $datetime_tickets = array(), |
|
1128 | - $all_tickets = array(), |
|
1129 | - $default = false, |
|
1130 | - $all_datetimes = array() |
|
1131 | - ) { |
|
1132 | - $dtt_display_template_args = array( |
|
1133 | - 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
1134 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1135 | - $datetime_row, |
|
1136 | - $datetime, |
|
1137 | - $datetime_tickets, |
|
1138 | - $all_tickets, |
|
1139 | - $default |
|
1140 | - ), |
|
1141 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1142 | - ); |
|
1143 | - return EEH_Template::display_template( |
|
1144 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1145 | - $dtt_display_template_args, |
|
1146 | - true |
|
1147 | - ); |
|
1148 | - } |
|
1149 | - |
|
1150 | - |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * This method is used to generate a dtt fields edit row. |
|
1154 | - * The same row is used to generate a row with valid DTT objects |
|
1155 | - * and the default row that is used as the skeleton by the js. |
|
1156 | - * |
|
1157 | - * @param int $datetime_row The row number for the row being generated. |
|
1158 | - * @param EE_Datetime $datetime |
|
1159 | - * @param bool $default Whether a default row is being generated or not. |
|
1160 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1161 | - * @return string |
|
1162 | - * @throws DomainException |
|
1163 | - * @throws EE_Error |
|
1164 | - */ |
|
1165 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1166 | - { |
|
1167 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1168 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1169 | - $template_args = array( |
|
1170 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1171 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1172 | - 'edit_dtt_expanded' => '', |
|
1173 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1174 | - 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
1175 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1176 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1177 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1178 | - 'DTT_reg_limit' => $default |
|
1179 | - ? '' |
|
1180 | - : $datetime->get_pretty( |
|
1181 | - 'DTT_reg_limit', |
|
1182 | - 'input' |
|
1183 | - ), |
|
1184 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1185 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1186 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1187 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1188 | - ? '' |
|
1189 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1190 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1191 | - ? 'ee-lock-icon' |
|
1192 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1193 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1194 | - ? '' |
|
1195 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
1196 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1197 | - REG_ADMIN_URL |
|
1198 | - ), |
|
1199 | - ); |
|
1200 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1201 | - ? ' style="display:none"' |
|
1202 | - : ''; |
|
1203 | - //allow filtering of template args at this point. |
|
1204 | - $template_args = apply_filters( |
|
1205 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1206 | - $template_args, |
|
1207 | - $datetime_row, |
|
1208 | - $datetime, |
|
1209 | - $default, |
|
1210 | - $all_datetimes, |
|
1211 | - $this->_is_creating_event |
|
1212 | - ); |
|
1213 | - return EEH_Template::display_template( |
|
1214 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1215 | - $template_args, |
|
1216 | - true |
|
1217 | - ); |
|
1218 | - } |
|
1219 | - |
|
1220 | - |
|
1221 | - |
|
1222 | - /** |
|
1223 | - * @param int $datetime_row |
|
1224 | - * @param EE_Datetime $datetime |
|
1225 | - * @param array $datetime_tickets |
|
1226 | - * @param array $all_tickets |
|
1227 | - * @param bool $default |
|
1228 | - * @return mixed |
|
1229 | - * @throws DomainException |
|
1230 | - * @throws EE_Error |
|
1231 | - */ |
|
1232 | - protected function _get_dtt_attached_tickets_row( |
|
1233 | - $datetime_row, |
|
1234 | - $datetime, |
|
1235 | - $datetime_tickets = array(), |
|
1236 | - $all_tickets = array(), |
|
1237 | - $default |
|
1238 | - ) { |
|
1239 | - $template_args = array( |
|
1240 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1241 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1242 | - 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1243 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1244 | - 'show_tickets_row' => ' style="display:none;"', |
|
1245 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1246 | - 'add_new_ticket_via_datetime', |
|
1247 | - $this->_adminpage_obj->page_slug, |
|
1248 | - $this->_adminpage_obj->get_req_action(), |
|
1249 | - false, |
|
1250 | - false |
|
1251 | - ), |
|
1252 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1253 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1254 | - ); |
|
1255 | - //need to setup the list items (but only if this isn't a default skeleton setup) |
|
1256 | - if (! $default) { |
|
1257 | - $ticket_row = 1; |
|
1258 | - foreach ($all_tickets as $ticket) { |
|
1259 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1260 | - $datetime_row, |
|
1261 | - $ticket_row, |
|
1262 | - $datetime, |
|
1263 | - $ticket, |
|
1264 | - $datetime_tickets, |
|
1265 | - $default |
|
1266 | - ); |
|
1267 | - $ticket_row++; |
|
1268 | - } |
|
1269 | - } |
|
1270 | - //filter template args at this point |
|
1271 | - $template_args = apply_filters( |
|
1272 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1273 | - $template_args, |
|
1274 | - $datetime_row, |
|
1275 | - $datetime, |
|
1276 | - $datetime_tickets, |
|
1277 | - $all_tickets, |
|
1278 | - $default, |
|
1279 | - $this->_is_creating_event |
|
1280 | - ); |
|
1281 | - return EEH_Template::display_template( |
|
1282 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1283 | - $template_args, |
|
1284 | - true |
|
1285 | - ); |
|
1286 | - } |
|
1287 | - |
|
1288 | - |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * @param int $datetime_row |
|
1292 | - * @param int $ticket_row |
|
1293 | - * @param EE_Datetime $datetime |
|
1294 | - * @param EE_Ticket $ticket |
|
1295 | - * @param array $datetime_tickets |
|
1296 | - * @param bool $default |
|
1297 | - * @return mixed |
|
1298 | - * @throws DomainException |
|
1299 | - * @throws EE_Error |
|
1300 | - */ |
|
1301 | - protected function _get_datetime_tickets_list_item( |
|
1302 | - $datetime_row, |
|
1303 | - $ticket_row, |
|
1304 | - $datetime, |
|
1305 | - $ticket, |
|
1306 | - $datetime_tickets = array(), |
|
1307 | - $default |
|
1308 | - ) { |
|
1309 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
1310 | - ? $datetime_tickets[$datetime->ID()] |
|
1311 | - : array(); |
|
1312 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1313 | - $no_ticket = $default && empty($ticket); |
|
1314 | - $template_args = array( |
|
1315 | - 'dtt_row' => $default |
|
1316 | - ? 'DTTNUM' |
|
1317 | - : $datetime_row, |
|
1318 | - 'tkt_row' => $no_ticket |
|
1319 | - ? 'TICKETNUM' |
|
1320 | - : $ticket_row, |
|
1321 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1322 | - ? ' checked="checked"' |
|
1323 | - : '', |
|
1324 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1325 | - ? ' ticket-selected' |
|
1326 | - : '', |
|
1327 | - 'TKT_name' => $no_ticket |
|
1328 | - ? 'TKTNAME' |
|
1329 | - : $ticket->get('TKT_name'), |
|
1330 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1331 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1332 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1333 | - ); |
|
1334 | - //filter template args |
|
1335 | - $template_args = apply_filters( |
|
1336 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1337 | - $template_args, |
|
1338 | - $datetime_row, |
|
1339 | - $ticket_row, |
|
1340 | - $datetime, |
|
1341 | - $ticket, |
|
1342 | - $datetime_tickets, |
|
1343 | - $default, |
|
1344 | - $this->_is_creating_event |
|
1345 | - ); |
|
1346 | - return EEH_Template::display_template( |
|
1347 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1348 | - $template_args, |
|
1349 | - true |
|
1350 | - ); |
|
1351 | - } |
|
1352 | - |
|
1353 | - |
|
1354 | - |
|
1355 | - /** |
|
1356 | - * This generates the ticket row for tickets. |
|
1357 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
1358 | - * (when default === true) |
|
1359 | - * |
|
1360 | - * @param int $ticket_row Represents the row number being generated. |
|
1361 | - * @param $ticket |
|
1362 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1363 | - * or empty for default |
|
1364 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1365 | - * @param bool $default Whether default row being generated or not. |
|
1366 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1367 | - * (or empty in the case of defaults) |
|
1368 | - * @return mixed |
|
1369 | - * @throws DomainException |
|
1370 | - * @throws EE_Error |
|
1371 | - */ |
|
1372 | - protected function _get_ticket_row( |
|
1373 | - $ticket_row, |
|
1374 | - $ticket, |
|
1375 | - $ticket_datetimes, |
|
1376 | - $all_datetimes, |
|
1377 | - $default = false, |
|
1378 | - $all_tickets = array() |
|
1379 | - ) { |
|
1380 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1381 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1382 | - $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
1383 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
1384 | - // if there is only one price (which would be the base price) |
|
1385 | - // or NO prices and this ticket is a default ticket, |
|
1386 | - // let's just make sure there are no cached default prices on the object. |
|
1387 | - // This is done by not including any query_params. |
|
1388 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1389 | - $prices = $ticket->prices(); |
|
1390 | - } |
|
1391 | - // check if we're dealing with a default ticket in which case |
|
1392 | - // we don't want any starting_ticket_datetime_row values set |
|
1393 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1394 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1395 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1396 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1397 | - ? $ticket_datetimes[$ticket->ID()] |
|
1398 | - : array(); |
|
1399 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1400 | - $base_price = $default ? null : $ticket->base_price(); |
|
1401 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1402 | - //breaking out complicated condition for ticket_status |
|
1403 | - if ($default) { |
|
1404 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1405 | - } else { |
|
1406 | - $ticket_status_class = $ticket->is_default() |
|
1407 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1408 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1409 | - } |
|
1410 | - //breaking out complicated condition for TKT_taxable |
|
1411 | - if ($default) { |
|
1412 | - $TKT_taxable = ''; |
|
1413 | - } else { |
|
1414 | - $TKT_taxable = $ticket->taxable() |
|
1415 | - ? ' checked="checked"' |
|
1416 | - : ''; |
|
1417 | - } |
|
1418 | - if ($default) { |
|
1419 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1420 | - } elseif ($ticket->is_default()) { |
|
1421 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1422 | - } else { |
|
1423 | - $TKT_status = $ticket->ticket_status(true); |
|
1424 | - } |
|
1425 | - if ($default) { |
|
1426 | - $TKT_min = ''; |
|
1427 | - } else { |
|
1428 | - $TKT_min = $ticket->min(); |
|
1429 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
1430 | - $TKT_min = ''; |
|
1431 | - } |
|
1432 | - } |
|
1433 | - $template_args = array( |
|
1434 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1435 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1436 | - //on initial page load this will always be the correct order. |
|
1437 | - 'tkt_status_class' => $ticket_status_class, |
|
1438 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
1439 | - 'edit_tkt_expanded' => '', |
|
1440 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1441 | - 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
1442 | - 'TKT_start_date' => $default |
|
1443 | - ? '' |
|
1444 | - : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1445 | - 'TKT_end_date' => $default |
|
1446 | - ? '' |
|
1447 | - : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1448 | - 'TKT_status' => $TKT_status, |
|
1449 | - 'TKT_price' => $default |
|
1450 | - ? '' |
|
1451 | - : EEH_Template::format_currency( |
|
1452 | - $ticket->get_ticket_total_with_taxes(), |
|
1453 | - false, |
|
1454 | - false |
|
1455 | - ), |
|
1456 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1457 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1458 | - 'TKT_qty' => $default |
|
1459 | - ? '' |
|
1460 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1461 | - 'TKT_qty_for_input' => $default |
|
1462 | - ? '' |
|
1463 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
1464 | - 'TKT_uses' => $default |
|
1465 | - ? '' |
|
1466 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
1467 | - 'TKT_min' => $TKT_min, |
|
1468 | - 'TKT_max' => $default |
|
1469 | - ? '' |
|
1470 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
1471 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1472 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1473 | - 'TKT_registrations' => $default |
|
1474 | - ? 0 |
|
1475 | - : $ticket->count_registrations( |
|
1476 | - array( |
|
1477 | - array( |
|
1478 | - 'STS_ID' => array( |
|
1479 | - '!=', |
|
1480 | - EEM_Registration::status_id_incomplete, |
|
1481 | - ), |
|
1482 | - ), |
|
1483 | - ) |
|
1484 | - ), |
|
1485 | - 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1486 | - 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
1487 | - 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1488 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1489 | - 'TKT_is_default_selector' => '', |
|
1490 | - 'ticket_price_rows' => '', |
|
1491 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1492 | - ? '' |
|
1493 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1494 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1495 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1496 | - ? '' |
|
1497 | - : ' style="display:none;"', |
|
1498 | - 'show_price_mod_button' => count($prices) > 1 |
|
1499 | - || ($default && $count_price_mods > 0) |
|
1500 | - || (! $default && $ticket->deleted()) |
|
1501 | - ? ' style="display:none;"' |
|
1502 | - : '', |
|
1503 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1504 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1505 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1506 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1507 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1508 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1509 | - 'TKT_taxable' => $TKT_taxable, |
|
1510 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1511 | - ? '' |
|
1512 | - : ' style="display:none"', |
|
1513 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1514 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1515 | - $ticket_subtotal, |
|
1516 | - false, |
|
1517 | - false |
|
1518 | - ), |
|
1519 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1520 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1521 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1522 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1523 | - ? ' ticket-archived' |
|
1524 | - : '', |
|
1525 | - 'trash_icon' => $ticket instanceof EE_Ticket |
|
1526 | - && $ticket->deleted() |
|
1527 | - && ! $ticket->is_permanently_deleteable() |
|
1528 | - ? 'ee-lock-icon ' |
|
1529 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1530 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1531 | - ? '' |
|
1532 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1533 | - ); |
|
1534 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1535 | - ? ' style="display:none"' |
|
1536 | - : ''; |
|
1537 | - //handle rows that should NOT be empty |
|
1538 | - if (empty($template_args['TKT_start_date'])) { |
|
1539 | - //if empty then the start date will be now. |
|
1540 | - $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
1541 | - current_time('timestamp')); |
|
1542 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1543 | - } |
|
1544 | - if (empty($template_args['TKT_end_date'])) { |
|
1545 | - //get the earliest datetime (if present); |
|
1546 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1547 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1548 | - 'Datetime', |
|
1549 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1550 | - ) |
|
1551 | - : null; |
|
1552 | - if (! empty($earliest_dtt)) { |
|
1553 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1554 | - 'DTT_EVT_start', |
|
1555 | - $this->_date_time_format |
|
1556 | - ); |
|
1557 | - } else { |
|
1558 | - //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1559 | - $template_args['TKT_end_date'] = date( |
|
1560 | - $this->_date_time_format, |
|
1561 | - mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
1562 | - ) |
|
1563 | - ); |
|
1564 | - } |
|
1565 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1566 | - } |
|
1567 | - //generate ticket_datetime items |
|
1568 | - if (! $default) { |
|
1569 | - $datetime_row = 1; |
|
1570 | - foreach ($all_datetimes as $datetime) { |
|
1571 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1572 | - $datetime_row, |
|
1573 | - $ticket_row, |
|
1574 | - $datetime, |
|
1575 | - $ticket, |
|
1576 | - $ticket_datetimes, |
|
1577 | - $default |
|
1578 | - ); |
|
1579 | - $datetime_row++; |
|
1580 | - } |
|
1581 | - } |
|
1582 | - $price_row = 1; |
|
1583 | - foreach ($prices as $price) { |
|
1584 | - if (! $price instanceof EE_Price) { |
|
1585 | - continue; |
|
1586 | - } |
|
1587 | - if ($price->is_base_price()) { |
|
1588 | - $price_row++; |
|
1589 | - continue; |
|
1590 | - } |
|
1591 | - $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1592 | - $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
1593 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1594 | - $ticket_row, |
|
1595 | - $price_row, |
|
1596 | - $price, |
|
1597 | - $default, |
|
1598 | - $ticket, |
|
1599 | - $show_trash, |
|
1600 | - $show_create |
|
1601 | - ); |
|
1602 | - $price_row++; |
|
1603 | - } |
|
1604 | - //filter $template_args |
|
1605 | - $template_args = apply_filters( |
|
1606 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1607 | - $template_args, |
|
1608 | - $ticket_row, |
|
1609 | - $ticket, |
|
1610 | - $ticket_datetimes, |
|
1611 | - $all_datetimes, |
|
1612 | - $default, |
|
1613 | - $all_tickets, |
|
1614 | - $this->_is_creating_event |
|
1615 | - ); |
|
1616 | - return EEH_Template::display_template( |
|
1617 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1618 | - $template_args, |
|
1619 | - true |
|
1620 | - ); |
|
1621 | - } |
|
1622 | - |
|
1623 | - |
|
1624 | - |
|
1625 | - /** |
|
1626 | - * @param int $ticket_row |
|
1627 | - * @param EE_Ticket|null $ticket |
|
1628 | - * @return string |
|
1629 | - * @throws DomainException |
|
1630 | - * @throws EE_Error |
|
1631 | - */ |
|
1632 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
1633 | - { |
|
1634 | - $tax_rows = ''; |
|
1635 | - /** @var EE_Price[] $taxes */ |
|
1636 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1637 | - foreach ($taxes as $tax) { |
|
1638 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1639 | - $template_args = array( |
|
1640 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1641 | - ? '' |
|
1642 | - : ' style="display:none;"', |
|
1643 | - 'tax_id' => $tax->ID(), |
|
1644 | - 'tkt_row' => $ticket_row, |
|
1645 | - 'tax_label' => $tax->get('PRC_name'), |
|
1646 | - 'tax_added' => $tax_added, |
|
1647 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1648 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
1649 | - ); |
|
1650 | - $template_args = apply_filters( |
|
1651 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1652 | - $template_args, |
|
1653 | - $ticket_row, |
|
1654 | - $ticket, |
|
1655 | - $this->_is_creating_event |
|
1656 | - ); |
|
1657 | - $tax_rows .= EEH_Template::display_template( |
|
1658 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1659 | - $template_args, |
|
1660 | - true |
|
1661 | - ); |
|
1662 | - } |
|
1663 | - return $tax_rows; |
|
1664 | - } |
|
1665 | - |
|
1666 | - |
|
1667 | - |
|
1668 | - /** |
|
1669 | - * @param EE_Price $tax |
|
1670 | - * @param EE_Ticket|null $ticket |
|
1671 | - * @return float|int |
|
1672 | - * @throws EE_Error |
|
1673 | - */ |
|
1674 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1675 | - { |
|
1676 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1677 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
1678 | - } |
|
1679 | - |
|
1680 | - |
|
1681 | - |
|
1682 | - /** |
|
1683 | - * @param int $ticket_row |
|
1684 | - * @param int $price_row |
|
1685 | - * @param EE_Price|null $price |
|
1686 | - * @param bool $default |
|
1687 | - * @param EE_Ticket|null $ticket |
|
1688 | - * @param bool $show_trash |
|
1689 | - * @param bool $show_create |
|
1690 | - * @return mixed |
|
1691 | - * @throws DomainException |
|
1692 | - * @throws EE_Error |
|
1693 | - */ |
|
1694 | - protected function _get_ticket_price_row( |
|
1695 | - $ticket_row, |
|
1696 | - $price_row, |
|
1697 | - $price, |
|
1698 | - $default, |
|
1699 | - $ticket, |
|
1700 | - $show_trash = true, |
|
1701 | - $show_create = true |
|
1702 | - ) { |
|
1703 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1704 | - $template_args = array( |
|
1705 | - 'tkt_row' => $default && empty($ticket) |
|
1706 | - ? 'TICKETNUM' |
|
1707 | - : $ticket_row, |
|
1708 | - 'PRC_order' => $default && empty($price) |
|
1709 | - ? 'PRICENUM' |
|
1710 | - : $price_row, |
|
1711 | - 'edit_prices_name' => $default && empty($price) |
|
1712 | - ? 'PRICENAMEATTR' |
|
1713 | - : 'edit_prices', |
|
1714 | - 'price_type_selector' => $default && empty($price) |
|
1715 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1716 | - : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
1717 | - 'PRC_ID' => $default && empty($price) |
|
1718 | - ? 0 |
|
1719 | - : $price->ID(), |
|
1720 | - 'PRC_is_default' => $default && empty($price) |
|
1721 | - ? 0 |
|
1722 | - : $price->get('PRC_is_default'), |
|
1723 | - 'PRC_name' => $default && empty($price) |
|
1724 | - ? '' |
|
1725 | - : $price->get('PRC_name'), |
|
1726 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1727 | - 'show_plus_or_minus' => $default && empty($price) |
|
1728 | - ? '' |
|
1729 | - : ' style="display:none;"', |
|
1730 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1731 | - ? ' style="display:none;"' |
|
1732 | - : '', |
|
1733 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1734 | - ? ' style="display:none;"' |
|
1735 | - : '', |
|
1736 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1737 | - ? ' style="display:none"' |
|
1738 | - : '', |
|
1739 | - 'PRC_amount' => $default && empty($price) |
|
1740 | - ? 0 |
|
1741 | - : $price->get_pretty('PRC_amount', |
|
1742 | - 'localized_float'), |
|
1743 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1744 | - ? ' style="display:none;"' |
|
1745 | - : '', |
|
1746 | - 'show_trash_icon' => $show_trash |
|
1747 | - ? '' |
|
1748 | - : ' style="display:none;"', |
|
1749 | - 'show_create_button' => $show_create |
|
1750 | - ? '' |
|
1751 | - : ' style="display:none;"', |
|
1752 | - 'PRC_desc' => $default && empty($price) |
|
1753 | - ? '' |
|
1754 | - : $price->get('PRC_desc'), |
|
1755 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1756 | - ); |
|
1757 | - $template_args = apply_filters( |
|
1758 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1759 | - $template_args, |
|
1760 | - $ticket_row, |
|
1761 | - $price_row, |
|
1762 | - $price, |
|
1763 | - $default, |
|
1764 | - $ticket, |
|
1765 | - $show_trash, |
|
1766 | - $show_create, |
|
1767 | - $this->_is_creating_event |
|
1768 | - ); |
|
1769 | - return EEH_Template::display_template( |
|
1770 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1771 | - $template_args, |
|
1772 | - true |
|
1773 | - ); |
|
1774 | - } |
|
1775 | - |
|
1776 | - |
|
1777 | - |
|
1778 | - /** |
|
1779 | - * @param int $ticket_row |
|
1780 | - * @param int $price_row |
|
1781 | - * @param EE_Price $price |
|
1782 | - * @param bool $default |
|
1783 | - * @param bool $disabled |
|
1784 | - * @return mixed |
|
1785 | - * @throws DomainException |
|
1786 | - * @throws EE_Error |
|
1787 | - */ |
|
1788 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1789 | - { |
|
1790 | - if ($price->is_base_price()) { |
|
1791 | - return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
1792 | - } |
|
1793 | - return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
1794 | - } |
|
1795 | - |
|
1796 | - |
|
1797 | - |
|
1798 | - /** |
|
1799 | - * @param int $ticket_row |
|
1800 | - * @param int $price_row |
|
1801 | - * @param EE_Price $price |
|
1802 | - * @param bool $default |
|
1803 | - * @return mixed |
|
1804 | - * @throws DomainException |
|
1805 | - * @throws EE_Error |
|
1806 | - */ |
|
1807 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1808 | - { |
|
1809 | - $template_args = array( |
|
1810 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1811 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1812 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1813 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1814 | - 'price_selected_operator' => '+', |
|
1815 | - 'price_selected_is_percent' => 0, |
|
1816 | - ); |
|
1817 | - $template_args = apply_filters( |
|
1818 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1819 | - $template_args, |
|
1820 | - $ticket_row, |
|
1821 | - $price_row, |
|
1822 | - $price, |
|
1823 | - $default, |
|
1824 | - $this->_is_creating_event |
|
1825 | - ); |
|
1826 | - return EEH_Template::display_template( |
|
1827 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1828 | - $template_args, |
|
1829 | - true |
|
1830 | - ); |
|
1831 | - } |
|
1832 | - |
|
1833 | - |
|
1834 | - |
|
1835 | - /** |
|
1836 | - * @param int $ticket_row |
|
1837 | - * @param int $price_row |
|
1838 | - * @param EE_Price $price |
|
1839 | - * @param bool $default |
|
1840 | - * @param bool $disabled |
|
1841 | - * @return mixed |
|
1842 | - * @throws DomainException |
|
1843 | - * @throws EE_Error |
|
1844 | - */ |
|
1845 | - protected function _get_price_modifier_template( |
|
1846 | - $ticket_row, |
|
1847 | - $price_row, |
|
1848 | - $price, |
|
1849 | - $default, |
|
1850 | - $disabled = false |
|
1851 | - ) { |
|
1852 | - $select_name = $default && ! $price instanceof EE_Price |
|
1853 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1854 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1855 | - /** @var EEM_Price_Type $price_type_model */ |
|
1856 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1857 | - $price_types = $price_type_model->get_all(array( |
|
1858 | - array( |
|
1859 | - 'OR' => array( |
|
1860 | - 'PBT_ID' => '2', |
|
1861 | - 'PBT_ID*' => '3', |
|
1862 | - ), |
|
1863 | - ), |
|
1864 | - )); |
|
1865 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
1866 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1867 | - : array(); |
|
1868 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1869 | - $price_option_spans = ''; |
|
1870 | - //setup price types for selector |
|
1871 | - foreach ($price_types as $price_type) { |
|
1872 | - if (! $price_type instanceof EE_Price_Type) { |
|
1873 | - continue; |
|
1874 | - } |
|
1875 | - $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
1876 | - //while we're in the loop let's setup the option spans used by js |
|
1877 | - $span_args = array( |
|
1878 | - 'PRT_ID' => $price_type->ID(), |
|
1879 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1880 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1881 | - ); |
|
1882 | - $price_option_spans .= EEH_Template::display_template( |
|
1883 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1884 | - $span_args, |
|
1885 | - true |
|
1886 | - ); |
|
1887 | - } |
|
1888 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1889 | - $select_input = new EE_Select_Input( |
|
1890 | - $all_price_types, |
|
1891 | - array( |
|
1892 | - 'default' => $selected_price_type_id, |
|
1893 | - 'html_name' => $select_name, |
|
1894 | - 'html_class' => 'edit-price-PRT_ID', |
|
1895 | - 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1896 | - ) |
|
1897 | - ); |
|
1898 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1899 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1900 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1901 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1902 | - $template_args = array( |
|
1903 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1904 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1905 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1906 | - 'main_name' => $select_name, |
|
1907 | - 'selected_price_type_id' => $selected_price_type_id, |
|
1908 | - 'price_option_spans' => $price_option_spans, |
|
1909 | - 'price_selected_operator' => $price_selected_operator, |
|
1910 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
1911 | - 'disabled' => $disabled, |
|
1912 | - ); |
|
1913 | - $template_args = apply_filters( |
|
1914 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1915 | - $template_args, |
|
1916 | - $ticket_row, |
|
1917 | - $price_row, |
|
1918 | - $price, |
|
1919 | - $default, |
|
1920 | - $disabled, |
|
1921 | - $this->_is_creating_event |
|
1922 | - ); |
|
1923 | - return EEH_Template::display_template( |
|
1924 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1925 | - $template_args, |
|
1926 | - true |
|
1927 | - ); |
|
1928 | - } |
|
1929 | - |
|
1930 | - |
|
1931 | - |
|
1932 | - /** |
|
1933 | - * @param int $datetime_row |
|
1934 | - * @param int $ticket_row |
|
1935 | - * @param EE_Datetime|null $datetime |
|
1936 | - * @param EE_Ticket|null $ticket |
|
1937 | - * @param array $ticket_datetimes |
|
1938 | - * @param bool $default |
|
1939 | - * @return mixed |
|
1940 | - * @throws DomainException |
|
1941 | - * @throws EE_Error |
|
1942 | - */ |
|
1943 | - protected function _get_ticket_datetime_list_item( |
|
1944 | - $datetime_row, |
|
1945 | - $ticket_row, |
|
1946 | - $datetime, |
|
1947 | - $ticket, |
|
1948 | - $ticket_datetimes = array(), |
|
1949 | - $default |
|
1950 | - ) { |
|
1951 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1952 | - ? $ticket_datetimes[$ticket->ID()] |
|
1953 | - : array(); |
|
1954 | - $template_args = array( |
|
1955 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
1956 | - ? 'DTTNUM' |
|
1957 | - : $datetime_row, |
|
1958 | - 'tkt_row' => $default |
|
1959 | - ? 'TICKETNUM' |
|
1960 | - : $ticket_row, |
|
1961 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
1962 | - ? ' ticket-selected' |
|
1963 | - : '', |
|
1964 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
1965 | - ? ' checked="checked"' |
|
1966 | - : '', |
|
1967 | - 'DTT_name' => $default && empty($datetime) |
|
1968 | - ? 'DTTNAME' |
|
1969 | - : $datetime->get_dtt_display_name(true), |
|
1970 | - 'tkt_status_class' => '', |
|
1971 | - ); |
|
1972 | - $template_args = apply_filters( |
|
1973 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
1974 | - $template_args, |
|
1975 | - $datetime_row, |
|
1976 | - $ticket_row, |
|
1977 | - $datetime, |
|
1978 | - $ticket, |
|
1979 | - $ticket_datetimes, |
|
1980 | - $default, |
|
1981 | - $this->_is_creating_event |
|
1982 | - ); |
|
1983 | - return EEH_Template::display_template( |
|
1984 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1985 | - $template_args, |
|
1986 | - true |
|
1987 | - ); |
|
1988 | - } |
|
1989 | - |
|
1990 | - |
|
1991 | - |
|
1992 | - /** |
|
1993 | - * @param array $all_datetimes |
|
1994 | - * @param array $all_tickets |
|
1995 | - * @return mixed |
|
1996 | - * @throws DomainException |
|
1997 | - * @throws EE_Error |
|
1998 | - */ |
|
1999 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2000 | - { |
|
2001 | - $template_args = array( |
|
2002 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2003 | - 'DTTNUM', |
|
2004 | - null, |
|
2005 | - true, |
|
2006 | - $all_datetimes |
|
2007 | - ), |
|
2008 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
2009 | - 'TICKETNUM', |
|
2010 | - null, |
|
2011 | - array(), |
|
2012 | - array(), |
|
2013 | - true |
|
2014 | - ), |
|
2015 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
2016 | - 'TICKETNUM', |
|
2017 | - 'PRICENUM', |
|
2018 | - null, |
|
2019 | - true, |
|
2020 | - null |
|
2021 | - ), |
|
2022 | - 'default_price_rows' => '', |
|
2023 | - 'default_base_price_amount' => 0, |
|
2024 | - 'default_base_price_name' => '', |
|
2025 | - 'default_base_price_description' => '', |
|
2026 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2027 | - 'TICKETNUM', |
|
2028 | - 'PRICENUM', |
|
2029 | - null, |
|
2030 | - true |
|
2031 | - ), |
|
2032 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2033 | - 'DTTNUM', |
|
2034 | - null, |
|
2035 | - array(), |
|
2036 | - array(), |
|
2037 | - true |
|
2038 | - ), |
|
2039 | - 'existing_available_datetime_tickets_list' => '', |
|
2040 | - 'existing_available_ticket_datetimes_list' => '', |
|
2041 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2042 | - 'DTTNUM', |
|
2043 | - 'TICKETNUM', |
|
2044 | - null, |
|
2045 | - null, |
|
2046 | - array(), |
|
2047 | - true |
|
2048 | - ), |
|
2049 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2050 | - 'DTTNUM', |
|
2051 | - 'TICKETNUM', |
|
2052 | - null, |
|
2053 | - null, |
|
2054 | - array(), |
|
2055 | - true |
|
2056 | - ), |
|
2057 | - ); |
|
2058 | - $ticket_row = 1; |
|
2059 | - foreach ($all_tickets as $ticket) { |
|
2060 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2061 | - 'DTTNUM', |
|
2062 | - $ticket_row, |
|
2063 | - null, |
|
2064 | - $ticket, |
|
2065 | - array(), |
|
2066 | - true |
|
2067 | - ); |
|
2068 | - $ticket_row++; |
|
2069 | - } |
|
2070 | - $datetime_row = 1; |
|
2071 | - foreach ($all_datetimes as $datetime) { |
|
2072 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2073 | - $datetime_row, |
|
2074 | - 'TICKETNUM', |
|
2075 | - $datetime, |
|
2076 | - null, |
|
2077 | - array(), |
|
2078 | - true |
|
2079 | - ); |
|
2080 | - $datetime_row++; |
|
2081 | - } |
|
2082 | - /** @var EEM_Price $price_model */ |
|
2083 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
2084 | - $default_prices = $price_model->get_all_default_prices(); |
|
2085 | - $price_row = 1; |
|
2086 | - foreach ($default_prices as $price) { |
|
2087 | - if (! $price instanceof EE_Price) { |
|
2088 | - continue; |
|
2089 | - } |
|
2090 | - if ($price->is_base_price()) { |
|
2091 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2092 | - 'PRC_amount', |
|
2093 | - 'localized_float' |
|
2094 | - ); |
|
2095 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2096 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2097 | - $price_row++; |
|
2098 | - continue; |
|
2099 | - } |
|
2100 | - $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2101 | - $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2102 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2103 | - 'TICKETNUM', |
|
2104 | - $price_row, |
|
2105 | - $price, |
|
2106 | - true, |
|
2107 | - null, |
|
2108 | - $show_trash, |
|
2109 | - $show_create |
|
2110 | - ); |
|
2111 | - $price_row++; |
|
2112 | - } |
|
2113 | - $template_args = apply_filters( |
|
2114 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2115 | - $template_args, |
|
2116 | - $all_datetimes, |
|
2117 | - $all_tickets, |
|
2118 | - $this->_is_creating_event |
|
2119 | - ); |
|
2120 | - return EEH_Template::display_template( |
|
2121 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2122 | - $template_args, |
|
2123 | - true |
|
2124 | - ); |
|
2125 | - } |
|
18 | + /** |
|
19 | + * This property is just used to hold the status of whether an event is currently being |
|
20 | + * created (true) or edited (false) |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $_is_creating_event; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Used to contain the format strings for date and time that will be used for php date and |
|
30 | + * time. |
|
31 | + * Is set in the _set_hooks_properties() method. |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $_date_format_strings; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string $_date_time_format |
|
40 | + */ |
|
41 | + protected $_date_time_format; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * |
|
47 | + */ |
|
48 | + protected function _set_hooks_properties() |
|
49 | + { |
|
50 | + $this->_name = 'pricing'; |
|
51 | + //capability check |
|
52 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
53 | + 'ee_read_default_prices', |
|
54 | + 'advanced_ticket_datetime_metabox' |
|
55 | + )) { |
|
56 | + return; |
|
57 | + } |
|
58 | + $this->_setup_metaboxes(); |
|
59 | + $this->_set_date_time_formats(); |
|
60 | + $this->_validate_format_strings(); |
|
61 | + $this->_set_scripts_styles(); |
|
62 | + // commented out temporarily until logic is implemented in callback |
|
63 | + // add_action( |
|
64 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
65 | + // array($this, 'autosave_handling') |
|
66 | + // ); |
|
67 | + add_filter( |
|
68 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
69 | + array($this, 'caf_updates') |
|
70 | + ); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + protected function _setup_metaboxes() |
|
79 | + { |
|
80 | + //if we were going to add our own metaboxes we'd use the below. |
|
81 | + $this->_metaboxes = array( |
|
82 | + 0 => array( |
|
83 | + 'page_route' => array('edit', 'create_new'), |
|
84 | + 'func' => 'pricing_metabox', |
|
85 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
86 | + 'priority' => 'high', |
|
87 | + 'context' => 'normal', |
|
88 | + ), |
|
89 | + ); |
|
90 | + $this->_remove_metaboxes = array( |
|
91 | + 0 => array( |
|
92 | + 'page_route' => array('edit', 'create_new'), |
|
93 | + 'id' => 'espresso_event_editor_tickets', |
|
94 | + 'context' => 'normal', |
|
95 | + ), |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + protected function _set_date_time_formats() |
|
105 | + { |
|
106 | + /** |
|
107 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
108 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
109 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
110 | + * |
|
111 | + * @since 4.6.7 |
|
112 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
113 | + */ |
|
114 | + $this->_date_format_strings = apply_filters( |
|
115 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
116 | + array( |
|
117 | + 'date' => 'Y-m-d', |
|
118 | + 'time' => 'h:i a', |
|
119 | + ) |
|
120 | + ); |
|
121 | + //validate |
|
122 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
123 | + ? $this->_date_format_strings['date'] |
|
124 | + : null; |
|
125 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
126 | + ? $this->_date_format_strings['time'] |
|
127 | + : null; |
|
128 | + $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + protected function _validate_format_strings() |
|
137 | + { |
|
138 | + //validate format strings |
|
139 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
140 | + $this->_date_time_format |
|
141 | + ); |
|
142 | + if (is_array($format_validation)) { |
|
143 | + $msg = '<p>'; |
|
144 | + $msg .= sprintf( |
|
145 | + esc_html__( |
|
146 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
147 | + 'event_espresso' |
|
148 | + ), |
|
149 | + $this->_date_time_format |
|
150 | + ); |
|
151 | + $msg .= '</p><ul>'; |
|
152 | + foreach ($format_validation as $error) { |
|
153 | + $msg .= '<li>' . $error . '</li>'; |
|
154 | + } |
|
155 | + $msg .= '</ul><p>'; |
|
156 | + $msg .= sprintf( |
|
157 | + esc_html__( |
|
158 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
159 | + 'event_espresso' |
|
160 | + ), |
|
161 | + '<span style="color:#D54E21;">', |
|
162 | + '</span>' |
|
163 | + ); |
|
164 | + $msg .= '</p>'; |
|
165 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
166 | + $this->_date_format_strings = array( |
|
167 | + 'date' => 'Y-m-d', |
|
168 | + 'time' => 'h:i a', |
|
169 | + ); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @return void |
|
177 | + */ |
|
178 | + protected function _set_scripts_styles() |
|
179 | + { |
|
180 | + $this->_scripts_styles = array( |
|
181 | + 'registers' => array( |
|
182 | + 'ee-tickets-datetimes-css' => array( |
|
183 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
184 | + 'type' => 'css', |
|
185 | + ), |
|
186 | + 'ee-dtt-ticket-metabox' => array( |
|
187 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
188 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
189 | + ), |
|
190 | + ), |
|
191 | + 'deregisters' => array( |
|
192 | + 'event-editor-css' => array('type' => 'css'), |
|
193 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
194 | + ), |
|
195 | + 'enqueues' => array( |
|
196 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
197 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
198 | + ), |
|
199 | + 'localize' => array( |
|
200 | + 'ee-dtt-ticket-metabox' => array( |
|
201 | + 'DTT_TRASH_BLOCK' => array( |
|
202 | + 'main_warning' => esc_html__( |
|
203 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
204 | + 'event_espresso' |
|
205 | + ), |
|
206 | + 'after_warning' => esc_html__( |
|
207 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
208 | + 'event_espresso' |
|
209 | + ), |
|
210 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
211 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
212 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
213 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
214 | + 'single_warning_from_tkt' => esc_html__( |
|
215 | + 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
216 | + 'event_espresso' |
|
217 | + ), |
|
218 | + 'single_warning_from_dtt' => esc_html__( |
|
219 | + 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
220 | + 'event_espresso' |
|
221 | + ), |
|
222 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
223 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
224 | + ), |
|
225 | + 'DTT_ERROR_MSG' => array( |
|
226 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
227 | + 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
228 | + . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
229 | + ), |
|
230 | + 'DTT_OVERSELL_WARNING' => array( |
|
231 | + 'datetime_ticket' => esc_html__( |
|
232 | + 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
233 | + 'event_espresso' |
|
234 | + ), |
|
235 | + 'ticket_datetime' => esc_html__( |
|
236 | + 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
237 | + 'event_espresso' |
|
238 | + ), |
|
239 | + ), |
|
240 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
241 | + $this->_date_format_strings['date'], |
|
242 | + $this->_date_format_strings['time'] |
|
243 | + ), |
|
244 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
245 | + ), |
|
246 | + ), |
|
247 | + ); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param array $update_callbacks |
|
254 | + * @return array |
|
255 | + */ |
|
256 | + public function caf_updates(array $update_callbacks) |
|
257 | + { |
|
258 | + foreach ($update_callbacks as $key => $callback) { |
|
259 | + if ($callback[1] === '_default_tickets_update') { |
|
260 | + unset($update_callbacks[$key]); |
|
261 | + } |
|
262 | + } |
|
263 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
264 | + return $update_callbacks; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
270 | + * |
|
271 | + * @param EE_Event $event The Event object we're attaching data to |
|
272 | + * @param array $data The request data from the form |
|
273 | + * @throws EE_Error |
|
274 | + * @throws InvalidArgumentException |
|
275 | + */ |
|
276 | + public function datetime_and_tickets_caf_update($event, $data) |
|
277 | + { |
|
278 | + //first we need to start with datetimes cause they are the "root" items attached to events. |
|
279 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
280 | + //next tackle the tickets (and prices?) |
|
281 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * update event_datetimes |
|
287 | + * |
|
288 | + * @param EE_Event $event Event being updated |
|
289 | + * @param array $data the request data from the form |
|
290 | + * @return EE_Datetime[] |
|
291 | + * @throws InvalidArgumentException |
|
292 | + * @throws EE_Error |
|
293 | + */ |
|
294 | + protected function _update_datetimes($event, $data) |
|
295 | + { |
|
296 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
297 | + $saved_dtt_ids = array(); |
|
298 | + $saved_dtt_objs = array(); |
|
299 | + if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
300 | + throw new InvalidArgumentException( |
|
301 | + esc_html__( |
|
302 | + 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
303 | + 'event_espresso' |
|
304 | + ) |
|
305 | + ); |
|
306 | + } |
|
307 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
308 | + //trim all values to ensure any excess whitespace is removed. |
|
309 | + $datetime_data = array_map( |
|
310 | + function ($datetime_data) { |
|
311 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
312 | + }, |
|
313 | + $datetime_data |
|
314 | + ); |
|
315 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
316 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
317 | + ? $datetime_data['DTT_EVT_end'] |
|
318 | + : $datetime_data['DTT_EVT_start']; |
|
319 | + $datetime_values = array( |
|
320 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
321 | + ? $datetime_data['DTT_ID'] |
|
322 | + : null, |
|
323 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
324 | + ? $datetime_data['DTT_name'] |
|
325 | + : '', |
|
326 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
327 | + ? $datetime_data['DTT_description'] |
|
328 | + : '', |
|
329 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
330 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
331 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
332 | + ? EE_INF |
|
333 | + : $datetime_data['DTT_reg_limit'], |
|
334 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
335 | + ? $row |
|
336 | + : $datetime_data['DTT_order'], |
|
337 | + ); |
|
338 | + // if we have an id then let's get existing object first and then set the new values. |
|
339 | + // Otherwise we instantiate a new object for save. |
|
340 | + if (! empty($datetime_data['DTT_ID'])) { |
|
341 | + $datetime = EE_Registry::instance() |
|
342 | + ->load_model('Datetime', array($timezone)) |
|
343 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
344 | + //set date and time format according to what is set in this class. |
|
345 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
346 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
347 | + foreach ($datetime_values as $field => $value) { |
|
348 | + $datetime->set($field, $value); |
|
349 | + } |
|
350 | + // make sure the $dtt_id here is saved just in case |
|
351 | + // after the add_relation_to() the autosave replaces it. |
|
352 | + // We need to do this so we dont' TRASH the parent DTT. |
|
353 | + // (save the ID for both key and value to avoid duplications) |
|
354 | + $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
355 | + } else { |
|
356 | + $datetime = EE_Registry::instance()->load_class( |
|
357 | + 'Datetime', |
|
358 | + array( |
|
359 | + $datetime_values, |
|
360 | + $timezone, |
|
361 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
362 | + ), |
|
363 | + false, |
|
364 | + false |
|
365 | + ); |
|
366 | + foreach ($datetime_values as $field => $value) { |
|
367 | + $datetime->set($field, $value); |
|
368 | + } |
|
369 | + } |
|
370 | + $datetime->save(); |
|
371 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
372 | + // before going any further make sure our dates are setup correctly |
|
373 | + // so that the end date is always equal or greater than the start date. |
|
374 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
375 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
376 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
377 | + $datetime->save(); |
|
378 | + } |
|
379 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
380 | + // because it is possible there was a new one created for the autosave. |
|
381 | + // (save the ID for both key and value to avoid duplications) |
|
382 | + $DTT_ID = $datetime->ID(); |
|
383 | + $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
384 | + $saved_dtt_objs[$row] = $datetime; |
|
385 | + //todo if ANY of these updates fail then we want the appropriate global error message. |
|
386 | + } |
|
387 | + $event->save(); |
|
388 | + // now we need to REMOVE any datetimes that got deleted. |
|
389 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
390 | + // So its safe to permanently delete at this point. |
|
391 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
392 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
393 | + if (is_array($old_datetimes)) { |
|
394 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
395 | + foreach ($datetimes_to_delete as $id) { |
|
396 | + $id = absint($id); |
|
397 | + if (empty($id)) { |
|
398 | + continue; |
|
399 | + } |
|
400 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
401 | + //remove tkt relationships. |
|
402 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
403 | + foreach ($related_tickets as $tkt) { |
|
404 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
405 | + } |
|
406 | + $event->_remove_relation_to($id, 'Datetime'); |
|
407 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
408 | + } |
|
409 | + } |
|
410 | + return $saved_dtt_objs; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * update tickets |
|
416 | + * |
|
417 | + * @param EE_Event $event Event object being updated |
|
418 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
419 | + * @param array $data incoming request data |
|
420 | + * @return EE_Ticket[] |
|
421 | + * @throws InvalidArgumentException |
|
422 | + * @throws EE_Error |
|
423 | + */ |
|
424 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
425 | + { |
|
426 | + $new_tkt = null; |
|
427 | + $new_default = null; |
|
428 | + //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
429 | + $data = stripslashes_deep($data); |
|
430 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
431 | + $saved_tickets = $datetimes_on_existing = array(); |
|
432 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
433 | + if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
434 | + throw new InvalidArgumentException( |
|
435 | + esc_html__( |
|
436 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
437 | + 'event_espresso' |
|
438 | + ) |
|
439 | + ); |
|
440 | + } |
|
441 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
442 | + $update_prices = $create_new_TKT = false; |
|
443 | + // figure out what datetimes were added to the ticket |
|
444 | + // and what datetimes were removed from the ticket in the session. |
|
445 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
446 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
447 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
448 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
449 | + // trim inputs to ensure any excess whitespace is removed. |
|
450 | + $tkt = array_map( |
|
451 | + function ($ticket_data) { |
|
452 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
453 | + }, |
|
454 | + $tkt |
|
455 | + ); |
|
456 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
457 | + // because we're doing calculations prior to using the models. |
|
458 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
459 | + $ticket_price = isset($tkt['TKT_price']) |
|
460 | + ? round((float)$tkt['TKT_price'], 3) |
|
461 | + : 0; |
|
462 | + //note incoming base price needs converted from localized value. |
|
463 | + $base_price = isset($tkt['TKT_base_price']) |
|
464 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
465 | + : 0; |
|
466 | + //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
467 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
468 | + ? $base_price |
|
469 | + : $ticket_price; |
|
470 | + $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
471 | + ? $tkt['TKT_base_price_ID'] |
|
472 | + : 0; |
|
473 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
474 | + ? $data['edit_prices'][$row] |
|
475 | + : array(); |
|
476 | + $now = null; |
|
477 | + if (empty($tkt['TKT_start_date'])) { |
|
478 | + //lets' use now in the set timezone. |
|
479 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
480 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
481 | + } |
|
482 | + if (empty($tkt['TKT_end_date'])) { |
|
483 | + /** |
|
484 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
485 | + */ |
|
486 | + $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
487 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
488 | + } |
|
489 | + $TKT_values = array( |
|
490 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
491 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
492 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
493 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
494 | + && $tkt['TKT_description'] !== esc_html__( |
|
495 | + 'You can modify this description', |
|
496 | + 'event_espresso' |
|
497 | + ) |
|
498 | + ? $tkt['TKT_description'] |
|
499 | + : '', |
|
500 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
501 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
502 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
503 | + ? EE_INF |
|
504 | + : $tkt['TKT_qty'], |
|
505 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
506 | + ? EE_INF |
|
507 | + : $tkt['TKT_uses'], |
|
508 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
509 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
510 | + 'TKT_row' => $row, |
|
511 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
512 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
513 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
514 | + 'TKT_price' => $ticket_price, |
|
515 | + ); |
|
516 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
517 | + // which means in turn that the prices will become new prices as well. |
|
518 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
519 | + $TKT_values['TKT_ID'] = 0; |
|
520 | + $TKT_values['TKT_is_default'] = 0; |
|
521 | + $update_prices = true; |
|
522 | + } |
|
523 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
524 | + // we actually do our saves ahead of doing any add_relations to |
|
525 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
526 | + // but DID have it's items modified. |
|
527 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
528 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
529 | + if (absint($TKT_values['TKT_ID'])) { |
|
530 | + $ticket = EE_Registry::instance() |
|
531 | + ->load_model('Ticket', array($timezone)) |
|
532 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
533 | + if ($ticket instanceof EE_Ticket) { |
|
534 | + $ticket = $this->_update_ticket_datetimes( |
|
535 | + $ticket, |
|
536 | + $saved_datetimes, |
|
537 | + $datetimes_added, |
|
538 | + $datetimes_removed |
|
539 | + ); |
|
540 | + // are there any registrations using this ticket ? |
|
541 | + $tickets_sold = $ticket->count_related( |
|
542 | + 'Registration', |
|
543 | + array( |
|
544 | + array( |
|
545 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
546 | + ), |
|
547 | + ) |
|
548 | + ); |
|
549 | + //set ticket formats |
|
550 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
551 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
552 | + // let's just check the total price for the existing ticket |
|
553 | + // and determine if it matches the new total price. |
|
554 | + // if they are different then we create a new ticket (if tickets sold) |
|
555 | + // if they aren't different then we go ahead and modify existing ticket. |
|
556 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
557 | + //set new values |
|
558 | + foreach ($TKT_values as $field => $value) { |
|
559 | + if ($field === 'TKT_qty') { |
|
560 | + $ticket->set_qty($value); |
|
561 | + } else { |
|
562 | + $ticket->set($field, $value); |
|
563 | + } |
|
564 | + } |
|
565 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
566 | + // Otherwise we have to create a new ticket. |
|
567 | + if ($create_new_TKT) { |
|
568 | + $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
569 | + $base_price_id); |
|
570 | + } |
|
571 | + } |
|
572 | + } else { |
|
573 | + // no TKT_id so a new TKT |
|
574 | + $ticket = EE_Ticket::new_instance( |
|
575 | + $TKT_values, |
|
576 | + $timezone, |
|
577 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
578 | + ); |
|
579 | + if ($ticket instanceof EE_Ticket) { |
|
580 | + // make sure ticket has an ID of setting relations won't work |
|
581 | + $ticket->save(); |
|
582 | + $ticket = $this->_update_ticket_datetimes( |
|
583 | + $ticket, |
|
584 | + $saved_datetimes, |
|
585 | + $datetimes_added, |
|
586 | + $datetimes_removed |
|
587 | + ); |
|
588 | + $update_prices = true; |
|
589 | + } |
|
590 | + } |
|
591 | + //make sure any current values have been saved. |
|
592 | + //$ticket->save(); |
|
593 | + // before going any further make sure our dates are setup correctly |
|
594 | + // so that the end date is always equal or greater than the start date. |
|
595 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
596 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
597 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
598 | + } |
|
599 | + //let's make sure the base price is handled |
|
600 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
601 | + $base_price_id) : $ticket; |
|
602 | + //add/update price_modifiers |
|
603 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
604 | + //need to make sue that the TKT_price is accurate after saving the prices. |
|
605 | + $ticket->ensure_TKT_Price_correct(); |
|
606 | + //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
607 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
608 | + $update_prices = true; |
|
609 | + $new_default = clone $ticket; |
|
610 | + $new_default->set('TKT_ID', 0); |
|
611 | + $new_default->set('TKT_is_default', 1); |
|
612 | + $new_default->set('TKT_row', 1); |
|
613 | + $new_default->set('TKT_price', $ticket_price); |
|
614 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
615 | + // (note this is just removing the cached relations in the object) |
|
616 | + $new_default->_remove_relations('Datetime'); |
|
617 | + //todo we need to add the current attached prices as new prices to the new default ticket. |
|
618 | + $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
619 | + //don't forget the base price! |
|
620 | + $new_default = $this->_add_prices_to_ticket( |
|
621 | + array(), |
|
622 | + $new_default, |
|
623 | + $update_prices, |
|
624 | + $base_price, |
|
625 | + $base_price_id |
|
626 | + ); |
|
627 | + $new_default->save(); |
|
628 | + do_action( |
|
629 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
630 | + $new_default, |
|
631 | + $row, |
|
632 | + $ticket, |
|
633 | + $data |
|
634 | + ); |
|
635 | + } |
|
636 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
637 | + // for the given dtt that are related to the current ticket. |
|
638 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
639 | + // what current ticket the archived tickets are related to |
|
640 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
641 | + //let's assign any tickets that have been setup to the saved_tickets tracker |
|
642 | + //save existing TKT |
|
643 | + $ticket->save(); |
|
644 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
645 | + //save new TKT |
|
646 | + $new_tkt->save(); |
|
647 | + //add new ticket to array |
|
648 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
649 | + do_action( |
|
650 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
651 | + $new_tkt, |
|
652 | + $row, |
|
653 | + $tkt, |
|
654 | + $data |
|
655 | + ); |
|
656 | + } else { |
|
657 | + //add tkt to saved tkts |
|
658 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
659 | + do_action( |
|
660 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
661 | + $ticket, |
|
662 | + $row, |
|
663 | + $tkt, |
|
664 | + $data |
|
665 | + ); |
|
666 | + } |
|
667 | + } |
|
668 | + // now we need to handle tickets actually "deleted permanently". |
|
669 | + // There are cases where we'd want this to happen |
|
670 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
671 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
672 | + // No sense in keeping all the related data in the db! |
|
673 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
674 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
675 | + foreach ($tickets_removed as $id) { |
|
676 | + $id = absint($id); |
|
677 | + //get the ticket for this id |
|
678 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
679 | + //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
680 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
681 | + continue; |
|
682 | + } |
|
683 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
684 | + // because we don't actually permanently delete these tickets. |
|
685 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
686 | + $tkt_to_remove->delete(); |
|
687 | + continue; |
|
688 | + } |
|
689 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
690 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
691 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
692 | + foreach ($datetimes as $datetime) { |
|
693 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
694 | + } |
|
695 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
696 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
697 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
698 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
699 | + // finally let's delete this ticket |
|
700 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
701 | + $tkt_to_remove->delete_permanently(); |
|
702 | + } |
|
703 | + return $saved_tickets; |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * @access protected |
|
710 | + * @param \EE_Ticket $ticket |
|
711 | + * @param \EE_Datetime[] $saved_datetimes |
|
712 | + * @param \EE_Datetime[] $added_datetimes |
|
713 | + * @param \EE_Datetime[] $removed_datetimes |
|
714 | + * @return \EE_Ticket |
|
715 | + * @throws \EE_Error |
|
716 | + */ |
|
717 | + protected function _update_ticket_datetimes( |
|
718 | + EE_Ticket $ticket, |
|
719 | + $saved_datetimes = array(), |
|
720 | + $added_datetimes = array(), |
|
721 | + $removed_datetimes = array() |
|
722 | + ) { |
|
723 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
724 | + // and removing the ticket from datetimes it got removed from. |
|
725 | + // first let's add datetimes |
|
726 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
727 | + foreach ($added_datetimes as $row_id) { |
|
728 | + $row_id = (int)$row_id; |
|
729 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
730 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
731 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
732 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
733 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
734 | + $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
735 | + $saved_datetimes[$row_id]->save(); |
|
736 | + } |
|
737 | + } |
|
738 | + } |
|
739 | + } |
|
740 | + // then remove datetimes |
|
741 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
742 | + foreach ($removed_datetimes as $row_id) { |
|
743 | + $row_id = (int)$row_id; |
|
744 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
745 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
746 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
747 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
748 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
749 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
750 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
751 | + $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
752 | + $saved_datetimes[$row_id]->save(); |
|
753 | + } |
|
754 | + } |
|
755 | + } |
|
756 | + } |
|
757 | + // cap ticket qty by datetime reg limits |
|
758 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
759 | + return $ticket; |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + |
|
764 | + /** |
|
765 | + * @access protected |
|
766 | + * @param \EE_Ticket $ticket |
|
767 | + * @param array $price_rows |
|
768 | + * @param int $ticket_price |
|
769 | + * @param int $base_price |
|
770 | + * @param int $base_price_id |
|
771 | + * @return \EE_Ticket |
|
772 | + * @throws \EE_Error |
|
773 | + */ |
|
774 | + protected function _duplicate_ticket( |
|
775 | + EE_Ticket $ticket, |
|
776 | + $price_rows = array(), |
|
777 | + $ticket_price = 0, |
|
778 | + $base_price = 0, |
|
779 | + $base_price_id = 0 |
|
780 | + ) { |
|
781 | + // create new ticket that's a copy of the existing |
|
782 | + // except a new id of course (and not archived) |
|
783 | + // AND has the new TKT_price associated with it. |
|
784 | + $new_ticket = clone $ticket; |
|
785 | + $new_ticket->set('TKT_ID', 0); |
|
786 | + $new_ticket->set_deleted(0); |
|
787 | + $new_ticket->set_price($ticket_price); |
|
788 | + $new_ticket->set_sold(0); |
|
789 | + // let's get a new ID for this ticket |
|
790 | + $new_ticket->save(); |
|
791 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
792 | + $datetimes_on_existing = $ticket->datetimes(); |
|
793 | + $new_ticket = $this->_update_ticket_datetimes( |
|
794 | + $new_ticket, |
|
795 | + $datetimes_on_existing, |
|
796 | + array_keys($datetimes_on_existing) |
|
797 | + ); |
|
798 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
799 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
800 | + // available. |
|
801 | + if ($ticket->sold() > 0) { |
|
802 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
803 | + $new_ticket->set_qty($new_qty); |
|
804 | + } |
|
805 | + //now we update the prices just for this ticket |
|
806 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
807 | + //and we update the base price |
|
808 | + $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
809 | + return $new_ticket; |
|
810 | + } |
|
811 | + |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * This attaches a list of given prices to a ticket. |
|
816 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
817 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
818 | + * price info and prices are automatically "archived" via the ticket. |
|
819 | + * |
|
820 | + * @access private |
|
821 | + * @param array $prices Array of prices from the form. |
|
822 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
823 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
824 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
825 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
826 | + * @return EE_Ticket |
|
827 | + * @throws EE_Error |
|
828 | + */ |
|
829 | + protected function _add_prices_to_ticket( |
|
830 | + $prices = array(), |
|
831 | + EE_Ticket $ticket, |
|
832 | + $new_prices = false, |
|
833 | + $base_price = false, |
|
834 | + $base_price_id = false |
|
835 | + ) { |
|
836 | + // let's just get any current prices that may exist on the given ticket |
|
837 | + // so we can remove any prices that got trashed in this session. |
|
838 | + $current_prices_on_ticket = $base_price !== false |
|
839 | + ? $ticket->base_price(true) |
|
840 | + : $ticket->price_modifiers(); |
|
841 | + $updated_prices = array(); |
|
842 | + // if $base_price ! FALSE then updating a base price. |
|
843 | + if ($base_price !== false) { |
|
844 | + $prices[1] = array( |
|
845 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
846 | + 'PRT_ID' => 1, |
|
847 | + 'PRC_amount' => $base_price, |
|
848 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
849 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
850 | + ); |
|
851 | + } |
|
852 | + //possibly need to save tkt |
|
853 | + if (! $ticket->ID()) { |
|
854 | + $ticket->save(); |
|
855 | + } |
|
856 | + foreach ($prices as $row => $prc) { |
|
857 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
858 | + if (empty($prt_id)) { |
|
859 | + continue; |
|
860 | + } //prices MUST have a price type id. |
|
861 | + $PRC_values = array( |
|
862 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
863 | + 'PRT_ID' => $prt_id, |
|
864 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
865 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
866 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
867 | + 'PRC_is_default' => false, |
|
868 | + //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
869 | + 'PRC_order' => $row, |
|
870 | + ); |
|
871 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
872 | + $PRC_values['PRC_ID'] = 0; |
|
873 | + $price = EE_Registry::instance()->load_class( |
|
874 | + 'Price', |
|
875 | + array($PRC_values), |
|
876 | + false, |
|
877 | + false |
|
878 | + ); |
|
879 | + } else { |
|
880 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
881 | + //update this price with new values |
|
882 | + foreach ($PRC_values as $field => $value) { |
|
883 | + $price->set($field, $value); |
|
884 | + } |
|
885 | + } |
|
886 | + $price->save(); |
|
887 | + $updated_prices[$price->ID()] = $price; |
|
888 | + $ticket->_add_relation_to($price, 'Price'); |
|
889 | + } |
|
890 | + //now let's remove any prices that got removed from the ticket |
|
891 | + if (! empty ($current_prices_on_ticket)) { |
|
892 | + $current = array_keys($current_prices_on_ticket); |
|
893 | + $updated = array_keys($updated_prices); |
|
894 | + $prices_to_remove = array_diff($current, $updated); |
|
895 | + if (! empty($prices_to_remove)) { |
|
896 | + foreach ($prices_to_remove as $prc_id) { |
|
897 | + $p = $current_prices_on_ticket[$prc_id]; |
|
898 | + $ticket->_remove_relation_to($p, 'Price'); |
|
899 | + //delete permanently the price |
|
900 | + $p->delete_permanently(); |
|
901 | + } |
|
902 | + } |
|
903 | + } |
|
904 | + return $ticket; |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * @param Events_Admin_Page $event_admin_obj |
|
911 | + * @return Events_Admin_Page |
|
912 | + */ |
|
913 | + public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
914 | + { |
|
915 | + return $event_admin_obj; |
|
916 | + //doing nothing for the moment. |
|
917 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
918 | + // (use the set_template_args() method) |
|
919 | + /** |
|
920 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
921 | + * 1. TKT_is_default_selector (visible) |
|
922 | + * 2. TKT_is_default (hidden) |
|
923 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
924 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
925 | + * this ticket to be saved as a default. |
|
926 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
927 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
928 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
929 | + * the TKT HAS been saved as a default.. |
|
930 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
931 | + * On Autosave: |
|
932 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
933 | + * then set the TKT_is_default to false. |
|
934 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
935 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
936 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
937 | + */ |
|
938 | + } |
|
939 | + |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * @throws DomainException |
|
944 | + * @throws EE_Error |
|
945 | + */ |
|
946 | + public function pricing_metabox() |
|
947 | + { |
|
948 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
949 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
950 | + //set is_creating_event property. |
|
951 | + $EVT_ID = $event->ID(); |
|
952 | + $this->_is_creating_event = absint($EVT_ID) === 0; |
|
953 | + //default main template args |
|
954 | + $main_template_args = array( |
|
955 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
956 | + 'event_editor_event_datetimes_help_tab', |
|
957 | + $this->_adminpage_obj->page_slug, |
|
958 | + $this->_adminpage_obj->get_req_action(), |
|
959 | + false, |
|
960 | + false |
|
961 | + ), |
|
962 | + // todo need to add a filter to the template for the help text |
|
963 | + // in the Events_Admin_Page core file so we can add further help |
|
964 | + 'existing_datetime_ids' => '', |
|
965 | + 'total_dtt_rows' => 1, |
|
966 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
967 | + 'add_new_dtt_info', |
|
968 | + $this->_adminpage_obj->page_slug, |
|
969 | + $this->_adminpage_obj->get_req_action(), |
|
970 | + false, |
|
971 | + false |
|
972 | + ), |
|
973 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
974 | + 'datetime_rows' => '', |
|
975 | + 'show_tickets_container' => '', |
|
976 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
977 | + 'ticket_rows' => '', |
|
978 | + 'existing_ticket_ids' => '', |
|
979 | + 'total_ticket_rows' => 1, |
|
980 | + 'ticket_js_structure' => '', |
|
981 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
982 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
983 | + ); |
|
984 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
985 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
986 | + /** |
|
987 | + * 1. Start with retrieving Datetimes |
|
988 | + * 2. For each datetime get related tickets |
|
989 | + * 3. For each ticket get related prices |
|
990 | + */ |
|
991 | + /** @var EEM_Datetime $datetime_model */ |
|
992 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
993 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
994 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
995 | + /** |
|
996 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
997 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
998 | + */ |
|
999 | + $datetime_row = 1; |
|
1000 | + foreach ($datetimes as $datetime) { |
|
1001 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
1002 | + $datetime->set('DTT_order', $datetime_row); |
|
1003 | + $existing_datetime_ids[] = $DTT_ID; |
|
1004 | + //tickets attached |
|
1005 | + $related_tickets = $datetime->ID() > 0 |
|
1006 | + ? $datetime->get_many_related( |
|
1007 | + 'Ticket', |
|
1008 | + array( |
|
1009 | + array( |
|
1010 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1011 | + ), |
|
1012 | + 'default_where_conditions' => 'none', |
|
1013 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
1014 | + ) |
|
1015 | + ) |
|
1016 | + : array(); |
|
1017 | + //if there are no related tickets this is likely a new event OR autodraft |
|
1018 | + // event so we need to generate the default tickets because datetimes |
|
1019 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1020 | + // datetime on the event. |
|
1021 | + if (empty ($related_tickets) && count($datetimes) < 2) { |
|
1022 | + /** @var EEM_Ticket $ticket_model */ |
|
1023 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1024 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1025 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1026 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1027 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1028 | + $main_default_ticket = reset($related_tickets); |
|
1029 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
1030 | + foreach ($default_prices as $default_price) { |
|
1031 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1032 | + continue; |
|
1033 | + } |
|
1034 | + $main_default_ticket->cache('Price', $default_price); |
|
1035 | + } |
|
1036 | + } |
|
1037 | + } |
|
1038 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
1039 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1040 | + // So we're going to temporarily cache some of that information. |
|
1041 | + //loop through and setup the ticket rows and make sure the order is set. |
|
1042 | + foreach ($related_tickets as $ticket) { |
|
1043 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
1044 | + $ticket_row = $ticket->get('TKT_row'); |
|
1045 | + //we only want unique tickets in our final display!! |
|
1046 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1047 | + $existing_ticket_ids[] = $TKT_ID; |
|
1048 | + $all_tickets[] = $ticket; |
|
1049 | + } |
|
1050 | + //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1051 | + $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
1052 | + //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1053 | + if ( |
|
1054 | + ! isset($ticket_datetimes[$TKT_ID]) |
|
1055 | + || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
1056 | + ) { |
|
1057 | + $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
1058 | + } |
|
1059 | + } |
|
1060 | + $datetime_row++; |
|
1061 | + } |
|
1062 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1063 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1064 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1065 | + //sort $all_tickets by order |
|
1066 | + usort( |
|
1067 | + $all_tickets, |
|
1068 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
1069 | + $a_order = (int)$a->get('TKT_order'); |
|
1070 | + $b_order = (int)$b->get('TKT_order'); |
|
1071 | + if ($a_order === $b_order) { |
|
1072 | + return 0; |
|
1073 | + } |
|
1074 | + return ($a_order < $b_order) ? -1 : 1; |
|
1075 | + } |
|
1076 | + ); |
|
1077 | + // k NOW we have all the data we need for setting up the dtt rows |
|
1078 | + // and ticket rows so we start our dtt loop again. |
|
1079 | + $datetime_row = 1; |
|
1080 | + foreach ($datetimes as $datetime) { |
|
1081 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1082 | + $datetime_row, |
|
1083 | + $datetime, |
|
1084 | + $datetime_tickets, |
|
1085 | + $all_tickets, |
|
1086 | + false, |
|
1087 | + $datetimes |
|
1088 | + ); |
|
1089 | + $datetime_row++; |
|
1090 | + } |
|
1091 | + //then loop through all tickets for the ticket rows. |
|
1092 | + $ticket_row = 1; |
|
1093 | + foreach ($all_tickets as $ticket) { |
|
1094 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1095 | + $ticket_row, |
|
1096 | + $ticket, |
|
1097 | + $ticket_datetimes, |
|
1098 | + $datetimes, |
|
1099 | + false, |
|
1100 | + $all_tickets |
|
1101 | + ); |
|
1102 | + $ticket_row++; |
|
1103 | + } |
|
1104 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1105 | + EEH_Template::display_template( |
|
1106 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1107 | + $main_template_args |
|
1108 | + ); |
|
1109 | + } |
|
1110 | + |
|
1111 | + |
|
1112 | + |
|
1113 | + /** |
|
1114 | + * @param int $datetime_row |
|
1115 | + * @param EE_Datetime $datetime |
|
1116 | + * @param array $datetime_tickets |
|
1117 | + * @param array $all_tickets |
|
1118 | + * @param bool $default |
|
1119 | + * @param array $all_datetimes |
|
1120 | + * @return mixed |
|
1121 | + * @throws DomainException |
|
1122 | + * @throws EE_Error |
|
1123 | + */ |
|
1124 | + protected function _get_datetime_row( |
|
1125 | + $datetime_row, |
|
1126 | + EE_Datetime $datetime, |
|
1127 | + $datetime_tickets = array(), |
|
1128 | + $all_tickets = array(), |
|
1129 | + $default = false, |
|
1130 | + $all_datetimes = array() |
|
1131 | + ) { |
|
1132 | + $dtt_display_template_args = array( |
|
1133 | + 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
1134 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1135 | + $datetime_row, |
|
1136 | + $datetime, |
|
1137 | + $datetime_tickets, |
|
1138 | + $all_tickets, |
|
1139 | + $default |
|
1140 | + ), |
|
1141 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1142 | + ); |
|
1143 | + return EEH_Template::display_template( |
|
1144 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1145 | + $dtt_display_template_args, |
|
1146 | + true |
|
1147 | + ); |
|
1148 | + } |
|
1149 | + |
|
1150 | + |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * This method is used to generate a dtt fields edit row. |
|
1154 | + * The same row is used to generate a row with valid DTT objects |
|
1155 | + * and the default row that is used as the skeleton by the js. |
|
1156 | + * |
|
1157 | + * @param int $datetime_row The row number for the row being generated. |
|
1158 | + * @param EE_Datetime $datetime |
|
1159 | + * @param bool $default Whether a default row is being generated or not. |
|
1160 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1161 | + * @return string |
|
1162 | + * @throws DomainException |
|
1163 | + * @throws EE_Error |
|
1164 | + */ |
|
1165 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1166 | + { |
|
1167 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1168 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1169 | + $template_args = array( |
|
1170 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1171 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1172 | + 'edit_dtt_expanded' => '', |
|
1173 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1174 | + 'DTT_name' => $default ? '' : $datetime->get_f('DTT_name'), |
|
1175 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1176 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1177 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1178 | + 'DTT_reg_limit' => $default |
|
1179 | + ? '' |
|
1180 | + : $datetime->get_pretty( |
|
1181 | + 'DTT_reg_limit', |
|
1182 | + 'input' |
|
1183 | + ), |
|
1184 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1185 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1186 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1187 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1188 | + ? '' |
|
1189 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1190 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1191 | + ? 'ee-lock-icon' |
|
1192 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1193 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1194 | + ? '' |
|
1195 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
1196 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1197 | + REG_ADMIN_URL |
|
1198 | + ), |
|
1199 | + ); |
|
1200 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1201 | + ? ' style="display:none"' |
|
1202 | + : ''; |
|
1203 | + //allow filtering of template args at this point. |
|
1204 | + $template_args = apply_filters( |
|
1205 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1206 | + $template_args, |
|
1207 | + $datetime_row, |
|
1208 | + $datetime, |
|
1209 | + $default, |
|
1210 | + $all_datetimes, |
|
1211 | + $this->_is_creating_event |
|
1212 | + ); |
|
1213 | + return EEH_Template::display_template( |
|
1214 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1215 | + $template_args, |
|
1216 | + true |
|
1217 | + ); |
|
1218 | + } |
|
1219 | + |
|
1220 | + |
|
1221 | + |
|
1222 | + /** |
|
1223 | + * @param int $datetime_row |
|
1224 | + * @param EE_Datetime $datetime |
|
1225 | + * @param array $datetime_tickets |
|
1226 | + * @param array $all_tickets |
|
1227 | + * @param bool $default |
|
1228 | + * @return mixed |
|
1229 | + * @throws DomainException |
|
1230 | + * @throws EE_Error |
|
1231 | + */ |
|
1232 | + protected function _get_dtt_attached_tickets_row( |
|
1233 | + $datetime_row, |
|
1234 | + $datetime, |
|
1235 | + $datetime_tickets = array(), |
|
1236 | + $all_tickets = array(), |
|
1237 | + $default |
|
1238 | + ) { |
|
1239 | + $template_args = array( |
|
1240 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1241 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1242 | + 'DTT_description' => $default ? '' : $datetime->get_f('DTT_description'), |
|
1243 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1244 | + 'show_tickets_row' => ' style="display:none;"', |
|
1245 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1246 | + 'add_new_ticket_via_datetime', |
|
1247 | + $this->_adminpage_obj->page_slug, |
|
1248 | + $this->_adminpage_obj->get_req_action(), |
|
1249 | + false, |
|
1250 | + false |
|
1251 | + ), |
|
1252 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1253 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1254 | + ); |
|
1255 | + //need to setup the list items (but only if this isn't a default skeleton setup) |
|
1256 | + if (! $default) { |
|
1257 | + $ticket_row = 1; |
|
1258 | + foreach ($all_tickets as $ticket) { |
|
1259 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1260 | + $datetime_row, |
|
1261 | + $ticket_row, |
|
1262 | + $datetime, |
|
1263 | + $ticket, |
|
1264 | + $datetime_tickets, |
|
1265 | + $default |
|
1266 | + ); |
|
1267 | + $ticket_row++; |
|
1268 | + } |
|
1269 | + } |
|
1270 | + //filter template args at this point |
|
1271 | + $template_args = apply_filters( |
|
1272 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1273 | + $template_args, |
|
1274 | + $datetime_row, |
|
1275 | + $datetime, |
|
1276 | + $datetime_tickets, |
|
1277 | + $all_tickets, |
|
1278 | + $default, |
|
1279 | + $this->_is_creating_event |
|
1280 | + ); |
|
1281 | + return EEH_Template::display_template( |
|
1282 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1283 | + $template_args, |
|
1284 | + true |
|
1285 | + ); |
|
1286 | + } |
|
1287 | + |
|
1288 | + |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * @param int $datetime_row |
|
1292 | + * @param int $ticket_row |
|
1293 | + * @param EE_Datetime $datetime |
|
1294 | + * @param EE_Ticket $ticket |
|
1295 | + * @param array $datetime_tickets |
|
1296 | + * @param bool $default |
|
1297 | + * @return mixed |
|
1298 | + * @throws DomainException |
|
1299 | + * @throws EE_Error |
|
1300 | + */ |
|
1301 | + protected function _get_datetime_tickets_list_item( |
|
1302 | + $datetime_row, |
|
1303 | + $ticket_row, |
|
1304 | + $datetime, |
|
1305 | + $ticket, |
|
1306 | + $datetime_tickets = array(), |
|
1307 | + $default |
|
1308 | + ) { |
|
1309 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
1310 | + ? $datetime_tickets[$datetime->ID()] |
|
1311 | + : array(); |
|
1312 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1313 | + $no_ticket = $default && empty($ticket); |
|
1314 | + $template_args = array( |
|
1315 | + 'dtt_row' => $default |
|
1316 | + ? 'DTTNUM' |
|
1317 | + : $datetime_row, |
|
1318 | + 'tkt_row' => $no_ticket |
|
1319 | + ? 'TICKETNUM' |
|
1320 | + : $ticket_row, |
|
1321 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1322 | + ? ' checked="checked"' |
|
1323 | + : '', |
|
1324 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1325 | + ? ' ticket-selected' |
|
1326 | + : '', |
|
1327 | + 'TKT_name' => $no_ticket |
|
1328 | + ? 'TKTNAME' |
|
1329 | + : $ticket->get('TKT_name'), |
|
1330 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1331 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1332 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
1333 | + ); |
|
1334 | + //filter template args |
|
1335 | + $template_args = apply_filters( |
|
1336 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1337 | + $template_args, |
|
1338 | + $datetime_row, |
|
1339 | + $ticket_row, |
|
1340 | + $datetime, |
|
1341 | + $ticket, |
|
1342 | + $datetime_tickets, |
|
1343 | + $default, |
|
1344 | + $this->_is_creating_event |
|
1345 | + ); |
|
1346 | + return EEH_Template::display_template( |
|
1347 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1348 | + $template_args, |
|
1349 | + true |
|
1350 | + ); |
|
1351 | + } |
|
1352 | + |
|
1353 | + |
|
1354 | + |
|
1355 | + /** |
|
1356 | + * This generates the ticket row for tickets. |
|
1357 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
1358 | + * (when default === true) |
|
1359 | + * |
|
1360 | + * @param int $ticket_row Represents the row number being generated. |
|
1361 | + * @param $ticket |
|
1362 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1363 | + * or empty for default |
|
1364 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1365 | + * @param bool $default Whether default row being generated or not. |
|
1366 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1367 | + * (or empty in the case of defaults) |
|
1368 | + * @return mixed |
|
1369 | + * @throws DomainException |
|
1370 | + * @throws EE_Error |
|
1371 | + */ |
|
1372 | + protected function _get_ticket_row( |
|
1373 | + $ticket_row, |
|
1374 | + $ticket, |
|
1375 | + $ticket_datetimes, |
|
1376 | + $all_datetimes, |
|
1377 | + $default = false, |
|
1378 | + $all_tickets = array() |
|
1379 | + ) { |
|
1380 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1381 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1382 | + $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
1383 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
1384 | + // if there is only one price (which would be the base price) |
|
1385 | + // or NO prices and this ticket is a default ticket, |
|
1386 | + // let's just make sure there are no cached default prices on the object. |
|
1387 | + // This is done by not including any query_params. |
|
1388 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1389 | + $prices = $ticket->prices(); |
|
1390 | + } |
|
1391 | + // check if we're dealing with a default ticket in which case |
|
1392 | + // we don't want any starting_ticket_datetime_row values set |
|
1393 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1394 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1395 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1396 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1397 | + ? $ticket_datetimes[$ticket->ID()] |
|
1398 | + : array(); |
|
1399 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1400 | + $base_price = $default ? null : $ticket->base_price(); |
|
1401 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1402 | + //breaking out complicated condition for ticket_status |
|
1403 | + if ($default) { |
|
1404 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1405 | + } else { |
|
1406 | + $ticket_status_class = $ticket->is_default() |
|
1407 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1408 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
1409 | + } |
|
1410 | + //breaking out complicated condition for TKT_taxable |
|
1411 | + if ($default) { |
|
1412 | + $TKT_taxable = ''; |
|
1413 | + } else { |
|
1414 | + $TKT_taxable = $ticket->taxable() |
|
1415 | + ? ' checked="checked"' |
|
1416 | + : ''; |
|
1417 | + } |
|
1418 | + if ($default) { |
|
1419 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1420 | + } elseif ($ticket->is_default()) { |
|
1421 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1422 | + } else { |
|
1423 | + $TKT_status = $ticket->ticket_status(true); |
|
1424 | + } |
|
1425 | + if ($default) { |
|
1426 | + $TKT_min = ''; |
|
1427 | + } else { |
|
1428 | + $TKT_min = $ticket->min(); |
|
1429 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
1430 | + $TKT_min = ''; |
|
1431 | + } |
|
1432 | + } |
|
1433 | + $template_args = array( |
|
1434 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1435 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1436 | + //on initial page load this will always be the correct order. |
|
1437 | + 'tkt_status_class' => $ticket_status_class, |
|
1438 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
1439 | + 'edit_tkt_expanded' => '', |
|
1440 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1441 | + 'TKT_name' => $default ? '' : $ticket->get_f('TKT_name'), |
|
1442 | + 'TKT_start_date' => $default |
|
1443 | + ? '' |
|
1444 | + : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1445 | + 'TKT_end_date' => $default |
|
1446 | + ? '' |
|
1447 | + : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1448 | + 'TKT_status' => $TKT_status, |
|
1449 | + 'TKT_price' => $default |
|
1450 | + ? '' |
|
1451 | + : EEH_Template::format_currency( |
|
1452 | + $ticket->get_ticket_total_with_taxes(), |
|
1453 | + false, |
|
1454 | + false |
|
1455 | + ), |
|
1456 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1457 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1458 | + 'TKT_qty' => $default |
|
1459 | + ? '' |
|
1460 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1461 | + 'TKT_qty_for_input' => $default |
|
1462 | + ? '' |
|
1463 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
1464 | + 'TKT_uses' => $default |
|
1465 | + ? '' |
|
1466 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
1467 | + 'TKT_min' => $TKT_min, |
|
1468 | + 'TKT_max' => $default |
|
1469 | + ? '' |
|
1470 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
1471 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1472 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1473 | + 'TKT_registrations' => $default |
|
1474 | + ? 0 |
|
1475 | + : $ticket->count_registrations( |
|
1476 | + array( |
|
1477 | + array( |
|
1478 | + 'STS_ID' => array( |
|
1479 | + '!=', |
|
1480 | + EEM_Registration::status_id_incomplete, |
|
1481 | + ), |
|
1482 | + ), |
|
1483 | + ) |
|
1484 | + ), |
|
1485 | + 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1486 | + 'TKT_description' => $default ? '' : $ticket->get_f('TKT_description'), |
|
1487 | + 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1488 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1489 | + 'TKT_is_default_selector' => '', |
|
1490 | + 'ticket_price_rows' => '', |
|
1491 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1492 | + ? '' |
|
1493 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1494 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1495 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1496 | + ? '' |
|
1497 | + : ' style="display:none;"', |
|
1498 | + 'show_price_mod_button' => count($prices) > 1 |
|
1499 | + || ($default && $count_price_mods > 0) |
|
1500 | + || (! $default && $ticket->deleted()) |
|
1501 | + ? ' style="display:none;"' |
|
1502 | + : '', |
|
1503 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1504 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1505 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1506 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1507 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1508 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1509 | + 'TKT_taxable' => $TKT_taxable, |
|
1510 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1511 | + ? '' |
|
1512 | + : ' style="display:none"', |
|
1513 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1514 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1515 | + $ticket_subtotal, |
|
1516 | + false, |
|
1517 | + false |
|
1518 | + ), |
|
1519 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1520 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1521 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1522 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1523 | + ? ' ticket-archived' |
|
1524 | + : '', |
|
1525 | + 'trash_icon' => $ticket instanceof EE_Ticket |
|
1526 | + && $ticket->deleted() |
|
1527 | + && ! $ticket->is_permanently_deleteable() |
|
1528 | + ? 'ee-lock-icon ' |
|
1529 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1530 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1531 | + ? '' |
|
1532 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1533 | + ); |
|
1534 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1535 | + ? ' style="display:none"' |
|
1536 | + : ''; |
|
1537 | + //handle rows that should NOT be empty |
|
1538 | + if (empty($template_args['TKT_start_date'])) { |
|
1539 | + //if empty then the start date will be now. |
|
1540 | + $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
1541 | + current_time('timestamp')); |
|
1542 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1543 | + } |
|
1544 | + if (empty($template_args['TKT_end_date'])) { |
|
1545 | + //get the earliest datetime (if present); |
|
1546 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1547 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1548 | + 'Datetime', |
|
1549 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1550 | + ) |
|
1551 | + : null; |
|
1552 | + if (! empty($earliest_dtt)) { |
|
1553 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1554 | + 'DTT_EVT_start', |
|
1555 | + $this->_date_time_format |
|
1556 | + ); |
|
1557 | + } else { |
|
1558 | + //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1559 | + $template_args['TKT_end_date'] = date( |
|
1560 | + $this->_date_time_format, |
|
1561 | + mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
1562 | + ) |
|
1563 | + ); |
|
1564 | + } |
|
1565 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1566 | + } |
|
1567 | + //generate ticket_datetime items |
|
1568 | + if (! $default) { |
|
1569 | + $datetime_row = 1; |
|
1570 | + foreach ($all_datetimes as $datetime) { |
|
1571 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1572 | + $datetime_row, |
|
1573 | + $ticket_row, |
|
1574 | + $datetime, |
|
1575 | + $ticket, |
|
1576 | + $ticket_datetimes, |
|
1577 | + $default |
|
1578 | + ); |
|
1579 | + $datetime_row++; |
|
1580 | + } |
|
1581 | + } |
|
1582 | + $price_row = 1; |
|
1583 | + foreach ($prices as $price) { |
|
1584 | + if (! $price instanceof EE_Price) { |
|
1585 | + continue; |
|
1586 | + } |
|
1587 | + if ($price->is_base_price()) { |
|
1588 | + $price_row++; |
|
1589 | + continue; |
|
1590 | + } |
|
1591 | + $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1592 | + $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
1593 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1594 | + $ticket_row, |
|
1595 | + $price_row, |
|
1596 | + $price, |
|
1597 | + $default, |
|
1598 | + $ticket, |
|
1599 | + $show_trash, |
|
1600 | + $show_create |
|
1601 | + ); |
|
1602 | + $price_row++; |
|
1603 | + } |
|
1604 | + //filter $template_args |
|
1605 | + $template_args = apply_filters( |
|
1606 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1607 | + $template_args, |
|
1608 | + $ticket_row, |
|
1609 | + $ticket, |
|
1610 | + $ticket_datetimes, |
|
1611 | + $all_datetimes, |
|
1612 | + $default, |
|
1613 | + $all_tickets, |
|
1614 | + $this->_is_creating_event |
|
1615 | + ); |
|
1616 | + return EEH_Template::display_template( |
|
1617 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1618 | + $template_args, |
|
1619 | + true |
|
1620 | + ); |
|
1621 | + } |
|
1622 | + |
|
1623 | + |
|
1624 | + |
|
1625 | + /** |
|
1626 | + * @param int $ticket_row |
|
1627 | + * @param EE_Ticket|null $ticket |
|
1628 | + * @return string |
|
1629 | + * @throws DomainException |
|
1630 | + * @throws EE_Error |
|
1631 | + */ |
|
1632 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
1633 | + { |
|
1634 | + $tax_rows = ''; |
|
1635 | + /** @var EE_Price[] $taxes */ |
|
1636 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1637 | + foreach ($taxes as $tax) { |
|
1638 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1639 | + $template_args = array( |
|
1640 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1641 | + ? '' |
|
1642 | + : ' style="display:none;"', |
|
1643 | + 'tax_id' => $tax->ID(), |
|
1644 | + 'tkt_row' => $ticket_row, |
|
1645 | + 'tax_label' => $tax->get('PRC_name'), |
|
1646 | + 'tax_added' => $tax_added, |
|
1647 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1648 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
1649 | + ); |
|
1650 | + $template_args = apply_filters( |
|
1651 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1652 | + $template_args, |
|
1653 | + $ticket_row, |
|
1654 | + $ticket, |
|
1655 | + $this->_is_creating_event |
|
1656 | + ); |
|
1657 | + $tax_rows .= EEH_Template::display_template( |
|
1658 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1659 | + $template_args, |
|
1660 | + true |
|
1661 | + ); |
|
1662 | + } |
|
1663 | + return $tax_rows; |
|
1664 | + } |
|
1665 | + |
|
1666 | + |
|
1667 | + |
|
1668 | + /** |
|
1669 | + * @param EE_Price $tax |
|
1670 | + * @param EE_Ticket|null $ticket |
|
1671 | + * @return float|int |
|
1672 | + * @throws EE_Error |
|
1673 | + */ |
|
1674 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1675 | + { |
|
1676 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1677 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
1678 | + } |
|
1679 | + |
|
1680 | + |
|
1681 | + |
|
1682 | + /** |
|
1683 | + * @param int $ticket_row |
|
1684 | + * @param int $price_row |
|
1685 | + * @param EE_Price|null $price |
|
1686 | + * @param bool $default |
|
1687 | + * @param EE_Ticket|null $ticket |
|
1688 | + * @param bool $show_trash |
|
1689 | + * @param bool $show_create |
|
1690 | + * @return mixed |
|
1691 | + * @throws DomainException |
|
1692 | + * @throws EE_Error |
|
1693 | + */ |
|
1694 | + protected function _get_ticket_price_row( |
|
1695 | + $ticket_row, |
|
1696 | + $price_row, |
|
1697 | + $price, |
|
1698 | + $default, |
|
1699 | + $ticket, |
|
1700 | + $show_trash = true, |
|
1701 | + $show_create = true |
|
1702 | + ) { |
|
1703 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1704 | + $template_args = array( |
|
1705 | + 'tkt_row' => $default && empty($ticket) |
|
1706 | + ? 'TICKETNUM' |
|
1707 | + : $ticket_row, |
|
1708 | + 'PRC_order' => $default && empty($price) |
|
1709 | + ? 'PRICENUM' |
|
1710 | + : $price_row, |
|
1711 | + 'edit_prices_name' => $default && empty($price) |
|
1712 | + ? 'PRICENAMEATTR' |
|
1713 | + : 'edit_prices', |
|
1714 | + 'price_type_selector' => $default && empty($price) |
|
1715 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1716 | + : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
1717 | + 'PRC_ID' => $default && empty($price) |
|
1718 | + ? 0 |
|
1719 | + : $price->ID(), |
|
1720 | + 'PRC_is_default' => $default && empty($price) |
|
1721 | + ? 0 |
|
1722 | + : $price->get('PRC_is_default'), |
|
1723 | + 'PRC_name' => $default && empty($price) |
|
1724 | + ? '' |
|
1725 | + : $price->get('PRC_name'), |
|
1726 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1727 | + 'show_plus_or_minus' => $default && empty($price) |
|
1728 | + ? '' |
|
1729 | + : ' style="display:none;"', |
|
1730 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1731 | + ? ' style="display:none;"' |
|
1732 | + : '', |
|
1733 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1734 | + ? ' style="display:none;"' |
|
1735 | + : '', |
|
1736 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1737 | + ? ' style="display:none"' |
|
1738 | + : '', |
|
1739 | + 'PRC_amount' => $default && empty($price) |
|
1740 | + ? 0 |
|
1741 | + : $price->get_pretty('PRC_amount', |
|
1742 | + 'localized_float'), |
|
1743 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1744 | + ? ' style="display:none;"' |
|
1745 | + : '', |
|
1746 | + 'show_trash_icon' => $show_trash |
|
1747 | + ? '' |
|
1748 | + : ' style="display:none;"', |
|
1749 | + 'show_create_button' => $show_create |
|
1750 | + ? '' |
|
1751 | + : ' style="display:none;"', |
|
1752 | + 'PRC_desc' => $default && empty($price) |
|
1753 | + ? '' |
|
1754 | + : $price->get('PRC_desc'), |
|
1755 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1756 | + ); |
|
1757 | + $template_args = apply_filters( |
|
1758 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1759 | + $template_args, |
|
1760 | + $ticket_row, |
|
1761 | + $price_row, |
|
1762 | + $price, |
|
1763 | + $default, |
|
1764 | + $ticket, |
|
1765 | + $show_trash, |
|
1766 | + $show_create, |
|
1767 | + $this->_is_creating_event |
|
1768 | + ); |
|
1769 | + return EEH_Template::display_template( |
|
1770 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1771 | + $template_args, |
|
1772 | + true |
|
1773 | + ); |
|
1774 | + } |
|
1775 | + |
|
1776 | + |
|
1777 | + |
|
1778 | + /** |
|
1779 | + * @param int $ticket_row |
|
1780 | + * @param int $price_row |
|
1781 | + * @param EE_Price $price |
|
1782 | + * @param bool $default |
|
1783 | + * @param bool $disabled |
|
1784 | + * @return mixed |
|
1785 | + * @throws DomainException |
|
1786 | + * @throws EE_Error |
|
1787 | + */ |
|
1788 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1789 | + { |
|
1790 | + if ($price->is_base_price()) { |
|
1791 | + return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
1792 | + } |
|
1793 | + return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
1794 | + } |
|
1795 | + |
|
1796 | + |
|
1797 | + |
|
1798 | + /** |
|
1799 | + * @param int $ticket_row |
|
1800 | + * @param int $price_row |
|
1801 | + * @param EE_Price $price |
|
1802 | + * @param bool $default |
|
1803 | + * @return mixed |
|
1804 | + * @throws DomainException |
|
1805 | + * @throws EE_Error |
|
1806 | + */ |
|
1807 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1808 | + { |
|
1809 | + $template_args = array( |
|
1810 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1811 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1812 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1813 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1814 | + 'price_selected_operator' => '+', |
|
1815 | + 'price_selected_is_percent' => 0, |
|
1816 | + ); |
|
1817 | + $template_args = apply_filters( |
|
1818 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1819 | + $template_args, |
|
1820 | + $ticket_row, |
|
1821 | + $price_row, |
|
1822 | + $price, |
|
1823 | + $default, |
|
1824 | + $this->_is_creating_event |
|
1825 | + ); |
|
1826 | + return EEH_Template::display_template( |
|
1827 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1828 | + $template_args, |
|
1829 | + true |
|
1830 | + ); |
|
1831 | + } |
|
1832 | + |
|
1833 | + |
|
1834 | + |
|
1835 | + /** |
|
1836 | + * @param int $ticket_row |
|
1837 | + * @param int $price_row |
|
1838 | + * @param EE_Price $price |
|
1839 | + * @param bool $default |
|
1840 | + * @param bool $disabled |
|
1841 | + * @return mixed |
|
1842 | + * @throws DomainException |
|
1843 | + * @throws EE_Error |
|
1844 | + */ |
|
1845 | + protected function _get_price_modifier_template( |
|
1846 | + $ticket_row, |
|
1847 | + $price_row, |
|
1848 | + $price, |
|
1849 | + $default, |
|
1850 | + $disabled = false |
|
1851 | + ) { |
|
1852 | + $select_name = $default && ! $price instanceof EE_Price |
|
1853 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1854 | + : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1855 | + /** @var EEM_Price_Type $price_type_model */ |
|
1856 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1857 | + $price_types = $price_type_model->get_all(array( |
|
1858 | + array( |
|
1859 | + 'OR' => array( |
|
1860 | + 'PBT_ID' => '2', |
|
1861 | + 'PBT_ID*' => '3', |
|
1862 | + ), |
|
1863 | + ), |
|
1864 | + )); |
|
1865 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
1866 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1867 | + : array(); |
|
1868 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1869 | + $price_option_spans = ''; |
|
1870 | + //setup price types for selector |
|
1871 | + foreach ($price_types as $price_type) { |
|
1872 | + if (! $price_type instanceof EE_Price_Type) { |
|
1873 | + continue; |
|
1874 | + } |
|
1875 | + $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
1876 | + //while we're in the loop let's setup the option spans used by js |
|
1877 | + $span_args = array( |
|
1878 | + 'PRT_ID' => $price_type->ID(), |
|
1879 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1880 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1881 | + ); |
|
1882 | + $price_option_spans .= EEH_Template::display_template( |
|
1883 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1884 | + $span_args, |
|
1885 | + true |
|
1886 | + ); |
|
1887 | + } |
|
1888 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1889 | + $select_input = new EE_Select_Input( |
|
1890 | + $all_price_types, |
|
1891 | + array( |
|
1892 | + 'default' => $selected_price_type_id, |
|
1893 | + 'html_name' => $select_name, |
|
1894 | + 'html_class' => 'edit-price-PRT_ID', |
|
1895 | + 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1896 | + ) |
|
1897 | + ); |
|
1898 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1899 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1900 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1901 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1902 | + $template_args = array( |
|
1903 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1904 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1905 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1906 | + 'main_name' => $select_name, |
|
1907 | + 'selected_price_type_id' => $selected_price_type_id, |
|
1908 | + 'price_option_spans' => $price_option_spans, |
|
1909 | + 'price_selected_operator' => $price_selected_operator, |
|
1910 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
1911 | + 'disabled' => $disabled, |
|
1912 | + ); |
|
1913 | + $template_args = apply_filters( |
|
1914 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1915 | + $template_args, |
|
1916 | + $ticket_row, |
|
1917 | + $price_row, |
|
1918 | + $price, |
|
1919 | + $default, |
|
1920 | + $disabled, |
|
1921 | + $this->_is_creating_event |
|
1922 | + ); |
|
1923 | + return EEH_Template::display_template( |
|
1924 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1925 | + $template_args, |
|
1926 | + true |
|
1927 | + ); |
|
1928 | + } |
|
1929 | + |
|
1930 | + |
|
1931 | + |
|
1932 | + /** |
|
1933 | + * @param int $datetime_row |
|
1934 | + * @param int $ticket_row |
|
1935 | + * @param EE_Datetime|null $datetime |
|
1936 | + * @param EE_Ticket|null $ticket |
|
1937 | + * @param array $ticket_datetimes |
|
1938 | + * @param bool $default |
|
1939 | + * @return mixed |
|
1940 | + * @throws DomainException |
|
1941 | + * @throws EE_Error |
|
1942 | + */ |
|
1943 | + protected function _get_ticket_datetime_list_item( |
|
1944 | + $datetime_row, |
|
1945 | + $ticket_row, |
|
1946 | + $datetime, |
|
1947 | + $ticket, |
|
1948 | + $ticket_datetimes = array(), |
|
1949 | + $default |
|
1950 | + ) { |
|
1951 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1952 | + ? $ticket_datetimes[$ticket->ID()] |
|
1953 | + : array(); |
|
1954 | + $template_args = array( |
|
1955 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
1956 | + ? 'DTTNUM' |
|
1957 | + : $datetime_row, |
|
1958 | + 'tkt_row' => $default |
|
1959 | + ? 'TICKETNUM' |
|
1960 | + : $ticket_row, |
|
1961 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
1962 | + ? ' ticket-selected' |
|
1963 | + : '', |
|
1964 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
1965 | + ? ' checked="checked"' |
|
1966 | + : '', |
|
1967 | + 'DTT_name' => $default && empty($datetime) |
|
1968 | + ? 'DTTNAME' |
|
1969 | + : $datetime->get_dtt_display_name(true), |
|
1970 | + 'tkt_status_class' => '', |
|
1971 | + ); |
|
1972 | + $template_args = apply_filters( |
|
1973 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
1974 | + $template_args, |
|
1975 | + $datetime_row, |
|
1976 | + $ticket_row, |
|
1977 | + $datetime, |
|
1978 | + $ticket, |
|
1979 | + $ticket_datetimes, |
|
1980 | + $default, |
|
1981 | + $this->_is_creating_event |
|
1982 | + ); |
|
1983 | + return EEH_Template::display_template( |
|
1984 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1985 | + $template_args, |
|
1986 | + true |
|
1987 | + ); |
|
1988 | + } |
|
1989 | + |
|
1990 | + |
|
1991 | + |
|
1992 | + /** |
|
1993 | + * @param array $all_datetimes |
|
1994 | + * @param array $all_tickets |
|
1995 | + * @return mixed |
|
1996 | + * @throws DomainException |
|
1997 | + * @throws EE_Error |
|
1998 | + */ |
|
1999 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2000 | + { |
|
2001 | + $template_args = array( |
|
2002 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2003 | + 'DTTNUM', |
|
2004 | + null, |
|
2005 | + true, |
|
2006 | + $all_datetimes |
|
2007 | + ), |
|
2008 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
2009 | + 'TICKETNUM', |
|
2010 | + null, |
|
2011 | + array(), |
|
2012 | + array(), |
|
2013 | + true |
|
2014 | + ), |
|
2015 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
2016 | + 'TICKETNUM', |
|
2017 | + 'PRICENUM', |
|
2018 | + null, |
|
2019 | + true, |
|
2020 | + null |
|
2021 | + ), |
|
2022 | + 'default_price_rows' => '', |
|
2023 | + 'default_base_price_amount' => 0, |
|
2024 | + 'default_base_price_name' => '', |
|
2025 | + 'default_base_price_description' => '', |
|
2026 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2027 | + 'TICKETNUM', |
|
2028 | + 'PRICENUM', |
|
2029 | + null, |
|
2030 | + true |
|
2031 | + ), |
|
2032 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2033 | + 'DTTNUM', |
|
2034 | + null, |
|
2035 | + array(), |
|
2036 | + array(), |
|
2037 | + true |
|
2038 | + ), |
|
2039 | + 'existing_available_datetime_tickets_list' => '', |
|
2040 | + 'existing_available_ticket_datetimes_list' => '', |
|
2041 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2042 | + 'DTTNUM', |
|
2043 | + 'TICKETNUM', |
|
2044 | + null, |
|
2045 | + null, |
|
2046 | + array(), |
|
2047 | + true |
|
2048 | + ), |
|
2049 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2050 | + 'DTTNUM', |
|
2051 | + 'TICKETNUM', |
|
2052 | + null, |
|
2053 | + null, |
|
2054 | + array(), |
|
2055 | + true |
|
2056 | + ), |
|
2057 | + ); |
|
2058 | + $ticket_row = 1; |
|
2059 | + foreach ($all_tickets as $ticket) { |
|
2060 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2061 | + 'DTTNUM', |
|
2062 | + $ticket_row, |
|
2063 | + null, |
|
2064 | + $ticket, |
|
2065 | + array(), |
|
2066 | + true |
|
2067 | + ); |
|
2068 | + $ticket_row++; |
|
2069 | + } |
|
2070 | + $datetime_row = 1; |
|
2071 | + foreach ($all_datetimes as $datetime) { |
|
2072 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2073 | + $datetime_row, |
|
2074 | + 'TICKETNUM', |
|
2075 | + $datetime, |
|
2076 | + null, |
|
2077 | + array(), |
|
2078 | + true |
|
2079 | + ); |
|
2080 | + $datetime_row++; |
|
2081 | + } |
|
2082 | + /** @var EEM_Price $price_model */ |
|
2083 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
2084 | + $default_prices = $price_model->get_all_default_prices(); |
|
2085 | + $price_row = 1; |
|
2086 | + foreach ($default_prices as $price) { |
|
2087 | + if (! $price instanceof EE_Price) { |
|
2088 | + continue; |
|
2089 | + } |
|
2090 | + if ($price->is_base_price()) { |
|
2091 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2092 | + 'PRC_amount', |
|
2093 | + 'localized_float' |
|
2094 | + ); |
|
2095 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2096 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2097 | + $price_row++; |
|
2098 | + continue; |
|
2099 | + } |
|
2100 | + $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2101 | + $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2102 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2103 | + 'TICKETNUM', |
|
2104 | + $price_row, |
|
2105 | + $price, |
|
2106 | + true, |
|
2107 | + null, |
|
2108 | + $show_trash, |
|
2109 | + $show_create |
|
2110 | + ); |
|
2111 | + $price_row++; |
|
2112 | + } |
|
2113 | + $template_args = apply_filters( |
|
2114 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2115 | + $template_args, |
|
2116 | + $all_datetimes, |
|
2117 | + $all_tickets, |
|
2118 | + $this->_is_creating_event |
|
2119 | + ); |
|
2120 | + return EEH_Template::display_template( |
|
2121 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2122 | + $template_args, |
|
2123 | + true |
|
2124 | + ); |
|
2125 | + } |
|
2126 | 2126 | |
2127 | 2127 | |
2128 | 2128 | } //end class espresso_events_Pricing_Hooks |