@@ -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 | |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | * classname to create an alternative index for retrieving data_handlers. |
27 | 27 | * @return bool |
28 | 28 | */ |
29 | - public function add( $data_handler, $data = null) { |
|
29 | + public function add($data_handler, $data = null) { |
|
30 | 30 | $data = $data === null ? array() : (array) $data; |
31 | - $info['key'] = $this->get_key( get_class( $data_handler ), $data ); |
|
32 | - return parent::add( $data_handler, $info ); |
|
31 | + $info['key'] = $this->get_key(get_class($data_handler), $data); |
|
32 | + return parent::add($data_handler, $info); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return string md5 hash using provided info. |
46 | 46 | */ |
47 | - public function get_key( $classname, $data ) { |
|
48 | - return md5( $classname . serialize( $data ) ); |
|
47 | + public function get_key($classname, $data) { |
|
48 | + return md5($classname.serialize($data)); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return null|EE_Messages_incoming_data |
63 | 63 | */ |
64 | - public function get_by_key( $key ) { |
|
64 | + public function get_by_key($key) { |
|
65 | 65 | $this->rewind(); |
66 | - while( $this->valid() ) { |
|
66 | + while ($this->valid()) { |
|
67 | 67 | $data = $this->getInfo(); |
68 | - if ( isset( $data['key'] ) && $data['key'] === $key ) { |
|
68 | + if (isset($data['key']) && $data['key'] === $key) { |
|
69 | 69 | $handler = $this->current(); |
70 | 70 | $this->rewind(); |
71 | 71 | return $handler; |
@@ -18,1496 +18,1496 @@ |
||
18 | 18 | class EE_Line_Item extends EE_Base_Class implements EEI_Line_Item |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * for children line items (currently not a normal relation) |
|
23 | - * |
|
24 | - * @type EE_Line_Item[] |
|
25 | - */ |
|
26 | - protected $_children = array(); |
|
27 | - |
|
28 | - /** |
|
29 | - * for the parent line item |
|
30 | - * |
|
31 | - * @var EE_Line_Item |
|
32 | - */ |
|
33 | - protected $_parent; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * |
|
39 | - * @param array $props_n_values incoming values |
|
40 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
41 | - * used.) |
|
42 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
43 | - * date_format and the second value is the time format |
|
44 | - * @return EE_Line_Item |
|
45 | - * @throws EE_Error |
|
46 | - */ |
|
47 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
48 | - { |
|
49 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
50 | - return $has_object |
|
51 | - ? $has_object |
|
52 | - : new self($props_n_values, false, $timezone); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param array $props_n_values incoming values from the database |
|
59 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
60 | - * the website will be used. |
|
61 | - * @return EE_Line_Item |
|
62 | - * @throws EE_Error |
|
63 | - */ |
|
64 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
65 | - { |
|
66 | - return new self($props_n_values, true, $timezone); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Adds some defaults if they're not specified |
|
73 | - * |
|
74 | - * @param array $fieldValues |
|
75 | - * @param bool $bydb |
|
76 | - * @param string $timezone |
|
77 | - * @throws EE_Error |
|
78 | - */ |
|
79 | - protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
|
80 | - { |
|
81 | - parent::__construct($fieldValues, $bydb, $timezone); |
|
82 | - if (! $this->get('LIN_code')) { |
|
83 | - $this->set_code($this->generate_code()); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Gets ID |
|
91 | - * |
|
92 | - * @return int |
|
93 | - * @throws EE_Error |
|
94 | - */ |
|
95 | - public function ID() |
|
96 | - { |
|
97 | - return $this->get('LIN_ID'); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Gets TXN_ID |
|
104 | - * |
|
105 | - * @return int |
|
106 | - * @throws EE_Error |
|
107 | - */ |
|
108 | - public function TXN_ID() |
|
109 | - { |
|
110 | - return $this->get('TXN_ID'); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Sets TXN_ID |
|
117 | - * |
|
118 | - * @param int $TXN_ID |
|
119 | - * @throws EE_Error |
|
120 | - */ |
|
121 | - public function set_TXN_ID($TXN_ID) |
|
122 | - { |
|
123 | - $this->set('TXN_ID', $TXN_ID); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * Gets name |
|
130 | - * |
|
131 | - * @return string |
|
132 | - * @throws EE_Error |
|
133 | - */ |
|
134 | - public function name() |
|
135 | - { |
|
136 | - $name = $this->get('LIN_name'); |
|
137 | - if (! $name) { |
|
138 | - $name = ucwords(str_replace('-', ' ', $this->type())); |
|
139 | - } |
|
140 | - return $name; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Sets name |
|
147 | - * |
|
148 | - * @param string $name |
|
149 | - * @throws EE_Error |
|
150 | - */ |
|
151 | - public function set_name($name) |
|
152 | - { |
|
153 | - $this->set('LIN_name', $name); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * Gets desc |
|
160 | - * |
|
161 | - * @return string |
|
162 | - * @throws EE_Error |
|
163 | - */ |
|
164 | - public function desc() |
|
165 | - { |
|
166 | - return $this->get('LIN_desc'); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Sets desc |
|
173 | - * |
|
174 | - * @param string $desc |
|
175 | - * @throws EE_Error |
|
176 | - */ |
|
177 | - public function set_desc($desc) |
|
178 | - { |
|
179 | - $this->set('LIN_desc', $desc); |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * Gets quantity |
|
186 | - * |
|
187 | - * @return int |
|
188 | - * @throws EE_Error |
|
189 | - */ |
|
190 | - public function quantity() |
|
191 | - { |
|
192 | - return $this->get('LIN_quantity'); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * Sets quantity |
|
199 | - * |
|
200 | - * @param int $quantity |
|
201 | - * @throws EE_Error |
|
202 | - */ |
|
203 | - public function set_quantity($quantity) |
|
204 | - { |
|
205 | - $this->set('LIN_quantity', max($quantity, 0)); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Gets item_id |
|
212 | - * |
|
213 | - * @return string |
|
214 | - * @throws EE_Error |
|
215 | - */ |
|
216 | - public function OBJ_ID() |
|
217 | - { |
|
218 | - return $this->get('OBJ_ID'); |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Sets item_id |
|
225 | - * |
|
226 | - * @param string $item_id |
|
227 | - * @throws EE_Error |
|
228 | - */ |
|
229 | - public function set_OBJ_ID($item_id) |
|
230 | - { |
|
231 | - $this->set('OBJ_ID', $item_id); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Gets item_type |
|
238 | - * |
|
239 | - * @return string |
|
240 | - * @throws EE_Error |
|
241 | - */ |
|
242 | - public function OBJ_type() |
|
243 | - { |
|
244 | - return $this->get('OBJ_type'); |
|
245 | - } |
|
246 | - |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * Gets item_type |
|
251 | - * |
|
252 | - * @return string |
|
253 | - * @throws EE_Error |
|
254 | - */ |
|
255 | - public function OBJ_type_i18n() |
|
256 | - { |
|
257 | - $obj_type = $this->OBJ_type(); |
|
258 | - switch ($obj_type) { |
|
259 | - case 'Event': |
|
260 | - $obj_type = __('Event', 'event_espresso'); |
|
261 | - break; |
|
262 | - case 'Price': |
|
263 | - $obj_type = __('Price', 'event_espresso'); |
|
264 | - break; |
|
265 | - case 'Promotion': |
|
266 | - $obj_type = __('Promotion', 'event_espresso'); |
|
267 | - break; |
|
268 | - case 'Ticket': |
|
269 | - $obj_type = __('Ticket', 'event_espresso'); |
|
270 | - break; |
|
271 | - case 'Transaction': |
|
272 | - $obj_type = __('Transaction', 'event_espresso'); |
|
273 | - break; |
|
274 | - } |
|
275 | - return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Sets item_type |
|
282 | - * |
|
283 | - * @param string $OBJ_type |
|
284 | - * @throws EE_Error |
|
285 | - */ |
|
286 | - public function set_OBJ_type($OBJ_type) |
|
287 | - { |
|
288 | - $this->set('OBJ_type', $OBJ_type); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Gets unit_price |
|
295 | - * |
|
296 | - * @return float |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - public function unit_price() |
|
300 | - { |
|
301 | - return $this->get('LIN_unit_price'); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Sets unit_price |
|
308 | - * |
|
309 | - * @param float $unit_price |
|
310 | - * @throws EE_Error |
|
311 | - */ |
|
312 | - public function set_unit_price($unit_price) |
|
313 | - { |
|
314 | - $this->set('LIN_unit_price', $unit_price); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * Checks if this item is a percentage modifier or not |
|
321 | - * |
|
322 | - * @return boolean |
|
323 | - * @throws EE_Error |
|
324 | - */ |
|
325 | - public function is_percent() |
|
326 | - { |
|
327 | - if ($this->is_tax_sub_total()) { |
|
328 | - //tax subtotals HAVE a percent on them, that percentage only applies |
|
329 | - //to taxable items, so its' an exception. Treat it like a flat line item |
|
330 | - return false; |
|
331 | - } |
|
332 | - $unit_price = abs($this->get('LIN_unit_price')); |
|
333 | - $percent = abs($this->get('LIN_percent')); |
|
334 | - if ($unit_price < .001 && $percent) { |
|
335 | - return true; |
|
336 | - } |
|
337 | - if ($unit_price >= .001 && ! $percent) { |
|
338 | - return false; |
|
339 | - } |
|
340 | - if ($unit_price >= .001 && $percent) { |
|
341 | - throw new EE_Error( |
|
342 | - sprintf( |
|
343 | - esc_html__('A Line Item can not have a unit price of (%s) AND a percent (%s)!', 'event_espresso'), |
|
344 | - $unit_price, $percent |
|
345 | - ) |
|
346 | - ); |
|
347 | - } |
|
348 | - // if they're both 0, assume its not a percent item |
|
349 | - return false; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * Gets percent (between 100-.001) |
|
356 | - * |
|
357 | - * @return float |
|
358 | - * @throws EE_Error |
|
359 | - */ |
|
360 | - public function percent() |
|
361 | - { |
|
362 | - return $this->get('LIN_percent'); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * Sets percent (between 100-0.01) |
|
369 | - * |
|
370 | - * @param float $percent |
|
371 | - * @throws EE_Error |
|
372 | - */ |
|
373 | - public function set_percent($percent) |
|
374 | - { |
|
375 | - $this->set('LIN_percent', $percent); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * Gets total |
|
382 | - * |
|
383 | - * @return float |
|
384 | - * @throws EE_Error |
|
385 | - */ |
|
386 | - public function total() |
|
387 | - { |
|
388 | - return $this->get('LIN_total'); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * Sets total |
|
395 | - * |
|
396 | - * @param float $total |
|
397 | - * @throws EE_Error |
|
398 | - */ |
|
399 | - public function set_total($total) |
|
400 | - { |
|
401 | - $this->set('LIN_total', $total); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Gets order |
|
408 | - * |
|
409 | - * @return int |
|
410 | - * @throws EE_Error |
|
411 | - */ |
|
412 | - public function order() |
|
413 | - { |
|
414 | - return $this->get('LIN_order'); |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * Sets order |
|
421 | - * |
|
422 | - * @param int $order |
|
423 | - * @throws EE_Error |
|
424 | - */ |
|
425 | - public function set_order($order) |
|
426 | - { |
|
427 | - $this->set('LIN_order', $order); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * Gets parent |
|
434 | - * |
|
435 | - * @return int |
|
436 | - * @throws EE_Error |
|
437 | - */ |
|
438 | - public function parent_ID() |
|
439 | - { |
|
440 | - return $this->get('LIN_parent'); |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * Sets parent |
|
447 | - * |
|
448 | - * @param int $parent |
|
449 | - * @throws EE_Error |
|
450 | - */ |
|
451 | - public function set_parent_ID($parent) |
|
452 | - { |
|
453 | - $this->set('LIN_parent', $parent); |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * Gets type |
|
460 | - * |
|
461 | - * @return string |
|
462 | - * @throws EE_Error |
|
463 | - */ |
|
464 | - public function type() |
|
465 | - { |
|
466 | - return $this->get('LIN_type'); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * Sets type |
|
473 | - * |
|
474 | - * @param string $type |
|
475 | - * @throws EE_Error |
|
476 | - */ |
|
477 | - public function set_type($type) |
|
478 | - { |
|
479 | - $this->set('LIN_type', $type); |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - |
|
484 | - /** |
|
485 | - * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\ |
|
486 | - * If this line item is saved to the DB, fetches the parent from the DB. However, if this line item isn't in the DB |
|
487 | - * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()` |
|
488 | - * or indirectly by `EE_Line_item::add_child_line_item()`) |
|
489 | - * |
|
490 | - * @return EE_Base_Class|EE_Line_Item |
|
491 | - * @throws EE_Error |
|
492 | - */ |
|
493 | - public function parent() |
|
494 | - { |
|
495 | - return $this->ID() |
|
496 | - ? $this->get_model()->get_one_by_ID($this->parent_ID()) |
|
497 | - : $this->_parent; |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * Gets ALL the children of this line item (ie, all the parts that contribute towards this total). |
|
504 | - * |
|
505 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
506 | - * @throws EE_Error |
|
507 | - */ |
|
508 | - public function children() |
|
509 | - { |
|
510 | - if ($this->ID()) { |
|
511 | - return $this->get_model()->get_all( |
|
512 | - array( |
|
513 | - array('LIN_parent' => $this->ID()), |
|
514 | - 'order_by' => array('LIN_order' => 'ASC'), |
|
515 | - ) |
|
516 | - ); |
|
517 | - } |
|
518 | - if (! is_array($this->_children)) { |
|
519 | - $this->_children = array(); |
|
520 | - } |
|
521 | - return $this->_children; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * Gets code |
|
528 | - * |
|
529 | - * @return string |
|
530 | - * @throws EE_Error |
|
531 | - */ |
|
532 | - public function code() |
|
533 | - { |
|
534 | - return $this->get('LIN_code'); |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * Sets code |
|
541 | - * |
|
542 | - * @param string $code |
|
543 | - * @throws EE_Error |
|
544 | - */ |
|
545 | - public function set_code($code) |
|
546 | - { |
|
547 | - $this->set('LIN_code', $code); |
|
548 | - } |
|
549 | - |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * Gets is_taxable |
|
554 | - * |
|
555 | - * @return boolean |
|
556 | - * @throws EE_Error |
|
557 | - */ |
|
558 | - public function is_taxable() |
|
559 | - { |
|
560 | - return $this->get('LIN_is_taxable'); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * Sets is_taxable |
|
567 | - * |
|
568 | - * @param boolean $is_taxable |
|
569 | - * @throws EE_Error |
|
570 | - */ |
|
571 | - public function set_is_taxable($is_taxable) |
|
572 | - { |
|
573 | - $this->set('LIN_is_taxable', $is_taxable); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * Gets the object that this model-joins-to. |
|
580 | - * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on |
|
581 | - * EEM_Promotion_Object |
|
582 | - * |
|
583 | - * Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object |
|
584 | - * |
|
585 | - * @return EE_Base_Class | NULL |
|
586 | - * @throws EE_Error |
|
587 | - */ |
|
588 | - public function get_object() |
|
589 | - { |
|
590 | - $model_name_of_related_obj = $this->OBJ_type(); |
|
591 | - return $this->get_model()->has_relation($model_name_of_related_obj) |
|
592 | - ? $this->get_first_related($model_name_of_related_obj) |
|
593 | - : null; |
|
594 | - } |
|
595 | - |
|
596 | - |
|
597 | - |
|
598 | - /** |
|
599 | - * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket. |
|
600 | - * (IE, if this line item is for a price or something else, will return NULL) |
|
601 | - * |
|
602 | - * @param array $query_params |
|
603 | - * @return EE_Base_Class|EE_Ticket |
|
604 | - * @throws EE_Error |
|
605 | - */ |
|
606 | - public function ticket($query_params = array()) |
|
607 | - { |
|
608 | - //we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived. This can be overridden via the incoming $query_params argument |
|
609 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
610 | - $query_params = array_merge($remove_defaults, $query_params); |
|
611 | - return $this->get_first_related('Ticket', $query_params); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket |
|
618 | - * |
|
619 | - * @return EE_Datetime | NULL |
|
620 | - * @throws EE_Error |
|
621 | - */ |
|
622 | - public function get_ticket_datetime() |
|
623 | - { |
|
624 | - if ($this->OBJ_type() === 'Ticket') { |
|
625 | - $ticket = $this->ticket(); |
|
626 | - if ($ticket instanceof EE_Ticket) { |
|
627 | - $datetime = $ticket->first_datetime(); |
|
628 | - if ($datetime instanceof EE_Datetime) { |
|
629 | - return $datetime; |
|
630 | - } |
|
631 | - } |
|
632 | - } |
|
633 | - return null; |
|
634 | - } |
|
635 | - |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * Gets the event's name that's related to the ticket, if this is for |
|
640 | - * a ticket |
|
641 | - * |
|
642 | - * @return string |
|
643 | - * @throws EE_Error |
|
644 | - */ |
|
645 | - public function ticket_event_name() |
|
646 | - { |
|
647 | - $event_name = esc_html__('Unknown', 'event_espresso'); |
|
648 | - $event = $this->ticket_event(); |
|
649 | - if ($event instanceof EE_Event) { |
|
650 | - $event_name = $event->name(); |
|
651 | - } |
|
652 | - return $event_name; |
|
653 | - } |
|
654 | - |
|
655 | - |
|
656 | - /** |
|
657 | - * Gets the event that's related to the ticket, if this line item represents a ticket. |
|
658 | - * |
|
659 | - * @return EE_Event|null |
|
660 | - * @throws EE_Error |
|
661 | - */ |
|
662 | - public function ticket_event() |
|
663 | - { |
|
664 | - $event = null; |
|
665 | - $ticket = $this->ticket(); |
|
666 | - if ($ticket instanceof EE_Ticket) { |
|
667 | - $datetime = $ticket->first_datetime(); |
|
668 | - if ($datetime instanceof EE_Datetime) { |
|
669 | - $event = $datetime->event(); |
|
670 | - } |
|
671 | - } |
|
672 | - return $event; |
|
673 | - } |
|
674 | - |
|
675 | - |
|
676 | - |
|
677 | - /** |
|
678 | - * Gets the first datetime for this lien item, assuming it's for a ticket |
|
679 | - * |
|
680 | - * @param string $date_format |
|
681 | - * @param string $time_format |
|
682 | - * @return string |
|
683 | - * @throws EE_Error |
|
684 | - */ |
|
685 | - public function ticket_datetime_start($date_format = '', $time_format = '') |
|
686 | - { |
|
687 | - $first_datetime_string = esc_html__('Unknown', 'event_espresso'); |
|
688 | - $datetime = $this->get_ticket_datetime(); |
|
689 | - if ($datetime) { |
|
690 | - $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
691 | - } |
|
692 | - return $first_datetime_string; |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - |
|
697 | - /** |
|
698 | - * Adds the line item as a child to this line item. If there is another child line |
|
699 | - * item with the same LIN_code, it is overwritten by this new one |
|
700 | - * |
|
701 | - * @param EEI_Line_Item $line_item |
|
702 | - * @param bool $set_order |
|
703 | - * @return bool success |
|
704 | - * @throws EE_Error |
|
705 | - */ |
|
706 | - public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) |
|
707 | - { |
|
708 | - // should we calculate the LIN_order for this line item ? |
|
709 | - if ($set_order || $line_item->order() === null) { |
|
710 | - $line_item->set_order(count($this->children())); |
|
711 | - } |
|
712 | - if ($this->ID()) { |
|
713 | - //check for any duplicate line items (with the same code), if so, this replaces it |
|
714 | - $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
715 | - if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
716 | - $this->delete_child_line_item($line_item_with_same_code->code()); |
|
717 | - } |
|
718 | - $line_item->set_parent_ID($this->ID()); |
|
719 | - if ($this->TXN_ID()) { |
|
720 | - $line_item->set_TXN_ID($this->TXN_ID()); |
|
721 | - } |
|
722 | - return $line_item->save(); |
|
723 | - } |
|
724 | - $this->_children[$line_item->code()] = $line_item; |
|
725 | - if ($line_item->parent() !== $this) { |
|
726 | - $line_item->set_parent($this); |
|
727 | - } |
|
728 | - return true; |
|
729 | - } |
|
730 | - |
|
731 | - |
|
732 | - /** |
|
733 | - * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation. |
|
734 | - * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save() |
|
735 | - * However, if this line item is NOT saved to the DB, this just caches the parent on |
|
736 | - * the EE_Line_Item::_parent property. |
|
737 | - * |
|
738 | - * @param EE_Line_Item $line_item |
|
739 | - * @throws EE_Error |
|
740 | - */ |
|
741 | - public function set_parent($line_item) |
|
742 | - { |
|
743 | - if ($this->ID()) { |
|
744 | - if (! $line_item->ID()) { |
|
745 | - $line_item->save(); |
|
746 | - } |
|
747 | - $this->set_parent_ID($line_item->ID()); |
|
748 | - $this->save(); |
|
749 | - } else { |
|
750 | - $this->_parent = $line_item; |
|
751 | - $this->set_parent_ID($line_item->ID()); |
|
752 | - } |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * Gets the child line item as specified by its code. Because this returns an object (by reference) |
|
759 | - * you can modify this child line item and the parent (this object) can know about them |
|
760 | - * because it also has a reference to that line item |
|
761 | - * |
|
762 | - * @param string $code |
|
763 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
764 | - * @throws EE_Error |
|
765 | - */ |
|
766 | - public function get_child_line_item($code) |
|
767 | - { |
|
768 | - if ($this->ID()) { |
|
769 | - return $this->get_model()->get_one( |
|
770 | - array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code)) |
|
771 | - ); |
|
772 | - } |
|
773 | - return isset($this->_children[$code]) |
|
774 | - ? $this->_children[$code] |
|
775 | - : null; |
|
776 | - } |
|
777 | - |
|
778 | - |
|
779 | - |
|
780 | - /** |
|
781 | - * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD |
|
782 | - * cached on it) |
|
783 | - * |
|
784 | - * @return int |
|
785 | - * @throws EE_Error |
|
786 | - */ |
|
787 | - public function delete_children_line_items() |
|
788 | - { |
|
789 | - if ($this->ID()) { |
|
790 | - return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
791 | - } |
|
792 | - $count = count($this->_children); |
|
793 | - $this->_children = array(); |
|
794 | - return $count; |
|
795 | - } |
|
796 | - |
|
797 | - |
|
798 | - |
|
799 | - /** |
|
800 | - * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
|
801 | - * HAS NOT been saved to the DB, removes the child line item with index $code. |
|
802 | - * Also searches through the child's children for a matching line item. However, once a line item has been found |
|
803 | - * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be |
|
804 | - * deleted) |
|
805 | - * |
|
806 | - * @param string $code |
|
807 | - * @param bool $stop_search_once_found |
|
808 | - * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to |
|
809 | - * the DB yet) |
|
810 | - * @throws EE_Error |
|
811 | - */ |
|
812 | - public function delete_child_line_item($code, $stop_search_once_found = true) |
|
813 | - { |
|
814 | - if ($this->ID()) { |
|
815 | - $items_deleted = 0; |
|
816 | - if ($this->code() === $code) { |
|
817 | - $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
818 | - $items_deleted += (int)$this->delete(); |
|
819 | - if ($stop_search_once_found) { |
|
820 | - return $items_deleted; |
|
821 | - } |
|
822 | - } |
|
823 | - foreach ($this->children() as $child_line_item) { |
|
824 | - $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
825 | - } |
|
826 | - return $items_deleted; |
|
827 | - } |
|
828 | - if (isset($this->_children[$code])) { |
|
829 | - unset($this->_children[$code]); |
|
830 | - return 1; |
|
831 | - } |
|
832 | - return 0; |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * If this line item is in the database, is of the type subtotal, and |
|
838 | - * has no children, why do we have it? It should be deleted so this function |
|
839 | - * does that |
|
840 | - * |
|
841 | - * @return boolean |
|
842 | - * @throws EE_Error |
|
843 | - */ |
|
844 | - public function delete_if_childless_subtotal() |
|
845 | - { |
|
846 | - if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) { |
|
847 | - return $this->delete(); |
|
848 | - } |
|
849 | - return false; |
|
850 | - } |
|
851 | - |
|
852 | - |
|
853 | - |
|
854 | - /** |
|
855 | - * Creates a code and returns a string. doesn't assign the code to this model object |
|
856 | - * |
|
857 | - * @return string |
|
858 | - * @throws EE_Error |
|
859 | - */ |
|
860 | - public function generate_code() |
|
861 | - { |
|
862 | - // each line item in the cart requires a unique identifier |
|
863 | - return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime()); |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - |
|
868 | - /** |
|
869 | - * @return bool |
|
870 | - * @throws EE_Error |
|
871 | - */ |
|
872 | - public function is_tax() |
|
873 | - { |
|
874 | - return $this->type() === EEM_Line_Item::type_tax; |
|
875 | - } |
|
876 | - |
|
877 | - |
|
878 | - |
|
879 | - /** |
|
880 | - * @return bool |
|
881 | - * @throws EE_Error |
|
882 | - */ |
|
883 | - public function is_tax_sub_total() |
|
884 | - { |
|
885 | - return $this->type() === EEM_Line_Item::type_tax_sub_total; |
|
886 | - } |
|
887 | - |
|
888 | - |
|
889 | - |
|
890 | - /** |
|
891 | - * @return bool |
|
892 | - * @throws EE_Error |
|
893 | - */ |
|
894 | - public function is_line_item() |
|
895 | - { |
|
896 | - return $this->type() === EEM_Line_Item::type_line_item; |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * @return bool |
|
903 | - * @throws EE_Error |
|
904 | - */ |
|
905 | - public function is_sub_line_item() |
|
906 | - { |
|
907 | - return $this->type() === EEM_Line_Item::type_sub_line_item; |
|
908 | - } |
|
909 | - |
|
910 | - |
|
911 | - |
|
912 | - /** |
|
913 | - * @return bool |
|
914 | - * @throws EE_Error |
|
915 | - */ |
|
916 | - public function is_sub_total() |
|
917 | - { |
|
918 | - return $this->type() === EEM_Line_Item::type_sub_total; |
|
919 | - } |
|
920 | - |
|
921 | - |
|
922 | - |
|
923 | - /** |
|
924 | - * Whether or not this line item is a cancellation line item |
|
925 | - * |
|
926 | - * @return boolean |
|
927 | - * @throws EE_Error |
|
928 | - */ |
|
929 | - public function is_cancellation() |
|
930 | - { |
|
931 | - return EEM_Line_Item::type_cancellation === $this->type(); |
|
932 | - } |
|
933 | - |
|
934 | - |
|
935 | - |
|
936 | - /** |
|
937 | - * @return bool |
|
938 | - * @throws EE_Error |
|
939 | - */ |
|
940 | - public function is_total() |
|
941 | - { |
|
942 | - return $this->type() === EEM_Line_Item::type_total; |
|
943 | - } |
|
944 | - |
|
945 | - |
|
946 | - |
|
947 | - /** |
|
948 | - * @return bool |
|
949 | - * @throws EE_Error |
|
950 | - */ |
|
951 | - public function is_cancelled() |
|
952 | - { |
|
953 | - return $this->type() === EEM_Line_Item::type_cancellation; |
|
954 | - } |
|
955 | - |
|
956 | - |
|
957 | - |
|
958 | - /** |
|
959 | - * @return string like '2, 004.00', formatted according to the localized currency |
|
960 | - * @throws EE_Error |
|
961 | - */ |
|
962 | - public function unit_price_no_code() |
|
963 | - { |
|
964 | - return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
965 | - } |
|
966 | - |
|
967 | - |
|
968 | - |
|
969 | - /** |
|
970 | - * @return string like '2, 004.00', formatted according to the localized currency |
|
971 | - * @throws EE_Error |
|
972 | - */ |
|
973 | - public function total_no_code() |
|
974 | - { |
|
975 | - return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
976 | - } |
|
977 | - |
|
978 | - |
|
979 | - |
|
980 | - /** |
|
981 | - * Gets the final total on this item, taking taxes into account. |
|
982 | - * Has the side-effect of setting the sub-total as it was just calculated. |
|
983 | - * If this is used on a grand-total line item, also updates the transaction's |
|
984 | - * TXN_total (provided this line item is allowed to persist, otherwise we don't |
|
985 | - * want to change a persistable transaction with info from a non-persistent line item) |
|
986 | - * |
|
987 | - * @return float |
|
988 | - * @throws EE_Error |
|
989 | - * @throws InvalidArgumentException |
|
990 | - * @throws InvalidInterfaceException |
|
991 | - * @throws InvalidDataTypeException |
|
992 | - */ |
|
993 | - public function recalculate_total_including_taxes() |
|
994 | - { |
|
995 | - $pre_tax_total = $this->recalculate_pre_tax_total(); |
|
996 | - $tax_total = $this->recalculate_taxes_and_tax_total(); |
|
997 | - $total = $pre_tax_total + $tax_total; |
|
998 | - // no negative totals plz |
|
999 | - $total = max($total, 0); |
|
1000 | - $this->set_total($total); |
|
1001 | - //only update the related transaction's total |
|
1002 | - //if we intend to save this line item and its a grand total |
|
1003 | - if ( |
|
1004 | - $this->allow_persist() && $this->type() === EEM_Line_Item::type_total |
|
1005 | - && $this->transaction() |
|
1006 | - instanceof |
|
1007 | - EE_Transaction |
|
1008 | - ) { |
|
1009 | - $this->transaction()->set_total($total); |
|
1010 | - if ($this->transaction()->ID()) { |
|
1011 | - $this->transaction()->save(); |
|
1012 | - } |
|
1013 | - } |
|
1014 | - $this->maybe_save(); |
|
1015 | - return $total; |
|
1016 | - } |
|
1017 | - |
|
1018 | - |
|
1019 | - /** |
|
1020 | - * Recursively goes through all the children and recalculates sub-totals EXCEPT for |
|
1021 | - * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its |
|
1022 | - * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and |
|
1023 | - * when this is called on the grand total |
|
1024 | - * |
|
1025 | - * @return float |
|
1026 | - * @throws InvalidArgumentException |
|
1027 | - * @throws InvalidInterfaceException |
|
1028 | - * @throws InvalidDataTypeException |
|
1029 | - * @throws EE_Error |
|
1030 | - */ |
|
1031 | - public function recalculate_pre_tax_total() |
|
1032 | - { |
|
1033 | - $total = 0; |
|
1034 | - $my_children = $this->children(); |
|
1035 | - $has_children = ! empty($my_children); |
|
1036 | - if ($has_children && $this->is_line_item()) { |
|
1037 | - $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children); |
|
1038 | - } elseif (! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) { |
|
1039 | - $total = $this->unit_price() * $this->quantity(); |
|
1040 | - } elseif ($this->is_sub_total() || $this->is_total()) { |
|
1041 | - $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children); |
|
1042 | - } elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) { |
|
1043 | - // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total |
|
1044 | - return 0; |
|
1045 | - } |
|
1046 | - // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events) |
|
1047 | - if ( |
|
1048 | - ! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation() |
|
1049 | - ) { |
|
1050 | - if ($this->OBJ_type() !== 'Event') { |
|
1051 | - $this->set_quantity(1); |
|
1052 | - } |
|
1053 | - if (! $this->is_percent()) { |
|
1054 | - $this->set_unit_price($total); |
|
1055 | - } |
|
1056 | - } |
|
1057 | - //we don't want to bother saving grand totals, because that needs to factor in taxes anyways |
|
1058 | - //so it ought to be |
|
1059 | - if (! $this->is_total()) { |
|
1060 | - $this->set_total($total); |
|
1061 | - //if not a percent line item, make sure we keep the unit price in sync |
|
1062 | - if ( |
|
1063 | - $has_children |
|
1064 | - && $this->is_line_item() |
|
1065 | - && ! $this->is_percent() |
|
1066 | - ) { |
|
1067 | - if ($this->quantity() === 0) { |
|
1068 | - $new_unit_price = 0; |
|
1069 | - } else { |
|
1070 | - $new_unit_price = $this->total() / $this->quantity(); |
|
1071 | - } |
|
1072 | - $this->set_unit_price($new_unit_price); |
|
1073 | - } |
|
1074 | - $this->maybe_save(); |
|
1075 | - } |
|
1076 | - return $total; |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * Calculates the pretax total when this line item is a subtotal or total line item. |
|
1083 | - * Basically does a sum-then-round approach (ie, any percent line item that are children |
|
1084 | - * will calculate their total based on the un-rounded total we're working with so far, and |
|
1085 | - * THEN round the result; instead of rounding as we go like with sub-line-items) |
|
1086 | - * |
|
1087 | - * @param float $calculated_total_so_far |
|
1088 | - * @param EE_Line_Item[] $my_children |
|
1089 | - * @return float |
|
1090 | - * @throws InvalidArgumentException |
|
1091 | - * @throws InvalidInterfaceException |
|
1092 | - * @throws InvalidDataTypeException |
|
1093 | - * @throws EE_Error |
|
1094 | - */ |
|
1095 | - protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) |
|
1096 | - { |
|
1097 | - if ($my_children === null) { |
|
1098 | - $my_children = $this->children(); |
|
1099 | - } |
|
1100 | - //get the total of all its children |
|
1101 | - foreach ($my_children as $child_line_item) { |
|
1102 | - if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) { |
|
1103 | - // percentage line items are based on total so far |
|
1104 | - if ($child_line_item->is_percent()) { |
|
1105 | - //round as we go so that the line items add up ok |
|
1106 | - $percent_total = round( |
|
1107 | - $calculated_total_so_far * $child_line_item->percent() / 100, |
|
1108 | - EE_Registry::instance()->CFG->currency->dec_plc |
|
1109 | - ); |
|
1110 | - $child_line_item->set_total($percent_total); |
|
1111 | - //so far all percent line items should have a quantity of 1 |
|
1112 | - //(ie, no double percent discounts. Although that might be requested someday) |
|
1113 | - $child_line_item->set_quantity(1); |
|
1114 | - $child_line_item->maybe_save(); |
|
1115 | - $calculated_total_so_far += $percent_total; |
|
1116 | - } else { |
|
1117 | - //verify flat sub-line-item quantities match their parent |
|
1118 | - if ($child_line_item->is_sub_line_item()) { |
|
1119 | - $child_line_item->set_quantity($this->quantity()); |
|
1120 | - } |
|
1121 | - $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
|
1122 | - } |
|
1123 | - } |
|
1124 | - } |
|
1125 | - if ($this->is_sub_total()) { |
|
1126 | - // no negative totals plz |
|
1127 | - $calculated_total_so_far = max($calculated_total_so_far, 0); |
|
1128 | - } |
|
1129 | - return $calculated_total_so_far; |
|
1130 | - } |
|
1131 | - |
|
1132 | - |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * Calculates the pretax total for a normal line item, in a round-then-sum approach |
|
1136 | - * (where each sub-line-item is applied to the base price for the line item |
|
1137 | - * and the result is immediately rounded, rather than summing all the sub-line-items |
|
1138 | - * then rounding, like we do when recalculating pretax totals on totals and subtotals). |
|
1139 | - * |
|
1140 | - * @param float $calculated_total_so_far |
|
1141 | - * @param EE_Line_Item[] $my_children |
|
1142 | - * @return float |
|
1143 | - * @throws InvalidArgumentException |
|
1144 | - * @throws InvalidInterfaceException |
|
1145 | - * @throws InvalidDataTypeException |
|
1146 | - * @throws EE_Error |
|
1147 | - */ |
|
1148 | - protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) |
|
1149 | - { |
|
1150 | - if ($my_children === null) { |
|
1151 | - $my_children = $this->children(); |
|
1152 | - } |
|
1153 | - //we need to keep track of the running total for a single item, |
|
1154 | - //because we need to round as we go |
|
1155 | - $unit_price_for_total = 0; |
|
1156 | - $quantity_for_total = 1; |
|
1157 | - //get the total of all its children |
|
1158 | - foreach ($my_children as $child_line_item) { |
|
1159 | - if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) { |
|
1160 | - if ($child_line_item->is_percent()) { |
|
1161 | - //it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity |
|
1162 | - //not total multiplied by percent, because that ignores rounding along-the-way |
|
1163 | - $percent_unit_price = round( |
|
1164 | - $unit_price_for_total * $child_line_item->percent() / 100, |
|
1165 | - EE_Registry::instance()->CFG->currency->dec_plc |
|
1166 | - ); |
|
1167 | - $percent_total = $percent_unit_price * $quantity_for_total; |
|
1168 | - $child_line_item->set_total($percent_total); |
|
1169 | - //so far all percent line items should have a quantity of 1 |
|
1170 | - //(ie, no double percent discounts. Although that might be requested someday) |
|
1171 | - $child_line_item->set_quantity(1); |
|
1172 | - $child_line_item->maybe_save(); |
|
1173 | - $calculated_total_so_far += $percent_total; |
|
1174 | - $unit_price_for_total += $percent_unit_price; |
|
1175 | - } else { |
|
1176 | - //verify flat sub-line-item quantities match their parent |
|
1177 | - if ($child_line_item->is_sub_line_item()) { |
|
1178 | - $child_line_item->set_quantity($this->quantity()); |
|
1179 | - } |
|
1180 | - $quantity_for_total = $child_line_item->quantity(); |
|
1181 | - $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
|
1182 | - $unit_price_for_total += $child_line_item->unit_price(); |
|
1183 | - } |
|
1184 | - } |
|
1185 | - } |
|
1186 | - return $calculated_total_so_far; |
|
1187 | - } |
|
1188 | - |
|
1189 | - |
|
1190 | - |
|
1191 | - /** |
|
1192 | - * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets |
|
1193 | - * the totals on each tax calculated, and returns the final tax total |
|
1194 | - * |
|
1195 | - * @return float |
|
1196 | - * @throws EE_Error |
|
1197 | - */ |
|
1198 | - public function recalculate_taxes_and_tax_total() |
|
1199 | - { |
|
1200 | - //get all taxes |
|
1201 | - $taxes = $this->tax_descendants(); |
|
1202 | - //calculate the pretax total |
|
1203 | - $taxable_total = $this->taxable_total(); |
|
1204 | - $tax_total = 0; |
|
1205 | - foreach ($taxes as $tax) { |
|
1206 | - $total_on_this_tax = $taxable_total * $tax->percent() / 100; |
|
1207 | - //remember the total on this line item |
|
1208 | - $tax->set_total($total_on_this_tax); |
|
1209 | - $tax_total += $tax->total(); |
|
1210 | - } |
|
1211 | - $this->_recalculate_tax_sub_total(); |
|
1212 | - return $tax_total; |
|
1213 | - } |
|
1214 | - |
|
1215 | - |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * Simply forces all the tax-sub-totals to recalculate. Assumes the taxes have been calculated |
|
1219 | - * |
|
1220 | - * @return void |
|
1221 | - * @throws EE_Error |
|
1222 | - */ |
|
1223 | - private function _recalculate_tax_sub_total() |
|
1224 | - { |
|
1225 | - if ($this->is_tax_sub_total()) { |
|
1226 | - $total = 0; |
|
1227 | - $total_percent = 0; |
|
1228 | - //simply loop through all its children (which should be taxes) and sum their total |
|
1229 | - foreach ($this->children() as $child_tax) { |
|
1230 | - if ($child_tax instanceof EE_Line_Item) { |
|
1231 | - $total += $child_tax->total(); |
|
1232 | - $total_percent += $child_tax->percent(); |
|
1233 | - } |
|
1234 | - } |
|
1235 | - $this->set_total($total); |
|
1236 | - $this->set_percent($total_percent); |
|
1237 | - } elseif ($this->is_total()) { |
|
1238 | - foreach ($this->children() as $maybe_tax_subtotal) { |
|
1239 | - if ($maybe_tax_subtotal instanceof EE_Line_Item) { |
|
1240 | - $maybe_tax_subtotal->_recalculate_tax_sub_total(); |
|
1241 | - } |
|
1242 | - } |
|
1243 | - } |
|
1244 | - } |
|
1245 | - |
|
1246 | - |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * Gets the total tax on this line item. Assumes taxes have already been calculated using |
|
1250 | - * recalculate_taxes_and_total |
|
1251 | - * |
|
1252 | - * @return float |
|
1253 | - * @throws EE_Error |
|
1254 | - */ |
|
1255 | - public function get_total_tax() |
|
1256 | - { |
|
1257 | - $this->_recalculate_tax_sub_total(); |
|
1258 | - $total = 0; |
|
1259 | - foreach ($this->tax_descendants() as $tax_line_item) { |
|
1260 | - if ($tax_line_item instanceof EE_Line_Item) { |
|
1261 | - $total += $tax_line_item->total(); |
|
1262 | - } |
|
1263 | - } |
|
1264 | - return $total; |
|
1265 | - } |
|
1266 | - |
|
1267 | - |
|
1268 | - /** |
|
1269 | - * Gets the total for all the items purchased only |
|
1270 | - * |
|
1271 | - * @return float |
|
1272 | - * @throws EE_Error |
|
1273 | - */ |
|
1274 | - public function get_items_total() |
|
1275 | - { |
|
1276 | - //by default, let's make sure we're consistent with the existing line item |
|
1277 | - if ($this->is_total()) { |
|
1278 | - $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this); |
|
1279 | - if ($pretax_subtotal_li instanceof EE_Line_Item) { |
|
1280 | - return $pretax_subtotal_li->total(); |
|
1281 | - } |
|
1282 | - } |
|
1283 | - $total = 0; |
|
1284 | - foreach ($this->get_items() as $item) { |
|
1285 | - if ($item instanceof EE_Line_Item) { |
|
1286 | - $total += $item->total(); |
|
1287 | - } |
|
1288 | - } |
|
1289 | - return $total; |
|
1290 | - } |
|
1291 | - |
|
1292 | - |
|
1293 | - |
|
1294 | - /** |
|
1295 | - * Gets all the descendants (ie, children or children of children etc) that |
|
1296 | - * are of the type 'tax' |
|
1297 | - * |
|
1298 | - * @return EE_Line_Item[] |
|
1299 | - */ |
|
1300 | - public function tax_descendants() |
|
1301 | - { |
|
1302 | - return EEH_Line_Item::get_tax_descendants($this); |
|
1303 | - } |
|
1304 | - |
|
1305 | - |
|
1306 | - |
|
1307 | - /** |
|
1308 | - * Gets all the real items purchased which are children of this item |
|
1309 | - * |
|
1310 | - * @return EE_Line_Item[] |
|
1311 | - */ |
|
1312 | - public function get_items() |
|
1313 | - { |
|
1314 | - return EEH_Line_Item::get_line_item_descendants($this); |
|
1315 | - } |
|
1316 | - |
|
1317 | - |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * Returns the amount taxable among this line item's children (or if it has no children, |
|
1321 | - * how much of it is taxable). Does not recalculate totals or subtotals. |
|
1322 | - * If the taxable total is negative, (eg, if none of the tickets were taxable, |
|
1323 | - * but there is a "Taxable" discount), returns 0. |
|
1324 | - * |
|
1325 | - * @return float |
|
1326 | - * @throws EE_Error |
|
1327 | - */ |
|
1328 | - public function taxable_total() |
|
1329 | - { |
|
1330 | - $total = 0; |
|
1331 | - if ($this->children()) { |
|
1332 | - foreach ($this->children() as $child_line_item) { |
|
1333 | - if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1334 | - //if it's a percent item, only take into account the percent |
|
1335 | - //that's taxable too (the taxable total so far) |
|
1336 | - if ($child_line_item->is_percent()) { |
|
1337 | - $total += ($total * $child_line_item->percent() / 100); |
|
1338 | - } else { |
|
1339 | - $total += $child_line_item->total(); |
|
1340 | - } |
|
1341 | - } elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) { |
|
1342 | - $total += $child_line_item->taxable_total(); |
|
1343 | - } |
|
1344 | - } |
|
1345 | - } |
|
1346 | - return max($total, 0); |
|
1347 | - } |
|
1348 | - |
|
1349 | - |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Gets the transaction for this line item |
|
1353 | - * |
|
1354 | - * @return EE_Base_Class|EE_Transaction |
|
1355 | - * @throws EE_Error |
|
1356 | - */ |
|
1357 | - public function transaction() |
|
1358 | - { |
|
1359 | - return $this->get_first_related('Transaction'); |
|
1360 | - } |
|
1361 | - |
|
1362 | - |
|
1363 | - |
|
1364 | - /** |
|
1365 | - * Saves this line item to the DB, and recursively saves its descendants. |
|
1366 | - * Because there currently is no proper parent-child relation on the model, |
|
1367 | - * save_this_and_cached() will NOT save the descendants. |
|
1368 | - * Also sets the transaction on this line item and all its descendants before saving |
|
1369 | - * |
|
1370 | - * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
|
1371 | - * @return int count of items saved |
|
1372 | - * @throws EE_Error |
|
1373 | - */ |
|
1374 | - public function save_this_and_descendants_to_txn($txn_id = null) |
|
1375 | - { |
|
1376 | - $count = 0; |
|
1377 | - if (! $txn_id) { |
|
1378 | - $txn_id = $this->TXN_ID(); |
|
1379 | - } |
|
1380 | - $this->set_TXN_ID($txn_id); |
|
1381 | - $children = $this->children(); |
|
1382 | - $count += $this->save() |
|
1383 | - ? 1 |
|
1384 | - : 0; |
|
1385 | - foreach ($children as $child_line_item) { |
|
1386 | - if ($child_line_item instanceof EE_Line_Item) { |
|
1387 | - $child_line_item->set_parent_ID($this->ID()); |
|
1388 | - $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1389 | - } |
|
1390 | - } |
|
1391 | - return $count; |
|
1392 | - } |
|
1393 | - |
|
1394 | - |
|
1395 | - |
|
1396 | - /** |
|
1397 | - * Saves this line item to the DB, and recursively saves its descendants. |
|
1398 | - * |
|
1399 | - * @return int count of items saved |
|
1400 | - * @throws EE_Error |
|
1401 | - */ |
|
1402 | - public function save_this_and_descendants() |
|
1403 | - { |
|
1404 | - $count = 0; |
|
1405 | - $children = $this->children(); |
|
1406 | - $count += $this->save() |
|
1407 | - ? 1 |
|
1408 | - : 0; |
|
1409 | - foreach ($children as $child_line_item) { |
|
1410 | - if ($child_line_item instanceof EE_Line_Item) { |
|
1411 | - $child_line_item->set_parent_ID($this->ID()); |
|
1412 | - $count += $child_line_item->save_this_and_descendants(); |
|
1413 | - } |
|
1414 | - } |
|
1415 | - return $count; |
|
1416 | - } |
|
1417 | - |
|
1418 | - |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * returns the cancellation line item if this item was cancelled |
|
1422 | - * |
|
1423 | - * @return EE_Line_Item[] |
|
1424 | - * @throws InvalidArgumentException |
|
1425 | - * @throws InvalidInterfaceException |
|
1426 | - * @throws InvalidDataTypeException |
|
1427 | - * @throws ReflectionException |
|
1428 | - * @throws EE_Error |
|
1429 | - */ |
|
1430 | - public function get_cancellations() |
|
1431 | - { |
|
1432 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
1433 | - return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1434 | - } |
|
1435 | - |
|
1436 | - |
|
1437 | - |
|
1438 | - /** |
|
1439 | - * If this item has an ID, then this saves it again to update the db |
|
1440 | - * |
|
1441 | - * @return int count of items saved |
|
1442 | - * @throws EE_Error |
|
1443 | - */ |
|
1444 | - public function maybe_save() |
|
1445 | - { |
|
1446 | - if ($this->ID()) { |
|
1447 | - return $this->save(); |
|
1448 | - } |
|
1449 | - return false; |
|
1450 | - } |
|
1451 | - |
|
1452 | - |
|
1453 | - /** |
|
1454 | - * clears the cached children and parent from the line item |
|
1455 | - * |
|
1456 | - * @return void |
|
1457 | - */ |
|
1458 | - public function clear_related_line_item_cache() |
|
1459 | - { |
|
1460 | - $this->_children = array(); |
|
1461 | - $this->_parent = null; |
|
1462 | - } |
|
1463 | - |
|
1464 | - |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * @param bool $raw |
|
1468 | - * @return int |
|
1469 | - * @throws EE_Error |
|
1470 | - */ |
|
1471 | - public function timestamp($raw = false) |
|
1472 | - { |
|
1473 | - return $raw |
|
1474 | - ? $this->get_raw('LIN_timestamp') |
|
1475 | - : $this->get('LIN_timestamp'); |
|
1476 | - } |
|
1477 | - |
|
1478 | - |
|
1479 | - |
|
1480 | - |
|
1481 | - /************************* DEPRECATED *************************/ |
|
1482 | - /** |
|
1483 | - * @deprecated 4.6.0 |
|
1484 | - * @param string $type one of the constants on EEM_Line_Item |
|
1485 | - * @return EE_Line_Item[] |
|
1486 | - */ |
|
1487 | - protected function _get_descendants_of_type($type) |
|
1488 | - { |
|
1489 | - EE_Error::doing_it_wrong( |
|
1490 | - 'EE_Line_Item::_get_descendants_of_type()', |
|
1491 | - __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0' |
|
1492 | - ); |
|
1493 | - return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1494 | - } |
|
1495 | - |
|
1496 | - |
|
1497 | - |
|
1498 | - /** |
|
1499 | - * @deprecated 4.6.0 |
|
1500 | - * @param string $type like one of the EEM_Line_Item::type_* |
|
1501 | - * @return EE_Line_Item |
|
1502 | - */ |
|
1503 | - public function get_nearest_descendant_of_type($type) |
|
1504 | - { |
|
1505 | - EE_Error::doing_it_wrong( |
|
1506 | - 'EE_Line_Item::get_nearest_descendant_of_type()', |
|
1507 | - __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0' |
|
1508 | - ); |
|
1509 | - return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1510 | - } |
|
21 | + /** |
|
22 | + * for children line items (currently not a normal relation) |
|
23 | + * |
|
24 | + * @type EE_Line_Item[] |
|
25 | + */ |
|
26 | + protected $_children = array(); |
|
27 | + |
|
28 | + /** |
|
29 | + * for the parent line item |
|
30 | + * |
|
31 | + * @var EE_Line_Item |
|
32 | + */ |
|
33 | + protected $_parent; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * |
|
39 | + * @param array $props_n_values incoming values |
|
40 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
41 | + * used.) |
|
42 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
43 | + * date_format and the second value is the time format |
|
44 | + * @return EE_Line_Item |
|
45 | + * @throws EE_Error |
|
46 | + */ |
|
47 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
48 | + { |
|
49 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
50 | + return $has_object |
|
51 | + ? $has_object |
|
52 | + : new self($props_n_values, false, $timezone); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param array $props_n_values incoming values from the database |
|
59 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
60 | + * the website will be used. |
|
61 | + * @return EE_Line_Item |
|
62 | + * @throws EE_Error |
|
63 | + */ |
|
64 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
65 | + { |
|
66 | + return new self($props_n_values, true, $timezone); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Adds some defaults if they're not specified |
|
73 | + * |
|
74 | + * @param array $fieldValues |
|
75 | + * @param bool $bydb |
|
76 | + * @param string $timezone |
|
77 | + * @throws EE_Error |
|
78 | + */ |
|
79 | + protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
|
80 | + { |
|
81 | + parent::__construct($fieldValues, $bydb, $timezone); |
|
82 | + if (! $this->get('LIN_code')) { |
|
83 | + $this->set_code($this->generate_code()); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Gets ID |
|
91 | + * |
|
92 | + * @return int |
|
93 | + * @throws EE_Error |
|
94 | + */ |
|
95 | + public function ID() |
|
96 | + { |
|
97 | + return $this->get('LIN_ID'); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Gets TXN_ID |
|
104 | + * |
|
105 | + * @return int |
|
106 | + * @throws EE_Error |
|
107 | + */ |
|
108 | + public function TXN_ID() |
|
109 | + { |
|
110 | + return $this->get('TXN_ID'); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Sets TXN_ID |
|
117 | + * |
|
118 | + * @param int $TXN_ID |
|
119 | + * @throws EE_Error |
|
120 | + */ |
|
121 | + public function set_TXN_ID($TXN_ID) |
|
122 | + { |
|
123 | + $this->set('TXN_ID', $TXN_ID); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * Gets name |
|
130 | + * |
|
131 | + * @return string |
|
132 | + * @throws EE_Error |
|
133 | + */ |
|
134 | + public function name() |
|
135 | + { |
|
136 | + $name = $this->get('LIN_name'); |
|
137 | + if (! $name) { |
|
138 | + $name = ucwords(str_replace('-', ' ', $this->type())); |
|
139 | + } |
|
140 | + return $name; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Sets name |
|
147 | + * |
|
148 | + * @param string $name |
|
149 | + * @throws EE_Error |
|
150 | + */ |
|
151 | + public function set_name($name) |
|
152 | + { |
|
153 | + $this->set('LIN_name', $name); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * Gets desc |
|
160 | + * |
|
161 | + * @return string |
|
162 | + * @throws EE_Error |
|
163 | + */ |
|
164 | + public function desc() |
|
165 | + { |
|
166 | + return $this->get('LIN_desc'); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Sets desc |
|
173 | + * |
|
174 | + * @param string $desc |
|
175 | + * @throws EE_Error |
|
176 | + */ |
|
177 | + public function set_desc($desc) |
|
178 | + { |
|
179 | + $this->set('LIN_desc', $desc); |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * Gets quantity |
|
186 | + * |
|
187 | + * @return int |
|
188 | + * @throws EE_Error |
|
189 | + */ |
|
190 | + public function quantity() |
|
191 | + { |
|
192 | + return $this->get('LIN_quantity'); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * Sets quantity |
|
199 | + * |
|
200 | + * @param int $quantity |
|
201 | + * @throws EE_Error |
|
202 | + */ |
|
203 | + public function set_quantity($quantity) |
|
204 | + { |
|
205 | + $this->set('LIN_quantity', max($quantity, 0)); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Gets item_id |
|
212 | + * |
|
213 | + * @return string |
|
214 | + * @throws EE_Error |
|
215 | + */ |
|
216 | + public function OBJ_ID() |
|
217 | + { |
|
218 | + return $this->get('OBJ_ID'); |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Sets item_id |
|
225 | + * |
|
226 | + * @param string $item_id |
|
227 | + * @throws EE_Error |
|
228 | + */ |
|
229 | + public function set_OBJ_ID($item_id) |
|
230 | + { |
|
231 | + $this->set('OBJ_ID', $item_id); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Gets item_type |
|
238 | + * |
|
239 | + * @return string |
|
240 | + * @throws EE_Error |
|
241 | + */ |
|
242 | + public function OBJ_type() |
|
243 | + { |
|
244 | + return $this->get('OBJ_type'); |
|
245 | + } |
|
246 | + |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * Gets item_type |
|
251 | + * |
|
252 | + * @return string |
|
253 | + * @throws EE_Error |
|
254 | + */ |
|
255 | + public function OBJ_type_i18n() |
|
256 | + { |
|
257 | + $obj_type = $this->OBJ_type(); |
|
258 | + switch ($obj_type) { |
|
259 | + case 'Event': |
|
260 | + $obj_type = __('Event', 'event_espresso'); |
|
261 | + break; |
|
262 | + case 'Price': |
|
263 | + $obj_type = __('Price', 'event_espresso'); |
|
264 | + break; |
|
265 | + case 'Promotion': |
|
266 | + $obj_type = __('Promotion', 'event_espresso'); |
|
267 | + break; |
|
268 | + case 'Ticket': |
|
269 | + $obj_type = __('Ticket', 'event_espresso'); |
|
270 | + break; |
|
271 | + case 'Transaction': |
|
272 | + $obj_type = __('Transaction', 'event_espresso'); |
|
273 | + break; |
|
274 | + } |
|
275 | + return apply_filters('FHEE__EE_Line_Item__OBJ_type_i18n', $obj_type, $this); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Sets item_type |
|
282 | + * |
|
283 | + * @param string $OBJ_type |
|
284 | + * @throws EE_Error |
|
285 | + */ |
|
286 | + public function set_OBJ_type($OBJ_type) |
|
287 | + { |
|
288 | + $this->set('OBJ_type', $OBJ_type); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Gets unit_price |
|
295 | + * |
|
296 | + * @return float |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + public function unit_price() |
|
300 | + { |
|
301 | + return $this->get('LIN_unit_price'); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Sets unit_price |
|
308 | + * |
|
309 | + * @param float $unit_price |
|
310 | + * @throws EE_Error |
|
311 | + */ |
|
312 | + public function set_unit_price($unit_price) |
|
313 | + { |
|
314 | + $this->set('LIN_unit_price', $unit_price); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * Checks if this item is a percentage modifier or not |
|
321 | + * |
|
322 | + * @return boolean |
|
323 | + * @throws EE_Error |
|
324 | + */ |
|
325 | + public function is_percent() |
|
326 | + { |
|
327 | + if ($this->is_tax_sub_total()) { |
|
328 | + //tax subtotals HAVE a percent on them, that percentage only applies |
|
329 | + //to taxable items, so its' an exception. Treat it like a flat line item |
|
330 | + return false; |
|
331 | + } |
|
332 | + $unit_price = abs($this->get('LIN_unit_price')); |
|
333 | + $percent = abs($this->get('LIN_percent')); |
|
334 | + if ($unit_price < .001 && $percent) { |
|
335 | + return true; |
|
336 | + } |
|
337 | + if ($unit_price >= .001 && ! $percent) { |
|
338 | + return false; |
|
339 | + } |
|
340 | + if ($unit_price >= .001 && $percent) { |
|
341 | + throw new EE_Error( |
|
342 | + sprintf( |
|
343 | + esc_html__('A Line Item can not have a unit price of (%s) AND a percent (%s)!', 'event_espresso'), |
|
344 | + $unit_price, $percent |
|
345 | + ) |
|
346 | + ); |
|
347 | + } |
|
348 | + // if they're both 0, assume its not a percent item |
|
349 | + return false; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * Gets percent (between 100-.001) |
|
356 | + * |
|
357 | + * @return float |
|
358 | + * @throws EE_Error |
|
359 | + */ |
|
360 | + public function percent() |
|
361 | + { |
|
362 | + return $this->get('LIN_percent'); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * Sets percent (between 100-0.01) |
|
369 | + * |
|
370 | + * @param float $percent |
|
371 | + * @throws EE_Error |
|
372 | + */ |
|
373 | + public function set_percent($percent) |
|
374 | + { |
|
375 | + $this->set('LIN_percent', $percent); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * Gets total |
|
382 | + * |
|
383 | + * @return float |
|
384 | + * @throws EE_Error |
|
385 | + */ |
|
386 | + public function total() |
|
387 | + { |
|
388 | + return $this->get('LIN_total'); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * Sets total |
|
395 | + * |
|
396 | + * @param float $total |
|
397 | + * @throws EE_Error |
|
398 | + */ |
|
399 | + public function set_total($total) |
|
400 | + { |
|
401 | + $this->set('LIN_total', $total); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Gets order |
|
408 | + * |
|
409 | + * @return int |
|
410 | + * @throws EE_Error |
|
411 | + */ |
|
412 | + public function order() |
|
413 | + { |
|
414 | + return $this->get('LIN_order'); |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * Sets order |
|
421 | + * |
|
422 | + * @param int $order |
|
423 | + * @throws EE_Error |
|
424 | + */ |
|
425 | + public function set_order($order) |
|
426 | + { |
|
427 | + $this->set('LIN_order', $order); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * Gets parent |
|
434 | + * |
|
435 | + * @return int |
|
436 | + * @throws EE_Error |
|
437 | + */ |
|
438 | + public function parent_ID() |
|
439 | + { |
|
440 | + return $this->get('LIN_parent'); |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * Sets parent |
|
447 | + * |
|
448 | + * @param int $parent |
|
449 | + * @throws EE_Error |
|
450 | + */ |
|
451 | + public function set_parent_ID($parent) |
|
452 | + { |
|
453 | + $this->set('LIN_parent', $parent); |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * Gets type |
|
460 | + * |
|
461 | + * @return string |
|
462 | + * @throws EE_Error |
|
463 | + */ |
|
464 | + public function type() |
|
465 | + { |
|
466 | + return $this->get('LIN_type'); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * Sets type |
|
473 | + * |
|
474 | + * @param string $type |
|
475 | + * @throws EE_Error |
|
476 | + */ |
|
477 | + public function set_type($type) |
|
478 | + { |
|
479 | + $this->set('LIN_type', $type); |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + |
|
484 | + /** |
|
485 | + * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\ |
|
486 | + * If this line item is saved to the DB, fetches the parent from the DB. However, if this line item isn't in the DB |
|
487 | + * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()` |
|
488 | + * or indirectly by `EE_Line_item::add_child_line_item()`) |
|
489 | + * |
|
490 | + * @return EE_Base_Class|EE_Line_Item |
|
491 | + * @throws EE_Error |
|
492 | + */ |
|
493 | + public function parent() |
|
494 | + { |
|
495 | + return $this->ID() |
|
496 | + ? $this->get_model()->get_one_by_ID($this->parent_ID()) |
|
497 | + : $this->_parent; |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * Gets ALL the children of this line item (ie, all the parts that contribute towards this total). |
|
504 | + * |
|
505 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
506 | + * @throws EE_Error |
|
507 | + */ |
|
508 | + public function children() |
|
509 | + { |
|
510 | + if ($this->ID()) { |
|
511 | + return $this->get_model()->get_all( |
|
512 | + array( |
|
513 | + array('LIN_parent' => $this->ID()), |
|
514 | + 'order_by' => array('LIN_order' => 'ASC'), |
|
515 | + ) |
|
516 | + ); |
|
517 | + } |
|
518 | + if (! is_array($this->_children)) { |
|
519 | + $this->_children = array(); |
|
520 | + } |
|
521 | + return $this->_children; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * Gets code |
|
528 | + * |
|
529 | + * @return string |
|
530 | + * @throws EE_Error |
|
531 | + */ |
|
532 | + public function code() |
|
533 | + { |
|
534 | + return $this->get('LIN_code'); |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * Sets code |
|
541 | + * |
|
542 | + * @param string $code |
|
543 | + * @throws EE_Error |
|
544 | + */ |
|
545 | + public function set_code($code) |
|
546 | + { |
|
547 | + $this->set('LIN_code', $code); |
|
548 | + } |
|
549 | + |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * Gets is_taxable |
|
554 | + * |
|
555 | + * @return boolean |
|
556 | + * @throws EE_Error |
|
557 | + */ |
|
558 | + public function is_taxable() |
|
559 | + { |
|
560 | + return $this->get('LIN_is_taxable'); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * Sets is_taxable |
|
567 | + * |
|
568 | + * @param boolean $is_taxable |
|
569 | + * @throws EE_Error |
|
570 | + */ |
|
571 | + public function set_is_taxable($is_taxable) |
|
572 | + { |
|
573 | + $this->set('LIN_is_taxable', $is_taxable); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * Gets the object that this model-joins-to. |
|
580 | + * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on |
|
581 | + * EEM_Promotion_Object |
|
582 | + * |
|
583 | + * Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object |
|
584 | + * |
|
585 | + * @return EE_Base_Class | NULL |
|
586 | + * @throws EE_Error |
|
587 | + */ |
|
588 | + public function get_object() |
|
589 | + { |
|
590 | + $model_name_of_related_obj = $this->OBJ_type(); |
|
591 | + return $this->get_model()->has_relation($model_name_of_related_obj) |
|
592 | + ? $this->get_first_related($model_name_of_related_obj) |
|
593 | + : null; |
|
594 | + } |
|
595 | + |
|
596 | + |
|
597 | + |
|
598 | + /** |
|
599 | + * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket. |
|
600 | + * (IE, if this line item is for a price or something else, will return NULL) |
|
601 | + * |
|
602 | + * @param array $query_params |
|
603 | + * @return EE_Base_Class|EE_Ticket |
|
604 | + * @throws EE_Error |
|
605 | + */ |
|
606 | + public function ticket($query_params = array()) |
|
607 | + { |
|
608 | + //we're going to assume that when this method is called we always want to receive the attached ticket EVEN if that ticket is archived. This can be overridden via the incoming $query_params argument |
|
609 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
610 | + $query_params = array_merge($remove_defaults, $query_params); |
|
611 | + return $this->get_first_related('Ticket', $query_params); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket |
|
618 | + * |
|
619 | + * @return EE_Datetime | NULL |
|
620 | + * @throws EE_Error |
|
621 | + */ |
|
622 | + public function get_ticket_datetime() |
|
623 | + { |
|
624 | + if ($this->OBJ_type() === 'Ticket') { |
|
625 | + $ticket = $this->ticket(); |
|
626 | + if ($ticket instanceof EE_Ticket) { |
|
627 | + $datetime = $ticket->first_datetime(); |
|
628 | + if ($datetime instanceof EE_Datetime) { |
|
629 | + return $datetime; |
|
630 | + } |
|
631 | + } |
|
632 | + } |
|
633 | + return null; |
|
634 | + } |
|
635 | + |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * Gets the event's name that's related to the ticket, if this is for |
|
640 | + * a ticket |
|
641 | + * |
|
642 | + * @return string |
|
643 | + * @throws EE_Error |
|
644 | + */ |
|
645 | + public function ticket_event_name() |
|
646 | + { |
|
647 | + $event_name = esc_html__('Unknown', 'event_espresso'); |
|
648 | + $event = $this->ticket_event(); |
|
649 | + if ($event instanceof EE_Event) { |
|
650 | + $event_name = $event->name(); |
|
651 | + } |
|
652 | + return $event_name; |
|
653 | + } |
|
654 | + |
|
655 | + |
|
656 | + /** |
|
657 | + * Gets the event that's related to the ticket, if this line item represents a ticket. |
|
658 | + * |
|
659 | + * @return EE_Event|null |
|
660 | + * @throws EE_Error |
|
661 | + */ |
|
662 | + public function ticket_event() |
|
663 | + { |
|
664 | + $event = null; |
|
665 | + $ticket = $this->ticket(); |
|
666 | + if ($ticket instanceof EE_Ticket) { |
|
667 | + $datetime = $ticket->first_datetime(); |
|
668 | + if ($datetime instanceof EE_Datetime) { |
|
669 | + $event = $datetime->event(); |
|
670 | + } |
|
671 | + } |
|
672 | + return $event; |
|
673 | + } |
|
674 | + |
|
675 | + |
|
676 | + |
|
677 | + /** |
|
678 | + * Gets the first datetime for this lien item, assuming it's for a ticket |
|
679 | + * |
|
680 | + * @param string $date_format |
|
681 | + * @param string $time_format |
|
682 | + * @return string |
|
683 | + * @throws EE_Error |
|
684 | + */ |
|
685 | + public function ticket_datetime_start($date_format = '', $time_format = '') |
|
686 | + { |
|
687 | + $first_datetime_string = esc_html__('Unknown', 'event_espresso'); |
|
688 | + $datetime = $this->get_ticket_datetime(); |
|
689 | + if ($datetime) { |
|
690 | + $first_datetime_string = $datetime->start_date_and_time($date_format, $time_format); |
|
691 | + } |
|
692 | + return $first_datetime_string; |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + |
|
697 | + /** |
|
698 | + * Adds the line item as a child to this line item. If there is another child line |
|
699 | + * item with the same LIN_code, it is overwritten by this new one |
|
700 | + * |
|
701 | + * @param EEI_Line_Item $line_item |
|
702 | + * @param bool $set_order |
|
703 | + * @return bool success |
|
704 | + * @throws EE_Error |
|
705 | + */ |
|
706 | + public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) |
|
707 | + { |
|
708 | + // should we calculate the LIN_order for this line item ? |
|
709 | + if ($set_order || $line_item->order() === null) { |
|
710 | + $line_item->set_order(count($this->children())); |
|
711 | + } |
|
712 | + if ($this->ID()) { |
|
713 | + //check for any duplicate line items (with the same code), if so, this replaces it |
|
714 | + $line_item_with_same_code = $this->get_child_line_item($line_item->code()); |
|
715 | + if ($line_item_with_same_code instanceof EE_Line_Item && $line_item_with_same_code !== $line_item) { |
|
716 | + $this->delete_child_line_item($line_item_with_same_code->code()); |
|
717 | + } |
|
718 | + $line_item->set_parent_ID($this->ID()); |
|
719 | + if ($this->TXN_ID()) { |
|
720 | + $line_item->set_TXN_ID($this->TXN_ID()); |
|
721 | + } |
|
722 | + return $line_item->save(); |
|
723 | + } |
|
724 | + $this->_children[$line_item->code()] = $line_item; |
|
725 | + if ($line_item->parent() !== $this) { |
|
726 | + $line_item->set_parent($this); |
|
727 | + } |
|
728 | + return true; |
|
729 | + } |
|
730 | + |
|
731 | + |
|
732 | + /** |
|
733 | + * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation. |
|
734 | + * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save() |
|
735 | + * However, if this line item is NOT saved to the DB, this just caches the parent on |
|
736 | + * the EE_Line_Item::_parent property. |
|
737 | + * |
|
738 | + * @param EE_Line_Item $line_item |
|
739 | + * @throws EE_Error |
|
740 | + */ |
|
741 | + public function set_parent($line_item) |
|
742 | + { |
|
743 | + if ($this->ID()) { |
|
744 | + if (! $line_item->ID()) { |
|
745 | + $line_item->save(); |
|
746 | + } |
|
747 | + $this->set_parent_ID($line_item->ID()); |
|
748 | + $this->save(); |
|
749 | + } else { |
|
750 | + $this->_parent = $line_item; |
|
751 | + $this->set_parent_ID($line_item->ID()); |
|
752 | + } |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * Gets the child line item as specified by its code. Because this returns an object (by reference) |
|
759 | + * you can modify this child line item and the parent (this object) can know about them |
|
760 | + * because it also has a reference to that line item |
|
761 | + * |
|
762 | + * @param string $code |
|
763 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
764 | + * @throws EE_Error |
|
765 | + */ |
|
766 | + public function get_child_line_item($code) |
|
767 | + { |
|
768 | + if ($this->ID()) { |
|
769 | + return $this->get_model()->get_one( |
|
770 | + array(array('LIN_parent' => $this->ID(), 'LIN_code' => $code)) |
|
771 | + ); |
|
772 | + } |
|
773 | + return isset($this->_children[$code]) |
|
774 | + ? $this->_children[$code] |
|
775 | + : null; |
|
776 | + } |
|
777 | + |
|
778 | + |
|
779 | + |
|
780 | + /** |
|
781 | + * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD |
|
782 | + * cached on it) |
|
783 | + * |
|
784 | + * @return int |
|
785 | + * @throws EE_Error |
|
786 | + */ |
|
787 | + public function delete_children_line_items() |
|
788 | + { |
|
789 | + if ($this->ID()) { |
|
790 | + return $this->get_model()->delete(array(array('LIN_parent' => $this->ID()))); |
|
791 | + } |
|
792 | + $count = count($this->_children); |
|
793 | + $this->_children = array(); |
|
794 | + return $count; |
|
795 | + } |
|
796 | + |
|
797 | + |
|
798 | + |
|
799 | + /** |
|
800 | + * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
|
801 | + * HAS NOT been saved to the DB, removes the child line item with index $code. |
|
802 | + * Also searches through the child's children for a matching line item. However, once a line item has been found |
|
803 | + * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be |
|
804 | + * deleted) |
|
805 | + * |
|
806 | + * @param string $code |
|
807 | + * @param bool $stop_search_once_found |
|
808 | + * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to |
|
809 | + * the DB yet) |
|
810 | + * @throws EE_Error |
|
811 | + */ |
|
812 | + public function delete_child_line_item($code, $stop_search_once_found = true) |
|
813 | + { |
|
814 | + if ($this->ID()) { |
|
815 | + $items_deleted = 0; |
|
816 | + if ($this->code() === $code) { |
|
817 | + $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
|
818 | + $items_deleted += (int)$this->delete(); |
|
819 | + if ($stop_search_once_found) { |
|
820 | + return $items_deleted; |
|
821 | + } |
|
822 | + } |
|
823 | + foreach ($this->children() as $child_line_item) { |
|
824 | + $items_deleted += $child_line_item->delete_child_line_item($code, $stop_search_once_found); |
|
825 | + } |
|
826 | + return $items_deleted; |
|
827 | + } |
|
828 | + if (isset($this->_children[$code])) { |
|
829 | + unset($this->_children[$code]); |
|
830 | + return 1; |
|
831 | + } |
|
832 | + return 0; |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * If this line item is in the database, is of the type subtotal, and |
|
838 | + * has no children, why do we have it? It should be deleted so this function |
|
839 | + * does that |
|
840 | + * |
|
841 | + * @return boolean |
|
842 | + * @throws EE_Error |
|
843 | + */ |
|
844 | + public function delete_if_childless_subtotal() |
|
845 | + { |
|
846 | + if ($this->ID() && $this->type() === EEM_Line_Item::type_sub_total && ! $this->children()) { |
|
847 | + return $this->delete(); |
|
848 | + } |
|
849 | + return false; |
|
850 | + } |
|
851 | + |
|
852 | + |
|
853 | + |
|
854 | + /** |
|
855 | + * Creates a code and returns a string. doesn't assign the code to this model object |
|
856 | + * |
|
857 | + * @return string |
|
858 | + * @throws EE_Error |
|
859 | + */ |
|
860 | + public function generate_code() |
|
861 | + { |
|
862 | + // each line item in the cart requires a unique identifier |
|
863 | + return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime()); |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + |
|
868 | + /** |
|
869 | + * @return bool |
|
870 | + * @throws EE_Error |
|
871 | + */ |
|
872 | + public function is_tax() |
|
873 | + { |
|
874 | + return $this->type() === EEM_Line_Item::type_tax; |
|
875 | + } |
|
876 | + |
|
877 | + |
|
878 | + |
|
879 | + /** |
|
880 | + * @return bool |
|
881 | + * @throws EE_Error |
|
882 | + */ |
|
883 | + public function is_tax_sub_total() |
|
884 | + { |
|
885 | + return $this->type() === EEM_Line_Item::type_tax_sub_total; |
|
886 | + } |
|
887 | + |
|
888 | + |
|
889 | + |
|
890 | + /** |
|
891 | + * @return bool |
|
892 | + * @throws EE_Error |
|
893 | + */ |
|
894 | + public function is_line_item() |
|
895 | + { |
|
896 | + return $this->type() === EEM_Line_Item::type_line_item; |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * @return bool |
|
903 | + * @throws EE_Error |
|
904 | + */ |
|
905 | + public function is_sub_line_item() |
|
906 | + { |
|
907 | + return $this->type() === EEM_Line_Item::type_sub_line_item; |
|
908 | + } |
|
909 | + |
|
910 | + |
|
911 | + |
|
912 | + /** |
|
913 | + * @return bool |
|
914 | + * @throws EE_Error |
|
915 | + */ |
|
916 | + public function is_sub_total() |
|
917 | + { |
|
918 | + return $this->type() === EEM_Line_Item::type_sub_total; |
|
919 | + } |
|
920 | + |
|
921 | + |
|
922 | + |
|
923 | + /** |
|
924 | + * Whether or not this line item is a cancellation line item |
|
925 | + * |
|
926 | + * @return boolean |
|
927 | + * @throws EE_Error |
|
928 | + */ |
|
929 | + public function is_cancellation() |
|
930 | + { |
|
931 | + return EEM_Line_Item::type_cancellation === $this->type(); |
|
932 | + } |
|
933 | + |
|
934 | + |
|
935 | + |
|
936 | + /** |
|
937 | + * @return bool |
|
938 | + * @throws EE_Error |
|
939 | + */ |
|
940 | + public function is_total() |
|
941 | + { |
|
942 | + return $this->type() === EEM_Line_Item::type_total; |
|
943 | + } |
|
944 | + |
|
945 | + |
|
946 | + |
|
947 | + /** |
|
948 | + * @return bool |
|
949 | + * @throws EE_Error |
|
950 | + */ |
|
951 | + public function is_cancelled() |
|
952 | + { |
|
953 | + return $this->type() === EEM_Line_Item::type_cancellation; |
|
954 | + } |
|
955 | + |
|
956 | + |
|
957 | + |
|
958 | + /** |
|
959 | + * @return string like '2, 004.00', formatted according to the localized currency |
|
960 | + * @throws EE_Error |
|
961 | + */ |
|
962 | + public function unit_price_no_code() |
|
963 | + { |
|
964 | + return $this->get_pretty('LIN_unit_price', 'no_currency_code'); |
|
965 | + } |
|
966 | + |
|
967 | + |
|
968 | + |
|
969 | + /** |
|
970 | + * @return string like '2, 004.00', formatted according to the localized currency |
|
971 | + * @throws EE_Error |
|
972 | + */ |
|
973 | + public function total_no_code() |
|
974 | + { |
|
975 | + return $this->get_pretty('LIN_total', 'no_currency_code'); |
|
976 | + } |
|
977 | + |
|
978 | + |
|
979 | + |
|
980 | + /** |
|
981 | + * Gets the final total on this item, taking taxes into account. |
|
982 | + * Has the side-effect of setting the sub-total as it was just calculated. |
|
983 | + * If this is used on a grand-total line item, also updates the transaction's |
|
984 | + * TXN_total (provided this line item is allowed to persist, otherwise we don't |
|
985 | + * want to change a persistable transaction with info from a non-persistent line item) |
|
986 | + * |
|
987 | + * @return float |
|
988 | + * @throws EE_Error |
|
989 | + * @throws InvalidArgumentException |
|
990 | + * @throws InvalidInterfaceException |
|
991 | + * @throws InvalidDataTypeException |
|
992 | + */ |
|
993 | + public function recalculate_total_including_taxes() |
|
994 | + { |
|
995 | + $pre_tax_total = $this->recalculate_pre_tax_total(); |
|
996 | + $tax_total = $this->recalculate_taxes_and_tax_total(); |
|
997 | + $total = $pre_tax_total + $tax_total; |
|
998 | + // no negative totals plz |
|
999 | + $total = max($total, 0); |
|
1000 | + $this->set_total($total); |
|
1001 | + //only update the related transaction's total |
|
1002 | + //if we intend to save this line item and its a grand total |
|
1003 | + if ( |
|
1004 | + $this->allow_persist() && $this->type() === EEM_Line_Item::type_total |
|
1005 | + && $this->transaction() |
|
1006 | + instanceof |
|
1007 | + EE_Transaction |
|
1008 | + ) { |
|
1009 | + $this->transaction()->set_total($total); |
|
1010 | + if ($this->transaction()->ID()) { |
|
1011 | + $this->transaction()->save(); |
|
1012 | + } |
|
1013 | + } |
|
1014 | + $this->maybe_save(); |
|
1015 | + return $total; |
|
1016 | + } |
|
1017 | + |
|
1018 | + |
|
1019 | + /** |
|
1020 | + * Recursively goes through all the children and recalculates sub-totals EXCEPT for |
|
1021 | + * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its |
|
1022 | + * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and |
|
1023 | + * when this is called on the grand total |
|
1024 | + * |
|
1025 | + * @return float |
|
1026 | + * @throws InvalidArgumentException |
|
1027 | + * @throws InvalidInterfaceException |
|
1028 | + * @throws InvalidDataTypeException |
|
1029 | + * @throws EE_Error |
|
1030 | + */ |
|
1031 | + public function recalculate_pre_tax_total() |
|
1032 | + { |
|
1033 | + $total = 0; |
|
1034 | + $my_children = $this->children(); |
|
1035 | + $has_children = ! empty($my_children); |
|
1036 | + if ($has_children && $this->is_line_item()) { |
|
1037 | + $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children); |
|
1038 | + } elseif (! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) { |
|
1039 | + $total = $this->unit_price() * $this->quantity(); |
|
1040 | + } elseif ($this->is_sub_total() || $this->is_total()) { |
|
1041 | + $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children); |
|
1042 | + } elseif ($this->is_tax_sub_total() || $this->is_tax() || $this->is_cancelled()) { |
|
1043 | + // completely ignore tax totals, tax sub-totals, and cancelled line items, when calculating the pre-tax-total |
|
1044 | + return 0; |
|
1045 | + } |
|
1046 | + // ensure all non-line items and non-sub-line-items have a quantity of 1 (except for Events) |
|
1047 | + if ( |
|
1048 | + ! $this->is_line_item() && ! $this->is_sub_line_item() && ! $this->is_cancellation() |
|
1049 | + ) { |
|
1050 | + if ($this->OBJ_type() !== 'Event') { |
|
1051 | + $this->set_quantity(1); |
|
1052 | + } |
|
1053 | + if (! $this->is_percent()) { |
|
1054 | + $this->set_unit_price($total); |
|
1055 | + } |
|
1056 | + } |
|
1057 | + //we don't want to bother saving grand totals, because that needs to factor in taxes anyways |
|
1058 | + //so it ought to be |
|
1059 | + if (! $this->is_total()) { |
|
1060 | + $this->set_total($total); |
|
1061 | + //if not a percent line item, make sure we keep the unit price in sync |
|
1062 | + if ( |
|
1063 | + $has_children |
|
1064 | + && $this->is_line_item() |
|
1065 | + && ! $this->is_percent() |
|
1066 | + ) { |
|
1067 | + if ($this->quantity() === 0) { |
|
1068 | + $new_unit_price = 0; |
|
1069 | + } else { |
|
1070 | + $new_unit_price = $this->total() / $this->quantity(); |
|
1071 | + } |
|
1072 | + $this->set_unit_price($new_unit_price); |
|
1073 | + } |
|
1074 | + $this->maybe_save(); |
|
1075 | + } |
|
1076 | + return $total; |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * Calculates the pretax total when this line item is a subtotal or total line item. |
|
1083 | + * Basically does a sum-then-round approach (ie, any percent line item that are children |
|
1084 | + * will calculate their total based on the un-rounded total we're working with so far, and |
|
1085 | + * THEN round the result; instead of rounding as we go like with sub-line-items) |
|
1086 | + * |
|
1087 | + * @param float $calculated_total_so_far |
|
1088 | + * @param EE_Line_Item[] $my_children |
|
1089 | + * @return float |
|
1090 | + * @throws InvalidArgumentException |
|
1091 | + * @throws InvalidInterfaceException |
|
1092 | + * @throws InvalidDataTypeException |
|
1093 | + * @throws EE_Error |
|
1094 | + */ |
|
1095 | + protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) |
|
1096 | + { |
|
1097 | + if ($my_children === null) { |
|
1098 | + $my_children = $this->children(); |
|
1099 | + } |
|
1100 | + //get the total of all its children |
|
1101 | + foreach ($my_children as $child_line_item) { |
|
1102 | + if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) { |
|
1103 | + // percentage line items are based on total so far |
|
1104 | + if ($child_line_item->is_percent()) { |
|
1105 | + //round as we go so that the line items add up ok |
|
1106 | + $percent_total = round( |
|
1107 | + $calculated_total_so_far * $child_line_item->percent() / 100, |
|
1108 | + EE_Registry::instance()->CFG->currency->dec_plc |
|
1109 | + ); |
|
1110 | + $child_line_item->set_total($percent_total); |
|
1111 | + //so far all percent line items should have a quantity of 1 |
|
1112 | + //(ie, no double percent discounts. Although that might be requested someday) |
|
1113 | + $child_line_item->set_quantity(1); |
|
1114 | + $child_line_item->maybe_save(); |
|
1115 | + $calculated_total_so_far += $percent_total; |
|
1116 | + } else { |
|
1117 | + //verify flat sub-line-item quantities match their parent |
|
1118 | + if ($child_line_item->is_sub_line_item()) { |
|
1119 | + $child_line_item->set_quantity($this->quantity()); |
|
1120 | + } |
|
1121 | + $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
|
1122 | + } |
|
1123 | + } |
|
1124 | + } |
|
1125 | + if ($this->is_sub_total()) { |
|
1126 | + // no negative totals plz |
|
1127 | + $calculated_total_so_far = max($calculated_total_so_far, 0); |
|
1128 | + } |
|
1129 | + return $calculated_total_so_far; |
|
1130 | + } |
|
1131 | + |
|
1132 | + |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * Calculates the pretax total for a normal line item, in a round-then-sum approach |
|
1136 | + * (where each sub-line-item is applied to the base price for the line item |
|
1137 | + * and the result is immediately rounded, rather than summing all the sub-line-items |
|
1138 | + * then rounding, like we do when recalculating pretax totals on totals and subtotals). |
|
1139 | + * |
|
1140 | + * @param float $calculated_total_so_far |
|
1141 | + * @param EE_Line_Item[] $my_children |
|
1142 | + * @return float |
|
1143 | + * @throws InvalidArgumentException |
|
1144 | + * @throws InvalidInterfaceException |
|
1145 | + * @throws InvalidDataTypeException |
|
1146 | + * @throws EE_Error |
|
1147 | + */ |
|
1148 | + protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) |
|
1149 | + { |
|
1150 | + if ($my_children === null) { |
|
1151 | + $my_children = $this->children(); |
|
1152 | + } |
|
1153 | + //we need to keep track of the running total for a single item, |
|
1154 | + //because we need to round as we go |
|
1155 | + $unit_price_for_total = 0; |
|
1156 | + $quantity_for_total = 1; |
|
1157 | + //get the total of all its children |
|
1158 | + foreach ($my_children as $child_line_item) { |
|
1159 | + if ($child_line_item instanceof EE_Line_Item && ! $child_line_item->is_cancellation()) { |
|
1160 | + if ($child_line_item->is_percent()) { |
|
1161 | + //it should be the unit-price-so-far multiplied by teh percent multiplied by the quantity |
|
1162 | + //not total multiplied by percent, because that ignores rounding along-the-way |
|
1163 | + $percent_unit_price = round( |
|
1164 | + $unit_price_for_total * $child_line_item->percent() / 100, |
|
1165 | + EE_Registry::instance()->CFG->currency->dec_plc |
|
1166 | + ); |
|
1167 | + $percent_total = $percent_unit_price * $quantity_for_total; |
|
1168 | + $child_line_item->set_total($percent_total); |
|
1169 | + //so far all percent line items should have a quantity of 1 |
|
1170 | + //(ie, no double percent discounts. Although that might be requested someday) |
|
1171 | + $child_line_item->set_quantity(1); |
|
1172 | + $child_line_item->maybe_save(); |
|
1173 | + $calculated_total_so_far += $percent_total; |
|
1174 | + $unit_price_for_total += $percent_unit_price; |
|
1175 | + } else { |
|
1176 | + //verify flat sub-line-item quantities match their parent |
|
1177 | + if ($child_line_item->is_sub_line_item()) { |
|
1178 | + $child_line_item->set_quantity($this->quantity()); |
|
1179 | + } |
|
1180 | + $quantity_for_total = $child_line_item->quantity(); |
|
1181 | + $calculated_total_so_far += $child_line_item->recalculate_pre_tax_total(); |
|
1182 | + $unit_price_for_total += $child_line_item->unit_price(); |
|
1183 | + } |
|
1184 | + } |
|
1185 | + } |
|
1186 | + return $calculated_total_so_far; |
|
1187 | + } |
|
1188 | + |
|
1189 | + |
|
1190 | + |
|
1191 | + /** |
|
1192 | + * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets |
|
1193 | + * the totals on each tax calculated, and returns the final tax total |
|
1194 | + * |
|
1195 | + * @return float |
|
1196 | + * @throws EE_Error |
|
1197 | + */ |
|
1198 | + public function recalculate_taxes_and_tax_total() |
|
1199 | + { |
|
1200 | + //get all taxes |
|
1201 | + $taxes = $this->tax_descendants(); |
|
1202 | + //calculate the pretax total |
|
1203 | + $taxable_total = $this->taxable_total(); |
|
1204 | + $tax_total = 0; |
|
1205 | + foreach ($taxes as $tax) { |
|
1206 | + $total_on_this_tax = $taxable_total * $tax->percent() / 100; |
|
1207 | + //remember the total on this line item |
|
1208 | + $tax->set_total($total_on_this_tax); |
|
1209 | + $tax_total += $tax->total(); |
|
1210 | + } |
|
1211 | + $this->_recalculate_tax_sub_total(); |
|
1212 | + return $tax_total; |
|
1213 | + } |
|
1214 | + |
|
1215 | + |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * Simply forces all the tax-sub-totals to recalculate. Assumes the taxes have been calculated |
|
1219 | + * |
|
1220 | + * @return void |
|
1221 | + * @throws EE_Error |
|
1222 | + */ |
|
1223 | + private function _recalculate_tax_sub_total() |
|
1224 | + { |
|
1225 | + if ($this->is_tax_sub_total()) { |
|
1226 | + $total = 0; |
|
1227 | + $total_percent = 0; |
|
1228 | + //simply loop through all its children (which should be taxes) and sum their total |
|
1229 | + foreach ($this->children() as $child_tax) { |
|
1230 | + if ($child_tax instanceof EE_Line_Item) { |
|
1231 | + $total += $child_tax->total(); |
|
1232 | + $total_percent += $child_tax->percent(); |
|
1233 | + } |
|
1234 | + } |
|
1235 | + $this->set_total($total); |
|
1236 | + $this->set_percent($total_percent); |
|
1237 | + } elseif ($this->is_total()) { |
|
1238 | + foreach ($this->children() as $maybe_tax_subtotal) { |
|
1239 | + if ($maybe_tax_subtotal instanceof EE_Line_Item) { |
|
1240 | + $maybe_tax_subtotal->_recalculate_tax_sub_total(); |
|
1241 | + } |
|
1242 | + } |
|
1243 | + } |
|
1244 | + } |
|
1245 | + |
|
1246 | + |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * Gets the total tax on this line item. Assumes taxes have already been calculated using |
|
1250 | + * recalculate_taxes_and_total |
|
1251 | + * |
|
1252 | + * @return float |
|
1253 | + * @throws EE_Error |
|
1254 | + */ |
|
1255 | + public function get_total_tax() |
|
1256 | + { |
|
1257 | + $this->_recalculate_tax_sub_total(); |
|
1258 | + $total = 0; |
|
1259 | + foreach ($this->tax_descendants() as $tax_line_item) { |
|
1260 | + if ($tax_line_item instanceof EE_Line_Item) { |
|
1261 | + $total += $tax_line_item->total(); |
|
1262 | + } |
|
1263 | + } |
|
1264 | + return $total; |
|
1265 | + } |
|
1266 | + |
|
1267 | + |
|
1268 | + /** |
|
1269 | + * Gets the total for all the items purchased only |
|
1270 | + * |
|
1271 | + * @return float |
|
1272 | + * @throws EE_Error |
|
1273 | + */ |
|
1274 | + public function get_items_total() |
|
1275 | + { |
|
1276 | + //by default, let's make sure we're consistent with the existing line item |
|
1277 | + if ($this->is_total()) { |
|
1278 | + $pretax_subtotal_li = EEH_Line_Item::get_pre_tax_subtotal($this); |
|
1279 | + if ($pretax_subtotal_li instanceof EE_Line_Item) { |
|
1280 | + return $pretax_subtotal_li->total(); |
|
1281 | + } |
|
1282 | + } |
|
1283 | + $total = 0; |
|
1284 | + foreach ($this->get_items() as $item) { |
|
1285 | + if ($item instanceof EE_Line_Item) { |
|
1286 | + $total += $item->total(); |
|
1287 | + } |
|
1288 | + } |
|
1289 | + return $total; |
|
1290 | + } |
|
1291 | + |
|
1292 | + |
|
1293 | + |
|
1294 | + /** |
|
1295 | + * Gets all the descendants (ie, children or children of children etc) that |
|
1296 | + * are of the type 'tax' |
|
1297 | + * |
|
1298 | + * @return EE_Line_Item[] |
|
1299 | + */ |
|
1300 | + public function tax_descendants() |
|
1301 | + { |
|
1302 | + return EEH_Line_Item::get_tax_descendants($this); |
|
1303 | + } |
|
1304 | + |
|
1305 | + |
|
1306 | + |
|
1307 | + /** |
|
1308 | + * Gets all the real items purchased which are children of this item |
|
1309 | + * |
|
1310 | + * @return EE_Line_Item[] |
|
1311 | + */ |
|
1312 | + public function get_items() |
|
1313 | + { |
|
1314 | + return EEH_Line_Item::get_line_item_descendants($this); |
|
1315 | + } |
|
1316 | + |
|
1317 | + |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * Returns the amount taxable among this line item's children (or if it has no children, |
|
1321 | + * how much of it is taxable). Does not recalculate totals or subtotals. |
|
1322 | + * If the taxable total is negative, (eg, if none of the tickets were taxable, |
|
1323 | + * but there is a "Taxable" discount), returns 0. |
|
1324 | + * |
|
1325 | + * @return float |
|
1326 | + * @throws EE_Error |
|
1327 | + */ |
|
1328 | + public function taxable_total() |
|
1329 | + { |
|
1330 | + $total = 0; |
|
1331 | + if ($this->children()) { |
|
1332 | + foreach ($this->children() as $child_line_item) { |
|
1333 | + if ($child_line_item->type() === EEM_Line_Item::type_line_item && $child_line_item->is_taxable()) { |
|
1334 | + //if it's a percent item, only take into account the percent |
|
1335 | + //that's taxable too (the taxable total so far) |
|
1336 | + if ($child_line_item->is_percent()) { |
|
1337 | + $total += ($total * $child_line_item->percent() / 100); |
|
1338 | + } else { |
|
1339 | + $total += $child_line_item->total(); |
|
1340 | + } |
|
1341 | + } elseif ($child_line_item->type() === EEM_Line_Item::type_sub_total) { |
|
1342 | + $total += $child_line_item->taxable_total(); |
|
1343 | + } |
|
1344 | + } |
|
1345 | + } |
|
1346 | + return max($total, 0); |
|
1347 | + } |
|
1348 | + |
|
1349 | + |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * Gets the transaction for this line item |
|
1353 | + * |
|
1354 | + * @return EE_Base_Class|EE_Transaction |
|
1355 | + * @throws EE_Error |
|
1356 | + */ |
|
1357 | + public function transaction() |
|
1358 | + { |
|
1359 | + return $this->get_first_related('Transaction'); |
|
1360 | + } |
|
1361 | + |
|
1362 | + |
|
1363 | + |
|
1364 | + /** |
|
1365 | + * Saves this line item to the DB, and recursively saves its descendants. |
|
1366 | + * Because there currently is no proper parent-child relation on the model, |
|
1367 | + * save_this_and_cached() will NOT save the descendants. |
|
1368 | + * Also sets the transaction on this line item and all its descendants before saving |
|
1369 | + * |
|
1370 | + * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
|
1371 | + * @return int count of items saved |
|
1372 | + * @throws EE_Error |
|
1373 | + */ |
|
1374 | + public function save_this_and_descendants_to_txn($txn_id = null) |
|
1375 | + { |
|
1376 | + $count = 0; |
|
1377 | + if (! $txn_id) { |
|
1378 | + $txn_id = $this->TXN_ID(); |
|
1379 | + } |
|
1380 | + $this->set_TXN_ID($txn_id); |
|
1381 | + $children = $this->children(); |
|
1382 | + $count += $this->save() |
|
1383 | + ? 1 |
|
1384 | + : 0; |
|
1385 | + foreach ($children as $child_line_item) { |
|
1386 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1387 | + $child_line_item->set_parent_ID($this->ID()); |
|
1388 | + $count += $child_line_item->save_this_and_descendants_to_txn($txn_id); |
|
1389 | + } |
|
1390 | + } |
|
1391 | + return $count; |
|
1392 | + } |
|
1393 | + |
|
1394 | + |
|
1395 | + |
|
1396 | + /** |
|
1397 | + * Saves this line item to the DB, and recursively saves its descendants. |
|
1398 | + * |
|
1399 | + * @return int count of items saved |
|
1400 | + * @throws EE_Error |
|
1401 | + */ |
|
1402 | + public function save_this_and_descendants() |
|
1403 | + { |
|
1404 | + $count = 0; |
|
1405 | + $children = $this->children(); |
|
1406 | + $count += $this->save() |
|
1407 | + ? 1 |
|
1408 | + : 0; |
|
1409 | + foreach ($children as $child_line_item) { |
|
1410 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1411 | + $child_line_item->set_parent_ID($this->ID()); |
|
1412 | + $count += $child_line_item->save_this_and_descendants(); |
|
1413 | + } |
|
1414 | + } |
|
1415 | + return $count; |
|
1416 | + } |
|
1417 | + |
|
1418 | + |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * returns the cancellation line item if this item was cancelled |
|
1422 | + * |
|
1423 | + * @return EE_Line_Item[] |
|
1424 | + * @throws InvalidArgumentException |
|
1425 | + * @throws InvalidInterfaceException |
|
1426 | + * @throws InvalidDataTypeException |
|
1427 | + * @throws ReflectionException |
|
1428 | + * @throws EE_Error |
|
1429 | + */ |
|
1430 | + public function get_cancellations() |
|
1431 | + { |
|
1432 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
1433 | + return EEH_Line_Item::get_descendants_of_type($this, EEM_Line_Item::type_cancellation); |
|
1434 | + } |
|
1435 | + |
|
1436 | + |
|
1437 | + |
|
1438 | + /** |
|
1439 | + * If this item has an ID, then this saves it again to update the db |
|
1440 | + * |
|
1441 | + * @return int count of items saved |
|
1442 | + * @throws EE_Error |
|
1443 | + */ |
|
1444 | + public function maybe_save() |
|
1445 | + { |
|
1446 | + if ($this->ID()) { |
|
1447 | + return $this->save(); |
|
1448 | + } |
|
1449 | + return false; |
|
1450 | + } |
|
1451 | + |
|
1452 | + |
|
1453 | + /** |
|
1454 | + * clears the cached children and parent from the line item |
|
1455 | + * |
|
1456 | + * @return void |
|
1457 | + */ |
|
1458 | + public function clear_related_line_item_cache() |
|
1459 | + { |
|
1460 | + $this->_children = array(); |
|
1461 | + $this->_parent = null; |
|
1462 | + } |
|
1463 | + |
|
1464 | + |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * @param bool $raw |
|
1468 | + * @return int |
|
1469 | + * @throws EE_Error |
|
1470 | + */ |
|
1471 | + public function timestamp($raw = false) |
|
1472 | + { |
|
1473 | + return $raw |
|
1474 | + ? $this->get_raw('LIN_timestamp') |
|
1475 | + : $this->get('LIN_timestamp'); |
|
1476 | + } |
|
1477 | + |
|
1478 | + |
|
1479 | + |
|
1480 | + |
|
1481 | + /************************* DEPRECATED *************************/ |
|
1482 | + /** |
|
1483 | + * @deprecated 4.6.0 |
|
1484 | + * @param string $type one of the constants on EEM_Line_Item |
|
1485 | + * @return EE_Line_Item[] |
|
1486 | + */ |
|
1487 | + protected function _get_descendants_of_type($type) |
|
1488 | + { |
|
1489 | + EE_Error::doing_it_wrong( |
|
1490 | + 'EE_Line_Item::_get_descendants_of_type()', |
|
1491 | + __('Method replaced with EEH_Line_Item::get_descendants_of_type()', 'event_espresso'), '4.6.0' |
|
1492 | + ); |
|
1493 | + return EEH_Line_Item::get_descendants_of_type($this, $type); |
|
1494 | + } |
|
1495 | + |
|
1496 | + |
|
1497 | + |
|
1498 | + /** |
|
1499 | + * @deprecated 4.6.0 |
|
1500 | + * @param string $type like one of the EEM_Line_Item::type_* |
|
1501 | + * @return EE_Line_Item |
|
1502 | + */ |
|
1503 | + public function get_nearest_descendant_of_type($type) |
|
1504 | + { |
|
1505 | + EE_Error::doing_it_wrong( |
|
1506 | + 'EE_Line_Item::get_nearest_descendant_of_type()', |
|
1507 | + __('Method replaced with EEH_Line_Item::get_nearest_descendant_of_type()', 'event_espresso'), '4.6.0' |
|
1508 | + ); |
|
1509 | + return EEH_Line_Item::get_nearest_descendant_of_type($this, $type); |
|
1510 | + } |
|
1511 | 1511 | |
1512 | 1512 | |
1513 | 1513 |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
80 | 80 | { |
81 | 81 | parent::__construct($fieldValues, $bydb, $timezone); |
82 | - if (! $this->get('LIN_code')) { |
|
82 | + if ( ! $this->get('LIN_code')) { |
|
83 | 83 | $this->set_code($this->generate_code()); |
84 | 84 | } |
85 | 85 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | public function name() |
135 | 135 | { |
136 | 136 | $name = $this->get('LIN_name'); |
137 | - if (! $name) { |
|
137 | + if ( ! $name) { |
|
138 | 138 | $name = ucwords(str_replace('-', ' ', $this->type())); |
139 | 139 | } |
140 | 140 | return $name; |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | ) |
516 | 516 | ); |
517 | 517 | } |
518 | - if (! is_array($this->_children)) { |
|
518 | + if ( ! is_array($this->_children)) { |
|
519 | 519 | $this->_children = array(); |
520 | 520 | } |
521 | 521 | return $this->_children; |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | public function set_parent($line_item) |
742 | 742 | { |
743 | 743 | if ($this->ID()) { |
744 | - if (! $line_item->ID()) { |
|
744 | + if ( ! $line_item->ID()) { |
|
745 | 745 | $line_item->save(); |
746 | 746 | } |
747 | 747 | $this->set_parent_ID($line_item->ID()); |
@@ -815,7 +815,7 @@ discard block |
||
815 | 815 | $items_deleted = 0; |
816 | 816 | if ($this->code() === $code) { |
817 | 817 | $items_deleted += EEH_Line_Item::delete_all_child_items($this); |
818 | - $items_deleted += (int)$this->delete(); |
|
818 | + $items_deleted += (int) $this->delete(); |
|
819 | 819 | if ($stop_search_once_found) { |
820 | 820 | return $items_deleted; |
821 | 821 | } |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | public function generate_code() |
861 | 861 | { |
862 | 862 | // each line item in the cart requires a unique identifier |
863 | - return md5($this->get('OBJ_type') . $this->get('OBJ_ID') . microtime()); |
|
863 | + return md5($this->get('OBJ_type').$this->get('OBJ_ID').microtime()); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | $has_children = ! empty($my_children); |
1036 | 1036 | if ($has_children && $this->is_line_item()) { |
1037 | 1037 | $total = $this->_recalculate_pretax_total_for_line_item($total, $my_children); |
1038 | - } elseif (! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) { |
|
1038 | + } elseif ( ! $has_children && ($this->is_sub_line_item() || $this->is_line_item())) { |
|
1039 | 1039 | $total = $this->unit_price() * $this->quantity(); |
1040 | 1040 | } elseif ($this->is_sub_total() || $this->is_total()) { |
1041 | 1041 | $total = $this->_recalculate_pretax_total_for_subtotal($total, $my_children); |
@@ -1050,13 +1050,13 @@ discard block |
||
1050 | 1050 | if ($this->OBJ_type() !== 'Event') { |
1051 | 1051 | $this->set_quantity(1); |
1052 | 1052 | } |
1053 | - if (! $this->is_percent()) { |
|
1053 | + if ( ! $this->is_percent()) { |
|
1054 | 1054 | $this->set_unit_price($total); |
1055 | 1055 | } |
1056 | 1056 | } |
1057 | 1057 | //we don't want to bother saving grand totals, because that needs to factor in taxes anyways |
1058 | 1058 | //so it ought to be |
1059 | - if (! $this->is_total()) { |
|
1059 | + if ( ! $this->is_total()) { |
|
1060 | 1060 | $this->set_total($total); |
1061 | 1061 | //if not a percent line item, make sure we keep the unit price in sync |
1062 | 1062 | if ( |
@@ -1374,7 +1374,7 @@ discard block |
||
1374 | 1374 | public function save_this_and_descendants_to_txn($txn_id = null) |
1375 | 1375 | { |
1376 | 1376 | $count = 0; |
1377 | - if (! $txn_id) { |
|
1377 | + if ( ! $txn_id) { |
|
1378 | 1378 | $txn_id = $this->TXN_ID(); |
1379 | 1379 | } |
1380 | 1380 | $this->set_TXN_ID($txn_id); |
@@ -863,7 +863,7 @@ |
||
863 | 863 | * handles toggling the checkin status for the registration, |
864 | 864 | * |
865 | 865 | * @access protected |
866 | - * @return int|void |
|
866 | + * @return integer |
|
867 | 867 | */ |
868 | 868 | protected function _toggle_checkin_status() |
869 | 869 | { |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\ui\browser\checkins\entities\CheckinStatusDashicon; |
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 | |
@@ -20,1178 +20,1178 @@ discard block |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * This is used to hold the reports template data which is setup early in the request. |
|
25 | - * |
|
26 | - * @type array |
|
27 | - */ |
|
28 | - protected $_reports_template_data = array(); |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Extend_Registrations_Admin_Page constructor. |
|
34 | - * |
|
35 | - * @param bool $routing |
|
36 | - */ |
|
37 | - public function __construct($routing = true) |
|
38 | - { |
|
39 | - parent::__construct($routing); |
|
40 | - if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
41 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
42 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
43 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - protected function _extend_page_config() |
|
50 | - { |
|
51 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
52 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
53 | - ? $this->_req_data['_REG_ID'] |
|
54 | - : 0; |
|
55 | - // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0; |
|
56 | - // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) |
|
57 | - // ? $this->_req_data['post'] : $att_id; |
|
58 | - $new_page_routes = array( |
|
59 | - 'reports' => array( |
|
60 | - 'func' => '_registration_reports', |
|
61 | - 'capability' => 'ee_read_registrations', |
|
62 | - ), |
|
63 | - 'registration_checkins' => array( |
|
64 | - 'func' => '_registration_checkin_list_table', |
|
65 | - 'capability' => 'ee_read_checkins', |
|
66 | - ), |
|
67 | - 'newsletter_selected_send' => array( |
|
68 | - 'func' => '_newsletter_selected_send', |
|
69 | - 'noheader' => true, |
|
70 | - 'capability' => 'ee_send_message', |
|
71 | - ), |
|
72 | - 'delete_checkin_rows' => array( |
|
73 | - 'func' => '_delete_checkin_rows', |
|
74 | - 'noheader' => true, |
|
75 | - 'capability' => 'ee_delete_checkins', |
|
76 | - ), |
|
77 | - 'delete_checkin_row' => array( |
|
78 | - 'func' => '_delete_checkin_row', |
|
79 | - 'noheader' => true, |
|
80 | - 'capability' => 'ee_delete_checkin', |
|
81 | - 'obj_id' => $reg_id, |
|
82 | - ), |
|
83 | - 'toggle_checkin_status' => array( |
|
84 | - 'func' => '_toggle_checkin_status', |
|
85 | - 'noheader' => true, |
|
86 | - 'capability' => 'ee_edit_checkin', |
|
87 | - 'obj_id' => $reg_id, |
|
88 | - ), |
|
89 | - 'event_registrations' => array( |
|
90 | - 'func' => '_event_registrations_list_table', |
|
91 | - 'capability' => 'ee_read_checkins', |
|
92 | - ), |
|
93 | - 'registrations_checkin_report' => array( |
|
94 | - 'func' => '_registrations_checkin_report', |
|
95 | - 'noheader' => true, |
|
96 | - 'capability' => 'ee_read_registrations', |
|
97 | - ), |
|
98 | - ); |
|
99 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
100 | - $new_page_config = array( |
|
101 | - 'reports' => array( |
|
102 | - 'nav' => array( |
|
103 | - 'label' => __('Reports', 'event_espresso'), |
|
104 | - 'order' => 30, |
|
105 | - ), |
|
106 | - 'help_tabs' => array( |
|
107 | - 'registrations_reports_help_tab' => array( |
|
108 | - 'title' => __('Registration Reports', 'event_espresso'), |
|
109 | - 'filename' => 'registrations_reports', |
|
110 | - ), |
|
111 | - ), |
|
112 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
113 | - 'require_nonce' => false, |
|
114 | - ), |
|
115 | - 'event_registrations' => array( |
|
116 | - 'nav' => array( |
|
117 | - 'label' => __('Event Check-In', 'event_espresso'), |
|
118 | - 'order' => 10, |
|
119 | - 'persistent' => true, |
|
120 | - ), |
|
121 | - 'help_tabs' => array( |
|
122 | - 'registrations_event_checkin_help_tab' => array( |
|
123 | - 'title' => __('Registrations Event Check-In', 'event_espresso'), |
|
124 | - 'filename' => 'registrations_event_checkin', |
|
125 | - ), |
|
126 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
127 | - 'title' => __('Event Check-In Table Column Headings', 'event_espresso'), |
|
128 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
129 | - ), |
|
130 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
131 | - 'title' => __('Event Check-In Filters', 'event_espresso'), |
|
132 | - 'filename' => 'registrations_event_checkin_filters', |
|
133 | - ), |
|
134 | - 'registrations_event_checkin_views_help_tab' => array( |
|
135 | - 'title' => __('Event Check-In Views', 'event_espresso'), |
|
136 | - 'filename' => 'registrations_event_checkin_views', |
|
137 | - ), |
|
138 | - 'registrations_event_checkin_other_help_tab' => array( |
|
139 | - 'title' => __('Event Check-In Other', 'event_espresso'), |
|
140 | - 'filename' => 'registrations_event_checkin_other', |
|
141 | - ), |
|
142 | - ), |
|
143 | - 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
144 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
145 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
146 | - 'metaboxes' => array(), |
|
147 | - 'require_nonce' => false, |
|
148 | - ), |
|
149 | - 'registration_checkins' => array( |
|
150 | - 'nav' => array( |
|
151 | - 'label' => __('Check-In Records', 'event_espresso'), |
|
152 | - 'order' => 15, |
|
153 | - 'persistent' => false, |
|
154 | - ), |
|
155 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
156 | - //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
157 | - 'metaboxes' => array(), |
|
158 | - 'require_nonce' => false, |
|
159 | - ), |
|
160 | - ); |
|
161 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
162 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
163 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - protected function _ajax_hooks() |
|
169 | - { |
|
170 | - parent::_ajax_hooks(); |
|
171 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - |
|
176 | - public function load_scripts_styles() |
|
177 | - { |
|
178 | - parent::load_scripts_styles(); |
|
179 | - //if newsletter message type is active then let's add filter and load js for it. |
|
180 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
181 | - //enqueue newsletter js |
|
182 | - wp_enqueue_script( |
|
183 | - 'ee-newsletter-trigger', |
|
184 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
185 | - array('ee-dialog'), |
|
186 | - EVENT_ESPRESSO_VERSION, |
|
187 | - true |
|
188 | - ); |
|
189 | - wp_enqueue_style( |
|
190 | - 'ee-newsletter-trigger-css', |
|
191 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
192 | - array(), |
|
193 | - EVENT_ESPRESSO_VERSION |
|
194 | - ); |
|
195 | - //hook in buttons for newsletter message type trigger. |
|
196 | - add_action( |
|
197 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
198 | - array($this, 'add_newsletter_action_buttons'), |
|
199 | - 10 |
|
200 | - ); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - public function load_scripts_styles_reports() |
|
207 | - { |
|
208 | - wp_register_script( |
|
209 | - 'ee-reg-reports-js', |
|
210 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
211 | - array('google-charts'), |
|
212 | - EVENT_ESPRESSO_VERSION, |
|
213 | - true |
|
214 | - ); |
|
215 | - wp_enqueue_script('ee-reg-reports-js'); |
|
216 | - $this->_registration_reports_js_setup(); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - protected function _add_screen_options_event_registrations() |
|
222 | - { |
|
223 | - $this->_per_page_screen_option(); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - |
|
228 | - protected function _add_screen_options_registration_checkins() |
|
229 | - { |
|
230 | - $page_title = $this->_admin_page_title; |
|
231 | - $this->_admin_page_title = __('Check-In Records', 'event_espresso'); |
|
232 | - $this->_per_page_screen_option(); |
|
233 | - $this->_admin_page_title = $page_title; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - protected function _set_list_table_views_event_registrations() |
|
239 | - { |
|
240 | - $this->_views = array( |
|
241 | - 'all' => array( |
|
242 | - 'slug' => 'all', |
|
243 | - 'label' => __('All', 'event_espresso'), |
|
244 | - 'count' => 0, |
|
245 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
246 | - ? array() |
|
247 | - : array( |
|
248 | - 'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'), |
|
249 | - //'trash_registrations' => __('Trash Registrations', 'event_espresso') |
|
250 | - ), |
|
251 | - ), |
|
252 | - ); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - |
|
257 | - protected function _set_list_table_views_registration_checkins() |
|
258 | - { |
|
259 | - $this->_views = array( |
|
260 | - 'all' => array( |
|
261 | - 'slug' => 'all', |
|
262 | - 'label' => __('All', 'event_espresso'), |
|
263 | - 'count' => 0, |
|
264 | - 'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')), |
|
265 | - ), |
|
266 | - ); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * callback for ajax action. |
|
273 | - * |
|
274 | - * @since 4.3.0 |
|
275 | - * @return void (JSON) |
|
276 | - * @throws \EE_Error |
|
277 | - */ |
|
278 | - public function get_newsletter_form_content() |
|
279 | - { |
|
280 | - //do a nonce check cause we're not coming in from an normal route here. |
|
281 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
282 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
283 | - ) : ''; |
|
284 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
285 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
286 | - //let's get the mtp for the incoming MTP_ ID |
|
287 | - if ( ! isset($this->_req_data['GRP_ID'])) { |
|
288 | - EE_Error::add_error( |
|
289 | - __( |
|
290 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
291 | - 'event_espresso' |
|
292 | - ), |
|
293 | - __FILE__, |
|
294 | - __FUNCTION__, |
|
295 | - __LINE__ |
|
296 | - ); |
|
297 | - $this->_template_args['success'] = false; |
|
298 | - $this->_template_args['error'] = true; |
|
299 | - $this->_return_json(); |
|
300 | - } |
|
301 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
302 | - if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
303 | - EE_Error::add_error( |
|
304 | - sprintf( |
|
305 | - __( |
|
306 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
307 | - 'event_espresso' |
|
308 | - ), |
|
309 | - $this->_req_data['GRP_ID'] |
|
310 | - ), |
|
311 | - __FILE__, |
|
312 | - __FUNCTION__, |
|
313 | - __LINE__ |
|
314 | - ); |
|
315 | - $this->_template_args['success'] = false; |
|
316 | - $this->_template_args['error'] = true; |
|
317 | - $this->_return_json(); |
|
318 | - } |
|
319 | - $MTPs = $MTPG->context_templates(); |
|
320 | - $MTPs = $MTPs['attendee']; |
|
321 | - $template_fields = array(); |
|
322 | - /** @var EE_Message_Template $MTP */ |
|
323 | - foreach ($MTPs as $MTP) { |
|
324 | - $field = $MTP->get('MTP_template_field'); |
|
325 | - if ($field === 'content') { |
|
326 | - $content = $MTP->get('MTP_content'); |
|
327 | - if ( ! empty($content['newsletter_content'])) { |
|
328 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
329 | - } |
|
330 | - continue; |
|
331 | - } |
|
332 | - $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
333 | - } |
|
334 | - $this->_template_args['success'] = true; |
|
335 | - $this->_template_args['error'] = false; |
|
336 | - $this->_template_args['data'] = array( |
|
337 | - 'batch_message_from' => isset($template_fields['from']) |
|
338 | - ? $template_fields['from'] |
|
339 | - : '', |
|
340 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
341 | - ? $template_fields['subject'] |
|
342 | - : '', |
|
343 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
344 | - ? $template_fields['newsletter_content'] |
|
345 | - : '', |
|
346 | - ); |
|
347 | - $this->_return_json(); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
354 | - * |
|
355 | - * @since 4.3.0 |
|
356 | - * @param EE_Admin_List_Table $list_table |
|
357 | - * @return void |
|
358 | - */ |
|
359 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
360 | - { |
|
361 | - if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
362 | - 'ee_send_message', |
|
363 | - 'espresso_registrations_newsletter_selected_send' |
|
364 | - ) |
|
365 | - ) { |
|
366 | - return; |
|
367 | - } |
|
368 | - $routes_to_add_to = array( |
|
369 | - 'contact_list', |
|
370 | - 'event_registrations', |
|
371 | - 'default', |
|
372 | - ); |
|
373 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
374 | - if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
375 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
376 | - ) { |
|
377 | - echo ''; |
|
378 | - } else { |
|
379 | - $button_text = sprintf( |
|
380 | - __('Send Batch Message (%s selected)', 'event_espresso'), |
|
381 | - '<span class="send-selected-newsletter-count">0</span>' |
|
382 | - ); |
|
383 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' |
|
384 | - . $button_text |
|
385 | - . '</button>'; |
|
386 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
387 | - } |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - |
|
393 | - public function newsletter_send_form_skeleton() |
|
394 | - { |
|
395 | - $list_table = $this->_list_table_object; |
|
396 | - $codes = array(); |
|
397 | - //need to templates for the newsletter message type for the template selector. |
|
398 | - $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
399 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
400 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
401 | - ); |
|
402 | - foreach ($mtps as $mtp) { |
|
403 | - $name = $mtp->name(); |
|
404 | - $values[] = array( |
|
405 | - 'text' => empty($name) ? __('Global', 'event_espresso') : $name, |
|
406 | - 'id' => $mtp->ID(), |
|
407 | - ); |
|
408 | - } |
|
409 | - //need to get a list of shortcodes that are available for the newsletter message type. |
|
410 | - $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false); |
|
411 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
412 | - $codes[$field] = implode(', ', array_keys($shortcode_array)); |
|
413 | - } |
|
414 | - $shortcodes = $codes; |
|
415 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
416 | - $form_template_args = array( |
|
417 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
418 | - 'form_route' => 'newsletter_selected_send', |
|
419 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
420 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
421 | - 'redirect_back_to' => $this->_req_action, |
|
422 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
423 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
424 | - 'shortcodes' => $shortcodes, |
|
425 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
426 | - ); |
|
427 | - EEH_Template::display_template($form_template, $form_template_args); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * Handles sending selected registrations/contacts a newsletter. |
|
434 | - * |
|
435 | - * @since 4.3.0 |
|
436 | - * @return void |
|
437 | - * @throws \EE_Error |
|
438 | - */ |
|
439 | - protected function _newsletter_selected_send() |
|
440 | - { |
|
441 | - $success = true; |
|
442 | - //first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
443 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
444 | - EE_Error::add_error( |
|
445 | - __( |
|
446 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
447 | - 'event_espresso' |
|
448 | - ), |
|
449 | - __FILE__, |
|
450 | - __FUNCTION__, |
|
451 | - __LINE__ |
|
452 | - ); |
|
453 | - $success = false; |
|
454 | - } |
|
455 | - if ($success) { |
|
456 | - //update Message template in case there are any changes |
|
457 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
458 | - $this->_req_data['newsletter_mtp_selected'] |
|
459 | - ); |
|
460 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
461 | - ? $Message_Template_Group->context_templates() |
|
462 | - : array(); |
|
463 | - if (empty($Message_Templates)) { |
|
464 | - EE_Error::add_error( |
|
465 | - __( |
|
466 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
467 | - 'event_espresso' |
|
468 | - ), |
|
469 | - __FILE__, |
|
470 | - __FUNCTION__, |
|
471 | - __LINE__ |
|
472 | - ); |
|
473 | - } |
|
474 | - //let's just update the specific fields |
|
475 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
476 | - if ($Message_Template instanceof EE_Message_Template) { |
|
477 | - $field = $Message_Template->get('MTP_template_field'); |
|
478 | - $content = $Message_Template->get('MTP_content'); |
|
479 | - $new_content = $content; |
|
480 | - switch ($field) { |
|
481 | - case 'from' : |
|
482 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
483 | - ? $this->_req_data['batch_message']['from'] |
|
484 | - : $content; |
|
485 | - break; |
|
486 | - case 'subject' : |
|
487 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
488 | - ? $this->_req_data['batch_message']['subject'] |
|
489 | - : $content; |
|
490 | - break; |
|
491 | - case 'content' : |
|
492 | - $new_content = $content; |
|
493 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
494 | - ? $this->_req_data['batch_message']['content'] |
|
495 | - : $content['newsletter_content']; |
|
496 | - break; |
|
497 | - default : |
|
498 | - //continue the foreach loop, we don't want to set $new_content nor save. |
|
499 | - continue 2; |
|
500 | - } |
|
501 | - $Message_Template->set('MTP_content', $new_content); |
|
502 | - $Message_Template->save(); |
|
503 | - } |
|
504 | - } |
|
505 | - //great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
506 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
507 | - ? $this->_req_data['batch_message']['id_type'] |
|
508 | - : 'registration'; |
|
509 | - //id_type will affect how we assemble the ids. |
|
510 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
511 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
512 | - : array(); |
|
513 | - $registrations_used_for_contact_data = array(); |
|
514 | - //using switch because eventually we'll have other contexts that will be used for generating messages. |
|
515 | - switch ($id_type) { |
|
516 | - case 'registration' : |
|
517 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
518 | - array( |
|
519 | - array( |
|
520 | - 'REG_ID' => array('IN', $ids), |
|
521 | - ), |
|
522 | - ) |
|
523 | - ); |
|
524 | - break; |
|
525 | - case 'contact' : |
|
526 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
527 | - ->get_latest_registration_for_each_of_given_contacts($ids); |
|
528 | - break; |
|
529 | - } |
|
530 | - do_action( |
|
531 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
532 | - $registrations_used_for_contact_data, |
|
533 | - $Message_Template_Group->ID() |
|
534 | - ); |
|
535 | - //kept for backward compat, internally we no longer use this action. |
|
536 | - //@deprecated 4.8.36.rc.002 |
|
537 | - $contacts = $id_type === 'registration' |
|
538 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
539 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
540 | - do_action( |
|
541 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
542 | - $contacts, |
|
543 | - $Message_Template_Group->ID() |
|
544 | - ); |
|
545 | - } |
|
546 | - $query_args = array( |
|
547 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
548 | - ? $this->_req_data['redirect_back_to'] |
|
549 | - : 'default', |
|
550 | - ); |
|
551 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - |
|
556 | - /** |
|
557 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
558 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
559 | - */ |
|
560 | - protected function _registration_reports_js_setup() |
|
561 | - { |
|
562 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
563 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * generates Business Reports regarding Registrations |
|
570 | - * |
|
571 | - * @access protected |
|
572 | - * @return void |
|
573 | - */ |
|
574 | - protected function _registration_reports() |
|
575 | - { |
|
576 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
577 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
578 | - $template_path, |
|
579 | - $this->_reports_template_data, |
|
580 | - true |
|
581 | - ); |
|
582 | - // the final template wrapper |
|
583 | - $this->display_admin_page_with_no_sidebar(); |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * Generates Business Report showing total registrations per day. |
|
590 | - * |
|
591 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
592 | - * @return string |
|
593 | - */ |
|
594 | - private function _registrations_per_day_report($period = '-1 month') |
|
595 | - { |
|
596 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
597 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
598 | - $results = (array)$results; |
|
599 | - $regs = array(); |
|
600 | - $subtitle = ''; |
|
601 | - if ($results) { |
|
602 | - $column_titles = array(); |
|
603 | - $tracker = 0; |
|
604 | - foreach ($results as $result) { |
|
605 | - $report_column_values = array(); |
|
606 | - foreach ($result as $property_name => $property_value) { |
|
607 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
608 | - : (int)$property_value; |
|
609 | - $report_column_values[] = $property_value; |
|
610 | - if ($tracker === 0) { |
|
611 | - if ($property_name === 'Registration_REG_date') { |
|
612 | - $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso'); |
|
613 | - } else { |
|
614 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
615 | - } |
|
616 | - } |
|
617 | - } |
|
618 | - $tracker++; |
|
619 | - $regs[] = $report_column_values; |
|
620 | - } |
|
621 | - //make sure the column_titles is pushed to the beginning of the array |
|
622 | - array_unshift($regs, $column_titles); |
|
623 | - //setup the date range. |
|
624 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
625 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
626 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
627 | - $subtitle = sprintf( |
|
628 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
629 | - $beginning_date->format('Y-m-d'), |
|
630 | - $ending_date->format('Y-m-d') |
|
631 | - ); |
|
632 | - } |
|
633 | - $report_title = __('Total Registrations per Day', 'event_espresso'); |
|
634 | - $report_params = array( |
|
635 | - 'title' => $report_title, |
|
636 | - 'subtitle' => $subtitle, |
|
637 | - 'id' => $report_ID, |
|
638 | - 'regs' => $regs, |
|
639 | - 'noResults' => empty($regs), |
|
640 | - 'noRegsMsg' => sprintf( |
|
641 | - __( |
|
642 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
643 | - 'event_espresso' |
|
644 | - ), |
|
645 | - '<h2>' . $report_title . '</h2><p>', |
|
646 | - '</p>' |
|
647 | - ), |
|
648 | - ); |
|
649 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
650 | - return $report_ID; |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - |
|
655 | - /** |
|
656 | - * Generates Business Report showing total registrations per event. |
|
657 | - * |
|
658 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - private function _registrations_per_event_report($period = '-1 month') |
|
662 | - { |
|
663 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
664 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
665 | - $results = (array)$results; |
|
666 | - $regs = array(); |
|
667 | - $subtitle = ''; |
|
668 | - if ($results) { |
|
669 | - $column_titles = array(); |
|
670 | - $tracker = 0; |
|
671 | - foreach ($results as $result) { |
|
672 | - $report_column_values = array(); |
|
673 | - foreach ($result as $property_name => $property_value) { |
|
674 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
675 | - $property_value, |
|
676 | - 4, |
|
677 | - '...' |
|
678 | - ) : (int)$property_value; |
|
679 | - $report_column_values[] = $property_value; |
|
680 | - if ($tracker === 0) { |
|
681 | - if ($property_name === 'Registration_Event') { |
|
682 | - $column_titles[] = __('Event', 'event_espresso'); |
|
683 | - } else { |
|
684 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
685 | - } |
|
686 | - } |
|
687 | - } |
|
688 | - $tracker++; |
|
689 | - $regs[] = $report_column_values; |
|
690 | - } |
|
691 | - //make sure the column_titles is pushed to the beginning of the array |
|
692 | - array_unshift($regs, $column_titles); |
|
693 | - //setup the date range. |
|
694 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
695 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
696 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
697 | - $subtitle = sprintf( |
|
698 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
699 | - $beginning_date->format('Y-m-d'), |
|
700 | - $ending_date->format('Y-m-d') |
|
701 | - ); |
|
702 | - } |
|
703 | - $report_title = __('Total Registrations per Event', 'event_espresso'); |
|
704 | - $report_params = array( |
|
705 | - 'title' => $report_title, |
|
706 | - 'subtitle' => $subtitle, |
|
707 | - 'id' => $report_ID, |
|
708 | - 'regs' => $regs, |
|
709 | - 'noResults' => empty($regs), |
|
710 | - 'noRegsMsg' => sprintf( |
|
711 | - __( |
|
712 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
713 | - 'event_espresso' |
|
714 | - ), |
|
715 | - '<h2>' . $report_title . '</h2><p>', |
|
716 | - '</p>' |
|
717 | - ), |
|
718 | - ); |
|
719 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
720 | - return $report_ID; |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - |
|
725 | - /** |
|
726 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
727 | - * |
|
728 | - * @access protected |
|
729 | - * @return void |
|
730 | - * @throws \EE_Error |
|
731 | - */ |
|
732 | - protected function _registration_checkin_list_table() |
|
733 | - { |
|
734 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
735 | - $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null; |
|
736 | - /** @var EE_Registration $registration */ |
|
737 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
738 | - $attendee = $registration->attendee(); |
|
739 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
740 | - 'new_registration', |
|
741 | - 'add-registrant', |
|
742 | - array('event_id' => $registration->event_ID()), |
|
743 | - 'add-new-h2' |
|
744 | - ); |
|
745 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
746 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
747 | - $legend_items = array( |
|
748 | - 'checkin' => array( |
|
749 | - 'class' => $checked_in->cssClasses(), |
|
750 | - 'desc' => $checked_in->legendLabel(), |
|
751 | - ), |
|
752 | - 'checkout' => array( |
|
753 | - 'class' => $checked_out->cssClasses(), |
|
754 | - 'desc' => $checked_out->legendLabel(), |
|
755 | - ), |
|
756 | - ); |
|
757 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
758 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
759 | - /** @var EE_Datetime $datetime */ |
|
760 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
761 | - $datetime_label = ''; |
|
762 | - if ($datetime instanceof EE_Datetime) { |
|
763 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
764 | - $datetime_label .= ! empty($datetime_label) |
|
765 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
766 | - : $datetime->get_dtt_display_name(); |
|
767 | - } |
|
768 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
769 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
770 | - array( |
|
771 | - 'action' => 'event_registrations', |
|
772 | - 'event_id' => $registration->event_ID(), |
|
773 | - 'DTT_ID' => $dtt_id, |
|
774 | - ), |
|
775 | - $this->_admin_base_url |
|
776 | - ) |
|
777 | - : ''; |
|
778 | - $datetime_link = ! empty($datetime_link) |
|
779 | - ? '<a href="' . $datetime_link . '">' |
|
780 | - . '<span id="checkin-dtt">' |
|
781 | - . $datetime_label |
|
782 | - . '</span></a>' |
|
783 | - : $datetime_label; |
|
784 | - $attendee_name = $attendee instanceof EE_Attendee |
|
785 | - ? $attendee->full_name() |
|
786 | - : ''; |
|
787 | - $attendee_link = $attendee instanceof EE_Attendee |
|
788 | - ? $attendee->get_admin_details_link() |
|
789 | - : ''; |
|
790 | - $attendee_link = ! empty($attendee_link) |
|
791 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
792 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
793 | - . '<span id="checkin-attendee-name">' |
|
794 | - . $attendee_name |
|
795 | - . '</span></a>' |
|
796 | - : ''; |
|
797 | - $event_link = $registration->event() instanceof EE_Event |
|
798 | - ? $registration->event()->get_admin_details_link() |
|
799 | - : ''; |
|
800 | - $event_link = ! empty($event_link) |
|
801 | - ? '<a href="' . $event_link . '"' |
|
802 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
803 | - . '<span id="checkin-event-name">' |
|
804 | - . $registration->event_name() |
|
805 | - . '</span>' |
|
806 | - . '</a>' |
|
807 | - : ''; |
|
808 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
809 | - ? '<h2>' . sprintf( |
|
810 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
811 | - $attendee_link, |
|
812 | - $datetime_link, |
|
813 | - $event_link |
|
814 | - ) . '</h2>' |
|
815 | - : ''; |
|
816 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
817 | - ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
818 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
819 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
820 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
821 | - } |
|
822 | - |
|
823 | - |
|
824 | - |
|
825 | - /** |
|
826 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
827 | - * |
|
828 | - * @return void (JSON) |
|
829 | - */ |
|
830 | - public function toggle_checkin_status() |
|
831 | - { |
|
832 | - //first make sure we have the necessary data |
|
833 | - if ( ! isset($this->_req_data['_regid'])) { |
|
834 | - EE_Error::add_error( |
|
835 | - __( |
|
836 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
837 | - 'event_espresso' |
|
838 | - ), |
|
839 | - __FILE__, |
|
840 | - __FUNCTION__, |
|
841 | - __LINE__ |
|
842 | - ); |
|
843 | - $this->_template_args['success'] = false; |
|
844 | - $this->_template_args['error'] = true; |
|
845 | - $this->_return_json(); |
|
846 | - }; |
|
847 | - //do a nonce check cause we're not coming in from an normal route here. |
|
848 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
849 | - : ''; |
|
850 | - $nonce_ref = 'checkin_nonce'; |
|
851 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
852 | - //beautiful! Made it this far so let's get the status. |
|
853 | - $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
854 | - //setup new class to return via ajax |
|
855 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
856 | - $this->_template_args['success'] = true; |
|
857 | - $this->_return_json(); |
|
858 | - } |
|
859 | - |
|
860 | - |
|
861 | - |
|
862 | - /** |
|
863 | - * handles toggling the checkin status for the registration, |
|
864 | - * |
|
865 | - * @access protected |
|
866 | - * @return int|void |
|
867 | - */ |
|
868 | - protected function _toggle_checkin_status() |
|
869 | - { |
|
870 | - //first let's get the query args out of the way for the redirect |
|
871 | - $query_args = array( |
|
872 | - 'action' => 'event_registrations', |
|
873 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
874 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
875 | - ); |
|
876 | - $new_status = false; |
|
877 | - // bulk action check in toggle |
|
878 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
879 | - // cycle thru checkboxes |
|
880 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
881 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
882 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
883 | - } |
|
884 | - } elseif (isset($this->_req_data['_regid'])) { |
|
885 | - //coming from ajax request |
|
886 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
887 | - $query_args['DTT_ID'] = $DTT_ID; |
|
888 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
889 | - } else { |
|
890 | - EE_Error::add_error( |
|
891 | - __('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
892 | - __FILE__, |
|
893 | - __FUNCTION__, |
|
894 | - __LINE__ |
|
895 | - ); |
|
896 | - } |
|
897 | - if (defined('DOING_AJAX')) { |
|
898 | - return $new_status; |
|
899 | - } |
|
900 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
901 | - } |
|
902 | - |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * This is toggles a single Check-in for the given registration and datetime. |
|
907 | - * |
|
908 | - * @param int $REG_ID The registration we're toggling |
|
909 | - * @param int $DTT_ID The datetime we're toggling |
|
910 | - * @return int The new status toggled to. |
|
911 | - * @throws \EE_Error |
|
912 | - */ |
|
913 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
914 | - { |
|
915 | - /** @var EE_Registration $REG */ |
|
916 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
917 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
918 | - if ($new_status !== false) { |
|
919 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
920 | - } else { |
|
921 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
922 | - $new_status = false; |
|
923 | - } |
|
924 | - return $new_status; |
|
925 | - } |
|
926 | - |
|
927 | - |
|
928 | - |
|
929 | - /** |
|
930 | - * Takes care of deleting multiple EE_Checkin table rows |
|
931 | - * |
|
932 | - * @access protected |
|
933 | - * @return void |
|
934 | - * @throws \EE_Error |
|
935 | - */ |
|
936 | - protected function _delete_checkin_rows() |
|
937 | - { |
|
938 | - $query_args = array( |
|
939 | - 'action' => 'registration_checkins', |
|
940 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
941 | - '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
942 | - ); |
|
943 | - $errors = 0; |
|
944 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
945 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
946 | - if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
947 | - $errors++; |
|
948 | - } |
|
949 | - } |
|
950 | - } else { |
|
951 | - EE_Error::add_error( |
|
952 | - __( |
|
953 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
954 | - 'event_espresso' |
|
955 | - ), |
|
956 | - __FILE__, |
|
957 | - __FUNCTION__, |
|
958 | - __LINE__ |
|
959 | - ); |
|
960 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
961 | - } |
|
962 | - if ($errors > 0) { |
|
963 | - EE_Error::add_error( |
|
964 | - sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
965 | - __FILE__, |
|
966 | - __FUNCTION__, |
|
967 | - __LINE__ |
|
968 | - ); |
|
969 | - } else { |
|
970 | - EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
971 | - } |
|
972 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
973 | - } |
|
974 | - |
|
975 | - |
|
976 | - |
|
977 | - /** |
|
978 | - * Deletes a single EE_Checkin row |
|
979 | - * |
|
980 | - * @return void |
|
981 | - * @throws \EE_Error |
|
982 | - */ |
|
983 | - protected function _delete_checkin_row() |
|
984 | - { |
|
985 | - $query_args = array( |
|
986 | - 'action' => 'registration_checkins', |
|
987 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
988 | - '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
989 | - ); |
|
990 | - if ( ! empty($this->_req_data['CHK_ID'])) { |
|
991 | - if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
992 | - EE_Error::add_error( |
|
993 | - __('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
994 | - __FILE__, |
|
995 | - __FUNCTION__, |
|
996 | - __LINE__ |
|
997 | - ); |
|
998 | - } else { |
|
999 | - EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1000 | - } |
|
1001 | - } else { |
|
1002 | - EE_Error::add_error( |
|
1003 | - __( |
|
1004 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1005 | - 'event_espresso' |
|
1006 | - ), |
|
1007 | - __FILE__, |
|
1008 | - __FUNCTION__, |
|
1009 | - __LINE__ |
|
1010 | - ); |
|
1011 | - } |
|
1012 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1013 | - } |
|
1014 | - |
|
1015 | - |
|
1016 | - |
|
1017 | - /** |
|
1018 | - * generates HTML for the Event Registrations List Table |
|
1019 | - * |
|
1020 | - * @access protected |
|
1021 | - * @return void |
|
1022 | - * @throws \EE_Error |
|
1023 | - */ |
|
1024 | - protected function _event_registrations_list_table() |
|
1025 | - { |
|
1026 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1027 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1028 | - ? $this->get_action_link_or_button( |
|
1029 | - 'new_registration', |
|
1030 | - 'add-registrant', |
|
1031 | - array('event_id' => $this->_req_data['event_id']), |
|
1032 | - 'add-new-h2', |
|
1033 | - '', |
|
1034 | - false |
|
1035 | - ) |
|
1036 | - : ''; |
|
1037 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1038 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1039 | - $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1040 | - $legend_items = array( |
|
1041 | - 'star-icon' => array( |
|
1042 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1043 | - 'desc' => __('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1044 | - ), |
|
1045 | - 'checkin' => array( |
|
1046 | - 'class' => $checked_in->cssClasses(), |
|
1047 | - 'desc' => $checked_in->legendLabel(), |
|
1048 | - ), |
|
1049 | - 'checkout' => array( |
|
1050 | - 'class' => $checked_out->cssClasses(), |
|
1051 | - 'desc' => $checked_out->legendLabel(), |
|
1052 | - ), |
|
1053 | - 'nocheckinrecord' => array( |
|
1054 | - 'class' => $checked_never->cssClasses(), |
|
1055 | - 'desc' => $checked_never->legendLabel(), |
|
1056 | - ), |
|
1057 | - 'view_details' => array( |
|
1058 | - 'class' => 'dashicons dashicons-search', |
|
1059 | - 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
|
1060 | - ), |
|
1061 | - 'approved_status' => array( |
|
1062 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1063 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1064 | - ), |
|
1065 | - 'cancelled_status' => array( |
|
1066 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1067 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1068 | - ), |
|
1069 | - 'declined_status' => array( |
|
1070 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1071 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1072 | - ), |
|
1073 | - 'not_approved' => array( |
|
1074 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1075 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1076 | - ), |
|
1077 | - 'pending_status' => array( |
|
1078 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1079 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1080 | - ), |
|
1081 | - 'wait_list' => array( |
|
1082 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1083 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1084 | - ), |
|
1085 | - ); |
|
1086 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1087 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1088 | - $this->_template_args['before_list_table'] = ! empty($event_id) |
|
1089 | - ? '<h2>' . sprintf( |
|
1090 | - __('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1091 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1092 | - ) . '</h2>' |
|
1093 | - : ''; |
|
1094 | - //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
|
1095 | - /** @var EE_Event $event */ |
|
1096 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1097 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1098 | - $datetime = null; |
|
1099 | - if ($event instanceof EE_Event) { |
|
1100 | - $datetimes_on_event = $event->datetimes(); |
|
1101 | - if (count($datetimes_on_event) === 1) { |
|
1102 | - $datetime = reset($datetimes_on_event); |
|
1103 | - } |
|
1104 | - } |
|
1105 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1106 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1107 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1108 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1109 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1110 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1111 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1112 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1113 | - } |
|
1114 | - //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
|
1115 | - //represents |
|
1116 | - if ( ! $datetime instanceof EE_Datetime) { |
|
1117 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1118 | - . __('In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1119 | - 'event_espresso') |
|
1120 | - . '</p>'; |
|
1121 | - } |
|
1122 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1123 | - } |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1127 | - * conditions) |
|
1128 | - * |
|
1129 | - * @return void ends the request by a redirect or download |
|
1130 | - */ |
|
1131 | - public function _registrations_checkin_report() |
|
1132 | - { |
|
1133 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1134 | - } |
|
1135 | - |
|
1136 | - /** |
|
1137 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1138 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1139 | - * |
|
1140 | - * @param array $request |
|
1141 | - * @param int $per_page |
|
1142 | - * @param bool $count |
|
1143 | - * @return array |
|
1144 | - */ |
|
1145 | - protected function _get_checkin_query_params_from_request( |
|
1146 | - $request, |
|
1147 | - $per_page = 10, |
|
1148 | - $count = false |
|
1149 | - ) { |
|
1150 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1151 | - //unlike the regular registrations list table, |
|
1152 | - $status_ids_array = apply_filters( |
|
1153 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1154 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1155 | - ); |
|
1156 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1157 | - return $query_params; |
|
1158 | - } |
|
1159 | - |
|
1160 | - |
|
1161 | - |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * Gets registrations for an event |
|
1165 | - * |
|
1166 | - * @param int $per_page |
|
1167 | - * @param bool $count whether to return count or data. |
|
1168 | - * @param bool $trash |
|
1169 | - * @param string $orderby |
|
1170 | - * @return EE_Registration[]|int |
|
1171 | - * @throws \EE_Error |
|
1172 | - */ |
|
1173 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1174 | - { |
|
1175 | - //normalize some request params that get setup by the parent `get_registrations` method. |
|
1176 | - $request = $this->_req_data; |
|
1177 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1178 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1179 | - if($trash){ |
|
1180 | - $request['status'] = 'trash'; |
|
1181 | - } |
|
1182 | - $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count ); |
|
1183 | - /** |
|
1184 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1185 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1186 | - * @see EEM_Base::get_all() |
|
1187 | - */ |
|
1188 | - $query_params['group_by'] = ''; |
|
1189 | - |
|
1190 | - return $count |
|
1191 | - ? EEM_Registration::instance()->count($query_params) |
|
1192 | - /** @type EE_Registration[] */ |
|
1193 | - : EEM_Registration::instance()->get_all($query_params); |
|
1194 | - } |
|
23 | + /** |
|
24 | + * This is used to hold the reports template data which is setup early in the request. |
|
25 | + * |
|
26 | + * @type array |
|
27 | + */ |
|
28 | + protected $_reports_template_data = array(); |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Extend_Registrations_Admin_Page constructor. |
|
34 | + * |
|
35 | + * @param bool $routing |
|
36 | + */ |
|
37 | + public function __construct($routing = true) |
|
38 | + { |
|
39 | + parent::__construct($routing); |
|
40 | + if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
41 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
42 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
43 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + protected function _extend_page_config() |
|
50 | + { |
|
51 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
52 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
53 | + ? $this->_req_data['_REG_ID'] |
|
54 | + : 0; |
|
55 | + // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0; |
|
56 | + // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] ) |
|
57 | + // ? $this->_req_data['post'] : $att_id; |
|
58 | + $new_page_routes = array( |
|
59 | + 'reports' => array( |
|
60 | + 'func' => '_registration_reports', |
|
61 | + 'capability' => 'ee_read_registrations', |
|
62 | + ), |
|
63 | + 'registration_checkins' => array( |
|
64 | + 'func' => '_registration_checkin_list_table', |
|
65 | + 'capability' => 'ee_read_checkins', |
|
66 | + ), |
|
67 | + 'newsletter_selected_send' => array( |
|
68 | + 'func' => '_newsletter_selected_send', |
|
69 | + 'noheader' => true, |
|
70 | + 'capability' => 'ee_send_message', |
|
71 | + ), |
|
72 | + 'delete_checkin_rows' => array( |
|
73 | + 'func' => '_delete_checkin_rows', |
|
74 | + 'noheader' => true, |
|
75 | + 'capability' => 'ee_delete_checkins', |
|
76 | + ), |
|
77 | + 'delete_checkin_row' => array( |
|
78 | + 'func' => '_delete_checkin_row', |
|
79 | + 'noheader' => true, |
|
80 | + 'capability' => 'ee_delete_checkin', |
|
81 | + 'obj_id' => $reg_id, |
|
82 | + ), |
|
83 | + 'toggle_checkin_status' => array( |
|
84 | + 'func' => '_toggle_checkin_status', |
|
85 | + 'noheader' => true, |
|
86 | + 'capability' => 'ee_edit_checkin', |
|
87 | + 'obj_id' => $reg_id, |
|
88 | + ), |
|
89 | + 'event_registrations' => array( |
|
90 | + 'func' => '_event_registrations_list_table', |
|
91 | + 'capability' => 'ee_read_checkins', |
|
92 | + ), |
|
93 | + 'registrations_checkin_report' => array( |
|
94 | + 'func' => '_registrations_checkin_report', |
|
95 | + 'noheader' => true, |
|
96 | + 'capability' => 'ee_read_registrations', |
|
97 | + ), |
|
98 | + ); |
|
99 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
100 | + $new_page_config = array( |
|
101 | + 'reports' => array( |
|
102 | + 'nav' => array( |
|
103 | + 'label' => __('Reports', 'event_espresso'), |
|
104 | + 'order' => 30, |
|
105 | + ), |
|
106 | + 'help_tabs' => array( |
|
107 | + 'registrations_reports_help_tab' => array( |
|
108 | + 'title' => __('Registration Reports', 'event_espresso'), |
|
109 | + 'filename' => 'registrations_reports', |
|
110 | + ), |
|
111 | + ), |
|
112 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
113 | + 'require_nonce' => false, |
|
114 | + ), |
|
115 | + 'event_registrations' => array( |
|
116 | + 'nav' => array( |
|
117 | + 'label' => __('Event Check-In', 'event_espresso'), |
|
118 | + 'order' => 10, |
|
119 | + 'persistent' => true, |
|
120 | + ), |
|
121 | + 'help_tabs' => array( |
|
122 | + 'registrations_event_checkin_help_tab' => array( |
|
123 | + 'title' => __('Registrations Event Check-In', 'event_espresso'), |
|
124 | + 'filename' => 'registrations_event_checkin', |
|
125 | + ), |
|
126 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
127 | + 'title' => __('Event Check-In Table Column Headings', 'event_espresso'), |
|
128 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
129 | + ), |
|
130 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
131 | + 'title' => __('Event Check-In Filters', 'event_espresso'), |
|
132 | + 'filename' => 'registrations_event_checkin_filters', |
|
133 | + ), |
|
134 | + 'registrations_event_checkin_views_help_tab' => array( |
|
135 | + 'title' => __('Event Check-In Views', 'event_espresso'), |
|
136 | + 'filename' => 'registrations_event_checkin_views', |
|
137 | + ), |
|
138 | + 'registrations_event_checkin_other_help_tab' => array( |
|
139 | + 'title' => __('Event Check-In Other', 'event_espresso'), |
|
140 | + 'filename' => 'registrations_event_checkin_other', |
|
141 | + ), |
|
142 | + ), |
|
143 | + 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
144 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
145 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
146 | + 'metaboxes' => array(), |
|
147 | + 'require_nonce' => false, |
|
148 | + ), |
|
149 | + 'registration_checkins' => array( |
|
150 | + 'nav' => array( |
|
151 | + 'label' => __('Check-In Records', 'event_espresso'), |
|
152 | + 'order' => 15, |
|
153 | + 'persistent' => false, |
|
154 | + ), |
|
155 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
156 | + //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
157 | + 'metaboxes' => array(), |
|
158 | + 'require_nonce' => false, |
|
159 | + ), |
|
160 | + ); |
|
161 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
162 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
163 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + protected function _ajax_hooks() |
|
169 | + { |
|
170 | + parent::_ajax_hooks(); |
|
171 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + |
|
176 | + public function load_scripts_styles() |
|
177 | + { |
|
178 | + parent::load_scripts_styles(); |
|
179 | + //if newsletter message type is active then let's add filter and load js for it. |
|
180 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
181 | + //enqueue newsletter js |
|
182 | + wp_enqueue_script( |
|
183 | + 'ee-newsletter-trigger', |
|
184 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
185 | + array('ee-dialog'), |
|
186 | + EVENT_ESPRESSO_VERSION, |
|
187 | + true |
|
188 | + ); |
|
189 | + wp_enqueue_style( |
|
190 | + 'ee-newsletter-trigger-css', |
|
191 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
192 | + array(), |
|
193 | + EVENT_ESPRESSO_VERSION |
|
194 | + ); |
|
195 | + //hook in buttons for newsletter message type trigger. |
|
196 | + add_action( |
|
197 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
198 | + array($this, 'add_newsletter_action_buttons'), |
|
199 | + 10 |
|
200 | + ); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + public function load_scripts_styles_reports() |
|
207 | + { |
|
208 | + wp_register_script( |
|
209 | + 'ee-reg-reports-js', |
|
210 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
211 | + array('google-charts'), |
|
212 | + EVENT_ESPRESSO_VERSION, |
|
213 | + true |
|
214 | + ); |
|
215 | + wp_enqueue_script('ee-reg-reports-js'); |
|
216 | + $this->_registration_reports_js_setup(); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + protected function _add_screen_options_event_registrations() |
|
222 | + { |
|
223 | + $this->_per_page_screen_option(); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + |
|
228 | + protected function _add_screen_options_registration_checkins() |
|
229 | + { |
|
230 | + $page_title = $this->_admin_page_title; |
|
231 | + $this->_admin_page_title = __('Check-In Records', 'event_espresso'); |
|
232 | + $this->_per_page_screen_option(); |
|
233 | + $this->_admin_page_title = $page_title; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + protected function _set_list_table_views_event_registrations() |
|
239 | + { |
|
240 | + $this->_views = array( |
|
241 | + 'all' => array( |
|
242 | + 'slug' => 'all', |
|
243 | + 'label' => __('All', 'event_espresso'), |
|
244 | + 'count' => 0, |
|
245 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
246 | + ? array() |
|
247 | + : array( |
|
248 | + 'toggle_checkin_status' => __('Toggle Check-In', 'event_espresso'), |
|
249 | + //'trash_registrations' => __('Trash Registrations', 'event_espresso') |
|
250 | + ), |
|
251 | + ), |
|
252 | + ); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + |
|
257 | + protected function _set_list_table_views_registration_checkins() |
|
258 | + { |
|
259 | + $this->_views = array( |
|
260 | + 'all' => array( |
|
261 | + 'slug' => 'all', |
|
262 | + 'label' => __('All', 'event_espresso'), |
|
263 | + 'count' => 0, |
|
264 | + 'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')), |
|
265 | + ), |
|
266 | + ); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * callback for ajax action. |
|
273 | + * |
|
274 | + * @since 4.3.0 |
|
275 | + * @return void (JSON) |
|
276 | + * @throws \EE_Error |
|
277 | + */ |
|
278 | + public function get_newsletter_form_content() |
|
279 | + { |
|
280 | + //do a nonce check cause we're not coming in from an normal route here. |
|
281 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
282 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
283 | + ) : ''; |
|
284 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
285 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
286 | + //let's get the mtp for the incoming MTP_ ID |
|
287 | + if ( ! isset($this->_req_data['GRP_ID'])) { |
|
288 | + EE_Error::add_error( |
|
289 | + __( |
|
290 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
291 | + 'event_espresso' |
|
292 | + ), |
|
293 | + __FILE__, |
|
294 | + __FUNCTION__, |
|
295 | + __LINE__ |
|
296 | + ); |
|
297 | + $this->_template_args['success'] = false; |
|
298 | + $this->_template_args['error'] = true; |
|
299 | + $this->_return_json(); |
|
300 | + } |
|
301 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
302 | + if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
303 | + EE_Error::add_error( |
|
304 | + sprintf( |
|
305 | + __( |
|
306 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
307 | + 'event_espresso' |
|
308 | + ), |
|
309 | + $this->_req_data['GRP_ID'] |
|
310 | + ), |
|
311 | + __FILE__, |
|
312 | + __FUNCTION__, |
|
313 | + __LINE__ |
|
314 | + ); |
|
315 | + $this->_template_args['success'] = false; |
|
316 | + $this->_template_args['error'] = true; |
|
317 | + $this->_return_json(); |
|
318 | + } |
|
319 | + $MTPs = $MTPG->context_templates(); |
|
320 | + $MTPs = $MTPs['attendee']; |
|
321 | + $template_fields = array(); |
|
322 | + /** @var EE_Message_Template $MTP */ |
|
323 | + foreach ($MTPs as $MTP) { |
|
324 | + $field = $MTP->get('MTP_template_field'); |
|
325 | + if ($field === 'content') { |
|
326 | + $content = $MTP->get('MTP_content'); |
|
327 | + if ( ! empty($content['newsletter_content'])) { |
|
328 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
329 | + } |
|
330 | + continue; |
|
331 | + } |
|
332 | + $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
333 | + } |
|
334 | + $this->_template_args['success'] = true; |
|
335 | + $this->_template_args['error'] = false; |
|
336 | + $this->_template_args['data'] = array( |
|
337 | + 'batch_message_from' => isset($template_fields['from']) |
|
338 | + ? $template_fields['from'] |
|
339 | + : '', |
|
340 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
341 | + ? $template_fields['subject'] |
|
342 | + : '', |
|
343 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
344 | + ? $template_fields['newsletter_content'] |
|
345 | + : '', |
|
346 | + ); |
|
347 | + $this->_return_json(); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
354 | + * |
|
355 | + * @since 4.3.0 |
|
356 | + * @param EE_Admin_List_Table $list_table |
|
357 | + * @return void |
|
358 | + */ |
|
359 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
360 | + { |
|
361 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
362 | + 'ee_send_message', |
|
363 | + 'espresso_registrations_newsletter_selected_send' |
|
364 | + ) |
|
365 | + ) { |
|
366 | + return; |
|
367 | + } |
|
368 | + $routes_to_add_to = array( |
|
369 | + 'contact_list', |
|
370 | + 'event_registrations', |
|
371 | + 'default', |
|
372 | + ); |
|
373 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
374 | + if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
375 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
376 | + ) { |
|
377 | + echo ''; |
|
378 | + } else { |
|
379 | + $button_text = sprintf( |
|
380 | + __('Send Batch Message (%s selected)', 'event_espresso'), |
|
381 | + '<span class="send-selected-newsletter-count">0</span>' |
|
382 | + ); |
|
383 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>' |
|
384 | + . $button_text |
|
385 | + . '</button>'; |
|
386 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
387 | + } |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + |
|
393 | + public function newsletter_send_form_skeleton() |
|
394 | + { |
|
395 | + $list_table = $this->_list_table_object; |
|
396 | + $codes = array(); |
|
397 | + //need to templates for the newsletter message type for the template selector. |
|
398 | + $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
399 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
400 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
401 | + ); |
|
402 | + foreach ($mtps as $mtp) { |
|
403 | + $name = $mtp->name(); |
|
404 | + $values[] = array( |
|
405 | + 'text' => empty($name) ? __('Global', 'event_espresso') : $name, |
|
406 | + 'id' => $mtp->ID(), |
|
407 | + ); |
|
408 | + } |
|
409 | + //need to get a list of shortcodes that are available for the newsletter message type. |
|
410 | + $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false); |
|
411 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
412 | + $codes[$field] = implode(', ', array_keys($shortcode_array)); |
|
413 | + } |
|
414 | + $shortcodes = $codes; |
|
415 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
416 | + $form_template_args = array( |
|
417 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
418 | + 'form_route' => 'newsletter_selected_send', |
|
419 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
420 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
421 | + 'redirect_back_to' => $this->_req_action, |
|
422 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
423 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
424 | + 'shortcodes' => $shortcodes, |
|
425 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
426 | + ); |
|
427 | + EEH_Template::display_template($form_template, $form_template_args); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * Handles sending selected registrations/contacts a newsletter. |
|
434 | + * |
|
435 | + * @since 4.3.0 |
|
436 | + * @return void |
|
437 | + * @throws \EE_Error |
|
438 | + */ |
|
439 | + protected function _newsletter_selected_send() |
|
440 | + { |
|
441 | + $success = true; |
|
442 | + //first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
443 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
444 | + EE_Error::add_error( |
|
445 | + __( |
|
446 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
447 | + 'event_espresso' |
|
448 | + ), |
|
449 | + __FILE__, |
|
450 | + __FUNCTION__, |
|
451 | + __LINE__ |
|
452 | + ); |
|
453 | + $success = false; |
|
454 | + } |
|
455 | + if ($success) { |
|
456 | + //update Message template in case there are any changes |
|
457 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
458 | + $this->_req_data['newsletter_mtp_selected'] |
|
459 | + ); |
|
460 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
461 | + ? $Message_Template_Group->context_templates() |
|
462 | + : array(); |
|
463 | + if (empty($Message_Templates)) { |
|
464 | + EE_Error::add_error( |
|
465 | + __( |
|
466 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
467 | + 'event_espresso' |
|
468 | + ), |
|
469 | + __FILE__, |
|
470 | + __FUNCTION__, |
|
471 | + __LINE__ |
|
472 | + ); |
|
473 | + } |
|
474 | + //let's just update the specific fields |
|
475 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
476 | + if ($Message_Template instanceof EE_Message_Template) { |
|
477 | + $field = $Message_Template->get('MTP_template_field'); |
|
478 | + $content = $Message_Template->get('MTP_content'); |
|
479 | + $new_content = $content; |
|
480 | + switch ($field) { |
|
481 | + case 'from' : |
|
482 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
483 | + ? $this->_req_data['batch_message']['from'] |
|
484 | + : $content; |
|
485 | + break; |
|
486 | + case 'subject' : |
|
487 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
488 | + ? $this->_req_data['batch_message']['subject'] |
|
489 | + : $content; |
|
490 | + break; |
|
491 | + case 'content' : |
|
492 | + $new_content = $content; |
|
493 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
494 | + ? $this->_req_data['batch_message']['content'] |
|
495 | + : $content['newsletter_content']; |
|
496 | + break; |
|
497 | + default : |
|
498 | + //continue the foreach loop, we don't want to set $new_content nor save. |
|
499 | + continue 2; |
|
500 | + } |
|
501 | + $Message_Template->set('MTP_content', $new_content); |
|
502 | + $Message_Template->save(); |
|
503 | + } |
|
504 | + } |
|
505 | + //great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
506 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
507 | + ? $this->_req_data['batch_message']['id_type'] |
|
508 | + : 'registration'; |
|
509 | + //id_type will affect how we assemble the ids. |
|
510 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
511 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
512 | + : array(); |
|
513 | + $registrations_used_for_contact_data = array(); |
|
514 | + //using switch because eventually we'll have other contexts that will be used for generating messages. |
|
515 | + switch ($id_type) { |
|
516 | + case 'registration' : |
|
517 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
518 | + array( |
|
519 | + array( |
|
520 | + 'REG_ID' => array('IN', $ids), |
|
521 | + ), |
|
522 | + ) |
|
523 | + ); |
|
524 | + break; |
|
525 | + case 'contact' : |
|
526 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
527 | + ->get_latest_registration_for_each_of_given_contacts($ids); |
|
528 | + break; |
|
529 | + } |
|
530 | + do_action( |
|
531 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
532 | + $registrations_used_for_contact_data, |
|
533 | + $Message_Template_Group->ID() |
|
534 | + ); |
|
535 | + //kept for backward compat, internally we no longer use this action. |
|
536 | + //@deprecated 4.8.36.rc.002 |
|
537 | + $contacts = $id_type === 'registration' |
|
538 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
539 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
540 | + do_action( |
|
541 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
542 | + $contacts, |
|
543 | + $Message_Template_Group->ID() |
|
544 | + ); |
|
545 | + } |
|
546 | + $query_args = array( |
|
547 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
548 | + ? $this->_req_data['redirect_back_to'] |
|
549 | + : 'default', |
|
550 | + ); |
|
551 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + |
|
556 | + /** |
|
557 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
558 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
559 | + */ |
|
560 | + protected function _registration_reports_js_setup() |
|
561 | + { |
|
562 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
563 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * generates Business Reports regarding Registrations |
|
570 | + * |
|
571 | + * @access protected |
|
572 | + * @return void |
|
573 | + */ |
|
574 | + protected function _registration_reports() |
|
575 | + { |
|
576 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
577 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
578 | + $template_path, |
|
579 | + $this->_reports_template_data, |
|
580 | + true |
|
581 | + ); |
|
582 | + // the final template wrapper |
|
583 | + $this->display_admin_page_with_no_sidebar(); |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * Generates Business Report showing total registrations per day. |
|
590 | + * |
|
591 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
592 | + * @return string |
|
593 | + */ |
|
594 | + private function _registrations_per_day_report($period = '-1 month') |
|
595 | + { |
|
596 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
597 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
598 | + $results = (array)$results; |
|
599 | + $regs = array(); |
|
600 | + $subtitle = ''; |
|
601 | + if ($results) { |
|
602 | + $column_titles = array(); |
|
603 | + $tracker = 0; |
|
604 | + foreach ($results as $result) { |
|
605 | + $report_column_values = array(); |
|
606 | + foreach ($result as $property_name => $property_value) { |
|
607 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
608 | + : (int)$property_value; |
|
609 | + $report_column_values[] = $property_value; |
|
610 | + if ($tracker === 0) { |
|
611 | + if ($property_name === 'Registration_REG_date') { |
|
612 | + $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso'); |
|
613 | + } else { |
|
614 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
615 | + } |
|
616 | + } |
|
617 | + } |
|
618 | + $tracker++; |
|
619 | + $regs[] = $report_column_values; |
|
620 | + } |
|
621 | + //make sure the column_titles is pushed to the beginning of the array |
|
622 | + array_unshift($regs, $column_titles); |
|
623 | + //setup the date range. |
|
624 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
625 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
626 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
627 | + $subtitle = sprintf( |
|
628 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
629 | + $beginning_date->format('Y-m-d'), |
|
630 | + $ending_date->format('Y-m-d') |
|
631 | + ); |
|
632 | + } |
|
633 | + $report_title = __('Total Registrations per Day', 'event_espresso'); |
|
634 | + $report_params = array( |
|
635 | + 'title' => $report_title, |
|
636 | + 'subtitle' => $subtitle, |
|
637 | + 'id' => $report_ID, |
|
638 | + 'regs' => $regs, |
|
639 | + 'noResults' => empty($regs), |
|
640 | + 'noRegsMsg' => sprintf( |
|
641 | + __( |
|
642 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
643 | + 'event_espresso' |
|
644 | + ), |
|
645 | + '<h2>' . $report_title . '</h2><p>', |
|
646 | + '</p>' |
|
647 | + ), |
|
648 | + ); |
|
649 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
650 | + return $report_ID; |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + |
|
655 | + /** |
|
656 | + * Generates Business Report showing total registrations per event. |
|
657 | + * |
|
658 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + private function _registrations_per_event_report($period = '-1 month') |
|
662 | + { |
|
663 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
664 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
665 | + $results = (array)$results; |
|
666 | + $regs = array(); |
|
667 | + $subtitle = ''; |
|
668 | + if ($results) { |
|
669 | + $column_titles = array(); |
|
670 | + $tracker = 0; |
|
671 | + foreach ($results as $result) { |
|
672 | + $report_column_values = array(); |
|
673 | + foreach ($result as $property_name => $property_value) { |
|
674 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
675 | + $property_value, |
|
676 | + 4, |
|
677 | + '...' |
|
678 | + ) : (int)$property_value; |
|
679 | + $report_column_values[] = $property_value; |
|
680 | + if ($tracker === 0) { |
|
681 | + if ($property_name === 'Registration_Event') { |
|
682 | + $column_titles[] = __('Event', 'event_espresso'); |
|
683 | + } else { |
|
684 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
685 | + } |
|
686 | + } |
|
687 | + } |
|
688 | + $tracker++; |
|
689 | + $regs[] = $report_column_values; |
|
690 | + } |
|
691 | + //make sure the column_titles is pushed to the beginning of the array |
|
692 | + array_unshift($regs, $column_titles); |
|
693 | + //setup the date range. |
|
694 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
695 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
696 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
697 | + $subtitle = sprintf( |
|
698 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
699 | + $beginning_date->format('Y-m-d'), |
|
700 | + $ending_date->format('Y-m-d') |
|
701 | + ); |
|
702 | + } |
|
703 | + $report_title = __('Total Registrations per Event', 'event_espresso'); |
|
704 | + $report_params = array( |
|
705 | + 'title' => $report_title, |
|
706 | + 'subtitle' => $subtitle, |
|
707 | + 'id' => $report_ID, |
|
708 | + 'regs' => $regs, |
|
709 | + 'noResults' => empty($regs), |
|
710 | + 'noRegsMsg' => sprintf( |
|
711 | + __( |
|
712 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
713 | + 'event_espresso' |
|
714 | + ), |
|
715 | + '<h2>' . $report_title . '</h2><p>', |
|
716 | + '</p>' |
|
717 | + ), |
|
718 | + ); |
|
719 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
720 | + return $report_ID; |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + |
|
725 | + /** |
|
726 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
727 | + * |
|
728 | + * @access protected |
|
729 | + * @return void |
|
730 | + * @throws \EE_Error |
|
731 | + */ |
|
732 | + protected function _registration_checkin_list_table() |
|
733 | + { |
|
734 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
735 | + $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null; |
|
736 | + /** @var EE_Registration $registration */ |
|
737 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
738 | + $attendee = $registration->attendee(); |
|
739 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
740 | + 'new_registration', |
|
741 | + 'add-registrant', |
|
742 | + array('event_id' => $registration->event_ID()), |
|
743 | + 'add-new-h2' |
|
744 | + ); |
|
745 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
746 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
747 | + $legend_items = array( |
|
748 | + 'checkin' => array( |
|
749 | + 'class' => $checked_in->cssClasses(), |
|
750 | + 'desc' => $checked_in->legendLabel(), |
|
751 | + ), |
|
752 | + 'checkout' => array( |
|
753 | + 'class' => $checked_out->cssClasses(), |
|
754 | + 'desc' => $checked_out->legendLabel(), |
|
755 | + ), |
|
756 | + ); |
|
757 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
758 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
759 | + /** @var EE_Datetime $datetime */ |
|
760 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
761 | + $datetime_label = ''; |
|
762 | + if ($datetime instanceof EE_Datetime) { |
|
763 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
764 | + $datetime_label .= ! empty($datetime_label) |
|
765 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
766 | + : $datetime->get_dtt_display_name(); |
|
767 | + } |
|
768 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
769 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
770 | + array( |
|
771 | + 'action' => 'event_registrations', |
|
772 | + 'event_id' => $registration->event_ID(), |
|
773 | + 'DTT_ID' => $dtt_id, |
|
774 | + ), |
|
775 | + $this->_admin_base_url |
|
776 | + ) |
|
777 | + : ''; |
|
778 | + $datetime_link = ! empty($datetime_link) |
|
779 | + ? '<a href="' . $datetime_link . '">' |
|
780 | + . '<span id="checkin-dtt">' |
|
781 | + . $datetime_label |
|
782 | + . '</span></a>' |
|
783 | + : $datetime_label; |
|
784 | + $attendee_name = $attendee instanceof EE_Attendee |
|
785 | + ? $attendee->full_name() |
|
786 | + : ''; |
|
787 | + $attendee_link = $attendee instanceof EE_Attendee |
|
788 | + ? $attendee->get_admin_details_link() |
|
789 | + : ''; |
|
790 | + $attendee_link = ! empty($attendee_link) |
|
791 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
792 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
793 | + . '<span id="checkin-attendee-name">' |
|
794 | + . $attendee_name |
|
795 | + . '</span></a>' |
|
796 | + : ''; |
|
797 | + $event_link = $registration->event() instanceof EE_Event |
|
798 | + ? $registration->event()->get_admin_details_link() |
|
799 | + : ''; |
|
800 | + $event_link = ! empty($event_link) |
|
801 | + ? '<a href="' . $event_link . '"' |
|
802 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
803 | + . '<span id="checkin-event-name">' |
|
804 | + . $registration->event_name() |
|
805 | + . '</span>' |
|
806 | + . '</a>' |
|
807 | + : ''; |
|
808 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
809 | + ? '<h2>' . sprintf( |
|
810 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
811 | + $attendee_link, |
|
812 | + $datetime_link, |
|
813 | + $event_link |
|
814 | + ) . '</h2>' |
|
815 | + : ''; |
|
816 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
817 | + ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
818 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
819 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
820 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
821 | + } |
|
822 | + |
|
823 | + |
|
824 | + |
|
825 | + /** |
|
826 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
827 | + * |
|
828 | + * @return void (JSON) |
|
829 | + */ |
|
830 | + public function toggle_checkin_status() |
|
831 | + { |
|
832 | + //first make sure we have the necessary data |
|
833 | + if ( ! isset($this->_req_data['_regid'])) { |
|
834 | + EE_Error::add_error( |
|
835 | + __( |
|
836 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
837 | + 'event_espresso' |
|
838 | + ), |
|
839 | + __FILE__, |
|
840 | + __FUNCTION__, |
|
841 | + __LINE__ |
|
842 | + ); |
|
843 | + $this->_template_args['success'] = false; |
|
844 | + $this->_template_args['error'] = true; |
|
845 | + $this->_return_json(); |
|
846 | + }; |
|
847 | + //do a nonce check cause we're not coming in from an normal route here. |
|
848 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
849 | + : ''; |
|
850 | + $nonce_ref = 'checkin_nonce'; |
|
851 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
852 | + //beautiful! Made it this far so let's get the status. |
|
853 | + $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
854 | + //setup new class to return via ajax |
|
855 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
856 | + $this->_template_args['success'] = true; |
|
857 | + $this->_return_json(); |
|
858 | + } |
|
859 | + |
|
860 | + |
|
861 | + |
|
862 | + /** |
|
863 | + * handles toggling the checkin status for the registration, |
|
864 | + * |
|
865 | + * @access protected |
|
866 | + * @return int|void |
|
867 | + */ |
|
868 | + protected function _toggle_checkin_status() |
|
869 | + { |
|
870 | + //first let's get the query args out of the way for the redirect |
|
871 | + $query_args = array( |
|
872 | + 'action' => 'event_registrations', |
|
873 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
874 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
875 | + ); |
|
876 | + $new_status = false; |
|
877 | + // bulk action check in toggle |
|
878 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
879 | + // cycle thru checkboxes |
|
880 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
881 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
882 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
883 | + } |
|
884 | + } elseif (isset($this->_req_data['_regid'])) { |
|
885 | + //coming from ajax request |
|
886 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
887 | + $query_args['DTT_ID'] = $DTT_ID; |
|
888 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
889 | + } else { |
|
890 | + EE_Error::add_error( |
|
891 | + __('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
892 | + __FILE__, |
|
893 | + __FUNCTION__, |
|
894 | + __LINE__ |
|
895 | + ); |
|
896 | + } |
|
897 | + if (defined('DOING_AJAX')) { |
|
898 | + return $new_status; |
|
899 | + } |
|
900 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
901 | + } |
|
902 | + |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * This is toggles a single Check-in for the given registration and datetime. |
|
907 | + * |
|
908 | + * @param int $REG_ID The registration we're toggling |
|
909 | + * @param int $DTT_ID The datetime we're toggling |
|
910 | + * @return int The new status toggled to. |
|
911 | + * @throws \EE_Error |
|
912 | + */ |
|
913 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
914 | + { |
|
915 | + /** @var EE_Registration $REG */ |
|
916 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
917 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
918 | + if ($new_status !== false) { |
|
919 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
920 | + } else { |
|
921 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
922 | + $new_status = false; |
|
923 | + } |
|
924 | + return $new_status; |
|
925 | + } |
|
926 | + |
|
927 | + |
|
928 | + |
|
929 | + /** |
|
930 | + * Takes care of deleting multiple EE_Checkin table rows |
|
931 | + * |
|
932 | + * @access protected |
|
933 | + * @return void |
|
934 | + * @throws \EE_Error |
|
935 | + */ |
|
936 | + protected function _delete_checkin_rows() |
|
937 | + { |
|
938 | + $query_args = array( |
|
939 | + 'action' => 'registration_checkins', |
|
940 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
941 | + '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
942 | + ); |
|
943 | + $errors = 0; |
|
944 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
945 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
946 | + if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
947 | + $errors++; |
|
948 | + } |
|
949 | + } |
|
950 | + } else { |
|
951 | + EE_Error::add_error( |
|
952 | + __( |
|
953 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
954 | + 'event_espresso' |
|
955 | + ), |
|
956 | + __FILE__, |
|
957 | + __FUNCTION__, |
|
958 | + __LINE__ |
|
959 | + ); |
|
960 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
961 | + } |
|
962 | + if ($errors > 0) { |
|
963 | + EE_Error::add_error( |
|
964 | + sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
965 | + __FILE__, |
|
966 | + __FUNCTION__, |
|
967 | + __LINE__ |
|
968 | + ); |
|
969 | + } else { |
|
970 | + EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
971 | + } |
|
972 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
973 | + } |
|
974 | + |
|
975 | + |
|
976 | + |
|
977 | + /** |
|
978 | + * Deletes a single EE_Checkin row |
|
979 | + * |
|
980 | + * @return void |
|
981 | + * @throws \EE_Error |
|
982 | + */ |
|
983 | + protected function _delete_checkin_row() |
|
984 | + { |
|
985 | + $query_args = array( |
|
986 | + 'action' => 'registration_checkins', |
|
987 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
988 | + '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0, |
|
989 | + ); |
|
990 | + if ( ! empty($this->_req_data['CHK_ID'])) { |
|
991 | + if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
992 | + EE_Error::add_error( |
|
993 | + __('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
994 | + __FILE__, |
|
995 | + __FUNCTION__, |
|
996 | + __LINE__ |
|
997 | + ); |
|
998 | + } else { |
|
999 | + EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1000 | + } |
|
1001 | + } else { |
|
1002 | + EE_Error::add_error( |
|
1003 | + __( |
|
1004 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1005 | + 'event_espresso' |
|
1006 | + ), |
|
1007 | + __FILE__, |
|
1008 | + __FUNCTION__, |
|
1009 | + __LINE__ |
|
1010 | + ); |
|
1011 | + } |
|
1012 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1013 | + } |
|
1014 | + |
|
1015 | + |
|
1016 | + |
|
1017 | + /** |
|
1018 | + * generates HTML for the Event Registrations List Table |
|
1019 | + * |
|
1020 | + * @access protected |
|
1021 | + * @return void |
|
1022 | + * @throws \EE_Error |
|
1023 | + */ |
|
1024 | + protected function _event_registrations_list_table() |
|
1025 | + { |
|
1026 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1027 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1028 | + ? $this->get_action_link_or_button( |
|
1029 | + 'new_registration', |
|
1030 | + 'add-registrant', |
|
1031 | + array('event_id' => $this->_req_data['event_id']), |
|
1032 | + 'add-new-h2', |
|
1033 | + '', |
|
1034 | + false |
|
1035 | + ) |
|
1036 | + : ''; |
|
1037 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1038 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1039 | + $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1040 | + $legend_items = array( |
|
1041 | + 'star-icon' => array( |
|
1042 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1043 | + 'desc' => __('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1044 | + ), |
|
1045 | + 'checkin' => array( |
|
1046 | + 'class' => $checked_in->cssClasses(), |
|
1047 | + 'desc' => $checked_in->legendLabel(), |
|
1048 | + ), |
|
1049 | + 'checkout' => array( |
|
1050 | + 'class' => $checked_out->cssClasses(), |
|
1051 | + 'desc' => $checked_out->legendLabel(), |
|
1052 | + ), |
|
1053 | + 'nocheckinrecord' => array( |
|
1054 | + 'class' => $checked_never->cssClasses(), |
|
1055 | + 'desc' => $checked_never->legendLabel(), |
|
1056 | + ), |
|
1057 | + 'view_details' => array( |
|
1058 | + 'class' => 'dashicons dashicons-search', |
|
1059 | + 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
|
1060 | + ), |
|
1061 | + 'approved_status' => array( |
|
1062 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1063 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1064 | + ), |
|
1065 | + 'cancelled_status' => array( |
|
1066 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1067 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1068 | + ), |
|
1069 | + 'declined_status' => array( |
|
1070 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1071 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1072 | + ), |
|
1073 | + 'not_approved' => array( |
|
1074 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1075 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1076 | + ), |
|
1077 | + 'pending_status' => array( |
|
1078 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1079 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1080 | + ), |
|
1081 | + 'wait_list' => array( |
|
1082 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1083 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1084 | + ), |
|
1085 | + ); |
|
1086 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1087 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1088 | + $this->_template_args['before_list_table'] = ! empty($event_id) |
|
1089 | + ? '<h2>' . sprintf( |
|
1090 | + __('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1091 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1092 | + ) . '</h2>' |
|
1093 | + : ''; |
|
1094 | + //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
|
1095 | + /** @var EE_Event $event */ |
|
1096 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1097 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1098 | + $datetime = null; |
|
1099 | + if ($event instanceof EE_Event) { |
|
1100 | + $datetimes_on_event = $event->datetimes(); |
|
1101 | + if (count($datetimes_on_event) === 1) { |
|
1102 | + $datetime = reset($datetimes_on_event); |
|
1103 | + } |
|
1104 | + } |
|
1105 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1106 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1107 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1108 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1109 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1110 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1111 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1112 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1113 | + } |
|
1114 | + //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
|
1115 | + //represents |
|
1116 | + if ( ! $datetime instanceof EE_Datetime) { |
|
1117 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1118 | + . __('In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1119 | + 'event_espresso') |
|
1120 | + . '</p>'; |
|
1121 | + } |
|
1122 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1123 | + } |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1127 | + * conditions) |
|
1128 | + * |
|
1129 | + * @return void ends the request by a redirect or download |
|
1130 | + */ |
|
1131 | + public function _registrations_checkin_report() |
|
1132 | + { |
|
1133 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1134 | + } |
|
1135 | + |
|
1136 | + /** |
|
1137 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1138 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1139 | + * |
|
1140 | + * @param array $request |
|
1141 | + * @param int $per_page |
|
1142 | + * @param bool $count |
|
1143 | + * @return array |
|
1144 | + */ |
|
1145 | + protected function _get_checkin_query_params_from_request( |
|
1146 | + $request, |
|
1147 | + $per_page = 10, |
|
1148 | + $count = false |
|
1149 | + ) { |
|
1150 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1151 | + //unlike the regular registrations list table, |
|
1152 | + $status_ids_array = apply_filters( |
|
1153 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1154 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1155 | + ); |
|
1156 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1157 | + return $query_params; |
|
1158 | + } |
|
1159 | + |
|
1160 | + |
|
1161 | + |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * Gets registrations for an event |
|
1165 | + * |
|
1166 | + * @param int $per_page |
|
1167 | + * @param bool $count whether to return count or data. |
|
1168 | + * @param bool $trash |
|
1169 | + * @param string $orderby |
|
1170 | + * @return EE_Registration[]|int |
|
1171 | + * @throws \EE_Error |
|
1172 | + */ |
|
1173 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1174 | + { |
|
1175 | + //normalize some request params that get setup by the parent `get_registrations` method. |
|
1176 | + $request = $this->_req_data; |
|
1177 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1178 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1179 | + if($trash){ |
|
1180 | + $request['status'] = 'trash'; |
|
1181 | + } |
|
1182 | + $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count ); |
|
1183 | + /** |
|
1184 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1185 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1186 | + * @see EEM_Base::get_all() |
|
1187 | + */ |
|
1188 | + $query_params['group_by'] = ''; |
|
1189 | + |
|
1190 | + return $count |
|
1191 | + ? EEM_Registration::instance()->count($query_params) |
|
1192 | + /** @type EE_Registration[] */ |
|
1193 | + : EEM_Registration::instance()->get_all($query_params); |
|
1194 | + } |
|
1195 | 1195 | |
1196 | 1196 | |
1197 | 1197 | } //end class Registrations Admin Page |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | { |
39 | 39 | parent::__construct($routing); |
40 | 40 | if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
41 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
42 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
43 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
41 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/'); |
|
42 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/'); |
|
43 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/'); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | protected function _extend_page_config() |
50 | 50 | { |
51 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
51 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations'; |
|
52 | 52 | $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
53 | 53 | ? $this->_req_data['_REG_ID'] |
54 | 54 | : 0; |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | //enqueue newsletter js |
182 | 182 | wp_enqueue_script( |
183 | 183 | 'ee-newsletter-trigger', |
184 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
184 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js', |
|
185 | 185 | array('ee-dialog'), |
186 | 186 | EVENT_ESPRESSO_VERSION, |
187 | 187 | true |
188 | 188 | ); |
189 | 189 | wp_enqueue_style( |
190 | 190 | 'ee-newsletter-trigger-css', |
191 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
191 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css', |
|
192 | 192 | array(), |
193 | 193 | EVENT_ESPRESSO_VERSION |
194 | 194 | ); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | { |
208 | 208 | wp_register_script( |
209 | 209 | 'ee-reg-reports-js', |
210 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
210 | + REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js', |
|
211 | 211 | array('google-charts'), |
212 | 212 | EVENT_ESPRESSO_VERSION, |
213 | 213 | true |
@@ -412,7 +412,7 @@ discard block |
||
412 | 412 | $codes[$field] = implode(', ', array_keys($shortcode_array)); |
413 | 413 | } |
414 | 414 | $shortcodes = $codes; |
415 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
415 | + $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php'; |
|
416 | 416 | $form_template_args = array( |
417 | 417 | 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
418 | 418 | 'form_route' => 'newsletter_selected_send', |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | */ |
574 | 574 | protected function _registration_reports() |
575 | 575 | { |
576 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
576 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
577 | 577 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
578 | 578 | $template_path, |
579 | 579 | $this->_reports_template_data, |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | { |
596 | 596 | $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
597 | 597 | $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
598 | - $results = (array)$results; |
|
598 | + $results = (array) $results; |
|
599 | 599 | $regs = array(); |
600 | 600 | $subtitle = ''; |
601 | 601 | if ($results) { |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | $report_column_values = array(); |
606 | 606 | foreach ($result as $property_name => $property_value) { |
607 | 607 | $property_value = $property_name === 'Registration_REG_date' ? $property_value |
608 | - : (int)$property_value; |
|
608 | + : (int) $property_value; |
|
609 | 609 | $report_column_values[] = $property_value; |
610 | 610 | if ($tracker === 0) { |
611 | 611 | if ($property_name === 'Registration_REG_date') { |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | array_unshift($regs, $column_titles); |
623 | 623 | //setup the date range. |
624 | 624 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
625 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
625 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
626 | 626 | $ending_date = new DateTime("now", $DateTimeZone); |
627 | 627 | $subtitle = sprintf( |
628 | 628 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | '%sThere are currently no registration records in the last month for this report.%s', |
643 | 643 | 'event_espresso' |
644 | 644 | ), |
645 | - '<h2>' . $report_title . '</h2><p>', |
|
645 | + '<h2>'.$report_title.'</h2><p>', |
|
646 | 646 | '</p>' |
647 | 647 | ), |
648 | 648 | ); |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | { |
663 | 663 | $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
664 | 664 | $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
665 | - $results = (array)$results; |
|
665 | + $results = (array) $results; |
|
666 | 666 | $regs = array(); |
667 | 667 | $subtitle = ''; |
668 | 668 | if ($results) { |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | $property_value, |
676 | 676 | 4, |
677 | 677 | '...' |
678 | - ) : (int)$property_value; |
|
678 | + ) : (int) $property_value; |
|
679 | 679 | $report_column_values[] = $property_value; |
680 | 680 | if ($tracker === 0) { |
681 | 681 | if ($property_name === 'Registration_Event') { |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | array_unshift($regs, $column_titles); |
693 | 693 | //setup the date range. |
694 | 694 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
695 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
695 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
696 | 696 | $ending_date = new DateTime("now", $DateTimeZone); |
697 | 697 | $subtitle = sprintf( |
698 | 698 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | '%sThere are currently no registration records in the last month for this report.%s', |
713 | 713 | 'event_espresso' |
714 | 714 | ), |
715 | - '<h2>' . $report_title . '</h2><p>', |
|
715 | + '<h2>'.$report_title.'</h2><p>', |
|
716 | 716 | '</p>' |
717 | 717 | ), |
718 | 718 | ); |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | if ($datetime instanceof EE_Datetime) { |
763 | 763 | $datetime_label = $datetime->get_dtt_display_name(true); |
764 | 764 | $datetime_label .= ! empty($datetime_label) |
765 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
765 | + ? ' ('.$datetime->get_dtt_display_name().')' |
|
766 | 766 | : $datetime->get_dtt_display_name(); |
767 | 767 | } |
768 | 768 | $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | ) |
777 | 777 | : ''; |
778 | 778 | $datetime_link = ! empty($datetime_link) |
779 | - ? '<a href="' . $datetime_link . '">' |
|
779 | + ? '<a href="'.$datetime_link.'">' |
|
780 | 780 | . '<span id="checkin-dtt">' |
781 | 781 | . $datetime_label |
782 | 782 | . '</span></a>' |
@@ -788,8 +788,8 @@ discard block |
||
788 | 788 | ? $attendee->get_admin_details_link() |
789 | 789 | : ''; |
790 | 790 | $attendee_link = ! empty($attendee_link) |
791 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
792 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
791 | + ? '<a href="'.$attendee->get_admin_details_link().'"' |
|
792 | + . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">' |
|
793 | 793 | . '<span id="checkin-attendee-name">' |
794 | 794 | . $attendee_name |
795 | 795 | . '</span></a>' |
@@ -798,25 +798,25 @@ discard block |
||
798 | 798 | ? $registration->event()->get_admin_details_link() |
799 | 799 | : ''; |
800 | 800 | $event_link = ! empty($event_link) |
801 | - ? '<a href="' . $event_link . '"' |
|
802 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
801 | + ? '<a href="'.$event_link.'"' |
|
802 | + . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">' |
|
803 | 803 | . '<span id="checkin-event-name">' |
804 | 804 | . $registration->event_name() |
805 | 805 | . '</span>' |
806 | 806 | . '</a>' |
807 | 807 | : ''; |
808 | 808 | $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
809 | - ? '<h2>' . sprintf( |
|
809 | + ? '<h2>'.sprintf( |
|
810 | 810 | esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
811 | 811 | $attendee_link, |
812 | 812 | $datetime_link, |
813 | 813 | $event_link |
814 | - ) . '</h2>' |
|
814 | + ).'</h2>' |
|
815 | 815 | : ''; |
816 | 816 | $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
817 | - ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : ''; |
|
817 | + ? '<input type="hidden" name="_REGID" value="'.$reg_id.'">' : ''; |
|
818 | 818 | $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
819 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
819 | + ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : ''; |
|
820 | 820 | $this->display_admin_list_table_page_with_no_sidebar(); |
821 | 821 | } |
822 | 822 | |
@@ -852,7 +852,7 @@ discard block |
||
852 | 852 | //beautiful! Made it this far so let's get the status. |
853 | 853 | $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
854 | 854 | //setup new class to return via ajax |
855 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
855 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses(); |
|
856 | 856 | $this->_template_args['success'] = true; |
857 | 857 | $this->_return_json(); |
858 | 858 | } |
@@ -1059,37 +1059,37 @@ discard block |
||
1059 | 1059 | 'desc' => __('View All Check-in Records for this Registrant', 'event_espresso'), |
1060 | 1060 | ), |
1061 | 1061 | 'approved_status' => array( |
1062 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1062 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved, |
|
1063 | 1063 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
1064 | 1064 | ), |
1065 | 1065 | 'cancelled_status' => array( |
1066 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1066 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled, |
|
1067 | 1067 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
1068 | 1068 | ), |
1069 | 1069 | 'declined_status' => array( |
1070 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1070 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined, |
|
1071 | 1071 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
1072 | 1072 | ), |
1073 | 1073 | 'not_approved' => array( |
1074 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1074 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved, |
|
1075 | 1075 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
1076 | 1076 | ), |
1077 | 1077 | 'pending_status' => array( |
1078 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1078 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment, |
|
1079 | 1079 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
1080 | 1080 | ), |
1081 | 1081 | 'wait_list' => array( |
1082 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1082 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list, |
|
1083 | 1083 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
1084 | 1084 | ), |
1085 | 1085 | ); |
1086 | 1086 | $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
1087 | 1087 | $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
1088 | 1088 | $this->_template_args['before_list_table'] = ! empty($event_id) |
1089 | - ? '<h2>' . sprintf( |
|
1089 | + ? '<h2>'.sprintf( |
|
1090 | 1090 | __('Viewing Registrations for Event: %s', 'event_espresso'), |
1091 | 1091 | EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
1092 | - ) . '</h2>' |
|
1092 | + ).'</h2>' |
|
1093 | 1093 | : ''; |
1094 | 1094 | //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event. |
1095 | 1095 | /** @var EE_Event $event */ |
@@ -1108,7 +1108,7 @@ discard block |
||
1108 | 1108 | $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
1109 | 1109 | $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
1110 | 1110 | $this->_template_args['before_list_table'] .= $datetime->name(); |
1111 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1111 | + $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )'; |
|
1112 | 1112 | $this->_template_args['before_list_table'] .= '</span></h2>'; |
1113 | 1113 | } |
1114 | 1114 | //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column |
@@ -1175,11 +1175,11 @@ discard block |
||
1175 | 1175 | //normalize some request params that get setup by the parent `get_registrations` method. |
1176 | 1176 | $request = $this->_req_data; |
1177 | 1177 | $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
1178 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1179 | - if($trash){ |
|
1178 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1179 | + if ($trash) { |
|
1180 | 1180 | $request['status'] = 'trash'; |
1181 | 1181 | } |
1182 | - $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count ); |
|
1182 | + $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
1183 | 1183 | /** |
1184 | 1184 | * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
1185 | 1185 | * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
@@ -21,100 +21,100 @@ |
||
21 | 21 | class CheckinStatusDashicon |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var int $checkin_status |
|
26 | - */ |
|
27 | - private $checkin_status; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * CheckinStatusDashicon constructor. |
|
32 | - * |
|
33 | - * @param int $checkin_status |
|
34 | - */ |
|
35 | - public function __construct($checkin_status = EE_Checkin::status_checked_never) |
|
36 | - { |
|
37 | - $this->checkin_status = $checkin_status; |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @param EE_Checkin $checkin |
|
43 | - * @return CheckinStatusDashicon |
|
44 | - * @throws EE_Error |
|
45 | - */ |
|
46 | - public static function fromCheckin(EE_Checkin $checkin) |
|
47 | - { |
|
48 | - return new CheckinStatusDashicon( |
|
49 | - $checkin->status() |
|
50 | - ? EE_Checkin::status_checked_in |
|
51 | - : EE_Checkin::status_checked_out |
|
52 | - ); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param EE_Registration $registration |
|
58 | - * @param EE_Datetime $datetime |
|
59 | - * @return CheckinStatusDashicon |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public static function fromRegistrationAndDatetime(EE_Registration $registration, EE_Datetime $datetime) |
|
63 | - { |
|
64 | - return new CheckinStatusDashicon( |
|
65 | - $registration->check_in_status_for_datetime( |
|
66 | - $datetime->ID() |
|
67 | - ) |
|
68 | - ); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param EE_Registration $registration |
|
74 | - * @param int $DTT_ID |
|
75 | - * @return CheckinStatusDashicon |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public static function fromRegistrationAndDatetimeId(EE_Registration $registration, $DTT_ID = 0) |
|
79 | - { |
|
80 | - return new CheckinStatusDashicon( |
|
81 | - $registration->check_in_status_for_datetime( |
|
82 | - absint($DTT_ID) |
|
83 | - ) |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Will return the correct set of dashicon css classes for the set checkin status |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function cssClasses() |
|
93 | - { |
|
94 | - if ($this->checkin_status === EE_Checkin::status_checked_in) { |
|
95 | - return "ee-dashicons ee-icon-check-in checkin-icons checkedin-status-{$this->checkin_status}"; |
|
96 | - } |
|
97 | - if ($this->checkin_status === EE_Checkin::status_checked_out) { |
|
98 | - return "ee-dashicons ee-icon-check-out checkin-icons checkedin-status-{$this->checkin_status}"; |
|
99 | - } |
|
100 | - return "dashicons dashicons-no checkin-icons checkedin-status-{$this->checkin_status}"; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * returns a description for the Checkin Status Dashicon that can be used in List Table Legends |
|
105 | - * |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public function legendLabel() |
|
109 | - { |
|
110 | - if ($this->checkin_status === EE_Checkin::status_checked_in) { |
|
111 | - return esc_html__('This Registrant has been Checked In', 'event_espresso'); |
|
112 | - } |
|
113 | - if ($this->checkin_status === EE_Checkin::status_checked_out) { |
|
114 | - return esc_html__('This Registrant has been Checked Out', 'event_espresso'); |
|
115 | - } |
|
116 | - return esc_html__('No Check-in Record has been Created for this Registrant', 'event_espresso'); |
|
117 | - } |
|
24 | + /** |
|
25 | + * @var int $checkin_status |
|
26 | + */ |
|
27 | + private $checkin_status; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * CheckinStatusDashicon constructor. |
|
32 | + * |
|
33 | + * @param int $checkin_status |
|
34 | + */ |
|
35 | + public function __construct($checkin_status = EE_Checkin::status_checked_never) |
|
36 | + { |
|
37 | + $this->checkin_status = $checkin_status; |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @param EE_Checkin $checkin |
|
43 | + * @return CheckinStatusDashicon |
|
44 | + * @throws EE_Error |
|
45 | + */ |
|
46 | + public static function fromCheckin(EE_Checkin $checkin) |
|
47 | + { |
|
48 | + return new CheckinStatusDashicon( |
|
49 | + $checkin->status() |
|
50 | + ? EE_Checkin::status_checked_in |
|
51 | + : EE_Checkin::status_checked_out |
|
52 | + ); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param EE_Registration $registration |
|
58 | + * @param EE_Datetime $datetime |
|
59 | + * @return CheckinStatusDashicon |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public static function fromRegistrationAndDatetime(EE_Registration $registration, EE_Datetime $datetime) |
|
63 | + { |
|
64 | + return new CheckinStatusDashicon( |
|
65 | + $registration->check_in_status_for_datetime( |
|
66 | + $datetime->ID() |
|
67 | + ) |
|
68 | + ); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param EE_Registration $registration |
|
74 | + * @param int $DTT_ID |
|
75 | + * @return CheckinStatusDashicon |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public static function fromRegistrationAndDatetimeId(EE_Registration $registration, $DTT_ID = 0) |
|
79 | + { |
|
80 | + return new CheckinStatusDashicon( |
|
81 | + $registration->check_in_status_for_datetime( |
|
82 | + absint($DTT_ID) |
|
83 | + ) |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Will return the correct set of dashicon css classes for the set checkin status |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function cssClasses() |
|
93 | + { |
|
94 | + if ($this->checkin_status === EE_Checkin::status_checked_in) { |
|
95 | + return "ee-dashicons ee-icon-check-in checkin-icons checkedin-status-{$this->checkin_status}"; |
|
96 | + } |
|
97 | + if ($this->checkin_status === EE_Checkin::status_checked_out) { |
|
98 | + return "ee-dashicons ee-icon-check-out checkin-icons checkedin-status-{$this->checkin_status}"; |
|
99 | + } |
|
100 | + return "dashicons dashicons-no checkin-icons checkedin-status-{$this->checkin_status}"; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * returns a description for the Checkin Status Dashicon that can be used in List Table Legends |
|
105 | + * |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public function legendLabel() |
|
109 | + { |
|
110 | + if ($this->checkin_status === EE_Checkin::status_checked_in) { |
|
111 | + return esc_html__('This Registrant has been Checked In', 'event_espresso'); |
|
112 | + } |
|
113 | + if ($this->checkin_status === EE_Checkin::status_checked_out) { |
|
114 | + return esc_html__('This Registrant has been Checked Out', 'event_espresso'); |
|
115 | + } |
|
116 | + return esc_html__('No Check-in Record has been Created for this Registrant', 'event_espresso'); |
|
117 | + } |
|
118 | 118 | |
119 | 119 | |
120 | 120 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php 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 | - ); ?> |
|
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 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
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 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.048'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.048'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |