@@ -20,521 +20,521 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * user id for logged in user when data collected |
|
25 | - * |
|
26 | - * @var string $user_id |
|
27 | - */ |
|
28 | - public $user_id; |
|
29 | - |
|
30 | - /** |
|
31 | - * IP Address of browser used |
|
32 | - * |
|
33 | - * @var string $ip_address |
|
34 | - */ |
|
35 | - public $ip_address; |
|
36 | - |
|
37 | - /** |
|
38 | - * browser |
|
39 | - * |
|
40 | - * @var string $user_agent |
|
41 | - */ |
|
42 | - public $user_agent; |
|
43 | - |
|
44 | - /** |
|
45 | - * Unix timestamp |
|
46 | - * |
|
47 | - * @var string $init_access |
|
48 | - */ |
|
49 | - public $init_access; |
|
50 | - |
|
51 | - /** |
|
52 | - * Unix timestamp |
|
53 | - * |
|
54 | - * @var string $last_access |
|
55 | - */ |
|
56 | - public $last_access; |
|
57 | - |
|
58 | - /** |
|
59 | - * The registrations details from the cart |
|
60 | - * |
|
61 | - * @var array $reg_info |
|
62 | - */ |
|
63 | - public $reg_info; |
|
64 | - |
|
65 | - /** |
|
66 | - * Some data handlers can set what reg status all the registrations are filtered by. |
|
67 | - * The status should match a EEM_Registration status constant. |
|
68 | - * |
|
69 | - * @var string $filtered_reg_status |
|
70 | - */ |
|
71 | - public $filtered_reg_status; |
|
72 | - |
|
73 | - /** |
|
74 | - * will hold an array of events assembled from $reg_info |
|
75 | - * |
|
76 | - * @var EE_Event[] $events |
|
77 | - */ |
|
78 | - public $events; |
|
79 | - |
|
80 | - /** |
|
81 | - * holds an array of datetimes assembled from the incoming data. |
|
82 | - * |
|
83 | - * @var EE_Datetime[] $datetimes |
|
84 | - */ |
|
85 | - public $datetimes; |
|
86 | - |
|
87 | - /** |
|
88 | - * holds an array of tickets assembled from the incoming data. |
|
89 | - * |
|
90 | - * @var EE_Ticket[] $tickets |
|
91 | - */ |
|
92 | - public $tickets; |
|
93 | - |
|
94 | - /** |
|
95 | - * holds an array with a key of parent line item and values are an array of children of that line item. |
|
96 | - * |
|
97 | - * @since 4.5.0 |
|
98 | - * @var EE_Line_Item[] $line_items_with_children |
|
99 | - */ |
|
100 | - public $line_items_with_children; |
|
101 | - |
|
102 | - /** |
|
103 | - * will hold an array of attendees assembled from the $reg_info |
|
104 | - * |
|
105 | - * @var EE_Attendee[] $attendees |
|
106 | - */ |
|
107 | - public $attendees; |
|
108 | - |
|
109 | - /** |
|
110 | - * will hold an array of cached registration objects and info assembled from reg_info |
|
111 | - * |
|
112 | - * @var array $registrations |
|
113 | - */ |
|
114 | - public $registrations; |
|
115 | - |
|
116 | - /** |
|
117 | - * will hold an array of answers assembled from the $reg_info |
|
118 | - * |
|
119 | - * @var EE_Answer[] $answers |
|
120 | - */ |
|
121 | - public $answers; |
|
122 | - |
|
123 | - /** |
|
124 | - * will hold an array of questions assembled from the $reg_info (indexed by Answer ID); |
|
125 | - * |
|
126 | - * @var EE_Question[] $questions |
|
127 | - */ |
|
128 | - public $questions; |
|
129 | - |
|
130 | - /** |
|
131 | - * Will hold billing data assembled from $billing_info (if present) |
|
132 | - * |
|
133 | - * @var mixed (array|null) $billing |
|
134 | - */ |
|
135 | - public $billing; |
|
136 | - |
|
137 | - /** |
|
138 | - * The total amount of tax for the transaction |
|
139 | - * |
|
140 | - * @var float $taxes |
|
141 | - */ |
|
142 | - public $taxes; |
|
143 | - |
|
144 | - /** |
|
145 | - * Holds the line items related to taxes |
|
146 | - * |
|
147 | - * @since 4.5.0 |
|
148 | - * @var EE_Line_Item[] $tax_line_items |
|
149 | - */ |
|
150 | - public $tax_line_items; |
|
151 | - |
|
152 | - /** |
|
153 | - * Hold the line items which aren't taxes and don't relate |
|
154 | - * to tickets. So: promotions and miscellaneous charges |
|
155 | - * |
|
156 | - * @since 4.5 |
|
157 | - * @var EE_Line_Item[] $additional_line_items |
|
158 | - */ |
|
159 | - public $additional_line_items; |
|
160 | - |
|
161 | - /** |
|
162 | - * Holds the grand total EE_Line_Item |
|
163 | - * |
|
164 | - * @var EE_Line_Item $grand_total_line_item |
|
165 | - */ |
|
166 | - public $grand_total_line_item; |
|
167 | - |
|
168 | - /** |
|
169 | - * holds the grand total price object |
|
170 | - * currently not used. |
|
171 | - * |
|
172 | - * @var null $grand_total_price_object |
|
173 | - */ |
|
174 | - public $grand_total_price_object; |
|
175 | - |
|
176 | - /** |
|
177 | - * total number of tickets |
|
178 | - * |
|
179 | - * @var int $total_ticket_count |
|
180 | - */ |
|
181 | - public $total_ticket_count; |
|
182 | - |
|
183 | - /** |
|
184 | - * Will hold the final transaction object (EE_Transaction) |
|
185 | - * |
|
186 | - * @var EE_Transaction $txn |
|
187 | - */ |
|
188 | - public $txn; |
|
189 | - |
|
190 | - /** |
|
191 | - * Holds the payments related to a transaction |
|
192 | - * |
|
193 | - * @since 4.5.0 |
|
194 | - * @var EE_Payment[] $payments |
|
195 | - */ |
|
196 | - public $payments; |
|
197 | - |
|
198 | - /** |
|
199 | - * Holds the first related payment related for a transaction |
|
200 | - * |
|
201 | - * @since 4.5.0 |
|
202 | - * @var EE_Payment $payment |
|
203 | - */ |
|
204 | - public $payment; |
|
205 | - |
|
206 | - /** |
|
207 | - * Will hold the label for the txn status |
|
208 | - * |
|
209 | - * @var string $txn_status |
|
210 | - */ |
|
211 | - public $txn_status; |
|
212 | - |
|
213 | - /** |
|
214 | - * Will hold the final registration object (EE_Registration) |
|
215 | - * |
|
216 | - * @var EE_Registration[] $reg_objs |
|
217 | - */ |
|
218 | - public $reg_objs; |
|
219 | - |
|
220 | - /** |
|
221 | - * Will hold an array of primary attendee data (if present) |
|
222 | - * |
|
223 | - * @var array $primary_attendee_data |
|
224 | - */ |
|
225 | - public $primary_attendee_data; |
|
226 | - |
|
227 | - /** |
|
228 | - * This is just an internal object used for passing around the incoming data. |
|
229 | - * |
|
230 | - * @var mixed $_data |
|
231 | - */ |
|
232 | - protected $_data; |
|
233 | - |
|
234 | - /** |
|
235 | - * This is just an internal object used for passing around the incoming data. |
|
236 | - * |
|
237 | - * @var mixed $incoming_data |
|
238 | - */ |
|
239 | - public $incoming_data; |
|
240 | - |
|
241 | - /** |
|
242 | - * hold objects that might be created |
|
243 | - * |
|
244 | - * @type EE_Registration $reg_obj |
|
245 | - */ |
|
246 | - public $reg_obj; |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * constructor |
|
251 | - * |
|
252 | - * @param mixed $data incoming data object|array. Suggested that child classes use type hinting for expected |
|
253 | - * data object. But here parent will be generic because we don't know what's coming in. |
|
254 | - */ |
|
255 | - public function __construct($data) |
|
256 | - { |
|
257 | - $this->_data = $data; |
|
258 | - $this->_setup_data(); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * Every child class has to setup the data object ! |
|
264 | - * |
|
265 | - * @return void |
|
266 | - */ |
|
267 | - abstract protected function _setup_data(); |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * Returns database safe representation of the data later used to when instantiating this object. |
|
272 | - * |
|
273 | - * @param mixed $data The incoming data to be prepped. |
|
274 | - * @return mixed The prepped data for db |
|
275 | - */ |
|
276 | - public static function convert_data_for_persistent_storage($data) |
|
277 | - { |
|
278 | - return $data; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
284 | - * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
285 | - * |
|
286 | - * @param $data |
|
287 | - * @return mixed |
|
288 | - */ |
|
289 | - public static function convert_data_from_persistent_storage($data) |
|
290 | - { |
|
291 | - return $data; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * only purpose is to return the data |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @return mixed the formatted data object! |
|
300 | - */ |
|
301 | - public function data() |
|
302 | - { |
|
303 | - return $this->_data; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * This helper method can be used by any incoming data handlers to setup the data correctly. All that is required |
|
309 | - * is that $this->reg_objs be set. |
|
310 | - * |
|
311 | - * @throws EE_Error |
|
312 | - * @throws InvalidDataTypeException |
|
313 | - * @throws InvalidInterfaceException |
|
314 | - * @throws InvalidArgumentException |
|
315 | - * @throws EntityNotFoundException |
|
316 | - */ |
|
317 | - protected function _assemble_data() |
|
318 | - { |
|
319 | - //verify that reg_objs is set |
|
320 | - if (! is_array($this->reg_objs) |
|
321 | - && ! reset($this->reg_objs) instanceof EE_Registration |
|
322 | - ) { |
|
323 | - throw new EE_Error( |
|
324 | - esc_html__( |
|
325 | - 'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects', |
|
326 | - 'event_espresso' |
|
327 | - ) |
|
328 | - ); |
|
329 | - } |
|
330 | - |
|
331 | - //get all attendee and events associated with the registrations in this transaction |
|
332 | - $events = $event_setup = $evtcache = $tickets = $datetimes = array(); |
|
333 | - $answers = $questions = $attendees = $line_items = $registrations = array(); |
|
334 | - $total_ticket_count = 0; |
|
335 | - |
|
336 | - if (! empty($this->reg_objs)) { |
|
337 | - $event_attendee_count = array(); |
|
338 | - /** @var EE_Registration $reg */ |
|
339 | - foreach ($this->reg_objs as $reg) { |
|
340 | - if ($this->_skip_registration_for_processing($reg) |
|
341 | - ) { |
|
342 | - continue; |
|
343 | - } |
|
344 | - |
|
345 | - $evt_id = $reg->event_ID(); |
|
346 | - /** @type EE_Ticket $ticket */ |
|
347 | - $ticket = $reg->get_first_related('Ticket'); |
|
348 | - $attendee = $reg->attendee(); |
|
349 | - $event = $reg->event(); |
|
350 | - //if none of the following entities are available, then we can't setup other data reliably, |
|
351 | - // so let's just skip. |
|
352 | - if (! $ticket instanceof EE_Ticket |
|
353 | - || ! $attendee instanceof EE_Attendee |
|
354 | - || ! $event instanceof EE_Event |
|
355 | - ) { |
|
356 | - continue; |
|
357 | - } |
|
358 | - $relateddatetime = $ticket->datetimes(); |
|
359 | - $total_ticket_count++; |
|
360 | - $tickets[$ticket->ID()]['ticket'] = $ticket; |
|
361 | - $tickets[$ticket->ID()]['count'] = is_array($tickets[$ticket->ID()]) |
|
362 | - && isset($tickets[$ticket->ID()]['count']) |
|
363 | - ? $tickets[$ticket->ID()]['count'] + 1 |
|
364 | - : 1; |
|
365 | - $tickets[$ticket->ID()]['att_objs'][$attendee->ID()] = $attendee; |
|
366 | - $tickets[$ticket->ID()]['dtt_objs'] = $relateddatetime; |
|
367 | - $tickets[$ticket->ID()]['reg_objs'][$reg->ID()] = $reg; |
|
368 | - $tickets[$ticket->ID()]['EE_Event'] = $event; |
|
369 | - $evtcache[$evt_id] = $event; |
|
370 | - $eventsetup[$evt_id]['reg_objs'][$reg->ID()] = $reg; |
|
371 | - $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()] = $ticket; |
|
372 | - $eventsetup[$evt_id]['att_objs'][$attendee->ID()] = $attendee; |
|
373 | - $event_attendee_count[$evt_id] = isset($event_attendee_count[$evt_id]) |
|
374 | - ? $event_attendee_count[$evt_id] + 1 |
|
375 | - : 0; |
|
376 | - $attendees[$reg->attendee_ID()]['line_ref'][] = $evt_id; |
|
377 | - $attendees[$reg->attendee_ID()]['att_obj'] = $attendee; |
|
378 | - $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()] = $reg; |
|
379 | - //$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID(); |
|
380 | - $attendees[$reg->attendee_ID()]['attendee_email'] = $attendee->email(); |
|
381 | - $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket; |
|
382 | - $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id] = $event; |
|
383 | - |
|
384 | - //registrations |
|
385 | - $registrations[$reg->ID()]['tkt_obj'] = $ticket; |
|
386 | - $registrations[$reg->ID()]['evt_obj'] = $event; |
|
387 | - $registrations[$reg->ID()]['reg_obj'] = $reg; |
|
388 | - $registrations[$reg->ID()]['att_obj'] = $attendee; |
|
389 | - |
|
390 | - //set up answer objects |
|
391 | - $rel_ans = $reg->get_many_related('Answer'); |
|
392 | - foreach ($rel_ans as $ansid => $answer) { |
|
393 | - if (! isset($questions[$ansid])) { |
|
394 | - $questions[$ansid] = $answer->get_first_related('Question'); |
|
395 | - } |
|
396 | - $answers[$ansid] = $answer; |
|
397 | - $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer; |
|
398 | - } |
|
399 | - /** |
|
400 | - * @var int $dtt_id |
|
401 | - * @var EE_Datetime $datetime |
|
402 | - */ |
|
403 | - foreach ($relateddatetime as $dtt_id => $datetime) { |
|
404 | - $eventsetup[$evt_id]['dtt_objs'][$dtt_id] = $datetime; |
|
405 | - $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime; |
|
406 | - |
|
407 | - if (isset($datetimes[$dtt_id])) { |
|
408 | - continue; //already have this info in the datetimes array. |
|
409 | - } |
|
410 | - |
|
411 | - $datetimes[$dtt_id]['tkt_objs'][] = $ticket; |
|
412 | - $datetimes[$dtt_id]['datetime'] = $datetime; |
|
413 | - $datetimes[$dtt_id]['evt_objs'][$evt_id] = $event; |
|
414 | - $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg; |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - //let's loop through the unique event=>reg items and setup data on them |
|
419 | - |
|
420 | - if (! empty($eventsetup)) { |
|
421 | - foreach ($eventsetup as $evt_id => $items) { |
|
422 | - $ticket_line_items_for_event = array(); |
|
423 | - if ($this->txn instanceof EE_Transaction) { |
|
424 | - $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all( |
|
425 | - array( |
|
426 | - array( |
|
427 | - 'Ticket.Datetime.EVT_ID' => $evt_id, |
|
428 | - 'TXN_ID' => $this->txn->ID(), |
|
429 | - ), |
|
430 | - 'default_where_conditions' => 'none', |
|
431 | - ) |
|
432 | - ); |
|
433 | - } |
|
434 | - $events[$evt_id] = array( |
|
435 | - 'ID' => $evt_id, |
|
436 | - 'event' => $evtcache[$evt_id], |
|
437 | - 'name' => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '', |
|
438 | - 'total_attendees' => $event_attendee_count[$evt_id], |
|
439 | - 'reg_objs' => $items['reg_objs'], |
|
440 | - 'tkt_objs' => $items['tkt_objs'], |
|
441 | - 'att_objs' => $items['att_objs'], |
|
442 | - 'dtt_objs' => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(), |
|
443 | - 'line_items' => $ticket_line_items_for_event, |
|
444 | - ); |
|
445 | - |
|
446 | - //make sure the tickets have the line items setup for them. |
|
447 | - foreach ($ticket_line_items_for_event as $line_id => $line_item) { |
|
448 | - if ($line_item instanceof EE_Line_Item) { |
|
449 | - $tickets[$line_item->ticket()->ID()]['line_item'] = $line_item; |
|
450 | - $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children(); |
|
451 | - $line_items[$line_item->ID()]['children'] = $line_item->children(); |
|
452 | - $line_items[$line_item->ID()]['EE_Ticket'] = $line_item->ticket(); |
|
453 | - } |
|
454 | - } |
|
455 | - } |
|
456 | - } |
|
457 | - |
|
458 | - $this->grand_total_line_item = $this->txn instanceof EE_Transaction |
|
459 | - ? $this->txn->total_line_item() |
|
460 | - : null; |
|
461 | - } |
|
462 | - |
|
463 | - //lets set the attendees and events properties |
|
464 | - $this->attendees = $attendees; |
|
465 | - $this->events = $events; |
|
466 | - $this->tickets = $tickets; |
|
467 | - $this->line_items_with_children = $line_items; |
|
468 | - $this->datetimes = $datetimes; |
|
469 | - $this->questions = $questions; |
|
470 | - $this->answers = $answers; |
|
471 | - $this->total_ticket_count = $total_ticket_count; |
|
472 | - $this->registrations = $registrations; |
|
473 | - |
|
474 | - if ($this->txn instanceof EE_Transaction) { |
|
475 | - $this->tax_line_items = $this->txn->tax_items(); |
|
476 | - $this->additional_line_items = $this->txn->non_ticket_line_items(); |
|
477 | - $this->payments = $this->txn->payments(); |
|
478 | - |
|
479 | - //setup primary registration if we have a single transaction object to work with |
|
480 | - |
|
481 | - //let's get just the primary_attendee_data! First we get the primary registration object. |
|
482 | - $primary_reg = $this->txn->primary_registration(); |
|
483 | - // verify |
|
484 | - if ($primary_reg instanceof EE_Registration) { |
|
485 | - // get attendee object |
|
486 | - if ($primary_reg->attendee() instanceof EE_Attendee) { |
|
487 | - //now we can setup the primary_attendee_data array |
|
488 | - $this->primary_attendee_data = array( |
|
489 | - 'registration_id' => $primary_reg->ID(), |
|
490 | - 'att_obj' => $primary_reg->attendee(), |
|
491 | - 'reg_obj' => $primary_reg, |
|
492 | - 'primary_att_obj' => $primary_reg->attendee(), |
|
493 | - 'primary_reg_obj' => $primary_reg, |
|
494 | - ); |
|
495 | - |
|
496 | - } else { |
|
497 | - EE_Error::add_error( |
|
498 | - esc_html__( |
|
499 | - 'Incoming data does not have a valid Attendee object for the primary registrant.', |
|
500 | - 'event_espresso' |
|
501 | - ), |
|
502 | - __FILE__, |
|
503 | - __FUNCTION__, |
|
504 | - __LINE__ |
|
505 | - ); |
|
506 | - } |
|
507 | - } else { |
|
508 | - EE_Error::add_error( |
|
509 | - esc_html__( |
|
510 | - 'Incoming data does not have a valid Registration object for the primary registrant.', |
|
511 | - 'event_espresso' |
|
512 | - ), |
|
513 | - __FILE__, |
|
514 | - __FUNCTION__, |
|
515 | - __LINE__ |
|
516 | - ); |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
520 | - |
|
521 | - /** |
|
522 | - * This simply considers whether the given registration should be processed or not based on comparison with the |
|
523 | - * filtered_reg_status property. |
|
524 | - * |
|
525 | - * @param EE_Registration $registration |
|
526 | - * @return bool returning true means we DO want to skip processing. returning false means we DON'T want to skip |
|
527 | - * processing |
|
528 | - */ |
|
529 | - protected function _skip_registration_for_processing(EE_Registration $registration) |
|
530 | - { |
|
531 | - if (empty($this->filtered_reg_status)) { |
|
532 | - return false; |
|
533 | - } |
|
534 | - |
|
535 | - //if we made it here then we just compare the filtered_reg_status with the registration status and return that |
|
536 | - return $this->filtered_reg_status !== $registration->status_ID(); |
|
537 | - } |
|
23 | + /** |
|
24 | + * user id for logged in user when data collected |
|
25 | + * |
|
26 | + * @var string $user_id |
|
27 | + */ |
|
28 | + public $user_id; |
|
29 | + |
|
30 | + /** |
|
31 | + * IP Address of browser used |
|
32 | + * |
|
33 | + * @var string $ip_address |
|
34 | + */ |
|
35 | + public $ip_address; |
|
36 | + |
|
37 | + /** |
|
38 | + * browser |
|
39 | + * |
|
40 | + * @var string $user_agent |
|
41 | + */ |
|
42 | + public $user_agent; |
|
43 | + |
|
44 | + /** |
|
45 | + * Unix timestamp |
|
46 | + * |
|
47 | + * @var string $init_access |
|
48 | + */ |
|
49 | + public $init_access; |
|
50 | + |
|
51 | + /** |
|
52 | + * Unix timestamp |
|
53 | + * |
|
54 | + * @var string $last_access |
|
55 | + */ |
|
56 | + public $last_access; |
|
57 | + |
|
58 | + /** |
|
59 | + * The registrations details from the cart |
|
60 | + * |
|
61 | + * @var array $reg_info |
|
62 | + */ |
|
63 | + public $reg_info; |
|
64 | + |
|
65 | + /** |
|
66 | + * Some data handlers can set what reg status all the registrations are filtered by. |
|
67 | + * The status should match a EEM_Registration status constant. |
|
68 | + * |
|
69 | + * @var string $filtered_reg_status |
|
70 | + */ |
|
71 | + public $filtered_reg_status; |
|
72 | + |
|
73 | + /** |
|
74 | + * will hold an array of events assembled from $reg_info |
|
75 | + * |
|
76 | + * @var EE_Event[] $events |
|
77 | + */ |
|
78 | + public $events; |
|
79 | + |
|
80 | + /** |
|
81 | + * holds an array of datetimes assembled from the incoming data. |
|
82 | + * |
|
83 | + * @var EE_Datetime[] $datetimes |
|
84 | + */ |
|
85 | + public $datetimes; |
|
86 | + |
|
87 | + /** |
|
88 | + * holds an array of tickets assembled from the incoming data. |
|
89 | + * |
|
90 | + * @var EE_Ticket[] $tickets |
|
91 | + */ |
|
92 | + public $tickets; |
|
93 | + |
|
94 | + /** |
|
95 | + * holds an array with a key of parent line item and values are an array of children of that line item. |
|
96 | + * |
|
97 | + * @since 4.5.0 |
|
98 | + * @var EE_Line_Item[] $line_items_with_children |
|
99 | + */ |
|
100 | + public $line_items_with_children; |
|
101 | + |
|
102 | + /** |
|
103 | + * will hold an array of attendees assembled from the $reg_info |
|
104 | + * |
|
105 | + * @var EE_Attendee[] $attendees |
|
106 | + */ |
|
107 | + public $attendees; |
|
108 | + |
|
109 | + /** |
|
110 | + * will hold an array of cached registration objects and info assembled from reg_info |
|
111 | + * |
|
112 | + * @var array $registrations |
|
113 | + */ |
|
114 | + public $registrations; |
|
115 | + |
|
116 | + /** |
|
117 | + * will hold an array of answers assembled from the $reg_info |
|
118 | + * |
|
119 | + * @var EE_Answer[] $answers |
|
120 | + */ |
|
121 | + public $answers; |
|
122 | + |
|
123 | + /** |
|
124 | + * will hold an array of questions assembled from the $reg_info (indexed by Answer ID); |
|
125 | + * |
|
126 | + * @var EE_Question[] $questions |
|
127 | + */ |
|
128 | + public $questions; |
|
129 | + |
|
130 | + /** |
|
131 | + * Will hold billing data assembled from $billing_info (if present) |
|
132 | + * |
|
133 | + * @var mixed (array|null) $billing |
|
134 | + */ |
|
135 | + public $billing; |
|
136 | + |
|
137 | + /** |
|
138 | + * The total amount of tax for the transaction |
|
139 | + * |
|
140 | + * @var float $taxes |
|
141 | + */ |
|
142 | + public $taxes; |
|
143 | + |
|
144 | + /** |
|
145 | + * Holds the line items related to taxes |
|
146 | + * |
|
147 | + * @since 4.5.0 |
|
148 | + * @var EE_Line_Item[] $tax_line_items |
|
149 | + */ |
|
150 | + public $tax_line_items; |
|
151 | + |
|
152 | + /** |
|
153 | + * Hold the line items which aren't taxes and don't relate |
|
154 | + * to tickets. So: promotions and miscellaneous charges |
|
155 | + * |
|
156 | + * @since 4.5 |
|
157 | + * @var EE_Line_Item[] $additional_line_items |
|
158 | + */ |
|
159 | + public $additional_line_items; |
|
160 | + |
|
161 | + /** |
|
162 | + * Holds the grand total EE_Line_Item |
|
163 | + * |
|
164 | + * @var EE_Line_Item $grand_total_line_item |
|
165 | + */ |
|
166 | + public $grand_total_line_item; |
|
167 | + |
|
168 | + /** |
|
169 | + * holds the grand total price object |
|
170 | + * currently not used. |
|
171 | + * |
|
172 | + * @var null $grand_total_price_object |
|
173 | + */ |
|
174 | + public $grand_total_price_object; |
|
175 | + |
|
176 | + /** |
|
177 | + * total number of tickets |
|
178 | + * |
|
179 | + * @var int $total_ticket_count |
|
180 | + */ |
|
181 | + public $total_ticket_count; |
|
182 | + |
|
183 | + /** |
|
184 | + * Will hold the final transaction object (EE_Transaction) |
|
185 | + * |
|
186 | + * @var EE_Transaction $txn |
|
187 | + */ |
|
188 | + public $txn; |
|
189 | + |
|
190 | + /** |
|
191 | + * Holds the payments related to a transaction |
|
192 | + * |
|
193 | + * @since 4.5.0 |
|
194 | + * @var EE_Payment[] $payments |
|
195 | + */ |
|
196 | + public $payments; |
|
197 | + |
|
198 | + /** |
|
199 | + * Holds the first related payment related for a transaction |
|
200 | + * |
|
201 | + * @since 4.5.0 |
|
202 | + * @var EE_Payment $payment |
|
203 | + */ |
|
204 | + public $payment; |
|
205 | + |
|
206 | + /** |
|
207 | + * Will hold the label for the txn status |
|
208 | + * |
|
209 | + * @var string $txn_status |
|
210 | + */ |
|
211 | + public $txn_status; |
|
212 | + |
|
213 | + /** |
|
214 | + * Will hold the final registration object (EE_Registration) |
|
215 | + * |
|
216 | + * @var EE_Registration[] $reg_objs |
|
217 | + */ |
|
218 | + public $reg_objs; |
|
219 | + |
|
220 | + /** |
|
221 | + * Will hold an array of primary attendee data (if present) |
|
222 | + * |
|
223 | + * @var array $primary_attendee_data |
|
224 | + */ |
|
225 | + public $primary_attendee_data; |
|
226 | + |
|
227 | + /** |
|
228 | + * This is just an internal object used for passing around the incoming data. |
|
229 | + * |
|
230 | + * @var mixed $_data |
|
231 | + */ |
|
232 | + protected $_data; |
|
233 | + |
|
234 | + /** |
|
235 | + * This is just an internal object used for passing around the incoming data. |
|
236 | + * |
|
237 | + * @var mixed $incoming_data |
|
238 | + */ |
|
239 | + public $incoming_data; |
|
240 | + |
|
241 | + /** |
|
242 | + * hold objects that might be created |
|
243 | + * |
|
244 | + * @type EE_Registration $reg_obj |
|
245 | + */ |
|
246 | + public $reg_obj; |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * constructor |
|
251 | + * |
|
252 | + * @param mixed $data incoming data object|array. Suggested that child classes use type hinting for expected |
|
253 | + * data object. But here parent will be generic because we don't know what's coming in. |
|
254 | + */ |
|
255 | + public function __construct($data) |
|
256 | + { |
|
257 | + $this->_data = $data; |
|
258 | + $this->_setup_data(); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * Every child class has to setup the data object ! |
|
264 | + * |
|
265 | + * @return void |
|
266 | + */ |
|
267 | + abstract protected function _setup_data(); |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * Returns database safe representation of the data later used to when instantiating this object. |
|
272 | + * |
|
273 | + * @param mixed $data The incoming data to be prepped. |
|
274 | + * @return mixed The prepped data for db |
|
275 | + */ |
|
276 | + public static function convert_data_for_persistent_storage($data) |
|
277 | + { |
|
278 | + return $data; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
284 | + * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
285 | + * |
|
286 | + * @param $data |
|
287 | + * @return mixed |
|
288 | + */ |
|
289 | + public static function convert_data_from_persistent_storage($data) |
|
290 | + { |
|
291 | + return $data; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * only purpose is to return the data |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @return mixed the formatted data object! |
|
300 | + */ |
|
301 | + public function data() |
|
302 | + { |
|
303 | + return $this->_data; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * This helper method can be used by any incoming data handlers to setup the data correctly. All that is required |
|
309 | + * is that $this->reg_objs be set. |
|
310 | + * |
|
311 | + * @throws EE_Error |
|
312 | + * @throws InvalidDataTypeException |
|
313 | + * @throws InvalidInterfaceException |
|
314 | + * @throws InvalidArgumentException |
|
315 | + * @throws EntityNotFoundException |
|
316 | + */ |
|
317 | + protected function _assemble_data() |
|
318 | + { |
|
319 | + //verify that reg_objs is set |
|
320 | + if (! is_array($this->reg_objs) |
|
321 | + && ! reset($this->reg_objs) instanceof EE_Registration |
|
322 | + ) { |
|
323 | + throw new EE_Error( |
|
324 | + esc_html__( |
|
325 | + 'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects', |
|
326 | + 'event_espresso' |
|
327 | + ) |
|
328 | + ); |
|
329 | + } |
|
330 | + |
|
331 | + //get all attendee and events associated with the registrations in this transaction |
|
332 | + $events = $event_setup = $evtcache = $tickets = $datetimes = array(); |
|
333 | + $answers = $questions = $attendees = $line_items = $registrations = array(); |
|
334 | + $total_ticket_count = 0; |
|
335 | + |
|
336 | + if (! empty($this->reg_objs)) { |
|
337 | + $event_attendee_count = array(); |
|
338 | + /** @var EE_Registration $reg */ |
|
339 | + foreach ($this->reg_objs as $reg) { |
|
340 | + if ($this->_skip_registration_for_processing($reg) |
|
341 | + ) { |
|
342 | + continue; |
|
343 | + } |
|
344 | + |
|
345 | + $evt_id = $reg->event_ID(); |
|
346 | + /** @type EE_Ticket $ticket */ |
|
347 | + $ticket = $reg->get_first_related('Ticket'); |
|
348 | + $attendee = $reg->attendee(); |
|
349 | + $event = $reg->event(); |
|
350 | + //if none of the following entities are available, then we can't setup other data reliably, |
|
351 | + // so let's just skip. |
|
352 | + if (! $ticket instanceof EE_Ticket |
|
353 | + || ! $attendee instanceof EE_Attendee |
|
354 | + || ! $event instanceof EE_Event |
|
355 | + ) { |
|
356 | + continue; |
|
357 | + } |
|
358 | + $relateddatetime = $ticket->datetimes(); |
|
359 | + $total_ticket_count++; |
|
360 | + $tickets[$ticket->ID()]['ticket'] = $ticket; |
|
361 | + $tickets[$ticket->ID()]['count'] = is_array($tickets[$ticket->ID()]) |
|
362 | + && isset($tickets[$ticket->ID()]['count']) |
|
363 | + ? $tickets[$ticket->ID()]['count'] + 1 |
|
364 | + : 1; |
|
365 | + $tickets[$ticket->ID()]['att_objs'][$attendee->ID()] = $attendee; |
|
366 | + $tickets[$ticket->ID()]['dtt_objs'] = $relateddatetime; |
|
367 | + $tickets[$ticket->ID()]['reg_objs'][$reg->ID()] = $reg; |
|
368 | + $tickets[$ticket->ID()]['EE_Event'] = $event; |
|
369 | + $evtcache[$evt_id] = $event; |
|
370 | + $eventsetup[$evt_id]['reg_objs'][$reg->ID()] = $reg; |
|
371 | + $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()] = $ticket; |
|
372 | + $eventsetup[$evt_id]['att_objs'][$attendee->ID()] = $attendee; |
|
373 | + $event_attendee_count[$evt_id] = isset($event_attendee_count[$evt_id]) |
|
374 | + ? $event_attendee_count[$evt_id] + 1 |
|
375 | + : 0; |
|
376 | + $attendees[$reg->attendee_ID()]['line_ref'][] = $evt_id; |
|
377 | + $attendees[$reg->attendee_ID()]['att_obj'] = $attendee; |
|
378 | + $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()] = $reg; |
|
379 | + //$attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID(); |
|
380 | + $attendees[$reg->attendee_ID()]['attendee_email'] = $attendee->email(); |
|
381 | + $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket; |
|
382 | + $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id] = $event; |
|
383 | + |
|
384 | + //registrations |
|
385 | + $registrations[$reg->ID()]['tkt_obj'] = $ticket; |
|
386 | + $registrations[$reg->ID()]['evt_obj'] = $event; |
|
387 | + $registrations[$reg->ID()]['reg_obj'] = $reg; |
|
388 | + $registrations[$reg->ID()]['att_obj'] = $attendee; |
|
389 | + |
|
390 | + //set up answer objects |
|
391 | + $rel_ans = $reg->get_many_related('Answer'); |
|
392 | + foreach ($rel_ans as $ansid => $answer) { |
|
393 | + if (! isset($questions[$ansid])) { |
|
394 | + $questions[$ansid] = $answer->get_first_related('Question'); |
|
395 | + } |
|
396 | + $answers[$ansid] = $answer; |
|
397 | + $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer; |
|
398 | + } |
|
399 | + /** |
|
400 | + * @var int $dtt_id |
|
401 | + * @var EE_Datetime $datetime |
|
402 | + */ |
|
403 | + foreach ($relateddatetime as $dtt_id => $datetime) { |
|
404 | + $eventsetup[$evt_id]['dtt_objs'][$dtt_id] = $datetime; |
|
405 | + $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime; |
|
406 | + |
|
407 | + if (isset($datetimes[$dtt_id])) { |
|
408 | + continue; //already have this info in the datetimes array. |
|
409 | + } |
|
410 | + |
|
411 | + $datetimes[$dtt_id]['tkt_objs'][] = $ticket; |
|
412 | + $datetimes[$dtt_id]['datetime'] = $datetime; |
|
413 | + $datetimes[$dtt_id]['evt_objs'][$evt_id] = $event; |
|
414 | + $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg; |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + //let's loop through the unique event=>reg items and setup data on them |
|
419 | + |
|
420 | + if (! empty($eventsetup)) { |
|
421 | + foreach ($eventsetup as $evt_id => $items) { |
|
422 | + $ticket_line_items_for_event = array(); |
|
423 | + if ($this->txn instanceof EE_Transaction) { |
|
424 | + $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all( |
|
425 | + array( |
|
426 | + array( |
|
427 | + 'Ticket.Datetime.EVT_ID' => $evt_id, |
|
428 | + 'TXN_ID' => $this->txn->ID(), |
|
429 | + ), |
|
430 | + 'default_where_conditions' => 'none', |
|
431 | + ) |
|
432 | + ); |
|
433 | + } |
|
434 | + $events[$evt_id] = array( |
|
435 | + 'ID' => $evt_id, |
|
436 | + 'event' => $evtcache[$evt_id], |
|
437 | + 'name' => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '', |
|
438 | + 'total_attendees' => $event_attendee_count[$evt_id], |
|
439 | + 'reg_objs' => $items['reg_objs'], |
|
440 | + 'tkt_objs' => $items['tkt_objs'], |
|
441 | + 'att_objs' => $items['att_objs'], |
|
442 | + 'dtt_objs' => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(), |
|
443 | + 'line_items' => $ticket_line_items_for_event, |
|
444 | + ); |
|
445 | + |
|
446 | + //make sure the tickets have the line items setup for them. |
|
447 | + foreach ($ticket_line_items_for_event as $line_id => $line_item) { |
|
448 | + if ($line_item instanceof EE_Line_Item) { |
|
449 | + $tickets[$line_item->ticket()->ID()]['line_item'] = $line_item; |
|
450 | + $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children(); |
|
451 | + $line_items[$line_item->ID()]['children'] = $line_item->children(); |
|
452 | + $line_items[$line_item->ID()]['EE_Ticket'] = $line_item->ticket(); |
|
453 | + } |
|
454 | + } |
|
455 | + } |
|
456 | + } |
|
457 | + |
|
458 | + $this->grand_total_line_item = $this->txn instanceof EE_Transaction |
|
459 | + ? $this->txn->total_line_item() |
|
460 | + : null; |
|
461 | + } |
|
462 | + |
|
463 | + //lets set the attendees and events properties |
|
464 | + $this->attendees = $attendees; |
|
465 | + $this->events = $events; |
|
466 | + $this->tickets = $tickets; |
|
467 | + $this->line_items_with_children = $line_items; |
|
468 | + $this->datetimes = $datetimes; |
|
469 | + $this->questions = $questions; |
|
470 | + $this->answers = $answers; |
|
471 | + $this->total_ticket_count = $total_ticket_count; |
|
472 | + $this->registrations = $registrations; |
|
473 | + |
|
474 | + if ($this->txn instanceof EE_Transaction) { |
|
475 | + $this->tax_line_items = $this->txn->tax_items(); |
|
476 | + $this->additional_line_items = $this->txn->non_ticket_line_items(); |
|
477 | + $this->payments = $this->txn->payments(); |
|
478 | + |
|
479 | + //setup primary registration if we have a single transaction object to work with |
|
480 | + |
|
481 | + //let's get just the primary_attendee_data! First we get the primary registration object. |
|
482 | + $primary_reg = $this->txn->primary_registration(); |
|
483 | + // verify |
|
484 | + if ($primary_reg instanceof EE_Registration) { |
|
485 | + // get attendee object |
|
486 | + if ($primary_reg->attendee() instanceof EE_Attendee) { |
|
487 | + //now we can setup the primary_attendee_data array |
|
488 | + $this->primary_attendee_data = array( |
|
489 | + 'registration_id' => $primary_reg->ID(), |
|
490 | + 'att_obj' => $primary_reg->attendee(), |
|
491 | + 'reg_obj' => $primary_reg, |
|
492 | + 'primary_att_obj' => $primary_reg->attendee(), |
|
493 | + 'primary_reg_obj' => $primary_reg, |
|
494 | + ); |
|
495 | + |
|
496 | + } else { |
|
497 | + EE_Error::add_error( |
|
498 | + esc_html__( |
|
499 | + 'Incoming data does not have a valid Attendee object for the primary registrant.', |
|
500 | + 'event_espresso' |
|
501 | + ), |
|
502 | + __FILE__, |
|
503 | + __FUNCTION__, |
|
504 | + __LINE__ |
|
505 | + ); |
|
506 | + } |
|
507 | + } else { |
|
508 | + EE_Error::add_error( |
|
509 | + esc_html__( |
|
510 | + 'Incoming data does not have a valid Registration object for the primary registrant.', |
|
511 | + 'event_espresso' |
|
512 | + ), |
|
513 | + __FILE__, |
|
514 | + __FUNCTION__, |
|
515 | + __LINE__ |
|
516 | + ); |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | + |
|
521 | + /** |
|
522 | + * This simply considers whether the given registration should be processed or not based on comparison with the |
|
523 | + * filtered_reg_status property. |
|
524 | + * |
|
525 | + * @param EE_Registration $registration |
|
526 | + * @return bool returning true means we DO want to skip processing. returning false means we DON'T want to skip |
|
527 | + * processing |
|
528 | + */ |
|
529 | + protected function _skip_registration_for_processing(EE_Registration $registration) |
|
530 | + { |
|
531 | + if (empty($this->filtered_reg_status)) { |
|
532 | + return false; |
|
533 | + } |
|
534 | + |
|
535 | + //if we made it here then we just compare the filtered_reg_status with the registration status and return that |
|
536 | + return $this->filtered_reg_status !== $registration->status_ID(); |
|
537 | + } |
|
538 | 538 | |
539 | 539 | |
540 | 540 | } |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | protected function _assemble_data() |
318 | 318 | { |
319 | 319 | //verify that reg_objs is set |
320 | - if (! is_array($this->reg_objs) |
|
320 | + if ( ! is_array($this->reg_objs) |
|
321 | 321 | && ! reset($this->reg_objs) instanceof EE_Registration |
322 | 322 | ) { |
323 | 323 | throw new EE_Error( |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | $answers = $questions = $attendees = $line_items = $registrations = array(); |
334 | 334 | $total_ticket_count = 0; |
335 | 335 | |
336 | - if (! empty($this->reg_objs)) { |
|
336 | + if ( ! empty($this->reg_objs)) { |
|
337 | 337 | $event_attendee_count = array(); |
338 | 338 | /** @var EE_Registration $reg */ |
339 | 339 | foreach ($this->reg_objs as $reg) { |
@@ -344,12 +344,12 @@ discard block |
||
344 | 344 | |
345 | 345 | $evt_id = $reg->event_ID(); |
346 | 346 | /** @type EE_Ticket $ticket */ |
347 | - $ticket = $reg->get_first_related('Ticket'); |
|
347 | + $ticket = $reg->get_first_related('Ticket'); |
|
348 | 348 | $attendee = $reg->attendee(); |
349 | 349 | $event = $reg->event(); |
350 | 350 | //if none of the following entities are available, then we can't setup other data reliably, |
351 | 351 | // so let's just skip. |
352 | - if (! $ticket instanceof EE_Ticket |
|
352 | + if ( ! $ticket instanceof EE_Ticket |
|
353 | 353 | || ! $attendee instanceof EE_Attendee |
354 | 354 | || ! $event instanceof EE_Event |
355 | 355 | ) { |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | $evtcache[$evt_id] = $event; |
370 | 370 | $eventsetup[$evt_id]['reg_objs'][$reg->ID()] = $reg; |
371 | 371 | $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()] = $ticket; |
372 | - $eventsetup[$evt_id]['att_objs'][$attendee->ID()] = $attendee; |
|
372 | + $eventsetup[$evt_id]['att_objs'][$attendee->ID()] = $attendee; |
|
373 | 373 | $event_attendee_count[$evt_id] = isset($event_attendee_count[$evt_id]) |
374 | 374 | ? $event_attendee_count[$evt_id] + 1 |
375 | 375 | : 0; |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | //set up answer objects |
391 | 391 | $rel_ans = $reg->get_many_related('Answer'); |
392 | 392 | foreach ($rel_ans as $ansid => $answer) { |
393 | - if (! isset($questions[$ansid])) { |
|
393 | + if ( ! isset($questions[$ansid])) { |
|
394 | 394 | $questions[$ansid] = $answer->get_first_related('Question'); |
395 | 395 | } |
396 | 396 | $answers[$ansid] = $answer; |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | |
418 | 418 | //let's loop through the unique event=>reg items and setup data on them |
419 | 419 | |
420 | - if (! empty($eventsetup)) { |
|
420 | + if ( ! empty($eventsetup)) { |
|
421 | 421 | foreach ($eventsetup as $evt_id => $items) { |
422 | 422 | $ticket_line_items_for_event = array(); |
423 | 423 | if ($this->txn instanceof EE_Transaction) { |