@@ -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) { |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
446 | 446 | $new_question->set_system_ID( null ); |
447 | 447 | $new_question->set_wp_user( get_current_user_id() ); |
448 | - //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
449 | - $new_question->set_deleted( false ); |
|
448 | + //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
|
449 | + $new_question->set_deleted( false ); |
|
450 | 450 | $success = $new_question->save(); |
451 | 451 | if( $success ) { |
452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
@@ -501,8 +501,8 @@ discard block |
||
501 | 501 | } |
502 | 502 | // has this question been answered ? |
503 | 503 | if ( $answer instanceof EE_Answer |
504 | - && $answer->value() !== '' |
|
505 | - ) { |
|
504 | + && $answer->value() !== '' |
|
505 | + ) { |
|
506 | 506 | //answer gets htmlspecialchars called on it, undo that please |
507 | 507 | //because the form input's display strategy may call esc_attr too |
508 | 508 | //which also does html special characters |
@@ -516,10 +516,10 @@ discard block |
||
516 | 516 | } |
517 | 517 | $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() ); |
518 | 518 | if( in_array( |
519 | - $this->type(), |
|
520 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
521 | - true |
|
522 | - ) ) { |
|
519 | + $this->type(), |
|
520 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
521 | + true |
|
522 | + ) ) { |
|
523 | 523 | $input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy( |
524 | 524 | null, |
525 | 525 | min( $max_max_for_question, $this->max() ) |
@@ -632,17 +632,17 @@ discard block |
||
632 | 632 | |
633 | 633 | |
634 | 634 | |
635 | - /** |
|
636 | - * Returns whether or not this question type should have question option entries |
|
637 | - * @return bool |
|
638 | - */ |
|
635 | + /** |
|
636 | + * Returns whether or not this question type should have question option entries |
|
637 | + * @return bool |
|
638 | + */ |
|
639 | 639 | public function should_have_question_options() |
640 | - { |
|
641 | - return in_array( |
|
642 | - $this->type(), |
|
643 | - $this->_model->question_types_with_options(), |
|
644 | - true |
|
645 | - ); |
|
646 | - } |
|
640 | + { |
|
641 | + return in_array( |
|
642 | + $this->type(), |
|
643 | + $this->_model->question_types_with_options(), |
|
644 | + true |
|
645 | + ); |
|
646 | + } |
|
647 | 647 | |
648 | 648 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * date_format and the second value is the time format |
38 | 38 | * @return EE_Question |
39 | 39 | */ |
40 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
41 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
42 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
40 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
41 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
42 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * the website will be used. |
51 | 51 | * @return EE_Question |
52 | 52 | */ |
53 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
54 | - return new self( $props_n_values, TRUE, $timezone ); |
|
53 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
54 | + return new self($props_n_values, TRUE, $timezone); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | * @access public |
63 | 63 | * @param string $QST_display_text |
64 | 64 | */ |
65 | - public function set_display_text( $QST_display_text = '' ) { |
|
66 | - $this->set( 'QST_display_text', $QST_display_text ); |
|
65 | + public function set_display_text($QST_display_text = '') { |
|
66 | + $this->set('QST_display_text', $QST_display_text); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | |
@@ -74,8 +74,8 @@ discard block |
||
74 | 74 | * @access public |
75 | 75 | * @param string $QST_admin_label |
76 | 76 | */ |
77 | - public function set_admin_label( $QST_admin_label = '' ) { |
|
78 | - $this->set( 'QST_admin_label', $QST_admin_label ); |
|
77 | + public function set_admin_label($QST_admin_label = '') { |
|
78 | + $this->set('QST_admin_label', $QST_admin_label); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @access public |
87 | 87 | * @param mixed $QST_system |
88 | 88 | */ |
89 | - public function set_system_ID( $QST_system = '' ) { |
|
90 | - $this->set( 'QST_system', $QST_system ); |
|
89 | + public function set_system_ID($QST_system = '') { |
|
90 | + $this->set('QST_system', $QST_system); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | * @access public |
99 | 99 | * @param string $QST_type |
100 | 100 | */ |
101 | - public function set_question_type( $QST_type = '' ) { |
|
102 | - $this->set( 'QST_type', $QST_type ); |
|
101 | + public function set_question_type($QST_type = '') { |
|
102 | + $this->set('QST_type', $QST_type); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -110,8 +110,8 @@ discard block |
||
110 | 110 | * @access public |
111 | 111 | * @param bool $QST_required |
112 | 112 | */ |
113 | - public function set_required( $QST_required = FALSE ) { |
|
114 | - $this->set( 'QST_required', $QST_required ); |
|
113 | + public function set_required($QST_required = FALSE) { |
|
114 | + $this->set('QST_required', $QST_required); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @access public |
123 | 123 | * @param string $QST_required_text |
124 | 124 | */ |
125 | - public function set_required_text( $QST_required_text = '' ) { |
|
126 | - $this->set( 'QST_required_text', $QST_required_text ); |
|
125 | + public function set_required_text($QST_required_text = '') { |
|
126 | + $this->set('QST_required_text', $QST_required_text); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @access public |
135 | 135 | * @param int $QST_order |
136 | 136 | */ |
137 | - public function set_order( $QST_order = 0 ) { |
|
138 | - $this->set( 'QST_order', $QST_order ); |
|
137 | + public function set_order($QST_order = 0) { |
|
138 | + $this->set('QST_order', $QST_order); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * @access public |
147 | 147 | * @param bool $QST_admin_only |
148 | 148 | */ |
149 | - public function set_admin_only( $QST_admin_only = FALSE ) { |
|
150 | - $this->set( 'QST_admin_only', $QST_admin_only ); |
|
149 | + public function set_admin_only($QST_admin_only = FALSE) { |
|
150 | + $this->set('QST_admin_only', $QST_admin_only); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @access public |
159 | 159 | * @param int $QST_wp_user |
160 | 160 | */ |
161 | - public function set_wp_user( $QST_wp_user = 1 ) { |
|
162 | - $this->set( 'QST_wp_user', $QST_wp_user ); |
|
161 | + public function set_wp_user($QST_wp_user = 1) { |
|
162 | + $this->set('QST_wp_user', $QST_wp_user); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | * @access public |
176 | 176 | * @param bool $QST_deleted |
177 | 177 | */ |
178 | - public function set_deleted( $QST_deleted = FALSE ) { |
|
179 | - $this->set( 'QST_deleted', $QST_deleted ); |
|
178 | + public function set_deleted($QST_deleted = FALSE) { |
|
179 | + $this->set('QST_deleted', $QST_deleted); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @return string |
188 | 188 | */ |
189 | 189 | public function display_text() { |
190 | - return $this->get( 'QST_display_text' ); |
|
190 | + return $this->get('QST_display_text'); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @return string |
199 | 199 | */ |
200 | 200 | public function admin_label() { |
201 | - return $this->get( 'QST_admin_label' ); |
|
201 | + return $this->get('QST_admin_label'); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * @return string |
210 | 210 | */ |
211 | 211 | public function system_ID() { |
212 | - return $this->get( 'QST_system' ); |
|
212 | + return $this->get('QST_system'); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | * @return boolean |
221 | 221 | */ |
222 | 222 | public function required() { |
223 | - return $this->get( 'QST_required' ); |
|
223 | + return $this->get('QST_required'); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @return string |
233 | 233 | */ |
234 | 234 | public function required_text() { |
235 | - return $this->get( 'QST_required_text' ); |
|
235 | + return $this->get('QST_required_text'); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @return string |
244 | 244 | */ |
245 | 245 | public function type() { |
246 | - return $this->get( 'QST_type' ); |
|
246 | + return $this->get('QST_type'); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | * @return int |
256 | 256 | */ |
257 | 257 | public function order() { |
258 | - return $this->get( 'QST_order' ); |
|
258 | + return $this->get('QST_order'); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | * @return boolean |
268 | 268 | */ |
269 | 269 | public function admin_only() { |
270 | - return $this->get( 'QST_admin_only' ); |
|
270 | + return $this->get('QST_admin_only'); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | * @return int |
279 | 279 | */ |
280 | 280 | public function wp_user() { |
281 | - return $this->get( 'QST_wp_user' ); |
|
281 | + return $this->get('QST_wp_user'); |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @return boolean |
290 | 290 | */ |
291 | 291 | public function deleted() { |
292 | - return $this->get( 'QST_deleted' ); |
|
292 | + return $this->get('QST_deleted'); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @return EE_Answer[] |
300 | 300 | */ |
301 | 301 | public function answers() { |
302 | - return $this->get_many_related( 'Answer' ); |
|
302 | + return $this->get_many_related('Answer'); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | * @return boolean true = has answers, false = no answers. |
310 | 310 | */ |
311 | 311 | public function has_answers() { |
312 | - return $this->count_related( 'Answer' ) > 0 ? TRUE : FALSE; |
|
312 | + return $this->count_related('Answer') > 0 ? TRUE : FALSE; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @return EE_Question_Group[] |
320 | 320 | */ |
321 | 321 | public function question_groups() { |
322 | - return $this->get_many_related( 'Question_Group' ); |
|
322 | + return $this->get_many_related('Question_Group'); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | |
@@ -333,24 +333,24 @@ discard block |
||
333 | 333 | * whether it was trashed or not. |
334 | 334 | * @return EE_Question_Option[] |
335 | 335 | */ |
336 | - public function options( $notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL ) { |
|
337 | - if ( ! $this->ID() ) { |
|
336 | + public function options($notDeletedOptionsOnly = TRUE, $selected_value_to_always_include = NULL) { |
|
337 | + if ( ! $this->ID()) { |
|
338 | 338 | return array(); |
339 | 339 | } |
340 | 340 | $query_params = array(); |
341 | - if ( $selected_value_to_always_include ) { |
|
342 | - if ( is_array( $selected_value_to_always_include ) ) { |
|
343 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = array( 'IN', $selected_value_to_always_include ); |
|
341 | + if ($selected_value_to_always_include) { |
|
342 | + if (is_array($selected_value_to_always_include)) { |
|
343 | + $query_params[0]['OR*options-query']['QSO_value'] = array('IN', $selected_value_to_always_include); |
|
344 | 344 | } else { |
345 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_value' ] = $selected_value_to_always_include; |
|
345 | + $query_params[0]['OR*options-query']['QSO_value'] = $selected_value_to_always_include; |
|
346 | 346 | } |
347 | 347 | } |
348 | - if ( $notDeletedOptionsOnly ) { |
|
349 | - $query_params[ 0 ][ 'OR*options-query' ][ 'QSO_deleted' ] = FALSE; |
|
348 | + if ($notDeletedOptionsOnly) { |
|
349 | + $query_params[0]['OR*options-query']['QSO_deleted'] = FALSE; |
|
350 | 350 | } |
351 | 351 | //order by QSO_order |
352 | - $query_params[ 'order_by' ] = array( 'QSO_order' => 'ASC' ); |
|
353 | - return $this->get_many_related( 'Question_Option', $query_params ); |
|
352 | + $query_params['order_by'] = array('QSO_order' => 'ASC'); |
|
353 | + return $this->get_many_related('Question_Option', $query_params); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | * @return \EE_Question_Option[] |
361 | 361 | */ |
362 | 362 | public function temp_options() { |
363 | - return $this->_model_relations[ 'Question_Option' ]; |
|
363 | + return $this->_model_relations['Question_Option']; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | * @param EE_Question_Option $option |
372 | 372 | * @return boolean success |
373 | 373 | */ |
374 | - public function add_option( EE_Question_Option $option ) { |
|
375 | - return $this->_add_relation_to( $option, 'Question_Option' ); |
|
374 | + public function add_option(EE_Question_Option $option) { |
|
375 | + return $this->_add_relation_to($option, 'Question_Option'); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -382,8 +382,8 @@ discard block |
||
382 | 382 | * @param EE_Question_Option $option |
383 | 383 | * @return boolean success |
384 | 384 | */ |
385 | - public function add_temp_option( EE_Question_Option $option ) { |
|
386 | - $this->_model_relations[ 'Question_Option' ][ ] = $option; |
|
385 | + public function add_temp_option(EE_Question_Option $option) { |
|
386 | + $this->_model_relations['Question_Option'][] = $option; |
|
387 | 387 | return TRUE; |
388 | 388 | } |
389 | 389 | |
@@ -394,8 +394,8 @@ discard block |
||
394 | 394 | * @param EE_Question_Option $option |
395 | 395 | * @return boolean success |
396 | 396 | */ |
397 | - public function remove_option( EE_Question_Option $option ) { |
|
398 | - return $this->_remove_relation_to( $option, 'Question_Option' ); |
|
397 | + public function remove_option(EE_Question_Option $option) { |
|
398 | + return $this->_remove_relation_to($option, 'Question_Option'); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | |
@@ -404,8 +404,8 @@ discard block |
||
404 | 404 | * @return bool |
405 | 405 | */ |
406 | 406 | public function is_system_question() { |
407 | - $system_ID = $this->get( 'QST_system' ); |
|
408 | - return ! empty( $system_ID ) ? TRUE : FALSE; |
|
407 | + $system_ID = $this->get('QST_system'); |
|
408 | + return ! empty($system_ID) ? TRUE : FALSE; |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public function set_order_to_latest() { |
420 | 420 | $latest_order = $this->get_model()->get_latest_question_order(); |
421 | - $latest_order ++; |
|
422 | - $this->set( 'QST_order', $latest_order ); |
|
421 | + $latest_order++; |
|
422 | + $this->set('QST_order', $latest_order); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | |
@@ -438,20 +438,20 @@ discard block |
||
438 | 438 | * Duplicates this question and its question options |
439 | 439 | * @return \EE_Question |
440 | 440 | */ |
441 | - public function duplicate( $options = array() ) { |
|
441 | + public function duplicate($options = array()) { |
|
442 | 442 | $new_question = clone $this; |
443 | - $new_question->set( 'QST_ID', null ); |
|
444 | - $new_question->set_display_text( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->display_text() ) ); |
|
445 | - $new_question->set_admin_label( sprintf( __( '%s **Duplicate**', 'event_espresso' ), $this->admin_label() ) ); |
|
446 | - $new_question->set_system_ID( null ); |
|
447 | - $new_question->set_wp_user( get_current_user_id() ); |
|
443 | + $new_question->set('QST_ID', null); |
|
444 | + $new_question->set_display_text(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->display_text())); |
|
445 | + $new_question->set_admin_label(sprintf(__('%s **Duplicate**', 'event_espresso'), $this->admin_label())); |
|
446 | + $new_question->set_system_ID(null); |
|
447 | + $new_question->set_wp_user(get_current_user_id()); |
|
448 | 448 | //if we're duplicating a trashed question, assume we don't want the new one to be trashed |
449 | - $new_question->set_deleted( false ); |
|
449 | + $new_question->set_deleted(false); |
|
450 | 450 | $success = $new_question->save(); |
451 | - if( $success ) { |
|
451 | + if ($success) { |
|
452 | 452 | //we don't totally want to duplicate the question options, because we want them to be for the NEW question |
453 | - foreach( $this->options() as $question_option ) { |
|
454 | - $question_option->duplicate( array( 'QST_ID' => $new_question->ID() ) ); |
|
453 | + foreach ($this->options() as $question_option) { |
|
454 | + $question_option->duplicate(array('QST_ID' => $new_question->ID())); |
|
455 | 455 | } |
456 | 456 | return $new_question; |
457 | 457 | } else { |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * @return int|float |
465 | 465 | */ |
466 | 466 | public function max() { |
467 | - return $this->get( 'QST_max' ); |
|
467 | + return $this->get('QST_max'); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | /** |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | * @param int|float $new_max |
473 | 473 | * @return void |
474 | 474 | */ |
475 | - public function set_max( $new_max ) { |
|
476 | - $this->set( 'QST_max', $new_max ); |
|
475 | + public function set_max($new_max) { |
|
476 | + $this->set('QST_max', $new_max); |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | * @param array $input_constructor_args |
486 | 486 | * @return EE_Form_Input_Base |
487 | 487 | */ |
488 | - public function generate_form_input( $registration = null, $answer = null, $input_constructor_args = array() ) { |
|
488 | + public function generate_form_input($registration = null, $answer = null, $input_constructor_args = array()) { |
|
489 | 489 | $identifier = $this->is_system_question() ? $this->system_ID() : $this->ID(); |
490 | 490 | |
491 | 491 | $input_constructor_args = array_merge( |
@@ -496,33 +496,33 @@ discard block |
||
496 | 496 | ), |
497 | 497 | $input_constructor_args |
498 | 498 | ); |
499 | - if( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration ) { |
|
500 | - $answer = EEM_Answer::instance()->get_registration_question_answer_object( $registration, $this->ID() ); |
|
499 | + if ( ! $answer instanceof EE_Answer && $registration instanceof EE_Registration) { |
|
500 | + $answer = EEM_Answer::instance()->get_registration_question_answer_object($registration, $this->ID()); |
|
501 | 501 | } |
502 | 502 | // has this question been answered ? |
503 | - if ( $answer instanceof EE_Answer |
|
503 | + if ($answer instanceof EE_Answer |
|
504 | 504 | && $answer->value() !== '' |
505 | 505 | ) { |
506 | 506 | //answer gets htmlspecialchars called on it, undo that please |
507 | 507 | //because the form input's display strategy may call esc_attr too |
508 | 508 | //which also does html special characters |
509 | 509 | $values_with_html_special_chars = $answer->value(); |
510 | - if( is_array( $values_with_html_special_chars ) ) { |
|
511 | - $default_value = array_map( 'htmlspecialchars_decode', $values_with_html_special_chars ); |
|
510 | + if (is_array($values_with_html_special_chars)) { |
|
511 | + $default_value = array_map('htmlspecialchars_decode', $values_with_html_special_chars); |
|
512 | 512 | } else { |
513 | - $default_value = htmlspecialchars_decode( $values_with_html_special_chars ); |
|
513 | + $default_value = htmlspecialchars_decode($values_with_html_special_chars); |
|
514 | 514 | } |
515 | 515 | $input_constructor_args['default'] = $default_value; |
516 | 516 | } |
517 | - $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question( $this->system_ID() ); |
|
518 | - if( in_array( |
|
517 | + $max_max_for_question = EEM_Question::instance()->absolute_max_for_system_question($this->system_ID()); |
|
518 | + if (in_array( |
|
519 | 519 | $this->type(), |
520 | 520 | EEM_Question::instance()->questionTypesWithMaxLength(), |
521 | 521 | true |
522 | - ) ) { |
|
523 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Max_Length_Validation_Strategy( |
|
522 | + )) { |
|
523 | + $input_constructor_args['validation_strategies'][] = new EE_Max_Length_Validation_Strategy( |
|
524 | 524 | null, |
525 | - min( $max_max_for_question, $this->max() ) |
|
525 | + min($max_max_for_question, $this->max()) |
|
526 | 526 | ); |
527 | 527 | } |
528 | 528 | $input_constructor_args = apply_filters( |
@@ -534,22 +534,22 @@ discard block |
||
534 | 534 | ); |
535 | 535 | |
536 | 536 | $result = null; |
537 | - switch ( $this->type() ) { |
|
537 | + switch ($this->type()) { |
|
538 | 538 | // Text |
539 | 539 | case EEM_Question::QST_type_text : |
540 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
540 | + $result = new EE_Text_Input($input_constructor_args); |
|
541 | 541 | break; |
542 | 542 | // Textarea |
543 | 543 | case EEM_Question::QST_type_textarea : |
544 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
544 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
545 | 545 | break; |
546 | 546 | // Radio Buttons |
547 | 547 | case EEM_Question::QST_type_radio : |
548 | - $result = new EE_Radio_Button_Input( $this->options(), $input_constructor_args ); |
|
548 | + $result = new EE_Radio_Button_Input($this->options(), $input_constructor_args); |
|
549 | 549 | break; |
550 | 550 | // Dropdown |
551 | 551 | case EEM_Question::QST_type_dropdown : |
552 | - $result = new EE_Select_Input( $this->options(), $input_constructor_args ); |
|
552 | + $result = new EE_Select_Input($this->options(), $input_constructor_args); |
|
553 | 553 | break; |
554 | 554 | // State Dropdown |
555 | 555 | case EEM_Question::QST_type_state : |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | $registration, |
561 | 561 | $answer |
562 | 562 | ); |
563 | - $result = new EE_State_Select_Input( $state_options, $input_constructor_args ); |
|
563 | + $result = new EE_State_Select_Input($state_options, $input_constructor_args); |
|
564 | 564 | break; |
565 | 565 | // Country Dropdown |
566 | 566 | case EEM_Question::QST_type_country : |
@@ -571,47 +571,47 @@ discard block |
||
571 | 571 | $registration, |
572 | 572 | $answer |
573 | 573 | ); |
574 | - $result = new EE_Country_Select_Input( $country_options, $input_constructor_args ); |
|
574 | + $result = new EE_Country_Select_Input($country_options, $input_constructor_args); |
|
575 | 575 | break; |
576 | 576 | // Checkboxes |
577 | 577 | case EEM_Question::QST_type_checkbox : |
578 | - $result = new EE_Checkbox_Multi_Input( $this->options(), $input_constructor_args ); |
|
578 | + $result = new EE_Checkbox_Multi_Input($this->options(), $input_constructor_args); |
|
579 | 579 | break; |
580 | 580 | // Date |
581 | 581 | case EEM_Question::QST_type_date : |
582 | - $result = new EE_Datepicker_Input( $input_constructor_args ); |
|
582 | + $result = new EE_Datepicker_Input($input_constructor_args); |
|
583 | 583 | break; |
584 | 584 | case EEM_Question::QST_type_html_textarea : |
585 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_Simple_HTML_Validation_Strategy(); |
|
586 | - $result = new EE_Text_Area_Input( $input_constructor_args ); |
|
587 | - $result->remove_validation_strategy( 'EE_Plaintext_Validation_Strategy' ); |
|
585 | + $input_constructor_args['validation_strategies'][] = new EE_Simple_HTML_Validation_Strategy(); |
|
586 | + $result = new EE_Text_Area_Input($input_constructor_args); |
|
587 | + $result->remove_validation_strategy('EE_Plaintext_Validation_Strategy'); |
|
588 | 588 | break; |
589 | 589 | case EEM_Question::QST_type_email : |
590 | - $result = new EE_Email_Input( $input_constructor_args ); |
|
590 | + $result = new EE_Email_Input($input_constructor_args); |
|
591 | 591 | break; |
592 | 592 | case EEM_Question::QST_type_us_phone : |
593 | - $result = new EE_Phone_Input( $input_constructor_args ); |
|
593 | + $result = new EE_Phone_Input($input_constructor_args); |
|
594 | 594 | break; |
595 | 595 | case EEM_Question::QST_type_int : |
596 | - $result = new EE_Integer_Input( $input_constructor_args ); |
|
596 | + $result = new EE_Integer_Input($input_constructor_args); |
|
597 | 597 | break; |
598 | 598 | case EEM_Question::QST_type_decimal : |
599 | - $result = new EE_Float_Input( $input_constructor_args ); |
|
599 | + $result = new EE_Float_Input($input_constructor_args); |
|
600 | 600 | break; |
601 | 601 | case EEM_Question::QST_type_url : |
602 | - $input_constructor_args[ 'validation_strategies' ][] = new EE_URL_Validation_Strategy(); |
|
603 | - $result = new EE_Text_Input( $input_constructor_args ); |
|
602 | + $input_constructor_args['validation_strategies'][] = new EE_URL_Validation_Strategy(); |
|
603 | + $result = new EE_Text_Input($input_constructor_args); |
|
604 | 604 | break; |
605 | 605 | case EEM_Question::QST_type_year : |
606 | 606 | $result = new EE_Year_Input( |
607 | 607 | $input_constructor_args, |
608 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this ), |
|
609 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this ), |
|
610 | - apply_filters( 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this ) |
|
608 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__four_digit', true, $this), |
|
609 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__early_range', 100, $this), |
|
610 | + apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__year_question__end_range', 100, $this) |
|
611 | 611 | ); |
612 | 612 | break; |
613 | 613 | case EEM_Question::QST_type_multi_select : |
614 | - $result = new EE_Select_Multiple_Input( $this->options(), $input_constructor_args ); |
|
614 | + $result = new EE_Select_Multiple_Input($this->options(), $input_constructor_args); |
|
615 | 615 | break; |
616 | 616 | // fallback |
617 | 617 | default : |
@@ -622,12 +622,12 @@ discard block |
||
622 | 622 | $this, |
623 | 623 | $input_constructor_args |
624 | 624 | ); |
625 | - if( ! $default_input ){ |
|
626 | - $default_input = new EE_Text_Input( $input_constructor_args ); |
|
625 | + if ( ! $default_input) { |
|
626 | + $default_input = new EE_Text_Input($input_constructor_args); |
|
627 | 627 | } |
628 | 628 | $result = $default_input; |
629 | 629 | } |
630 | - return apply_filters( 'FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer ); |
|
630 | + return apply_filters('FHEE__EE_Question__generate_form_input__return', $result, $registration, $this, $answer); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php'); |
5 | 5 | require_once(EE_CLASSES . 'EE_Question.class.php'); |
@@ -16,431 +16,431 @@ discard block |
||
16 | 16 | class EEM_Question extends EEM_Soft_Delete_Base |
17 | 17 | { |
18 | 18 | |
19 | - // constant used to indicate that the question type is COUNTRY |
|
20 | - const QST_type_country = 'COUNTRY'; |
|
21 | - |
|
22 | - // constant used to indicate that the question type is DATE |
|
23 | - const QST_type_date = 'DATE'; |
|
24 | - |
|
25 | - // constant used to indicate that the question type is DROPDOWN |
|
26 | - const QST_type_dropdown = 'DROPDOWN'; |
|
27 | - |
|
28 | - // constant used to indicate that the question type is CHECKBOX |
|
29 | - const QST_type_checkbox = 'CHECKBOX'; |
|
30 | - |
|
31 | - // constant used to indicate that the question type is RADIO_BTN |
|
32 | - const QST_type_radio = 'RADIO_BTN'; |
|
33 | - |
|
34 | - // constant used to indicate that the question type is STATE |
|
35 | - const QST_type_state = 'STATE'; |
|
36 | - |
|
37 | - // constant used to indicate that the question type is TEXT |
|
38 | - const QST_type_text = 'TEXT'; |
|
39 | - |
|
40 | - // constant used to indicate that the question type is TEXTAREA |
|
41 | - const QST_type_textarea = 'TEXTAREA'; |
|
42 | - |
|
43 | - // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
44 | - const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
45 | - |
|
46 | - // constant used to indicate that the question type is an email input |
|
47 | - const QST_type_email = 'EMAIL'; |
|
48 | - |
|
49 | - // constant used to indicate that the question type is a US-formatted phone number |
|
50 | - const QST_type_us_phone = 'US_PHONE'; |
|
51 | - |
|
52 | - // constant used to indicate that the question type is an integer (whole number) |
|
53 | - const QST_type_int = 'INTEGER'; |
|
54 | - |
|
55 | - // constant used to indicate that the question type is a decimal (float) |
|
56 | - const QST_type_decimal = 'DECIMAL'; |
|
57 | - |
|
58 | - // constant used to indicate that the question type is a valid URL |
|
59 | - const QST_type_url = 'URL'; |
|
60 | - |
|
61 | - // constant used to indicate that the question type is a YEAR |
|
62 | - const QST_type_year = 'YEAR'; |
|
63 | - |
|
64 | - // constant used to indicate that the question type is a multi-select |
|
65 | - const QST_type_multi_select = 'MULTI_SELECT'; |
|
66 | - |
|
67 | - /** |
|
68 | - * Question types that are interchangeable, even after answers have been provided for them. |
|
69 | - * Top-level keys are category slugs, next level is an array of question types. If question types |
|
70 | - * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
71 | - * |
|
72 | - * @access protected |
|
73 | - * @var array $_question_type_categories { |
|
74 | - * @type string $text |
|
75 | - * @type string $single -answer-enum |
|
76 | - * @type string $multi -answer-enum |
|
77 | - * } |
|
78 | - */ |
|
79 | - protected $_question_type_categories = array(); |
|
80 | - |
|
81 | - /** |
|
82 | - * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
83 | - * |
|
84 | - * @access protected |
|
85 | - * @var array $_allowed_question_types |
|
86 | - */ |
|
87 | - protected $_allowed_question_types = array(); |
|
88 | - |
|
89 | - /** |
|
90 | - * brief descriptions for all the question types |
|
91 | - * |
|
92 | - * @access protected |
|
93 | - * @var EEM_Question $_instance |
|
94 | - */ |
|
95 | - protected $_question_descriptions; |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Question types that should have an admin-defined max input length |
|
100 | - * @var array |
|
101 | - */ |
|
102 | - protected $question_types_with_max_lengh; |
|
103 | - |
|
104 | - |
|
105 | - // private instance of the Attendee object |
|
106 | - protected static $_instance = NULL; |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * EEM_Question constructor. |
|
111 | - * |
|
112 | - * @param null $timezone |
|
113 | - */ |
|
114 | - protected function __construct($timezone = NULL) |
|
115 | - { |
|
116 | - $this->singular_item = __('Question', 'event_espresso'); |
|
117 | - $this->plural_item = __('Questions', 'event_espresso'); |
|
118 | - $this->_allowed_question_types = apply_filters( |
|
119 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
120 | - array( |
|
121 | - EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
122 | - EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
123 | - EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
124 | - EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
125 | - EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
126 | - EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
127 | - EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
128 | - EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
129 | - EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
130 | - EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
131 | - EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
132 | - EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
133 | - EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
134 | - EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
135 | - EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
136 | - EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
137 | - ) |
|
138 | - ); |
|
139 | - $this->_question_descriptions = apply_filters( |
|
140 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
141 | - array( |
|
142 | - EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
143 | - EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
144 | - EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
145 | - EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
146 | - EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
147 | - EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
148 | - EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
149 | - EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
150 | - EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
151 | - EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
152 | - EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
153 | - EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
154 | - EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
155 | - EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
156 | - EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
157 | - EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
158 | - ) |
|
159 | - ); |
|
160 | - $this->_question_type_categories = (array)apply_filters( |
|
161 | - 'FHEE__EEM_Question__construct__question_type_categories', |
|
162 | - array( |
|
163 | - 'text' => array( |
|
164 | - EEM_Question::QST_type_text, |
|
165 | - EEM_Question::QST_type_textarea, |
|
166 | - EEM_Question::QST_type_date, |
|
167 | - EEM_Question::QST_type_html_textarea, |
|
168 | - EEM_Question::QST_type_email, |
|
169 | - EEM_Question::QST_type_us_phone, |
|
170 | - EEM_Question::QST_type_decimal, |
|
171 | - EEM_Question::QST_type_int, |
|
172 | - EEM_Question::QST_type_url, |
|
173 | - EEM_Question::QST_type_year |
|
174 | - ), |
|
175 | - 'single-answer-enum' => array( |
|
176 | - EEM_Question::QST_type_radio, |
|
177 | - EEM_Question::QST_type_dropdown |
|
178 | - ), |
|
179 | - 'multi-answer-enum' => array( |
|
180 | - EEM_Question::QST_type_checkbox, |
|
181 | - EEM_Question::QST_type_multi_select |
|
182 | - ) |
|
183 | - ) |
|
184 | - ); |
|
185 | - $this->question_types_with_max_lengh = apply_filters( |
|
186 | - 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
187 | - array( |
|
188 | - EEM_Question::QST_type_text, |
|
189 | - EEM_Question::QST_type_textarea, |
|
190 | - EEM_Question::QST_type_html_textarea |
|
191 | - ) |
|
192 | - ); |
|
193 | - |
|
194 | - $this->_tables = array( |
|
195 | - 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
196 | - ); |
|
197 | - $this->_fields = array( |
|
198 | - 'Question' => array( |
|
199 | - 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
200 | - 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
201 | - 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
202 | - 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
203 | - 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
204 | - 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
205 | - 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
206 | - 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
207 | - 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
208 | - 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
209 | - 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
210 | - 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
211 | - ) |
|
212 | - ); |
|
213 | - $this->_model_relations = array( |
|
214 | - 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
215 | - 'Question_Option' => new EE_Has_Many_Relation(), |
|
216 | - 'Answer' => new EE_Has_Many_Relation(), |
|
217 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
218 | - //for QST_order column |
|
219 | - 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
220 | - ); |
|
221 | - //this model is generally available for reading |
|
222 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
223 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
224 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
225 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
226 | - parent::__construct($timezone); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
231 | - * but they can be extended |
|
232 | - * @return string[] |
|
233 | - */ |
|
234 | - public function allowed_question_types() |
|
235 | - { |
|
236 | - return $this->_allowed_question_types; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets all the question types in the same category |
|
241 | - * @param string $question_type one of EEM_Question::allowed_question_types( |
|
242 | - * @return string[] like EEM_Question::allowed_question_types() |
|
243 | - */ |
|
244 | - public function question_types_in_same_category($question_type) |
|
245 | - { |
|
246 | - $question_types = array($question_type); |
|
247 | - foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
248 | - if (in_array($question_type, $question_types_in_category)) { |
|
249 | - $question_types = $question_types_in_category; |
|
250 | - break; |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Determines if the given question type is in the given question type category |
|
259 | - * @param string $question_type one of EEM_Question::allowed_question_types() |
|
260 | - * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
261 | - * @return boolean |
|
262 | - */ |
|
263 | - public function question_type_is_in_category($question_type, $category) |
|
264 | - { |
|
265 | - if (!isset($this->_question_type_categories[$category])) { |
|
266 | - return false; |
|
267 | - } |
|
268 | - return in_array($question_type, $this->_question_type_categories[$category]); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Returns all the question types in the given category |
|
274 | - * @param string $category |
|
275 | - * @return array|mixed |
|
276 | - */ |
|
277 | - public function question_types_in_category($category) |
|
278 | - { |
|
279 | - if (isset($this->_question_type_categories[$category])) { |
|
280 | - return $this->_question_type_categories[$category]; |
|
281 | - } |
|
282 | - return array(); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Returns all the question types that should have question options |
|
288 | - * @return array |
|
289 | - */ |
|
290 | - public function question_types_with_options() |
|
291 | - { |
|
292 | - return array_merge( |
|
293 | - $this->question_types_in_category('single-answer-enum'), |
|
294 | - $this->question_types_in_category('multi-answer-enum') |
|
295 | - ); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Returns the question type categories 2d array |
|
300 | - * @return array see EEM_Question::_question_type_categories |
|
301 | - */ |
|
302 | - public function question_type_categories() |
|
303 | - { |
|
304 | - return $this->_question_type_categories; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns an array of all the QST_system values that can be allowed in the system question group |
|
309 | - * identified by $system_question_group_id |
|
310 | - * @param string $system_question_group_id QSG_system |
|
311 | - * @return array of system question names (QST_system) |
|
312 | - */ |
|
313 | - public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
314 | - { |
|
315 | - $question_system_ids = array(); |
|
316 | - switch ($system_question_group_id) { |
|
317 | - case EEM_Question_Group::system_personal: |
|
318 | - $question_system_ids = array( |
|
319 | - EEM_Attendee::system_question_fname, |
|
320 | - EEM_Attendee::system_question_lname, |
|
321 | - EEM_Attendee::system_question_email, |
|
322 | - EEM_Attendee::system_question_phone |
|
323 | - ); |
|
324 | - break; |
|
325 | - case EEM_Question_Group::system_address: |
|
326 | - $question_system_ids = array( |
|
327 | - EEM_Attendee::system_question_address, |
|
328 | - EEM_Attendee::system_question_address2, |
|
329 | - EEM_Attendee::system_question_city, |
|
330 | - EEM_Attendee::system_question_state, |
|
331 | - EEM_Attendee::system_question_country, |
|
332 | - EEM_Attendee::system_question_zip, |
|
333 | - EEM_Attendee::system_question_phone |
|
334 | - ); |
|
335 | - break; |
|
336 | - } |
|
337 | - return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Returns an array of all the QST_system values that are required in the system question group |
|
342 | - * identified by $system_question_group_id |
|
343 | - * @param string $system_question_group_id QSG_system |
|
344 | - * @return array of system question names (QST_system) |
|
345 | - */ |
|
346 | - public function required_system_questions_in_system_question_group($system_question_group_id) |
|
347 | - { |
|
348 | - $question_system_ids = null; |
|
349 | - switch ($system_question_group_id) { |
|
350 | - case EEM_Question_Group::system_personal: |
|
351 | - $question_system_ids = array( |
|
352 | - EEM_Attendee::system_question_fname, |
|
353 | - EEM_Attendee::system_question_email, |
|
354 | - ); |
|
355 | - break; |
|
356 | - default: |
|
357 | - $question_system_ids = array(); |
|
358 | - } |
|
359 | - return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
365 | - * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
366 | - * @param $QST_system |
|
367 | - * @return int of QST_ID for the question that corresponds to that QST_system |
|
368 | - */ |
|
369 | - public function get_Question_ID_from_system_string($QST_system) |
|
370 | - { |
|
371 | - return $this->get_var(array(array('QST_system' => $QST_system))); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * searches the db for the question with the latest question order and returns that value. |
|
377 | - * @access public |
|
378 | - * @return int |
|
379 | - */ |
|
380 | - public function get_latest_question_order() |
|
381 | - { |
|
382 | - $columns_to_select = array( |
|
383 | - 'max_order' => array("MAX(QST_order)", "%d") |
|
384 | - ); |
|
385 | - $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
386 | - return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Returns an array where keys are system question QST_system values, |
|
391 | - * and values are the highest question max the admin can set on the question |
|
392 | - * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
393 | - * of 5, but no larger than 12) |
|
394 | - * @return array |
|
395 | - */ |
|
396 | - public function system_question_maxes() |
|
397 | - { |
|
398 | - return array( |
|
399 | - 'fname' => 45, |
|
400 | - 'lname' => 45, |
|
401 | - 'address' => 255, |
|
402 | - 'address2' => 255, |
|
403 | - 'city' => 45, |
|
404 | - 'zip' => 12, |
|
405 | - 'email' => 255, |
|
406 | - 'phone' => 45, |
|
407 | - ); |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Given a QST_system value, gets the question's largest allowable max input. |
|
412 | - * @see Registration_Form_Admin_Page::system_question_maxes() |
|
413 | - * @param string $system_question_value |
|
414 | - * @return int|float |
|
415 | - */ |
|
416 | - public function absolute_max_for_system_question($system_question_value) |
|
417 | - { |
|
418 | - $maxes = $this->system_question_maxes(); |
|
419 | - if (isset($maxes[$system_question_value])) { |
|
420 | - return $maxes[$system_question_value]; |
|
421 | - } else { |
|
422 | - return EE_INF; |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * @return array |
|
429 | - */ |
|
430 | - public function question_descriptions() |
|
431 | - { |
|
432 | - return $this->_question_descriptions; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Returns all the question types that should have an admin-defined max input length |
|
438 | - * @return array |
|
439 | - */ |
|
440 | - public function questionTypesWithMaxLength() |
|
441 | - { |
|
442 | - return (array)$this->question_types_with_max_lengh; |
|
443 | - } |
|
19 | + // constant used to indicate that the question type is COUNTRY |
|
20 | + const QST_type_country = 'COUNTRY'; |
|
21 | + |
|
22 | + // constant used to indicate that the question type is DATE |
|
23 | + const QST_type_date = 'DATE'; |
|
24 | + |
|
25 | + // constant used to indicate that the question type is DROPDOWN |
|
26 | + const QST_type_dropdown = 'DROPDOWN'; |
|
27 | + |
|
28 | + // constant used to indicate that the question type is CHECKBOX |
|
29 | + const QST_type_checkbox = 'CHECKBOX'; |
|
30 | + |
|
31 | + // constant used to indicate that the question type is RADIO_BTN |
|
32 | + const QST_type_radio = 'RADIO_BTN'; |
|
33 | + |
|
34 | + // constant used to indicate that the question type is STATE |
|
35 | + const QST_type_state = 'STATE'; |
|
36 | + |
|
37 | + // constant used to indicate that the question type is TEXT |
|
38 | + const QST_type_text = 'TEXT'; |
|
39 | + |
|
40 | + // constant used to indicate that the question type is TEXTAREA |
|
41 | + const QST_type_textarea = 'TEXTAREA'; |
|
42 | + |
|
43 | + // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
44 | + const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
45 | + |
|
46 | + // constant used to indicate that the question type is an email input |
|
47 | + const QST_type_email = 'EMAIL'; |
|
48 | + |
|
49 | + // constant used to indicate that the question type is a US-formatted phone number |
|
50 | + const QST_type_us_phone = 'US_PHONE'; |
|
51 | + |
|
52 | + // constant used to indicate that the question type is an integer (whole number) |
|
53 | + const QST_type_int = 'INTEGER'; |
|
54 | + |
|
55 | + // constant used to indicate that the question type is a decimal (float) |
|
56 | + const QST_type_decimal = 'DECIMAL'; |
|
57 | + |
|
58 | + // constant used to indicate that the question type is a valid URL |
|
59 | + const QST_type_url = 'URL'; |
|
60 | + |
|
61 | + // constant used to indicate that the question type is a YEAR |
|
62 | + const QST_type_year = 'YEAR'; |
|
63 | + |
|
64 | + // constant used to indicate that the question type is a multi-select |
|
65 | + const QST_type_multi_select = 'MULTI_SELECT'; |
|
66 | + |
|
67 | + /** |
|
68 | + * Question types that are interchangeable, even after answers have been provided for them. |
|
69 | + * Top-level keys are category slugs, next level is an array of question types. If question types |
|
70 | + * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
71 | + * |
|
72 | + * @access protected |
|
73 | + * @var array $_question_type_categories { |
|
74 | + * @type string $text |
|
75 | + * @type string $single -answer-enum |
|
76 | + * @type string $multi -answer-enum |
|
77 | + * } |
|
78 | + */ |
|
79 | + protected $_question_type_categories = array(); |
|
80 | + |
|
81 | + /** |
|
82 | + * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
83 | + * |
|
84 | + * @access protected |
|
85 | + * @var array $_allowed_question_types |
|
86 | + */ |
|
87 | + protected $_allowed_question_types = array(); |
|
88 | + |
|
89 | + /** |
|
90 | + * brief descriptions for all the question types |
|
91 | + * |
|
92 | + * @access protected |
|
93 | + * @var EEM_Question $_instance |
|
94 | + */ |
|
95 | + protected $_question_descriptions; |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Question types that should have an admin-defined max input length |
|
100 | + * @var array |
|
101 | + */ |
|
102 | + protected $question_types_with_max_lengh; |
|
103 | + |
|
104 | + |
|
105 | + // private instance of the Attendee object |
|
106 | + protected static $_instance = NULL; |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * EEM_Question constructor. |
|
111 | + * |
|
112 | + * @param null $timezone |
|
113 | + */ |
|
114 | + protected function __construct($timezone = NULL) |
|
115 | + { |
|
116 | + $this->singular_item = __('Question', 'event_espresso'); |
|
117 | + $this->plural_item = __('Questions', 'event_espresso'); |
|
118 | + $this->_allowed_question_types = apply_filters( |
|
119 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
120 | + array( |
|
121 | + EEM_Question::QST_type_text => __('Text', 'event_espresso'), |
|
122 | + EEM_Question::QST_type_textarea => __('Textarea', 'event_espresso'), |
|
123 | + EEM_Question::QST_type_checkbox => __('Checkboxes', 'event_espresso'), |
|
124 | + EEM_Question::QST_type_radio => __('Radio Buttons', 'event_espresso'), |
|
125 | + EEM_Question::QST_type_dropdown => __('Dropdown', 'event_espresso'), |
|
126 | + EEM_Question::QST_type_state => __('State/Province Dropdown', 'event_espresso'), |
|
127 | + EEM_Question::QST_type_country => __('Country Dropdown', 'event_espresso'), |
|
128 | + EEM_Question::QST_type_date => __('Date Picker', 'event_espresso'), |
|
129 | + EEM_Question::QST_type_html_textarea => __('HTML Textarea', 'event_espresso'), |
|
130 | + EEM_Question::QST_type_email => __('Email', 'event_espresso'), |
|
131 | + EEM_Question::QST_type_us_phone => __('USA - Format Phone', 'event_espresso'), |
|
132 | + EEM_Question::QST_type_decimal => __('Number', 'event_espresso'), |
|
133 | + EEM_Question::QST_type_int => __('Whole Number', 'event_espresso'), |
|
134 | + EEM_Question::QST_type_url => __('URL', 'event_espresso'), |
|
135 | + EEM_Question::QST_type_year => __('Year', 'event_espresso'), |
|
136 | + EEM_Question::QST_type_multi_select => __('Multi Select', 'event_espresso') |
|
137 | + ) |
|
138 | + ); |
|
139 | + $this->_question_descriptions = apply_filters( |
|
140 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
141 | + array( |
|
142 | + EEM_Question::QST_type_text => __('A single line text input field', 'event_espresso'), |
|
143 | + EEM_Question::QST_type_textarea => __('A multi line text input field', 'event_espresso'), |
|
144 | + EEM_Question::QST_type_checkbox => __('Allows multiple preset options to be selected', 'event_espresso'), |
|
145 | + EEM_Question::QST_type_radio => __('Allows a single preset option to be selected', 'event_espresso'), |
|
146 | + EEM_Question::QST_type_dropdown => __('A dropdown that allows a single selection', 'event_espresso'), |
|
147 | + EEM_Question::QST_type_state => __('A dropdown that lists states/provinces', 'event_espresso'), |
|
148 | + EEM_Question::QST_type_country => __('A dropdown that lists countries', 'event_espresso'), |
|
149 | + EEM_Question::QST_type_date => __('A popup calendar that allows date selections', 'event_espresso'), |
|
150 | + EEM_Question::QST_type_html_textarea => __('A multi line text input field that allows HTML', 'event_espresso'), |
|
151 | + EEM_Question::QST_type_email => __('A text field that must contain a valid Email address', 'event_espresso'), |
|
152 | + EEM_Question::QST_type_us_phone => __('A text field that must contain a valid US phone number', 'event_espresso'), |
|
153 | + EEM_Question::QST_type_decimal => __('A text field that allows number values with decimals', 'event_espresso'), |
|
154 | + EEM_Question::QST_type_int => __('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
155 | + EEM_Question::QST_type_url => __('A text field that must contain a valid URL', 'event_espresso'), |
|
156 | + EEM_Question::QST_type_year => __('A dropdown that lists the last 100 years', 'event_espresso'), |
|
157 | + EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
|
158 | + ) |
|
159 | + ); |
|
160 | + $this->_question_type_categories = (array)apply_filters( |
|
161 | + 'FHEE__EEM_Question__construct__question_type_categories', |
|
162 | + array( |
|
163 | + 'text' => array( |
|
164 | + EEM_Question::QST_type_text, |
|
165 | + EEM_Question::QST_type_textarea, |
|
166 | + EEM_Question::QST_type_date, |
|
167 | + EEM_Question::QST_type_html_textarea, |
|
168 | + EEM_Question::QST_type_email, |
|
169 | + EEM_Question::QST_type_us_phone, |
|
170 | + EEM_Question::QST_type_decimal, |
|
171 | + EEM_Question::QST_type_int, |
|
172 | + EEM_Question::QST_type_url, |
|
173 | + EEM_Question::QST_type_year |
|
174 | + ), |
|
175 | + 'single-answer-enum' => array( |
|
176 | + EEM_Question::QST_type_radio, |
|
177 | + EEM_Question::QST_type_dropdown |
|
178 | + ), |
|
179 | + 'multi-answer-enum' => array( |
|
180 | + EEM_Question::QST_type_checkbox, |
|
181 | + EEM_Question::QST_type_multi_select |
|
182 | + ) |
|
183 | + ) |
|
184 | + ); |
|
185 | + $this->question_types_with_max_lengh = apply_filters( |
|
186 | + 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
187 | + array( |
|
188 | + EEM_Question::QST_type_text, |
|
189 | + EEM_Question::QST_type_textarea, |
|
190 | + EEM_Question::QST_type_html_textarea |
|
191 | + ) |
|
192 | + ); |
|
193 | + |
|
194 | + $this->_tables = array( |
|
195 | + 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
196 | + ); |
|
197 | + $this->_fields = array( |
|
198 | + 'Question' => array( |
|
199 | + 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso')), |
|
200 | + 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', __('Question Text', 'event_espresso'), true, ''), |
|
201 | + 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', __('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
202 | + 'QST_system' => new EE_Plain_Text_Field('QST_system', __('Internal string ID for question', 'event_espresso'), false, ''), |
|
203 | + 'QST_type' => new EE_Enum_Text_Field('QST_type', __('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
204 | + 'QST_required' => new EE_Boolean_Field('QST_required', __('Required Question?', 'event_espresso'), false, false), |
|
205 | + 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', __('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
206 | + 'QST_order' => new EE_Integer_Field('QST_order', __('Question Order', 'event_espresso'), false, 0), |
|
207 | + 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', __('Admin-Only Question?', 'event_espresso'), false, false), |
|
208 | + 'QST_max' => new EE_Infinite_Integer_Field('QST_max', __('Max Size', 'event_espresso'), false, EE_INF), |
|
209 | + 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', __('Question Creator ID', 'event_espresso'), false), |
|
210 | + 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', __('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
211 | + ) |
|
212 | + ); |
|
213 | + $this->_model_relations = array( |
|
214 | + 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
215 | + 'Question_Option' => new EE_Has_Many_Relation(), |
|
216 | + 'Answer' => new EE_Has_Many_Relation(), |
|
217 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
218 | + //for QST_order column |
|
219 | + 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
220 | + ); |
|
221 | + //this model is generally available for reading |
|
222 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
223 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
224 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
225 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
226 | + parent::__construct($timezone); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
231 | + * but they can be extended |
|
232 | + * @return string[] |
|
233 | + */ |
|
234 | + public function allowed_question_types() |
|
235 | + { |
|
236 | + return $this->_allowed_question_types; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets all the question types in the same category |
|
241 | + * @param string $question_type one of EEM_Question::allowed_question_types( |
|
242 | + * @return string[] like EEM_Question::allowed_question_types() |
|
243 | + */ |
|
244 | + public function question_types_in_same_category($question_type) |
|
245 | + { |
|
246 | + $question_types = array($question_type); |
|
247 | + foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
248 | + if (in_array($question_type, $question_types_in_category)) { |
|
249 | + $question_types = $question_types_in_category; |
|
250 | + break; |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Determines if the given question type is in the given question type category |
|
259 | + * @param string $question_type one of EEM_Question::allowed_question_types() |
|
260 | + * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
261 | + * @return boolean |
|
262 | + */ |
|
263 | + public function question_type_is_in_category($question_type, $category) |
|
264 | + { |
|
265 | + if (!isset($this->_question_type_categories[$category])) { |
|
266 | + return false; |
|
267 | + } |
|
268 | + return in_array($question_type, $this->_question_type_categories[$category]); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Returns all the question types in the given category |
|
274 | + * @param string $category |
|
275 | + * @return array|mixed |
|
276 | + */ |
|
277 | + public function question_types_in_category($category) |
|
278 | + { |
|
279 | + if (isset($this->_question_type_categories[$category])) { |
|
280 | + return $this->_question_type_categories[$category]; |
|
281 | + } |
|
282 | + return array(); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Returns all the question types that should have question options |
|
288 | + * @return array |
|
289 | + */ |
|
290 | + public function question_types_with_options() |
|
291 | + { |
|
292 | + return array_merge( |
|
293 | + $this->question_types_in_category('single-answer-enum'), |
|
294 | + $this->question_types_in_category('multi-answer-enum') |
|
295 | + ); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Returns the question type categories 2d array |
|
300 | + * @return array see EEM_Question::_question_type_categories |
|
301 | + */ |
|
302 | + public function question_type_categories() |
|
303 | + { |
|
304 | + return $this->_question_type_categories; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns an array of all the QST_system values that can be allowed in the system question group |
|
309 | + * identified by $system_question_group_id |
|
310 | + * @param string $system_question_group_id QSG_system |
|
311 | + * @return array of system question names (QST_system) |
|
312 | + */ |
|
313 | + public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
314 | + { |
|
315 | + $question_system_ids = array(); |
|
316 | + switch ($system_question_group_id) { |
|
317 | + case EEM_Question_Group::system_personal: |
|
318 | + $question_system_ids = array( |
|
319 | + EEM_Attendee::system_question_fname, |
|
320 | + EEM_Attendee::system_question_lname, |
|
321 | + EEM_Attendee::system_question_email, |
|
322 | + EEM_Attendee::system_question_phone |
|
323 | + ); |
|
324 | + break; |
|
325 | + case EEM_Question_Group::system_address: |
|
326 | + $question_system_ids = array( |
|
327 | + EEM_Attendee::system_question_address, |
|
328 | + EEM_Attendee::system_question_address2, |
|
329 | + EEM_Attendee::system_question_city, |
|
330 | + EEM_Attendee::system_question_state, |
|
331 | + EEM_Attendee::system_question_country, |
|
332 | + EEM_Attendee::system_question_zip, |
|
333 | + EEM_Attendee::system_question_phone |
|
334 | + ); |
|
335 | + break; |
|
336 | + } |
|
337 | + return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Returns an array of all the QST_system values that are required in the system question group |
|
342 | + * identified by $system_question_group_id |
|
343 | + * @param string $system_question_group_id QSG_system |
|
344 | + * @return array of system question names (QST_system) |
|
345 | + */ |
|
346 | + public function required_system_questions_in_system_question_group($system_question_group_id) |
|
347 | + { |
|
348 | + $question_system_ids = null; |
|
349 | + switch ($system_question_group_id) { |
|
350 | + case EEM_Question_Group::system_personal: |
|
351 | + $question_system_ids = array( |
|
352 | + EEM_Attendee::system_question_fname, |
|
353 | + EEM_Attendee::system_question_email, |
|
354 | + ); |
|
355 | + break; |
|
356 | + default: |
|
357 | + $question_system_ids = array(); |
|
358 | + } |
|
359 | + return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
365 | + * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
366 | + * @param $QST_system |
|
367 | + * @return int of QST_ID for the question that corresponds to that QST_system |
|
368 | + */ |
|
369 | + public function get_Question_ID_from_system_string($QST_system) |
|
370 | + { |
|
371 | + return $this->get_var(array(array('QST_system' => $QST_system))); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * searches the db for the question with the latest question order and returns that value. |
|
377 | + * @access public |
|
378 | + * @return int |
|
379 | + */ |
|
380 | + public function get_latest_question_order() |
|
381 | + { |
|
382 | + $columns_to_select = array( |
|
383 | + 'max_order' => array("MAX(QST_order)", "%d") |
|
384 | + ); |
|
385 | + $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
386 | + return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Returns an array where keys are system question QST_system values, |
|
391 | + * and values are the highest question max the admin can set on the question |
|
392 | + * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
393 | + * of 5, but no larger than 12) |
|
394 | + * @return array |
|
395 | + */ |
|
396 | + public function system_question_maxes() |
|
397 | + { |
|
398 | + return array( |
|
399 | + 'fname' => 45, |
|
400 | + 'lname' => 45, |
|
401 | + 'address' => 255, |
|
402 | + 'address2' => 255, |
|
403 | + 'city' => 45, |
|
404 | + 'zip' => 12, |
|
405 | + 'email' => 255, |
|
406 | + 'phone' => 45, |
|
407 | + ); |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Given a QST_system value, gets the question's largest allowable max input. |
|
412 | + * @see Registration_Form_Admin_Page::system_question_maxes() |
|
413 | + * @param string $system_question_value |
|
414 | + * @return int|float |
|
415 | + */ |
|
416 | + public function absolute_max_for_system_question($system_question_value) |
|
417 | + { |
|
418 | + $maxes = $this->system_question_maxes(); |
|
419 | + if (isset($maxes[$system_question_value])) { |
|
420 | + return $maxes[$system_question_value]; |
|
421 | + } else { |
|
422 | + return EE_INF; |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * @return array |
|
429 | + */ |
|
430 | + public function question_descriptions() |
|
431 | + { |
|
432 | + return $this->_question_descriptions; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Returns all the question types that should have an admin-defined max input length |
|
438 | + * @return array |
|
439 | + */ |
|
440 | + public function questionTypesWithMaxLength() |
|
441 | + { |
|
442 | + return (array)$this->question_types_with_max_lengh; |
|
443 | + } |
|
444 | 444 | |
445 | 445 | |
446 | 446 | } |
@@ -1,8 +1,8 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | -require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php'); |
|
5 | -require_once(EE_CLASSES . 'EE_Question.class.php'); |
|
4 | +require_once(EE_MODELS.'EEM_Soft_Delete_Base.model.php'); |
|
5 | +require_once(EE_CLASSES.'EE_Question.class.php'); |
|
6 | 6 | |
7 | 7 | |
8 | 8 | /** |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | EEM_Question::QST_type_multi_select => __('A dropdown that allows multiple selections', 'event_espresso') |
158 | 158 | ) |
159 | 159 | ); |
160 | - $this->_question_type_categories = (array)apply_filters( |
|
160 | + $this->_question_type_categories = (array) apply_filters( |
|
161 | 161 | 'FHEE__EEM_Question__construct__question_type_categories', |
162 | 162 | array( |
163 | 163 | 'text' => array( |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | */ |
263 | 263 | public function question_type_is_in_category($question_type, $category) |
264 | 264 | { |
265 | - if (!isset($this->_question_type_categories[$category])) { |
|
265 | + if ( ! isset($this->_question_type_categories[$category])) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | return in_array($question_type, $this->_question_type_categories[$category]); |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | */ |
440 | 440 | public function questionTypesWithMaxLength() |
441 | 441 | { |
442 | - return (array)$this->question_types_with_max_lengh; |
|
442 | + return (array) $this->question_types_with_max_lengh; |
|
443 | 443 | } |
444 | 444 | |
445 | 445 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -28,621 +28,621 @@ discard block |
||
28 | 28 | class Registration_Form_Admin_Page extends EE_Admin_Page |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * _question |
|
33 | - * holds the specific question object for the question details screen |
|
34 | - * |
|
35 | - * @var EE_Question $_question |
|
36 | - */ |
|
37 | - protected $_question; |
|
38 | - |
|
39 | - /** |
|
40 | - * _question_group |
|
41 | - * holds the specific question group object for the question group details screen |
|
42 | - * |
|
43 | - * @var EE_Question_Group $_question_group |
|
44 | - */ |
|
45 | - protected $_question_group; |
|
46 | - |
|
47 | - /** |
|
48 | - *_question_model EEM_Question model instance (for queries) |
|
49 | - * |
|
50 | - * @var EEM_Question $_question_model ; |
|
51 | - */ |
|
52 | - protected $_question_model; |
|
53 | - |
|
54 | - /** |
|
55 | - * _question_group_model EEM_Question_group instance (for queries) |
|
56 | - * |
|
57 | - * @var EEM_Question_Group $_question_group_model |
|
58 | - */ |
|
59 | - protected $_question_group_model; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @Constructor |
|
64 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
65 | - * @access public |
|
66 | - */ |
|
67 | - public function __construct($routing = true) |
|
68 | - { |
|
69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
71 | - $this->_question_model = EEM_Question::instance(); |
|
72 | - $this->_question_group_model = EEM_Question_Group::instance(); |
|
73 | - parent::__construct($routing); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - protected function _init_page_props() |
|
78 | - { |
|
79 | - $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
80 | - $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
81 | - $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
82 | - $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - protected function _ajax_hooks() |
|
87 | - { |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - protected function _define_page_props() |
|
92 | - { |
|
93 | - $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
94 | - $this->_labels = array( |
|
95 | - 'buttons' => array( |
|
96 | - 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
97 | - ), |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - *_set_page_routes |
|
104 | - */ |
|
105 | - protected function _set_page_routes() |
|
106 | - { |
|
107 | - $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
108 | - $this->_page_routes = array( |
|
109 | - 'default' => array( |
|
110 | - 'func' => '_questions_overview_list_table', |
|
111 | - 'capability' => 'ee_read_questions', |
|
112 | - ), |
|
113 | - |
|
114 | - 'edit_question' => array( |
|
115 | - 'func' => '_edit_question', |
|
116 | - 'capability' => 'ee_edit_question', |
|
117 | - 'obj_id' => $qst_id, |
|
118 | - 'args' => array('edit'), |
|
119 | - ), |
|
120 | - |
|
121 | - 'question_groups' => array( |
|
122 | - 'func' => '_questions_groups_preview', |
|
123 | - 'capability' => 'ee_read_question_groups', |
|
124 | - ), |
|
125 | - |
|
126 | - 'update_question' => array( |
|
127 | - 'func' => '_insert_or_update_question', |
|
128 | - 'args' => array('new_question' => false), |
|
129 | - 'capability' => 'ee_edit_question', |
|
130 | - 'obj_id' => $qst_id, |
|
131 | - 'noheader' => true, |
|
132 | - ), |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - protected function _set_page_config() |
|
138 | - { |
|
139 | - $this->_page_config = array( |
|
140 | - 'default' => array( |
|
141 | - 'nav' => array( |
|
142 | - 'label' => esc_html__('Questions', 'event_espresso'), |
|
143 | - 'order' => 10, |
|
144 | - ), |
|
145 | - 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
146 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
147 | - 'help_tabs' => array( |
|
148 | - 'registration_form_questions_overview_help_tab' => array( |
|
149 | - 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
150 | - 'filename' => 'registration_form_questions_overview', |
|
151 | - ), |
|
152 | - 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
153 | - 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
154 | - 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
155 | - ), |
|
156 | - 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
157 | - 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
158 | - 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
159 | - ), |
|
160 | - ), |
|
161 | - 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
162 | - 'require_nonce' => false, |
|
163 | - 'qtips' => array( |
|
164 | - 'EE_Registration_Form_Tips', |
|
165 | - )/**/ |
|
166 | - ), |
|
167 | - |
|
168 | - 'question_groups' => array( |
|
169 | - 'nav' => array( |
|
170 | - 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
171 | - 'order' => 20, |
|
172 | - ), |
|
173 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
174 | - 'help_tabs' => array( |
|
175 | - 'registration_form_question_groups_help_tab' => array( |
|
176 | - 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
177 | - 'filename' => 'registration_form_question_groups', |
|
178 | - ), |
|
179 | - ), |
|
180 | - 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
181 | - 'require_nonce' => false, |
|
182 | - ), |
|
183 | - |
|
184 | - 'edit_question' => array( |
|
185 | - 'nav' => array( |
|
186 | - 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
187 | - 'order' => 15, |
|
188 | - 'persistent' => false, |
|
189 | - 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
190 | - $this->_current_page_view_url) : $this->_admin_base_url, |
|
191 | - ), |
|
192 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
193 | - 'help_tabs' => array( |
|
194 | - 'registration_form_edit_question_group_help_tab' => array( |
|
195 | - 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
196 | - 'filename' => 'registration_form_edit_question', |
|
197 | - ), |
|
198 | - ), |
|
199 | - 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
200 | - 'require_nonce' => false, |
|
201 | - ), |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - protected function _add_screen_options() |
|
207 | - { |
|
208 | - //todo |
|
209 | - } |
|
210 | - |
|
211 | - protected function _add_screen_options_default() |
|
212 | - { |
|
213 | - $page_title = $this->_admin_page_title; |
|
214 | - $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
215 | - $this->_per_page_screen_option(); |
|
216 | - $this->_admin_page_title = $page_title; |
|
217 | - } |
|
218 | - |
|
219 | - protected function _add_screen_options_question_groups() |
|
220 | - { |
|
221 | - $page_title = $this->_admin_page_title; |
|
222 | - $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
223 | - $this->_per_page_screen_option(); |
|
224 | - $this->_admin_page_title = $page_title; |
|
225 | - } |
|
226 | - |
|
227 | - //none of the below group are currently used for Event Categories |
|
228 | - protected function _add_feature_pointers() |
|
229 | - { |
|
230 | - } |
|
231 | - |
|
232 | - public function load_scripts_styles() |
|
233 | - { |
|
234 | - wp_register_style('espresso_registration', |
|
235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
236 | - wp_enqueue_style('espresso_registration'); |
|
237 | - } |
|
238 | - |
|
239 | - public function admin_init() |
|
240 | - { |
|
241 | - } |
|
242 | - |
|
243 | - public function admin_notices() |
|
244 | - { |
|
245 | - } |
|
246 | - |
|
247 | - public function admin_footer_scripts() |
|
248 | - { |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - public function load_scripts_styles_default() |
|
253 | - { |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - public function load_scripts_styles_add_question() |
|
258 | - { |
|
259 | - $this->load_scripts_styles_question_details(); |
|
260 | - } |
|
261 | - |
|
262 | - public function load_scripts_styles_edit_question() |
|
263 | - { |
|
264 | - $this->load_scripts_styles_question_details(); |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Loads the JS required for adding or editing a question |
|
269 | - */ |
|
270 | - protected function load_scripts_styles_question_details() |
|
271 | - { |
|
272 | - $this->load_scripts_styles_forms(); |
|
273 | - wp_register_script('espresso_registration_form_single', |
|
274 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
275 | - EVENT_ESPRESSO_VERSION, true); |
|
276 | - wp_enqueue_script('espresso_registration_form_single'); |
|
277 | - wp_localize_script( |
|
278 | - 'espresso_registration_form_single', |
|
279 | - 'ee_question_data', |
|
280 | - array( |
|
281 | - 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
282 | - 'question_type_with_options' => EEM_Question::instance()->question_types_with_options() |
|
283 | - ) |
|
284 | - ); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - public function recaptcha_info_help_tab() |
|
289 | - { |
|
290 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
291 | - EEH_Template::display_template($template, array()); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - public function load_scripts_styles_forms() |
|
296 | - { |
|
297 | - //styles |
|
298 | - wp_enqueue_style('espresso-ui-theme'); |
|
299 | - //scripts |
|
300 | - wp_enqueue_script('ee_admin_js'); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - protected function _set_list_table_views_default() |
|
305 | - { |
|
306 | - $this->_views = array( |
|
307 | - 'all' => array( |
|
308 | - 'slug' => 'all', |
|
309 | - 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
310 | - 'count' => 0, |
|
31 | + /** |
|
32 | + * _question |
|
33 | + * holds the specific question object for the question details screen |
|
34 | + * |
|
35 | + * @var EE_Question $_question |
|
36 | + */ |
|
37 | + protected $_question; |
|
38 | + |
|
39 | + /** |
|
40 | + * _question_group |
|
41 | + * holds the specific question group object for the question group details screen |
|
42 | + * |
|
43 | + * @var EE_Question_Group $_question_group |
|
44 | + */ |
|
45 | + protected $_question_group; |
|
46 | + |
|
47 | + /** |
|
48 | + *_question_model EEM_Question model instance (for queries) |
|
49 | + * |
|
50 | + * @var EEM_Question $_question_model ; |
|
51 | + */ |
|
52 | + protected $_question_model; |
|
53 | + |
|
54 | + /** |
|
55 | + * _question_group_model EEM_Question_group instance (for queries) |
|
56 | + * |
|
57 | + * @var EEM_Question_Group $_question_group_model |
|
58 | + */ |
|
59 | + protected $_question_group_model; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @Constructor |
|
64 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
65 | + * @access public |
|
66 | + */ |
|
67 | + public function __construct($routing = true) |
|
68 | + { |
|
69 | + require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
70 | + require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
71 | + $this->_question_model = EEM_Question::instance(); |
|
72 | + $this->_question_group_model = EEM_Question_Group::instance(); |
|
73 | + parent::__construct($routing); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + protected function _init_page_props() |
|
78 | + { |
|
79 | + $this->page_slug = REGISTRATION_FORM_PG_SLUG; |
|
80 | + $this->page_label = esc_html__('Registration Form', 'event_espresso'); |
|
81 | + $this->_admin_base_url = REGISTRATION_FORM_ADMIN_URL; |
|
82 | + $this->_admin_base_path = REGISTRATION_FORM_ADMIN; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + protected function _ajax_hooks() |
|
87 | + { |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + protected function _define_page_props() |
|
92 | + { |
|
93 | + $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso'); |
|
94 | + $this->_labels = array( |
|
95 | + 'buttons' => array( |
|
96 | + 'edit_question' => esc_html__('Edit Question', 'event_espresso'), |
|
97 | + ), |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + *_set_page_routes |
|
104 | + */ |
|
105 | + protected function _set_page_routes() |
|
106 | + { |
|
107 | + $qst_id = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
108 | + $this->_page_routes = array( |
|
109 | + 'default' => array( |
|
110 | + 'func' => '_questions_overview_list_table', |
|
111 | + 'capability' => 'ee_read_questions', |
|
112 | + ), |
|
113 | + |
|
114 | + 'edit_question' => array( |
|
115 | + 'func' => '_edit_question', |
|
116 | + 'capability' => 'ee_edit_question', |
|
117 | + 'obj_id' => $qst_id, |
|
118 | + 'args' => array('edit'), |
|
119 | + ), |
|
120 | + |
|
121 | + 'question_groups' => array( |
|
122 | + 'func' => '_questions_groups_preview', |
|
123 | + 'capability' => 'ee_read_question_groups', |
|
124 | + ), |
|
125 | + |
|
126 | + 'update_question' => array( |
|
127 | + 'func' => '_insert_or_update_question', |
|
128 | + 'args' => array('new_question' => false), |
|
129 | + 'capability' => 'ee_edit_question', |
|
130 | + 'obj_id' => $qst_id, |
|
131 | + 'noheader' => true, |
|
132 | + ), |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + protected function _set_page_config() |
|
138 | + { |
|
139 | + $this->_page_config = array( |
|
140 | + 'default' => array( |
|
141 | + 'nav' => array( |
|
142 | + 'label' => esc_html__('Questions', 'event_espresso'), |
|
143 | + 'order' => 10, |
|
144 | + ), |
|
145 | + 'list_table' => 'Registration_Form_Questions_Admin_List_Table', |
|
146 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
147 | + 'help_tabs' => array( |
|
148 | + 'registration_form_questions_overview_help_tab' => array( |
|
149 | + 'title' => esc_html__('Questions Overview', 'event_espresso'), |
|
150 | + 'filename' => 'registration_form_questions_overview', |
|
151 | + ), |
|
152 | + 'registration_form_questions_overview_table_column_headings_help_tab' => array( |
|
153 | + 'title' => esc_html__('Questions Overview Table Column Headings', 'event_espresso'), |
|
154 | + 'filename' => 'registration_form_questions_overview_table_column_headings', |
|
155 | + ), |
|
156 | + 'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array( |
|
157 | + 'title' => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'), |
|
158 | + 'filename' => 'registration_form_questions_overview_views_bulk_actions_search', |
|
159 | + ), |
|
160 | + ), |
|
161 | + 'help_tour' => array('Registration_Form_Questions_Overview_Help_Tour'), |
|
162 | + 'require_nonce' => false, |
|
163 | + 'qtips' => array( |
|
164 | + 'EE_Registration_Form_Tips', |
|
165 | + )/**/ |
|
166 | + ), |
|
167 | + |
|
168 | + 'question_groups' => array( |
|
169 | + 'nav' => array( |
|
170 | + 'label' => esc_html__('Question Groups', 'event_espresso'), |
|
171 | + 'order' => 20, |
|
172 | + ), |
|
173 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
174 | + 'help_tabs' => array( |
|
175 | + 'registration_form_question_groups_help_tab' => array( |
|
176 | + 'title' => esc_html__('Question Groups', 'event_espresso'), |
|
177 | + 'filename' => 'registration_form_question_groups', |
|
178 | + ), |
|
179 | + ), |
|
180 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
181 | + 'require_nonce' => false, |
|
182 | + ), |
|
183 | + |
|
184 | + 'edit_question' => array( |
|
185 | + 'nav' => array( |
|
186 | + 'label' => esc_html__('Edit Question', 'event_espresso'), |
|
187 | + 'order' => 15, |
|
188 | + 'persistent' => false, |
|
189 | + 'url' => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']), |
|
190 | + $this->_current_page_view_url) : $this->_admin_base_url, |
|
191 | + ), |
|
192 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
193 | + 'help_tabs' => array( |
|
194 | + 'registration_form_edit_question_group_help_tab' => array( |
|
195 | + 'title' => esc_html__('Edit Question', 'event_espresso'), |
|
196 | + 'filename' => 'registration_form_edit_question', |
|
197 | + ), |
|
198 | + ), |
|
199 | + 'help_tour' => array('Registration_Form_Edit_Question_Help_Tour'), |
|
200 | + 'require_nonce' => false, |
|
201 | + ), |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + protected function _add_screen_options() |
|
207 | + { |
|
208 | + //todo |
|
209 | + } |
|
210 | + |
|
211 | + protected function _add_screen_options_default() |
|
212 | + { |
|
213 | + $page_title = $this->_admin_page_title; |
|
214 | + $this->_admin_page_title = esc_html__('Questions', 'event_espresso'); |
|
215 | + $this->_per_page_screen_option(); |
|
216 | + $this->_admin_page_title = $page_title; |
|
217 | + } |
|
218 | + |
|
219 | + protected function _add_screen_options_question_groups() |
|
220 | + { |
|
221 | + $page_title = $this->_admin_page_title; |
|
222 | + $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso'); |
|
223 | + $this->_per_page_screen_option(); |
|
224 | + $this->_admin_page_title = $page_title; |
|
225 | + } |
|
226 | + |
|
227 | + //none of the below group are currently used for Event Categories |
|
228 | + protected function _add_feature_pointers() |
|
229 | + { |
|
230 | + } |
|
231 | + |
|
232 | + public function load_scripts_styles() |
|
233 | + { |
|
234 | + wp_register_style('espresso_registration', |
|
235 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
236 | + wp_enqueue_style('espresso_registration'); |
|
237 | + } |
|
238 | + |
|
239 | + public function admin_init() |
|
240 | + { |
|
241 | + } |
|
242 | + |
|
243 | + public function admin_notices() |
|
244 | + { |
|
245 | + } |
|
246 | + |
|
247 | + public function admin_footer_scripts() |
|
248 | + { |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + public function load_scripts_styles_default() |
|
253 | + { |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + public function load_scripts_styles_add_question() |
|
258 | + { |
|
259 | + $this->load_scripts_styles_question_details(); |
|
260 | + } |
|
261 | + |
|
262 | + public function load_scripts_styles_edit_question() |
|
263 | + { |
|
264 | + $this->load_scripts_styles_question_details(); |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Loads the JS required for adding or editing a question |
|
269 | + */ |
|
270 | + protected function load_scripts_styles_question_details() |
|
271 | + { |
|
272 | + $this->load_scripts_styles_forms(); |
|
273 | + wp_register_script('espresso_registration_form_single', |
|
274 | + REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
275 | + EVENT_ESPRESSO_VERSION, true); |
|
276 | + wp_enqueue_script('espresso_registration_form_single'); |
|
277 | + wp_localize_script( |
|
278 | + 'espresso_registration_form_single', |
|
279 | + 'ee_question_data', |
|
280 | + array( |
|
281 | + 'question_types_with_max' => EEM_Question::instance()->questionTypesWithMaxLength(), |
|
282 | + 'question_type_with_options' => EEM_Question::instance()->question_types_with_options() |
|
283 | + ) |
|
284 | + ); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + public function recaptcha_info_help_tab() |
|
289 | + { |
|
290 | + $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
291 | + EEH_Template::display_template($template, array()); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + public function load_scripts_styles_forms() |
|
296 | + { |
|
297 | + //styles |
|
298 | + wp_enqueue_style('espresso-ui-theme'); |
|
299 | + //scripts |
|
300 | + wp_enqueue_script('ee_admin_js'); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + protected function _set_list_table_views_default() |
|
305 | + { |
|
306 | + $this->_views = array( |
|
307 | + 'all' => array( |
|
308 | + 'slug' => 'all', |
|
309 | + 'label' => esc_html__('View All Questions', 'event_espresso'), |
|
310 | + 'count' => 0, |
|
311 | 311 | // 'bulk_action' => array( |
312 | 312 | // 'trash_questions' => esc_html__('Trash', 'event_espresso'), |
313 | 313 | // ) |
314 | - ), |
|
315 | - ); |
|
316 | - |
|
317 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
318 | - 'espresso_registration_form_trash_questions') |
|
319 | - ) { |
|
320 | - $this->_views['trash'] = array( |
|
321 | - 'slug' => 'trash', |
|
322 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
323 | - 'count' => 0, |
|
314 | + ), |
|
315 | + ); |
|
316 | + |
|
317 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', |
|
318 | + 'espresso_registration_form_trash_questions') |
|
319 | + ) { |
|
320 | + $this->_views['trash'] = array( |
|
321 | + 'slug' => 'trash', |
|
322 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
323 | + 'count' => 0, |
|
324 | 324 | // 'bulk_action' => array( |
325 | 325 | // 'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'), |
326 | 326 | // 'restore_questions' => esc_html__('Restore', 'event_espresso'), |
327 | - ); |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * This just previews the question groups tab that comes in caffeinated. |
|
333 | - * |
|
334 | - * @return string html |
|
335 | - */ |
|
336 | - protected function _questions_groups_preview() |
|
337 | - { |
|
338 | - $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
339 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
340 | - 'event_espresso') . '" />'; |
|
341 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
342 | - 'event_espresso') . '</strong>'; |
|
343 | - $this->display_admin_caf_preview_page('question_groups_tab'); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Extracts the question field's values from the POST request to update or insert them |
|
349 | - * |
|
350 | - * @param \EEM_Base $model |
|
351 | - * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
352 | - */ |
|
353 | - protected function _set_column_values_for(EEM_Base $model) |
|
354 | - { |
|
355 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
356 | - $set_column_values = array(); |
|
357 | - |
|
358 | - //some initial checks for proper values. |
|
359 | - //if QST_admin_only, then no matter what QST_required is we disable. |
|
360 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
361 | - $this->_req_data['QST_required'] = 0; |
|
362 | - } |
|
363 | - //if the question shouldn't have a max length, don't let them set one |
|
364 | - if (! isset( |
|
365 | - $this->_req_data['QST_type'], |
|
366 | - $this->_req_data['QST_max'] |
|
367 | - ) |
|
368 | - || ! in_array( |
|
369 | - $this->_req_data['QST_type'], |
|
370 | - EEM_Question::instance()->questionTypesWithMaxLength(), |
|
371 | - true) |
|
372 | - ) { |
|
373 | - //they're not allowed to set the max |
|
374 | - $this->_req_data['QST_max'] = null; |
|
375 | - } |
|
376 | - foreach ($model->field_settings() as $fieldName => $settings) { |
|
377 | - // basically if QSG_identifier is empty or not set |
|
378 | - if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
379 | - $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
380 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
327 | + ); |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * This just previews the question groups tab that comes in caffeinated. |
|
333 | + * |
|
334 | + * @return string html |
|
335 | + */ |
|
336 | + protected function _questions_groups_preview() |
|
337 | + { |
|
338 | + $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
|
339 | + $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
340 | + 'event_espresso') . '" />'; |
|
341 | + $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
342 | + 'event_espresso') . '</strong>'; |
|
343 | + $this->display_admin_caf_preview_page('question_groups_tab'); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Extracts the question field's values from the POST request to update or insert them |
|
349 | + * |
|
350 | + * @param \EEM_Base $model |
|
351 | + * @return array where each key is the name of a model's field/db column, and each value is its value. |
|
352 | + */ |
|
353 | + protected function _set_column_values_for(EEM_Base $model) |
|
354 | + { |
|
355 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
356 | + $set_column_values = array(); |
|
357 | + |
|
358 | + //some initial checks for proper values. |
|
359 | + //if QST_admin_only, then no matter what QST_required is we disable. |
|
360 | + if (! empty($this->_req_data['QST_admin_only'])) { |
|
361 | + $this->_req_data['QST_required'] = 0; |
|
362 | + } |
|
363 | + //if the question shouldn't have a max length, don't let them set one |
|
364 | + if (! isset( |
|
365 | + $this->_req_data['QST_type'], |
|
366 | + $this->_req_data['QST_max'] |
|
367 | + ) |
|
368 | + || ! in_array( |
|
369 | + $this->_req_data['QST_type'], |
|
370 | + EEM_Question::instance()->questionTypesWithMaxLength(), |
|
371 | + true) |
|
372 | + ) { |
|
373 | + //they're not allowed to set the max |
|
374 | + $this->_req_data['QST_max'] = null; |
|
375 | + } |
|
376 | + foreach ($model->field_settings() as $fieldName => $settings) { |
|
377 | + // basically if QSG_identifier is empty or not set |
|
378 | + if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
|
379 | + $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
|
380 | + $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
381 | 381 | // dd($set_column_values); |
382 | - } //if the admin label is blank, use a slug version of the question text |
|
383 | - else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
384 | - $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
385 | - $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
386 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
387 | - $set_column_values[$fieldName] = 0; |
|
388 | - } else if ($fieldName === 'QST_max') { |
|
389 | - $qst_system = EEM_Question::instance()->get_var( |
|
390 | - array( |
|
391 | - array( |
|
392 | - 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
393 | - ), |
|
394 | - ), |
|
395 | - 'QST_system'); |
|
396 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
397 | - if (empty($this->_req_data['QST_max']) || |
|
398 | - $this->_req_data['QST_max'] > $max_max |
|
399 | - ) { |
|
400 | - $set_column_values[$fieldName] = $max_max; |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
406 | - if ( |
|
407 | - ! isset($set_column_values[$fieldName]) && |
|
408 | - isset($this->_req_data[$fieldName]) |
|
409 | - ) { |
|
410 | - $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
411 | - } |
|
412 | - |
|
413 | - } |
|
414 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - *_questions_overview_list_table |
|
420 | - */ |
|
421 | - protected function _questions_overview_list_table() |
|
422 | - { |
|
423 | - $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
424 | - $this->display_admin_list_table_page_with_sidebar(); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * _edit_question |
|
430 | - */ |
|
431 | - protected function _edit_question() |
|
432 | - { |
|
433 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
434 | - $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
435 | - |
|
436 | - switch ($this->_req_action) { |
|
437 | - case 'add_question' : |
|
438 | - $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
439 | - break; |
|
440 | - case 'edit_question' : |
|
441 | - $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
442 | - break; |
|
443 | - default : |
|
444 | - $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
445 | - } |
|
446 | - |
|
447 | - // add PRC_ID to title if editing |
|
448 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
449 | - if ($ID) { |
|
450 | - $question = $this->_question_model->get_one_by_ID($ID); |
|
451 | - $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
452 | - $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
453 | - } else { |
|
454 | - $question = EE_Question::new_instance(); |
|
455 | - $question->set_order_to_latest(); |
|
456 | - $this->_set_add_edit_form_tags('insert_question'); |
|
457 | - } |
|
458 | - if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
459 | - $question_types = array_intersect_key( |
|
460 | - EEM_Question::instance()->allowed_question_types(), |
|
461 | - array_flip( |
|
462 | - array( |
|
463 | - EEM_Question::QST_type_text, |
|
464 | - EEM_Question::QST_type_us_phone |
|
465 | - ) |
|
466 | - ) |
|
467 | - ); |
|
468 | - } else { |
|
469 | - $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
470 | - } |
|
471 | - $this->_template_args['QST_ID'] = $ID; |
|
472 | - $this->_template_args['question'] = $question; |
|
473 | - $this->_template_args['question_types'] = $question_types; |
|
474 | - $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
475 | - $question->system_ID() |
|
476 | - ); |
|
477 | - $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
478 | - $this->_set_publish_post_box_vars('id', $ID); |
|
479 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
480 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
481 | - $this->_template_args, true |
|
482 | - ); |
|
483 | - |
|
484 | - // the details template wrapper |
|
485 | - $this->display_admin_page_with_sidebar(); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * @return string |
|
491 | - */ |
|
492 | - protected function _get_question_type_descriptions() |
|
493 | - { |
|
494 | - EE_Registry::instance()->load_helper('HTML'); |
|
495 | - $descriptions = ''; |
|
496 | - $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
497 | - foreach ($question_type_descriptions as $type => $question_type_description) { |
|
498 | - if ($type == 'HTML_TEXTAREA') { |
|
499 | - $html = new EE_Simple_HTML_Validation_Strategy(); |
|
500 | - $question_type_description .= sprintf( |
|
501 | - esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
502 | - '<br/>', |
|
503 | - $html->get_list_of_allowed_tags() |
|
504 | - ); |
|
505 | - } |
|
506 | - $descriptions .= EEH_HTML::p( |
|
507 | - $question_type_description, |
|
508 | - 'question_type_description-' . $type, |
|
509 | - 'question_type_description description', |
|
510 | - 'display:none;' |
|
511 | - ); |
|
512 | - } |
|
513 | - return $descriptions; |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * @param bool|true $new_question |
|
519 | - * @throws \EE_Error |
|
520 | - */ |
|
521 | - protected function _insert_or_update_question($new_question = true) |
|
522 | - { |
|
523 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
524 | - $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
525 | - if ($new_question) { |
|
526 | - $question = EE_Question::new_instance($set_column_values); |
|
527 | - $action_desc = 'added'; |
|
528 | - } else { |
|
529 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
530 | - foreach($set_column_values as $field => $new_value) { |
|
531 | - $question->set($field, $new_value); |
|
532 | - } |
|
533 | - $action_desc = 'updated'; |
|
534 | - } |
|
535 | - $success = $question->save(); |
|
536 | - $ID = $question->ID(); |
|
537 | - if ($ID && $question->should_have_question_options()) { |
|
538 | - //save the related options |
|
539 | - //trash removed options, save old ones |
|
540 | - //get list of all options |
|
541 | - $options = $question->options(); |
|
542 | - if (! empty($options)) { |
|
543 | - foreach ($options as $option_ID => $option) { |
|
544 | - $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
545 | - if ($option_req_index !== false) { |
|
546 | - $option->save($this->_req_data['question_options'][$option_req_index]); |
|
547 | - } else { |
|
548 | - //not found, remove it |
|
549 | - $option->delete(); |
|
550 | - } |
|
551 | - } |
|
552 | - } |
|
553 | - //save new related options |
|
554 | - foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
555 | - //skip $index that is from our sample |
|
556 | - if ( $index === 'xxcountxx' ) { |
|
557 | - continue; |
|
558 | - } |
|
559 | - //note we allow saving blank options. |
|
560 | - if (empty($option_req_data['QSO_ID']) |
|
561 | - ) {//no ID! save it! |
|
562 | - $new_option = EE_Question_Option::new_instance(array( |
|
563 | - 'QSO_value' => $option_req_data['QSO_value'], |
|
564 | - 'QSO_desc' => $option_req_data['QSO_desc'], |
|
565 | - 'QSO_order' => $option_req_data['QSO_order'], |
|
566 | - 'QST_ID' => $question->ID(), |
|
567 | - )); |
|
568 | - $new_option->save(); |
|
569 | - } |
|
570 | - } |
|
571 | - } |
|
572 | - $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
573 | - if ($success !== false) { |
|
574 | - $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
575 | - $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
576 | - $this->_question_model->item_name()); |
|
577 | - EE_Error::add_success($msg); |
|
578 | - } |
|
579 | - |
|
580 | - $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
586 | - * by ID |
|
587 | - * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
588 | - * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
589 | - * |
|
590 | - * @param int $ID of the question option to find |
|
591 | - * @return int index in question_options array if successful, FALSE if unsuccessful |
|
592 | - */ |
|
593 | - protected function _get_option_req_data_index($ID) |
|
594 | - { |
|
595 | - $req_data_for_question_options = $this->_req_data['question_options']; |
|
596 | - foreach ($req_data_for_question_options as $num => $option_data) { |
|
597 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
598 | - return $num; |
|
599 | - } |
|
600 | - } |
|
601 | - return false; |
|
602 | - } |
|
603 | - |
|
604 | - |
|
605 | - |
|
606 | - |
|
607 | - /***********/ |
|
608 | - /* QUERIES */ |
|
609 | - /** |
|
610 | - * For internal use in getting all the query parameters |
|
611 | - * (because it's pretty well the same between question, question groups, |
|
612 | - * and for both when searching for trashed and untrashed ones) |
|
613 | - * |
|
614 | - * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
615 | - * @param int $per_page |
|
616 | - * @param int $current_page |
|
617 | - * @return array lik EEM_Base::get_all's $query_params parameter |
|
618 | - */ |
|
619 | - protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
620 | - { |
|
621 | - $query_params = array(); |
|
622 | - $offset = ($current_page - 1) * $per_page; |
|
623 | - $query_params['limit'] = array($offset, $per_page); |
|
624 | - $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
625 | - $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
626 | - $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
627 | - $query_params['order_by'] = array($field_to_order_by => $order); |
|
628 | - $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
629 | - if (! empty($search_string)) { |
|
630 | - if ($model instanceof EEM_Question_Group) { |
|
631 | - $query_params[0] = array( |
|
632 | - 'OR' => array( |
|
633 | - 'QSG_name' => array('LIKE', "%$search_string%"), |
|
634 | - 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
635 | - ), |
|
636 | - ); |
|
637 | - } else { |
|
638 | - $query_params[0] = array( |
|
639 | - 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
640 | - ); |
|
641 | - } |
|
642 | - } |
|
643 | - |
|
644 | - //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
645 | - /*if ( $model instanceof EEM_Question_Group ) { |
|
382 | + } //if the admin label is blank, use a slug version of the question text |
|
383 | + else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
|
384 | + $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
|
385 | + $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
|
386 | + } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
387 | + $set_column_values[$fieldName] = 0; |
|
388 | + } else if ($fieldName === 'QST_max') { |
|
389 | + $qst_system = EEM_Question::instance()->get_var( |
|
390 | + array( |
|
391 | + array( |
|
392 | + 'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0, |
|
393 | + ), |
|
394 | + ), |
|
395 | + 'QST_system'); |
|
396 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
397 | + if (empty($this->_req_data['QST_max']) || |
|
398 | + $this->_req_data['QST_max'] > $max_max |
|
399 | + ) { |
|
400 | + $set_column_values[$fieldName] = $max_max; |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + //only add a property to the array if it's not null (otherwise the model should just use the default value) |
|
406 | + if ( |
|
407 | + ! isset($set_column_values[$fieldName]) && |
|
408 | + isset($this->_req_data[$fieldName]) |
|
409 | + ) { |
|
410 | + $set_column_values[$fieldName] = $this->_req_data[$fieldName]; |
|
411 | + } |
|
412 | + |
|
413 | + } |
|
414 | + return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + *_questions_overview_list_table |
|
420 | + */ |
|
421 | + protected function _questions_overview_list_table() |
|
422 | + { |
|
423 | + $this->_search_btn_label = esc_html__('Questions', 'event_espresso'); |
|
424 | + $this->display_admin_list_table_page_with_sidebar(); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * _edit_question |
|
430 | + */ |
|
431 | + protected function _edit_question() |
|
432 | + { |
|
433 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
434 | + $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false; |
|
435 | + |
|
436 | + switch ($this->_req_action) { |
|
437 | + case 'add_question' : |
|
438 | + $this->_admin_page_title = esc_html__('Add Question', 'event_espresso'); |
|
439 | + break; |
|
440 | + case 'edit_question' : |
|
441 | + $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso'); |
|
442 | + break; |
|
443 | + default : |
|
444 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
445 | + } |
|
446 | + |
|
447 | + // add PRC_ID to title if editing |
|
448 | + $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
449 | + if ($ID) { |
|
450 | + $question = $this->_question_model->get_one_by_ID($ID); |
|
451 | + $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
|
452 | + $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields); |
|
453 | + } else { |
|
454 | + $question = EE_Question::new_instance(); |
|
455 | + $question->set_order_to_latest(); |
|
456 | + $this->_set_add_edit_form_tags('insert_question'); |
|
457 | + } |
|
458 | + if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
459 | + $question_types = array_intersect_key( |
|
460 | + EEM_Question::instance()->allowed_question_types(), |
|
461 | + array_flip( |
|
462 | + array( |
|
463 | + EEM_Question::QST_type_text, |
|
464 | + EEM_Question::QST_type_us_phone |
|
465 | + ) |
|
466 | + ) |
|
467 | + ); |
|
468 | + } else { |
|
469 | + $question_types = $question->has_answers() ? $this->_question_model->question_types_in_same_category($question->type()) : $this->_question_model->allowed_question_types(); |
|
470 | + } |
|
471 | + $this->_template_args['QST_ID'] = $ID; |
|
472 | + $this->_template_args['question'] = $question; |
|
473 | + $this->_template_args['question_types'] = $question_types; |
|
474 | + $this->_template_args['max_max'] = EEM_Question::instance()->absolute_max_for_system_question( |
|
475 | + $question->system_ID() |
|
476 | + ); |
|
477 | + $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
|
478 | + $this->_set_publish_post_box_vars('id', $ID); |
|
479 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
480 | + REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
481 | + $this->_template_args, true |
|
482 | + ); |
|
483 | + |
|
484 | + // the details template wrapper |
|
485 | + $this->display_admin_page_with_sidebar(); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * @return string |
|
491 | + */ |
|
492 | + protected function _get_question_type_descriptions() |
|
493 | + { |
|
494 | + EE_Registry::instance()->load_helper('HTML'); |
|
495 | + $descriptions = ''; |
|
496 | + $question_type_descriptions = EEM_Question::instance()->question_descriptions(); |
|
497 | + foreach ($question_type_descriptions as $type => $question_type_description) { |
|
498 | + if ($type == 'HTML_TEXTAREA') { |
|
499 | + $html = new EE_Simple_HTML_Validation_Strategy(); |
|
500 | + $question_type_description .= sprintf( |
|
501 | + esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'), |
|
502 | + '<br/>', |
|
503 | + $html->get_list_of_allowed_tags() |
|
504 | + ); |
|
505 | + } |
|
506 | + $descriptions .= EEH_HTML::p( |
|
507 | + $question_type_description, |
|
508 | + 'question_type_description-' . $type, |
|
509 | + 'question_type_description description', |
|
510 | + 'display:none;' |
|
511 | + ); |
|
512 | + } |
|
513 | + return $descriptions; |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * @param bool|true $new_question |
|
519 | + * @throws \EE_Error |
|
520 | + */ |
|
521 | + protected function _insert_or_update_question($new_question = true) |
|
522 | + { |
|
523 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
524 | + $set_column_values = $this->_set_column_values_for($this->_question_model); |
|
525 | + if ($new_question) { |
|
526 | + $question = EE_Question::new_instance($set_column_values); |
|
527 | + $action_desc = 'added'; |
|
528 | + } else { |
|
529 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
530 | + foreach($set_column_values as $field => $new_value) { |
|
531 | + $question->set($field, $new_value); |
|
532 | + } |
|
533 | + $action_desc = 'updated'; |
|
534 | + } |
|
535 | + $success = $question->save(); |
|
536 | + $ID = $question->ID(); |
|
537 | + if ($ID && $question->should_have_question_options()) { |
|
538 | + //save the related options |
|
539 | + //trash removed options, save old ones |
|
540 | + //get list of all options |
|
541 | + $options = $question->options(); |
|
542 | + if (! empty($options)) { |
|
543 | + foreach ($options as $option_ID => $option) { |
|
544 | + $option_req_index = $this->_get_option_req_data_index($option_ID); |
|
545 | + if ($option_req_index !== false) { |
|
546 | + $option->save($this->_req_data['question_options'][$option_req_index]); |
|
547 | + } else { |
|
548 | + //not found, remove it |
|
549 | + $option->delete(); |
|
550 | + } |
|
551 | + } |
|
552 | + } |
|
553 | + //save new related options |
|
554 | + foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
|
555 | + //skip $index that is from our sample |
|
556 | + if ( $index === 'xxcountxx' ) { |
|
557 | + continue; |
|
558 | + } |
|
559 | + //note we allow saving blank options. |
|
560 | + if (empty($option_req_data['QSO_ID']) |
|
561 | + ) {//no ID! save it! |
|
562 | + $new_option = EE_Question_Option::new_instance(array( |
|
563 | + 'QSO_value' => $option_req_data['QSO_value'], |
|
564 | + 'QSO_desc' => $option_req_data['QSO_desc'], |
|
565 | + 'QSO_order' => $option_req_data['QSO_order'], |
|
566 | + 'QST_ID' => $question->ID(), |
|
567 | + )); |
|
568 | + $new_option->save(); |
|
569 | + } |
|
570 | + } |
|
571 | + } |
|
572 | + $query_args = array('action' => 'edit_question', 'QST_ID' => $ID); |
|
573 | + if ($success !== false) { |
|
574 | + $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'), |
|
575 | + $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'), |
|
576 | + $this->_question_model->item_name()); |
|
577 | + EE_Error::add_success($msg); |
|
578 | + } |
|
579 | + |
|
580 | + $this->_redirect_after_action(false, '', $action_desc, $query_args, true); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not |
|
586 | + * by ID |
|
587 | + * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously). |
|
588 | + * So, this function gets the index in that request data array called question_options. Returns FALSE if not found. |
|
589 | + * |
|
590 | + * @param int $ID of the question option to find |
|
591 | + * @return int index in question_options array if successful, FALSE if unsuccessful |
|
592 | + */ |
|
593 | + protected function _get_option_req_data_index($ID) |
|
594 | + { |
|
595 | + $req_data_for_question_options = $this->_req_data['question_options']; |
|
596 | + foreach ($req_data_for_question_options as $num => $option_data) { |
|
597 | + if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
598 | + return $num; |
|
599 | + } |
|
600 | + } |
|
601 | + return false; |
|
602 | + } |
|
603 | + |
|
604 | + |
|
605 | + |
|
606 | + |
|
607 | + /***********/ |
|
608 | + /* QUERIES */ |
|
609 | + /** |
|
610 | + * For internal use in getting all the query parameters |
|
611 | + * (because it's pretty well the same between question, question groups, |
|
612 | + * and for both when searching for trashed and untrashed ones) |
|
613 | + * |
|
614 | + * @param EEM_Base $model either EEM_Question or EEM_Question_Group |
|
615 | + * @param int $per_page |
|
616 | + * @param int $current_page |
|
617 | + * @return array lik EEM_Base::get_all's $query_params parameter |
|
618 | + */ |
|
619 | + protected function get_query_params($model, $per_page = 10, $current_page = 10) |
|
620 | + { |
|
621 | + $query_params = array(); |
|
622 | + $offset = ($current_page - 1) * $per_page; |
|
623 | + $query_params['limit'] = array($offset, $per_page); |
|
624 | + $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
625 | + $orderby_field = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order'; |
|
626 | + $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
|
627 | + $query_params['order_by'] = array($field_to_order_by => $order); |
|
628 | + $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
|
629 | + if (! empty($search_string)) { |
|
630 | + if ($model instanceof EEM_Question_Group) { |
|
631 | + $query_params[0] = array( |
|
632 | + 'OR' => array( |
|
633 | + 'QSG_name' => array('LIKE', "%$search_string%"), |
|
634 | + 'QSG_desc' => array('LIKE', "%$search_string%"), |
|
635 | + ), |
|
636 | + ); |
|
637 | + } else { |
|
638 | + $query_params[0] = array( |
|
639 | + 'QST_display_text' => array('LIKE', "%$search_string%"), |
|
640 | + ); |
|
641 | + } |
|
642 | + } |
|
643 | + |
|
644 | + //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented) |
|
645 | + /*if ( $model instanceof EEM_Question_Group ) { |
|
646 | 646 | if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) { |
647 | 647 | $query_params[0] = array( |
648 | 648 | 'AND' => array( |
@@ -672,62 +672,62 @@ discard block |
||
672 | 672 | } |
673 | 673 | }/**/ |
674 | 674 | |
675 | - return $query_params; |
|
676 | - |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * @param int $per_page |
|
682 | - * @param int $current_page |
|
683 | - * @param bool|false $count |
|
684 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
685 | - */ |
|
686 | - public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
687 | - { |
|
688 | - $QST = EEM_Question::instance(); |
|
689 | - $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
690 | - if ($count) { |
|
691 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
692 | - $results = $QST->count($where); |
|
693 | - } else { |
|
694 | - $results = $QST->get_all($query_params); |
|
695 | - } |
|
696 | - return $results; |
|
697 | - |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - /** |
|
702 | - * @param $per_page |
|
703 | - * @param int $current_page |
|
704 | - * @param bool|false $count |
|
705 | - * @return \EE_Soft_Delete_Base_Class[]|int |
|
706 | - */ |
|
707 | - public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
708 | - { |
|
709 | - $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
710 | - $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
711 | - $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
712 | - return $questions; |
|
713 | - } |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * @param $per_page |
|
718 | - * @param int $current_page |
|
719 | - * @param bool|false $count |
|
720 | - * @return \EE_Soft_Delete_Base_Class[] |
|
721 | - */ |
|
722 | - public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
723 | - { |
|
724 | - /** @type EEM_Question_Group $questionGroupModel */ |
|
725 | - $questionGroupModel = EEM_Question_Group::instance(); |
|
726 | - //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
727 | - return $questionGroupModel->get_all( |
|
728 | - $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
729 | - ); |
|
730 | - } |
|
675 | + return $query_params; |
|
676 | + |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * @param int $per_page |
|
682 | + * @param int $current_page |
|
683 | + * @param bool|false $count |
|
684 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
685 | + */ |
|
686 | + public function get_questions($per_page = 10, $current_page = 1, $count = false) |
|
687 | + { |
|
688 | + $QST = EEM_Question::instance(); |
|
689 | + $query_params = $this->get_query_params($QST, $per_page, $current_page); |
|
690 | + if ($count) { |
|
691 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
692 | + $results = $QST->count($where); |
|
693 | + } else { |
|
694 | + $results = $QST->get_all($query_params); |
|
695 | + } |
|
696 | + return $results; |
|
697 | + |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + /** |
|
702 | + * @param $per_page |
|
703 | + * @param int $current_page |
|
704 | + * @param bool|false $count |
|
705 | + * @return \EE_Soft_Delete_Base_Class[]|int |
|
706 | + */ |
|
707 | + public function get_trashed_questions($per_page, $current_page = 1, $count = false) |
|
708 | + { |
|
709 | + $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
|
710 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
711 | + $questions = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params); |
|
712 | + return $questions; |
|
713 | + } |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * @param $per_page |
|
718 | + * @param int $current_page |
|
719 | + * @param bool|false $count |
|
720 | + * @return \EE_Soft_Delete_Base_Class[] |
|
721 | + */ |
|
722 | + public function get_question_groups($per_page, $current_page = 1, $count = false) |
|
723 | + { |
|
724 | + /** @type EEM_Question_Group $questionGroupModel */ |
|
725 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
726 | + //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
|
727 | + return $questionGroupModel->get_all( |
|
728 | + $this->get_query_params($questionGroupModel, $per_page, $current_page) |
|
729 | + ); |
|
730 | + } |
|
731 | 731 | |
732 | 732 | |
733 | 733 | } //ends Registration_Form_Admin_Page class |
@@ -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 | |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function __construct($routing = true) |
68 | 68 | { |
69 | - require_once(EE_MODELS . 'EEM_Question.model.php'); |
|
70 | - require_once(EE_MODELS . 'EEM_Question_Group.model.php'); |
|
69 | + require_once(EE_MODELS.'EEM_Question.model.php'); |
|
70 | + require_once(EE_MODELS.'EEM_Question_Group.model.php'); |
|
71 | 71 | $this->_question_model = EEM_Question::instance(); |
72 | 72 | $this->_question_group_model = EEM_Question_Group::instance(); |
73 | 73 | parent::__construct($routing); |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | public function load_scripts_styles() |
233 | 233 | { |
234 | 234 | wp_register_style('espresso_registration', |
235 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
235 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
236 | 236 | wp_enqueue_style('espresso_registration'); |
237 | 237 | } |
238 | 238 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | { |
272 | 272 | $this->load_scripts_styles_forms(); |
273 | 273 | wp_register_script('espresso_registration_form_single', |
274 | - REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
274 | + REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'), |
|
275 | 275 | EVENT_ESPRESSO_VERSION, true); |
276 | 276 | wp_enqueue_script('espresso_registration_form_single'); |
277 | 277 | wp_localize_script( |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | public function recaptcha_info_help_tab() |
289 | 289 | { |
290 | - $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php'; |
|
290 | + $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php'; |
|
291 | 291 | EEH_Template::display_template($template, array()); |
292 | 292 | } |
293 | 293 | |
@@ -336,10 +336,10 @@ discard block |
||
336 | 336 | protected function _questions_groups_preview() |
337 | 337 | { |
338 | 338 | $this->_admin_page_title = esc_html__('Question Groups (Preview)', 'event_espresso'); |
339 | - $this->_template_args['preview_img'] = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
340 | - 'event_espresso') . '" />'; |
|
341 | - $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
342 | - 'event_espresso') . '</strong>'; |
|
339 | + $this->_template_args['preview_img'] = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot', |
|
340 | + 'event_espresso').'" />'; |
|
341 | + $this->_template_args['preview_text'] = '<strong>'.esc_html__('Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.', |
|
342 | + 'event_espresso').'</strong>'; |
|
343 | 343 | $this->display_admin_caf_preview_page('question_groups_tab'); |
344 | 344 | } |
345 | 345 | |
@@ -357,11 +357,11 @@ discard block |
||
357 | 357 | |
358 | 358 | //some initial checks for proper values. |
359 | 359 | //if QST_admin_only, then no matter what QST_required is we disable. |
360 | - if (! empty($this->_req_data['QST_admin_only'])) { |
|
360 | + if ( ! empty($this->_req_data['QST_admin_only'])) { |
|
361 | 361 | $this->_req_data['QST_required'] = 0; |
362 | 362 | } |
363 | 363 | //if the question shouldn't have a max length, don't let them set one |
364 | - if (! isset( |
|
364 | + if ( ! isset( |
|
365 | 365 | $this->_req_data['QST_type'], |
366 | 366 | $this->_req_data['QST_max'] |
367 | 367 | ) |
@@ -377,13 +377,13 @@ discard block |
||
377 | 377 | // basically if QSG_identifier is empty or not set |
378 | 378 | if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) { |
379 | 379 | $QSG_name = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : ''; |
380 | - $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true); |
|
380 | + $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true); |
|
381 | 381 | // dd($set_column_values); |
382 | 382 | } //if the admin label is blank, use a slug version of the question text |
383 | 383 | else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) { |
384 | 384 | $QST_text = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : ''; |
385 | 385 | $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10)); |
386 | - } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) { |
|
386 | + } else if ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) { |
|
387 | 387 | $set_column_values[$fieldName] = 0; |
388 | 388 | } else if ($fieldName === 'QST_max') { |
389 | 389 | $qst_system = EEM_Question::instance()->get_var( |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | ), |
394 | 394 | ), |
395 | 395 | 'QST_system'); |
396 | - $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
396 | + $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system); |
|
397 | 397 | if (empty($this->_req_data['QST_max']) || |
398 | 398 | $this->_req_data['QST_max'] > $max_max |
399 | 399 | ) { |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | } |
412 | 412 | |
413 | 413 | } |
414 | - return $set_column_values;//validation fo this data to be performed by the model before insertion. |
|
414 | + return $set_column_values; //validation fo this data to be performed by the model before insertion. |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | } |
446 | 446 | |
447 | 447 | // add PRC_ID to title if editing |
448 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
448 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
449 | 449 | if ($ID) { |
450 | 450 | $question = $this->_question_model->get_one_by_ID($ID); |
451 | 451 | $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID)); |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | $question->set_order_to_latest(); |
456 | 456 | $this->_set_add_edit_form_tags('insert_question'); |
457 | 457 | } |
458 | - if( $question->system_ID() === EEM_Attendee::system_question_phone ){ |
|
458 | + if ($question->system_ID() === EEM_Attendee::system_question_phone) { |
|
459 | 459 | $question_types = array_intersect_key( |
460 | 460 | EEM_Question::instance()->allowed_question_types(), |
461 | 461 | array_flip( |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions(); |
478 | 478 | $this->_set_publish_post_box_vars('id', $ID); |
479 | 479 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
480 | - REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php', |
|
480 | + REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php', |
|
481 | 481 | $this->_template_args, true |
482 | 482 | ); |
483 | 483 | |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | } |
506 | 506 | $descriptions .= EEH_HTML::p( |
507 | 507 | $question_type_description, |
508 | - 'question_type_description-' . $type, |
|
508 | + 'question_type_description-'.$type, |
|
509 | 509 | 'question_type_description description', |
510 | 510 | 'display:none;' |
511 | 511 | ); |
@@ -526,8 +526,8 @@ discard block |
||
526 | 526 | $question = EE_Question::new_instance($set_column_values); |
527 | 527 | $action_desc = 'added'; |
528 | 528 | } else { |
529 | - $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
530 | - foreach($set_column_values as $field => $new_value) { |
|
529 | + $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID'])); |
|
530 | + foreach ($set_column_values as $field => $new_value) { |
|
531 | 531 | $question->set($field, $new_value); |
532 | 532 | } |
533 | 533 | $action_desc = 'updated'; |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | //save the related options |
539 | 539 | //trash removed options, save old ones |
540 | 540 | //get list of all options |
541 | - $options = $question->options(); |
|
542 | - if (! empty($options)) { |
|
541 | + $options = $question->options(); |
|
542 | + if ( ! empty($options)) { |
|
543 | 543 | foreach ($options as $option_ID => $option) { |
544 | 544 | $option_req_index = $this->_get_option_req_data_index($option_ID); |
545 | 545 | if ($option_req_index !== false) { |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | //save new related options |
554 | 554 | foreach ($this->_req_data['question_options'] as $index => $option_req_data) { |
555 | 555 | //skip $index that is from our sample |
556 | - if ( $index === 'xxcountxx' ) { |
|
556 | + if ($index === 'xxcountxx') { |
|
557 | 557 | continue; |
558 | 558 | } |
559 | 559 | //note we allow saving blank options. |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | { |
595 | 595 | $req_data_for_question_options = $this->_req_data['question_options']; |
596 | 596 | foreach ($req_data_for_question_options as $num => $option_data) { |
597 | - if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) { |
|
597 | + if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) { |
|
598 | 598 | return $num; |
599 | 599 | } |
600 | 600 | } |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | $field_to_order_by = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby']; |
627 | 627 | $query_params['order_by'] = array($field_to_order_by => $order); |
628 | 628 | $search_string = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null; |
629 | - if (! empty($search_string)) { |
|
629 | + if ( ! empty($search_string)) { |
|
630 | 630 | if ($model instanceof EEM_Question_Group) { |
631 | 631 | $query_params[0] = array( |
632 | 632 | 'OR' => array( |
@@ -16,114 +16,114 @@ discard block |
||
16 | 16 | class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table |
17 | 17 | { |
18 | 18 | |
19 | - private $_status; |
|
20 | - |
|
21 | - |
|
22 | - /** |
|
23 | - * @param \Transactions_Admin_Page $admin_page |
|
24 | - */ |
|
25 | - public function __construct(\Transactions_Admin_Page $admin_page) |
|
26 | - { |
|
27 | - parent::__construct($admin_page); |
|
28 | - $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - *_setup_data |
|
34 | - */ |
|
35 | - protected function _setup_data() |
|
36 | - { |
|
37 | - $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
38 | - $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
39 | - $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - *_set_properties |
|
45 | - */ |
|
46 | - protected function _set_properties() |
|
47 | - { |
|
48 | - $this->_wp_list_args = array( |
|
49 | - 'singular' => __('transaction', 'event_espresso'), |
|
50 | - 'plural' => __('transactions', 'event_espresso'), |
|
51 | - 'ajax' => true, |
|
52 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | - ); |
|
54 | - $ID_column_name = __('ID', 'event_espresso'); |
|
55 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
56 | - $ID_column_name .= __('Transaction Date', 'event_espresso'); |
|
57 | - $ID_column_name .= '</span> '; |
|
58 | - $this->_columns = array( |
|
59 | - 'TXN_ID' => $ID_column_name, |
|
60 | - 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
|
61 | - 'TXN_total' => __('Total', 'event_espresso'), |
|
62 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
63 | - 'ATT_fname' => __('Primary Registrant', 'event_espresso'), |
|
64 | - 'event_name' => __('Event', 'event_espresso'), |
|
65 | - 'actions' => __('Actions', 'event_espresso'), |
|
66 | - ); |
|
67 | - |
|
68 | - $this->_sortable_columns = array( |
|
69 | - 'TXN_ID' => array('TXN_ID' => false), |
|
70 | - 'event_name' => array('event_name' => false), |
|
71 | - 'ATT_fname' => array('ATT_fname' => false), |
|
72 | - 'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted |
|
73 | - ); |
|
74 | - |
|
75 | - $this->_primary_column = 'TXN_ID'; |
|
76 | - |
|
77 | - $this->_hidden_columns = array(); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * This simply sets up the row class for the table rows. |
|
83 | - * Allows for easier overriding of child methods for setting up sorting. |
|
84 | - * |
|
85 | - * @param EE_Transaction $transaction the current item |
|
86 | - * @return string |
|
87 | - * @throws \EE_Error |
|
88 | - */ |
|
89 | - protected function _get_row_class($transaction) |
|
90 | - { |
|
91 | - $class = parent::_get_row_class($transaction); |
|
92 | - //add status class |
|
93 | - $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
94 | - if ($this->_has_checkbox_column) { |
|
95 | - $class .= ' has-checkbox-column'; |
|
96 | - } |
|
97 | - return $class; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * _get_table_filters |
|
103 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
104 | - * get's shown in the table. |
|
105 | - * |
|
106 | - * @abstract |
|
107 | - * @access protected |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - protected function _get_table_filters() |
|
111 | - { |
|
112 | - $filters = array(); |
|
113 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
114 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
115 | - : date( |
|
116 | - 'm/d/Y', |
|
117 | - strtotime('-10 year') |
|
118 | - ); |
|
119 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
120 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
121 | - : date( |
|
122 | - 'm/d/Y', |
|
123 | - current_time('timestamp') |
|
124 | - ); |
|
125 | - ob_start(); |
|
126 | - ?> |
|
19 | + private $_status; |
|
20 | + |
|
21 | + |
|
22 | + /** |
|
23 | + * @param \Transactions_Admin_Page $admin_page |
|
24 | + */ |
|
25 | + public function __construct(\Transactions_Admin_Page $admin_page) |
|
26 | + { |
|
27 | + parent::__construct($admin_page); |
|
28 | + $this->_status = $this->_admin_page->get_transaction_status_array(); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + *_setup_data |
|
34 | + */ |
|
35 | + protected function _setup_data() |
|
36 | + { |
|
37 | + $this->_data = $this->_admin_page->get_transactions($this->_per_page); |
|
38 | + $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; |
|
39 | + $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + *_set_properties |
|
45 | + */ |
|
46 | + protected function _set_properties() |
|
47 | + { |
|
48 | + $this->_wp_list_args = array( |
|
49 | + 'singular' => __('transaction', 'event_espresso'), |
|
50 | + 'plural' => __('transactions', 'event_espresso'), |
|
51 | + 'ajax' => true, |
|
52 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | + ); |
|
54 | + $ID_column_name = __('ID', 'event_espresso'); |
|
55 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
56 | + $ID_column_name .= __('Transaction Date', 'event_espresso'); |
|
57 | + $ID_column_name .= '</span> '; |
|
58 | + $this->_columns = array( |
|
59 | + 'TXN_ID' => $ID_column_name, |
|
60 | + 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
|
61 | + 'TXN_total' => __('Total', 'event_espresso'), |
|
62 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
63 | + 'ATT_fname' => __('Primary Registrant', 'event_espresso'), |
|
64 | + 'event_name' => __('Event', 'event_espresso'), |
|
65 | + 'actions' => __('Actions', 'event_espresso'), |
|
66 | + ); |
|
67 | + |
|
68 | + $this->_sortable_columns = array( |
|
69 | + 'TXN_ID' => array('TXN_ID' => false), |
|
70 | + 'event_name' => array('event_name' => false), |
|
71 | + 'ATT_fname' => array('ATT_fname' => false), |
|
72 | + 'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted |
|
73 | + ); |
|
74 | + |
|
75 | + $this->_primary_column = 'TXN_ID'; |
|
76 | + |
|
77 | + $this->_hidden_columns = array(); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * This simply sets up the row class for the table rows. |
|
83 | + * Allows for easier overriding of child methods for setting up sorting. |
|
84 | + * |
|
85 | + * @param EE_Transaction $transaction the current item |
|
86 | + * @return string |
|
87 | + * @throws \EE_Error |
|
88 | + */ |
|
89 | + protected function _get_row_class($transaction) |
|
90 | + { |
|
91 | + $class = parent::_get_row_class($transaction); |
|
92 | + //add status class |
|
93 | + $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
94 | + if ($this->_has_checkbox_column) { |
|
95 | + $class .= ' has-checkbox-column'; |
|
96 | + } |
|
97 | + return $class; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * _get_table_filters |
|
103 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
104 | + * get's shown in the table. |
|
105 | + * |
|
106 | + * @abstract |
|
107 | + * @access protected |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + protected function _get_table_filters() |
|
111 | + { |
|
112 | + $filters = array(); |
|
113 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
114 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
115 | + : date( |
|
116 | + 'm/d/Y', |
|
117 | + strtotime('-10 year') |
|
118 | + ); |
|
119 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
120 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
121 | + : date( |
|
122 | + 'm/d/Y', |
|
123 | + current_time('timestamp') |
|
124 | + ); |
|
125 | + ob_start(); |
|
126 | + ?> |
|
127 | 127 | <label for="txn-filter-start-date">Display Transactions from </label> |
128 | 128 | <input id="txn-filter-start-date" class="datepicker" type="text" value="<?php echo $start_date; ?>" |
129 | 129 | name="txn-filter-start-date" size="15"/> |
@@ -131,554 +131,554 @@ discard block |
||
131 | 131 | <input id="txn-filter-end-date" class="datepicker" type="text" value="<?php echo $end_date; ?>" |
132 | 132 | name="txn-filter-end-date" size="15"/> |
133 | 133 | <?php |
134 | - $filters[] = ob_get_contents(); |
|
135 | - ob_end_clean(); |
|
136 | - return $filters; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - *_add_view_counts |
|
142 | - */ |
|
143 | - protected function _add_view_counts() |
|
144 | - { |
|
145 | - $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); |
|
146 | - $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); |
|
147 | - $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * column TXN_ID |
|
153 | - * |
|
154 | - * @param \EE_Transaction $transaction |
|
155 | - * @return string |
|
156 | - * @throws \EE_Error |
|
157 | - */ |
|
158 | - public function column_TXN_ID(EE_Transaction $transaction) |
|
159 | - { |
|
160 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
161 | - 'action' => 'view_transaction', |
|
162 | - 'TXN_ID' => $transaction->ID(), |
|
163 | - ), TXN_ADMIN_URL); |
|
164 | - $content = '<a href="' . $view_lnk_url . '"' |
|
165 | - . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
166 | - . $transaction->ID() |
|
167 | - . '</a>'; |
|
168 | - |
|
169 | - //txn timestamp |
|
170 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
171 | - return $content; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param \EE_Transaction $transaction |
|
177 | - * @return string |
|
178 | - * @throws EE_Error |
|
179 | - * @throws InvalidArgumentException |
|
180 | - * @throws InvalidDataTypeException |
|
181 | - * @throws InvalidInterfaceException |
|
182 | - */ |
|
183 | - protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
184 | - { |
|
185 | - //txn timestamp |
|
186 | - // is TXN less than 2 hours old ? |
|
187 | - if (($transaction->failed() || $transaction->is_abandoned()) |
|
188 | - && ( |
|
189 | - (time() - EE_Registry::instance()->SSN->lifespan()) < $transaction->datetime(false, true) |
|
190 | - ) |
|
191 | - ) { |
|
192 | - $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
193 | - } else { |
|
194 | - $timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); |
|
195 | - } |
|
196 | - return $timestamp; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * column_cb |
|
202 | - * |
|
203 | - * @param \EE_Transaction $transaction |
|
204 | - * @return string |
|
205 | - * @throws \EE_Error |
|
206 | - */ |
|
207 | - public function column_cb($transaction) |
|
208 | - { |
|
209 | - return sprintf( |
|
210 | - '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
211 | - $this->_wp_list_args['singular'], |
|
212 | - $transaction->ID() |
|
213 | - ); |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * column_TXN_timestamp |
|
219 | - * |
|
220 | - * @param \EE_Transaction $transaction |
|
221 | - * @return string |
|
222 | - * @throws \EE_Error |
|
223 | - */ |
|
224 | - public function column_TXN_timestamp(EE_Transaction $transaction) |
|
225 | - { |
|
226 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
227 | - 'action' => 'view_transaction', |
|
228 | - 'TXN_ID' => $transaction->ID(), |
|
229 | - ), TXN_ADMIN_URL); |
|
230 | - $txn_date = '<a href="' . $view_lnk_url . '"' |
|
231 | - . ' title="' |
|
232 | - . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
233 | - . $this->_get_txn_timestamp($transaction) |
|
234 | - . '</a>'; |
|
235 | - //status |
|
236 | - $txn_date .= '<br><span class="ee-status-text-small">' |
|
237 | - . EEH_Template::pretty_status( |
|
238 | - $transaction->status_ID(), |
|
239 | - false, |
|
240 | - 'sentence' |
|
241 | - ) |
|
242 | - . '</span>'; |
|
243 | - return $txn_date; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * column_TXN_total |
|
249 | - * |
|
250 | - * @param \EE_Transaction $transaction |
|
251 | - * @return string |
|
252 | - * @throws \EE_Error |
|
253 | - */ |
|
254 | - public function column_TXN_total(EE_Transaction $transaction) |
|
255 | - { |
|
256 | - if ($transaction->get('TXN_total') > 0) { |
|
257 | - return '<span class="txn-pad-rght">' |
|
258 | - . apply_filters( |
|
259 | - 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
260 | - $transaction->get_pretty('TXN_total'), |
|
261 | - $transaction |
|
262 | - ) |
|
263 | - . '</span>'; |
|
264 | - } else { |
|
265 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * column_TXN_paid |
|
272 | - * |
|
273 | - * @param \EE_Transaction $transaction |
|
274 | - * @return mixed|string |
|
275 | - * @throws \EE_Error |
|
276 | - */ |
|
277 | - public function column_TXN_paid(EE_Transaction $transaction) |
|
278 | - { |
|
279 | - $transaction_total = $transaction->get('TXN_total'); |
|
280 | - $transaction_paid = $transaction->get('TXN_paid'); |
|
281 | - |
|
282 | - if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
283 | - // monies owing |
|
284 | - $span_class = 'txn-overview-part-payment-spn'; |
|
285 | - if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
286 | - // paid in full |
|
287 | - $span_class = 'txn-overview-full-payment-spn'; |
|
288 | - } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
289 | - // no payments made |
|
290 | - $span_class = 'txn-overview-no-payment-spn'; |
|
291 | - } |
|
292 | - } else { |
|
293 | - $span_class = 'txn-overview-free-event-spn'; |
|
294 | - $transaction_paid = 0; |
|
295 | - } |
|
296 | - |
|
297 | - $payment_method = $transaction->payment_method(); |
|
298 | - $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
299 | - ? $payment_method->admin_name() |
|
300 | - : esc_html__('Unknown', 'event_espresso'); |
|
301 | - $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; |
|
302 | - |
|
303 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
304 | - . $transaction_paid_content |
|
305 | - . '</span>'; |
|
306 | - if ($transaction_paid > 0) { |
|
307 | - $content .= '<br><span class="ee-status-text-small">' |
|
308 | - . sprintf( |
|
309 | - esc_html__('...via %s', 'event_espresso'), |
|
310 | - $payment_method_name |
|
311 | - ) |
|
312 | - . '</span>'; |
|
313 | - } |
|
314 | - return $content; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * column_ATT_fname |
|
320 | - * |
|
321 | - * @param \EE_Transaction $transaction |
|
322 | - * @return string |
|
323 | - * @throws EE_Error |
|
324 | - * @throws InvalidArgumentException |
|
325 | - * @throws InvalidDataTypeException |
|
326 | - * @throws InvalidInterfaceException |
|
327 | - */ |
|
328 | - public function column_ATT_fname(EE_Transaction $transaction) |
|
329 | - { |
|
330 | - $primary_reg = $transaction->primary_registration(); |
|
331 | - $attendee = $primary_reg->get_first_related('Attendee'); |
|
332 | - if ($attendee instanceof EE_Attendee) { |
|
333 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
334 | - 'action' => 'view_registration', |
|
335 | - '_REG_ID' => $primary_reg->ID(), |
|
336 | - ), REG_ADMIN_URL); |
|
337 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
338 | - 'ee_read_registration', |
|
339 | - 'espresso_registrations_view_registration', |
|
340 | - $primary_reg->ID() |
|
341 | - ) |
|
342 | - ? '<a href="' . $edit_lnk_url . '"' |
|
343 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
344 | - . $attendee->full_name() |
|
345 | - . '</a>' |
|
346 | - : $attendee->full_name(); |
|
347 | - $content .= '<br>' . $attendee->email(); |
|
348 | - return $content; |
|
349 | - } |
|
350 | - return $transaction->failed() || $transaction->is_abandoned() |
|
351 | - ? esc_html__('no contact record.', 'event_espresso') |
|
352 | - : esc_html__( |
|
353 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
354 | - 'event_espresso' |
|
355 | - ); |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * column_ATT_email |
|
361 | - * |
|
362 | - * @param \EE_Transaction $transaction |
|
363 | - * @return string |
|
364 | - * @throws \EE_Error |
|
365 | - */ |
|
366 | - public function column_ATT_email(EE_Transaction $transaction) |
|
367 | - { |
|
368 | - $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
369 | - if (! empty($attendee)) { |
|
370 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
371 | - . $attendee->get('ATT_email') |
|
372 | - . '</a>'; |
|
373 | - } else { |
|
374 | - return $transaction->failed() || $transaction->is_abandoned() |
|
375 | - ? esc_html__('no contact record.', 'event_espresso') |
|
376 | - : esc_html__( |
|
377 | - 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
378 | - 'event_espresso' |
|
379 | - ); |
|
380 | - } |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * column_event_name |
|
386 | - * |
|
387 | - * @param \EE_Transaction $transaction |
|
388 | - * @return string |
|
389 | - * @throws EE_Error |
|
390 | - * @throws InvalidArgumentException |
|
391 | - * @throws InvalidDataTypeException |
|
392 | - * @throws InvalidInterfaceException |
|
393 | - */ |
|
394 | - public function column_event_name(EE_Transaction $transaction) |
|
395 | - { |
|
396 | - $actions = array(); |
|
397 | - $event = $transaction->primary_registration()->get_first_related('Event'); |
|
398 | - if (! empty($event)) { |
|
399 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
400 | - array('action' => 'edit', 'post' => $event->ID()), |
|
401 | - EVENTS_ADMIN_URL |
|
402 | - ); |
|
403 | - $event_name = $event->get('EVT_name'); |
|
404 | - |
|
405 | - //filter this view by transactions for this event |
|
406 | - $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
|
407 | - 'action' => 'default', |
|
408 | - 'EVT_ID' => $event->ID(), |
|
409 | - )); |
|
410 | - if (empty($this->_req_data['EVT_ID']) |
|
411 | - && EE_Registry::instance()->CAP->current_user_can( |
|
412 | - 'ee_edit_event', |
|
413 | - 'espresso_events_edit', |
|
414 | - $event->ID() |
|
415 | - ) |
|
416 | - ) { |
|
417 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
418 | - . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' |
|
419 | - . esc_html__('View Transactions for this event', 'event_espresso') |
|
420 | - . '</a>'; |
|
421 | - } |
|
422 | - |
|
423 | - return sprintf( |
|
424 | - '%1$s %2$s', |
|
425 | - EE_Registry::instance()->CAP->current_user_can( |
|
426 | - 'ee_edit_event', |
|
427 | - 'espresso_events_edit', |
|
428 | - $event->ID() |
|
429 | - ) |
|
430 | - ? '<a href="' . $edit_event_url . '"' |
|
431 | - . ' title="' |
|
432 | - . sprintf( |
|
433 | - esc_attr__('Edit Event: %s', 'event_espresso'), |
|
434 | - $event->get('EVT_name') |
|
435 | - ) |
|
436 | - . '">' |
|
437 | - . wp_trim_words( |
|
438 | - $event_name, |
|
439 | - 30, |
|
440 | - '...' |
|
441 | - ) |
|
442 | - . '</a>' |
|
443 | - : wp_trim_words($event_name, 30, '...'), |
|
444 | - $this->row_actions($actions) |
|
445 | - ); |
|
446 | - } else { |
|
447 | - return esc_html__( |
|
448 | - 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
449 | - 'event_espresso' |
|
450 | - ); |
|
451 | - } |
|
452 | - } |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * column_actions |
|
457 | - * |
|
458 | - * @param \EE_Transaction $transaction |
|
459 | - * @return string |
|
460 | - * @throws \EE_Error |
|
461 | - */ |
|
462 | - public function column_actions(EE_Transaction $transaction) |
|
463 | - { |
|
464 | - return $this->_action_string( |
|
465 | - $this->get_transaction_details_link($transaction) |
|
466 | - . $this->get_invoice_link($transaction) |
|
467 | - . $this->get_receipt_link($transaction) |
|
468 | - . $this->get_primary_registration_details_link($transaction) |
|
469 | - . $this->get_send_payment_reminder_trigger_link($transaction) |
|
470 | - . $this->get_payment_overview_link($transaction) |
|
471 | - . $this->get_related_messages_link($transaction), |
|
472 | - $transaction, |
|
473 | - 'ul', |
|
474 | - 'txn-overview-actions-ul' |
|
475 | - ); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Get the transaction details link. |
|
481 | - * @param EE_Transaction $transaction |
|
482 | - * @return string |
|
483 | - * @throws EE_Error |
|
484 | - */ |
|
485 | - protected function get_transaction_details_link(EE_Transaction $transaction) |
|
486 | - { |
|
487 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
488 | - 'action' => 'view_transaction', |
|
489 | - 'TXN_ID' => $transaction->ID(), |
|
490 | - ), TXN_ADMIN_URL); |
|
491 | - return ' |
|
134 | + $filters[] = ob_get_contents(); |
|
135 | + ob_end_clean(); |
|
136 | + return $filters; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + *_add_view_counts |
|
142 | + */ |
|
143 | + protected function _add_view_counts() |
|
144 | + { |
|
145 | + $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); |
|
146 | + $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); |
|
147 | + $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * column TXN_ID |
|
153 | + * |
|
154 | + * @param \EE_Transaction $transaction |
|
155 | + * @return string |
|
156 | + * @throws \EE_Error |
|
157 | + */ |
|
158 | + public function column_TXN_ID(EE_Transaction $transaction) |
|
159 | + { |
|
160 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
161 | + 'action' => 'view_transaction', |
|
162 | + 'TXN_ID' => $transaction->ID(), |
|
163 | + ), TXN_ADMIN_URL); |
|
164 | + $content = '<a href="' . $view_lnk_url . '"' |
|
165 | + . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
166 | + . $transaction->ID() |
|
167 | + . '</a>'; |
|
168 | + |
|
169 | + //txn timestamp |
|
170 | + $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
171 | + return $content; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param \EE_Transaction $transaction |
|
177 | + * @return string |
|
178 | + * @throws EE_Error |
|
179 | + * @throws InvalidArgumentException |
|
180 | + * @throws InvalidDataTypeException |
|
181 | + * @throws InvalidInterfaceException |
|
182 | + */ |
|
183 | + protected function _get_txn_timestamp(EE_Transaction $transaction) |
|
184 | + { |
|
185 | + //txn timestamp |
|
186 | + // is TXN less than 2 hours old ? |
|
187 | + if (($transaction->failed() || $transaction->is_abandoned()) |
|
188 | + && ( |
|
189 | + (time() - EE_Registry::instance()->SSN->lifespan()) < $transaction->datetime(false, true) |
|
190 | + ) |
|
191 | + ) { |
|
192 | + $timestamp = esc_html__('TXN in progress...', 'event_espresso'); |
|
193 | + } else { |
|
194 | + $timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); |
|
195 | + } |
|
196 | + return $timestamp; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * column_cb |
|
202 | + * |
|
203 | + * @param \EE_Transaction $transaction |
|
204 | + * @return string |
|
205 | + * @throws \EE_Error |
|
206 | + */ |
|
207 | + public function column_cb($transaction) |
|
208 | + { |
|
209 | + return sprintf( |
|
210 | + '<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
211 | + $this->_wp_list_args['singular'], |
|
212 | + $transaction->ID() |
|
213 | + ); |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * column_TXN_timestamp |
|
219 | + * |
|
220 | + * @param \EE_Transaction $transaction |
|
221 | + * @return string |
|
222 | + * @throws \EE_Error |
|
223 | + */ |
|
224 | + public function column_TXN_timestamp(EE_Transaction $transaction) |
|
225 | + { |
|
226 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
227 | + 'action' => 'view_transaction', |
|
228 | + 'TXN_ID' => $transaction->ID(), |
|
229 | + ), TXN_ADMIN_URL); |
|
230 | + $txn_date = '<a href="' . $view_lnk_url . '"' |
|
231 | + . ' title="' |
|
232 | + . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
233 | + . $this->_get_txn_timestamp($transaction) |
|
234 | + . '</a>'; |
|
235 | + //status |
|
236 | + $txn_date .= '<br><span class="ee-status-text-small">' |
|
237 | + . EEH_Template::pretty_status( |
|
238 | + $transaction->status_ID(), |
|
239 | + false, |
|
240 | + 'sentence' |
|
241 | + ) |
|
242 | + . '</span>'; |
|
243 | + return $txn_date; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * column_TXN_total |
|
249 | + * |
|
250 | + * @param \EE_Transaction $transaction |
|
251 | + * @return string |
|
252 | + * @throws \EE_Error |
|
253 | + */ |
|
254 | + public function column_TXN_total(EE_Transaction $transaction) |
|
255 | + { |
|
256 | + if ($transaction->get('TXN_total') > 0) { |
|
257 | + return '<span class="txn-pad-rght">' |
|
258 | + . apply_filters( |
|
259 | + 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', |
|
260 | + $transaction->get_pretty('TXN_total'), |
|
261 | + $transaction |
|
262 | + ) |
|
263 | + . '</span>'; |
|
264 | + } else { |
|
265 | + return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * column_TXN_paid |
|
272 | + * |
|
273 | + * @param \EE_Transaction $transaction |
|
274 | + * @return mixed|string |
|
275 | + * @throws \EE_Error |
|
276 | + */ |
|
277 | + public function column_TXN_paid(EE_Transaction $transaction) |
|
278 | + { |
|
279 | + $transaction_total = $transaction->get('TXN_total'); |
|
280 | + $transaction_paid = $transaction->get('TXN_paid'); |
|
281 | + |
|
282 | + if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { |
|
283 | + // monies owing |
|
284 | + $span_class = 'txn-overview-part-payment-spn'; |
|
285 | + if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { |
|
286 | + // paid in full |
|
287 | + $span_class = 'txn-overview-full-payment-spn'; |
|
288 | + } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { |
|
289 | + // no payments made |
|
290 | + $span_class = 'txn-overview-no-payment-spn'; |
|
291 | + } |
|
292 | + } else { |
|
293 | + $span_class = 'txn-overview-free-event-spn'; |
|
294 | + $transaction_paid = 0; |
|
295 | + } |
|
296 | + |
|
297 | + $payment_method = $transaction->payment_method(); |
|
298 | + $payment_method_name = $payment_method instanceof EE_Payment_Method |
|
299 | + ? $payment_method->admin_name() |
|
300 | + : esc_html__('Unknown', 'event_espresso'); |
|
301 | + $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; |
|
302 | + |
|
303 | + $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
304 | + . $transaction_paid_content |
|
305 | + . '</span>'; |
|
306 | + if ($transaction_paid > 0) { |
|
307 | + $content .= '<br><span class="ee-status-text-small">' |
|
308 | + . sprintf( |
|
309 | + esc_html__('...via %s', 'event_espresso'), |
|
310 | + $payment_method_name |
|
311 | + ) |
|
312 | + . '</span>'; |
|
313 | + } |
|
314 | + return $content; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * column_ATT_fname |
|
320 | + * |
|
321 | + * @param \EE_Transaction $transaction |
|
322 | + * @return string |
|
323 | + * @throws EE_Error |
|
324 | + * @throws InvalidArgumentException |
|
325 | + * @throws InvalidDataTypeException |
|
326 | + * @throws InvalidInterfaceException |
|
327 | + */ |
|
328 | + public function column_ATT_fname(EE_Transaction $transaction) |
|
329 | + { |
|
330 | + $primary_reg = $transaction->primary_registration(); |
|
331 | + $attendee = $primary_reg->get_first_related('Attendee'); |
|
332 | + if ($attendee instanceof EE_Attendee) { |
|
333 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
334 | + 'action' => 'view_registration', |
|
335 | + '_REG_ID' => $primary_reg->ID(), |
|
336 | + ), REG_ADMIN_URL); |
|
337 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
338 | + 'ee_read_registration', |
|
339 | + 'espresso_registrations_view_registration', |
|
340 | + $primary_reg->ID() |
|
341 | + ) |
|
342 | + ? '<a href="' . $edit_lnk_url . '"' |
|
343 | + . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
344 | + . $attendee->full_name() |
|
345 | + . '</a>' |
|
346 | + : $attendee->full_name(); |
|
347 | + $content .= '<br>' . $attendee->email(); |
|
348 | + return $content; |
|
349 | + } |
|
350 | + return $transaction->failed() || $transaction->is_abandoned() |
|
351 | + ? esc_html__('no contact record.', 'event_espresso') |
|
352 | + : esc_html__( |
|
353 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
354 | + 'event_espresso' |
|
355 | + ); |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * column_ATT_email |
|
361 | + * |
|
362 | + * @param \EE_Transaction $transaction |
|
363 | + * @return string |
|
364 | + * @throws \EE_Error |
|
365 | + */ |
|
366 | + public function column_ATT_email(EE_Transaction $transaction) |
|
367 | + { |
|
368 | + $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
|
369 | + if (! empty($attendee)) { |
|
370 | + return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
371 | + . $attendee->get('ATT_email') |
|
372 | + . '</a>'; |
|
373 | + } else { |
|
374 | + return $transaction->failed() || $transaction->is_abandoned() |
|
375 | + ? esc_html__('no contact record.', 'event_espresso') |
|
376 | + : esc_html__( |
|
377 | + 'No contact record, because the transaction was abandoned or the registration process failed.', |
|
378 | + 'event_espresso' |
|
379 | + ); |
|
380 | + } |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * column_event_name |
|
386 | + * |
|
387 | + * @param \EE_Transaction $transaction |
|
388 | + * @return string |
|
389 | + * @throws EE_Error |
|
390 | + * @throws InvalidArgumentException |
|
391 | + * @throws InvalidDataTypeException |
|
392 | + * @throws InvalidInterfaceException |
|
393 | + */ |
|
394 | + public function column_event_name(EE_Transaction $transaction) |
|
395 | + { |
|
396 | + $actions = array(); |
|
397 | + $event = $transaction->primary_registration()->get_first_related('Event'); |
|
398 | + if (! empty($event)) { |
|
399 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
|
400 | + array('action' => 'edit', 'post' => $event->ID()), |
|
401 | + EVENTS_ADMIN_URL |
|
402 | + ); |
|
403 | + $event_name = $event->get('EVT_name'); |
|
404 | + |
|
405 | + //filter this view by transactions for this event |
|
406 | + $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
|
407 | + 'action' => 'default', |
|
408 | + 'EVT_ID' => $event->ID(), |
|
409 | + )); |
|
410 | + if (empty($this->_req_data['EVT_ID']) |
|
411 | + && EE_Registry::instance()->CAP->current_user_can( |
|
412 | + 'ee_edit_event', |
|
413 | + 'espresso_events_edit', |
|
414 | + $event->ID() |
|
415 | + ) |
|
416 | + ) { |
|
417 | + $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
418 | + . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' |
|
419 | + . esc_html__('View Transactions for this event', 'event_espresso') |
|
420 | + . '</a>'; |
|
421 | + } |
|
422 | + |
|
423 | + return sprintf( |
|
424 | + '%1$s %2$s', |
|
425 | + EE_Registry::instance()->CAP->current_user_can( |
|
426 | + 'ee_edit_event', |
|
427 | + 'espresso_events_edit', |
|
428 | + $event->ID() |
|
429 | + ) |
|
430 | + ? '<a href="' . $edit_event_url . '"' |
|
431 | + . ' title="' |
|
432 | + . sprintf( |
|
433 | + esc_attr__('Edit Event: %s', 'event_espresso'), |
|
434 | + $event->get('EVT_name') |
|
435 | + ) |
|
436 | + . '">' |
|
437 | + . wp_trim_words( |
|
438 | + $event_name, |
|
439 | + 30, |
|
440 | + '...' |
|
441 | + ) |
|
442 | + . '</a>' |
|
443 | + : wp_trim_words($event_name, 30, '...'), |
|
444 | + $this->row_actions($actions) |
|
445 | + ); |
|
446 | + } else { |
|
447 | + return esc_html__( |
|
448 | + 'The event associated with this transaction via the primary registration cannot be retrieved.', |
|
449 | + 'event_espresso' |
|
450 | + ); |
|
451 | + } |
|
452 | + } |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * column_actions |
|
457 | + * |
|
458 | + * @param \EE_Transaction $transaction |
|
459 | + * @return string |
|
460 | + * @throws \EE_Error |
|
461 | + */ |
|
462 | + public function column_actions(EE_Transaction $transaction) |
|
463 | + { |
|
464 | + return $this->_action_string( |
|
465 | + $this->get_transaction_details_link($transaction) |
|
466 | + . $this->get_invoice_link($transaction) |
|
467 | + . $this->get_receipt_link($transaction) |
|
468 | + . $this->get_primary_registration_details_link($transaction) |
|
469 | + . $this->get_send_payment_reminder_trigger_link($transaction) |
|
470 | + . $this->get_payment_overview_link($transaction) |
|
471 | + . $this->get_related_messages_link($transaction), |
|
472 | + $transaction, |
|
473 | + 'ul', |
|
474 | + 'txn-overview-actions-ul' |
|
475 | + ); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Get the transaction details link. |
|
481 | + * @param EE_Transaction $transaction |
|
482 | + * @return string |
|
483 | + * @throws EE_Error |
|
484 | + */ |
|
485 | + protected function get_transaction_details_link(EE_Transaction $transaction) |
|
486 | + { |
|
487 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
488 | + 'action' => 'view_transaction', |
|
489 | + 'TXN_ID' => $transaction->ID(), |
|
490 | + ), TXN_ADMIN_URL); |
|
491 | + return ' |
|
492 | 492 | <li> |
493 | 493 | <a href="' . $url . '"' |
494 | - . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
494 | + . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
495 | 495 | <span class="dashicons dashicons-cart"></span> |
496 | 496 | </a> |
497 | 497 | </li>'; |
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * Get the invoice link for the given registration. |
|
503 | - * @param EE_Transaction $transaction |
|
504 | - * @return string |
|
505 | - * @throws EE_Error |
|
506 | - */ |
|
507 | - protected function get_invoice_link(EE_Transaction $transaction) |
|
508 | - { |
|
509 | - $registration = $transaction->primary_registration(); |
|
510 | - if ($registration instanceof EE_Registration) { |
|
511 | - $url = $registration->invoice_url(); |
|
512 | - //only show invoice link if message type is active. |
|
513 | - if ($registration->attendee() instanceof EE_Attendee |
|
514 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
515 | - ) { |
|
516 | - return ' |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * Get the invoice link for the given registration. |
|
503 | + * @param EE_Transaction $transaction |
|
504 | + * @return string |
|
505 | + * @throws EE_Error |
|
506 | + */ |
|
507 | + protected function get_invoice_link(EE_Transaction $transaction) |
|
508 | + { |
|
509 | + $registration = $transaction->primary_registration(); |
|
510 | + if ($registration instanceof EE_Registration) { |
|
511 | + $url = $registration->invoice_url(); |
|
512 | + //only show invoice link if message type is active. |
|
513 | + if ($registration->attendee() instanceof EE_Attendee |
|
514 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
515 | + ) { |
|
516 | + return ' |
|
517 | 517 | <li> |
518 | 518 | <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
519 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
519 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
520 | 520 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
521 | 521 | </a> |
522 | 522 | </li>'; |
523 | - } |
|
524 | - } |
|
525 | - return ''; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * Get the receipt link for the transaction. |
|
531 | - * @param EE_Transaction $transaction |
|
532 | - * @return string |
|
533 | - * @throws EE_Error |
|
534 | - */ |
|
535 | - protected function get_receipt_link(EE_Transaction $transaction) |
|
536 | - { |
|
537 | - $registration = $transaction->primary_registration(); |
|
538 | - if ($registration instanceof EE_Registration) { |
|
539 | - $url = $registration->receipt_url(); |
|
540 | - //only show receipt link if message type is active. |
|
541 | - if ($registration->attendee() instanceof EE_Attendee |
|
542 | - && EEH_MSG_Template::is_mt_active('receipt')) { |
|
543 | - return ' |
|
523 | + } |
|
524 | + } |
|
525 | + return ''; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * Get the receipt link for the transaction. |
|
531 | + * @param EE_Transaction $transaction |
|
532 | + * @return string |
|
533 | + * @throws EE_Error |
|
534 | + */ |
|
535 | + protected function get_receipt_link(EE_Transaction $transaction) |
|
536 | + { |
|
537 | + $registration = $transaction->primary_registration(); |
|
538 | + if ($registration instanceof EE_Registration) { |
|
539 | + $url = $registration->receipt_url(); |
|
540 | + //only show receipt link if message type is active. |
|
541 | + if ($registration->attendee() instanceof EE_Attendee |
|
542 | + && EEH_MSG_Template::is_mt_active('receipt')) { |
|
543 | + return ' |
|
544 | 544 | <li> |
545 | 545 | <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
546 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
546 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
547 | 547 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> |
548 | 548 | </a> |
549 | 549 | </li>'; |
550 | - } |
|
551 | - } |
|
552 | - return ''; |
|
553 | - } |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * Get the link to view the details for the primary registration. |
|
558 | - * |
|
559 | - * @param EE_Transaction $transaction |
|
560 | - * @return string |
|
561 | - * @throws EE_Error |
|
562 | - * @throws InvalidArgumentException |
|
563 | - * @throws InvalidDataTypeException |
|
564 | - * @throws InvalidInterfaceException |
|
565 | - */ |
|
566 | - protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
567 | - { |
|
568 | - $registration = $transaction->primary_registration(); |
|
569 | - if ($registration instanceof EE_Registration) { |
|
570 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
571 | - 'action' => 'view_registration', |
|
572 | - '_REG_ID' => $registration->ID(), |
|
573 | - ), REG_ADMIN_URL); |
|
574 | - return EE_Registry::instance()->CAP->current_user_can( |
|
575 | - 'ee_read_registration', |
|
576 | - 'espresso_registrations_view_registration', |
|
577 | - $registration->ID() |
|
578 | - ) |
|
579 | - ? ' |
|
550 | + } |
|
551 | + } |
|
552 | + return ''; |
|
553 | + } |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * Get the link to view the details for the primary registration. |
|
558 | + * |
|
559 | + * @param EE_Transaction $transaction |
|
560 | + * @return string |
|
561 | + * @throws EE_Error |
|
562 | + * @throws InvalidArgumentException |
|
563 | + * @throws InvalidDataTypeException |
|
564 | + * @throws InvalidInterfaceException |
|
565 | + */ |
|
566 | + protected function get_primary_registration_details_link(EE_Transaction $transaction) |
|
567 | + { |
|
568 | + $registration = $transaction->primary_registration(); |
|
569 | + if ($registration instanceof EE_Registration) { |
|
570 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
571 | + 'action' => 'view_registration', |
|
572 | + '_REG_ID' => $registration->ID(), |
|
573 | + ), REG_ADMIN_URL); |
|
574 | + return EE_Registry::instance()->CAP->current_user_can( |
|
575 | + 'ee_read_registration', |
|
576 | + 'espresso_registrations_view_registration', |
|
577 | + $registration->ID() |
|
578 | + ) |
|
579 | + ? ' |
|
580 | 580 | <li> |
581 | 581 | <a href="' . $url . '"' |
582 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
582 | + . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
583 | 583 | <span class="dashicons dashicons-clipboard"></span> |
584 | 584 | </a> |
585 | 585 | </li>' |
586 | - : ''; |
|
587 | - } |
|
588 | - return ''; |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * Get send payment reminder trigger link |
|
594 | - * @param EE_Transaction $transaction |
|
595 | - * @return string |
|
596 | - * @throws EE_Error |
|
597 | - * @throws InvalidArgumentException |
|
598 | - * @throws InvalidDataTypeException |
|
599 | - * @throws InvalidInterfaceException |
|
600 | - */ |
|
601 | - protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
602 | - { |
|
603 | - $registration = $transaction->primary_registration(); |
|
604 | - if ($registration instanceof EE_Registration |
|
605 | - && $registration->attendee() instanceof EE_Attendee |
|
606 | - && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
607 | - && ! in_array( |
|
608 | - $transaction->status_ID(), |
|
609 | - array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
610 | - true |
|
611 | - ) |
|
612 | - && EE_Registry::instance()->CAP->current_user_can( |
|
613 | - 'ee_send_message', |
|
614 | - 'espresso_transactions_send_payment_reminder' |
|
615 | - ) |
|
616 | - ) { |
|
617 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
618 | - 'action' => 'send_payment_reminder', |
|
619 | - 'TXN_ID' => $transaction->ID(), |
|
620 | - ), TXN_ADMIN_URL); |
|
621 | - return ' |
|
586 | + : ''; |
|
587 | + } |
|
588 | + return ''; |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * Get send payment reminder trigger link |
|
594 | + * @param EE_Transaction $transaction |
|
595 | + * @return string |
|
596 | + * @throws EE_Error |
|
597 | + * @throws InvalidArgumentException |
|
598 | + * @throws InvalidDataTypeException |
|
599 | + * @throws InvalidInterfaceException |
|
600 | + */ |
|
601 | + protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) |
|
602 | + { |
|
603 | + $registration = $transaction->primary_registration(); |
|
604 | + if ($registration instanceof EE_Registration |
|
605 | + && $registration->attendee() instanceof EE_Attendee |
|
606 | + && EEH_MSG_Template::is_mt_active('payment_reminder') |
|
607 | + && ! in_array( |
|
608 | + $transaction->status_ID(), |
|
609 | + array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), |
|
610 | + true |
|
611 | + ) |
|
612 | + && EE_Registry::instance()->CAP->current_user_can( |
|
613 | + 'ee_send_message', |
|
614 | + 'espresso_transactions_send_payment_reminder' |
|
615 | + ) |
|
616 | + ) { |
|
617 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
618 | + 'action' => 'send_payment_reminder', |
|
619 | + 'TXN_ID' => $transaction->ID(), |
|
620 | + ), TXN_ADMIN_URL); |
|
621 | + return ' |
|
622 | 622 | <li> |
623 | 623 | <a href="' . $url . '"' |
624 | - . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
624 | + . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
625 | 625 | <span class="dashicons dashicons-email-alt"></span> |
626 | 626 | </a> |
627 | 627 | </li>'; |
628 | - } |
|
629 | - return ''; |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * Get link to filtered view in the message activity list table of messages for this transaction. |
|
635 | - * @param EE_Transaction $transaction |
|
636 | - * @return string |
|
637 | - * @throws EE_Error |
|
638 | - * @throws InvalidArgumentException |
|
639 | - * @throws InvalidDataTypeException |
|
640 | - * @throws InvalidInterfaceException |
|
641 | - */ |
|
642 | - protected function get_related_messages_link(EE_Transaction $transaction) |
|
643 | - { |
|
644 | - $url = EEH_MSG_Template::get_message_action_link( |
|
645 | - 'see_notifications_for', |
|
646 | - null, |
|
647 | - array('TXN_ID' => $transaction->ID()) |
|
648 | - ); |
|
649 | - return EE_Registry::instance()->CAP->current_user_can( |
|
650 | - 'ee_read_global_messages', |
|
651 | - 'view_filtered_messages' |
|
652 | - ) |
|
653 | - ? '<li>' . $url . '</li>' |
|
654 | - : ''; |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * Return the link to make a payment on the frontend |
|
660 | - * @param EE_Transaction $transaction |
|
661 | - * @return string |
|
662 | - * @throws EE_Error |
|
663 | - */ |
|
664 | - protected function get_payment_overview_link(EE_Transaction $transaction) |
|
665 | - { |
|
666 | - $registration = $transaction->primary_registration(); |
|
667 | - if ($registration instanceof EE_Registration |
|
668 | - && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
669 | - && $registration->owes_monies_and_can_pay() |
|
670 | - ) { |
|
671 | - return ' |
|
628 | + } |
|
629 | + return ''; |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * Get link to filtered view in the message activity list table of messages for this transaction. |
|
635 | + * @param EE_Transaction $transaction |
|
636 | + * @return string |
|
637 | + * @throws EE_Error |
|
638 | + * @throws InvalidArgumentException |
|
639 | + * @throws InvalidDataTypeException |
|
640 | + * @throws InvalidInterfaceException |
|
641 | + */ |
|
642 | + protected function get_related_messages_link(EE_Transaction $transaction) |
|
643 | + { |
|
644 | + $url = EEH_MSG_Template::get_message_action_link( |
|
645 | + 'see_notifications_for', |
|
646 | + null, |
|
647 | + array('TXN_ID' => $transaction->ID()) |
|
648 | + ); |
|
649 | + return EE_Registry::instance()->CAP->current_user_can( |
|
650 | + 'ee_read_global_messages', |
|
651 | + 'view_filtered_messages' |
|
652 | + ) |
|
653 | + ? '<li>' . $url . '</li>' |
|
654 | + : ''; |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * Return the link to make a payment on the frontend |
|
660 | + * @param EE_Transaction $transaction |
|
661 | + * @return string |
|
662 | + * @throws EE_Error |
|
663 | + */ |
|
664 | + protected function get_payment_overview_link(EE_Transaction $transaction) |
|
665 | + { |
|
666 | + $registration = $transaction->primary_registration(); |
|
667 | + if ($registration instanceof EE_Registration |
|
668 | + && $transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
669 | + && $registration->owes_monies_and_can_pay() |
|
670 | + ) { |
|
671 | + return ' |
|
672 | 672 | <li> |
673 | 673 | <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
674 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
675 | - . ' class="tiny-text"> |
|
674 | + . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
675 | + . ' class="tiny-text"> |
|
676 | 676 | <span class="dashicons dashicons-money ee-icon-size-18"></span> |
677 | 677 | </a> |
678 | 678 | </li> |
679 | 679 | '; |
680 | 680 | |
681 | - } |
|
682 | - return ''; |
|
683 | - } |
|
681 | + } |
|
682 | + return ''; |
|
683 | + } |
|
684 | 684 | } |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | 'ajax' => true, |
52 | 52 | 'screen' => $this->_admin_page->get_current_screen()->id, |
53 | 53 | ); |
54 | - $ID_column_name = __('ID', 'event_espresso'); |
|
54 | + $ID_column_name = __('ID', 'event_espresso'); |
|
55 | 55 | $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
56 | 56 | $ID_column_name .= __('Transaction Date', 'event_espresso'); |
57 | 57 | $ID_column_name .= '</span> '; |
58 | - $this->_columns = array( |
|
58 | + $this->_columns = array( |
|
59 | 59 | 'TXN_ID' => $ID_column_name, |
60 | 60 | 'TXN_timestamp' => __('Transaction Date', 'event_espresso'), |
61 | 61 | 'TXN_total' => __('Total', 'event_espresso'), |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | { |
91 | 91 | $class = parent::_get_row_class($transaction); |
92 | 92 | //add status class |
93 | - $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); |
|
93 | + $class .= ' ee-status-strip txn-status-'.$transaction->status_ID(); |
|
94 | 94 | if ($this->_has_checkbox_column) { |
95 | 95 | $class .= ' has-checkbox-column'; |
96 | 96 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | 'm/d/Y', |
117 | 117 | strtotime('-10 year') |
118 | 118 | ); |
119 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
119 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
120 | 120 | ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
121 | 121 | : date( |
122 | 122 | 'm/d/Y', |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | 'action' => 'view_transaction', |
162 | 162 | 'TXN_ID' => $transaction->ID(), |
163 | 163 | ), TXN_ADMIN_URL); |
164 | - $content = '<a href="' . $view_lnk_url . '"' |
|
165 | - . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' |
|
164 | + $content = '<a href="'.$view_lnk_url.'"' |
|
165 | + . ' title="'.esc_attr__('Go to Transaction Details', 'event_espresso').'">' |
|
166 | 166 | . $transaction->ID() |
167 | 167 | . '</a>'; |
168 | 168 | |
169 | 169 | //txn timestamp |
170 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; |
|
170 | + $content .= ' <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>'; |
|
171 | 171 | return $content; |
172 | 172 | } |
173 | 173 | |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | 'action' => 'view_transaction', |
228 | 228 | 'TXN_ID' => $transaction->ID(), |
229 | 229 | ), TXN_ADMIN_URL); |
230 | - $txn_date = '<a href="' . $view_lnk_url . '"' |
|
230 | + $txn_date = '<a href="'.$view_lnk_url.'"' |
|
231 | 231 | . ' title="' |
232 | - . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' |
|
232 | + . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID().'">' |
|
233 | 233 | . $this->_get_txn_timestamp($transaction) |
234 | 234 | . '</a>'; |
235 | 235 | //status |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | ) |
263 | 263 | . '</span>'; |
264 | 264 | } else { |
265 | - return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; |
|
265 | + return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>'; |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | : esc_html__('Unknown', 'event_espresso'); |
301 | 301 | $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; |
302 | 302 | |
303 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' |
|
303 | + $content = '<span class="'.$span_class.' txn-pad-rght">' |
|
304 | 304 | . $transaction_paid_content |
305 | 305 | . '</span>'; |
306 | 306 | if ($transaction_paid > 0) { |
@@ -334,17 +334,17 @@ discard block |
||
334 | 334 | 'action' => 'view_registration', |
335 | 335 | '_REG_ID' => $primary_reg->ID(), |
336 | 336 | ), REG_ADMIN_URL); |
337 | - $content = EE_Registry::instance()->CAP->current_user_can( |
|
337 | + $content = EE_Registry::instance()->CAP->current_user_can( |
|
338 | 338 | 'ee_read_registration', |
339 | 339 | 'espresso_registrations_view_registration', |
340 | 340 | $primary_reg->ID() |
341 | 341 | ) |
342 | - ? '<a href="' . $edit_lnk_url . '"' |
|
343 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' |
|
342 | + ? '<a href="'.$edit_lnk_url.'"' |
|
343 | + . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
344 | 344 | . $attendee->full_name() |
345 | 345 | . '</a>' |
346 | 346 | : $attendee->full_name(); |
347 | - $content .= '<br>' . $attendee->email(); |
|
347 | + $content .= '<br>'.$attendee->email(); |
|
348 | 348 | return $content; |
349 | 349 | } |
350 | 350 | return $transaction->failed() || $transaction->is_abandoned() |
@@ -366,8 +366,8 @@ discard block |
||
366 | 366 | public function column_ATT_email(EE_Transaction $transaction) |
367 | 367 | { |
368 | 368 | $attendee = $transaction->primary_registration()->get_first_related('Attendee'); |
369 | - if (! empty($attendee)) { |
|
370 | - return '<a href="mailto:' . $attendee->get('ATT_email') . '">' |
|
369 | + if ( ! empty($attendee)) { |
|
370 | + return '<a href="mailto:'.$attendee->get('ATT_email').'">' |
|
371 | 371 | . $attendee->get('ATT_email') |
372 | 372 | . '</a>'; |
373 | 373 | } else { |
@@ -395,12 +395,12 @@ discard block |
||
395 | 395 | { |
396 | 396 | $actions = array(); |
397 | 397 | $event = $transaction->primary_registration()->get_first_related('Event'); |
398 | - if (! empty($event)) { |
|
398 | + if ( ! empty($event)) { |
|
399 | 399 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( |
400 | 400 | array('action' => 'edit', 'post' => $event->ID()), |
401 | 401 | EVENTS_ADMIN_URL |
402 | 402 | ); |
403 | - $event_name = $event->get('EVT_name'); |
|
403 | + $event_name = $event->get('EVT_name'); |
|
404 | 404 | |
405 | 405 | //filter this view by transactions for this event |
406 | 406 | $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( |
@@ -414,8 +414,8 @@ discard block |
||
414 | 414 | $event->ID() |
415 | 415 | ) |
416 | 416 | ) { |
417 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' |
|
418 | - . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' |
|
417 | + $actions['filter_by_event'] = '<a href="'.$txn_by_event_lnk.'"' |
|
418 | + . ' title="'.esc_attr__('Filter transactions by this event', 'event_espresso').'">' |
|
419 | 419 | . esc_html__('View Transactions for this event', 'event_espresso') |
420 | 420 | . '</a>'; |
421 | 421 | } |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | 'espresso_events_edit', |
428 | 428 | $event->ID() |
429 | 429 | ) |
430 | - ? '<a href="' . $edit_event_url . '"' |
|
430 | + ? '<a href="'.$edit_event_url.'"' |
|
431 | 431 | . ' title="' |
432 | 432 | . sprintf( |
433 | 433 | esc_attr__('Edit Event: %s', 'event_espresso'), |
@@ -484,14 +484,14 @@ discard block |
||
484 | 484 | */ |
485 | 485 | protected function get_transaction_details_link(EE_Transaction $transaction) |
486 | 486 | { |
487 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
487 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
488 | 488 | 'action' => 'view_transaction', |
489 | 489 | 'TXN_ID' => $transaction->ID(), |
490 | 490 | ), TXN_ADMIN_URL); |
491 | 491 | return ' |
492 | 492 | <li> |
493 | - <a href="' . $url . '"' |
|
494 | - . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> |
|
493 | + <a href="' . $url.'"' |
|
494 | + . ' title="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="tiny-text"> |
|
495 | 495 | <span class="dashicons dashicons-cart"></span> |
496 | 496 | </a> |
497 | 497 | </li>'; |
@@ -515,8 +515,8 @@ discard block |
||
515 | 515 | ) { |
516 | 516 | return ' |
517 | 517 | <li> |
518 | - <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' |
|
519 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
518 | + <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"' |
|
519 | + . ' target="_blank" href="'.$url.'" class="tiny-text"> |
|
520 | 520 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
521 | 521 | </a> |
522 | 522 | </li>'; |
@@ -542,8 +542,8 @@ discard block |
||
542 | 542 | && EEH_MSG_Template::is_mt_active('receipt')) { |
543 | 543 | return ' |
544 | 544 | <li> |
545 | - <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' |
|
546 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> |
|
545 | + <a title="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"' |
|
546 | + . ' target="_blank" href="'.$url.'" class="tiny-text"> |
|
547 | 547 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> |
548 | 548 | </a> |
549 | 549 | </li>'; |
@@ -578,8 +578,8 @@ discard block |
||
578 | 578 | ) |
579 | 579 | ? ' |
580 | 580 | <li> |
581 | - <a href="' . $url . '"' |
|
582 | - . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
581 | + <a href="' . $url.'"' |
|
582 | + . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text"> |
|
583 | 583 | <span class="dashicons dashicons-clipboard"></span> |
584 | 584 | </a> |
585 | 585 | </li>' |
@@ -620,8 +620,8 @@ discard block |
||
620 | 620 | ), TXN_ADMIN_URL); |
621 | 621 | return ' |
622 | 622 | <li> |
623 | - <a href="' . $url . '"' |
|
624 | - . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> |
|
623 | + <a href="' . $url.'"' |
|
624 | + . ' title="'.esc_attr__('Send Payment Reminder', 'event_espresso').'" class="tiny-text"> |
|
625 | 625 | <span class="dashicons dashicons-email-alt"></span> |
626 | 626 | </a> |
627 | 627 | </li>'; |
@@ -650,7 +650,7 @@ discard block |
||
650 | 650 | 'ee_read_global_messages', |
651 | 651 | 'view_filtered_messages' |
652 | 652 | ) |
653 | - ? '<li>' . $url . '</li>' |
|
653 | + ? '<li>'.$url.'</li>' |
|
654 | 654 | : ''; |
655 | 655 | } |
656 | 656 | |
@@ -670,8 +670,8 @@ discard block |
||
670 | 670 | ) { |
671 | 671 | return ' |
672 | 672 | <li> |
673 | - <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' |
|
674 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' |
|
673 | + <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"' |
|
674 | + . ' target="_blank" href="'.$registration->payment_overview_url(true).'"' |
|
675 | 675 | . ' class="tiny-text"> |
676 | 676 | <span class="dashicons dashicons-money ee-icon-size-18"></span> |
677 | 677 | </a> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
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 | |
@@ -22,975 +22,975 @@ discard block |
||
22 | 22 | class EED_Ticket_Sales_Monitor extends EED_Module |
23 | 23 | { |
24 | 24 | |
25 | - const debug = false; // true false |
|
26 | - |
|
27 | - /** |
|
28 | - * an array of raw ticket data from EED_Ticket_Selector |
|
29 | - * |
|
30 | - * @var array $ticket_selections |
|
31 | - */ |
|
32 | - protected $ticket_selections = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | - * according to how they are displayed in the actual Ticket_Selector |
|
37 | - * this tracks the current row being processed |
|
38 | - * |
|
39 | - * @var int $current_row |
|
40 | - */ |
|
41 | - protected $current_row = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * an array for tracking names of tickets that have sold out |
|
45 | - * |
|
46 | - * @var array $sold_out_tickets |
|
47 | - */ |
|
48 | - protected $sold_out_tickets = array(); |
|
49 | - |
|
50 | - /** |
|
51 | - * an array for tracking names of tickets that have had their quantities reduced |
|
52 | - * |
|
53 | - * @var array $decremented_tickets |
|
54 | - */ |
|
55 | - protected $decremented_tickets = array(); |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public static function set_hooks() |
|
65 | - { |
|
66 | - // release tickets for expired carts |
|
67 | - add_action( |
|
68 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | - 1 |
|
71 | - ); |
|
72 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | - add_filter( |
|
74 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | - 20, |
|
77 | - 3 |
|
78 | - ); |
|
79 | - // add notices for sold out tickets |
|
80 | - add_action( |
|
81 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | - 10 |
|
84 | - ); |
|
85 | - // handle ticket quantities adjusted in cart |
|
86 | - //add_action( |
|
87 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
88 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
89 | - // 10, 2 |
|
90 | - //); |
|
91 | - // handle tickets deleted from cart |
|
92 | - add_action( |
|
93 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
94 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
95 | - 10, |
|
96 | - 2 |
|
97 | - ); |
|
98 | - // handle emptied carts |
|
99 | - add_action( |
|
100 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
101 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
102 | - 10, |
|
103 | - 1 |
|
104 | - ); |
|
105 | - add_action( |
|
106 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
107 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
108 | - 10, |
|
109 | - 1 |
|
110 | - ); |
|
111 | - // handle cancelled registrations |
|
112 | - add_action( |
|
113 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
114 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
115 | - 10, |
|
116 | - 1 |
|
117 | - ); |
|
118 | - // cron tasks |
|
119 | - add_action( |
|
120 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
121 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
122 | - 10, |
|
123 | - 1 |
|
124 | - ); |
|
125 | - add_action( |
|
126 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
127 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
128 | - 10, |
|
129 | - 1 |
|
130 | - ); |
|
131 | - add_action( |
|
132 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
133 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
134 | - 10, |
|
135 | - 1 |
|
136 | - ); |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
143 | - * |
|
144 | - * @return void |
|
145 | - */ |
|
146 | - public static function set_hooks_admin() |
|
147 | - { |
|
148 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
155 | - */ |
|
156 | - public static function instance() |
|
157 | - { |
|
158 | - return parent::get_instance(__CLASS__); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param WP_Query $WP_Query |
|
165 | - * @return void |
|
166 | - */ |
|
167 | - public function run($WP_Query) |
|
168 | - { |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * Retrieves grand totals from the line items that have no TXN ID |
|
179 | - * and timestamps less than the current time minus the session lifespan. |
|
180 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
181 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
182 | - * |
|
183 | - * @return void |
|
184 | - * @throws EE_Error |
|
185 | - * @throws InvalidArgumentException |
|
186 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
187 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
188 | - */ |
|
189 | - public static function release_tickets_for_expired_carts() |
|
190 | - { |
|
191 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
192 | - $expired_ticket_IDs = array(); |
|
193 | - $valid_ticket_line_items = array(); |
|
194 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
195 | - if (empty($total_line_items)) { |
|
196 | - do_action( |
|
197 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
198 | - $total_line_items, |
|
199 | - $valid_ticket_line_items, |
|
200 | - $expired_ticket_IDs |
|
201 | - ); |
|
202 | - return; |
|
203 | - } |
|
204 | - $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
205 | - foreach ($total_line_items as $total_line_item) { |
|
206 | - /** @var EE_Line_Item $total_line_item */ |
|
207 | - $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
208 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
209 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
210 | - continue; |
|
211 | - } |
|
212 | - if ($total_line_item->timestamp(true) <= $expired) { |
|
213 | - $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
214 | - } else { |
|
215 | - $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
216 | - } |
|
217 | - } |
|
218 | - } |
|
219 | - if (! empty($expired_ticket_IDs)) { |
|
220 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
221 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
222 | - $valid_ticket_line_items |
|
223 | - ); |
|
224 | - // let's get rid of expired line items so that they can't interfere with tracking |
|
225 | - add_action( |
|
226 | - 'shutdown', |
|
227 | - array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
228 | - 999 |
|
229 | - ); |
|
230 | - } |
|
231 | - do_action( |
|
232 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
233 | - $total_line_items, |
|
234 | - $valid_ticket_line_items, |
|
235 | - $expired_ticket_IDs |
|
236 | - ); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
242 | - |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
247 | - * |
|
248 | - * @param int $qty |
|
249 | - * @param EE_Ticket $ticket |
|
250 | - * @return bool |
|
251 | - * @throws UnexpectedEntityException |
|
252 | - * @throws EE_Error |
|
253 | - */ |
|
254 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
255 | - { |
|
256 | - $qty = absint($qty); |
|
257 | - if ($qty > 0) { |
|
258 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
259 | - } |
|
260 | - if (self::debug) { |
|
261 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
262 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
263 | - } |
|
264 | - return $qty; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
271 | - * |
|
272 | - * @param EE_Ticket $ticket |
|
273 | - * @param int $qty |
|
274 | - * @return int |
|
275 | - * @throws UnexpectedEntityException |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
279 | - { |
|
280 | - if (self::debug) { |
|
281 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
282 | - } |
|
283 | - if (! $ticket instanceof EE_Ticket) { |
|
284 | - return 0; |
|
285 | - } |
|
286 | - if (self::debug) { |
|
287 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
288 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
289 | - } |
|
290 | - $ticket->refresh_from_db(); |
|
291 | - // first let's determine the ticket availability based on sales |
|
292 | - $available = $ticket->qty('saleable'); |
|
293 | - if (self::debug) { |
|
294 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
295 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
296 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
297 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
298 | - echo '<br /> . . . available: ' . $available; |
|
299 | - } |
|
300 | - if ($available < 1) { |
|
301 | - $this->_ticket_sold_out($ticket); |
|
302 | - return 0; |
|
303 | - } |
|
304 | - if (self::debug) { |
|
305 | - echo '<br /> . . . qty: ' . $qty; |
|
306 | - } |
|
307 | - if ($available < $qty) { |
|
308 | - $qty = $available; |
|
309 | - if (self::debug) { |
|
310 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
311 | - } |
|
312 | - $this->_ticket_quantity_decremented($ticket); |
|
313 | - } |
|
314 | - $this->_reserve_ticket($ticket, $qty); |
|
315 | - return $qty; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * increments ticket reserved based on quantity passed |
|
322 | - * |
|
323 | - * @param EE_Ticket $ticket |
|
324 | - * @param int $quantity |
|
325 | - * @return bool |
|
326 | - * @throws EE_Error |
|
327 | - */ |
|
328 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
329 | - { |
|
330 | - if (self::debug) { |
|
331 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
332 | - } |
|
333 | - $ticket->increase_reserved($quantity); |
|
334 | - return $ticket->save(); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @param EE_Ticket $ticket |
|
341 | - * @param int $quantity |
|
342 | - * @return bool |
|
343 | - * @throws EE_Error |
|
344 | - */ |
|
345 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
346 | - { |
|
347 | - if (self::debug) { |
|
348 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
349 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
350 | - } |
|
351 | - $ticket->decrease_reserved($quantity); |
|
352 | - if (self::debug) { |
|
353 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
354 | - } |
|
355 | - return $ticket->save() ? 1 : 0; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * removes quantities within the ticket selector based on zero ticket availability |
|
362 | - * |
|
363 | - * @param EE_Ticket $ticket |
|
364 | - * @return void |
|
365 | - * @throws UnexpectedEntityException |
|
366 | - * @throws EE_Error |
|
367 | - */ |
|
368 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
369 | - { |
|
370 | - if (self::debug) { |
|
371 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
372 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
373 | - } |
|
374 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
381 | - * |
|
382 | - * @param EE_Ticket $ticket |
|
383 | - * @return void |
|
384 | - * @throws UnexpectedEntityException |
|
385 | - * @throws EE_Error |
|
386 | - */ |
|
387 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
388 | - { |
|
389 | - if (self::debug) { |
|
390 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
391 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
392 | - } |
|
393 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - |
|
398 | - /** |
|
399 | - * builds string out of ticket and event name |
|
400 | - * |
|
401 | - * @param EE_Ticket $ticket |
|
402 | - * @return string |
|
403 | - * @throws UnexpectedEntityException |
|
404 | - * @throws EE_Error |
|
405 | - */ |
|
406 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
407 | - { |
|
408 | - $event = $ticket->get_related_event(); |
|
409 | - if ($event instanceof EE_Event) { |
|
410 | - $ticket_name = sprintf( |
|
411 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
412 | - $ticket->name(), |
|
413 | - $event->name() |
|
414 | - ); |
|
415 | - } else { |
|
416 | - $ticket_name = $ticket->name(); |
|
417 | - } |
|
418 | - return $ticket_name; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /********************************** EVENT CART **********************************/ |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * releases or reserves ticket(s) based on quantity passed |
|
429 | - * |
|
430 | - * @param EE_Line_Item $line_item |
|
431 | - * @param int $quantity |
|
432 | - * @return void |
|
433 | - * @throws EE_Error |
|
434 | - * @throws InvalidArgumentException |
|
435 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
436 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
437 | - */ |
|
438 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
439 | - { |
|
440 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
441 | - if ($ticket instanceof EE_Ticket) { |
|
442 | - if ($quantity > 0) { |
|
443 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
444 | - } else { |
|
445 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
446 | - } |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * releases reserved ticket(s) based on quantity passed |
|
454 | - * |
|
455 | - * @param EE_Ticket $ticket |
|
456 | - * @param int $quantity |
|
457 | - * @return void |
|
458 | - * @throws EE_Error |
|
459 | - */ |
|
460 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
461 | - { |
|
462 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /********************************** POST_NOTICES **********************************/ |
|
468 | - |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * @return void |
|
473 | - * @throws EE_Error |
|
474 | - * @throws InvalidArgumentException |
|
475 | - * @throws ReflectionException |
|
476 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
477 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
478 | - */ |
|
479 | - public static function post_notices() |
|
480 | - { |
|
481 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * @return void |
|
488 | - * @throws EE_Error |
|
489 | - * @throws InvalidArgumentException |
|
490 | - * @throws ReflectionException |
|
491 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
492 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
493 | - */ |
|
494 | - protected function _post_notices() |
|
495 | - { |
|
496 | - if (self::debug) { |
|
497 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
498 | - } |
|
499 | - $refresh_msg = ''; |
|
500 | - $none_added_msg = ''; |
|
501 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
502 | - $refresh_msg = __( |
|
503 | - 'Please refresh the page to view updated ticket quantities.', |
|
504 | - 'event_espresso' |
|
505 | - ); |
|
506 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
507 | - } |
|
508 | - if (! empty($this->sold_out_tickets)) { |
|
509 | - EE_Error::add_attention( |
|
510 | - sprintf( |
|
511 | - apply_filters( |
|
512 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
513 | - __( |
|
514 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
515 | - 'event_espresso' |
|
516 | - ) |
|
517 | - ), |
|
518 | - '<br />', |
|
519 | - implode('<br />', $this->sold_out_tickets), |
|
520 | - $none_added_msg, |
|
521 | - $refresh_msg |
|
522 | - ) |
|
523 | - ); |
|
524 | - // alter code flow in the Ticket Selector for better UX |
|
525 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
526 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
527 | - $this->sold_out_tickets = array(); |
|
528 | - // and reset the cart |
|
529 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
530 | - } |
|
531 | - if (! empty($this->decremented_tickets)) { |
|
532 | - EE_Error::add_attention( |
|
533 | - sprintf( |
|
534 | - apply_filters( |
|
535 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
536 | - __( |
|
537 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
538 | - 'event_espresso' |
|
539 | - ) |
|
540 | - ), |
|
541 | - '<br />', |
|
542 | - implode('<br />', $this->decremented_tickets), |
|
543 | - $none_added_msg, |
|
544 | - $refresh_msg |
|
545 | - ) |
|
546 | - ); |
|
547 | - $this->decremented_tickets = array(); |
|
548 | - } |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - |
|
553 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
554 | - |
|
555 | - |
|
556 | - |
|
557 | - /** |
|
558 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
559 | - * by default, will NOT release tickets for finalized transactions |
|
560 | - * |
|
561 | - * @param EE_Transaction $transaction |
|
562 | - * @return int |
|
563 | - * @throws EE_Error |
|
564 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
565 | - */ |
|
566 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
567 | - { |
|
568 | - if (self::debug) { |
|
569 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
570 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
571 | - } |
|
572 | - // check if 'finalize_registration' step has been completed... |
|
573 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
574 | - if (self::debug) { |
|
575 | - // DEBUG LOG |
|
576 | - EEH_Debug_Tools::log( |
|
577 | - __CLASS__, |
|
578 | - __FUNCTION__, |
|
579 | - __LINE__, |
|
580 | - array('finalized' => $finalized), |
|
581 | - false, |
|
582 | - 'EE_Transaction: ' . $transaction->ID() |
|
583 | - ); |
|
584 | - } |
|
585 | - // how many tickets were released |
|
586 | - $count = 0; |
|
587 | - if (self::debug) { |
|
588 | - echo '<br /> . . . finalized: ' . $finalized; |
|
589 | - } |
|
590 | - $release_tickets_with_TXN_status = array( |
|
591 | - EEM_Transaction::failed_status_code, |
|
592 | - EEM_Transaction::abandoned_status_code, |
|
593 | - EEM_Transaction::incomplete_status_code, |
|
594 | - ); |
|
595 | - // if the session is getting cleared BEFORE the TXN has been finalized |
|
596 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
597 | - // let's cancel any reserved tickets |
|
598 | - $registrations = $transaction->registrations(); |
|
599 | - if (! empty($registrations)) { |
|
600 | - foreach ($registrations as $registration) { |
|
601 | - if ($registration instanceof EE_Registration) { |
|
602 | - $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
603 | - } |
|
604 | - } |
|
605 | - } |
|
606 | - } |
|
607 | - return $count; |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * releases reserved tickets for an EE_Registration |
|
614 | - * by default, will NOT release tickets for APPROVED registrations |
|
615 | - * |
|
616 | - * @param EE_Registration $registration |
|
617 | - * @param EE_Transaction $transaction |
|
618 | - * @return int |
|
619 | - * @throws EE_Error |
|
620 | - */ |
|
621 | - protected function _release_reserved_ticket_for_registration( |
|
622 | - EE_Registration $registration, |
|
623 | - EE_Transaction $transaction |
|
624 | - ) { |
|
625 | - $STS_ID = $transaction->status_ID(); |
|
626 | - if (self::debug) { |
|
627 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
628 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
629 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
630 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
631 | - } |
|
632 | - if ( |
|
633 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
634 | - $STS_ID === EEM_Transaction::failed_status_code |
|
635 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
636 | - || ( |
|
637 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
638 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
639 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
640 | - ) |
|
641 | - ) { |
|
642 | - $ticket = $registration->ticket(); |
|
643 | - if ($ticket instanceof EE_Ticket) { |
|
644 | - return $this->_release_reserved_ticket($ticket); |
|
645 | - } |
|
646 | - } |
|
647 | - return 0; |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - |
|
652 | - /********************************** SESSION_CART_RESET **********************************/ |
|
653 | - |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
658 | - * |
|
659 | - * @param EE_Session $session |
|
660 | - * @return void |
|
661 | - * @throws EE_Error |
|
662 | - * @throws InvalidArgumentException |
|
663 | - * @throws ReflectionException |
|
664 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
665 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
666 | - */ |
|
667 | - public static function session_cart_reset(EE_Session $session) |
|
668 | - { |
|
669 | - if (self::debug) { |
|
670 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
671 | - } |
|
672 | - $cart = $session->cart(); |
|
673 | - if ($cart instanceof EE_Cart) { |
|
674 | - if (self::debug) { |
|
675 | - echo '<br /><br /> cart instance of EE_Cart: '; |
|
676 | - } |
|
677 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
678 | - } else { |
|
679 | - if (self::debug) { |
|
680 | - echo '<br /><br /> invalid EE_Cart: '; |
|
681 | - var_export($cart, true); |
|
682 | - } |
|
683 | - } |
|
684 | - } |
|
685 | - |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * releases reserved tickets in the EE_Cart |
|
690 | - * |
|
691 | - * @param EE_Cart $cart |
|
692 | - * @return void |
|
693 | - * @throws EE_Error |
|
694 | - * @throws InvalidArgumentException |
|
695 | - * @throws ReflectionException |
|
696 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
697 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
698 | - */ |
|
699 | - protected function _session_cart_reset(EE_Cart $cart) |
|
700 | - { |
|
701 | - if (self::debug) { |
|
702 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
703 | - } |
|
704 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
705 | - $ticket_line_items = $cart->get_tickets(); |
|
706 | - if (empty($ticket_line_items)) { |
|
707 | - return; |
|
708 | - } |
|
709 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
710 | - if (self::debug) { |
|
711 | - echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
712 | - } |
|
713 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
714 | - if (self::debug) { |
|
715 | - echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
716 | - } |
|
717 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
718 | - if ($ticket instanceof EE_Ticket) { |
|
719 | - if (self::debug) { |
|
720 | - echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
721 | - echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
722 | - } |
|
723 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
724 | - } |
|
725 | - } |
|
726 | - } |
|
727 | - if (self::debug) { |
|
728 | - echo '<br /><br /> RESET COMPLETED '; |
|
729 | - } |
|
730 | - } |
|
731 | - |
|
732 | - |
|
733 | - |
|
734 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
735 | - |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
740 | - * |
|
741 | - * @param EE_Session $session |
|
742 | - * @return void |
|
743 | - * @throws EE_Error |
|
744 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
745 | - */ |
|
746 | - public static function session_checkout_reset(EE_Session $session) |
|
747 | - { |
|
748 | - $checkout = $session->checkout(); |
|
749 | - if ($checkout instanceof EE_Checkout) { |
|
750 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
751 | - } |
|
752 | - } |
|
753 | - |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * releases reserved tickets for the EE_Checkout->transaction |
|
758 | - * |
|
759 | - * @param EE_Checkout $checkout |
|
760 | - * @return void |
|
761 | - * @throws EE_Error |
|
762 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
763 | - */ |
|
764 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
765 | - { |
|
766 | - if (self::debug) { |
|
767 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
768 | - } |
|
769 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
770 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
771 | - return; |
|
772 | - } |
|
773 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
774 | - } |
|
775 | - |
|
776 | - |
|
777 | - |
|
778 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
779 | - |
|
780 | - |
|
781 | - |
|
782 | - /** |
|
783 | - * @param EE_Session $session |
|
784 | - * @return void |
|
785 | - */ |
|
786 | - public static function session_expired_reset(EE_Session $session) |
|
787 | - { |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - |
|
792 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
793 | - |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
798 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
799 | - * |
|
800 | - * @param EE_Transaction $transaction |
|
801 | - * @return void |
|
802 | - * @throws EE_Error |
|
803 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
804 | - */ |
|
805 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
806 | - { |
|
807 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
808 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
809 | - if (self::debug) { |
|
810 | - // DEBUG LOG |
|
811 | - EEH_Debug_Tools::log( |
|
812 | - __CLASS__, |
|
813 | - __FUNCTION__, |
|
814 | - __LINE__, |
|
815 | - array($transaction), |
|
816 | - false, |
|
817 | - 'EE_Transaction: ' . $transaction->ID() |
|
818 | - ); |
|
819 | - } |
|
820 | - return; |
|
821 | - } |
|
822 | - // have their been any successful payments made ? |
|
823 | - $payments = $transaction->payments(); |
|
824 | - foreach ($payments as $payment) { |
|
825 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
826 | - if (self::debug) { |
|
827 | - // DEBUG LOG |
|
828 | - EEH_Debug_Tools::log( |
|
829 | - __CLASS__, |
|
830 | - __FUNCTION__, |
|
831 | - __LINE__, |
|
832 | - array($payment), |
|
833 | - false, |
|
834 | - 'EE_Transaction: ' . $transaction->ID() |
|
835 | - ); |
|
836 | - } |
|
837 | - return; |
|
838 | - } |
|
839 | - } |
|
840 | - // since you haven't even attempted to pay for your ticket... |
|
841 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
842 | - } |
|
843 | - |
|
844 | - |
|
845 | - |
|
846 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
847 | - |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
852 | - * |
|
853 | - * @param EE_Transaction $transaction |
|
854 | - * @return void |
|
855 | - * @throws EE_Error |
|
856 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
857 | - */ |
|
858 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
859 | - { |
|
860 | - // since you haven't even attempted to pay for your ticket... |
|
861 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - |
|
866 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
867 | - /** |
|
868 | - * Resets all ticket and datetime reserved counts to zero |
|
869 | - * Tickets that are currently associated with a Transaction that is in progress |
|
870 | - * |
|
871 | - * @throws \EE_Error |
|
872 | - * @throws \DomainException |
|
873 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
874 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
875 | - * @throws \InvalidArgumentException |
|
876 | - */ |
|
877 | - public static function reset_reservation_counts() |
|
878 | - { |
|
879 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
880 | - $valid_reserved_tickets = array(); |
|
881 | - $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
882 | - foreach ($transactions_in_progress as $transaction_in_progress) { |
|
883 | - // if this TXN has been fully completed, then skip it |
|
884 | - if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
885 | - continue; |
|
886 | - } |
|
887 | - /** @var EE_Transaction $transaction_in_progress */ |
|
888 | - $total_line_item = $transaction_in_progress->total_line_item(); |
|
889 | - // $transaction_in_progress->line |
|
890 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
891 | - throw new DomainException( |
|
892 | - esc_html__( |
|
893 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
894 | - 'event_espresso' |
|
895 | - ) |
|
896 | - ); |
|
897 | - } |
|
898 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
899 | - $total_line_item |
|
900 | - ); |
|
901 | - } |
|
902 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
903 | - foreach ($total_line_items as $total_line_item) { |
|
904 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
905 | - $total_line_item |
|
906 | - ); |
|
907 | - } |
|
908 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
909 | - EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
910 | - $valid_reserved_tickets |
|
911 | - ); |
|
912 | - } |
|
913 | - |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * @param EE_Line_Item $total_line_item |
|
918 | - * @return EE_Line_Item[] |
|
919 | - */ |
|
920 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
921 | - { |
|
922 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
923 | - $valid_reserved_tickets = array(); |
|
924 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
925 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
926 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
927 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
928 | - } |
|
929 | - } |
|
930 | - return $valid_reserved_tickets; |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - |
|
935 | - /** |
|
936 | - * @param EE_Ticket[] $tickets_with_reservations |
|
937 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
938 | - * @return int |
|
939 | - * @throws \EE_Error |
|
940 | - */ |
|
941 | - private static function release_reservations_for_tickets( |
|
942 | - array $tickets_with_reservations, |
|
943 | - $valid_reserved_ticket_line_items = array() |
|
944 | - ) { |
|
945 | - $total_tickets_released = 0; |
|
946 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
947 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
948 | - continue; |
|
949 | - } |
|
950 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
951 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
952 | - if ( |
|
953 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
954 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
955 | - ) { |
|
956 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
957 | - } |
|
958 | - } |
|
959 | - if ($reserved_qty > 0) { |
|
960 | - $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
961 | - $ticket_with_reservations->save(); |
|
962 | - $total_tickets_released += $reserved_qty; |
|
963 | - } |
|
964 | - } |
|
965 | - return $total_tickets_released; |
|
966 | - } |
|
967 | - |
|
968 | - |
|
969 | - |
|
970 | - /********************************** SHUTDOWN **********************************/ |
|
971 | - |
|
972 | - |
|
973 | - |
|
974 | - /** |
|
975 | - * @return false|int |
|
976 | - * @throws EE_Error |
|
977 | - * @throws InvalidArgumentException |
|
978 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
979 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
980 | - */ |
|
981 | - public static function clear_expired_line_items_with_no_transaction() |
|
982 | - { |
|
983 | - /** @type WPDB $wpdb */ |
|
984 | - global $wpdb; |
|
985 | - return $wpdb->query( |
|
986 | - $wpdb->prepare( |
|
987 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
25 | + const debug = false; // true false |
|
26 | + |
|
27 | + /** |
|
28 | + * an array of raw ticket data from EED_Ticket_Selector |
|
29 | + * |
|
30 | + * @var array $ticket_selections |
|
31 | + */ |
|
32 | + protected $ticket_selections = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | + * according to how they are displayed in the actual Ticket_Selector |
|
37 | + * this tracks the current row being processed |
|
38 | + * |
|
39 | + * @var int $current_row |
|
40 | + */ |
|
41 | + protected $current_row = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * an array for tracking names of tickets that have sold out |
|
45 | + * |
|
46 | + * @var array $sold_out_tickets |
|
47 | + */ |
|
48 | + protected $sold_out_tickets = array(); |
|
49 | + |
|
50 | + /** |
|
51 | + * an array for tracking names of tickets that have had their quantities reduced |
|
52 | + * |
|
53 | + * @var array $decremented_tickets |
|
54 | + */ |
|
55 | + protected $decremented_tickets = array(); |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public static function set_hooks() |
|
65 | + { |
|
66 | + // release tickets for expired carts |
|
67 | + add_action( |
|
68 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | + 1 |
|
71 | + ); |
|
72 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | + add_filter( |
|
74 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | + 20, |
|
77 | + 3 |
|
78 | + ); |
|
79 | + // add notices for sold out tickets |
|
80 | + add_action( |
|
81 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | + 10 |
|
84 | + ); |
|
85 | + // handle ticket quantities adjusted in cart |
|
86 | + //add_action( |
|
87 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
88 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
89 | + // 10, 2 |
|
90 | + //); |
|
91 | + // handle tickets deleted from cart |
|
92 | + add_action( |
|
93 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
94 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
95 | + 10, |
|
96 | + 2 |
|
97 | + ); |
|
98 | + // handle emptied carts |
|
99 | + add_action( |
|
100 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
101 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
102 | + 10, |
|
103 | + 1 |
|
104 | + ); |
|
105 | + add_action( |
|
106 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
107 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
108 | + 10, |
|
109 | + 1 |
|
110 | + ); |
|
111 | + // handle cancelled registrations |
|
112 | + add_action( |
|
113 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
114 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
115 | + 10, |
|
116 | + 1 |
|
117 | + ); |
|
118 | + // cron tasks |
|
119 | + add_action( |
|
120 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
121 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
122 | + 10, |
|
123 | + 1 |
|
124 | + ); |
|
125 | + add_action( |
|
126 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
127 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
128 | + 10, |
|
129 | + 1 |
|
130 | + ); |
|
131 | + add_action( |
|
132 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
133 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
134 | + 10, |
|
135 | + 1 |
|
136 | + ); |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
143 | + * |
|
144 | + * @return void |
|
145 | + */ |
|
146 | + public static function set_hooks_admin() |
|
147 | + { |
|
148 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
155 | + */ |
|
156 | + public static function instance() |
|
157 | + { |
|
158 | + return parent::get_instance(__CLASS__); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param WP_Query $WP_Query |
|
165 | + * @return void |
|
166 | + */ |
|
167 | + public function run($WP_Query) |
|
168 | + { |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * Retrieves grand totals from the line items that have no TXN ID |
|
179 | + * and timestamps less than the current time minus the session lifespan. |
|
180 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
181 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
182 | + * |
|
183 | + * @return void |
|
184 | + * @throws EE_Error |
|
185 | + * @throws InvalidArgumentException |
|
186 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
187 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
188 | + */ |
|
189 | + public static function release_tickets_for_expired_carts() |
|
190 | + { |
|
191 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
192 | + $expired_ticket_IDs = array(); |
|
193 | + $valid_ticket_line_items = array(); |
|
194 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
195 | + if (empty($total_line_items)) { |
|
196 | + do_action( |
|
197 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
198 | + $total_line_items, |
|
199 | + $valid_ticket_line_items, |
|
200 | + $expired_ticket_IDs |
|
201 | + ); |
|
202 | + return; |
|
203 | + } |
|
204 | + $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
205 | + foreach ($total_line_items as $total_line_item) { |
|
206 | + /** @var EE_Line_Item $total_line_item */ |
|
207 | + $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
208 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
209 | + if (! $ticket_line_item instanceof EE_Line_Item) { |
|
210 | + continue; |
|
211 | + } |
|
212 | + if ($total_line_item->timestamp(true) <= $expired) { |
|
213 | + $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
214 | + } else { |
|
215 | + $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
216 | + } |
|
217 | + } |
|
218 | + } |
|
219 | + if (! empty($expired_ticket_IDs)) { |
|
220 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
221 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
222 | + $valid_ticket_line_items |
|
223 | + ); |
|
224 | + // let's get rid of expired line items so that they can't interfere with tracking |
|
225 | + add_action( |
|
226 | + 'shutdown', |
|
227 | + array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
228 | + 999 |
|
229 | + ); |
|
230 | + } |
|
231 | + do_action( |
|
232 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
233 | + $total_line_items, |
|
234 | + $valid_ticket_line_items, |
|
235 | + $expired_ticket_IDs |
|
236 | + ); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + |
|
241 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
242 | + |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
247 | + * |
|
248 | + * @param int $qty |
|
249 | + * @param EE_Ticket $ticket |
|
250 | + * @return bool |
|
251 | + * @throws UnexpectedEntityException |
|
252 | + * @throws EE_Error |
|
253 | + */ |
|
254 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
255 | + { |
|
256 | + $qty = absint($qty); |
|
257 | + if ($qty > 0) { |
|
258 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
259 | + } |
|
260 | + if (self::debug) { |
|
261 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
262 | + echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
263 | + } |
|
264 | + return $qty; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
271 | + * |
|
272 | + * @param EE_Ticket $ticket |
|
273 | + * @param int $qty |
|
274 | + * @return int |
|
275 | + * @throws UnexpectedEntityException |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
279 | + { |
|
280 | + if (self::debug) { |
|
281 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
282 | + } |
|
283 | + if (! $ticket instanceof EE_Ticket) { |
|
284 | + return 0; |
|
285 | + } |
|
286 | + if (self::debug) { |
|
287 | + echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
288 | + echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
289 | + } |
|
290 | + $ticket->refresh_from_db(); |
|
291 | + // first let's determine the ticket availability based on sales |
|
292 | + $available = $ticket->qty('saleable'); |
|
293 | + if (self::debug) { |
|
294 | + echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
295 | + echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
296 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
297 | + echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
298 | + echo '<br /> . . . available: ' . $available; |
|
299 | + } |
|
300 | + if ($available < 1) { |
|
301 | + $this->_ticket_sold_out($ticket); |
|
302 | + return 0; |
|
303 | + } |
|
304 | + if (self::debug) { |
|
305 | + echo '<br /> . . . qty: ' . $qty; |
|
306 | + } |
|
307 | + if ($available < $qty) { |
|
308 | + $qty = $available; |
|
309 | + if (self::debug) { |
|
310 | + echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
311 | + } |
|
312 | + $this->_ticket_quantity_decremented($ticket); |
|
313 | + } |
|
314 | + $this->_reserve_ticket($ticket, $qty); |
|
315 | + return $qty; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * increments ticket reserved based on quantity passed |
|
322 | + * |
|
323 | + * @param EE_Ticket $ticket |
|
324 | + * @param int $quantity |
|
325 | + * @return bool |
|
326 | + * @throws EE_Error |
|
327 | + */ |
|
328 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
329 | + { |
|
330 | + if (self::debug) { |
|
331 | + echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
332 | + } |
|
333 | + $ticket->increase_reserved($quantity); |
|
334 | + return $ticket->save(); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @param EE_Ticket $ticket |
|
341 | + * @param int $quantity |
|
342 | + * @return bool |
|
343 | + * @throws EE_Error |
|
344 | + */ |
|
345 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
346 | + { |
|
347 | + if (self::debug) { |
|
348 | + echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
349 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
350 | + } |
|
351 | + $ticket->decrease_reserved($quantity); |
|
352 | + if (self::debug) { |
|
353 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
354 | + } |
|
355 | + return $ticket->save() ? 1 : 0; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * removes quantities within the ticket selector based on zero ticket availability |
|
362 | + * |
|
363 | + * @param EE_Ticket $ticket |
|
364 | + * @return void |
|
365 | + * @throws UnexpectedEntityException |
|
366 | + * @throws EE_Error |
|
367 | + */ |
|
368 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
369 | + { |
|
370 | + if (self::debug) { |
|
371 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
372 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
373 | + } |
|
374 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
381 | + * |
|
382 | + * @param EE_Ticket $ticket |
|
383 | + * @return void |
|
384 | + * @throws UnexpectedEntityException |
|
385 | + * @throws EE_Error |
|
386 | + */ |
|
387 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
388 | + { |
|
389 | + if (self::debug) { |
|
390 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
391 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
392 | + } |
|
393 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + |
|
398 | + /** |
|
399 | + * builds string out of ticket and event name |
|
400 | + * |
|
401 | + * @param EE_Ticket $ticket |
|
402 | + * @return string |
|
403 | + * @throws UnexpectedEntityException |
|
404 | + * @throws EE_Error |
|
405 | + */ |
|
406 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
407 | + { |
|
408 | + $event = $ticket->get_related_event(); |
|
409 | + if ($event instanceof EE_Event) { |
|
410 | + $ticket_name = sprintf( |
|
411 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
412 | + $ticket->name(), |
|
413 | + $event->name() |
|
414 | + ); |
|
415 | + } else { |
|
416 | + $ticket_name = $ticket->name(); |
|
417 | + } |
|
418 | + return $ticket_name; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /********************************** EVENT CART **********************************/ |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * releases or reserves ticket(s) based on quantity passed |
|
429 | + * |
|
430 | + * @param EE_Line_Item $line_item |
|
431 | + * @param int $quantity |
|
432 | + * @return void |
|
433 | + * @throws EE_Error |
|
434 | + * @throws InvalidArgumentException |
|
435 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
436 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
437 | + */ |
|
438 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
439 | + { |
|
440 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
441 | + if ($ticket instanceof EE_Ticket) { |
|
442 | + if ($quantity > 0) { |
|
443 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
444 | + } else { |
|
445 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
446 | + } |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * releases reserved ticket(s) based on quantity passed |
|
454 | + * |
|
455 | + * @param EE_Ticket $ticket |
|
456 | + * @param int $quantity |
|
457 | + * @return void |
|
458 | + * @throws EE_Error |
|
459 | + */ |
|
460 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
461 | + { |
|
462 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /********************************** POST_NOTICES **********************************/ |
|
468 | + |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * @return void |
|
473 | + * @throws EE_Error |
|
474 | + * @throws InvalidArgumentException |
|
475 | + * @throws ReflectionException |
|
476 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
477 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
478 | + */ |
|
479 | + public static function post_notices() |
|
480 | + { |
|
481 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * @return void |
|
488 | + * @throws EE_Error |
|
489 | + * @throws InvalidArgumentException |
|
490 | + * @throws ReflectionException |
|
491 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
492 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
493 | + */ |
|
494 | + protected function _post_notices() |
|
495 | + { |
|
496 | + if (self::debug) { |
|
497 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
498 | + } |
|
499 | + $refresh_msg = ''; |
|
500 | + $none_added_msg = ''; |
|
501 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
502 | + $refresh_msg = __( |
|
503 | + 'Please refresh the page to view updated ticket quantities.', |
|
504 | + 'event_espresso' |
|
505 | + ); |
|
506 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
507 | + } |
|
508 | + if (! empty($this->sold_out_tickets)) { |
|
509 | + EE_Error::add_attention( |
|
510 | + sprintf( |
|
511 | + apply_filters( |
|
512 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
513 | + __( |
|
514 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
515 | + 'event_espresso' |
|
516 | + ) |
|
517 | + ), |
|
518 | + '<br />', |
|
519 | + implode('<br />', $this->sold_out_tickets), |
|
520 | + $none_added_msg, |
|
521 | + $refresh_msg |
|
522 | + ) |
|
523 | + ); |
|
524 | + // alter code flow in the Ticket Selector for better UX |
|
525 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
526 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
527 | + $this->sold_out_tickets = array(); |
|
528 | + // and reset the cart |
|
529 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
530 | + } |
|
531 | + if (! empty($this->decremented_tickets)) { |
|
532 | + EE_Error::add_attention( |
|
533 | + sprintf( |
|
534 | + apply_filters( |
|
535 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
536 | + __( |
|
537 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
538 | + 'event_espresso' |
|
539 | + ) |
|
540 | + ), |
|
541 | + '<br />', |
|
542 | + implode('<br />', $this->decremented_tickets), |
|
543 | + $none_added_msg, |
|
544 | + $refresh_msg |
|
545 | + ) |
|
546 | + ); |
|
547 | + $this->decremented_tickets = array(); |
|
548 | + } |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + |
|
553 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
554 | + |
|
555 | + |
|
556 | + |
|
557 | + /** |
|
558 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
559 | + * by default, will NOT release tickets for finalized transactions |
|
560 | + * |
|
561 | + * @param EE_Transaction $transaction |
|
562 | + * @return int |
|
563 | + * @throws EE_Error |
|
564 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
565 | + */ |
|
566 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
567 | + { |
|
568 | + if (self::debug) { |
|
569 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
570 | + echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
571 | + } |
|
572 | + // check if 'finalize_registration' step has been completed... |
|
573 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
574 | + if (self::debug) { |
|
575 | + // DEBUG LOG |
|
576 | + EEH_Debug_Tools::log( |
|
577 | + __CLASS__, |
|
578 | + __FUNCTION__, |
|
579 | + __LINE__, |
|
580 | + array('finalized' => $finalized), |
|
581 | + false, |
|
582 | + 'EE_Transaction: ' . $transaction->ID() |
|
583 | + ); |
|
584 | + } |
|
585 | + // how many tickets were released |
|
586 | + $count = 0; |
|
587 | + if (self::debug) { |
|
588 | + echo '<br /> . . . finalized: ' . $finalized; |
|
589 | + } |
|
590 | + $release_tickets_with_TXN_status = array( |
|
591 | + EEM_Transaction::failed_status_code, |
|
592 | + EEM_Transaction::abandoned_status_code, |
|
593 | + EEM_Transaction::incomplete_status_code, |
|
594 | + ); |
|
595 | + // if the session is getting cleared BEFORE the TXN has been finalized |
|
596 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
597 | + // let's cancel any reserved tickets |
|
598 | + $registrations = $transaction->registrations(); |
|
599 | + if (! empty($registrations)) { |
|
600 | + foreach ($registrations as $registration) { |
|
601 | + if ($registration instanceof EE_Registration) { |
|
602 | + $count += $this->_release_reserved_ticket_for_registration($registration, $transaction); |
|
603 | + } |
|
604 | + } |
|
605 | + } |
|
606 | + } |
|
607 | + return $count; |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * releases reserved tickets for an EE_Registration |
|
614 | + * by default, will NOT release tickets for APPROVED registrations |
|
615 | + * |
|
616 | + * @param EE_Registration $registration |
|
617 | + * @param EE_Transaction $transaction |
|
618 | + * @return int |
|
619 | + * @throws EE_Error |
|
620 | + */ |
|
621 | + protected function _release_reserved_ticket_for_registration( |
|
622 | + EE_Registration $registration, |
|
623 | + EE_Transaction $transaction |
|
624 | + ) { |
|
625 | + $STS_ID = $transaction->status_ID(); |
|
626 | + if (self::debug) { |
|
627 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
628 | + echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
629 | + echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
630 | + echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
631 | + } |
|
632 | + if ( |
|
633 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
634 | + $STS_ID === EEM_Transaction::failed_status_code |
|
635 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
636 | + || ( |
|
637 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
638 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
639 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
640 | + ) |
|
641 | + ) { |
|
642 | + $ticket = $registration->ticket(); |
|
643 | + if ($ticket instanceof EE_Ticket) { |
|
644 | + return $this->_release_reserved_ticket($ticket); |
|
645 | + } |
|
646 | + } |
|
647 | + return 0; |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + |
|
652 | + /********************************** SESSION_CART_RESET **********************************/ |
|
653 | + |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
658 | + * |
|
659 | + * @param EE_Session $session |
|
660 | + * @return void |
|
661 | + * @throws EE_Error |
|
662 | + * @throws InvalidArgumentException |
|
663 | + * @throws ReflectionException |
|
664 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
665 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
666 | + */ |
|
667 | + public static function session_cart_reset(EE_Session $session) |
|
668 | + { |
|
669 | + if (self::debug) { |
|
670 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
671 | + } |
|
672 | + $cart = $session->cart(); |
|
673 | + if ($cart instanceof EE_Cart) { |
|
674 | + if (self::debug) { |
|
675 | + echo '<br /><br /> cart instance of EE_Cart: '; |
|
676 | + } |
|
677 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart); |
|
678 | + } else { |
|
679 | + if (self::debug) { |
|
680 | + echo '<br /><br /> invalid EE_Cart: '; |
|
681 | + var_export($cart, true); |
|
682 | + } |
|
683 | + } |
|
684 | + } |
|
685 | + |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * releases reserved tickets in the EE_Cart |
|
690 | + * |
|
691 | + * @param EE_Cart $cart |
|
692 | + * @return void |
|
693 | + * @throws EE_Error |
|
694 | + * @throws InvalidArgumentException |
|
695 | + * @throws ReflectionException |
|
696 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
697 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
698 | + */ |
|
699 | + protected function _session_cart_reset(EE_Cart $cart) |
|
700 | + { |
|
701 | + if (self::debug) { |
|
702 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
703 | + } |
|
704 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
705 | + $ticket_line_items = $cart->get_tickets(); |
|
706 | + if (empty($ticket_line_items)) { |
|
707 | + return; |
|
708 | + } |
|
709 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
710 | + if (self::debug) { |
|
711 | + echo '<br /> . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
712 | + } |
|
713 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
714 | + if (self::debug) { |
|
715 | + echo '<br /> . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
716 | + } |
|
717 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
718 | + if ($ticket instanceof EE_Ticket) { |
|
719 | + if (self::debug) { |
|
720 | + echo '<br /> . . ticket->ID(): ' . $ticket->ID(); |
|
721 | + echo '<br /> . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
722 | + } |
|
723 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
724 | + } |
|
725 | + } |
|
726 | + } |
|
727 | + if (self::debug) { |
|
728 | + echo '<br /><br /> RESET COMPLETED '; |
|
729 | + } |
|
730 | + } |
|
731 | + |
|
732 | + |
|
733 | + |
|
734 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
735 | + |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
740 | + * |
|
741 | + * @param EE_Session $session |
|
742 | + * @return void |
|
743 | + * @throws EE_Error |
|
744 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
745 | + */ |
|
746 | + public static function session_checkout_reset(EE_Session $session) |
|
747 | + { |
|
748 | + $checkout = $session->checkout(); |
|
749 | + if ($checkout instanceof EE_Checkout) { |
|
750 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
751 | + } |
|
752 | + } |
|
753 | + |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * releases reserved tickets for the EE_Checkout->transaction |
|
758 | + * |
|
759 | + * @param EE_Checkout $checkout |
|
760 | + * @return void |
|
761 | + * @throws EE_Error |
|
762 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
763 | + */ |
|
764 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
765 | + { |
|
766 | + if (self::debug) { |
|
767 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
768 | + } |
|
769 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
770 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
771 | + return; |
|
772 | + } |
|
773 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
774 | + } |
|
775 | + |
|
776 | + |
|
777 | + |
|
778 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
779 | + |
|
780 | + |
|
781 | + |
|
782 | + /** |
|
783 | + * @param EE_Session $session |
|
784 | + * @return void |
|
785 | + */ |
|
786 | + public static function session_expired_reset(EE_Session $session) |
|
787 | + { |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + |
|
792 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
793 | + |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
798 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
799 | + * |
|
800 | + * @param EE_Transaction $transaction |
|
801 | + * @return void |
|
802 | + * @throws EE_Error |
|
803 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
804 | + */ |
|
805 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
806 | + { |
|
807 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
808 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
809 | + if (self::debug) { |
|
810 | + // DEBUG LOG |
|
811 | + EEH_Debug_Tools::log( |
|
812 | + __CLASS__, |
|
813 | + __FUNCTION__, |
|
814 | + __LINE__, |
|
815 | + array($transaction), |
|
816 | + false, |
|
817 | + 'EE_Transaction: ' . $transaction->ID() |
|
818 | + ); |
|
819 | + } |
|
820 | + return; |
|
821 | + } |
|
822 | + // have their been any successful payments made ? |
|
823 | + $payments = $transaction->payments(); |
|
824 | + foreach ($payments as $payment) { |
|
825 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
826 | + if (self::debug) { |
|
827 | + // DEBUG LOG |
|
828 | + EEH_Debug_Tools::log( |
|
829 | + __CLASS__, |
|
830 | + __FUNCTION__, |
|
831 | + __LINE__, |
|
832 | + array($payment), |
|
833 | + false, |
|
834 | + 'EE_Transaction: ' . $transaction->ID() |
|
835 | + ); |
|
836 | + } |
|
837 | + return; |
|
838 | + } |
|
839 | + } |
|
840 | + // since you haven't even attempted to pay for your ticket... |
|
841 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
842 | + } |
|
843 | + |
|
844 | + |
|
845 | + |
|
846 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
847 | + |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
852 | + * |
|
853 | + * @param EE_Transaction $transaction |
|
854 | + * @return void |
|
855 | + * @throws EE_Error |
|
856 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
857 | + */ |
|
858 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
859 | + { |
|
860 | + // since you haven't even attempted to pay for your ticket... |
|
861 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + |
|
866 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
867 | + /** |
|
868 | + * Resets all ticket and datetime reserved counts to zero |
|
869 | + * Tickets that are currently associated with a Transaction that is in progress |
|
870 | + * |
|
871 | + * @throws \EE_Error |
|
872 | + * @throws \DomainException |
|
873 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
874 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
875 | + * @throws \InvalidArgumentException |
|
876 | + */ |
|
877 | + public static function reset_reservation_counts() |
|
878 | + { |
|
879 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
880 | + $valid_reserved_tickets = array(); |
|
881 | + $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
882 | + foreach ($transactions_in_progress as $transaction_in_progress) { |
|
883 | + // if this TXN has been fully completed, then skip it |
|
884 | + if ($transaction_in_progress->reg_step_completed('finalize_registration')) { |
|
885 | + continue; |
|
886 | + } |
|
887 | + /** @var EE_Transaction $transaction_in_progress */ |
|
888 | + $total_line_item = $transaction_in_progress->total_line_item(); |
|
889 | + // $transaction_in_progress->line |
|
890 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
891 | + throw new DomainException( |
|
892 | + esc_html__( |
|
893 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
894 | + 'event_espresso' |
|
895 | + ) |
|
896 | + ); |
|
897 | + } |
|
898 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
899 | + $total_line_item |
|
900 | + ); |
|
901 | + } |
|
902 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
903 | + foreach ($total_line_items as $total_line_item) { |
|
904 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
905 | + $total_line_item |
|
906 | + ); |
|
907 | + } |
|
908 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
909 | + EEM_Ticket::instance()->get_tickets_with_reservations(), |
|
910 | + $valid_reserved_tickets |
|
911 | + ); |
|
912 | + } |
|
913 | + |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * @param EE_Line_Item $total_line_item |
|
918 | + * @return EE_Line_Item[] |
|
919 | + */ |
|
920 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
921 | + { |
|
922 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
923 | + $valid_reserved_tickets = array(); |
|
924 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
925 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
926 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
927 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
928 | + } |
|
929 | + } |
|
930 | + return $valid_reserved_tickets; |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + |
|
935 | + /** |
|
936 | + * @param EE_Ticket[] $tickets_with_reservations |
|
937 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
938 | + * @return int |
|
939 | + * @throws \EE_Error |
|
940 | + */ |
|
941 | + private static function release_reservations_for_tickets( |
|
942 | + array $tickets_with_reservations, |
|
943 | + $valid_reserved_ticket_line_items = array() |
|
944 | + ) { |
|
945 | + $total_tickets_released = 0; |
|
946 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
947 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
948 | + continue; |
|
949 | + } |
|
950 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
951 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
952 | + if ( |
|
953 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
954 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
955 | + ) { |
|
956 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
957 | + } |
|
958 | + } |
|
959 | + if ($reserved_qty > 0) { |
|
960 | + $ticket_with_reservations->decrease_reserved($reserved_qty); |
|
961 | + $ticket_with_reservations->save(); |
|
962 | + $total_tickets_released += $reserved_qty; |
|
963 | + } |
|
964 | + } |
|
965 | + return $total_tickets_released; |
|
966 | + } |
|
967 | + |
|
968 | + |
|
969 | + |
|
970 | + /********************************** SHUTDOWN **********************************/ |
|
971 | + |
|
972 | + |
|
973 | + |
|
974 | + /** |
|
975 | + * @return false|int |
|
976 | + * @throws EE_Error |
|
977 | + * @throws InvalidArgumentException |
|
978 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
979 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
980 | + */ |
|
981 | + public static function clear_expired_line_items_with_no_transaction() |
|
982 | + { |
|
983 | + /** @type WPDB $wpdb */ |
|
984 | + global $wpdb; |
|
985 | + return $wpdb->query( |
|
986 | + $wpdb->prepare( |
|
987 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
988 | 988 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
989 | - // use GMT time because that's what LIN_timestamps are in |
|
990 | - date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
991 | - ) |
|
992 | - ); |
|
993 | - } |
|
989 | + // use GMT time because that's what LIN_timestamps are in |
|
990 | + date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
991 | + ) |
|
992 | + ); |
|
993 | + } |
|
994 | 994 | |
995 | 995 | } |
996 | 996 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * cancelTicketSelections |
43 | 43 | * |
44 | - * @return string |
|
44 | + * @return false|null |
|
45 | 45 | * @throws EE_Error |
46 | 46 | * @throws InvalidArgumentException |
47 | 47 | * @throws InvalidInterfaceException |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * process_ticket_selections |
115 | 115 | * |
116 | - * @return array|bool |
|
116 | + * @return boolean|null |
|
117 | 117 | * @throws \ReflectionException |
118 | 118 | * @throws InvalidArgumentException |
119 | 119 | * @throws InvalidInterfaceException |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * validate_post_data |
288 | 288 | * |
289 | 289 | * @param int $id |
290 | - * @return array|FALSE |
|
290 | + * @return string |
|
291 | 291 | * @throws \ReflectionException |
292 | 292 | * @throws InvalidArgumentException |
293 | 293 | * @throws InvalidInterfaceException |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * |
411 | 411 | * @param EE_Ticket $ticket |
412 | 412 | * @param int $qty |
413 | - * @return TRUE on success, FALSE on fail |
|
413 | + * @return boolean on success, FALSE on fail |
|
414 | 414 | * @throws InvalidArgumentException |
415 | 415 | * @throws InvalidInterfaceException |
416 | 416 | * @throws InvalidDataTypeException |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use InvalidArgumentException; |
14 | 14 | |
15 | 15 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
16 | - exit('No direct script access allowed'); |
|
16 | + exit('No direct script access allowed'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
@@ -30,592 +30,592 @@ discard block |
||
30 | 30 | class ProcessTicketSelector |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * array of datetimes and the spaces available for them |
|
35 | - * |
|
36 | - * @var array[][] |
|
37 | - */ |
|
38 | - private static $_available_spaces = array(); |
|
33 | + /** |
|
34 | + * array of datetimes and the spaces available for them |
|
35 | + * |
|
36 | + * @var array[][] |
|
37 | + */ |
|
38 | + private static $_available_spaces = array(); |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * cancelTicketSelections |
|
43 | - * |
|
44 | - * @return string |
|
45 | - * @throws EE_Error |
|
46 | - * @throws InvalidArgumentException |
|
47 | - * @throws InvalidInterfaceException |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - */ |
|
50 | - public function cancelTicketSelections() |
|
51 | - { |
|
52 | - // check nonce |
|
53 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
54 | - return false; |
|
55 | - } |
|
56 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
57 | - if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
58 | - wp_safe_redirect( |
|
59 | - EEH_Event_View::event_link_url( |
|
60 | - EE_Registry::instance()->REQ->get('event_id') |
|
61 | - ) |
|
62 | - ); |
|
63 | - } else { |
|
64 | - wp_safe_redirect( |
|
65 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
66 | - ); |
|
67 | - } |
|
68 | - exit(); |
|
69 | - } |
|
41 | + /** |
|
42 | + * cancelTicketSelections |
|
43 | + * |
|
44 | + * @return string |
|
45 | + * @throws EE_Error |
|
46 | + * @throws InvalidArgumentException |
|
47 | + * @throws InvalidInterfaceException |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + */ |
|
50 | + public function cancelTicketSelections() |
|
51 | + { |
|
52 | + // check nonce |
|
53 | + if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
54 | + return false; |
|
55 | + } |
|
56 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
57 | + if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
58 | + wp_safe_redirect( |
|
59 | + EEH_Event_View::event_link_url( |
|
60 | + EE_Registry::instance()->REQ->get('event_id') |
|
61 | + ) |
|
62 | + ); |
|
63 | + } else { |
|
64 | + wp_safe_redirect( |
|
65 | + site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
66 | + ); |
|
67 | + } |
|
68 | + exit(); |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * processTicketSelectorNonce |
|
74 | - * |
|
75 | - * @param string $nonce_name |
|
76 | - * @param string $id |
|
77 | - * @return bool |
|
78 | - * @throws InvalidArgumentException |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - */ |
|
82 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
83 | - { |
|
84 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
85 | - if ( |
|
86 | - ! is_admin() |
|
87 | - && ( |
|
88 | - ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
89 | - || ! wp_verify_nonce( |
|
90 | - EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
91 | - $nonce_name |
|
92 | - ) |
|
93 | - ) |
|
94 | - ) { |
|
95 | - EE_Error::add_error( |
|
96 | - sprintf( |
|
97 | - __( |
|
98 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
99 | - 'event_espresso' |
|
100 | - ), |
|
101 | - '<br/>' |
|
102 | - ), |
|
103 | - __FILE__, |
|
104 | - __FUNCTION__, |
|
105 | - __LINE__ |
|
106 | - ); |
|
107 | - return false; |
|
108 | - } |
|
109 | - return true; |
|
110 | - } |
|
72 | + /** |
|
73 | + * processTicketSelectorNonce |
|
74 | + * |
|
75 | + * @param string $nonce_name |
|
76 | + * @param string $id |
|
77 | + * @return bool |
|
78 | + * @throws InvalidArgumentException |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + */ |
|
82 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
83 | + { |
|
84 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
85 | + if ( |
|
86 | + ! is_admin() |
|
87 | + && ( |
|
88 | + ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
89 | + || ! wp_verify_nonce( |
|
90 | + EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
91 | + $nonce_name |
|
92 | + ) |
|
93 | + ) |
|
94 | + ) { |
|
95 | + EE_Error::add_error( |
|
96 | + sprintf( |
|
97 | + __( |
|
98 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
99 | + 'event_espresso' |
|
100 | + ), |
|
101 | + '<br/>' |
|
102 | + ), |
|
103 | + __FILE__, |
|
104 | + __FUNCTION__, |
|
105 | + __LINE__ |
|
106 | + ); |
|
107 | + return false; |
|
108 | + } |
|
109 | + return true; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * process_ticket_selections |
|
115 | - * |
|
116 | - * @return array|bool |
|
117 | - * @throws \ReflectionException |
|
118 | - * @throws InvalidArgumentException |
|
119 | - * @throws InvalidInterfaceException |
|
120 | - * @throws InvalidDataTypeException |
|
121 | - * @throws EE_Error |
|
122 | - */ |
|
123 | - public function processTicketSelections() |
|
124 | - { |
|
125 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
126 | - // do we have an event id? |
|
127 | - if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
128 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
129 | - EE_Error::add_error( |
|
130 | - sprintf( |
|
131 | - __( |
|
132 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
133 | - 'event_espresso' |
|
134 | - ), |
|
135 | - '<br/>' |
|
136 | - ), |
|
137 | - __FILE__, |
|
138 | - __FUNCTION__, |
|
139 | - __LINE__ |
|
140 | - ); |
|
141 | - } |
|
142 | - //if event id is valid |
|
143 | - $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
144 | - // d( \EE_Registry::instance()->REQ ); |
|
145 | - self::$_available_spaces = array( |
|
146 | - 'tickets' => array(), |
|
147 | - 'datetimes' => array(), |
|
148 | - ); |
|
149 | - //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
150 | - // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
151 | - EE_Registry::instance()->load_core('Session'); |
|
152 | - // unless otherwise requested, clear the session |
|
153 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
154 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
155 | - } |
|
156 | - //d( \EE_Registry::instance()->SSN ); |
|
157 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
158 | - // validate/sanitize data |
|
159 | - $valid = $this->validatePostData($id); |
|
160 | - //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
161 | - //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
162 | - //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
163 | - //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
164 | - //check total tickets ordered vs max number of attendees that can register |
|
165 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
166 | - // ordering too many tickets !!! |
|
167 | - $total_tickets_string = _n( |
|
168 | - 'You have attempted to purchase %s ticket.', |
|
169 | - 'You have attempted to purchase %s tickets.', |
|
170 | - $valid['total_tickets'], |
|
171 | - 'event_espresso' |
|
172 | - ); |
|
173 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
174 | - // dev only message |
|
175 | - $max_atndz_string = _n( |
|
176 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
177 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
178 | - $valid['max_atndz'], |
|
179 | - 'event_espresso' |
|
180 | - ); |
|
181 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
182 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
183 | - } else { |
|
184 | - // all data appears to be valid |
|
185 | - $tckts_slctd = false; |
|
186 | - $tickets_added = 0; |
|
187 | - $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
188 | - $valid); |
|
189 | - if ($valid['total_tickets'] > 0) { |
|
190 | - // load cart |
|
191 | - EE_Registry::instance()->load_core('Cart'); |
|
192 | - // cycle thru the number of data rows sent from the event listing |
|
193 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
194 | - // does this row actually contain a ticket quantity? |
|
195 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
196 | - // YES we have a ticket quantity |
|
197 | - $tckts_slctd = true; |
|
198 | - // d( $valid['ticket_obj'][$x] ); |
|
199 | - if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
200 | - // then add ticket to cart |
|
201 | - $tickets_added += $this->addTicketToCart( |
|
202 | - $valid['ticket_obj'][ $x ], |
|
203 | - $valid['qty'][ $x ] |
|
204 | - ); |
|
205 | - if (EE_Error::has_error()) { |
|
206 | - break; |
|
207 | - } |
|
208 | - } else { |
|
209 | - // nothing added to cart retrieved |
|
210 | - EE_Error::add_error( |
|
211 | - sprintf( |
|
212 | - __( |
|
213 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
214 | - 'event_espresso' |
|
215 | - ), |
|
216 | - '<br/>' |
|
217 | - ), |
|
218 | - __FILE__, __FUNCTION__, __LINE__ |
|
219 | - ); |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - do_action( |
|
225 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
226 | - EE_Registry::instance()->CART, |
|
227 | - $this |
|
228 | - ); |
|
229 | - //d( \EE_Registry::instance()->CART ); |
|
230 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
231 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
232 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
233 | - do_action( |
|
234 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
235 | - EE_Registry::instance()->CART, |
|
236 | - $this |
|
237 | - ); |
|
238 | - EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
239 | - EE_Registry::instance()->CART->save_cart(false); |
|
240 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
241 | - // just return TRUE for registrations being made from admin |
|
242 | - if (is_admin()) { |
|
243 | - return true; |
|
244 | - } |
|
245 | - EE_Error::get_notices(false, true); |
|
246 | - wp_safe_redirect( |
|
247 | - apply_filters( |
|
248 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
249 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
250 | - ) |
|
251 | - ); |
|
252 | - exit(); |
|
253 | - } else { |
|
254 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
255 | - // nothing added to cart |
|
256 | - EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
257 | - __FILE__, __FUNCTION__, __LINE__); |
|
258 | - } |
|
259 | - } |
|
260 | - } else { |
|
261 | - // no ticket quantities were selected |
|
262 | - EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
263 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
264 | - } |
|
265 | - } |
|
266 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
267 | - // at this point, just return if registration is being made from admin |
|
268 | - if (is_admin()) { |
|
269 | - return false; |
|
270 | - } |
|
271 | - if ($valid['return_url']) { |
|
272 | - EE_Error::get_notices(false, true); |
|
273 | - wp_safe_redirect($valid['return_url']); |
|
274 | - exit(); |
|
275 | - } elseif (isset($event_to_add['id'])) { |
|
276 | - EE_Error::get_notices(false, true); |
|
277 | - wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
278 | - exit(); |
|
279 | - } else { |
|
280 | - echo EE_Error::get_notices(); |
|
281 | - } |
|
282 | - return false; |
|
283 | - } |
|
113 | + /** |
|
114 | + * process_ticket_selections |
|
115 | + * |
|
116 | + * @return array|bool |
|
117 | + * @throws \ReflectionException |
|
118 | + * @throws InvalidArgumentException |
|
119 | + * @throws InvalidInterfaceException |
|
120 | + * @throws InvalidDataTypeException |
|
121 | + * @throws EE_Error |
|
122 | + */ |
|
123 | + public function processTicketSelections() |
|
124 | + { |
|
125 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
126 | + // do we have an event id? |
|
127 | + if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
128 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
129 | + EE_Error::add_error( |
|
130 | + sprintf( |
|
131 | + __( |
|
132 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
133 | + 'event_espresso' |
|
134 | + ), |
|
135 | + '<br/>' |
|
136 | + ), |
|
137 | + __FILE__, |
|
138 | + __FUNCTION__, |
|
139 | + __LINE__ |
|
140 | + ); |
|
141 | + } |
|
142 | + //if event id is valid |
|
143 | + $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
144 | + // d( \EE_Registry::instance()->REQ ); |
|
145 | + self::$_available_spaces = array( |
|
146 | + 'tickets' => array(), |
|
147 | + 'datetimes' => array(), |
|
148 | + ); |
|
149 | + //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
150 | + // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
151 | + EE_Registry::instance()->load_core('Session'); |
|
152 | + // unless otherwise requested, clear the session |
|
153 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
154 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
155 | + } |
|
156 | + //d( \EE_Registry::instance()->SSN ); |
|
157 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
158 | + // validate/sanitize data |
|
159 | + $valid = $this->validatePostData($id); |
|
160 | + //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
161 | + //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
162 | + //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
163 | + //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
164 | + //check total tickets ordered vs max number of attendees that can register |
|
165 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
166 | + // ordering too many tickets !!! |
|
167 | + $total_tickets_string = _n( |
|
168 | + 'You have attempted to purchase %s ticket.', |
|
169 | + 'You have attempted to purchase %s tickets.', |
|
170 | + $valid['total_tickets'], |
|
171 | + 'event_espresso' |
|
172 | + ); |
|
173 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
174 | + // dev only message |
|
175 | + $max_atndz_string = _n( |
|
176 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
177 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
178 | + $valid['max_atndz'], |
|
179 | + 'event_espresso' |
|
180 | + ); |
|
181 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
182 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
183 | + } else { |
|
184 | + // all data appears to be valid |
|
185 | + $tckts_slctd = false; |
|
186 | + $tickets_added = 0; |
|
187 | + $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
188 | + $valid); |
|
189 | + if ($valid['total_tickets'] > 0) { |
|
190 | + // load cart |
|
191 | + EE_Registry::instance()->load_core('Cart'); |
|
192 | + // cycle thru the number of data rows sent from the event listing |
|
193 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
194 | + // does this row actually contain a ticket quantity? |
|
195 | + if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
196 | + // YES we have a ticket quantity |
|
197 | + $tckts_slctd = true; |
|
198 | + // d( $valid['ticket_obj'][$x] ); |
|
199 | + if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
200 | + // then add ticket to cart |
|
201 | + $tickets_added += $this->addTicketToCart( |
|
202 | + $valid['ticket_obj'][ $x ], |
|
203 | + $valid['qty'][ $x ] |
|
204 | + ); |
|
205 | + if (EE_Error::has_error()) { |
|
206 | + break; |
|
207 | + } |
|
208 | + } else { |
|
209 | + // nothing added to cart retrieved |
|
210 | + EE_Error::add_error( |
|
211 | + sprintf( |
|
212 | + __( |
|
213 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
214 | + 'event_espresso' |
|
215 | + ), |
|
216 | + '<br/>' |
|
217 | + ), |
|
218 | + __FILE__, __FUNCTION__, __LINE__ |
|
219 | + ); |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + do_action( |
|
225 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
226 | + EE_Registry::instance()->CART, |
|
227 | + $this |
|
228 | + ); |
|
229 | + //d( \EE_Registry::instance()->CART ); |
|
230 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
231 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
232 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
233 | + do_action( |
|
234 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
235 | + EE_Registry::instance()->CART, |
|
236 | + $this |
|
237 | + ); |
|
238 | + EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
239 | + EE_Registry::instance()->CART->save_cart(false); |
|
240 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
241 | + // just return TRUE for registrations being made from admin |
|
242 | + if (is_admin()) { |
|
243 | + return true; |
|
244 | + } |
|
245 | + EE_Error::get_notices(false, true); |
|
246 | + wp_safe_redirect( |
|
247 | + apply_filters( |
|
248 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
249 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
250 | + ) |
|
251 | + ); |
|
252 | + exit(); |
|
253 | + } else { |
|
254 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
255 | + // nothing added to cart |
|
256 | + EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
257 | + __FILE__, __FUNCTION__, __LINE__); |
|
258 | + } |
|
259 | + } |
|
260 | + } else { |
|
261 | + // no ticket quantities were selected |
|
262 | + EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
263 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
264 | + } |
|
265 | + } |
|
266 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
267 | + // at this point, just return if registration is being made from admin |
|
268 | + if (is_admin()) { |
|
269 | + return false; |
|
270 | + } |
|
271 | + if ($valid['return_url']) { |
|
272 | + EE_Error::get_notices(false, true); |
|
273 | + wp_safe_redirect($valid['return_url']); |
|
274 | + exit(); |
|
275 | + } elseif (isset($event_to_add['id'])) { |
|
276 | + EE_Error::get_notices(false, true); |
|
277 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
278 | + exit(); |
|
279 | + } else { |
|
280 | + echo EE_Error::get_notices(); |
|
281 | + } |
|
282 | + return false; |
|
283 | + } |
|
284 | 284 | |
285 | 285 | |
286 | - /** |
|
287 | - * validate_post_data |
|
288 | - * |
|
289 | - * @param int $id |
|
290 | - * @return array|FALSE |
|
291 | - * @throws \ReflectionException |
|
292 | - * @throws InvalidArgumentException |
|
293 | - * @throws InvalidInterfaceException |
|
294 | - * @throws InvalidDataTypeException |
|
295 | - * @throws EE_Error |
|
296 | - */ |
|
297 | - private function validatePostData($id = 0) |
|
298 | - { |
|
299 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
300 | - if (! $id) { |
|
301 | - EE_Error::add_error( |
|
302 | - __('The event id provided was not valid.', 'event_espresso'), |
|
303 | - __FILE__, |
|
304 | - __FUNCTION__, |
|
305 | - __LINE__ |
|
306 | - ); |
|
307 | - return false; |
|
308 | - } |
|
309 | - // start with an empty array() |
|
310 | - $valid_data = array(); |
|
311 | - // grab valid id |
|
312 | - $valid_data['id'] = $id; |
|
313 | - // array of other form names |
|
314 | - $inputs_to_clean = array( |
|
315 | - 'event_id' => 'tkt-slctr-event-id', |
|
316 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
317 | - 'rows' => 'tkt-slctr-rows-', |
|
318 | - 'qty' => 'tkt-slctr-qty-', |
|
319 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
320 | - 'return_url' => 'tkt-slctr-return-url-', |
|
321 | - ); |
|
322 | - // let's track the total number of tickets ordered.' |
|
323 | - $valid_data['total_tickets'] = 0; |
|
324 | - // cycle through $inputs_to_clean array |
|
325 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
326 | - // check for POST data |
|
327 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
328 | - // grab value |
|
329 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
330 | - switch ($what) { |
|
331 | - // integers |
|
332 | - case 'event_id': |
|
333 | - $valid_data[ $what ] = absint($input_value); |
|
334 | - // get event via the event id we put in the form |
|
335 | - $valid_data['event'] = EE_Registry::instance() |
|
336 | - ->load_model('Event') |
|
337 | - ->get_one_by_ID($valid_data['event_id']); |
|
338 | - break; |
|
339 | - case 'rows': |
|
340 | - case 'max_atndz': |
|
341 | - $valid_data[ $what ] = absint($input_value); |
|
342 | - break; |
|
343 | - // arrays of integers |
|
344 | - case 'qty': |
|
345 | - /** @var array $row_qty */ |
|
346 | - $row_qty = $input_value; |
|
347 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
348 | - if (! is_array($row_qty)) { |
|
349 | - // get number of rows |
|
350 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
351 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
352 | - : 1; |
|
353 | - // explode ints by the dash |
|
354 | - $row_qty = explode('-', $row_qty); |
|
355 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
356 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
357 | - $row_qty = array($row => $qty); |
|
358 | - for ($x = 1; $x <= $rows; $x++) { |
|
359 | - if (! isset($row_qty[ $x ])) { |
|
360 | - $row_qty[ $x ] = 0; |
|
361 | - } |
|
362 | - } |
|
363 | - } |
|
364 | - ksort($row_qty); |
|
365 | - // cycle thru values |
|
366 | - foreach ($row_qty as $qty) { |
|
367 | - $qty = absint($qty); |
|
368 | - // sanitize as integers |
|
369 | - $valid_data[ $what ][] = $qty; |
|
370 | - $valid_data['total_tickets'] += $qty; |
|
371 | - } |
|
372 | - break; |
|
373 | - // array of integers |
|
374 | - case 'ticket_id': |
|
375 | - $value_array = array(); |
|
376 | - // cycle thru values |
|
377 | - foreach ((array) $input_value as $key => $value) { |
|
378 | - // allow only numbers, letters, spaces, commas and dashes |
|
379 | - $value_array[ $key ] = wp_strip_all_tags($value); |
|
380 | - // get ticket via the ticket id we put in the form |
|
381 | - $ticket_obj = EE_Registry::instance() |
|
382 | - ->load_model('Ticket') |
|
383 | - ->get_one_by_ID($value); |
|
384 | - $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
385 | - } |
|
386 | - $valid_data[ $what ] = $value_array; |
|
387 | - break; |
|
388 | - case 'return_url' : |
|
389 | - // grab and sanitize return-url |
|
390 | - $input_value = esc_url_raw($input_value); |
|
391 | - // was the request coming from an iframe ? if so, then: |
|
392 | - if (strpos($input_value, 'event_list=iframe')) { |
|
393 | - // get anchor fragment |
|
394 | - $input_value = explode('#', $input_value); |
|
395 | - $input_value = end($input_value); |
|
396 | - // use event list url instead, but append anchor |
|
397 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
398 | - } |
|
399 | - $valid_data[ $what ] = $input_value; |
|
400 | - break; |
|
401 | - } // end switch $what |
|
402 | - } |
|
403 | - } // end foreach $inputs_to_clean |
|
404 | - return $valid_data; |
|
405 | - } |
|
286 | + /** |
|
287 | + * validate_post_data |
|
288 | + * |
|
289 | + * @param int $id |
|
290 | + * @return array|FALSE |
|
291 | + * @throws \ReflectionException |
|
292 | + * @throws InvalidArgumentException |
|
293 | + * @throws InvalidInterfaceException |
|
294 | + * @throws InvalidDataTypeException |
|
295 | + * @throws EE_Error |
|
296 | + */ |
|
297 | + private function validatePostData($id = 0) |
|
298 | + { |
|
299 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
300 | + if (! $id) { |
|
301 | + EE_Error::add_error( |
|
302 | + __('The event id provided was not valid.', 'event_espresso'), |
|
303 | + __FILE__, |
|
304 | + __FUNCTION__, |
|
305 | + __LINE__ |
|
306 | + ); |
|
307 | + return false; |
|
308 | + } |
|
309 | + // start with an empty array() |
|
310 | + $valid_data = array(); |
|
311 | + // grab valid id |
|
312 | + $valid_data['id'] = $id; |
|
313 | + // array of other form names |
|
314 | + $inputs_to_clean = array( |
|
315 | + 'event_id' => 'tkt-slctr-event-id', |
|
316 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
317 | + 'rows' => 'tkt-slctr-rows-', |
|
318 | + 'qty' => 'tkt-slctr-qty-', |
|
319 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
320 | + 'return_url' => 'tkt-slctr-return-url-', |
|
321 | + ); |
|
322 | + // let's track the total number of tickets ordered.' |
|
323 | + $valid_data['total_tickets'] = 0; |
|
324 | + // cycle through $inputs_to_clean array |
|
325 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
326 | + // check for POST data |
|
327 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
328 | + // grab value |
|
329 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
330 | + switch ($what) { |
|
331 | + // integers |
|
332 | + case 'event_id': |
|
333 | + $valid_data[ $what ] = absint($input_value); |
|
334 | + // get event via the event id we put in the form |
|
335 | + $valid_data['event'] = EE_Registry::instance() |
|
336 | + ->load_model('Event') |
|
337 | + ->get_one_by_ID($valid_data['event_id']); |
|
338 | + break; |
|
339 | + case 'rows': |
|
340 | + case 'max_atndz': |
|
341 | + $valid_data[ $what ] = absint($input_value); |
|
342 | + break; |
|
343 | + // arrays of integers |
|
344 | + case 'qty': |
|
345 | + /** @var array $row_qty */ |
|
346 | + $row_qty = $input_value; |
|
347 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
348 | + if (! is_array($row_qty)) { |
|
349 | + // get number of rows |
|
350 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
351 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
352 | + : 1; |
|
353 | + // explode ints by the dash |
|
354 | + $row_qty = explode('-', $row_qty); |
|
355 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
356 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
357 | + $row_qty = array($row => $qty); |
|
358 | + for ($x = 1; $x <= $rows; $x++) { |
|
359 | + if (! isset($row_qty[ $x ])) { |
|
360 | + $row_qty[ $x ] = 0; |
|
361 | + } |
|
362 | + } |
|
363 | + } |
|
364 | + ksort($row_qty); |
|
365 | + // cycle thru values |
|
366 | + foreach ($row_qty as $qty) { |
|
367 | + $qty = absint($qty); |
|
368 | + // sanitize as integers |
|
369 | + $valid_data[ $what ][] = $qty; |
|
370 | + $valid_data['total_tickets'] += $qty; |
|
371 | + } |
|
372 | + break; |
|
373 | + // array of integers |
|
374 | + case 'ticket_id': |
|
375 | + $value_array = array(); |
|
376 | + // cycle thru values |
|
377 | + foreach ((array) $input_value as $key => $value) { |
|
378 | + // allow only numbers, letters, spaces, commas and dashes |
|
379 | + $value_array[ $key ] = wp_strip_all_tags($value); |
|
380 | + // get ticket via the ticket id we put in the form |
|
381 | + $ticket_obj = EE_Registry::instance() |
|
382 | + ->load_model('Ticket') |
|
383 | + ->get_one_by_ID($value); |
|
384 | + $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
385 | + } |
|
386 | + $valid_data[ $what ] = $value_array; |
|
387 | + break; |
|
388 | + case 'return_url' : |
|
389 | + // grab and sanitize return-url |
|
390 | + $input_value = esc_url_raw($input_value); |
|
391 | + // was the request coming from an iframe ? if so, then: |
|
392 | + if (strpos($input_value, 'event_list=iframe')) { |
|
393 | + // get anchor fragment |
|
394 | + $input_value = explode('#', $input_value); |
|
395 | + $input_value = end($input_value); |
|
396 | + // use event list url instead, but append anchor |
|
397 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
398 | + } |
|
399 | + $valid_data[ $what ] = $input_value; |
|
400 | + break; |
|
401 | + } // end switch $what |
|
402 | + } |
|
403 | + } // end foreach $inputs_to_clean |
|
404 | + return $valid_data; |
|
405 | + } |
|
406 | 406 | |
407 | 407 | |
408 | - /** |
|
409 | - * adds a ticket to the cart |
|
410 | - * |
|
411 | - * @param EE_Ticket $ticket |
|
412 | - * @param int $qty |
|
413 | - * @return TRUE on success, FALSE on fail |
|
414 | - * @throws InvalidArgumentException |
|
415 | - * @throws InvalidInterfaceException |
|
416 | - * @throws InvalidDataTypeException |
|
417 | - * @throws EE_Error |
|
418 | - */ |
|
419 | - private function addTicketToCart(EE_Ticket $ticket = null, $qty = 1) |
|
420 | - { |
|
421 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
422 | - // get the number of spaces left for this datetime ticket |
|
423 | - $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
424 | - // compare available spaces against the number of tickets being purchased |
|
425 | - if ($available_spaces >= $qty) { |
|
426 | - // allow addons to prevent a ticket from being added to cart |
|
427 | - if ( |
|
428 | - ! apply_filters( |
|
429 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
430 | - true, |
|
431 | - $ticket, |
|
432 | - $qty, |
|
433 | - $available_spaces |
|
434 | - ) |
|
435 | - ) { |
|
436 | - return false; |
|
437 | - } |
|
438 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
439 | - // add event to cart |
|
440 | - if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
441 | - $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
442 | - return true; |
|
443 | - } |
|
444 | - return false; |
|
445 | - } |
|
446 | - // tickets can not be purchased but let's find the exact number left |
|
447 | - // for the last ticket selected PRIOR to subtracting tickets |
|
448 | - $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
449 | - // greedy greedy greedy eh? |
|
450 | - if ($available_spaces > 0) { |
|
451 | - if ( |
|
452 | - apply_filters( |
|
453 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
454 | - true, |
|
455 | - $ticket, |
|
456 | - $qty, |
|
457 | - $available_spaces |
|
458 | - ) |
|
459 | - ) { |
|
460 | - $this->displayAvailabilityError($available_spaces); |
|
461 | - } |
|
462 | - } else { |
|
463 | - EE_Error::add_error( |
|
464 | - __( |
|
465 | - 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
466 | - 'event_espresso' |
|
467 | - ), |
|
468 | - __FILE__, __FUNCTION__, __LINE__ |
|
469 | - ); |
|
470 | - } |
|
471 | - return false; |
|
472 | - } |
|
408 | + /** |
|
409 | + * adds a ticket to the cart |
|
410 | + * |
|
411 | + * @param EE_Ticket $ticket |
|
412 | + * @param int $qty |
|
413 | + * @return TRUE on success, FALSE on fail |
|
414 | + * @throws InvalidArgumentException |
|
415 | + * @throws InvalidInterfaceException |
|
416 | + * @throws InvalidDataTypeException |
|
417 | + * @throws EE_Error |
|
418 | + */ |
|
419 | + private function addTicketToCart(EE_Ticket $ticket = null, $qty = 1) |
|
420 | + { |
|
421 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
422 | + // get the number of spaces left for this datetime ticket |
|
423 | + $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
424 | + // compare available spaces against the number of tickets being purchased |
|
425 | + if ($available_spaces >= $qty) { |
|
426 | + // allow addons to prevent a ticket from being added to cart |
|
427 | + if ( |
|
428 | + ! apply_filters( |
|
429 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
430 | + true, |
|
431 | + $ticket, |
|
432 | + $qty, |
|
433 | + $available_spaces |
|
434 | + ) |
|
435 | + ) { |
|
436 | + return false; |
|
437 | + } |
|
438 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
439 | + // add event to cart |
|
440 | + if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
441 | + $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
442 | + return true; |
|
443 | + } |
|
444 | + return false; |
|
445 | + } |
|
446 | + // tickets can not be purchased but let's find the exact number left |
|
447 | + // for the last ticket selected PRIOR to subtracting tickets |
|
448 | + $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
449 | + // greedy greedy greedy eh? |
|
450 | + if ($available_spaces > 0) { |
|
451 | + if ( |
|
452 | + apply_filters( |
|
453 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
454 | + true, |
|
455 | + $ticket, |
|
456 | + $qty, |
|
457 | + $available_spaces |
|
458 | + ) |
|
459 | + ) { |
|
460 | + $this->displayAvailabilityError($available_spaces); |
|
461 | + } |
|
462 | + } else { |
|
463 | + EE_Error::add_error( |
|
464 | + __( |
|
465 | + 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
466 | + 'event_espresso' |
|
467 | + ), |
|
468 | + __FILE__, __FUNCTION__, __LINE__ |
|
469 | + ); |
|
470 | + } |
|
471 | + return false; |
|
472 | + } |
|
473 | 473 | |
474 | 474 | |
475 | - /** |
|
476 | - * @param int $available_spaces |
|
477 | - * @throws InvalidArgumentException |
|
478 | - * @throws InvalidInterfaceException |
|
479 | - * @throws InvalidDataTypeException |
|
480 | - * @throws EE_Error |
|
481 | - */ |
|
482 | - private function displayAvailabilityError($available_spaces = 1) |
|
483 | - { |
|
484 | - // add error messaging - we're using the _n function that will generate |
|
485 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
486 | - if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
487 | - $msg = sprintf( |
|
488 | - _n( |
|
489 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
490 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
491 | - $available_spaces, |
|
492 | - 'event_espresso' |
|
493 | - ), |
|
494 | - $available_spaces, |
|
495 | - '<br />' |
|
496 | - ); |
|
497 | - } else { |
|
498 | - $msg = sprintf( |
|
499 | - _n( |
|
500 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
501 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
502 | - $available_spaces, |
|
503 | - 'event_espresso' |
|
504 | - ), |
|
505 | - $available_spaces, |
|
506 | - '<br />' |
|
507 | - ); |
|
508 | - } |
|
509 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
510 | - } |
|
475 | + /** |
|
476 | + * @param int $available_spaces |
|
477 | + * @throws InvalidArgumentException |
|
478 | + * @throws InvalidInterfaceException |
|
479 | + * @throws InvalidDataTypeException |
|
480 | + * @throws EE_Error |
|
481 | + */ |
|
482 | + private function displayAvailabilityError($available_spaces = 1) |
|
483 | + { |
|
484 | + // add error messaging - we're using the _n function that will generate |
|
485 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
486 | + if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
487 | + $msg = sprintf( |
|
488 | + _n( |
|
489 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
490 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
491 | + $available_spaces, |
|
492 | + 'event_espresso' |
|
493 | + ), |
|
494 | + $available_spaces, |
|
495 | + '<br />' |
|
496 | + ); |
|
497 | + } else { |
|
498 | + $msg = sprintf( |
|
499 | + _n( |
|
500 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
501 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
502 | + $available_spaces, |
|
503 | + 'event_espresso' |
|
504 | + ), |
|
505 | + $available_spaces, |
|
506 | + '<br />' |
|
507 | + ); |
|
508 | + } |
|
509 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
510 | + } |
|
511 | 511 | |
512 | 512 | |
513 | - /** |
|
514 | - * ticketDatetimeAvailability |
|
515 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
516 | - * and tracks the spaces remaining for each of those datetimes |
|
517 | - * |
|
518 | - * @param EE_Ticket $ticket - selected ticket |
|
519 | - * @param bool $get_original_ticket_spaces |
|
520 | - * @return int |
|
521 | - * @throws InvalidArgumentException |
|
522 | - * @throws InvalidInterfaceException |
|
523 | - * @throws InvalidDataTypeException |
|
524 | - * @throws EE_Error |
|
525 | - */ |
|
526 | - private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
527 | - { |
|
528 | - // if the $_available_spaces array has not been set up yet... |
|
529 | - if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
530 | - $this->setInitialTicketDatetimeAvailability($ticket); |
|
531 | - } |
|
532 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
533 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
534 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
535 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
536 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
537 | - if ($get_original_ticket_spaces) { |
|
538 | - // then grab the available spaces from the "tickets" array |
|
539 | - // and compare with the above to get the lowest number |
|
540 | - $available_spaces = min( |
|
541 | - $available_spaces, |
|
542 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
543 | - ); |
|
544 | - } else { |
|
545 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
546 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
547 | - } |
|
548 | - } |
|
549 | - } |
|
550 | - return $available_spaces; |
|
551 | - } |
|
513 | + /** |
|
514 | + * ticketDatetimeAvailability |
|
515 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
516 | + * and tracks the spaces remaining for each of those datetimes |
|
517 | + * |
|
518 | + * @param EE_Ticket $ticket - selected ticket |
|
519 | + * @param bool $get_original_ticket_spaces |
|
520 | + * @return int |
|
521 | + * @throws InvalidArgumentException |
|
522 | + * @throws InvalidInterfaceException |
|
523 | + * @throws InvalidDataTypeException |
|
524 | + * @throws EE_Error |
|
525 | + */ |
|
526 | + private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
527 | + { |
|
528 | + // if the $_available_spaces array has not been set up yet... |
|
529 | + if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
530 | + $this->setInitialTicketDatetimeAvailability($ticket); |
|
531 | + } |
|
532 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
533 | + if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
534 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
535 | + foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
536 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
537 | + if ($get_original_ticket_spaces) { |
|
538 | + // then grab the available spaces from the "tickets" array |
|
539 | + // and compare with the above to get the lowest number |
|
540 | + $available_spaces = min( |
|
541 | + $available_spaces, |
|
542 | + self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
543 | + ); |
|
544 | + } else { |
|
545 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
546 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
547 | + } |
|
548 | + } |
|
549 | + } |
|
550 | + return $available_spaces; |
|
551 | + } |
|
552 | 552 | |
553 | 553 | |
554 | - /** |
|
555 | - * @param EE_Ticket $ticket |
|
556 | - * @return void |
|
557 | - * @throws InvalidArgumentException |
|
558 | - * @throws InvalidInterfaceException |
|
559 | - * @throws InvalidDataTypeException |
|
560 | - * @throws EE_Error |
|
561 | - */ |
|
562 | - private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
563 | - { |
|
564 | - // first, get all of the datetimes that are available to this ticket |
|
565 | - $datetimes = $ticket->get_many_related( |
|
566 | - 'Datetime', |
|
567 | - array( |
|
568 | - array( |
|
569 | - 'DTT_EVT_end' => array( |
|
570 | - '>=', |
|
571 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
572 | - ), |
|
573 | - ), |
|
574 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
575 | - ) |
|
576 | - ); |
|
577 | - if (! empty($datetimes)) { |
|
578 | - // now loop thru all of the datetimes |
|
579 | - foreach ($datetimes as $datetime) { |
|
580 | - if ($datetime instanceof EE_Datetime) { |
|
581 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
582 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
583 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
584 | - // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
585 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
586 | - $ticket->qty() - $ticket->sold(), |
|
587 | - $spaces_remaining |
|
588 | - ); |
|
589 | - // if the remaining spaces for this datetime is already set, |
|
590 | - // then compare that against the datetime spaces remaining, and take the lowest number, |
|
591 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
592 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
593 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
594 | - ) |
|
595 | - ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
596 | - : $spaces_remaining; |
|
597 | - } |
|
598 | - } |
|
599 | - } |
|
600 | - } |
|
554 | + /** |
|
555 | + * @param EE_Ticket $ticket |
|
556 | + * @return void |
|
557 | + * @throws InvalidArgumentException |
|
558 | + * @throws InvalidInterfaceException |
|
559 | + * @throws InvalidDataTypeException |
|
560 | + * @throws EE_Error |
|
561 | + */ |
|
562 | + private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
563 | + { |
|
564 | + // first, get all of the datetimes that are available to this ticket |
|
565 | + $datetimes = $ticket->get_many_related( |
|
566 | + 'Datetime', |
|
567 | + array( |
|
568 | + array( |
|
569 | + 'DTT_EVT_end' => array( |
|
570 | + '>=', |
|
571 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
572 | + ), |
|
573 | + ), |
|
574 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
575 | + ) |
|
576 | + ); |
|
577 | + if (! empty($datetimes)) { |
|
578 | + // now loop thru all of the datetimes |
|
579 | + foreach ($datetimes as $datetime) { |
|
580 | + if ($datetime instanceof EE_Datetime) { |
|
581 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
582 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
583 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
584 | + // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
585 | + self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
586 | + $ticket->qty() - $ticket->sold(), |
|
587 | + $spaces_remaining |
|
588 | + ); |
|
589 | + // if the remaining spaces for this datetime is already set, |
|
590 | + // then compare that against the datetime spaces remaining, and take the lowest number, |
|
591 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
592 | + self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
593 | + self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
594 | + ) |
|
595 | + ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
596 | + : $spaces_remaining; |
|
597 | + } |
|
598 | + } |
|
599 | + } |
|
600 | + } |
|
601 | 601 | |
602 | 602 | |
603 | - /** |
|
604 | - * @param EE_Ticket $ticket |
|
605 | - * @param int $qty |
|
606 | - * @return void |
|
607 | - * @throws EE_Error |
|
608 | - */ |
|
609 | - private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
610 | - { |
|
611 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
612 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
613 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
614 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
615 | - self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
616 | - } |
|
617 | - } |
|
618 | - } |
|
603 | + /** |
|
604 | + * @param EE_Ticket $ticket |
|
605 | + * @param int $qty |
|
606 | + * @return void |
|
607 | + * @throws EE_Error |
|
608 | + */ |
|
609 | + private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
610 | + { |
|
611 | + if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
612 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
613 | + foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
614 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
615 | + self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
616 | + } |
|
617 | + } |
|
618 | + } |
|
619 | 619 | } |
620 | 620 | // End of file ProcessTicketSelector.php |
621 | 621 | // Location: /ProcessTicketSelector.php |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
13 | 13 | use InvalidArgumentException; |
14 | 14 | |
15 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
15 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
16 | 16 | exit('No direct script access allowed'); |
17 | 17 | } |
18 | 18 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | public function cancelTicketSelections() |
51 | 51 | { |
52 | 52 | // check nonce |
53 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
53 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | ); |
63 | 63 | } else { |
64 | 64 | wp_safe_redirect( |
65 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
65 | + site_url('/'.EE_Registry::instance()->CFG->core->event_cpt_slug.'/') |
|
66 | 66 | ); |
67 | 67 | } |
68 | 68 | exit(); |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | { |
125 | 125 | do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
126 | 126 | // do we have an event id? |
127 | - if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
127 | + if ( ! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
128 | 128 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
129 | 129 | EE_Error::add_error( |
130 | 130 | sprintf( |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $valid['total_tickets'], |
171 | 171 | 'event_espresso' |
172 | 172 | ); |
173 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
173 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
174 | 174 | // dev only message |
175 | 175 | $max_atndz_string = _n( |
176 | 176 | 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | $valid['max_atndz'], |
179 | 179 | 'event_espresso' |
180 | 180 | ); |
181 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
182 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
181 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
182 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
183 | 183 | } else { |
184 | 184 | // all data appears to be valid |
185 | 185 | $tckts_slctd = false; |
@@ -192,15 +192,15 @@ discard block |
||
192 | 192 | // cycle thru the number of data rows sent from the event listing |
193 | 193 | for ($x = 0; $x < $valid['rows']; $x++) { |
194 | 194 | // does this row actually contain a ticket quantity? |
195 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
195 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
196 | 196 | // YES we have a ticket quantity |
197 | 197 | $tckts_slctd = true; |
198 | 198 | // d( $valid['ticket_obj'][$x] ); |
199 | - if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
199 | + if ($valid['ticket_obj'][$x] instanceof EE_Ticket) { |
|
200 | 200 | // then add ticket to cart |
201 | 201 | $tickets_added += $this->addTicketToCart( |
202 | - $valid['ticket_obj'][ $x ], |
|
203 | - $valid['qty'][ $x ] |
|
202 | + $valid['ticket_obj'][$x], |
|
203 | + $valid['qty'][$x] |
|
204 | 204 | ); |
205 | 205 | if (EE_Error::has_error()) { |
206 | 206 | break; |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | ); |
252 | 252 | exit(); |
253 | 253 | } else { |
254 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
254 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
255 | 255 | // nothing added to cart |
256 | 256 | EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
257 | 257 | __FILE__, __FUNCTION__, __LINE__); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | private function validatePostData($id = 0) |
298 | 298 | { |
299 | 299 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
300 | - if (! $id) { |
|
300 | + if ( ! $id) { |
|
301 | 301 | EE_Error::add_error( |
302 | 302 | __('The event id provided was not valid.', 'event_espresso'), |
303 | 303 | __FILE__, |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | // cycle through $inputs_to_clean array |
325 | 325 | foreach ($inputs_to_clean as $what => $input_to_clean) { |
326 | 326 | // check for POST data |
327 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
327 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean.$id)) { |
|
328 | 328 | // grab value |
329 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
329 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean.$id); |
|
330 | 330 | switch ($what) { |
331 | 331 | // integers |
332 | 332 | case 'event_id': |
333 | - $valid_data[ $what ] = absint($input_value); |
|
333 | + $valid_data[$what] = absint($input_value); |
|
334 | 334 | // get event via the event id we put in the form |
335 | 335 | $valid_data['event'] = EE_Registry::instance() |
336 | 336 | ->load_model('Event') |
@@ -338,17 +338,17 @@ discard block |
||
338 | 338 | break; |
339 | 339 | case 'rows': |
340 | 340 | case 'max_atndz': |
341 | - $valid_data[ $what ] = absint($input_value); |
|
341 | + $valid_data[$what] = absint($input_value); |
|
342 | 342 | break; |
343 | 343 | // arrays of integers |
344 | 344 | case 'qty': |
345 | 345 | /** @var array $row_qty */ |
346 | 346 | $row_qty = $input_value; |
347 | 347 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
348 | - if (! is_array($row_qty)) { |
|
348 | + if ( ! is_array($row_qty)) { |
|
349 | 349 | // get number of rows |
350 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
351 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
350 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-'.$id) |
|
351 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-'.$id)) |
|
352 | 352 | : 1; |
353 | 353 | // explode ints by the dash |
354 | 354 | $row_qty = explode('-', $row_qty); |
@@ -356,8 +356,8 @@ discard block |
||
356 | 356 | $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
357 | 357 | $row_qty = array($row => $qty); |
358 | 358 | for ($x = 1; $x <= $rows; $x++) { |
359 | - if (! isset($row_qty[ $x ])) { |
|
360 | - $row_qty[ $x ] = 0; |
|
359 | + if ( ! isset($row_qty[$x])) { |
|
360 | + $row_qty[$x] = 0; |
|
361 | 361 | } |
362 | 362 | } |
363 | 363 | } |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | foreach ($row_qty as $qty) { |
367 | 367 | $qty = absint($qty); |
368 | 368 | // sanitize as integers |
369 | - $valid_data[ $what ][] = $qty; |
|
369 | + $valid_data[$what][] = $qty; |
|
370 | 370 | $valid_data['total_tickets'] += $qty; |
371 | 371 | } |
372 | 372 | break; |
@@ -376,14 +376,14 @@ discard block |
||
376 | 376 | // cycle thru values |
377 | 377 | foreach ((array) $input_value as $key => $value) { |
378 | 378 | // allow only numbers, letters, spaces, commas and dashes |
379 | - $value_array[ $key ] = wp_strip_all_tags($value); |
|
379 | + $value_array[$key] = wp_strip_all_tags($value); |
|
380 | 380 | // get ticket via the ticket id we put in the form |
381 | 381 | $ticket_obj = EE_Registry::instance() |
382 | 382 | ->load_model('Ticket') |
383 | 383 | ->get_one_by_ID($value); |
384 | - $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
384 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
385 | 385 | } |
386 | - $valid_data[ $what ] = $value_array; |
|
386 | + $valid_data[$what] = $value_array; |
|
387 | 387 | break; |
388 | 388 | case 'return_url' : |
389 | 389 | // grab and sanitize return-url |
@@ -394,9 +394,9 @@ discard block |
||
394 | 394 | $input_value = explode('#', $input_value); |
395 | 395 | $input_value = end($input_value); |
396 | 396 | // use event list url instead, but append anchor |
397 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
397 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; |
|
398 | 398 | } |
399 | - $valid_data[ $what ] = $input_value; |
|
399 | + $valid_data[$what] = $input_value; |
|
400 | 400 | break; |
401 | 401 | } // end switch $what |
402 | 402 | } |
@@ -526,24 +526,24 @@ discard block |
||
526 | 526 | private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
527 | 527 | { |
528 | 528 | // if the $_available_spaces array has not been set up yet... |
529 | - if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
529 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
530 | 530 | $this->setInitialTicketDatetimeAvailability($ticket); |
531 | 531 | } |
532 | 532 | $available_spaces = $ticket->qty() - $ticket->sold(); |
533 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
533 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
534 | 534 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
535 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
535 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
536 | 536 | // if we want the original datetime availability BEFORE we started subtracting tickets ? |
537 | 537 | if ($get_original_ticket_spaces) { |
538 | 538 | // then grab the available spaces from the "tickets" array |
539 | 539 | // and compare with the above to get the lowest number |
540 | 540 | $available_spaces = min( |
541 | 541 | $available_spaces, |
542 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
542 | + self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
543 | 543 | ); |
544 | 544 | } else { |
545 | 545 | // we want the updated ticket availability as stored in the "datetimes" array |
546 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
546 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
547 | 547 | } |
548 | 548 | } |
549 | 549 | } |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | 'order_by' => array('DTT_EVT_start' => 'ASC'), |
575 | 575 | ) |
576 | 576 | ); |
577 | - if (! empty($datetimes)) { |
|
577 | + if ( ! empty($datetimes)) { |
|
578 | 578 | // now loop thru all of the datetimes |
579 | 579 | foreach ($datetimes as $datetime) { |
580 | 580 | if ($datetime instanceof EE_Datetime) { |
@@ -582,17 +582,17 @@ discard block |
||
582 | 582 | $spaces_remaining = $datetime->spaces_remaining(); |
583 | 583 | // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
584 | 584 | // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
585 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
585 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
586 | 586 | $ticket->qty() - $ticket->sold(), |
587 | 587 | $spaces_remaining |
588 | 588 | ); |
589 | 589 | // if the remaining spaces for this datetime is already set, |
590 | 590 | // then compare that against the datetime spaces remaining, and take the lowest number, |
591 | 591 | // else just take the datetime spaces remaining, and assign to the datetimes array |
592 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
593 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
592 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
593 | + self::$_available_spaces['datetimes'][$datetime->ID()] |
|
594 | 594 | ) |
595 | - ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
595 | + ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
596 | 596 | : $spaces_remaining; |
597 | 597 | } |
598 | 598 | } |
@@ -608,11 +608,11 @@ discard block |
||
608 | 608 | */ |
609 | 609 | private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
610 | 610 | { |
611 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
611 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
612 | 612 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
613 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
613 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
614 | 614 | // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
615 | - self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
615 | + self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
616 | 616 | } |
617 | 617 | } |
618 | 618 | } |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*'); |
13 | 13 | $class_to_filepath = array(); |
14 | 14 | foreach ($stages as $filepath) { |
15 | - $matches = array(); |
|
16 | - preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | - $class_to_filepath[$matches[1]] = $filepath; |
|
15 | + $matches = array(); |
|
16 | + preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | + $class_to_filepath[$matches[1]] = $filepath; |
|
18 | 18 | } |
19 | 19 | //give addons a chance to autoload their stages too |
20 | 20 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath); |
@@ -33,68 +33,68 @@ discard block |
||
33 | 33 | class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * return EE_DMS_Core_4_9_0 |
|
38 | - * |
|
39 | - * @param TableManager $table_manager |
|
40 | - * @param TableAnalysis $table_analysis |
|
41 | - */ |
|
42 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | - { |
|
44 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | - $this->_priority = 10; |
|
46 | - $this->_migration_stages = array( |
|
47 | - new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | - new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | - ); |
|
50 | - parent::__construct($table_manager, $table_analysis); |
|
51 | - } |
|
36 | + /** |
|
37 | + * return EE_DMS_Core_4_9_0 |
|
38 | + * |
|
39 | + * @param TableManager $table_manager |
|
40 | + * @param TableAnalysis $table_analysis |
|
41 | + */ |
|
42 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | + { |
|
44 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | + $this->_priority = 10; |
|
46 | + $this->_migration_stages = array( |
|
47 | + new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | + new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | + ); |
|
50 | + parent::__construct($table_manager, $table_analysis); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Whether to migrate or not. |
|
57 | - * |
|
58 | - * @param array $version_array |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function can_migrate_from_version($version_array) |
|
62 | - { |
|
63 | - $version_string = $version_array['Core']; |
|
64 | - if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) { |
|
65 | - // echo "$version_string can be migrated from"; |
|
66 | - return true; |
|
67 | - } elseif ( ! $version_string) { |
|
68 | - // echo "no version string provided: $version_string"; |
|
69 | - //no version string provided... this must be pre 4.3 |
|
70 | - return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | - } else { |
|
72 | - // echo "$version_string doesnt apply"; |
|
73 | - return false; |
|
74 | - } |
|
75 | - } |
|
55 | + /** |
|
56 | + * Whether to migrate or not. |
|
57 | + * |
|
58 | + * @param array $version_array |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function can_migrate_from_version($version_array) |
|
62 | + { |
|
63 | + $version_string = $version_array['Core']; |
|
64 | + if (version_compare($version_string, '4.9.0', '<=') && version_compare($version_string, '4.8.0', '>=')) { |
|
65 | + // echo "$version_string can be migrated from"; |
|
66 | + return true; |
|
67 | + } elseif ( ! $version_string) { |
|
68 | + // echo "no version string provided: $version_string"; |
|
69 | + //no version string provided... this must be pre 4.3 |
|
70 | + return false;//changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | + } else { |
|
72 | + // echo "$version_string doesnt apply"; |
|
73 | + return false; |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public function schema_changes_before_migration() |
|
83 | - { |
|
84 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | - $now_in_mysql = current_time('mysql', true); |
|
86 | - $table_name = 'esp_answer'; |
|
87 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
79 | + /** |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public function schema_changes_before_migration() |
|
83 | + { |
|
84 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | + $now_in_mysql = current_time('mysql', true); |
|
86 | + $table_name = 'esp_answer'; |
|
87 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
88 | 88 | REG_ID int(10) unsigned NOT NULL, |
89 | 89 | QST_ID int(10) unsigned NOT NULL, |
90 | 90 | ANS_value text NOT NULL, |
91 | 91 | PRIMARY KEY (ANS_ID), |
92 | 92 | KEY REG_ID (REG_ID), |
93 | 93 | KEY QST_ID (QST_ID)"; |
94 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | - $table_name = 'esp_attendee_meta'; |
|
96 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
94 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | + $table_name = 'esp_attendee_meta'; |
|
96 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
98 | 98 | ATT_ID bigint(20) unsigned NOT NULL, |
99 | 99 | ATT_fname varchar(45) NOT NULL, |
100 | 100 | ATT_lname varchar(45) NOT NULL, |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | KEY ATT_email (ATT_email(191)), |
112 | 112 | KEY ATT_lname (ATT_lname), |
113 | 113 | KEY ATT_fname (ATT_fname)"; |
114 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | - $table_name = 'esp_checkin'; |
|
116 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
114 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | + $table_name = 'esp_checkin'; |
|
116 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
117 | 117 | REG_ID int(10) unsigned NOT NULL, |
118 | 118 | DTT_ID int(10) unsigned NOT NULL, |
119 | 119 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | PRIMARY KEY (CHK_ID), |
122 | 122 | KEY REG_ID (REG_ID), |
123 | 123 | KEY DTT_ID (DTT_ID)"; |
124 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | - $table_name = 'esp_country'; |
|
126 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
124 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | + $table_name = 'esp_country'; |
|
126 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
127 | 127 | CNT_ISO3 varchar(3) NOT NULL, |
128 | 128 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
129 | 129 | CNT_name varchar(45) NOT NULL, |
@@ -139,29 +139,29 @@ discard block |
||
139 | 139 | CNT_is_EU tinyint(1) DEFAULT '0', |
140 | 140 | CNT_active tinyint(1) DEFAULT '0', |
141 | 141 | PRIMARY KEY (CNT_ISO)"; |
142 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | - $table_name = 'esp_currency'; |
|
144 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
142 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | + $table_name = 'esp_currency'; |
|
144 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
145 | 145 | CUR_single varchar(45) DEFAULT 'dollar', |
146 | 146 | CUR_plural varchar(45) DEFAULT 'dollars', |
147 | 147 | CUR_sign varchar(45) DEFAULT '$', |
148 | 148 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
149 | 149 | CUR_active tinyint(1) DEFAULT '0', |
150 | 150 | PRIMARY KEY (CUR_code)"; |
151 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | - //note: although this table is no longer in use, |
|
153 | - //it hasn't been removed because then queries to the model will have errors. |
|
154 | - //but you should expect this table and its corresponding model to be removed in |
|
155 | - //the next few months |
|
156 | - $table_name = 'esp_currency_payment_method'; |
|
157 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
151 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | + //note: although this table is no longer in use, |
|
153 | + //it hasn't been removed because then queries to the model will have errors. |
|
154 | + //but you should expect this table and its corresponding model to be removed in |
|
155 | + //the next few months |
|
156 | + $table_name = 'esp_currency_payment_method'; |
|
157 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
158 | 158 | CUR_code varchar(6) NOT NULL, |
159 | 159 | PMD_ID int(11) NOT NULL, |
160 | 160 | PRIMARY KEY (CPM_ID), |
161 | 161 | KEY PMD_ID (PMD_ID)"; |
162 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | - $table_name = 'esp_datetime'; |
|
164 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
162 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | + $table_name = 'esp_datetime'; |
|
164 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
165 | 165 | EVT_ID bigint(20) unsigned NOT NULL, |
166 | 166 | DTT_name varchar(255) NOT NULL DEFAULT '', |
167 | 167 | DTT_description text NOT NULL, |
@@ -178,25 +178,25 @@ discard block |
||
178 | 178 | KEY DTT_EVT_start (DTT_EVT_start), |
179 | 179 | KEY EVT_ID (EVT_ID), |
180 | 180 | KEY DTT_is_primary (DTT_is_primary)"; |
181 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | - $table_name = "esp_datetime_ticket"; |
|
183 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
181 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | + $table_name = "esp_datetime_ticket"; |
|
183 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
184 | 184 | DTT_ID int(10) unsigned NOT NULL, |
185 | 185 | TKT_ID int(10) unsigned NOT NULL, |
186 | 186 | PRIMARY KEY (DTK_ID), |
187 | 187 | KEY DTT_ID (DTT_ID), |
188 | 188 | KEY TKT_ID (TKT_ID)"; |
189 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | - $table_name = 'esp_event_message_template'; |
|
191 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
189 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | + $table_name = 'esp_event_message_template'; |
|
191 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
192 | 192 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
193 | 193 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
194 | 194 | PRIMARY KEY (EMT_ID), |
195 | 195 | KEY EVT_ID (EVT_ID), |
196 | 196 | KEY GRP_ID (GRP_ID)"; |
197 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_event_meta'; |
|
199 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_event_meta'; |
|
199 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
200 | 200 | EVT_ID bigint(20) unsigned NOT NULL, |
201 | 201 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
202 | 202 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -211,34 +211,34 @@ discard block |
||
211 | 211 | EVT_donations tinyint(1) NULL, |
212 | 212 | PRIMARY KEY (EVTM_ID), |
213 | 213 | KEY EVT_ID (EVT_ID)"; |
214 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | - $table_name = 'esp_event_question_group'; |
|
216 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
214 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | + $table_name = 'esp_event_question_group'; |
|
216 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
217 | 217 | EVT_ID bigint(20) unsigned NOT NULL, |
218 | 218 | QSG_ID int(10) unsigned NOT NULL, |
219 | 219 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
220 | 220 | PRIMARY KEY (EQG_ID), |
221 | 221 | KEY EVT_ID (EVT_ID), |
222 | 222 | KEY QSG_ID (QSG_ID)"; |
223 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | - $table_name = 'esp_event_venue'; |
|
225 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
223 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | + $table_name = 'esp_event_venue'; |
|
225 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
226 | 226 | EVT_ID bigint(20) unsigned NOT NULL, |
227 | 227 | VNU_ID bigint(20) unsigned NOT NULL, |
228 | 228 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
229 | 229 | PRIMARY KEY (EVV_ID)"; |
230 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | - $table_name = 'esp_extra_meta'; |
|
232 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
230 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | + $table_name = 'esp_extra_meta'; |
|
232 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
233 | 233 | OBJ_ID int(11) DEFAULT NULL, |
234 | 234 | EXM_type varchar(45) DEFAULT NULL, |
235 | 235 | EXM_key varchar(45) DEFAULT NULL, |
236 | 236 | EXM_value text, |
237 | 237 | PRIMARY KEY (EXM_ID), |
238 | 238 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
239 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | - $table_name = 'esp_extra_join'; |
|
241 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
239 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | + $table_name = 'esp_extra_join'; |
|
241 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
242 | 242 | EXJ_first_model_id varchar(6) NOT NULL, |
243 | 243 | EXJ_first_model_name varchar(20) NOT NULL, |
244 | 244 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | PRIMARY KEY (EXJ_ID), |
247 | 247 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
248 | 248 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
249 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | - $table_name = 'esp_line_item'; |
|
251 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
249 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | + $table_name = 'esp_line_item'; |
|
251 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
252 | 252 | LIN_code varchar(245) NOT NULL DEFAULT '', |
253 | 253 | TXN_ID int(11) DEFAULT NULL, |
254 | 254 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
270 | 270 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
271 | 271 | KEY obj_id_obj_type (OBJ_ID, OBJ_type)"; |
272 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
273 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
274 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
275 | - $table_name = 'esp_log'; |
|
276 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
272 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
273 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
274 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
275 | + $table_name = 'esp_log'; |
|
276 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
277 | 277 | LOG_time datetime DEFAULT NULL, |
278 | 278 | OBJ_ID varchar(45) DEFAULT NULL, |
279 | 279 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | KEY LOG_time (LOG_time), |
285 | 285 | KEY OBJ (OBJ_type,OBJ_ID), |
286 | 286 | KEY LOG_type (LOG_type)"; |
287 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
288 | - $table_name = 'esp_message'; |
|
289 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
290 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
291 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
292 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
287 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
288 | + $table_name = 'esp_message'; |
|
289 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
290 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
291 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
292 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
293 | 293 | GRP_ID int(10) unsigned NULL, |
294 | 294 | MSG_token varchar(255) NULL, |
295 | 295 | TXN_ID int(10) unsigned NULL, |
@@ -321,18 +321,18 @@ discard block |
||
321 | 321 | KEY STS_ID (STS_ID), |
322 | 322 | KEY MSG_created (MSG_created), |
323 | 323 | KEY MSG_modified (MSG_modified)"; |
324 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
325 | - $table_name = 'esp_message_template'; |
|
326 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
324 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
325 | + $table_name = 'esp_message_template'; |
|
326 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
327 | 327 | GRP_ID int(10) unsigned NOT NULL, |
328 | 328 | MTP_context varchar(50) NOT NULL, |
329 | 329 | MTP_template_field varchar(30) NOT NULL, |
330 | 330 | MTP_content text NOT NULL, |
331 | 331 | PRIMARY KEY (MTP_ID), |
332 | 332 | KEY GRP_ID (GRP_ID)"; |
333 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | - $table_name = 'esp_message_template_group'; |
|
335 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
333 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | + $table_name = 'esp_message_template_group'; |
|
335 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
336 | 336 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
337 | 337 | MTP_name varchar(245) NOT NULL DEFAULT '', |
338 | 338 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -344,9 +344,9 @@ discard block |
||
344 | 344 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
345 | 345 | PRIMARY KEY (GRP_ID), |
346 | 346 | KEY MTP_user_id (MTP_user_id)"; |
347 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
348 | - $table_name = 'esp_payment'; |
|
349 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
347 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
348 | + $table_name = 'esp_payment'; |
|
349 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
350 | 350 | TXN_ID int(10) unsigned DEFAULT NULL, |
351 | 351 | STS_ID varchar(3) DEFAULT NULL, |
352 | 352 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | PRIMARY KEY (PAY_ID), |
364 | 364 | KEY PAY_timestamp (PAY_timestamp), |
365 | 365 | KEY TXN_ID (TXN_ID)"; |
366 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
367 | - $table_name = 'esp_payment_method'; |
|
368 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
366 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
367 | + $table_name = 'esp_payment_method'; |
|
368 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
369 | 369 | PMD_type varchar(124) DEFAULT NULL, |
370 | 370 | PMD_name varchar(255) DEFAULT NULL, |
371 | 371 | PMD_desc text, |
@@ -381,24 +381,24 @@ discard block |
||
381 | 381 | PRIMARY KEY (PMD_ID), |
382 | 382 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
383 | 383 | KEY PMD_type (PMD_type)"; |
384 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
385 | - $table_name = "esp_ticket_price"; |
|
386 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
384 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
385 | + $table_name = "esp_ticket_price"; |
|
386 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
387 | 387 | TKT_ID int(10) unsigned NOT NULL, |
388 | 388 | PRC_ID int(10) unsigned NOT NULL, |
389 | 389 | PRIMARY KEY (TKP_ID), |
390 | 390 | KEY TKT_ID (TKT_ID), |
391 | 391 | KEY PRC_ID (PRC_ID)"; |
392 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | - $table_name = "esp_ticket_template"; |
|
394 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
392 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | + $table_name = "esp_ticket_template"; |
|
394 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
395 | 395 | TTM_name varchar(45) NOT NULL, |
396 | 396 | TTM_description text, |
397 | 397 | TTM_file varchar(45), |
398 | 398 | PRIMARY KEY (TTM_ID)"; |
399 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
400 | - $table_name = 'esp_question'; |
|
401 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
399 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
400 | + $table_name = 'esp_question'; |
|
401 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
402 | 402 | QST_display_text text NOT NULL, |
403 | 403 | QST_admin_label varchar(255) NOT NULL, |
404 | 404 | QST_system varchar(25) DEFAULT NULL, |
@@ -412,18 +412,18 @@ discard block |
||
412 | 412 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
413 | 413 | PRIMARY KEY (QST_ID), |
414 | 414 | KEY QST_order (QST_order)'; |
415 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | - $table_name = 'esp_question_group_question'; |
|
417 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
415 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | + $table_name = 'esp_question_group_question'; |
|
417 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
418 | 418 | QSG_ID int(10) unsigned NOT NULL, |
419 | 419 | QST_ID int(10) unsigned NOT NULL, |
420 | 420 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
421 | 421 | PRIMARY KEY (QGQ_ID), |
422 | 422 | KEY QST_ID (QST_ID), |
423 | 423 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
424 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | - $table_name = 'esp_question_option'; |
|
426 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
424 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | + $table_name = 'esp_question_option'; |
|
426 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
427 | 427 | QSO_value varchar(255) NOT NULL, |
428 | 428 | QSO_desc text NOT NULL, |
429 | 429 | QST_ID int(10) unsigned NOT NULL, |
@@ -433,9 +433,9 @@ discard block |
||
433 | 433 | PRIMARY KEY (QSO_ID), |
434 | 434 | KEY QST_ID (QST_ID), |
435 | 435 | KEY QSO_order (QSO_order)"; |
436 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
437 | - $table_name = 'esp_registration'; |
|
438 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
436 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
437 | + $table_name = 'esp_registration'; |
|
438 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
439 | 439 | EVT_ID bigint(20) unsigned NOT NULL, |
440 | 440 | ATT_ID bigint(20) unsigned NOT NULL, |
441 | 441 | TXN_ID int(10) unsigned NOT NULL, |
@@ -459,18 +459,18 @@ discard block |
||
459 | 459 | KEY TKT_ID (TKT_ID), |
460 | 460 | KEY EVT_ID (EVT_ID), |
461 | 461 | KEY STS_ID (STS_ID)"; |
462 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
463 | - $table_name = 'esp_registration_payment'; |
|
464 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
462 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
463 | + $table_name = 'esp_registration_payment'; |
|
464 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
465 | 465 | REG_ID int(10) unsigned NOT NULL, |
466 | 466 | PAY_ID int(10) unsigned NULL, |
467 | 467 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
468 | 468 | PRIMARY KEY (RPY_ID), |
469 | 469 | KEY REG_ID (REG_ID), |
470 | 470 | KEY PAY_ID (PAY_ID)"; |
471 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
472 | - $table_name = 'esp_state'; |
|
473 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
471 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
472 | + $table_name = 'esp_state'; |
|
473 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
474 | 474 | CNT_ISO varchar(2) NOT NULL, |
475 | 475 | STA_abbrev varchar(24) NOT NULL, |
476 | 476 | STA_name varchar(100) NOT NULL, |
@@ -478,9 +478,9 @@ discard block |
||
478 | 478 | PRIMARY KEY (STA_ID), |
479 | 479 | KEY STA_abbrev (STA_abbrev), |
480 | 480 | KEY CNT_ISO (CNT_ISO)"; |
481 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
482 | - $table_name = 'esp_status'; |
|
483 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
481 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
482 | + $table_name = 'esp_status'; |
|
483 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
484 | 484 | STS_code varchar(45) NOT NULL, |
485 | 485 | STS_type varchar(45) NOT NULL, |
486 | 486 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -488,9 +488,9 @@ discard block |
||
488 | 488 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
489 | 489 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
490 | 490 | KEY STS_type (STS_type)"; |
491 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
492 | - $table_name = 'esp_transaction'; |
|
493 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
491 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
492 | + $table_name = 'esp_transaction'; |
|
493 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
494 | 494 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
495 | 495 | TXN_total decimal(12,3) DEFAULT '0.00', |
496 | 496 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | PRIMARY KEY (TXN_ID), |
503 | 503 | KEY TXN_timestamp (TXN_timestamp), |
504 | 504 | KEY STS_ID (STS_ID)"; |
505 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
506 | - $table_name = 'esp_venue_meta'; |
|
507 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
505 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
506 | + $table_name = 'esp_venue_meta'; |
|
507 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
508 | 508 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
509 | 509 | VNU_address varchar(255) DEFAULT NULL, |
510 | 510 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -523,10 +523,10 @@ discard block |
||
523 | 523 | KEY VNU_ID (VNU_ID), |
524 | 524 | KEY STA_ID (STA_ID), |
525 | 525 | KEY CNT_ISO (CNT_ISO)"; |
526 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
527 | - //modified tables |
|
528 | - $table_name = "esp_price"; |
|
529 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
526 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
527 | + //modified tables |
|
528 | + $table_name = "esp_price"; |
|
529 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
530 | 530 | PRT_ID tinyint(3) unsigned NOT NULL, |
531 | 531 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
532 | 532 | PRC_name varchar(245) NOT NULL, |
@@ -539,9 +539,9 @@ discard block |
||
539 | 539 | PRC_parent int(10) unsigned DEFAULT 0, |
540 | 540 | PRIMARY KEY (PRC_ID), |
541 | 541 | KEY PRT_ID (PRT_ID)"; |
542 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
543 | - $table_name = "esp_price_type"; |
|
544 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
542 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
543 | + $table_name = "esp_price_type"; |
|
544 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
545 | 545 | PRT_name varchar(45) NOT NULL, |
546 | 546 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
547 | 547 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -550,9 +550,9 @@ discard block |
||
550 | 550 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
551 | 551 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
552 | 552 | PRIMARY KEY (PRT_ID)"; |
553 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
554 | - $table_name = "esp_ticket"; |
|
555 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
553 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
554 | + $table_name = "esp_ticket"; |
|
555 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
556 | 556 | TTM_ID int(10) unsigned NOT NULL, |
557 | 557 | TKT_name varchar(245) NOT NULL DEFAULT '', |
558 | 558 | TKT_description text NOT NULL, |
@@ -575,9 +575,9 @@ discard block |
||
575 | 575 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
576 | 576 | PRIMARY KEY (TKT_ID), |
577 | 577 | KEY TKT_start_date (TKT_start_date)"; |
578 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
579 | - $table_name = 'esp_question_group'; |
|
580 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
578 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
579 | + $table_name = 'esp_question_group'; |
|
580 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
581 | 581 | QSG_name varchar(255) NOT NULL, |
582 | 582 | QSG_identifier varchar(100) NOT NULL, |
583 | 583 | QSG_desc text NULL, |
@@ -590,145 +590,145 @@ discard block |
||
590 | 590 | PRIMARY KEY (QSG_ID), |
591 | 591 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
592 | 592 | KEY QSG_order (QSG_order)'; |
593 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
594 | - /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
595 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
596 | - //(because many need to convert old string states to foreign keys into the states table) |
|
597 | - $script_4_1_defaults->insert_default_states(); |
|
598 | - $script_4_1_defaults->insert_default_countries(); |
|
599 | - /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
600 | - $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
601 | - $script_4_5_defaults->insert_default_price_types(); |
|
602 | - $script_4_5_defaults->insert_default_prices(); |
|
603 | - $script_4_5_defaults->insert_default_tickets(); |
|
604 | - /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
605 | - $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
606 | - $script_4_6_defaults->add_default_admin_only_payments(); |
|
607 | - $script_4_6_defaults->insert_default_currencies(); |
|
608 | - /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
609 | - $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
610 | - $script_4_8_defaults->verify_new_countries(); |
|
611 | - $script_4_8_defaults->verify_new_currencies(); |
|
612 | - $this->verify_db_collations(); |
|
613 | - $this->verify_db_collations_again(); |
|
614 | - return true; |
|
615 | - } |
|
593 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
594 | + /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
595 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
596 | + //(because many need to convert old string states to foreign keys into the states table) |
|
597 | + $script_4_1_defaults->insert_default_states(); |
|
598 | + $script_4_1_defaults->insert_default_countries(); |
|
599 | + /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
600 | + $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
601 | + $script_4_5_defaults->insert_default_price_types(); |
|
602 | + $script_4_5_defaults->insert_default_prices(); |
|
603 | + $script_4_5_defaults->insert_default_tickets(); |
|
604 | + /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
605 | + $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
606 | + $script_4_6_defaults->add_default_admin_only_payments(); |
|
607 | + $script_4_6_defaults->insert_default_currencies(); |
|
608 | + /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
609 | + $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
610 | + $script_4_8_defaults->verify_new_countries(); |
|
611 | + $script_4_8_defaults->verify_new_currencies(); |
|
612 | + $this->verify_db_collations(); |
|
613 | + $this->verify_db_collations_again(); |
|
614 | + return true; |
|
615 | + } |
|
616 | 616 | |
617 | 617 | |
618 | 618 | |
619 | - /** |
|
620 | - * @return boolean |
|
621 | - */ |
|
622 | - public function schema_changes_after_migration() |
|
623 | - { |
|
624 | - return true; |
|
625 | - } |
|
619 | + /** |
|
620 | + * @return boolean |
|
621 | + */ |
|
622 | + public function schema_changes_after_migration() |
|
623 | + { |
|
624 | + return true; |
|
625 | + } |
|
626 | 626 | |
627 | 627 | |
628 | 628 | |
629 | - public function migration_page_hooks() |
|
630 | - { |
|
631 | - } |
|
629 | + public function migration_page_hooks() |
|
630 | + { |
|
631 | + } |
|
632 | 632 | |
633 | 633 | |
634 | 634 | |
635 | - /** |
|
636 | - * Verify all EE4 models' tables use utf8mb4 collation |
|
637 | - * |
|
638 | - * @return void |
|
639 | - */ |
|
640 | - public function verify_db_collations() |
|
641 | - { |
|
642 | - global $wpdb; |
|
643 | - //double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
644 | - if ('utf8mb4' !== $wpdb->charset |
|
645 | - || get_option('ee_verified_db_collations', false)) { |
|
646 | - return; |
|
647 | - } |
|
648 | - // grab tables from each model |
|
649 | - $tables_to_check = array(); |
|
650 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
651 | - if (method_exists($model_name, 'instance')) { |
|
652 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
653 | - if ($model_obj instanceof EEM_Base) { |
|
654 | - foreach ($model_obj->get_tables() as $table) { |
|
655 | - if ( |
|
656 | - strpos($table->get_table_name(), 'esp_') |
|
657 | - && (is_main_site()//for main tables, verify global tables |
|
658 | - || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
659 | - ) |
|
660 | - && function_exists('maybe_convert_table_to_utf8mb4') |
|
661 | - ) { |
|
662 | - $tables_to_check[] = $table->get_table_name(); |
|
663 | - } |
|
664 | - } |
|
665 | - } |
|
666 | - } |
|
667 | - } |
|
668 | - //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
669 | - //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
670 | - //of hard-coding this |
|
671 | - $addon_tables = array( |
|
672 | - //mailchimp |
|
673 | - 'esp_event_mailchimp_list_group', |
|
674 | - 'esp_event_question_mailchimp_field', |
|
675 | - //multisite |
|
676 | - 'esp_blog_meta', |
|
677 | - //people |
|
678 | - 'esp_people_to_post', |
|
679 | - //promotions |
|
680 | - 'esp_promotion', |
|
681 | - 'esp_promotion_object', |
|
682 | - ); |
|
683 | - foreach ($addon_tables as $table_name) { |
|
684 | - $tables_to_check[] = $table_name; |
|
685 | - } |
|
686 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
687 | - //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
688 | - add_option('ee_verified_db_collations', true, null, 'no'); |
|
689 | - //seeing how this ran with the fix from 10435, no need to check again |
|
690 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
691 | - } |
|
635 | + /** |
|
636 | + * Verify all EE4 models' tables use utf8mb4 collation |
|
637 | + * |
|
638 | + * @return void |
|
639 | + */ |
|
640 | + public function verify_db_collations() |
|
641 | + { |
|
642 | + global $wpdb; |
|
643 | + //double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
644 | + if ('utf8mb4' !== $wpdb->charset |
|
645 | + || get_option('ee_verified_db_collations', false)) { |
|
646 | + return; |
|
647 | + } |
|
648 | + // grab tables from each model |
|
649 | + $tables_to_check = array(); |
|
650 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
651 | + if (method_exists($model_name, 'instance')) { |
|
652 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
653 | + if ($model_obj instanceof EEM_Base) { |
|
654 | + foreach ($model_obj->get_tables() as $table) { |
|
655 | + if ( |
|
656 | + strpos($table->get_table_name(), 'esp_') |
|
657 | + && (is_main_site()//for main tables, verify global tables |
|
658 | + || ! $table->is_global()//if not the main site, then only verify non-global tables (avoid doubling up) |
|
659 | + ) |
|
660 | + && function_exists('maybe_convert_table_to_utf8mb4') |
|
661 | + ) { |
|
662 | + $tables_to_check[] = $table->get_table_name(); |
|
663 | + } |
|
664 | + } |
|
665 | + } |
|
666 | + } |
|
667 | + } |
|
668 | + //and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
669 | + //when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
670 | + //of hard-coding this |
|
671 | + $addon_tables = array( |
|
672 | + //mailchimp |
|
673 | + 'esp_event_mailchimp_list_group', |
|
674 | + 'esp_event_question_mailchimp_field', |
|
675 | + //multisite |
|
676 | + 'esp_blog_meta', |
|
677 | + //people |
|
678 | + 'esp_people_to_post', |
|
679 | + //promotions |
|
680 | + 'esp_promotion', |
|
681 | + 'esp_promotion_object', |
|
682 | + ); |
|
683 | + foreach ($addon_tables as $table_name) { |
|
684 | + $tables_to_check[] = $table_name; |
|
685 | + } |
|
686 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
687 | + //ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
688 | + add_option('ee_verified_db_collations', true, null, 'no'); |
|
689 | + //seeing how this ran with the fix from 10435, no need to check again |
|
690 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
691 | + } |
|
692 | 692 | |
693 | 693 | |
694 | 694 | |
695 | - /** |
|
696 | - * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
697 | - * which meant some DB collations might not have been updated |
|
698 | - * @return void |
|
699 | - */ |
|
700 | - public function verify_db_collations_again(){ |
|
701 | - global $wpdb; |
|
702 | - //double-check we haven't already done this or that the DB doesn't support it |
|
703 | - //compare to how WordPress' upgrade_430() function does this check |
|
704 | - if ('utf8mb4' !== $wpdb->charset |
|
705 | - || get_option('ee_verified_db_collations_again', false)) { |
|
706 | - return; |
|
707 | - } |
|
708 | - $tables_to_check = array( |
|
709 | - 'esp_attendee_meta', |
|
710 | - 'esp_message' |
|
711 | - ); |
|
712 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
713 | - add_option('ee_verified_db_collations_again',true,null,'no'); |
|
714 | - } |
|
695 | + /** |
|
696 | + * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
697 | + * which meant some DB collations might not have been updated |
|
698 | + * @return void |
|
699 | + */ |
|
700 | + public function verify_db_collations_again(){ |
|
701 | + global $wpdb; |
|
702 | + //double-check we haven't already done this or that the DB doesn't support it |
|
703 | + //compare to how WordPress' upgrade_430() function does this check |
|
704 | + if ('utf8mb4' !== $wpdb->charset |
|
705 | + || get_option('ee_verified_db_collations_again', false)) { |
|
706 | + return; |
|
707 | + } |
|
708 | + $tables_to_check = array( |
|
709 | + 'esp_attendee_meta', |
|
710 | + 'esp_message' |
|
711 | + ); |
|
712 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
713 | + add_option('ee_verified_db_collations_again',true,null,'no'); |
|
714 | + } |
|
715 | 715 | |
716 | 716 | |
717 | 717 | |
718 | - /** |
|
719 | - * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
720 | - * @param $tables_to_check |
|
721 | - * @return boolean true if logic ran, false if it didn't |
|
722 | - */ |
|
723 | - protected function _verify_db_collations_for_tables($tables_to_check) |
|
724 | - { |
|
725 | - foreach ($tables_to_check as $table_name) { |
|
726 | - $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
727 | - if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
728 | - && $this->_get_table_analysis()->tableExists($table_name) |
|
729 | - ) { |
|
730 | - maybe_convert_table_to_utf8mb4($table_name); |
|
731 | - } |
|
732 | - } |
|
733 | - } |
|
718 | + /** |
|
719 | + * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
720 | + * @param $tables_to_check |
|
721 | + * @return boolean true if logic ran, false if it didn't |
|
722 | + */ |
|
723 | + protected function _verify_db_collations_for_tables($tables_to_check) |
|
724 | + { |
|
725 | + foreach ($tables_to_check as $table_name) { |
|
726 | + $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
727 | + if ( ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name ) |
|
728 | + && $this->_get_table_analysis()->tableExists($table_name) |
|
729 | + ) { |
|
730 | + maybe_convert_table_to_utf8mb4($table_name); |
|
731 | + } |
|
732 | + } |
|
733 | + } |
|
734 | 734 | } |
735 | 735 | \ No newline at end of file |
@@ -38,216 +38,216 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.56.rc.016'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.56.rc.016'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | - /** |
|
119 | - * espresso_load_error_handling |
|
120 | - * this function loads EE's class for handling exceptions and errors |
|
121 | - */ |
|
122 | - function espresso_load_error_handling() |
|
123 | - { |
|
124 | - static $error_handling_loaded = false; |
|
125 | - if ($error_handling_loaded) { |
|
126 | - return; |
|
127 | - } |
|
128 | - // load debugging tools |
|
129 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
130 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
131 | - \EEH_Debug_Tools::instance(); |
|
132 | - } |
|
133 | - // load error handling |
|
134 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
135 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
136 | - } else { |
|
137 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
138 | - } |
|
139 | - $error_handling_loaded = true; |
|
140 | - } |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | + /** |
|
119 | + * espresso_load_error_handling |
|
120 | + * this function loads EE's class for handling exceptions and errors |
|
121 | + */ |
|
122 | + function espresso_load_error_handling() |
|
123 | + { |
|
124 | + static $error_handling_loaded = false; |
|
125 | + if ($error_handling_loaded) { |
|
126 | + return; |
|
127 | + } |
|
128 | + // load debugging tools |
|
129 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
130 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
131 | + \EEH_Debug_Tools::instance(); |
|
132 | + } |
|
133 | + // load error handling |
|
134 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
135 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
136 | + } else { |
|
137 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
138 | + } |
|
139 | + $error_handling_loaded = true; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * espresso_load_required |
|
144 | - * given a class name and path, this function will load that file or throw an exception |
|
145 | - * |
|
146 | - * @param string $classname |
|
147 | - * @param string $full_path_to_file |
|
148 | - * @throws EE_Error |
|
149 | - */ |
|
150 | - function espresso_load_required($classname, $full_path_to_file) |
|
151 | - { |
|
152 | - if (is_readable($full_path_to_file)) { |
|
153 | - require_once $full_path_to_file; |
|
154 | - } else { |
|
155 | - throw new \EE_Error ( |
|
156 | - sprintf( |
|
157 | - esc_html__( |
|
158 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
159 | - 'event_espresso' |
|
160 | - ), |
|
161 | - $classname |
|
162 | - ) |
|
163 | - ); |
|
164 | - } |
|
165 | - } |
|
142 | + /** |
|
143 | + * espresso_load_required |
|
144 | + * given a class name and path, this function will load that file or throw an exception |
|
145 | + * |
|
146 | + * @param string $classname |
|
147 | + * @param string $full_path_to_file |
|
148 | + * @throws EE_Error |
|
149 | + */ |
|
150 | + function espresso_load_required($classname, $full_path_to_file) |
|
151 | + { |
|
152 | + if (is_readable($full_path_to_file)) { |
|
153 | + require_once $full_path_to_file; |
|
154 | + } else { |
|
155 | + throw new \EE_Error ( |
|
156 | + sprintf( |
|
157 | + esc_html__( |
|
158 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
159 | + 'event_espresso' |
|
160 | + ), |
|
161 | + $classname |
|
162 | + ) |
|
163 | + ); |
|
164 | + } |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
168 | - * @since 4.9.27 |
|
169 | - * @throws \EE_Error |
|
170 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
171 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
172 | - * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
173 | - * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
174 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
175 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
176 | - * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
177 | - * @throws \OutOfBoundsException |
|
178 | - */ |
|
179 | - function bootstrap_espresso() |
|
180 | - { |
|
181 | - require_once __DIR__ . '/core/espresso_definitions.php'; |
|
182 | - try { |
|
183 | - espresso_load_error_handling(); |
|
184 | - espresso_load_required( |
|
185 | - 'EEH_Base', |
|
186 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
187 | - ); |
|
188 | - espresso_load_required( |
|
189 | - 'EEH_File', |
|
190 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
191 | - ); |
|
192 | - espresso_load_required( |
|
193 | - 'EEH_File', |
|
194 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
195 | - ); |
|
196 | - espresso_load_required( |
|
197 | - 'EEH_Array', |
|
198 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
199 | - ); |
|
200 | - // instantiate and configure PSR4 autoloader |
|
201 | - espresso_load_required( |
|
202 | - 'Psr4Autoloader', |
|
203 | - EE_CORE . 'Psr4Autoloader.php' |
|
204 | - ); |
|
205 | - espresso_load_required( |
|
206 | - 'EE_Psr4AutoloaderInit', |
|
207 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
208 | - ); |
|
209 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
210 | - $AutoloaderInit->initializeAutoloader(); |
|
211 | - espresso_load_required( |
|
212 | - 'EE_Request', |
|
213 | - EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
214 | - ); |
|
215 | - espresso_load_required( |
|
216 | - 'EE_Response', |
|
217 | - EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
218 | - ); |
|
219 | - espresso_load_required( |
|
220 | - 'EE_Bootstrap', |
|
221 | - EE_CORE . 'EE_Bootstrap.core.php' |
|
222 | - ); |
|
223 | - // bootstrap EE and the request stack |
|
224 | - new EE_Bootstrap( |
|
225 | - new EE_Request($_GET, $_POST, $_COOKIE), |
|
226 | - new EE_Response() |
|
227 | - ); |
|
228 | - } catch (Exception $e) { |
|
229 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
230 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
231 | - } |
|
232 | - } |
|
233 | - bootstrap_espresso(); |
|
234 | - } |
|
167 | + /** |
|
168 | + * @since 4.9.27 |
|
169 | + * @throws \EE_Error |
|
170 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
171 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
172 | + * @throws \EventEspresso\core\exceptions\InvalidIdentifierException |
|
173 | + * @throws \EventEspresso\core\exceptions\InvalidClassException |
|
174 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
175 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException |
|
176 | + * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException |
|
177 | + * @throws \OutOfBoundsException |
|
178 | + */ |
|
179 | + function bootstrap_espresso() |
|
180 | + { |
|
181 | + require_once __DIR__ . '/core/espresso_definitions.php'; |
|
182 | + try { |
|
183 | + espresso_load_error_handling(); |
|
184 | + espresso_load_required( |
|
185 | + 'EEH_Base', |
|
186 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
187 | + ); |
|
188 | + espresso_load_required( |
|
189 | + 'EEH_File', |
|
190 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
191 | + ); |
|
192 | + espresso_load_required( |
|
193 | + 'EEH_File', |
|
194 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
195 | + ); |
|
196 | + espresso_load_required( |
|
197 | + 'EEH_Array', |
|
198 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
199 | + ); |
|
200 | + // instantiate and configure PSR4 autoloader |
|
201 | + espresso_load_required( |
|
202 | + 'Psr4Autoloader', |
|
203 | + EE_CORE . 'Psr4Autoloader.php' |
|
204 | + ); |
|
205 | + espresso_load_required( |
|
206 | + 'EE_Psr4AutoloaderInit', |
|
207 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
208 | + ); |
|
209 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
210 | + $AutoloaderInit->initializeAutoloader(); |
|
211 | + espresso_load_required( |
|
212 | + 'EE_Request', |
|
213 | + EE_CORE . 'request_stack' . DS . 'EE_Request.core.php' |
|
214 | + ); |
|
215 | + espresso_load_required( |
|
216 | + 'EE_Response', |
|
217 | + EE_CORE . 'request_stack' . DS . 'EE_Response.core.php' |
|
218 | + ); |
|
219 | + espresso_load_required( |
|
220 | + 'EE_Bootstrap', |
|
221 | + EE_CORE . 'EE_Bootstrap.core.php' |
|
222 | + ); |
|
223 | + // bootstrap EE and the request stack |
|
224 | + new EE_Bootstrap( |
|
225 | + new EE_Request($_GET, $_POST, $_COOKIE), |
|
226 | + new EE_Response() |
|
227 | + ); |
|
228 | + } catch (Exception $e) { |
|
229 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
230 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
231 | + } |
|
232 | + } |
|
233 | + bootstrap_espresso(); |
|
234 | + } |
|
235 | 235 | } |
236 | 236 | if (! function_exists('espresso_deactivate_plugin')) { |
237 | - /** |
|
238 | - * deactivate_plugin |
|
239 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
240 | - * |
|
241 | - * @access public |
|
242 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
243 | - * @return void |
|
244 | - */ |
|
245 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
246 | - { |
|
247 | - if (! function_exists('deactivate_plugins')) { |
|
248 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
249 | - } |
|
250 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
251 | - deactivate_plugins($plugin_basename); |
|
252 | - } |
|
237 | + /** |
|
238 | + * deactivate_plugin |
|
239 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
240 | + * |
|
241 | + * @access public |
|
242 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
243 | + * @return void |
|
244 | + */ |
|
245 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
246 | + { |
|
247 | + if (! function_exists('deactivate_plugins')) { |
|
248 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
249 | + } |
|
250 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
251 | + deactivate_plugins($plugin_basename); |
|
252 | + } |
|
253 | 253 | } |