Completed
Branch dependabot/npm_and_yarn/wordpr... (bdc6c0)
by
unknown
87:38 queued 77:25
created
core/domain/services/event/EventSpacesCalculator.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@
 block discarded – undo
164 164
 
165 165
 
166 166
     /**
167
-     * @param $ticket
167
+     * @param \EE_Base_Class $ticket
168 168
      * @throws DomainException
169 169
      * @throws EE_Error
170 170
      * @throws UnexpectedEntityException
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
      */
175 175
     public function setActiveTickets(array $active_tickets = array())
176 176
     {
177
-        if (! empty($active_tickets)) {
177
+        if ( ! empty($active_tickets)) {
178 178
             foreach ($active_tickets as $active_ticket) {
179 179
                 $this->validateTicket($active_ticket);
180 180
             }
181 181
             // sort incoming array by ticket quantity (asc)
182 182
             usort(
183 183
                 $active_tickets,
184
-                function (EE_Ticket $a, EE_Ticket $b) {
184
+                function(EE_Ticket $a, EE_Ticket $b) {
185 185
                     if ($a->qty() === $b->qty()) {
186 186
                         return 0;
187 187
                     }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      */
204 204
     private function validateTicket($ticket)
205 205
     {
206
-        if (! $ticket instanceof EE_Ticket) {
206
+        if ( ! $ticket instanceof EE_Ticket) {
207 207
             throw new DomainException(
208 208
                 esc_html__(
209 209
                     'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.',
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
                 )
255 255
             );
256 256
         }
257
-        $this->datetimes[ $datetime->ID() ] = $datetime;
257
+        $this->datetimes[$datetime->ID()] = $datetime;
258 258
     }
259 259
 
260 260
 
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         $this->tickets_sold = array();
328 328
         $this->total_spaces = array();
329 329
         $active_tickets = $this->getActiveTickets();
330
-        if (! empty($active_tickets)) {
330
+        if ( ! empty($active_tickets)) {
331 331
             foreach ($active_tickets as $ticket) {
332 332
                 $this->validateTicket($ticket);
333 333
                 // we need to index our data arrays using strings for the purpose of sorting,
@@ -349,16 +349,16 @@  discard block
 block discarded – undo
349 349
                     // we are going to move all of our data into the following arrays:
350 350
                     // datetime spaces initially represents the reg limit for each datetime,
351 351
                     // but this will get adjusted as tickets are accounted for
352
-                    $this->datetime_spaces[ $datetime_identifier ] = $reg_limit;
352
+                    $this->datetime_spaces[$datetime_identifier] = $reg_limit;
353 353
                     // just an array of ticket IDs grouped by datetime
354
-                    $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier;
354
+                    $this->datetime_tickets[$datetime_identifier][] = $ticket_identifier;
355 355
                     // and an array of datetime IDs grouped by ticket
356
-                    $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier;
356
+                    $this->ticket_datetimes[$ticket_identifier][] = $datetime_identifier;
357 357
                 }
358 358
                 // total quantity of sold and reserved for each ticket
359
-                $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved();
359
+                $this->tickets_sold[$ticket_identifier] = $ticket->sold() + $ticket->reserved();
360 360
                 // and the maximum ticket quantities for each ticket (adjusted for reg limit)
361
-                $this->ticket_quantities[ $ticket_identifier ] = $max_tickets;
361
+                $this->ticket_quantities[$ticket_identifier] = $max_tickets;
362 362
             }
363 363
         }
364 364
         // sort datetime spaces by reg limit, but maintain our string indexes
@@ -417,11 +417,11 @@  discard block
 block discarded – undo
417 417
             \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
418 418
         }
419 419
         foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) {
420
-            if (isset($this->ticket_quantities[ $ticket_identifier ])) {
421
-                $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold;
420
+            if (isset($this->ticket_quantities[$ticket_identifier])) {
421
+                $this->ticket_quantities[$ticket_identifier] -= $tickets_sold;
422 422
                 // don't let values go below zero
423
-                $this->ticket_quantities[ $ticket_identifier ] = max(
424
-                    $this->ticket_quantities[ $ticket_identifier ],
423
+                $this->ticket_quantities[$ticket_identifier] = max(
424
+                    $this->ticket_quantities[$ticket_identifier],
425 425
                     0
426 426
                 );
427 427
                 if ($this->debug) {
@@ -433,15 +433,15 @@  discard block
 block discarded – undo
433 433
                     );
434 434
                 }
435 435
             }
436
-            if (isset($this->ticket_datetimes[ $ticket_identifier ])
437
-                && is_array($this->ticket_datetimes[ $ticket_identifier ])
436
+            if (isset($this->ticket_datetimes[$ticket_identifier])
437
+                && is_array($this->ticket_datetimes[$ticket_identifier])
438 438
             ) {
439
-                foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) {
440
-                    if (isset($this->ticket_quantities[ $ticket_identifier ])) {
441
-                        $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold;
439
+                foreach ($this->ticket_datetimes[$ticket_identifier] as $ticket_datetime) {
440
+                    if (isset($this->ticket_quantities[$ticket_identifier])) {
441
+                        $this->datetime_spaces[$ticket_datetime] -= $tickets_sold;
442 442
                         // don't let values go below zero
443
-                        $this->datetime_spaces[ $ticket_datetime ] = max(
444
-                            $this->datetime_spaces[ $ticket_datetime ],
443
+                        $this->datetime_spaces[$ticket_datetime] = max(
444
+                            $this->datetime_spaces[$ticket_datetime],
445 445
                             0
446 446
                         );
447 447
                         if ($this->debug) {
@@ -466,11 +466,11 @@  discard block
 block discarded – undo
466 466
     private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets)
467 467
     {
468 468
         // make sure a reg limit is set for the datetime
469
-        $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ])
470
-            ? $this->datetime_spaces[ $datetime_identifier ]
469
+        $reg_limit = isset($this->datetime_spaces[$datetime_identifier])
470
+            ? $this->datetime_spaces[$datetime_identifier]
471 471
             : 0;
472 472
         // and bail if it is not
473
-        if (! $reg_limit) {
473
+        if ( ! $reg_limit) {
474 474
             if ($this->debug) {
475 475
                 \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__);
476 476
             }
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
         }
488 488
         // number of allocated spaces always starts at zero
489 489
         $spaces_allocated = 0;
490
-        $this->total_spaces[ $datetime_identifier ] = 0;
490
+        $this->total_spaces[$datetime_identifier] = 0;
491 491
         foreach ($tickets as $ticket_identifier) {
492 492
             $spaces_allocated = $this->calculateAvailableSpacesForTicket(
493 493
                 $datetime_identifier,
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
         $spaces_allocated = max($spaces_allocated, 0);
501 501
         if ($spaces_allocated) {
502 502
             // track any non-zero values
503
-            $this->total_spaces[ $datetime_identifier ] += $spaces_allocated;
503
+            $this->total_spaces[$datetime_identifier] += $spaces_allocated;
504 504
             if ($this->debug) {
505 505
                 \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__);
506 506
             }
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
         }
512 512
         if ($this->debug) {
513 513
             \EEH_Debug_Tools::printr(
514
-                $this->total_spaces[ $datetime_identifier ],
514
+                $this->total_spaces[$datetime_identifier],
515 515
                 '$total_spaces',
516 516
                 __FILE__,
517 517
                 __LINE__
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
         $spaces_allocated
537 537
     ) {
538 538
         // make sure ticket quantity is set
539
-        $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ])
540
-            ? $this->ticket_quantities[ $ticket_identifier ]
539
+        $ticket_quantity = isset($this->ticket_quantities[$ticket_identifier])
540
+            ? $this->ticket_quantities[$ticket_identifier]
541 541
             : 0;
542 542
         if ($this->debug) {
543 543
             \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__);
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
                 //  or the maximum ticket quantity
568 568
                 $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity);
569 569
                 // adjust the available quantity in our tracking array
570
-                $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity;
570
+                $this->ticket_quantities[$ticket_identifier] -= $ticket_quantity;
571 571
                 // and increment spaces allocated for this datetime
572 572
                 $spaces_allocated += $ticket_quantity;
573 573
                 $at_capacity = $spaces_allocated >= $reg_limit;
@@ -624,14 +624,14 @@  discard block
 block discarded – undo
624 624
                 $ticket_quantity
625 625
             );
626 626
             // skip to next ticket if nothing changed
627
-            if (! ($adjusted || $at_capacity)) {
627
+            if ( ! ($adjusted || $at_capacity)) {
628 628
                 continue;
629 629
             }
630 630
             // then all of it's tickets are now unavailable
631 631
             foreach ($datetime_tickets as $datetime_ticket) {
632 632
                 if (($ticket_identifier === $datetime_ticket || $at_capacity)
633
-                    && isset($this->ticket_quantities[ $datetime_ticket ])
634
-                    && $this->ticket_quantities[ $datetime_ticket ] > 0
633
+                    && isset($this->ticket_quantities[$datetime_ticket])
634
+                    && $this->ticket_quantities[$datetime_ticket] > 0
635 635
                 ) {
636 636
                     if ($this->debug) {
637 637
                         \EEH_Debug_Tools::printr(
@@ -645,14 +645,14 @@  discard block
 block discarded – undo
645 645
                     // otherwise just subtract the ticket quantity
646 646
                     $new_quantity = $at_capacity
647 647
                         ? 0
648
-                        : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity;
648
+                        : $this->ticket_quantities[$datetime_ticket] - $ticket_quantity;
649 649
                     // don't let ticket quantity go below zero
650
-                    $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0);
650
+                    $this->ticket_quantities[$datetime_ticket] = max($new_quantity, 0);
651 651
                     if ($this->debug) {
652 652
                         \EEH_Debug_Tools::printr(
653 653
                             $at_capacity
654 654
                                 ? "0 because Datetime {$datetime_identifier} is at capacity"
655
-                                : "{$this->ticket_quantities[ $datetime_ticket ]}",
655
+                                : "{$this->ticket_quantities[$datetime_ticket]}",
656 656
                             " . . . . {$datetime_ticket} quantity set to ",
657 657
                             __FILE__,
658 658
                             __LINE__
@@ -661,8 +661,8 @@  discard block
 block discarded – undo
661 661
                 }
662 662
                 // but we also need to adjust spaces for any other datetimes this ticket has access to
663 663
                 if ($datetime_ticket === $ticket_identifier) {
664
-                    if (isset($this->ticket_datetimes[ $datetime_ticket ])
665
-                        && is_array($this->ticket_datetimes[ $datetime_ticket ])
664
+                    if (isset($this->ticket_datetimes[$datetime_ticket])
665
+                        && is_array($this->ticket_datetimes[$datetime_ticket])
666 666
                     ) {
667 667
                         if ($this->debug) {
668 668
                             \EEH_Debug_Tools::printr(
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
                                 __LINE__
673 673
                             );
674 674
                         }
675
-                        foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) {
675
+                        foreach ($this->ticket_datetimes[$datetime_ticket] as $datetime) {
676 676
                             // don't adjust the current datetime twice
677 677
                             if ($datetime !== $datetime_identifier) {
678 678
                                 $this->adjustDatetimeSpaces(
@@ -692,24 +692,24 @@  discard block
 block discarded – undo
692 692
     {
693 693
         // does datetime have spaces available?
694 694
         // and does the supplied ticket have access to this datetime ?
695
-        if ($this->datetime_spaces[ $datetime_identifier ] > 0
696
-            && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ])
697
-            && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true)
695
+        if ($this->datetime_spaces[$datetime_identifier] > 0
696
+            && isset($this->datetime_spaces[$datetime_identifier], $this->datetime_tickets[$datetime_identifier])
697
+            && in_array($ticket_identifier, $this->datetime_tickets[$datetime_identifier], true)
698 698
         ) {
699 699
             if ($this->debug) {
700 700
                 \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__);
701 701
                 \EEH_Debug_Tools::printr(
702
-                    "{$this->datetime_spaces[ $datetime_identifier ]}",
702
+                    "{$this->datetime_spaces[$datetime_identifier]}",
703 703
                     " . . current  {$datetime_identifier} spaces available",
704 704
                     __FILE__,
705 705
                     __LINE__
706 706
                 );
707 707
             }
708 708
             // then decrement the available spaces for the datetime
709
-            $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity;
709
+            $this->datetime_spaces[$datetime_identifier] -= $ticket_quantity;
710 710
             // but don't let quantities go below zero
711
-            $this->datetime_spaces[ $datetime_identifier ] = max(
712
-                $this->datetime_spaces[ $datetime_identifier ],
711
+            $this->datetime_spaces[$datetime_identifier] = max(
712
+                $this->datetime_spaces[$datetime_identifier],
713 713
                 0
714 714
             );
715 715
             if ($this->debug) {
Please login to merge, or discard this patch.
Indentation   +711 added lines, -711 removed lines patch added patch discarded remove patch
@@ -26,715 +26,715 @@
 block discarded – undo
26 26
 class EventSpacesCalculator
27 27
 {
28 28
 
29
-    /**
30
-     * @var EE_Event $event
31
-     */
32
-    private $event;
33
-
34
-    /**
35
-     * @var array $datetime_query_params
36
-     */
37
-    private $datetime_query_params;
38
-
39
-    /**
40
-     * @var EE_Ticket[] $active_tickets
41
-     */
42
-    private $active_tickets = array();
43
-
44
-    /**
45
-     * @var EE_Datetime[] $datetimes
46
-     */
47
-    private $datetimes = array();
48
-
49
-    /**
50
-     * Array of Ticket IDs grouped by Datetime
51
-     *
52
-     * @var array $datetimes
53
-     */
54
-    private $datetime_tickets = array();
55
-
56
-    /**
57
-     * Max spaces for each Datetime (reg limit - previous sold)
58
-     *
59
-     * @var array $datetime_spaces
60
-     */
61
-    private $datetime_spaces = array();
62
-
63
-    /**
64
-     * Array of Datetime IDs grouped by Ticket
65
-     *
66
-     * @var array[] $ticket_datetimes
67
-     */
68
-    private $ticket_datetimes = array();
69
-
70
-    /**
71
-     * maximum ticket quantities for each ticket (adjusted for reg limit)
72
-     *
73
-     * @var array $ticket_quantities
74
-     */
75
-    private $ticket_quantities = array();
76
-
77
-    /**
78
-     * total quantity of sold and reserved for each ticket
79
-     *
80
-     * @var array $tickets_sold
81
-     */
82
-    private $tickets_sold = array();
83
-
84
-    /**
85
-     * total spaces available across all datetimes
86
-     *
87
-     * @var array $total_spaces
88
-     */
89
-    private $total_spaces = array();
90
-
91
-    /**
92
-     * @var boolean $debug
93
-     */
94
-    private $debug = false; // true false
95
-
96
-    /**
97
-     * @var null|int $spaces_remaining
98
-     */
99
-    private $spaces_remaining;
100
-
101
-    /**
102
-     * @var null|int $total_spaces_available
103
-     */
104
-    private $total_spaces_available;
105
-
106
-
107
-    /**
108
-     * EventSpacesCalculator constructor.
109
-     *
110
-     * @param EE_Event $event
111
-     * @param array    $datetime_query_params
112
-     * @throws EE_Error
113
-     */
114
-    public function __construct(EE_Event $event, array $datetime_query_params = array())
115
-    {
116
-        if ($this->debug) {
117
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1);
118
-            \EEH_Debug_Tools::printr((string) $event->ID(), 'For event', __FILE__, __LINE__);
119
-        }
120
-        $this->event = $event;
121
-        $this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC'));
122
-        $this->setHooks();
123
-    }
124
-
125
-
126
-    /**
127
-     * @return void
128
-     */
129
-    private function setHooks()
130
-    {
131
-        add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults'));
132
-        add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults'));
133
-        add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults'));
134
-        add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults'));
135
-        add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults'));
136
-        add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults'));
137
-        add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults'));
138
-        add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults'));
139
-    }
140
-
141
-
142
-    /**
143
-     * @return void
144
-     */
145
-    public function clearResults()
146
-    {
147
-        if ($this->debug) {
148
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1);
149
-        }
150
-        $this->spaces_remaining = null;
151
-        $this->total_spaces_available = null;
152
-    }
153
-
154
-
155
-    /**
156
-     * @return EE_Ticket[]
157
-     * @throws EE_Error
158
-     * @throws InvalidDataTypeException
159
-     * @throws InvalidInterfaceException
160
-     * @throws InvalidArgumentException
161
-     */
162
-    public function getActiveTickets()
163
-    {
164
-        if (empty($this->active_tickets)) {
165
-            $this->active_tickets = $this->event->tickets(
166
-                array(
167
-                    array('TKT_deleted' => false),
168
-                    'order_by' => array('TKT_qty' => 'ASC'),
169
-                )
170
-            );
171
-        }
172
-        return $this->active_tickets;
173
-    }
174
-
175
-
176
-    /**
177
-     * @param EE_Ticket[] $active_tickets
178
-     * @throws EE_Error
179
-     * @throws DomainException
180
-     * @throws UnexpectedEntityException
181
-     */
182
-    public function setActiveTickets(array $active_tickets = array())
183
-    {
184
-        if (! empty($active_tickets)) {
185
-            foreach ($active_tickets as $active_ticket) {
186
-                $this->validateTicket($active_ticket);
187
-            }
188
-            // sort incoming array by ticket quantity (asc)
189
-            usort(
190
-                $active_tickets,
191
-                function (EE_Ticket $a, EE_Ticket $b) {
192
-                    if ($a->qty() === $b->qty()) {
193
-                        return 0;
194
-                    }
195
-                    return ($a->qty() < $b->qty())
196
-                        ? -1
197
-                        : 1;
198
-                }
199
-            );
200
-        }
201
-        $this->active_tickets = $active_tickets;
202
-    }
203
-
204
-
205
-    /**
206
-     * @param $ticket
207
-     * @throws DomainException
208
-     * @throws EE_Error
209
-     * @throws UnexpectedEntityException
210
-     */
211
-    private function validateTicket($ticket)
212
-    {
213
-        if (! $ticket instanceof EE_Ticket) {
214
-            throw new DomainException(
215
-                esc_html__(
216
-                    'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.',
217
-                    'event_espresso'
218
-                )
219
-            );
220
-        }
221
-        if ($ticket->get_event_ID() !== $this->event->ID()) {
222
-            throw new DomainException(
223
-                sprintf(
224
-                    esc_html__(
225
-                        'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.',
226
-                        'event_espresso'
227
-                    ),
228
-                    $ticket->get_event_ID(),
229
-                    $this->event->ID()
230
-                )
231
-            );
232
-        }
233
-    }
234
-
235
-
236
-    /**
237
-     * @return EE_Datetime[]
238
-     */
239
-    public function getDatetimes()
240
-    {
241
-        return $this->datetimes;
242
-    }
243
-
244
-
245
-    /**
246
-     * @param EE_Datetime $datetime
247
-     * @throws EE_Error
248
-     * @throws DomainException
249
-     */
250
-    public function setDatetime(EE_Datetime $datetime)
251
-    {
252
-        if ($datetime->event()->ID() !== $this->event->ID()) {
253
-            throw new DomainException(
254
-                sprintf(
255
-                    esc_html__(
256
-                        'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.',
257
-                        'event_espresso'
258
-                    ),
259
-                    $datetime->event()->ID(),
260
-                    $this->event->ID()
261
-                )
262
-            );
263
-        }
264
-        $this->datetimes[ $datetime->ID() ] = $datetime;
265
-    }
266
-
267
-
268
-    /**
269
-     * calculate spaces remaining based on "saleable" tickets
270
-     *
271
-     * @return float|int
272
-     * @throws EE_Error
273
-     * @throws DomainException
274
-     * @throws UnexpectedEntityException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     * @throws InvalidArgumentException
278
-     */
279
-    public function spacesRemaining()
280
-    {
281
-        if ($this->debug) {
282
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
283
-        }
284
-        if ($this->spaces_remaining === null) {
285
-            $this->initialize();
286
-            $this->spaces_remaining = $this->calculate();
287
-        }
288
-        return $this->spaces_remaining;
289
-    }
290
-
291
-
292
-    /**
293
-     * calculates total available spaces for an event with no regard for sold tickets
294
-     *
295
-     * @return int|float
296
-     * @throws EE_Error
297
-     * @throws DomainException
298
-     * @throws UnexpectedEntityException
299
-     * @throws InvalidDataTypeException
300
-     * @throws InvalidInterfaceException
301
-     * @throws InvalidArgumentException
302
-     */
303
-    public function totalSpacesAvailable()
304
-    {
305
-        if ($this->debug) {
306
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
307
-        }
308
-        if ($this->total_spaces_available === null) {
309
-            $this->initialize();
310
-            $this->total_spaces_available = $this->calculate(false);
311
-        }
312
-        return $this->total_spaces_available;
313
-    }
314
-
315
-
316
-    /**
317
-     * Loops through the active tickets for the event
318
-     * and builds a series of data arrays that will be used for calculating
319
-     * the total maximum available spaces, as well as the spaces remaining.
320
-     * Because ticket quantities affect datetime spaces and vice versa,
321
-     * we need to be constantly updating these data arrays as things change,
322
-     * which is the entire reason for their existence.
323
-     *
324
-     * @throws EE_Error
325
-     * @throws DomainException
326
-     * @throws UnexpectedEntityException
327
-     * @throws InvalidDataTypeException
328
-     * @throws InvalidInterfaceException
329
-     * @throws InvalidArgumentException
330
-     */
331
-    private function initialize()
332
-    {
333
-        if ($this->debug) {
334
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
335
-        }
336
-        $this->datetime_tickets = array();
337
-        $this->datetime_spaces = array();
338
-        $this->ticket_datetimes = array();
339
-        $this->ticket_quantities = array();
340
-        $this->tickets_sold = array();
341
-        $this->total_spaces = array();
342
-        $active_tickets = $this->getActiveTickets();
343
-        if (! empty($active_tickets)) {
344
-            foreach ($active_tickets as $ticket) {
345
-                $this->validateTicket($ticket);
346
-                // we need to index our data arrays using strings for the purpose of sorting,
347
-                // but we also need them to be unique, so  we'll just prepend a letter T to the ID
348
-                $ticket_identifier = "T{$ticket->ID()}";
349
-                // to start, we'll just consider the raw qty to be the maximum availability for this ticket,
350
-                // unless the ticket is past its "sell until" date, in which case the qty will be 0
351
-                $max_tickets = $ticket->is_expired() ? 0 : $ticket->qty();
352
-                // but we'll adjust that after looping over each datetime for the ticket and checking reg limits
353
-                $ticket_datetimes = $ticket->datetimes($this->datetime_query_params);
354
-                foreach ($ticket_datetimes as $datetime) {
355
-                    // save all datetimes
356
-                    $this->setDatetime($datetime);
357
-                    $datetime_identifier = "D{$datetime->ID()}";
358
-                    $reg_limit = $datetime->reg_limit();
359
-                    // ticket quantity can not exceed datetime reg limit
360
-                    $max_tickets = min($max_tickets, $reg_limit);
361
-                    // as described earlier, because we need to be able to constantly adjust numbers for things,
362
-                    // we are going to move all of our data into the following arrays:
363
-                    // datetime spaces initially represents the reg limit for each datetime,
364
-                    // but this will get adjusted as tickets are accounted for
365
-                    $this->datetime_spaces[ $datetime_identifier ] = $reg_limit;
366
-                    // just an array of ticket IDs grouped by datetime
367
-                    $this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier;
368
-                    // and an array of datetime IDs grouped by ticket
369
-                    $this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier;
370
-                }
371
-                // total quantity of sold and reserved for each ticket
372
-                $this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved();
373
-                // and the maximum ticket quantities for each ticket (adjusted for reg limit)
374
-                $this->ticket_quantities[ $ticket_identifier ] = $max_tickets;
375
-            }
376
-        }
377
-        // sort datetime spaces by reg limit, but maintain our string indexes
378
-        asort($this->datetime_spaces, SORT_NUMERIC);
379
-        // datetime tickets need to be sorted in the SAME order as the above array...
380
-        // so we'll just use array_merge() to take the structure of datetime_spaces
381
-        // but overwrite all of the data with that from datetime_tickets
382
-        $this->datetime_tickets = array_merge(
383
-            $this->datetime_spaces,
384
-            $this->datetime_tickets
385
-        );
386
-        if ($this->debug) {
387
-            \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__);
388
-            \EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__);
389
-            \EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__);
390
-        }
391
-    }
392
-
393
-
394
-    /**
395
-     * performs calculations on initialized data
396
-     *
397
-     * @param bool $consider_sold
398
-     * @return int|float
399
-     */
400
-    private function calculate($consider_sold = true)
401
-    {
402
-        if ($this->debug) {
403
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
404
-            \EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__);
405
-        }
406
-        if ($consider_sold) {
407
-            // subtract amounts sold from all ticket quantities and datetime spaces
408
-            $this->adjustTicketQuantitiesDueToSales();
409
-        }
410
-        foreach ($this->datetime_tickets as $datetime_identifier => $tickets) {
411
-            $this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets);
412
-        }
413
-        // total spaces available is just the sum of the spaces available for each datetime
414
-        $spaces_remaining = array_sum($this->total_spaces);
415
-        if ($this->debug) {
416
-            \EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__);
417
-            \EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__);
418
-            \EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__);
419
-        }
420
-        return $spaces_remaining;
421
-    }
422
-
423
-
424
-    /**
425
-     * subtracts amount of  tickets sold from ticket quantities and datetime spaces
426
-     */
427
-    private function adjustTicketQuantitiesDueToSales()
428
-    {
429
-        if ($this->debug) {
430
-            \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
431
-        }
432
-        foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) {
433
-            if (isset($this->ticket_quantities[ $ticket_identifier ])) {
434
-                $this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold;
435
-                // don't let values go below zero
436
-                $this->ticket_quantities[ $ticket_identifier ] = max(
437
-                    $this->ticket_quantities[ $ticket_identifier ],
438
-                    0
439
-                );
440
-                if ($this->debug) {
441
-                    \EEH_Debug_Tools::printr(
442
-                        "{$tickets_sold} sales for ticket {$ticket_identifier} ",
443
-                        'subtracting',
444
-                        __FILE__,
445
-                        __LINE__
446
-                    );
447
-                }
448
-            }
449
-            if (isset($this->ticket_datetimes[ $ticket_identifier ])
450
-                && is_array($this->ticket_datetimes[ $ticket_identifier ])
451
-            ) {
452
-                foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) {
453
-                    if (isset($this->ticket_quantities[ $ticket_identifier ])) {
454
-                        $this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold;
455
-                        // don't let values go below zero
456
-                        $this->datetime_spaces[ $ticket_datetime ] = max(
457
-                            $this->datetime_spaces[ $ticket_datetime ],
458
-                            0
459
-                        );
460
-                        if ($this->debug) {
461
-                            \EEH_Debug_Tools::printr(
462
-                                "{$tickets_sold} sales for datetime {$ticket_datetime} ",
463
-                                'subtracting',
464
-                                __FILE__,
465
-                                __LINE__
466
-                            );
467
-                        }
468
-                    }
469
-                }
470
-            }
471
-        }
472
-    }
473
-
474
-
475
-    /**
476
-     * @param string $datetime_identifier
477
-     * @param array  $tickets
478
-     */
479
-    private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets)
480
-    {
481
-        // make sure a reg limit is set for the datetime
482
-        $reg_limit = isset($this->datetime_spaces[ $datetime_identifier ])
483
-            ? $this->datetime_spaces[ $datetime_identifier ]
484
-            : 0;
485
-        // and bail if it is not
486
-        if (! $reg_limit) {
487
-            if ($this->debug) {
488
-                \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__);
489
-            }
490
-            return;
491
-        }
492
-        if ($this->debug) {
493
-            \EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1);
494
-            \EEH_Debug_Tools::printr(
495
-                "{$reg_limit}",
496
-                'REG LIMIT',
497
-                __FILE__,
498
-                __LINE__
499
-            );
500
-        }
501
-        // number of allocated spaces always starts at zero
502
-        $spaces_allocated = 0;
503
-        $this->total_spaces[ $datetime_identifier ] = 0;
504
-        foreach ($tickets as $ticket_identifier) {
505
-            $spaces_allocated = $this->calculateAvailableSpacesForTicket(
506
-                $datetime_identifier,
507
-                $reg_limit,
508
-                $ticket_identifier,
509
-                $spaces_allocated
510
-            );
511
-        }
512
-        // spaces can't be negative
513
-        $spaces_allocated = max($spaces_allocated, 0);
514
-        if ($spaces_allocated) {
515
-            // track any non-zero values
516
-            $this->total_spaces[ $datetime_identifier ] += $spaces_allocated;
517
-            if ($this->debug) {
518
-                \EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__);
519
-            }
520
-        } else {
521
-            if ($this->debug) {
522
-                \EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__);
523
-            }
524
-        }
525
-        if ($this->debug) {
526
-            \EEH_Debug_Tools::printr(
527
-                $this->total_spaces[ $datetime_identifier ],
528
-                '$total_spaces',
529
-                __FILE__,
530
-                __LINE__
531
-            );
532
-            \EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__);
533
-            \EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__);
534
-        }
535
-    }
536
-
537
-
538
-    /**
539
-     * @param string $datetime_identifier
540
-     * @param int    $reg_limit
541
-     * @param string $ticket_identifier
542
-     * @param int    $spaces_allocated
543
-     * @return int
544
-     */
545
-    private function calculateAvailableSpacesForTicket(
546
-        $datetime_identifier,
547
-        $reg_limit,
548
-        $ticket_identifier,
549
-        $spaces_allocated
550
-    ) {
551
-        // make sure ticket quantity is set
552
-        $ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ])
553
-            ? $this->ticket_quantities[ $ticket_identifier ]
554
-            : 0;
555
-        if ($this->debug) {
556
-            \EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__);
557
-            \EEH_Debug_Tools::printr(
558
-                "{$ticket_quantity}",
559
-                "ticket $ticket_identifier quantity: ",
560
-                __FILE__,
561
-                __LINE__,
562
-                2
563
-            );
564
-        }
565
-        if ($ticket_quantity) {
566
-            if ($this->debug) {
567
-                \EEH_Debug_Tools::printr(
568
-                    ($spaces_allocated <= $reg_limit)
569
-                        ? 'true'
570
-                        : 'false',
571
-                    ' . spaces_allocated <= reg_limit = ',
572
-                    __FILE__,
573
-                    __LINE__
574
-                );
575
-            }
576
-            // if the datetime is NOT at full capacity yet
577
-            if ($spaces_allocated <= $reg_limit) {
578
-                // then the maximum ticket quantity we can allocate is the lowest value of either:
579
-                //  the number of remaining spaces for the datetime, which is the limit - spaces already taken
580
-                //  or the maximum ticket quantity
581
-                $ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity);
582
-                // adjust the available quantity in our tracking array
583
-                $this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity;
584
-                // and increment spaces allocated for this datetime
585
-                $spaces_allocated += $ticket_quantity;
586
-                $at_capacity = $spaces_allocated >= $reg_limit;
587
-                if ($this->debug) {
588
-                    \EEH_Debug_Tools::printr(
589
-                        "{$ticket_quantity} {$ticket_identifier} tickets",
590
-                        ' > > allocate ',
591
-                        __FILE__,
592
-                        __LINE__,
593
-                        3
594
-                    );
595
-                    if ($at_capacity) {
596
-                        \EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3);
597
-                    }
598
-                }
599
-                // now adjust all other datetimes that allow access to this ticket
600
-                $this->adjustDatetimes(
601
-                    $datetime_identifier,
602
-                    $ticket_identifier,
603
-                    $ticket_quantity,
604
-                    $at_capacity
605
-                );
606
-            }
607
-        }
608
-        return $spaces_allocated;
609
-    }
610
-
611
-
612
-    /**
613
-     * subtracts ticket amounts from all datetime reg limits
614
-     * that allow access to the ticket specified,
615
-     * because that ticket could be used
616
-     * to attend any of the datetimes it has access to
617
-     *
618
-     * @param string $datetime_identifier
619
-     * @param string $ticket_identifier
620
-     * @param bool   $at_capacity
621
-     * @param int    $ticket_quantity
622
-     */
623
-    private function adjustDatetimes(
624
-        $datetime_identifier,
625
-        $ticket_identifier,
626
-        $ticket_quantity,
627
-        $at_capacity
628
-    ) {
629
-        /** @var array $datetime_tickets */
630
-        foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) {
631
-            if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) {
632
-                continue;
633
-            }
634
-            $adjusted = $this->adjustDatetimeSpaces(
635
-                $datetime_ID,
636
-                $ticket_identifier,
637
-                $ticket_quantity
638
-            );
639
-            // skip to next ticket if nothing changed
640
-            if (! ($adjusted || $at_capacity)) {
641
-                continue;
642
-            }
643
-            // then all of it's tickets are now unavailable
644
-            foreach ($datetime_tickets as $datetime_ticket) {
645
-                if (($ticket_identifier === $datetime_ticket || $at_capacity)
646
-                    && isset($this->ticket_quantities[ $datetime_ticket ])
647
-                    && $this->ticket_quantities[ $datetime_ticket ] > 0
648
-                ) {
649
-                    if ($this->debug) {
650
-                        \EEH_Debug_Tools::printr(
651
-                            $datetime_ticket,
652
-                            ' . . . adjust ticket quantities for',
653
-                            __FILE__,
654
-                            __LINE__
655
-                        );
656
-                    }
657
-                    // if this datetime is at full capacity, set any tracked available quantities to zero
658
-                    // otherwise just subtract the ticket quantity
659
-                    $new_quantity = $at_capacity
660
-                        ? 0
661
-                        : $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity;
662
-                    // don't let ticket quantity go below zero
663
-                    $this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0);
664
-                    if ($this->debug) {
665
-                        \EEH_Debug_Tools::printr(
666
-                            $at_capacity
667
-                                ? "0 because Datetime {$datetime_identifier} is at capacity"
668
-                                : "{$this->ticket_quantities[ $datetime_ticket ]}",
669
-                            " . . . . {$datetime_ticket} quantity set to ",
670
-                            __FILE__,
671
-                            __LINE__
672
-                        );
673
-                    }
674
-                }
675
-                // but we also need to adjust spaces for any other datetimes this ticket has access to
676
-                if ($datetime_ticket === $ticket_identifier) {
677
-                    if (isset($this->ticket_datetimes[ $datetime_ticket ])
678
-                        && is_array($this->ticket_datetimes[ $datetime_ticket ])
679
-                    ) {
680
-                        if ($this->debug) {
681
-                            \EEH_Debug_Tools::printr(
682
-                                $datetime_ticket,
683
-                                ' . . adjust other Datetimes for',
684
-                                __FILE__,
685
-                                __LINE__
686
-                            );
687
-                        }
688
-                        foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) {
689
-                            // don't adjust the current datetime twice
690
-                            if ($datetime !== $datetime_identifier) {
691
-                                $this->adjustDatetimeSpaces(
692
-                                    $datetime,
693
-                                    $datetime_ticket,
694
-                                    $ticket_quantity
695
-                                );
696
-                            }
697
-                        }
698
-                    }
699
-                }
700
-            }
701
-        }
702
-    }
703
-
704
-    private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0)
705
-    {
706
-        // does datetime have spaces available?
707
-        // and does the supplied ticket have access to this datetime ?
708
-        if ($this->datetime_spaces[ $datetime_identifier ] > 0
709
-            && isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ])
710
-            && in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true)
711
-        ) {
712
-            if ($this->debug) {
713
-                \EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__);
714
-                \EEH_Debug_Tools::printr(
715
-                    "{$this->datetime_spaces[ $datetime_identifier ]}",
716
-                    " . . current  {$datetime_identifier} spaces available",
717
-                    __FILE__,
718
-                    __LINE__
719
-                );
720
-            }
721
-            // then decrement the available spaces for the datetime
722
-            $this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity;
723
-            // but don't let quantities go below zero
724
-            $this->datetime_spaces[ $datetime_identifier ] = max(
725
-                $this->datetime_spaces[ $datetime_identifier ],
726
-                0
727
-            );
728
-            if ($this->debug) {
729
-                \EEH_Debug_Tools::printr(
730
-                    "{$ticket_quantity}",
731
-                    " . . . {$datetime_identifier} capacity reduced by",
732
-                    __FILE__,
733
-                    __LINE__
734
-                );
735
-            }
736
-            return true;
737
-        }
738
-        return false;
739
-    }
29
+	/**
30
+	 * @var EE_Event $event
31
+	 */
32
+	private $event;
33
+
34
+	/**
35
+	 * @var array $datetime_query_params
36
+	 */
37
+	private $datetime_query_params;
38
+
39
+	/**
40
+	 * @var EE_Ticket[] $active_tickets
41
+	 */
42
+	private $active_tickets = array();
43
+
44
+	/**
45
+	 * @var EE_Datetime[] $datetimes
46
+	 */
47
+	private $datetimes = array();
48
+
49
+	/**
50
+	 * Array of Ticket IDs grouped by Datetime
51
+	 *
52
+	 * @var array $datetimes
53
+	 */
54
+	private $datetime_tickets = array();
55
+
56
+	/**
57
+	 * Max spaces for each Datetime (reg limit - previous sold)
58
+	 *
59
+	 * @var array $datetime_spaces
60
+	 */
61
+	private $datetime_spaces = array();
62
+
63
+	/**
64
+	 * Array of Datetime IDs grouped by Ticket
65
+	 *
66
+	 * @var array[] $ticket_datetimes
67
+	 */
68
+	private $ticket_datetimes = array();
69
+
70
+	/**
71
+	 * maximum ticket quantities for each ticket (adjusted for reg limit)
72
+	 *
73
+	 * @var array $ticket_quantities
74
+	 */
75
+	private $ticket_quantities = array();
76
+
77
+	/**
78
+	 * total quantity of sold and reserved for each ticket
79
+	 *
80
+	 * @var array $tickets_sold
81
+	 */
82
+	private $tickets_sold = array();
83
+
84
+	/**
85
+	 * total spaces available across all datetimes
86
+	 *
87
+	 * @var array $total_spaces
88
+	 */
89
+	private $total_spaces = array();
90
+
91
+	/**
92
+	 * @var boolean $debug
93
+	 */
94
+	private $debug = false; // true false
95
+
96
+	/**
97
+	 * @var null|int $spaces_remaining
98
+	 */
99
+	private $spaces_remaining;
100
+
101
+	/**
102
+	 * @var null|int $total_spaces_available
103
+	 */
104
+	private $total_spaces_available;
105
+
106
+
107
+	/**
108
+	 * EventSpacesCalculator constructor.
109
+	 *
110
+	 * @param EE_Event $event
111
+	 * @param array    $datetime_query_params
112
+	 * @throws EE_Error
113
+	 */
114
+	public function __construct(EE_Event $event, array $datetime_query_params = array())
115
+	{
116
+		if ($this->debug) {
117
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1);
118
+			\EEH_Debug_Tools::printr((string) $event->ID(), 'For event', __FILE__, __LINE__);
119
+		}
120
+		$this->event = $event;
121
+		$this->datetime_query_params = $datetime_query_params + array('order_by' => array('DTT_reg_limit' => 'ASC'));
122
+		$this->setHooks();
123
+	}
124
+
125
+
126
+	/**
127
+	 * @return void
128
+	 */
129
+	private function setHooks()
130
+	{
131
+		add_action('AHEE__EE_Ticket__increase_sold', array($this, 'clearResults'));
132
+		add_action('AHEE__EE_Ticket__decrease_sold', array($this, 'clearResults'));
133
+		add_action('AHEE__EE_Datetime__increase_sold', array($this, 'clearResults'));
134
+		add_action('AHEE__EE_Datetime__decrease_sold', array($this, 'clearResults'));
135
+		add_action('AHEE__EE_Ticket__increase_reserved', array($this, 'clearResults'));
136
+		add_action('AHEE__EE_Ticket__decrease_reserved', array($this, 'clearResults'));
137
+		add_action('AHEE__EE_Datetime__increase_reserved', array($this, 'clearResults'));
138
+		add_action('AHEE__EE_Datetime__decrease_reserved', array($this, 'clearResults'));
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return void
144
+	 */
145
+	public function clearResults()
146
+	{
147
+		if ($this->debug) {
148
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 1);
149
+		}
150
+		$this->spaces_remaining = null;
151
+		$this->total_spaces_available = null;
152
+	}
153
+
154
+
155
+	/**
156
+	 * @return EE_Ticket[]
157
+	 * @throws EE_Error
158
+	 * @throws InvalidDataTypeException
159
+	 * @throws InvalidInterfaceException
160
+	 * @throws InvalidArgumentException
161
+	 */
162
+	public function getActiveTickets()
163
+	{
164
+		if (empty($this->active_tickets)) {
165
+			$this->active_tickets = $this->event->tickets(
166
+				array(
167
+					array('TKT_deleted' => false),
168
+					'order_by' => array('TKT_qty' => 'ASC'),
169
+				)
170
+			);
171
+		}
172
+		return $this->active_tickets;
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param EE_Ticket[] $active_tickets
178
+	 * @throws EE_Error
179
+	 * @throws DomainException
180
+	 * @throws UnexpectedEntityException
181
+	 */
182
+	public function setActiveTickets(array $active_tickets = array())
183
+	{
184
+		if (! empty($active_tickets)) {
185
+			foreach ($active_tickets as $active_ticket) {
186
+				$this->validateTicket($active_ticket);
187
+			}
188
+			// sort incoming array by ticket quantity (asc)
189
+			usort(
190
+				$active_tickets,
191
+				function (EE_Ticket $a, EE_Ticket $b) {
192
+					if ($a->qty() === $b->qty()) {
193
+						return 0;
194
+					}
195
+					return ($a->qty() < $b->qty())
196
+						? -1
197
+						: 1;
198
+				}
199
+			);
200
+		}
201
+		$this->active_tickets = $active_tickets;
202
+	}
203
+
204
+
205
+	/**
206
+	 * @param $ticket
207
+	 * @throws DomainException
208
+	 * @throws EE_Error
209
+	 * @throws UnexpectedEntityException
210
+	 */
211
+	private function validateTicket($ticket)
212
+	{
213
+		if (! $ticket instanceof EE_Ticket) {
214
+			throw new DomainException(
215
+				esc_html__(
216
+					'Invalid Ticket. Only EE_Ticket objects can be used to calculate event space availability.',
217
+					'event_espresso'
218
+				)
219
+			);
220
+		}
221
+		if ($ticket->get_event_ID() !== $this->event->ID()) {
222
+			throw new DomainException(
223
+				sprintf(
224
+					esc_html__(
225
+						'An EE_Ticket for Event %1$d was supplied while calculating event space availability for Event %2$d.',
226
+						'event_espresso'
227
+					),
228
+					$ticket->get_event_ID(),
229
+					$this->event->ID()
230
+				)
231
+			);
232
+		}
233
+	}
234
+
235
+
236
+	/**
237
+	 * @return EE_Datetime[]
238
+	 */
239
+	public function getDatetimes()
240
+	{
241
+		return $this->datetimes;
242
+	}
243
+
244
+
245
+	/**
246
+	 * @param EE_Datetime $datetime
247
+	 * @throws EE_Error
248
+	 * @throws DomainException
249
+	 */
250
+	public function setDatetime(EE_Datetime $datetime)
251
+	{
252
+		if ($datetime->event()->ID() !== $this->event->ID()) {
253
+			throw new DomainException(
254
+				sprintf(
255
+					esc_html__(
256
+						'An EE_Datetime for Event %1$d was supplied while calculating event space availability for Event %2$d.',
257
+						'event_espresso'
258
+					),
259
+					$datetime->event()->ID(),
260
+					$this->event->ID()
261
+				)
262
+			);
263
+		}
264
+		$this->datetimes[ $datetime->ID() ] = $datetime;
265
+	}
266
+
267
+
268
+	/**
269
+	 * calculate spaces remaining based on "saleable" tickets
270
+	 *
271
+	 * @return float|int
272
+	 * @throws EE_Error
273
+	 * @throws DomainException
274
+	 * @throws UnexpectedEntityException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 * @throws InvalidArgumentException
278
+	 */
279
+	public function spacesRemaining()
280
+	{
281
+		if ($this->debug) {
282
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
283
+		}
284
+		if ($this->spaces_remaining === null) {
285
+			$this->initialize();
286
+			$this->spaces_remaining = $this->calculate();
287
+		}
288
+		return $this->spaces_remaining;
289
+	}
290
+
291
+
292
+	/**
293
+	 * calculates total available spaces for an event with no regard for sold tickets
294
+	 *
295
+	 * @return int|float
296
+	 * @throws EE_Error
297
+	 * @throws DomainException
298
+	 * @throws UnexpectedEntityException
299
+	 * @throws InvalidDataTypeException
300
+	 * @throws InvalidInterfaceException
301
+	 * @throws InvalidArgumentException
302
+	 */
303
+	public function totalSpacesAvailable()
304
+	{
305
+		if ($this->debug) {
306
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
307
+		}
308
+		if ($this->total_spaces_available === null) {
309
+			$this->initialize();
310
+			$this->total_spaces_available = $this->calculate(false);
311
+		}
312
+		return $this->total_spaces_available;
313
+	}
314
+
315
+
316
+	/**
317
+	 * Loops through the active tickets for the event
318
+	 * and builds a series of data arrays that will be used for calculating
319
+	 * the total maximum available spaces, as well as the spaces remaining.
320
+	 * Because ticket quantities affect datetime spaces and vice versa,
321
+	 * we need to be constantly updating these data arrays as things change,
322
+	 * which is the entire reason for their existence.
323
+	 *
324
+	 * @throws EE_Error
325
+	 * @throws DomainException
326
+	 * @throws UnexpectedEntityException
327
+	 * @throws InvalidDataTypeException
328
+	 * @throws InvalidInterfaceException
329
+	 * @throws InvalidArgumentException
330
+	 */
331
+	private function initialize()
332
+	{
333
+		if ($this->debug) {
334
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
335
+		}
336
+		$this->datetime_tickets = array();
337
+		$this->datetime_spaces = array();
338
+		$this->ticket_datetimes = array();
339
+		$this->ticket_quantities = array();
340
+		$this->tickets_sold = array();
341
+		$this->total_spaces = array();
342
+		$active_tickets = $this->getActiveTickets();
343
+		if (! empty($active_tickets)) {
344
+			foreach ($active_tickets as $ticket) {
345
+				$this->validateTicket($ticket);
346
+				// we need to index our data arrays using strings for the purpose of sorting,
347
+				// but we also need them to be unique, so  we'll just prepend a letter T to the ID
348
+				$ticket_identifier = "T{$ticket->ID()}";
349
+				// to start, we'll just consider the raw qty to be the maximum availability for this ticket,
350
+				// unless the ticket is past its "sell until" date, in which case the qty will be 0
351
+				$max_tickets = $ticket->is_expired() ? 0 : $ticket->qty();
352
+				// but we'll adjust that after looping over each datetime for the ticket and checking reg limits
353
+				$ticket_datetimes = $ticket->datetimes($this->datetime_query_params);
354
+				foreach ($ticket_datetimes as $datetime) {
355
+					// save all datetimes
356
+					$this->setDatetime($datetime);
357
+					$datetime_identifier = "D{$datetime->ID()}";
358
+					$reg_limit = $datetime->reg_limit();
359
+					// ticket quantity can not exceed datetime reg limit
360
+					$max_tickets = min($max_tickets, $reg_limit);
361
+					// as described earlier, because we need to be able to constantly adjust numbers for things,
362
+					// we are going to move all of our data into the following arrays:
363
+					// datetime spaces initially represents the reg limit for each datetime,
364
+					// but this will get adjusted as tickets are accounted for
365
+					$this->datetime_spaces[ $datetime_identifier ] = $reg_limit;
366
+					// just an array of ticket IDs grouped by datetime
367
+					$this->datetime_tickets[ $datetime_identifier ][] = $ticket_identifier;
368
+					// and an array of datetime IDs grouped by ticket
369
+					$this->ticket_datetimes[ $ticket_identifier ][] = $datetime_identifier;
370
+				}
371
+				// total quantity of sold and reserved for each ticket
372
+				$this->tickets_sold[ $ticket_identifier ] = $ticket->sold() + $ticket->reserved();
373
+				// and the maximum ticket quantities for each ticket (adjusted for reg limit)
374
+				$this->ticket_quantities[ $ticket_identifier ] = $max_tickets;
375
+			}
376
+		}
377
+		// sort datetime spaces by reg limit, but maintain our string indexes
378
+		asort($this->datetime_spaces, SORT_NUMERIC);
379
+		// datetime tickets need to be sorted in the SAME order as the above array...
380
+		// so we'll just use array_merge() to take the structure of datetime_spaces
381
+		// but overwrite all of the data with that from datetime_tickets
382
+		$this->datetime_tickets = array_merge(
383
+			$this->datetime_spaces,
384
+			$this->datetime_tickets
385
+		);
386
+		if ($this->debug) {
387
+			\EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__);
388
+			\EEH_Debug_Tools::printr($this->datetime_tickets, 'datetime_tickets', __FILE__, __LINE__);
389
+			\EEH_Debug_Tools::printr($this->ticket_quantities, 'ticket_quantities', __FILE__, __LINE__);
390
+		}
391
+	}
392
+
393
+
394
+	/**
395
+	 * performs calculations on initialized data
396
+	 *
397
+	 * @param bool $consider_sold
398
+	 * @return int|float
399
+	 */
400
+	private function calculate($consider_sold = true)
401
+	{
402
+		if ($this->debug) {
403
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
404
+			\EEH_Debug_Tools::printr($consider_sold, '$consider_sold', __FILE__, __LINE__);
405
+		}
406
+		if ($consider_sold) {
407
+			// subtract amounts sold from all ticket quantities and datetime spaces
408
+			$this->adjustTicketQuantitiesDueToSales();
409
+		}
410
+		foreach ($this->datetime_tickets as $datetime_identifier => $tickets) {
411
+			$this->trackAvailableSpacesForDatetimes($datetime_identifier, $tickets);
412
+		}
413
+		// total spaces available is just the sum of the spaces available for each datetime
414
+		$spaces_remaining = array_sum($this->total_spaces);
415
+		if ($this->debug) {
416
+			\EEH_Debug_Tools::printr($this->total_spaces, '$this->total_spaces', __FILE__, __LINE__);
417
+			\EEH_Debug_Tools::printr($this->tickets_sold, '$this->tickets_sold', __FILE__, __LINE__);
418
+			\EEH_Debug_Tools::printr($spaces_remaining, '$spaces_remaining', __FILE__, __LINE__);
419
+		}
420
+		return $spaces_remaining;
421
+	}
422
+
423
+
424
+	/**
425
+	 * subtracts amount of  tickets sold from ticket quantities and datetime spaces
426
+	 */
427
+	private function adjustTicketQuantitiesDueToSales()
428
+	{
429
+		if ($this->debug) {
430
+			\EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2);
431
+		}
432
+		foreach ($this->tickets_sold as $ticket_identifier => $tickets_sold) {
433
+			if (isset($this->ticket_quantities[ $ticket_identifier ])) {
434
+				$this->ticket_quantities[ $ticket_identifier ] -= $tickets_sold;
435
+				// don't let values go below zero
436
+				$this->ticket_quantities[ $ticket_identifier ] = max(
437
+					$this->ticket_quantities[ $ticket_identifier ],
438
+					0
439
+				);
440
+				if ($this->debug) {
441
+					\EEH_Debug_Tools::printr(
442
+						"{$tickets_sold} sales for ticket {$ticket_identifier} ",
443
+						'subtracting',
444
+						__FILE__,
445
+						__LINE__
446
+					);
447
+				}
448
+			}
449
+			if (isset($this->ticket_datetimes[ $ticket_identifier ])
450
+				&& is_array($this->ticket_datetimes[ $ticket_identifier ])
451
+			) {
452
+				foreach ($this->ticket_datetimes[ $ticket_identifier ] as $ticket_datetime) {
453
+					if (isset($this->ticket_quantities[ $ticket_identifier ])) {
454
+						$this->datetime_spaces[ $ticket_datetime ] -= $tickets_sold;
455
+						// don't let values go below zero
456
+						$this->datetime_spaces[ $ticket_datetime ] = max(
457
+							$this->datetime_spaces[ $ticket_datetime ],
458
+							0
459
+						);
460
+						if ($this->debug) {
461
+							\EEH_Debug_Tools::printr(
462
+								"{$tickets_sold} sales for datetime {$ticket_datetime} ",
463
+								'subtracting',
464
+								__FILE__,
465
+								__LINE__
466
+							);
467
+						}
468
+					}
469
+				}
470
+			}
471
+		}
472
+	}
473
+
474
+
475
+	/**
476
+	 * @param string $datetime_identifier
477
+	 * @param array  $tickets
478
+	 */
479
+	private function trackAvailableSpacesForDatetimes($datetime_identifier, array $tickets)
480
+	{
481
+		// make sure a reg limit is set for the datetime
482
+		$reg_limit = isset($this->datetime_spaces[ $datetime_identifier ])
483
+			? $this->datetime_spaces[ $datetime_identifier ]
484
+			: 0;
485
+		// and bail if it is not
486
+		if (! $reg_limit) {
487
+			if ($this->debug) {
488
+				\EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__);
489
+			}
490
+			return;
491
+		}
492
+		if ($this->debug) {
493
+			\EEH_Debug_Tools::printr($datetime_identifier, '* $datetime_identifier', __FILE__, __LINE__, 1);
494
+			\EEH_Debug_Tools::printr(
495
+				"{$reg_limit}",
496
+				'REG LIMIT',
497
+				__FILE__,
498
+				__LINE__
499
+			);
500
+		}
501
+		// number of allocated spaces always starts at zero
502
+		$spaces_allocated = 0;
503
+		$this->total_spaces[ $datetime_identifier ] = 0;
504
+		foreach ($tickets as $ticket_identifier) {
505
+			$spaces_allocated = $this->calculateAvailableSpacesForTicket(
506
+				$datetime_identifier,
507
+				$reg_limit,
508
+				$ticket_identifier,
509
+				$spaces_allocated
510
+			);
511
+		}
512
+		// spaces can't be negative
513
+		$spaces_allocated = max($spaces_allocated, 0);
514
+		if ($spaces_allocated) {
515
+			// track any non-zero values
516
+			$this->total_spaces[ $datetime_identifier ] += $spaces_allocated;
517
+			if ($this->debug) {
518
+				\EEH_Debug_Tools::printr((string) $spaces_allocated, ' . $spaces_allocated: ', __FILE__, __LINE__);
519
+			}
520
+		} else {
521
+			if ($this->debug) {
522
+				\EEH_Debug_Tools::printr(' ', ' . NO TICKETS AVAILABLE FOR DATETIME', __FILE__, __LINE__);
523
+			}
524
+		}
525
+		if ($this->debug) {
526
+			\EEH_Debug_Tools::printr(
527
+				$this->total_spaces[ $datetime_identifier ],
528
+				'$total_spaces',
529
+				__FILE__,
530
+				__LINE__
531
+			);
532
+			\EEH_Debug_Tools::printr($this->ticket_quantities, '$ticket_quantities', __FILE__, __LINE__);
533
+			\EEH_Debug_Tools::printr($this->datetime_spaces, 'datetime_spaces', __FILE__, __LINE__);
534
+		}
535
+	}
536
+
537
+
538
+	/**
539
+	 * @param string $datetime_identifier
540
+	 * @param int    $reg_limit
541
+	 * @param string $ticket_identifier
542
+	 * @param int    $spaces_allocated
543
+	 * @return int
544
+	 */
545
+	private function calculateAvailableSpacesForTicket(
546
+		$datetime_identifier,
547
+		$reg_limit,
548
+		$ticket_identifier,
549
+		$spaces_allocated
550
+	) {
551
+		// make sure ticket quantity is set
552
+		$ticket_quantity = isset($this->ticket_quantities[ $ticket_identifier ])
553
+			? $this->ticket_quantities[ $ticket_identifier ]
554
+			: 0;
555
+		if ($this->debug) {
556
+			\EEH_Debug_Tools::printr("{$spaces_allocated}", '$spaces_allocated', __FILE__, __LINE__);
557
+			\EEH_Debug_Tools::printr(
558
+				"{$ticket_quantity}",
559
+				"ticket $ticket_identifier quantity: ",
560
+				__FILE__,
561
+				__LINE__,
562
+				2
563
+			);
564
+		}
565
+		if ($ticket_quantity) {
566
+			if ($this->debug) {
567
+				\EEH_Debug_Tools::printr(
568
+					($spaces_allocated <= $reg_limit)
569
+						? 'true'
570
+						: 'false',
571
+					' . spaces_allocated <= reg_limit = ',
572
+					__FILE__,
573
+					__LINE__
574
+				);
575
+			}
576
+			// if the datetime is NOT at full capacity yet
577
+			if ($spaces_allocated <= $reg_limit) {
578
+				// then the maximum ticket quantity we can allocate is the lowest value of either:
579
+				//  the number of remaining spaces for the datetime, which is the limit - spaces already taken
580
+				//  or the maximum ticket quantity
581
+				$ticket_quantity = min($reg_limit - $spaces_allocated, $ticket_quantity);
582
+				// adjust the available quantity in our tracking array
583
+				$this->ticket_quantities[ $ticket_identifier ] -= $ticket_quantity;
584
+				// and increment spaces allocated for this datetime
585
+				$spaces_allocated += $ticket_quantity;
586
+				$at_capacity = $spaces_allocated >= $reg_limit;
587
+				if ($this->debug) {
588
+					\EEH_Debug_Tools::printr(
589
+						"{$ticket_quantity} {$ticket_identifier} tickets",
590
+						' > > allocate ',
591
+						__FILE__,
592
+						__LINE__,
593
+						3
594
+					);
595
+					if ($at_capacity) {
596
+						\EEH_Debug_Tools::printr('AT CAPACITY', " . {$datetime_identifier}", __FILE__, __LINE__, 3);
597
+					}
598
+				}
599
+				// now adjust all other datetimes that allow access to this ticket
600
+				$this->adjustDatetimes(
601
+					$datetime_identifier,
602
+					$ticket_identifier,
603
+					$ticket_quantity,
604
+					$at_capacity
605
+				);
606
+			}
607
+		}
608
+		return $spaces_allocated;
609
+	}
610
+
611
+
612
+	/**
613
+	 * subtracts ticket amounts from all datetime reg limits
614
+	 * that allow access to the ticket specified,
615
+	 * because that ticket could be used
616
+	 * to attend any of the datetimes it has access to
617
+	 *
618
+	 * @param string $datetime_identifier
619
+	 * @param string $ticket_identifier
620
+	 * @param bool   $at_capacity
621
+	 * @param int    $ticket_quantity
622
+	 */
623
+	private function adjustDatetimes(
624
+		$datetime_identifier,
625
+		$ticket_identifier,
626
+		$ticket_quantity,
627
+		$at_capacity
628
+	) {
629
+		/** @var array $datetime_tickets */
630
+		foreach ($this->datetime_tickets as $datetime_ID => $datetime_tickets) {
631
+			if ($datetime_ID !== $datetime_identifier || ! is_array($datetime_tickets)) {
632
+				continue;
633
+			}
634
+			$adjusted = $this->adjustDatetimeSpaces(
635
+				$datetime_ID,
636
+				$ticket_identifier,
637
+				$ticket_quantity
638
+			);
639
+			// skip to next ticket if nothing changed
640
+			if (! ($adjusted || $at_capacity)) {
641
+				continue;
642
+			}
643
+			// then all of it's tickets are now unavailable
644
+			foreach ($datetime_tickets as $datetime_ticket) {
645
+				if (($ticket_identifier === $datetime_ticket || $at_capacity)
646
+					&& isset($this->ticket_quantities[ $datetime_ticket ])
647
+					&& $this->ticket_quantities[ $datetime_ticket ] > 0
648
+				) {
649
+					if ($this->debug) {
650
+						\EEH_Debug_Tools::printr(
651
+							$datetime_ticket,
652
+							' . . . adjust ticket quantities for',
653
+							__FILE__,
654
+							__LINE__
655
+						);
656
+					}
657
+					// if this datetime is at full capacity, set any tracked available quantities to zero
658
+					// otherwise just subtract the ticket quantity
659
+					$new_quantity = $at_capacity
660
+						? 0
661
+						: $this->ticket_quantities[ $datetime_ticket ] - $ticket_quantity;
662
+					// don't let ticket quantity go below zero
663
+					$this->ticket_quantities[ $datetime_ticket ] = max($new_quantity, 0);
664
+					if ($this->debug) {
665
+						\EEH_Debug_Tools::printr(
666
+							$at_capacity
667
+								? "0 because Datetime {$datetime_identifier} is at capacity"
668
+								: "{$this->ticket_quantities[ $datetime_ticket ]}",
669
+							" . . . . {$datetime_ticket} quantity set to ",
670
+							__FILE__,
671
+							__LINE__
672
+						);
673
+					}
674
+				}
675
+				// but we also need to adjust spaces for any other datetimes this ticket has access to
676
+				if ($datetime_ticket === $ticket_identifier) {
677
+					if (isset($this->ticket_datetimes[ $datetime_ticket ])
678
+						&& is_array($this->ticket_datetimes[ $datetime_ticket ])
679
+					) {
680
+						if ($this->debug) {
681
+							\EEH_Debug_Tools::printr(
682
+								$datetime_ticket,
683
+								' . . adjust other Datetimes for',
684
+								__FILE__,
685
+								__LINE__
686
+							);
687
+						}
688
+						foreach ($this->ticket_datetimes[ $datetime_ticket ] as $datetime) {
689
+							// don't adjust the current datetime twice
690
+							if ($datetime !== $datetime_identifier) {
691
+								$this->adjustDatetimeSpaces(
692
+									$datetime,
693
+									$datetime_ticket,
694
+									$ticket_quantity
695
+								);
696
+							}
697
+						}
698
+					}
699
+				}
700
+			}
701
+		}
702
+	}
703
+
704
+	private function adjustDatetimeSpaces($datetime_identifier, $ticket_identifier, $ticket_quantity = 0)
705
+	{
706
+		// does datetime have spaces available?
707
+		// and does the supplied ticket have access to this datetime ?
708
+		if ($this->datetime_spaces[ $datetime_identifier ] > 0
709
+			&& isset($this->datetime_spaces[ $datetime_identifier ], $this->datetime_tickets[ $datetime_identifier ])
710
+			&& in_array($ticket_identifier, $this->datetime_tickets[ $datetime_identifier ], true)
711
+		) {
712
+			if ($this->debug) {
713
+				\EEH_Debug_Tools::printr($datetime_identifier, ' . . adjust Datetime Spaces for', __FILE__, __LINE__);
714
+				\EEH_Debug_Tools::printr(
715
+					"{$this->datetime_spaces[ $datetime_identifier ]}",
716
+					" . . current  {$datetime_identifier} spaces available",
717
+					__FILE__,
718
+					__LINE__
719
+				);
720
+			}
721
+			// then decrement the available spaces for the datetime
722
+			$this->datetime_spaces[ $datetime_identifier ] -= $ticket_quantity;
723
+			// but don't let quantities go below zero
724
+			$this->datetime_spaces[ $datetime_identifier ] = max(
725
+				$this->datetime_spaces[ $datetime_identifier ],
726
+				0
727
+			);
728
+			if ($this->debug) {
729
+				\EEH_Debug_Tools::printr(
730
+					"{$ticket_quantity}",
731
+					" . . . {$datetime_identifier} capacity reduced by",
732
+					__FILE__,
733
+					__LINE__
734
+				);
735
+			}
736
+			return true;
737
+		}
738
+		return false;
739
+	}
740 740
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Float_Input.input.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -11,33 +11,33 @@
 block discarded – undo
11 11
 class EE_Float_Input extends EE_Form_Input_Base
12 12
 {
13 13
 
14
-    /**
15
-     * @param array $input_settings
16
-     * @throws InvalidArgumentException
17
-     */
18
-    public function __construct($input_settings = array())
19
-    {
20
-        $this->_set_display_strategy(
21
-            new EE_Number_Input_Display_Strategy(
22
-                isset($input_settings['min_value'])
23
-                    ? $input_settings['min_value']
24
-                    : null,
25
-                isset($input_settings['max_value'])
26
-                    ? $input_settings['max_value']
27
-                    : null,
28
-                isset($input_settings['step_value'])
29
-                    ? $input_settings['step_value']
30
-                    : null
31
-            )
32
-        );
33
-        $this->_set_normalization_strategy(new EE_Float_Normalization());
34
-        $this->_add_validation_strategy(
35
-            new EE_Float_Validation_Strategy(
36
-                isset($input_settings['validation_error_message'])
37
-                    ? $input_settings['validation_error_message']
38
-                    : null
39
-            )
40
-        );
41
-        parent::__construct($input_settings);
42
-    }
14
+	/**
15
+	 * @param array $input_settings
16
+	 * @throws InvalidArgumentException
17
+	 */
18
+	public function __construct($input_settings = array())
19
+	{
20
+		$this->_set_display_strategy(
21
+			new EE_Number_Input_Display_Strategy(
22
+				isset($input_settings['min_value'])
23
+					? $input_settings['min_value']
24
+					: null,
25
+				isset($input_settings['max_value'])
26
+					? $input_settings['max_value']
27
+					: null,
28
+				isset($input_settings['step_value'])
29
+					? $input_settings['step_value']
30
+					: null
31
+			)
32
+		);
33
+		$this->_set_normalization_strategy(new EE_Float_Normalization());
34
+		$this->_add_validation_strategy(
35
+			new EE_Float_Validation_Strategy(
36
+				isset($input_settings['validation_error_message'])
37
+					? $input_settings['validation_error_message']
38
+					: null
39
+			)
40
+		);
41
+		parent::__construct($input_settings);
42
+	}
43 43
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_List_Table.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -152,7 +152,7 @@
 block discarded – undo
152 152
 
153 153
     /**
154 154
      * @param EE_Event $item
155
-     * @return mixed|string
155
+     * @return string
156 156
      * @throws EE_Error
157 157
      */
158 158
     public function column_id(EE_Event $item)
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         $class = parent::_get_row_class($item);
113 113
         // add status class
114 114
         $class .= $item instanceof EE_Event
115
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
115
+            ? ' ee-status-strip event-status-'.$item->get_active_status()
116 116
             : '';
117 117
         if ($this->_has_checkbox_column) {
118 118
             $class .= ' has-checkbox-column';
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function column_cb($item)
143 143
     {
144
-        if (! $item instanceof EE_Event) {
144
+        if ( ! $item instanceof EE_Event) {
145 145
             return '';
146 146
         }
147 147
         $this->_dtt = $item->primary_datetime(); // set this for use in other columns
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
     public function column_id(EE_Event $item)
165 165
     {
166 166
         $content = $item->ID();
167
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
167
+        $content .= '  <span class="show-on-mobile-view-only">'.$item->name().'</span>';
168 168
         return $content;
169 169
     }
170 170
 
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         $actions = $this->_column_name_action_setup($item);
188 188
         $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
189 189
         $content = '<strong><a class="row-title" href="'
190
-                   . $edit_link . '">'
190
+                   . $edit_link.'">'
191 191
                    . $item->name()
192 192
                    . '</a></strong>'
193 193
                    . $status;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     protected function _column_name_action_setup(EE_Event $item)
217 217
     {
218 218
         // todo: remove when attendees is active
219
-        if (! defined('REG_ADMIN_URL')) {
219
+        if ( ! defined('REG_ADMIN_URL')) {
220 220
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
221 221
         }
222 222
         $actions = array();
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
                 'post'   => $item->ID(),
234 234
             );
235 235
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
236
-            $actions['edit'] = '<a href="' . $edit_link . '"'
237
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
236
+            $actions['edit'] = '<a href="'.$edit_link.'"'
237
+                               . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
238 238
                                . esc_html__('Edit', 'event_espresso')
239 239
                                . '</a>';
240 240
         }
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
                 'event_id' => $item->ID(),
254 254
             );
255 255
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
256
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
257
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
256
+            $actions['attendees'] = '<a href="'.$attendees_link.'"'
257
+                                    . ' title="'.esc_attr__('View Registrations', 'event_espresso').'">'
258 258
                                     . esc_html__('Registrations', 'event_espresso')
259 259
                                     . '</a>';
260 260
         }
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
             );
302 302
         }
303 303
         $view_link = get_permalink($item->ID());
304
-        $actions['view'] = '<a href="' . $view_link . '"'
305
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
304
+        $actions['view'] = '<a href="'.$view_link.'"'
305
+                           . ' title="'.esc_attr__('View Event', 'event_espresso').'">'
306 306
                            . esc_html__('View', 'event_espresso')
307 307
                            . '</a>';
308 308
         if ($item->get('status') === 'trash') {
@@ -311,8 +311,8 @@  discard block
 block discarded – undo
311 311
                 'espresso_events_restore_event',
312 312
                 $item->ID()
313 313
             )) {
314
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
315
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
314
+                $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'"'
315
+                                                 . ' title="'.esc_attr__('Restore from Trash', 'event_espresso')
316 316
                                                  . '">'
317 317
                                                  . esc_html__('Restore from Trash', 'event_espresso')
318 318
                                                  . '</a>';
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                     $item->ID()
325 325
                 )
326 326
             ) {
327
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
328
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
327
+                $actions['delete'] = '<a href="'.$delete_event_link.'"'
328
+                                     . ' title="'.esc_attr__('Delete Permanently', 'event_espresso').'">'
329 329
                                      . esc_html__('Delete Permanently', 'event_espresso')
330 330
                                      . '</a>';
331 331
             }
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
                 'espresso_events_trash_event',
336 336
                 $item->ID()
337 337
             )) {
338
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
339
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
338
+                $actions['move to trash'] = '<a href="'.$trash_event_link.'"'
339
+                                            . ' title="'.esc_attr__('Trash Event', 'event_espresso').'">'
340 340
                                             . esc_html__('Trash', 'event_espresso')
341 341
                                             . '</a>';
342 342
             }
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
             'EVT_wp_user' => $item->wp_user(),
362 362
         );
363 363
         $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
364
-        return $gravatar . '  <a href="' . $filter_url . '"'
365
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
364
+        return $gravatar.'  <a href="'.$filter_url.'"'
365
+               . ' title="'.esc_attr__('Click to filter events by this author.', 'event_espresso').'">'
366 366
                . $event_author->display_name
367 367
                . '</a>';
368 368
     }
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
         return implode(
380 380
             ', ',
381 381
             array_map(
382
-                function (EE_Term $category) {
382
+                function(EE_Term $category) {
383 383
                     return $category->name();
384 384
                 },
385 385
                 $event_categories
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
                    'ee_read_registrations',
455 455
                    'espresso_registrations_view_registration'
456 456
                )
457
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
457
+            ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>'
458 458
             : $registered_attendees;
459 459
     }
460 460
 
@@ -484,13 +484,13 @@  discard block
 block discarded – undo
484 484
     public function column_actions(EE_Event $item)
485 485
     {
486 486
         // todo: remove when attendees is active
487
-        if (! defined('REG_ADMIN_URL')) {
487
+        if ( ! defined('REG_ADMIN_URL')) {
488 488
             define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
489 489
         }
490 490
         $action_links = array();
491 491
         $view_link = get_permalink($item->ID());
492
-        $action_links[] = '<a href="' . $view_link . '"'
493
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
492
+        $action_links[] = '<a href="'.$view_link.'"'
493
+                          . ' title="'.esc_attr__('View Event', 'event_espresso').'" target="_blank">';
494 494
         $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
495 495
         if (EE_Registry::instance()->CAP->current_user_can(
496 496
             'ee_edit_event',
@@ -502,8 +502,8 @@  discard block
 block discarded – undo
502 502
                 'post'   => $item->ID(),
503 503
             );
504 504
             $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
505
-            $action_links[] = '<a href="' . $edit_link . '"'
506
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
505
+            $action_links[] = '<a href="'.$edit_link.'"'
506
+                              . ' title="'.esc_attr__('Edit Event', 'event_espresso').'">'
507 507
                               . '<div class="ee-icon ee-icon-calendar-edit"></div>'
508 508
                               . '</a>';
509 509
         }
@@ -521,8 +521,8 @@  discard block
 block discarded – undo
521 521
                 'event_id' => $item->ID(),
522 522
             );
523 523
             $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
524
-            $action_links[] = '<a href="' . $attendees_link . '"'
525
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
524
+            $action_links[] = '<a href="'.$attendees_link.'"'
525
+                              . ' title="'.esc_attr__('View Registrants', 'event_espresso').'">'
526 526
                               . '<div class="dashicons dashicons-groups"></div>'
527 527
                               . '</a>';
528 528
         }
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
         }
558 558
         $column_array = [];
559 559
         foreach ($this->_columns as $column => $column_label) {
560
-            $column_array[ $column ] = $column_label;
560
+            $column_array[$column] = $column_label;
561 561
             if ($column === 'venue') {
562 562
                 $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
563 563
             }
Please login to merge, or discard this patch.
Indentation   +549 added lines, -549 removed lines patch added patch discarded remove patch
@@ -15,553 +15,553 @@
 block discarded – undo
15 15
 class Events_Admin_List_Table extends EE_Admin_List_Table
16 16
 {
17 17
 
18
-    /**
19
-     * @var EE_Datetime
20
-     */
21
-    private $_dtt;
22
-
23
-
24
-    /**
25
-     * Initial setup of data properties for the list table.
26
-     */
27
-    protected function _setup_data()
28
-    {
29
-        $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
-        $this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
-    }
32
-
33
-
34
-    /**
35
-     * Set up of additional properties for the list table.
36
-     */
37
-    protected function _set_properties()
38
-    {
39
-        $this->_wp_list_args = array(
40
-            'singular' => esc_html__('event', 'event_espresso'),
41
-            'plural'   => esc_html__('events', 'event_espresso'),
42
-            'ajax'     => true, // for now
43
-            'screen'   => $this->_admin_page->get_current_screen()->id,
44
-        );
45
-        $this->_columns = array(
46
-            'cb'              => '<input type="checkbox" />',
47
-            'id'              => esc_html__('ID', 'event_espresso'),
48
-            'name'            => esc_html__('Name', 'event_espresso'),
49
-            'author'          => esc_html__('Author', 'event_espresso'),
50
-            'venue'           => esc_html__('Venue', 'event_espresso'),
51
-            'start_date_time' => esc_html__('Event Start', 'event_espresso'),
52
-            'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
53
-            'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
54
-                                 . '<span class="screen-reader-text">'
55
-                                 . esc_html__('Approved Registrations', 'event_espresso')
56
-                                 . '</span>'
57
-                                 . '</span>',
58
-            // 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
59
-            'actions'         => esc_html__('Actions', 'event_espresso'),
60
-        );
61
-        $this->addConditionalColumns();
62
-        $this->_sortable_columns = array(
63
-            'id'              => array('EVT_ID' => true),
64
-            'name'            => array('EVT_name' => false),
65
-            'author'          => array('EVT_wp_user' => false),
66
-            'venue'           => array('Venue.VNU_name' => false),
67
-            'start_date_time' => array('Datetime.DTT_EVT_start' => false),
68
-            'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
69
-        );
70
-
71
-        $this->_primary_column = 'id';
72
-        $this->_hidden_columns = array('author', 'event_category');
73
-    }
74
-
75
-
76
-    /**
77
-     * @return array
78
-     */
79
-    protected function _get_table_filters()
80
-    {
81
-        return array(); // no filters with decaf
82
-    }
83
-
84
-
85
-    /**
86
-     * Setup of views properties.
87
-     *
88
-     * @throws InvalidDataTypeException
89
-     * @throws InvalidInterfaceException
90
-     * @throws InvalidArgumentException
91
-     */
92
-    protected function _add_view_counts()
93
-    {
94
-        $this->_views['all']['count'] = $this->_admin_page->total_events();
95
-        $this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
96
-        if (EE_Registry::instance()->CAP->current_user_can(
97
-            'ee_delete_events',
98
-            'espresso_events_trash_events'
99
-        )) {
100
-            $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
101
-        }
102
-    }
103
-
104
-
105
-    /**
106
-     * @param EE_Event $item
107
-     * @return string
108
-     * @throws EE_Error
109
-     */
110
-    protected function _get_row_class($item)
111
-    {
112
-        $class = parent::_get_row_class($item);
113
-        // add status class
114
-        $class .= $item instanceof EE_Event
115
-            ? ' ee-status-strip event-status-' . $item->get_active_status()
116
-            : '';
117
-        if ($this->_has_checkbox_column) {
118
-            $class .= ' has-checkbox-column';
119
-        }
120
-        return $class;
121
-    }
122
-
123
-
124
-    /**
125
-     * @param EE_Event $item
126
-     * @return string
127
-     * @throws EE_Error
128
-     */
129
-    public function column_status(EE_Event $item)
130
-    {
131
-        return '<span class="ee-status-strip ee-status-strip-td event-status-'
132
-               . $item->get_active_status()
133
-               . '"></span>';
134
-    }
135
-
136
-
137
-    /**
138
-     * @param  EE_Event $item
139
-     * @return string
140
-     * @throws EE_Error
141
-     */
142
-    public function column_cb($item)
143
-    {
144
-        if (! $item instanceof EE_Event) {
145
-            return '';
146
-        }
147
-        $this->_dtt = $item->primary_datetime(); // set this for use in other columns
148
-        // does event have any attached registrations?
149
-        $regs = $item->count_related('Registration');
150
-        return $regs > 0 && $this->_view === 'trash'
151
-            ? '<span class="ee-lock-icon"></span>'
152
-            : sprintf(
153
-                '<input type="checkbox" name="EVT_IDs[]" value="%s" />',
154
-                $item->ID()
155
-            );
156
-    }
157
-
158
-
159
-    /**
160
-     * @param EE_Event $item
161
-     * @return mixed|string
162
-     * @throws EE_Error
163
-     */
164
-    public function column_id(EE_Event $item)
165
-    {
166
-        $content = $item->ID();
167
-        $content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
168
-        return $content;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param EE_Event $item
174
-     * @return string
175
-     * @throws EE_Error
176
-     * @throws InvalidArgumentException
177
-     * @throws InvalidDataTypeException
178
-     * @throws InvalidInterfaceException
179
-     */
180
-    public function column_name(EE_Event $item)
181
-    {
182
-        $edit_query_args = array(
183
-            'action' => 'edit',
184
-            'post'   => $item->ID(),
185
-        );
186
-        $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
187
-        $actions = $this->_column_name_action_setup($item);
188
-        $status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
189
-        $content = '<strong><a class="row-title" href="'
190
-                   . $edit_link . '">'
191
-                   . $item->name()
192
-                   . '</a></strong>'
193
-                   . $status;
194
-        $content .= '<br><span class="ee-status-text-small">'
195
-                    . EEH_Template::pretty_status(
196
-                        $item->get_active_status(),
197
-                        false,
198
-                        'sentence'
199
-                    )
200
-                    . '</span>';
201
-        $content .= $this->row_actions($actions);
202
-        return $content;
203
-    }
204
-
205
-
206
-    /**
207
-     * Just a method for setting up the actions for the name column
208
-     *
209
-     * @param EE_Event $item
210
-     * @return array array of actions
211
-     * @throws EE_Error
212
-     * @throws InvalidArgumentException
213
-     * @throws InvalidDataTypeException
214
-     * @throws InvalidInterfaceException
215
-     */
216
-    protected function _column_name_action_setup(EE_Event $item)
217
-    {
218
-        // todo: remove when attendees is active
219
-        if (! defined('REG_ADMIN_URL')) {
220
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
221
-        }
222
-        $actions = array();
223
-        $restore_event_link = '';
224
-        $delete_event_link = '';
225
-        $trash_event_link = '';
226
-        if (EE_Registry::instance()->CAP->current_user_can(
227
-            'ee_edit_event',
228
-            'espresso_events_edit',
229
-            $item->ID()
230
-        )) {
231
-            $edit_query_args = array(
232
-                'action' => 'edit',
233
-                'post'   => $item->ID(),
234
-            );
235
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
236
-            $actions['edit'] = '<a href="' . $edit_link . '"'
237
-                               . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
238
-                               . esc_html__('Edit', 'event_espresso')
239
-                               . '</a>';
240
-        }
241
-        if (EE_Registry::instance()->CAP->current_user_can(
242
-            'ee_read_registrations',
243
-            'espresso_registrations_view_registration'
244
-        )
245
-            && EE_Registry::instance()->CAP->current_user_can(
246
-                'ee_read_event',
247
-                'espresso_registrations_view_registration',
248
-                $item->ID()
249
-            )
250
-        ) {
251
-            $attendees_query_args = array(
252
-                'action'   => 'default',
253
-                'event_id' => $item->ID(),
254
-            );
255
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
256
-            $actions['attendees'] = '<a href="' . $attendees_link . '"'
257
-                                    . ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
258
-                                    . esc_html__('Registrations', 'event_espresso')
259
-                                    . '</a>';
260
-        }
261
-        if (EE_Registry::instance()->CAP->current_user_can(
262
-            'ee_delete_event',
263
-            'espresso_events_trash_event',
264
-            $item->ID()
265
-        )) {
266
-            $trash_event_query_args = array(
267
-                'action' => 'trash_event',
268
-                'EVT_ID' => $item->ID(),
269
-            );
270
-            $trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
271
-                $trash_event_query_args,
272
-                EVENTS_ADMIN_URL
273
-            );
274
-        }
275
-        if (EE_Registry::instance()->CAP->current_user_can(
276
-            'ee_delete_event',
277
-            'espresso_events_restore_event',
278
-            $item->ID()
279
-        )) {
280
-            $restore_event_query_args = array(
281
-                'action' => 'restore_event',
282
-                'EVT_ID' => $item->ID(),
283
-            );
284
-            $restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
285
-                $restore_event_query_args,
286
-                EVENTS_ADMIN_URL
287
-            );
288
-        }
289
-        if (EE_Registry::instance()->CAP->current_user_can(
290
-            'ee_delete_event',
291
-            'espresso_events_delete_event',
292
-            $item->ID()
293
-        )) {
294
-            $delete_event_query_args = array(
295
-                'action' => 'delete_event',
296
-                'EVT_ID' => $item->ID(),
297
-            );
298
-            $delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
299
-                $delete_event_query_args,
300
-                EVENTS_ADMIN_URL
301
-            );
302
-        }
303
-        $view_link = get_permalink($item->ID());
304
-        $actions['view'] = '<a href="' . $view_link . '"'
305
-                           . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
306
-                           . esc_html__('View', 'event_espresso')
307
-                           . '</a>';
308
-        if ($item->get('status') === 'trash') {
309
-            if (EE_Registry::instance()->CAP->current_user_can(
310
-                'ee_delete_event',
311
-                'espresso_events_restore_event',
312
-                $item->ID()
313
-            )) {
314
-                $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
315
-                                                 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
316
-                                                 . '">'
317
-                                                 . esc_html__('Restore from Trash', 'event_espresso')
318
-                                                 . '</a>';
319
-            }
320
-            if ($item->count_related('Registration') === 0
321
-                && EE_Registry::instance()->CAP->current_user_can(
322
-                    'ee_delete_event',
323
-                    'espresso_events_delete_event',
324
-                    $item->ID()
325
-                )
326
-            ) {
327
-                $actions['delete'] = '<a href="' . $delete_event_link . '"'
328
-                                     . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
329
-                                     . esc_html__('Delete Permanently', 'event_espresso')
330
-                                     . '</a>';
331
-            }
332
-        } else {
333
-            if (EE_Registry::instance()->CAP->current_user_can(
334
-                'ee_delete_event',
335
-                'espresso_events_trash_event',
336
-                $item->ID()
337
-            )) {
338
-                $actions['move to trash'] = '<a href="' . $trash_event_link . '"'
339
-                                            . ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
340
-                                            . esc_html__('Trash', 'event_espresso')
341
-                                            . '</a>';
342
-            }
343
-        }
344
-        return $actions;
345
-    }
346
-
347
-
348
-    /**
349
-     * @param EE_Event $item
350
-     * @return string
351
-     * @throws EE_Error
352
-     */
353
-    public function column_author(EE_Event $item)
354
-    {
355
-        // user author info
356
-        $event_author = get_userdata($item->wp_user());
357
-        $gravatar = get_avatar($item->wp_user(), '15');
358
-        // filter link
359
-        $query_args = array(
360
-            'action'      => 'default',
361
-            'EVT_wp_user' => $item->wp_user(),
362
-        );
363
-        $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
364
-        return $gravatar . '  <a href="' . $filter_url . '"'
365
-               . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
366
-               . $event_author->display_name
367
-               . '</a>';
368
-    }
369
-
370
-
371
-    /**
372
-     * @param EE_Event $event
373
-     * @return string
374
-     * @throws EE_Error
375
-     */
376
-    public function column_event_category(EE_Event $event)
377
-    {
378
-        $event_categories = $event->get_all_event_categories();
379
-        return implode(
380
-            ', ',
381
-            array_map(
382
-                function (EE_Term $category) {
383
-                    return $category->name();
384
-                },
385
-                $event_categories
386
-            )
387
-        );
388
-    }
389
-
390
-
391
-    /**
392
-     * @param EE_Event $item
393
-     * @return string
394
-     * @throws EE_Error
395
-     */
396
-    public function column_venue(EE_Event $item)
397
-    {
398
-        $venue = $item->get_first_related('Venue');
399
-        return ! empty($venue)
400
-            ? $venue->name()
401
-            : '';
402
-    }
403
-
404
-
405
-    /**
406
-     * @param EE_Event $item
407
-     * @return string
408
-     * @throws EE_Error
409
-     */
410
-    public function column_start_date_time(EE_Event $item)
411
-    {
412
-        return $this->_dtt instanceof EE_Datetime
413
-            ? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
414
-            : esc_html__('No Date was saved for this Event', 'event_espresso');
415
-    }
416
-
417
-
418
-    /**
419
-     * @param EE_Event $item
420
-     * @return string
421
-     * @throws EE_Error
422
-     */
423
-    public function column_reg_begins(EE_Event $item)
424
-    {
425
-        $reg_start = $item->get_ticket_with_earliest_start_time();
426
-        return $reg_start instanceof EE_Ticket
427
-            ? $reg_start->get_i18n_datetime('TKT_start_date')
428
-            : esc_html__('No Tickets have been setup for this Event', 'event_espresso');
429
-    }
430
-
431
-
432
-    /**
433
-     * @param EE_Event $item
434
-     * @return int|string
435
-     * @throws EE_Error
436
-     * @throws InvalidArgumentException
437
-     * @throws InvalidDataTypeException
438
-     * @throws InvalidInterfaceException
439
-     */
440
-    public function column_attendees(EE_Event $item)
441
-    {
442
-        $attendees_query_args = array(
443
-            'action'   => 'default',
444
-            'event_id' => $item->ID(),
445
-        );
446
-        $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
447
-        $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
448
-        return EE_Registry::instance()->CAP->current_user_can(
449
-            'ee_read_event',
450
-            'espresso_registrations_view_registration',
451
-            $item->ID()
452
-        )
453
-               && EE_Registry::instance()->CAP->current_user_can(
454
-                   'ee_read_registrations',
455
-                   'espresso_registrations_view_registration'
456
-               )
457
-            ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
458
-            : $registered_attendees;
459
-    }
460
-
461
-
462
-    /**
463
-     * @param EE_Event $item
464
-     * @return float
465
-     * @throws EE_Error
466
-     * @throws InvalidArgumentException
467
-     * @throws InvalidDataTypeException
468
-     * @throws InvalidInterfaceException
469
-     */
470
-    public function column_tkts_sold(EE_Event $item)
471
-    {
472
-        return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
473
-    }
474
-
475
-
476
-    /**
477
-     * @param EE_Event $item
478
-     * @return string
479
-     * @throws EE_Error
480
-     * @throws InvalidArgumentException
481
-     * @throws InvalidDataTypeException
482
-     * @throws InvalidInterfaceException
483
-     */
484
-    public function column_actions(EE_Event $item)
485
-    {
486
-        // todo: remove when attendees is active
487
-        if (! defined('REG_ADMIN_URL')) {
488
-            define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
489
-        }
490
-        $action_links = array();
491
-        $view_link = get_permalink($item->ID());
492
-        $action_links[] = '<a href="' . $view_link . '"'
493
-                          . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
494
-        $action_links[] = '<div class="dashicons dashicons-search"></div></a>';
495
-        if (EE_Registry::instance()->CAP->current_user_can(
496
-            'ee_edit_event',
497
-            'espresso_events_edit',
498
-            $item->ID()
499
-        )) {
500
-            $edit_query_args = array(
501
-                'action' => 'edit',
502
-                'post'   => $item->ID(),
503
-            );
504
-            $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
505
-            $action_links[] = '<a href="' . $edit_link . '"'
506
-                              . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
507
-                              . '<div class="ee-icon ee-icon-calendar-edit"></div>'
508
-                              . '</a>';
509
-        }
510
-        if (EE_Registry::instance()->CAP->current_user_can(
511
-            'ee_read_registrations',
512
-            'espresso_registrations_view_registration'
513
-        ) && EE_Registry::instance()->CAP->current_user_can(
514
-            'ee_read_event',
515
-            'espresso_registrations_view_registration',
516
-            $item->ID()
517
-        )
518
-        ) {
519
-            $attendees_query_args = array(
520
-                'action'   => 'default',
521
-                'event_id' => $item->ID(),
522
-            );
523
-            $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
524
-            $action_links[] = '<a href="' . $attendees_link . '"'
525
-                              . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
526
-                              . '<div class="dashicons dashicons-groups"></div>'
527
-                              . '</a>';
528
-        }
529
-        $action_links = apply_filters(
530
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
531
-            $action_links,
532
-            $item
533
-        );
534
-        return $this->_action_string(
535
-            implode("\n\t", $action_links),
536
-            $item,
537
-            'div'
538
-        );
539
-    }
540
-
541
-
542
-    /**
543
-     * Helper for adding columns conditionally
544
-     *
545
-     * @throws EE_Error
546
-     * @throws InvalidArgumentException
547
-     * @throws InvalidDataTypeException
548
-     * @throws InvalidInterfaceException
549
-     */
550
-    private function addConditionalColumns()
551
-    {
552
-        $event_category_count = EEM_Term::instance()->count(
553
-            [['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
554
-        );
555
-        if ($event_category_count === 0) {
556
-            return;
557
-        }
558
-        $column_array = [];
559
-        foreach ($this->_columns as $column => $column_label) {
560
-            $column_array[ $column ] = $column_label;
561
-            if ($column === 'venue') {
562
-                $column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
563
-            }
564
-        }
565
-        $this->_columns = $column_array;
566
-    }
18
+	/**
19
+	 * @var EE_Datetime
20
+	 */
21
+	private $_dtt;
22
+
23
+
24
+	/**
25
+	 * Initial setup of data properties for the list table.
26
+	 */
27
+	protected function _setup_data()
28
+	{
29
+		$this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page);
30
+		$this->_all_data_count = $this->_admin_page->get_events(0, 0, true);
31
+	}
32
+
33
+
34
+	/**
35
+	 * Set up of additional properties for the list table.
36
+	 */
37
+	protected function _set_properties()
38
+	{
39
+		$this->_wp_list_args = array(
40
+			'singular' => esc_html__('event', 'event_espresso'),
41
+			'plural'   => esc_html__('events', 'event_espresso'),
42
+			'ajax'     => true, // for now
43
+			'screen'   => $this->_admin_page->get_current_screen()->id,
44
+		);
45
+		$this->_columns = array(
46
+			'cb'              => '<input type="checkbox" />',
47
+			'id'              => esc_html__('ID', 'event_espresso'),
48
+			'name'            => esc_html__('Name', 'event_espresso'),
49
+			'author'          => esc_html__('Author', 'event_espresso'),
50
+			'venue'           => esc_html__('Venue', 'event_espresso'),
51
+			'start_date_time' => esc_html__('Event Start', 'event_espresso'),
52
+			'reg_begins'      => esc_html__('On Sale', 'event_espresso'),
53
+			'attendees'       => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20">'
54
+								 . '<span class="screen-reader-text">'
55
+								 . esc_html__('Approved Registrations', 'event_espresso')
56
+								 . '</span>'
57
+								 . '</span>',
58
+			// 'tkts_sold' => esc_html__('Tickets Sold', 'event_espresso'),
59
+			'actions'         => esc_html__('Actions', 'event_espresso'),
60
+		);
61
+		$this->addConditionalColumns();
62
+		$this->_sortable_columns = array(
63
+			'id'              => array('EVT_ID' => true),
64
+			'name'            => array('EVT_name' => false),
65
+			'author'          => array('EVT_wp_user' => false),
66
+			'venue'           => array('Venue.VNU_name' => false),
67
+			'start_date_time' => array('Datetime.DTT_EVT_start' => false),
68
+			'reg_begins'      => array('Datetime.Ticket.TKT_start_date' => false),
69
+		);
70
+
71
+		$this->_primary_column = 'id';
72
+		$this->_hidden_columns = array('author', 'event_category');
73
+	}
74
+
75
+
76
+	/**
77
+	 * @return array
78
+	 */
79
+	protected function _get_table_filters()
80
+	{
81
+		return array(); // no filters with decaf
82
+	}
83
+
84
+
85
+	/**
86
+	 * Setup of views properties.
87
+	 *
88
+	 * @throws InvalidDataTypeException
89
+	 * @throws InvalidInterfaceException
90
+	 * @throws InvalidArgumentException
91
+	 */
92
+	protected function _add_view_counts()
93
+	{
94
+		$this->_views['all']['count'] = $this->_admin_page->total_events();
95
+		$this->_views['draft']['count'] = $this->_admin_page->total_events_draft();
96
+		if (EE_Registry::instance()->CAP->current_user_can(
97
+			'ee_delete_events',
98
+			'espresso_events_trash_events'
99
+		)) {
100
+			$this->_views['trash']['count'] = $this->_admin_page->total_trashed_events();
101
+		}
102
+	}
103
+
104
+
105
+	/**
106
+	 * @param EE_Event $item
107
+	 * @return string
108
+	 * @throws EE_Error
109
+	 */
110
+	protected function _get_row_class($item)
111
+	{
112
+		$class = parent::_get_row_class($item);
113
+		// add status class
114
+		$class .= $item instanceof EE_Event
115
+			? ' ee-status-strip event-status-' . $item->get_active_status()
116
+			: '';
117
+		if ($this->_has_checkbox_column) {
118
+			$class .= ' has-checkbox-column';
119
+		}
120
+		return $class;
121
+	}
122
+
123
+
124
+	/**
125
+	 * @param EE_Event $item
126
+	 * @return string
127
+	 * @throws EE_Error
128
+	 */
129
+	public function column_status(EE_Event $item)
130
+	{
131
+		return '<span class="ee-status-strip ee-status-strip-td event-status-'
132
+			   . $item->get_active_status()
133
+			   . '"></span>';
134
+	}
135
+
136
+
137
+	/**
138
+	 * @param  EE_Event $item
139
+	 * @return string
140
+	 * @throws EE_Error
141
+	 */
142
+	public function column_cb($item)
143
+	{
144
+		if (! $item instanceof EE_Event) {
145
+			return '';
146
+		}
147
+		$this->_dtt = $item->primary_datetime(); // set this for use in other columns
148
+		// does event have any attached registrations?
149
+		$regs = $item->count_related('Registration');
150
+		return $regs > 0 && $this->_view === 'trash'
151
+			? '<span class="ee-lock-icon"></span>'
152
+			: sprintf(
153
+				'<input type="checkbox" name="EVT_IDs[]" value="%s" />',
154
+				$item->ID()
155
+			);
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param EE_Event $item
161
+	 * @return mixed|string
162
+	 * @throws EE_Error
163
+	 */
164
+	public function column_id(EE_Event $item)
165
+	{
166
+		$content = $item->ID();
167
+		$content .= '  <span class="show-on-mobile-view-only">' . $item->name() . '</span>';
168
+		return $content;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param EE_Event $item
174
+	 * @return string
175
+	 * @throws EE_Error
176
+	 * @throws InvalidArgumentException
177
+	 * @throws InvalidDataTypeException
178
+	 * @throws InvalidInterfaceException
179
+	 */
180
+	public function column_name(EE_Event $item)
181
+	{
182
+		$edit_query_args = array(
183
+			'action' => 'edit',
184
+			'post'   => $item->ID(),
185
+		);
186
+		$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
187
+		$actions = $this->_column_name_action_setup($item);
188
+		$status = ''; // $item->status() !== 'publish' ? ' (' . $item->status() . ')' : '';
189
+		$content = '<strong><a class="row-title" href="'
190
+				   . $edit_link . '">'
191
+				   . $item->name()
192
+				   . '</a></strong>'
193
+				   . $status;
194
+		$content .= '<br><span class="ee-status-text-small">'
195
+					. EEH_Template::pretty_status(
196
+						$item->get_active_status(),
197
+						false,
198
+						'sentence'
199
+					)
200
+					. '</span>';
201
+		$content .= $this->row_actions($actions);
202
+		return $content;
203
+	}
204
+
205
+
206
+	/**
207
+	 * Just a method for setting up the actions for the name column
208
+	 *
209
+	 * @param EE_Event $item
210
+	 * @return array array of actions
211
+	 * @throws EE_Error
212
+	 * @throws InvalidArgumentException
213
+	 * @throws InvalidDataTypeException
214
+	 * @throws InvalidInterfaceException
215
+	 */
216
+	protected function _column_name_action_setup(EE_Event $item)
217
+	{
218
+		// todo: remove when attendees is active
219
+		if (! defined('REG_ADMIN_URL')) {
220
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
221
+		}
222
+		$actions = array();
223
+		$restore_event_link = '';
224
+		$delete_event_link = '';
225
+		$trash_event_link = '';
226
+		if (EE_Registry::instance()->CAP->current_user_can(
227
+			'ee_edit_event',
228
+			'espresso_events_edit',
229
+			$item->ID()
230
+		)) {
231
+			$edit_query_args = array(
232
+				'action' => 'edit',
233
+				'post'   => $item->ID(),
234
+			);
235
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
236
+			$actions['edit'] = '<a href="' . $edit_link . '"'
237
+							   . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
238
+							   . esc_html__('Edit', 'event_espresso')
239
+							   . '</a>';
240
+		}
241
+		if (EE_Registry::instance()->CAP->current_user_can(
242
+			'ee_read_registrations',
243
+			'espresso_registrations_view_registration'
244
+		)
245
+			&& EE_Registry::instance()->CAP->current_user_can(
246
+				'ee_read_event',
247
+				'espresso_registrations_view_registration',
248
+				$item->ID()
249
+			)
250
+		) {
251
+			$attendees_query_args = array(
252
+				'action'   => 'default',
253
+				'event_id' => $item->ID(),
254
+			);
255
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
256
+			$actions['attendees'] = '<a href="' . $attendees_link . '"'
257
+									. ' title="' . esc_attr__('View Registrations', 'event_espresso') . '">'
258
+									. esc_html__('Registrations', 'event_espresso')
259
+									. '</a>';
260
+		}
261
+		if (EE_Registry::instance()->CAP->current_user_can(
262
+			'ee_delete_event',
263
+			'espresso_events_trash_event',
264
+			$item->ID()
265
+		)) {
266
+			$trash_event_query_args = array(
267
+				'action' => 'trash_event',
268
+				'EVT_ID' => $item->ID(),
269
+			);
270
+			$trash_event_link = EE_Admin_Page::add_query_args_and_nonce(
271
+				$trash_event_query_args,
272
+				EVENTS_ADMIN_URL
273
+			);
274
+		}
275
+		if (EE_Registry::instance()->CAP->current_user_can(
276
+			'ee_delete_event',
277
+			'espresso_events_restore_event',
278
+			$item->ID()
279
+		)) {
280
+			$restore_event_query_args = array(
281
+				'action' => 'restore_event',
282
+				'EVT_ID' => $item->ID(),
283
+			);
284
+			$restore_event_link = EE_Admin_Page::add_query_args_and_nonce(
285
+				$restore_event_query_args,
286
+				EVENTS_ADMIN_URL
287
+			);
288
+		}
289
+		if (EE_Registry::instance()->CAP->current_user_can(
290
+			'ee_delete_event',
291
+			'espresso_events_delete_event',
292
+			$item->ID()
293
+		)) {
294
+			$delete_event_query_args = array(
295
+				'action' => 'delete_event',
296
+				'EVT_ID' => $item->ID(),
297
+			);
298
+			$delete_event_link = EE_Admin_Page::add_query_args_and_nonce(
299
+				$delete_event_query_args,
300
+				EVENTS_ADMIN_URL
301
+			);
302
+		}
303
+		$view_link = get_permalink($item->ID());
304
+		$actions['view'] = '<a href="' . $view_link . '"'
305
+						   . ' title="' . esc_attr__('View Event', 'event_espresso') . '">'
306
+						   . esc_html__('View', 'event_espresso')
307
+						   . '</a>';
308
+		if ($item->get('status') === 'trash') {
309
+			if (EE_Registry::instance()->CAP->current_user_can(
310
+				'ee_delete_event',
311
+				'espresso_events_restore_event',
312
+				$item->ID()
313
+			)) {
314
+				$actions['restore_from_trash'] = '<a href="' . $restore_event_link . '"'
315
+												 . ' title="' . esc_attr__('Restore from Trash', 'event_espresso')
316
+												 . '">'
317
+												 . esc_html__('Restore from Trash', 'event_espresso')
318
+												 . '</a>';
319
+			}
320
+			if ($item->count_related('Registration') === 0
321
+				&& EE_Registry::instance()->CAP->current_user_can(
322
+					'ee_delete_event',
323
+					'espresso_events_delete_event',
324
+					$item->ID()
325
+				)
326
+			) {
327
+				$actions['delete'] = '<a href="' . $delete_event_link . '"'
328
+									 . ' title="' . esc_attr__('Delete Permanently', 'event_espresso') . '">'
329
+									 . esc_html__('Delete Permanently', 'event_espresso')
330
+									 . '</a>';
331
+			}
332
+		} else {
333
+			if (EE_Registry::instance()->CAP->current_user_can(
334
+				'ee_delete_event',
335
+				'espresso_events_trash_event',
336
+				$item->ID()
337
+			)) {
338
+				$actions['move to trash'] = '<a href="' . $trash_event_link . '"'
339
+											. ' title="' . esc_attr__('Trash Event', 'event_espresso') . '">'
340
+											. esc_html__('Trash', 'event_espresso')
341
+											. '</a>';
342
+			}
343
+		}
344
+		return $actions;
345
+	}
346
+
347
+
348
+	/**
349
+	 * @param EE_Event $item
350
+	 * @return string
351
+	 * @throws EE_Error
352
+	 */
353
+	public function column_author(EE_Event $item)
354
+	{
355
+		// user author info
356
+		$event_author = get_userdata($item->wp_user());
357
+		$gravatar = get_avatar($item->wp_user(), '15');
358
+		// filter link
359
+		$query_args = array(
360
+			'action'      => 'default',
361
+			'EVT_wp_user' => $item->wp_user(),
362
+		);
363
+		$filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL);
364
+		return $gravatar . '  <a href="' . $filter_url . '"'
365
+			   . ' title="' . esc_attr__('Click to filter events by this author.', 'event_espresso') . '">'
366
+			   . $event_author->display_name
367
+			   . '</a>';
368
+	}
369
+
370
+
371
+	/**
372
+	 * @param EE_Event $event
373
+	 * @return string
374
+	 * @throws EE_Error
375
+	 */
376
+	public function column_event_category(EE_Event $event)
377
+	{
378
+		$event_categories = $event->get_all_event_categories();
379
+		return implode(
380
+			', ',
381
+			array_map(
382
+				function (EE_Term $category) {
383
+					return $category->name();
384
+				},
385
+				$event_categories
386
+			)
387
+		);
388
+	}
389
+
390
+
391
+	/**
392
+	 * @param EE_Event $item
393
+	 * @return string
394
+	 * @throws EE_Error
395
+	 */
396
+	public function column_venue(EE_Event $item)
397
+	{
398
+		$venue = $item->get_first_related('Venue');
399
+		return ! empty($venue)
400
+			? $venue->name()
401
+			: '';
402
+	}
403
+
404
+
405
+	/**
406
+	 * @param EE_Event $item
407
+	 * @return string
408
+	 * @throws EE_Error
409
+	 */
410
+	public function column_start_date_time(EE_Event $item)
411
+	{
412
+		return $this->_dtt instanceof EE_Datetime
413
+			? $this->_dtt->get_i18n_datetime('DTT_EVT_start')
414
+			: esc_html__('No Date was saved for this Event', 'event_espresso');
415
+	}
416
+
417
+
418
+	/**
419
+	 * @param EE_Event $item
420
+	 * @return string
421
+	 * @throws EE_Error
422
+	 */
423
+	public function column_reg_begins(EE_Event $item)
424
+	{
425
+		$reg_start = $item->get_ticket_with_earliest_start_time();
426
+		return $reg_start instanceof EE_Ticket
427
+			? $reg_start->get_i18n_datetime('TKT_start_date')
428
+			: esc_html__('No Tickets have been setup for this Event', 'event_espresso');
429
+	}
430
+
431
+
432
+	/**
433
+	 * @param EE_Event $item
434
+	 * @return int|string
435
+	 * @throws EE_Error
436
+	 * @throws InvalidArgumentException
437
+	 * @throws InvalidDataTypeException
438
+	 * @throws InvalidInterfaceException
439
+	 */
440
+	public function column_attendees(EE_Event $item)
441
+	{
442
+		$attendees_query_args = array(
443
+			'action'   => 'default',
444
+			'event_id' => $item->ID(),
445
+		);
446
+		$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
447
+		$registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID());
448
+		return EE_Registry::instance()->CAP->current_user_can(
449
+			'ee_read_event',
450
+			'espresso_registrations_view_registration',
451
+			$item->ID()
452
+		)
453
+			   && EE_Registry::instance()->CAP->current_user_can(
454
+				   'ee_read_registrations',
455
+				   'espresso_registrations_view_registration'
456
+			   )
457
+			? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>'
458
+			: $registered_attendees;
459
+	}
460
+
461
+
462
+	/**
463
+	 * @param EE_Event $item
464
+	 * @return float
465
+	 * @throws EE_Error
466
+	 * @throws InvalidArgumentException
467
+	 * @throws InvalidDataTypeException
468
+	 * @throws InvalidInterfaceException
469
+	 */
470
+	public function column_tkts_sold(EE_Event $item)
471
+	{
472
+		return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold');
473
+	}
474
+
475
+
476
+	/**
477
+	 * @param EE_Event $item
478
+	 * @return string
479
+	 * @throws EE_Error
480
+	 * @throws InvalidArgumentException
481
+	 * @throws InvalidDataTypeException
482
+	 * @throws InvalidInterfaceException
483
+	 */
484
+	public function column_actions(EE_Event $item)
485
+	{
486
+		// todo: remove when attendees is active
487
+		if (! defined('REG_ADMIN_URL')) {
488
+			define('REG_ADMIN_URL', EVENTS_ADMIN_URL);
489
+		}
490
+		$action_links = array();
491
+		$view_link = get_permalink($item->ID());
492
+		$action_links[] = '<a href="' . $view_link . '"'
493
+						  . ' title="' . esc_attr__('View Event', 'event_espresso') . '" target="_blank">';
494
+		$action_links[] = '<div class="dashicons dashicons-search"></div></a>';
495
+		if (EE_Registry::instance()->CAP->current_user_can(
496
+			'ee_edit_event',
497
+			'espresso_events_edit',
498
+			$item->ID()
499
+		)) {
500
+			$edit_query_args = array(
501
+				'action' => 'edit',
502
+				'post'   => $item->ID(),
503
+			);
504
+			$edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL);
505
+			$action_links[] = '<a href="' . $edit_link . '"'
506
+							  . ' title="' . esc_attr__('Edit Event', 'event_espresso') . '">'
507
+							  . '<div class="ee-icon ee-icon-calendar-edit"></div>'
508
+							  . '</a>';
509
+		}
510
+		if (EE_Registry::instance()->CAP->current_user_can(
511
+			'ee_read_registrations',
512
+			'espresso_registrations_view_registration'
513
+		) && EE_Registry::instance()->CAP->current_user_can(
514
+			'ee_read_event',
515
+			'espresso_registrations_view_registration',
516
+			$item->ID()
517
+		)
518
+		) {
519
+			$attendees_query_args = array(
520
+				'action'   => 'default',
521
+				'event_id' => $item->ID(),
522
+			);
523
+			$attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL);
524
+			$action_links[] = '<a href="' . $attendees_link . '"'
525
+							  . ' title="' . esc_attr__('View Registrants', 'event_espresso') . '">'
526
+							  . '<div class="dashicons dashicons-groups"></div>'
527
+							  . '</a>';
528
+		}
529
+		$action_links = apply_filters(
530
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
531
+			$action_links,
532
+			$item
533
+		);
534
+		return $this->_action_string(
535
+			implode("\n\t", $action_links),
536
+			$item,
537
+			'div'
538
+		);
539
+	}
540
+
541
+
542
+	/**
543
+	 * Helper for adding columns conditionally
544
+	 *
545
+	 * @throws EE_Error
546
+	 * @throws InvalidArgumentException
547
+	 * @throws InvalidDataTypeException
548
+	 * @throws InvalidInterfaceException
549
+	 */
550
+	private function addConditionalColumns()
551
+	{
552
+		$event_category_count = EEM_Term::instance()->count(
553
+			[['Term_Taxonomy.taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY]]
554
+		);
555
+		if ($event_category_count === 0) {
556
+			return;
557
+		}
558
+		$column_array = [];
559
+		foreach ($this->_columns as $column => $column_label) {
560
+			$column_array[ $column ] = $column_label;
561
+			if ($column === 'venue') {
562
+				$column_array['event_category'] = esc_html__('Event Category', 'event_espresso');
563
+			}
564
+		}
565
+		$this->_columns = $column_array;
566
+	}
567 567
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Registration.class.php 3 patches
Doc Comments   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1164,7 +1164,7 @@  discard block
 block discarded – undo
1164 1164
      * Sets deleted
1165 1165
      *
1166 1166
      * @param boolean $deleted
1167
-     * @return bool
1167
+     * @return boolean|null
1168 1168
      * @throws EE_Error
1169 1169
      * @throws RuntimeException
1170 1170
      */
@@ -1222,6 +1222,7 @@  discard block
 block discarded – undo
1222 1222
      * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1223 1223
      * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1224 1224
      *                                          consider registration status as well as datetime access.
1225
+     * @param integer $DTT_OR_ID
1225 1226
      * @return bool
1226 1227
      * @throws EE_Error
1227 1228
      */
@@ -1392,7 +1393,7 @@  discard block
 block discarded – undo
1392 1393
      * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1393 1394
      * "Latest" is defined by the `DTT_EVT_start` column.
1394 1395
      *
1395
-     * @return EE_Datetime|null
1396
+     * @return null|EE_Base_Class
1396 1397
      * @throws EE_Error
1397 1398
      */
1398 1399
     public function get_latest_related_datetime()
@@ -1688,7 +1689,7 @@  discard block
 block discarded – undo
1688 1689
      * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1689 1690
      * Note: if there are no payments on the registration there will be no payment method returned.
1690 1691
      *
1691
-     * @return EE_Payment_Method|null
1692
+     * @return null|EE_Base_Class
1692 1693
      */
1693 1694
     public function payment_method()
1694 1695
     {
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     {
120 120
         switch ($field_name) {
121 121
             case 'REG_code':
122
-                if (! empty($field_value) && $this->reg_code() === null) {
122
+                if ( ! empty($field_value) && $this->reg_code() === null) {
123 123
                     $this->set_reg_code($field_value, $use_default);
124 124
                 }
125 125
                 break;
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
     public function event()
401 401
     {
402 402
         $event = $this->get_first_related('Event');
403
-        if (! $event instanceof \EE_Event) {
403
+        if ( ! $event instanceof \EE_Event) {
404 404
             throw new EntityNotFoundException('Event ID', $this->event_ID());
405 405
         }
406 406
         return $event;
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
     {
444 444
         // reserved ticket and datetime counts will be decremented as sold counts are incremented
445 445
         // so stop tracking that this reg has a ticket reserved
446
-        $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
446
+        $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:".__LINE__.')');
447 447
         $ticket = $this->ticket();
448 448
         $ticket->increaseSold();
449 449
         // possibly set event status to sold out
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
                 && $update_ticket
498 498
             ) {
499 499
                 $ticket = $this->ticket();
500
-                $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
500
+                $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:".__LINE__.')');
501 501
                 $ticket->save();
502 502
             }
503 503
         }
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
                 && $update_ticket
529 529
             ) {
530 530
                 $ticket = $this->ticket();
531
-                $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
531
+                $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:".__LINE__.')');
532 532
             }
533 533
         }
534 534
     }
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
                     : '';
1203 1203
                 break;
1204 1204
         }
1205
-        return $icon . $status[ $this->status_ID() ];
1205
+        return $icon.$status[$this->status_ID()];
1206 1206
     }
1207 1207
 
1208 1208
 
@@ -1420,7 +1420,7 @@  discard block
 block discarded – undo
1420 1420
             return false;
1421 1421
         }
1422 1422
         // is there a datetime ticket that matches this dtt_ID?
1423
-        if (! (EEM_Datetime_Ticket::instance()->exists(
1423
+        if ( ! (EEM_Datetime_Ticket::instance()->exists(
1424 1424
             array(
1425 1425
                 array(
1426 1426
                     'TKT_ID' => $this->get('TKT_ID'),
@@ -1451,7 +1451,7 @@  discard block
 block discarded – undo
1451 1451
     {
1452 1452
         $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1453 1453
 
1454
-        if (! $DTT_ID) {
1454
+        if ( ! $DTT_ID) {
1455 1455
             return false;
1456 1456
         }
1457 1457
 
@@ -1459,7 +1459,7 @@  discard block
 block discarded – undo
1459 1459
 
1460 1460
         // if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1461 1461
         // check-in or not.
1462
-        if (! $max_uses || $max_uses === EE_INF) {
1462
+        if ( ! $max_uses || $max_uses === EE_INF) {
1463 1463
             return true;
1464 1464
         }
1465 1465
 
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
             $datetime = $this->get_latest_related_datetime();
1520 1520
             $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1521 1521
             // verify the registration can checkin for the given DTT_ID
1522
-        } elseif (! $this->can_checkin($DTT_ID, $verify)) {
1522
+        } elseif ( ! $this->can_checkin($DTT_ID, $verify)) {
1523 1523
             EE_Error::add_error(
1524 1524
                 sprintf(
1525 1525
                     esc_html__(
@@ -1542,7 +1542,7 @@  discard block
 block discarded – undo
1542 1542
         );
1543 1543
         // start by getting the current status so we know what status we'll be changing to.
1544 1544
         $cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1545
-        $status_to = $status_paths[ $cur_status ];
1545
+        $status_to = $status_paths[$cur_status];
1546 1546
         // database only records true for checked IN or false for checked OUT
1547 1547
         // no record ( null ) means checked in NEVER, but we obviously don't save that
1548 1548
         $new_status = $status_to === EE_Checkin::status_checked_in ? true : false;
@@ -1707,7 +1707,7 @@  discard block
 block discarded – undo
1707 1707
     public function transaction()
1708 1708
     {
1709 1709
         $transaction = $this->get_first_related('Transaction');
1710
-        if (! $transaction instanceof \EE_Transaction) {
1710
+        if ( ! $transaction instanceof \EE_Transaction) {
1711 1711
             throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1712 1712
         }
1713 1713
         return $transaction;
@@ -1761,11 +1761,11 @@  discard block
 block discarded – undo
1761 1761
             );
1762 1762
             return;
1763 1763
         }
1764
-        if (! $this->reg_code()) {
1764
+        if ( ! $this->reg_code()) {
1765 1765
             parent::set('REG_code', $REG_code, $use_default);
1766 1766
         } else {
1767 1767
             EE_Error::doing_it_wrong(
1768
-                __CLASS__ . '::' . __FUNCTION__,
1768
+                __CLASS__.'::'.__FUNCTION__,
1769 1769
                 esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1770 1770
                 '4.6.0'
1771 1771
             );
@@ -1916,7 +1916,7 @@  discard block
 block discarded – undo
1916 1916
                 break;
1917 1917
             }
1918 1918
         }
1919
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1919
+        if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1920 1920
             throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1921 1921
         }
1922 1922
         return $line_item;
Please login to merge, or discard this patch.
Indentation   +2065 added lines, -2065 removed lines patch added patch discarded remove patch
@@ -17,2069 +17,2069 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Used to reference when a registration has never been checked in.
22
-     *
23
-     * @deprecated use \EE_Checkin::status_checked_never instead
24
-     * @type int
25
-     */
26
-    const checkin_status_never = 2;
27
-
28
-    /**
29
-     * Used to reference when a registration has been checked in.
30
-     *
31
-     * @deprecated use \EE_Checkin::status_checked_in instead
32
-     * @type int
33
-     */
34
-    const checkin_status_in = 1;
35
-
36
-
37
-    /**
38
-     * Used to reference when a registration has been checked out.
39
-     *
40
-     * @deprecated use \EE_Checkin::status_checked_out instead
41
-     * @type int
42
-     */
43
-    const checkin_status_out = 0;
44
-
45
-
46
-    /**
47
-     * extra meta key for tracking reg status os trashed registrations
48
-     *
49
-     * @type string
50
-     */
51
-    const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
52
-
53
-
54
-    /**
55
-     * extra meta key for tracking if registration has reserved ticket
56
-     *
57
-     * @type string
58
-     */
59
-    const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
60
-
61
-
62
-    /**
63
-     * @param array  $props_n_values          incoming values
64
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
65
-     *                                        used.)
66
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
67
-     *                                        date_format and the second value is the time format
68
-     * @return EE_Registration
69
-     * @throws EE_Error
70
-     */
71
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
72
-    {
73
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
74
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
75
-    }
76
-
77
-
78
-    /**
79
-     * @param array  $props_n_values  incoming values from the database
80
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
81
-     *                                the website will be used.
82
-     * @return EE_Registration
83
-     */
84
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
85
-    {
86
-        return new self($props_n_values, true, $timezone);
87
-    }
88
-
89
-
90
-    /**
91
-     *        Set Event ID
92
-     *
93
-     * @param        int $EVT_ID Event ID
94
-     * @throws EE_Error
95
-     * @throws RuntimeException
96
-     */
97
-    public function set_event($EVT_ID = 0)
98
-    {
99
-        $this->set('EVT_ID', $EVT_ID);
100
-    }
101
-
102
-
103
-    /**
104
-     * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
105
-     * be routed to internal methods
106
-     *
107
-     * @param string $field_name
108
-     * @param mixed  $field_value
109
-     * @param bool   $use_default
110
-     * @throws EE_Error
111
-     * @throws EntityNotFoundException
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     * @throws ReflectionException
116
-     * @throws RuntimeException
117
-     */
118
-    public function set($field_name, $field_value, $use_default = false)
119
-    {
120
-        switch ($field_name) {
121
-            case 'REG_code':
122
-                if (! empty($field_value) && $this->reg_code() === null) {
123
-                    $this->set_reg_code($field_value, $use_default);
124
-                }
125
-                break;
126
-            case 'STS_ID':
127
-                $this->set_status($field_value, $use_default);
128
-                break;
129
-            default:
130
-                parent::set($field_name, $field_value, $use_default);
131
-        }
132
-    }
133
-
134
-
135
-    /**
136
-     * Set Status ID
137
-     * updates the registration status and ALSO...
138
-     * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
139
-     * calls release_registration_space() if the reg status changes FROM approved to any other reg status
140
-     *
141
-     * @param string                $new_STS_ID
142
-     * @param boolean               $use_default
143
-     * @param ContextInterface|null $context
144
-     * @return bool
145
-     * @throws DomainException
146
-     * @throws EE_Error
147
-     * @throws EntityNotFoundException
148
-     * @throws InvalidArgumentException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidInterfaceException
151
-     * @throws ReflectionException
152
-     * @throws RuntimeException
153
-     * @throws UnexpectedEntityException
154
-     */
155
-    public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null)
156
-    {
157
-        // get current REG_Status
158
-        $old_STS_ID = $this->status_ID();
159
-        // if status has changed
160
-        if ($old_STS_ID !== $new_STS_ID // and that status has actually changed
161
-            && ! empty($old_STS_ID) // and that old status is actually set
162
-            && ! empty($new_STS_ID) // as well as the new status
163
-            && $this->ID() // ensure registration is in the db
164
-        ) {
165
-            // update internal status first
166
-            parent::set('STS_ID', $new_STS_ID, $use_default);
167
-            // THEN handle other changes that occur when reg status changes
168
-            // TO approved
169
-            if ($new_STS_ID === EEM_Registration::status_id_approved) {
170
-                // reserve a space by incrementing ticket and datetime sold values
171
-                $this->reserveRegistrationSpace();
172
-                do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context);
173
-                // OR FROM  approved
174
-            } elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
175
-                // release a space by decrementing ticket and datetime sold values
176
-                $this->releaseRegistrationSpace();
177
-                do_action(
178
-                    'AHEE__EE_Registration__set_status__from_approved',
179
-                    $this,
180
-                    $old_STS_ID,
181
-                    $new_STS_ID,
182
-                    $context
183
-                );
184
-            }
185
-            // update status
186
-            parent::set('STS_ID', $new_STS_ID, $use_default);
187
-            $this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context);
188
-            if ($this->statusChangeUpdatesTransaction($context)) {
189
-                $this->updateTransactionAfterStatusChange();
190
-            }
191
-            do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context);
192
-            return true;
193
-        }
194
-        // even though the old value matches the new value, it's still good to
195
-        // allow the parent set method to have a say
196
-        parent::set('STS_ID', $new_STS_ID, $use_default);
197
-        return true;
198
-    }
199
-
200
-
201
-    /**
202
-     * update REGs and TXN when cancelled or declined registrations involved
203
-     *
204
-     * @param string                $new_STS_ID
205
-     * @param string                $old_STS_ID
206
-     * @param ContextInterface|null $context
207
-     * @throws EE_Error
208
-     * @throws InvalidArgumentException
209
-     * @throws InvalidDataTypeException
210
-     * @throws InvalidInterfaceException
211
-     * @throws ReflectionException
212
-     * @throws RuntimeException
213
-     */
214
-    private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null)
215
-    {
216
-        // these reg statuses should not be considered in any calculations involving monies owing
217
-        $closed_reg_statuses = EEM_Registration::closed_reg_statuses();
218
-        // true if registration has been cancelled or declined
219
-        $this->updateIfCanceled(
220
-            $closed_reg_statuses,
221
-            $new_STS_ID,
222
-            $old_STS_ID,
223
-            $context
224
-        );
225
-        $this->updateIfReinstated(
226
-            $closed_reg_statuses,
227
-            $new_STS_ID,
228
-            $old_STS_ID,
229
-            $context
230
-        );
231
-    }
232
-
233
-
234
-    /**
235
-     * update REGs and TXN when cancelled or declined registrations involved
236
-     *
237
-     * @param array                 $closed_reg_statuses
238
-     * @param string                $new_STS_ID
239
-     * @param string                $old_STS_ID
240
-     * @param ContextInterface|null $context
241
-     * @throws EE_Error
242
-     * @throws InvalidArgumentException
243
-     * @throws InvalidDataTypeException
244
-     * @throws InvalidInterfaceException
245
-     * @throws ReflectionException
246
-     * @throws RuntimeException
247
-     */
248
-    private function updateIfCanceled(
249
-        array $closed_reg_statuses,
250
-        $new_STS_ID,
251
-        $old_STS_ID,
252
-        ContextInterface $context = null
253
-    ) {
254
-        // true if registration has been cancelled or declined
255
-        if (in_array($new_STS_ID, $closed_reg_statuses, true)
256
-            && ! in_array($old_STS_ID, $closed_reg_statuses, true)
257
-        ) {
258
-            /** @type EE_Registration_Processor $registration_processor */
259
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
260
-            /** @type EE_Transaction_Processor $transaction_processor */
261
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
262
-            // cancelled or declined registration
263
-            $registration_processor->update_registration_after_being_canceled_or_declined(
264
-                $this,
265
-                $closed_reg_statuses
266
-            );
267
-            $transaction_processor->update_transaction_after_canceled_or_declined_registration(
268
-                $this,
269
-                $closed_reg_statuses,
270
-                false
271
-            );
272
-            do_action(
273
-                'AHEE__EE_Registration__set_status__canceled_or_declined',
274
-                $this,
275
-                $old_STS_ID,
276
-                $new_STS_ID,
277
-                $context
278
-            );
279
-            return;
280
-        }
281
-    }
282
-
283
-
284
-    /**
285
-     * update REGs and TXN when cancelled or declined registrations involved
286
-     *
287
-     * @param array                 $closed_reg_statuses
288
-     * @param string                $new_STS_ID
289
-     * @param string                $old_STS_ID
290
-     * @param ContextInterface|null $context
291
-     * @throws EE_Error
292
-     * @throws InvalidArgumentException
293
-     * @throws InvalidDataTypeException
294
-     * @throws InvalidInterfaceException
295
-     * @throws ReflectionException
296
-     */
297
-    private function updateIfReinstated(
298
-        array $closed_reg_statuses,
299
-        $new_STS_ID,
300
-        $old_STS_ID,
301
-        ContextInterface $context = null
302
-    ) {
303
-        // true if reinstating cancelled or declined registration
304
-        if (in_array($old_STS_ID, $closed_reg_statuses, true)
305
-            && ! in_array($new_STS_ID, $closed_reg_statuses, true)
306
-        ) {
307
-            /** @type EE_Registration_Processor $registration_processor */
308
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
309
-            /** @type EE_Transaction_Processor $transaction_processor */
310
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
311
-            // reinstating cancelled or declined registration
312
-            $registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
313
-                $this,
314
-                $closed_reg_statuses
315
-            );
316
-            $transaction_processor->update_transaction_after_reinstating_canceled_registration(
317
-                $this,
318
-                $closed_reg_statuses,
319
-                false
320
-            );
321
-            do_action(
322
-                'AHEE__EE_Registration__set_status__after_reinstated',
323
-                $this,
324
-                $old_STS_ID,
325
-                $new_STS_ID,
326
-                $context
327
-            );
328
-        }
329
-    }
330
-
331
-
332
-    /**
333
-     * @param ContextInterface|null $context
334
-     * @return bool
335
-     */
336
-    private function statusChangeUpdatesTransaction(ContextInterface $context = null)
337
-    {
338
-        $contexts_that_do_not_update_transaction = (array) apply_filters(
339
-            'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction',
340
-            array('spco_reg_step_attendee_information_process_registrations'),
341
-            $context,
342
-            $this
343
-        );
344
-        return ! (
345
-            $context instanceof ContextInterface
346
-            && in_array($context->slug(), $contexts_that_do_not_update_transaction, true)
347
-        );
348
-    }
349
-
350
-
351
-    /**
352
-     * @throws EE_Error
353
-     * @throws EntityNotFoundException
354
-     * @throws InvalidArgumentException
355
-     * @throws InvalidDataTypeException
356
-     * @throws InvalidInterfaceException
357
-     * @throws ReflectionException
358
-     * @throws RuntimeException
359
-     */
360
-    private function updateTransactionAfterStatusChange()
361
-    {
362
-        /** @type EE_Transaction_Payments $transaction_payments */
363
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
364
-        $transaction_payments->recalculate_transaction_total($this->transaction(), false);
365
-        $this->transaction()->update_status_based_on_total_paid(true);
366
-    }
367
-
368
-
369
-    /**
370
-     *        get Status ID
371
-     */
372
-    public function status_ID()
373
-    {
374
-        return $this->get('STS_ID');
375
-    }
376
-
377
-
378
-    /**
379
-     * Gets the ticket this registration is for
380
-     *
381
-     * @param boolean $include_archived whether to include archived tickets or not.
382
-     *
383
-     * @return EE_Ticket|EE_Base_Class
384
-     * @throws EE_Error
385
-     */
386
-    public function ticket($include_archived = true)
387
-    {
388
-        $query_params = array();
389
-        if ($include_archived) {
390
-            $query_params['default_where_conditions'] = 'none';
391
-        }
392
-        return $this->get_first_related('Ticket', $query_params);
393
-    }
394
-
395
-
396
-    /**
397
-     * Gets the event this registration is for
398
-     *
399
-     * @return EE_Event
400
-     * @throws EE_Error
401
-     * @throws EntityNotFoundException
402
-     */
403
-    public function event()
404
-    {
405
-        $event = $this->get_first_related('Event');
406
-        if (! $event instanceof \EE_Event) {
407
-            throw new EntityNotFoundException('Event ID', $this->event_ID());
408
-        }
409
-        return $event;
410
-    }
411
-
412
-
413
-    /**
414
-     * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
415
-     * with the author of the event this registration is for.
416
-     *
417
-     * @since 4.5.0
418
-     * @return int
419
-     * @throws EE_Error
420
-     * @throws EntityNotFoundException
421
-     */
422
-    public function wp_user()
423
-    {
424
-        $event = $this->event();
425
-        if ($event instanceof EE_Event) {
426
-            return $event->wp_user();
427
-        }
428
-        return 0;
429
-    }
430
-
431
-
432
-    /**
433
-     * increments this registration's related ticket sold and corresponding datetime sold values
434
-     *
435
-     * @return void
436
-     * @throws DomainException
437
-     * @throws EE_Error
438
-     * @throws EntityNotFoundException
439
-     * @throws InvalidArgumentException
440
-     * @throws InvalidDataTypeException
441
-     * @throws InvalidInterfaceException
442
-     * @throws ReflectionException
443
-     * @throws UnexpectedEntityException
444
-     */
445
-    private function reserveRegistrationSpace()
446
-    {
447
-        // reserved ticket and datetime counts will be decremented as sold counts are incremented
448
-        // so stop tracking that this reg has a ticket reserved
449
-        $this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
450
-        $ticket = $this->ticket();
451
-        $ticket->increaseSold();
452
-        // possibly set event status to sold out
453
-        $this->event()->perform_sold_out_status_check();
454
-    }
455
-
456
-
457
-    /**
458
-     * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
459
-     *
460
-     * @return void
461
-     * @throws DomainException
462
-     * @throws EE_Error
463
-     * @throws EntityNotFoundException
464
-     * @throws InvalidArgumentException
465
-     * @throws InvalidDataTypeException
466
-     * @throws InvalidInterfaceException
467
-     * @throws ReflectionException
468
-     * @throws UnexpectedEntityException
469
-     */
470
-    private function releaseRegistrationSpace()
471
-    {
472
-        $ticket = $this->ticket();
473
-        $ticket->decreaseSold();
474
-        // possibly change event status from sold out back to previous status
475
-        $this->event()->perform_sold_out_status_check();
476
-    }
477
-
478
-
479
-    /**
480
-     * tracks this registration's ticket reservation in extra meta
481
-     * and can increment related ticket reserved and corresponding datetime reserved values
482
-     *
483
-     * @param bool $update_ticket if true, will increment ticket and datetime reserved count
484
-     * @return void
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws InvalidDataTypeException
488
-     * @throws InvalidInterfaceException
489
-     * @throws ReflectionException
490
-     */
491
-    public function reserve_ticket($update_ticket = false, $source = 'unknown')
492
-    {
493
-        // only reserve ticket if space is not currently reserved
494
-        if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) {
495
-            $this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}");
496
-            // IMPORTANT !!!
497
-            // although checking $update_ticket first would be more efficient,
498
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
499
-            if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true)
500
-                && $update_ticket
501
-            ) {
502
-                $ticket = $this->ticket();
503
-                $ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
504
-                $ticket->save();
505
-            }
506
-        }
507
-    }
508
-
509
-
510
-    /**
511
-     * stops tracking this registration's ticket reservation in extra meta
512
-     * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
513
-     *
514
-     * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
515
-     * @return void
516
-     * @throws EE_Error
517
-     * @throws InvalidArgumentException
518
-     * @throws InvalidDataTypeException
519
-     * @throws InvalidInterfaceException
520
-     * @throws ReflectionException
521
-     */
522
-    public function release_reserved_ticket($update_ticket = false, $source = 'unknown')
523
-    {
524
-        // only release ticket if space is currently reserved
525
-        if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) {
526
-            $this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}");
527
-            // IMPORTANT !!!
528
-            // although checking $update_ticket first would be more efficient,
529
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
530
-            if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false)
531
-                && $update_ticket
532
-            ) {
533
-                $ticket = $this->ticket();
534
-                $ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
535
-            }
536
-        }
537
-    }
538
-
539
-
540
-    /**
541
-     * Set Attendee ID
542
-     *
543
-     * @param        int $ATT_ID Attendee ID
544
-     * @throws EE_Error
545
-     * @throws RuntimeException
546
-     */
547
-    public function set_attendee_id($ATT_ID = 0)
548
-    {
549
-        $this->set('ATT_ID', $ATT_ID);
550
-    }
551
-
552
-
553
-    /**
554
-     *        Set Transaction ID
555
-     *
556
-     * @param        int $TXN_ID Transaction ID
557
-     * @throws EE_Error
558
-     * @throws RuntimeException
559
-     */
560
-    public function set_transaction_id($TXN_ID = 0)
561
-    {
562
-        $this->set('TXN_ID', $TXN_ID);
563
-    }
564
-
565
-
566
-    /**
567
-     *        Set Session
568
-     *
569
-     * @param    string $REG_session PHP Session ID
570
-     * @throws EE_Error
571
-     * @throws RuntimeException
572
-     */
573
-    public function set_session($REG_session = '')
574
-    {
575
-        $this->set('REG_session', $REG_session);
576
-    }
577
-
578
-
579
-    /**
580
-     *        Set Registration URL Link
581
-     *
582
-     * @param    string $REG_url_link Registration URL Link
583
-     * @throws EE_Error
584
-     * @throws RuntimeException
585
-     */
586
-    public function set_reg_url_link($REG_url_link = '')
587
-    {
588
-        $this->set('REG_url_link', $REG_url_link);
589
-    }
590
-
591
-
592
-    /**
593
-     *        Set Attendee Counter
594
-     *
595
-     * @param        int $REG_count Primary Attendee
596
-     * @throws EE_Error
597
-     * @throws RuntimeException
598
-     */
599
-    public function set_count($REG_count = 1)
600
-    {
601
-        $this->set('REG_count', $REG_count);
602
-    }
603
-
604
-
605
-    /**
606
-     *        Set Group Size
607
-     *
608
-     * @param        boolean $REG_group_size Group Registration
609
-     * @throws EE_Error
610
-     * @throws RuntimeException
611
-     */
612
-    public function set_group_size($REG_group_size = false)
613
-    {
614
-        $this->set('REG_group_size', $REG_group_size);
615
-    }
616
-
617
-
618
-    /**
619
-     *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
620
-     *    EEM_Registration::status_id_not_approved
621
-     *
622
-     * @return        boolean
623
-     */
624
-    public function is_not_approved()
625
-    {
626
-        return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
627
-    }
628
-
629
-
630
-    /**
631
-     *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
632
-     *    EEM_Registration::status_id_pending_payment
633
-     *
634
-     * @return        boolean
635
-     */
636
-    public function is_pending_payment()
637
-    {
638
-        return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
639
-    }
640
-
641
-
642
-    /**
643
-     *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
644
-     *
645
-     * @return        boolean
646
-     */
647
-    public function is_approved()
648
-    {
649
-        return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
650
-    }
651
-
652
-
653
-    /**
654
-     *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
655
-     *
656
-     * @return        boolean
657
-     */
658
-    public function is_cancelled()
659
-    {
660
-        return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
661
-    }
662
-
663
-
664
-    /**
665
-     *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
666
-     *
667
-     * @return        boolean
668
-     */
669
-    public function is_declined()
670
-    {
671
-        return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
672
-    }
673
-
674
-
675
-    /**
676
-     *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
677
-     *    EEM_Registration::status_id_incomplete
678
-     *
679
-     * @return        boolean
680
-     */
681
-    public function is_incomplete()
682
-    {
683
-        return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
684
-    }
685
-
686
-
687
-    /**
688
-     *        Set Registration Date
689
-     *
690
-     * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
691
-     *                                                 Date
692
-     * @throws EE_Error
693
-     * @throws RuntimeException
694
-     */
695
-    public function set_reg_date($REG_date = false)
696
-    {
697
-        $this->set('REG_date', $REG_date);
698
-    }
699
-
700
-
701
-    /**
702
-     *    Set final price owing for this registration after all ticket/price modifications
703
-     *
704
-     * @access    public
705
-     * @param    float $REG_final_price
706
-     * @throws EE_Error
707
-     * @throws RuntimeException
708
-     */
709
-    public function set_final_price($REG_final_price = 0.00)
710
-    {
711
-        $this->set('REG_final_price', $REG_final_price);
712
-    }
713
-
714
-
715
-    /**
716
-     *    Set amount paid towards this registration's final price
717
-     *
718
-     * @access    public
719
-     * @param    float $REG_paid
720
-     * @throws EE_Error
721
-     * @throws RuntimeException
722
-     */
723
-    public function set_paid($REG_paid = 0.00)
724
-    {
725
-        $this->set('REG_paid', $REG_paid);
726
-    }
727
-
728
-
729
-    /**
730
-     *        Attendee Is Going
731
-     *
732
-     * @param        boolean $REG_att_is_going Attendee Is Going
733
-     * @throws EE_Error
734
-     * @throws RuntimeException
735
-     */
736
-    public function set_att_is_going($REG_att_is_going = false)
737
-    {
738
-        $this->set('REG_att_is_going', $REG_att_is_going);
739
-    }
740
-
741
-
742
-    /**
743
-     * Gets the related attendee
744
-     *
745
-     * @return EE_Attendee
746
-     * @throws EE_Error
747
-     */
748
-    public function attendee()
749
-    {
750
-        return $this->get_first_related('Attendee');
751
-    }
752
-
753
-
754
-    /**
755
-     *        get Event ID
756
-     */
757
-    public function event_ID()
758
-    {
759
-        return $this->get('EVT_ID');
760
-    }
761
-
762
-
763
-    /**
764
-     *        get Event ID
765
-     */
766
-    public function event_name()
767
-    {
768
-        $event = $this->event_obj();
769
-        if ($event) {
770
-            return $event->name();
771
-        } else {
772
-            return null;
773
-        }
774
-    }
775
-
776
-
777
-    /**
778
-     * Fetches the event this registration is for
779
-     *
780
-     * @return EE_Event
781
-     * @throws EE_Error
782
-     */
783
-    public function event_obj()
784
-    {
785
-        return $this->get_first_related('Event');
786
-    }
787
-
788
-
789
-    /**
790
-     *        get Attendee ID
791
-     */
792
-    public function attendee_ID()
793
-    {
794
-        return $this->get('ATT_ID');
795
-    }
796
-
797
-
798
-    /**
799
-     *        get PHP Session ID
800
-     */
801
-    public function session_ID()
802
-    {
803
-        return $this->get('REG_session');
804
-    }
805
-
806
-
807
-    /**
808
-     * Gets the string which represents the URL trigger for the receipt template in the message template system.
809
-     *
810
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
811
-     * @return string
812
-     */
813
-    public function receipt_url($messenger = 'html')
814
-    {
815
-
816
-        /**
817
-         * The below will be deprecated one version after this.  We check first if there is a custom receipt template
818
-         * already in use on old system.  If there is then we just return the standard url for it.
819
-         *
820
-         * @since 4.5.0
821
-         */
822
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
823
-        $has_custom = EEH_Template::locate_template(
824
-            $template_relative_path,
825
-            array(),
826
-            true,
827
-            true,
828
-            true
829
-        );
830
-
831
-        if ($has_custom) {
832
-            return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
833
-        }
834
-        return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
835
-    }
836
-
837
-
838
-    /**
839
-     * Gets the string which represents the URL trigger for the invoice template in the message template system.
840
-     *
841
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
842
-     * @return string
843
-     * @throws EE_Error
844
-     */
845
-    public function invoice_url($messenger = 'html')
846
-    {
847
-        /**
848
-         * The below will be deprecated one version after this.  We check first if there is a custom invoice template
849
-         * already in use on old system.  If there is then we just return the standard url for it.
850
-         *
851
-         * @since 4.5.0
852
-         */
853
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
854
-        $has_custom = EEH_Template::locate_template(
855
-            $template_relative_path,
856
-            array(),
857
-            true,
858
-            true,
859
-            true
860
-        );
861
-
862
-        if ($has_custom) {
863
-            if ($messenger == 'html') {
864
-                return $this->invoice_url('launch');
865
-            }
866
-            $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
867
-
868
-            $query_args = array('ee' => $route, 'id' => $this->reg_url_link());
869
-            if ($messenger == 'html') {
870
-                $query_args['html'] = true;
871
-            }
872
-            return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
873
-        }
874
-        return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
875
-    }
876
-
877
-
878
-    /**
879
-     * get Registration URL Link
880
-     *
881
-     * @access public
882
-     * @return string
883
-     * @throws EE_Error
884
-     */
885
-    public function reg_url_link()
886
-    {
887
-        return (string) $this->get('REG_url_link');
888
-    }
889
-
890
-
891
-    /**
892
-     * Echoes out invoice_url()
893
-     *
894
-     * @param string $type 'download','launch', or 'html' (default is 'launch')
895
-     * @return void
896
-     * @throws EE_Error
897
-     */
898
-    public function e_invoice_url($type = 'launch')
899
-    {
900
-        echo $this->invoice_url($type);
901
-    }
902
-
903
-
904
-    /**
905
-     * Echoes out payment_overview_url
906
-     */
907
-    public function e_payment_overview_url()
908
-    {
909
-        echo $this->payment_overview_url();
910
-    }
911
-
912
-
913
-    /**
914
-     * Gets the URL for the checkout payment options reg step
915
-     * with this registration's REG_url_link added as a query parameter
916
-     *
917
-     * @param bool $clear_session Set to true when you want to clear the session on revisiting the
918
-     *                            payment overview url.
919
-     * @return string
920
-     * @throws InvalidInterfaceException
921
-     * @throws InvalidDataTypeException
922
-     * @throws EE_Error
923
-     * @throws InvalidArgumentException
924
-     */
925
-    public function payment_overview_url($clear_session = false)
926
-    {
927
-        return add_query_arg(
928
-            (array) apply_filters(
929
-                'FHEE__EE_Registration__payment_overview_url__query_args',
930
-                array(
931
-                    'e_reg_url_link' => $this->reg_url_link(),
932
-                    'step'           => 'payment_options',
933
-                    'revisit'        => true,
934
-                    'clear_session'  => (bool) $clear_session,
935
-                ),
936
-                $this
937
-            ),
938
-            EE_Registry::instance()->CFG->core->reg_page_url()
939
-        );
940
-    }
941
-
942
-
943
-    /**
944
-     * Gets the URL for the checkout attendee information reg step
945
-     * with this registration's REG_url_link added as a query parameter
946
-     *
947
-     * @return string
948
-     * @throws InvalidInterfaceException
949
-     * @throws InvalidDataTypeException
950
-     * @throws EE_Error
951
-     * @throws InvalidArgumentException
952
-     */
953
-    public function edit_attendee_information_url()
954
-    {
955
-        return add_query_arg(
956
-            (array) apply_filters(
957
-                'FHEE__EE_Registration__edit_attendee_information_url__query_args',
958
-                array(
959
-                    'e_reg_url_link' => $this->reg_url_link(),
960
-                    'step'           => 'attendee_information',
961
-                    'revisit'        => true,
962
-                ),
963
-                $this
964
-            ),
965
-            EE_Registry::instance()->CFG->core->reg_page_url()
966
-        );
967
-    }
968
-
969
-
970
-    /**
971
-     * Simply generates and returns the appropriate admin_url link to edit this registration
972
-     *
973
-     * @return string
974
-     * @throws EE_Error
975
-     */
976
-    public function get_admin_edit_url()
977
-    {
978
-        return EEH_URL::add_query_args_and_nonce(
979
-            array(
980
-                'page'    => 'espresso_registrations',
981
-                'action'  => 'view_registration',
982
-                '_REG_ID' => $this->ID(),
983
-            ),
984
-            admin_url('admin.php')
985
-        );
986
-    }
987
-
988
-
989
-    /**
990
-     *    is_primary_registrant?
991
-     */
992
-    public function is_primary_registrant()
993
-    {
994
-        return $this->get('REG_count') === 1 ? true : false;
995
-    }
996
-
997
-
998
-    /**
999
-     * This returns the primary registration object for this registration group (which may be this object).
1000
-     *
1001
-     * @return EE_Registration
1002
-     * @throws EE_Error
1003
-     */
1004
-    public function get_primary_registration()
1005
-    {
1006
-        if ($this->is_primary_registrant()) {
1007
-            return $this;
1008
-        }
1009
-
1010
-        // k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
1011
-        /** @var EE_Registration $primary_registrant */
1012
-        $primary_registrant = EEM_Registration::instance()->get_one(
1013
-            array(
1014
-                array(
1015
-                    'TXN_ID'    => $this->transaction_ID(),
1016
-                    'REG_count' => 1,
1017
-                ),
1018
-            )
1019
-        );
1020
-        return $primary_registrant;
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     *        get  Attendee Number
1026
-     *
1027
-     * @access        public
1028
-     */
1029
-    public function count()
1030
-    {
1031
-        return $this->get('REG_count');
1032
-    }
1033
-
1034
-
1035
-    /**
1036
-     *        get Group Size
1037
-     */
1038
-    public function group_size()
1039
-    {
1040
-        return $this->get('REG_group_size');
1041
-    }
1042
-
1043
-
1044
-    /**
1045
-     *        get Registration Date
1046
-     */
1047
-    public function date()
1048
-    {
1049
-        return $this->get('REG_date');
1050
-    }
1051
-
1052
-
1053
-    /**
1054
-     * gets a pretty date
1055
-     *
1056
-     * @param string $date_format
1057
-     * @param string $time_format
1058
-     * @return string
1059
-     * @throws EE_Error
1060
-     */
1061
-    public function pretty_date($date_format = null, $time_format = null)
1062
-    {
1063
-        return $this->get_datetime('REG_date', $date_format, $time_format);
1064
-    }
1065
-
1066
-
1067
-    /**
1068
-     * final_price
1069
-     * the registration's share of the transaction total, so that the
1070
-     * sum of all the transaction's REG_final_prices equal the transaction's total
1071
-     *
1072
-     * @return float
1073
-     * @throws EE_Error
1074
-     */
1075
-    public function final_price()
1076
-    {
1077
-        return $this->get('REG_final_price');
1078
-    }
1079
-
1080
-
1081
-    /**
1082
-     * pretty_final_price
1083
-     *  final price as formatted string, with correct decimal places and currency symbol
1084
-     *
1085
-     * @return string
1086
-     * @throws EE_Error
1087
-     */
1088
-    public function pretty_final_price()
1089
-    {
1090
-        return $this->get_pretty('REG_final_price');
1091
-    }
1092
-
1093
-
1094
-    /**
1095
-     * get paid (yeah)
1096
-     *
1097
-     * @return float
1098
-     * @throws EE_Error
1099
-     */
1100
-    public function paid()
1101
-    {
1102
-        return $this->get('REG_paid');
1103
-    }
1104
-
1105
-
1106
-    /**
1107
-     * pretty_paid
1108
-     *
1109
-     * @return float
1110
-     * @throws EE_Error
1111
-     */
1112
-    public function pretty_paid()
1113
-    {
1114
-        return $this->get_pretty('REG_paid');
1115
-    }
1116
-
1117
-
1118
-    /**
1119
-     * owes_monies_and_can_pay
1120
-     * whether or not this registration has monies owing and it's' status allows payment
1121
-     *
1122
-     * @param array $requires_payment
1123
-     * @return bool
1124
-     * @throws EE_Error
1125
-     */
1126
-    public function owes_monies_and_can_pay($requires_payment = array())
1127
-    {
1128
-        // these reg statuses require payment (if event is not free)
1129
-        $requires_payment = ! empty($requires_payment)
1130
-            ? $requires_payment
1131
-            : EEM_Registration::reg_statuses_that_allow_payment();
1132
-        if (in_array($this->status_ID(), $requires_payment) &&
1133
-            $this->final_price() != 0 &&
1134
-            $this->final_price() != $this->paid()
1135
-        ) {
1136
-            return true;
1137
-        } else {
1138
-            return false;
1139
-        }
1140
-    }
1141
-
1142
-
1143
-    /**
1144
-     * Prints out the return value of $this->pretty_status()
1145
-     *
1146
-     * @param bool $show_icons
1147
-     * @return void
1148
-     * @throws EE_Error
1149
-     */
1150
-    public function e_pretty_status($show_icons = false)
1151
-    {
1152
-        echo $this->pretty_status($show_icons);
1153
-    }
1154
-
1155
-
1156
-    /**
1157
-     * Returns a nice version of the status for displaying to customers
1158
-     *
1159
-     * @param bool $show_icons
1160
-     * @return string
1161
-     * @throws EE_Error
1162
-     */
1163
-    public function pretty_status($show_icons = false)
1164
-    {
1165
-        $status = EEM_Status::instance()->localized_status(
1166
-            array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
1167
-            false,
1168
-            'sentence'
1169
-        );
1170
-        $icon = '';
1171
-        switch ($this->status_ID()) {
1172
-            case EEM_Registration::status_id_approved:
1173
-                $icon = $show_icons
1174
-                    ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
1175
-                    : '';
1176
-                break;
1177
-            case EEM_Registration::status_id_pending_payment:
1178
-                $icon = $show_icons
1179
-                    ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
1180
-                    : '';
1181
-                break;
1182
-            case EEM_Registration::status_id_not_approved:
1183
-                $icon = $show_icons
1184
-                    ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
1185
-                    : '';
1186
-                break;
1187
-            case EEM_Registration::status_id_cancelled:
1188
-                $icon = $show_icons
1189
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
1190
-                    : '';
1191
-                break;
1192
-            case EEM_Registration::status_id_incomplete:
1193
-                $icon = $show_icons
1194
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1195
-                    : '';
1196
-                break;
1197
-            case EEM_Registration::status_id_declined:
1198
-                $icon = $show_icons
1199
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1200
-                    : '';
1201
-                break;
1202
-            case EEM_Registration::status_id_wait_list:
1203
-                $icon = $show_icons
1204
-                    ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1205
-                    : '';
1206
-                break;
1207
-        }
1208
-        return $icon . $status[ $this->status_ID() ];
1209
-    }
1210
-
1211
-
1212
-    /**
1213
-     *        get Attendee Is Going
1214
-     */
1215
-    public function att_is_going()
1216
-    {
1217
-        return $this->get('REG_att_is_going');
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     * Gets related answers
1223
-     *
1224
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1225
-     * @return EE_Answer[]
1226
-     * @throws EE_Error
1227
-     */
1228
-    public function answers($query_params = null)
1229
-    {
1230
-        return $this->get_many_related('Answer', $query_params);
1231
-    }
1232
-
1233
-
1234
-    /**
1235
-     * Gets the registration's answer value to the specified question
1236
-     * (either the question's ID or a question object)
1237
-     *
1238
-     * @param EE_Question|int $question
1239
-     * @param bool            $pretty_value
1240
-     * @return array|string if pretty_value= true, the result will always be a string
1241
-     * (because the answer might be an array of answer values, so passing pretty_value=true
1242
-     * will convert it into some kind of string)
1243
-     * @throws EE_Error
1244
-     */
1245
-    public function answer_value_to_question($question, $pretty_value = true)
1246
-    {
1247
-        $question_id = EEM_Question::instance()->ensure_is_ID($question);
1248
-        return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1249
-    }
1250
-
1251
-
1252
-    /**
1253
-     * question_groups
1254
-     * returns an array of EE_Question_Group objects for this registration
1255
-     *
1256
-     * @return EE_Question_Group[]
1257
-     * @throws EE_Error
1258
-     * @throws InvalidArgumentException
1259
-     * @throws InvalidDataTypeException
1260
-     * @throws InvalidInterfaceException
1261
-     * @throws ReflectionException
1262
-     */
1263
-    public function question_groups()
1264
-    {
1265
-        return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this);
1266
-    }
1267
-
1268
-
1269
-    /**
1270
-     * count_question_groups
1271
-     * returns a count of the number of EE_Question_Group objects for this registration
1272
-     *
1273
-     * @return int
1274
-     * @throws EE_Error
1275
-     * @throws EntityNotFoundException
1276
-     * @throws InvalidArgumentException
1277
-     * @throws InvalidDataTypeException
1278
-     * @throws InvalidInterfaceException
1279
-     * @throws ReflectionException
1280
-     */
1281
-    public function count_question_groups()
1282
-    {
1283
-        return EEM_Event::instance()->count_related(
1284
-            $this->event_ID(),
1285
-            'Question_Group',
1286
-            [
1287
-                [
1288
-                    'Event_Question_Group.'
1289
-                    . EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true,
1290
-                ]
1291
-            ]
1292
-        );
1293
-    }
1294
-
1295
-
1296
-    /**
1297
-     * Returns the registration date in the 'standard' string format
1298
-     * (function may be improved in the future to allow for different formats and timezones)
1299
-     *
1300
-     * @return string
1301
-     * @throws EE_Error
1302
-     */
1303
-    public function reg_date()
1304
-    {
1305
-        return $this->get_datetime('REG_date');
1306
-    }
1307
-
1308
-
1309
-    /**
1310
-     * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1311
-     * the ticket this registration purchased, or the datetime they have registered
1312
-     * to attend)
1313
-     *
1314
-     * @return EE_Datetime_Ticket
1315
-     * @throws EE_Error
1316
-     */
1317
-    public function datetime_ticket()
1318
-    {
1319
-        return $this->get_first_related('Datetime_Ticket');
1320
-    }
1321
-
1322
-
1323
-    /**
1324
-     * Sets the registration's datetime_ticket.
1325
-     *
1326
-     * @param EE_Datetime_Ticket $datetime_ticket
1327
-     * @return EE_Datetime_Ticket
1328
-     * @throws EE_Error
1329
-     */
1330
-    public function set_datetime_ticket($datetime_ticket)
1331
-    {
1332
-        return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1333
-    }
1334
-
1335
-    /**
1336
-     * Gets deleted
1337
-     *
1338
-     * @return bool
1339
-     * @throws EE_Error
1340
-     */
1341
-    public function deleted()
1342
-    {
1343
-        return $this->get('REG_deleted');
1344
-    }
1345
-
1346
-    /**
1347
-     * Sets deleted
1348
-     *
1349
-     * @param boolean $deleted
1350
-     * @return bool
1351
-     * @throws EE_Error
1352
-     * @throws RuntimeException
1353
-     */
1354
-    public function set_deleted($deleted)
1355
-    {
1356
-        if ($deleted) {
1357
-            $this->delete();
1358
-        } else {
1359
-            $this->restore();
1360
-        }
1361
-    }
1362
-
1363
-
1364
-    /**
1365
-     * Get the status object of this object
1366
-     *
1367
-     * @return EE_Status
1368
-     * @throws EE_Error
1369
-     */
1370
-    public function status_obj()
1371
-    {
1372
-        return $this->get_first_related('Status');
1373
-    }
1374
-
1375
-
1376
-    /**
1377
-     * Returns the number of times this registration has checked into any of the datetimes
1378
-     * its available for
1379
-     *
1380
-     * @return int
1381
-     * @throws EE_Error
1382
-     */
1383
-    public function count_checkins()
1384
-    {
1385
-        return $this->get_model()->count_related($this, 'Checkin');
1386
-    }
1387
-
1388
-
1389
-    /**
1390
-     * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1391
-     * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1392
-     *
1393
-     * @return int
1394
-     * @throws EE_Error
1395
-     */
1396
-    public function count_checkins_not_checkedout()
1397
-    {
1398
-        return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1399
-    }
1400
-
1401
-
1402
-    /**
1403
-     * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1404
-     *
1405
-     * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1406
-     * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1407
-     *                                          consider registration status as well as datetime access.
1408
-     * @return bool
1409
-     * @throws EE_Error
1410
-     */
1411
-    public function can_checkin($DTT_OR_ID, $check_approved = true)
1412
-    {
1413
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1414
-
1415
-        // first check registration status
1416
-        if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1417
-            return false;
1418
-        }
1419
-        // is there a datetime ticket that matches this dtt_ID?
1420
-        if (! (EEM_Datetime_Ticket::instance()->exists(
1421
-            array(
1422
-                array(
1423
-                    'TKT_ID' => $this->get('TKT_ID'),
1424
-                    'DTT_ID' => $DTT_ID,
1425
-                ),
1426
-            )
1427
-        ))
1428
-        ) {
1429
-            return false;
1430
-        }
1431
-
1432
-        // final check is against TKT_uses
1433
-        return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1434
-    }
1435
-
1436
-
1437
-    /**
1438
-     * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1439
-     * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1440
-     * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1441
-     * then return false.  Otherwise return true.
1442
-     *
1443
-     * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1444
-     * @return bool true means can checkin.  false means cannot checkin.
1445
-     * @throws EE_Error
1446
-     */
1447
-    public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1448
-    {
1449
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1450
-
1451
-        if (! $DTT_ID) {
1452
-            return false;
1453
-        }
1454
-
1455
-        $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1456
-
1457
-        // if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1458
-        // check-in or not.
1459
-        if (! $max_uses || $max_uses === EE_INF) {
1460
-            return true;
1461
-        }
1462
-
1463
-        // does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1464
-        // go ahead and toggle.
1465
-        if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1466
-            return true;
1467
-        }
1468
-
1469
-        // made it here so the last check is whether the number of checkins per unique datetime on this registration
1470
-        // disallows further check-ins.
1471
-        $count_unique_dtt_checkins = EEM_Checkin::instance()->count(
1472
-            array(
1473
-                array(
1474
-                    'REG_ID' => $this->ID(),
1475
-                    'CHK_in' => true,
1476
-                ),
1477
-            ),
1478
-            'DTT_ID',
1479
-            true
1480
-        );
1481
-        // checkins have already reached their max number of uses
1482
-        // so registrant can NOT checkin
1483
-        if ($count_unique_dtt_checkins >= $max_uses) {
1484
-            EE_Error::add_error(
1485
-                esc_html__(
1486
-                    'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1487
-                    'event_espresso'
1488
-                ),
1489
-                __FILE__,
1490
-                __FUNCTION__,
1491
-                __LINE__
1492
-            );
1493
-            return false;
1494
-        }
1495
-        return true;
1496
-    }
1497
-
1498
-
1499
-    /**
1500
-     * toggle Check-in status for this registration
1501
-     * Check-ins are toggled in the following order:
1502
-     * never checked in -> checked in
1503
-     * checked in -> checked out
1504
-     * checked out -> checked in
1505
-     *
1506
-     * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1507
-     *                      If not included or null, then it is assumed latest datetime is being toggled.
1508
-     * @param bool $verify  If true then can_checkin() is used to verify whether the person
1509
-     *                      can be checked in or not.  Otherwise this forces change in checkin status.
1510
-     * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1511
-     * @throws EE_Error
1512
-     */
1513
-    public function toggle_checkin_status($DTT_ID = null, $verify = false)
1514
-    {
1515
-        if (empty($DTT_ID)) {
1516
-            $datetime = $this->get_latest_related_datetime();
1517
-            $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1518
-            // verify the registration can checkin for the given DTT_ID
1519
-        } elseif (! $this->can_checkin($DTT_ID, $verify)) {
1520
-            EE_Error::add_error(
1521
-                sprintf(
1522
-                    esc_html__(
1523
-                        'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1524
-                        'event_espresso'
1525
-                    ),
1526
-                    $this->ID(),
1527
-                    $DTT_ID
1528
-                ),
1529
-                __FILE__,
1530
-                __FUNCTION__,
1531
-                __LINE__
1532
-            );
1533
-            return false;
1534
-        }
1535
-        $status_paths = array(
1536
-            EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1537
-            EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1538
-            EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1539
-        );
1540
-        // start by getting the current status so we know what status we'll be changing to.
1541
-        $cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1542
-        $status_to = $status_paths[ $cur_status ];
1543
-        // database only records true for checked IN or false for checked OUT
1544
-        // no record ( null ) means checked in NEVER, but we obviously don't save that
1545
-        $new_status = $status_to === EE_Checkin::status_checked_in ? true : false;
1546
-        // add relation - note Check-ins are always creating new rows
1547
-        // because we are keeping track of Check-ins over time.
1548
-        // Eventually we'll probably want to show a list table
1549
-        // for the individual Check-ins so that they can be managed.
1550
-        $checkin = EE_Checkin::new_instance(
1551
-            array(
1552
-                'REG_ID' => $this->ID(),
1553
-                'DTT_ID' => $DTT_ID,
1554
-                'CHK_in' => $new_status,
1555
-            )
1556
-        );
1557
-        // if the record could not be saved then return false
1558
-        if ($checkin->save() === 0) {
1559
-            if (WP_DEBUG) {
1560
-                global $wpdb;
1561
-                $error = sprintf(
1562
-                    esc_html__(
1563
-                        'Registration check in update failed because of the following database error: %1$s%2$s',
1564
-                        'event_espresso'
1565
-                    ),
1566
-                    '<br />',
1567
-                    $wpdb->last_error
1568
-                );
1569
-            } else {
1570
-                $error = esc_html__(
1571
-                    'Registration check in update failed because of an unknown database error',
1572
-                    'event_espresso'
1573
-                );
1574
-            }
1575
-            EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1576
-            return false;
1577
-        }
1578
-        return $status_to;
1579
-    }
1580
-
1581
-
1582
-    /**
1583
-     * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1584
-     * "Latest" is defined by the `DTT_EVT_start` column.
1585
-     *
1586
-     * @return EE_Datetime|null
1587
-     * @throws EE_Error
1588
-     */
1589
-    public function get_latest_related_datetime()
1590
-    {
1591
-        return EEM_Datetime::instance()->get_one(
1592
-            array(
1593
-                array(
1594
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1595
-                ),
1596
-                'order_by' => array('DTT_EVT_start' => 'DESC'),
1597
-            )
1598
-        );
1599
-    }
1600
-
1601
-
1602
-    /**
1603
-     * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1604
-     * "Earliest" is defined by the `DTT_EVT_start` column.
1605
-     *
1606
-     * @throws EE_Error
1607
-     */
1608
-    public function get_earliest_related_datetime()
1609
-    {
1610
-        return EEM_Datetime::instance()->get_one(
1611
-            array(
1612
-                array(
1613
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1614
-                ),
1615
-                'order_by' => array('DTT_EVT_start' => 'ASC'),
1616
-            )
1617
-        );
1618
-    }
1619
-
1620
-
1621
-    /**
1622
-     * This method simply returns the check-in status for this registration and the given datetime.
1623
-     * If neither the datetime nor the checkin values are provided as arguments,
1624
-     * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1625
-     *
1626
-     * @param  int       $DTT_ID  The ID of the datetime we're checking against
1627
-     *                            (if empty we'll get the primary datetime for
1628
-     *                            this registration (via event) and use it's ID);
1629
-     * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1630
-     *
1631
-     * @return int                Integer representing Check-in status.
1632
-     * @throws EE_Error
1633
-     */
1634
-    public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1635
-    {
1636
-        $checkin_query_params = array(
1637
-            'order_by' => array('CHK_timestamp' => 'DESC'),
1638
-        );
1639
-
1640
-        if ($DTT_ID > 0) {
1641
-            $checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1642
-        }
1643
-
1644
-        // get checkin object (if exists)
1645
-        $checkin = $checkin instanceof EE_Checkin
1646
-            ? $checkin
1647
-            : $this->get_first_related('Checkin', $checkin_query_params);
1648
-        if ($checkin instanceof EE_Checkin) {
1649
-            if ($checkin->get('CHK_in')) {
1650
-                return EE_Checkin::status_checked_in; // checked in
1651
-            }
1652
-            return EE_Checkin::status_checked_out; // had checked in but is now checked out.
1653
-        }
1654
-        return EE_Checkin::status_checked_never; // never been checked in
1655
-    }
1656
-
1657
-
1658
-    /**
1659
-     * This method returns a localized message for the toggled Check-in message.
1660
-     *
1661
-     * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1662
-     *                     then it is assumed Check-in for primary datetime was toggled.
1663
-     * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1664
-     *                     message can be customized with the attendee name.
1665
-     * @return string internationalized message
1666
-     * @throws EE_Error
1667
-     */
1668
-    public function get_checkin_msg($DTT_ID, $error = false)
1669
-    {
1670
-        // let's get the attendee first so we can include the name of the attendee
1671
-        $attendee = $this->get_first_related('Attendee');
1672
-        if ($attendee instanceof EE_Attendee) {
1673
-            if ($error) {
1674
-                return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1675
-            }
1676
-            $cur_status = $this->check_in_status_for_datetime($DTT_ID);
1677
-            // what is the status message going to be?
1678
-            switch ($cur_status) {
1679
-                case EE_Checkin::status_checked_never:
1680
-                    return sprintf(
1681
-                        __("%s has been removed from Check-in records", "event_espresso"),
1682
-                        $attendee->full_name()
1683
-                    );
1684
-                    break;
1685
-                case EE_Checkin::status_checked_in:
1686
-                    return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1687
-                    break;
1688
-                case EE_Checkin::status_checked_out:
1689
-                    return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1690
-                    break;
1691
-            }
1692
-        }
1693
-        return esc_html__("The check-in status could not be determined.", "event_espresso");
1694
-    }
1695
-
1696
-
1697
-    /**
1698
-     * Returns the related EE_Transaction to this registration
1699
-     *
1700
-     * @return EE_Transaction
1701
-     * @throws EE_Error
1702
-     * @throws EntityNotFoundException
1703
-     */
1704
-    public function transaction()
1705
-    {
1706
-        $transaction = $this->get_first_related('Transaction');
1707
-        if (! $transaction instanceof \EE_Transaction) {
1708
-            throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1709
-        }
1710
-        return $transaction;
1711
-    }
1712
-
1713
-
1714
-    /**
1715
-     *        get Registration Code
1716
-     */
1717
-    public function reg_code()
1718
-    {
1719
-        return $this->get('REG_code');
1720
-    }
1721
-
1722
-
1723
-    /**
1724
-     *        get Transaction ID
1725
-     */
1726
-    public function transaction_ID()
1727
-    {
1728
-        return $this->get('TXN_ID');
1729
-    }
1730
-
1731
-
1732
-    /**
1733
-     * @return int
1734
-     * @throws EE_Error
1735
-     */
1736
-    public function ticket_ID()
1737
-    {
1738
-        return $this->get('TKT_ID');
1739
-    }
1740
-
1741
-
1742
-    /**
1743
-     *        Set Registration Code
1744
-     *
1745
-     * @access    public
1746
-     * @param    string  $REG_code Registration Code
1747
-     * @param    boolean $use_default
1748
-     * @throws EE_Error
1749
-     */
1750
-    public function set_reg_code($REG_code, $use_default = false)
1751
-    {
1752
-        if (empty($REG_code)) {
1753
-            EE_Error::add_error(
1754
-                esc_html__('REG_code can not be empty.', 'event_espresso'),
1755
-                __FILE__,
1756
-                __FUNCTION__,
1757
-                __LINE__
1758
-            );
1759
-            return;
1760
-        }
1761
-        if (! $this->reg_code()) {
1762
-            parent::set('REG_code', $REG_code, $use_default);
1763
-        } else {
1764
-            EE_Error::doing_it_wrong(
1765
-                __CLASS__ . '::' . __FUNCTION__,
1766
-                esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1767
-                '4.6.0'
1768
-            );
1769
-        }
1770
-    }
1771
-
1772
-
1773
-    /**
1774
-     * Returns all other registrations in the same group as this registrant who have the same ticket option.
1775
-     * Note, if you want to just get all registrations in the same transaction (group), use:
1776
-     *    $registration->transaction()->registrations();
1777
-     *
1778
-     * @since 4.5.0
1779
-     * @return EE_Registration[] or empty array if this isn't a group registration.
1780
-     * @throws EE_Error
1781
-     */
1782
-    public function get_all_other_registrations_in_group()
1783
-    {
1784
-        if ($this->group_size() < 2) {
1785
-            return array();
1786
-        }
1787
-
1788
-        $query[0] = array(
1789
-            'TXN_ID' => $this->transaction_ID(),
1790
-            'REG_ID' => array('!=', $this->ID()),
1791
-            'TKT_ID' => $this->ticket_ID(),
1792
-        );
1793
-        /** @var EE_Registration[] $registrations */
1794
-        $registrations = $this->get_model()->get_all($query);
1795
-        return $registrations;
1796
-    }
1797
-
1798
-    /**
1799
-     * Return the link to the admin details for the object.
1800
-     *
1801
-     * @return string
1802
-     * @throws EE_Error
1803
-     */
1804
-    public function get_admin_details_link()
1805
-    {
1806
-        EE_Registry::instance()->load_helper('URL');
1807
-        return EEH_URL::add_query_args_and_nonce(
1808
-            array(
1809
-                'page'    => 'espresso_registrations',
1810
-                'action'  => 'view_registration',
1811
-                '_REG_ID' => $this->ID(),
1812
-            ),
1813
-            admin_url('admin.php')
1814
-        );
1815
-    }
1816
-
1817
-    /**
1818
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1819
-     *
1820
-     * @return string
1821
-     * @throws EE_Error
1822
-     */
1823
-    public function get_admin_edit_link()
1824
-    {
1825
-        return $this->get_admin_details_link();
1826
-    }
1827
-
1828
-    /**
1829
-     * Returns the link to a settings page for the object.
1830
-     *
1831
-     * @return string
1832
-     * @throws EE_Error
1833
-     */
1834
-    public function get_admin_settings_link()
1835
-    {
1836
-        return $this->get_admin_details_link();
1837
-    }
1838
-
1839
-    /**
1840
-     * Returns the link to the "overview" for the object (typically the "list table" view).
1841
-     *
1842
-     * @return string
1843
-     */
1844
-    public function get_admin_overview_link()
1845
-    {
1846
-        EE_Registry::instance()->load_helper('URL');
1847
-        return EEH_URL::add_query_args_and_nonce(
1848
-            array(
1849
-                'page' => 'espresso_registrations',
1850
-            ),
1851
-            admin_url('admin.php')
1852
-        );
1853
-    }
1854
-
1855
-
1856
-    /**
1857
-     * @param array $query_params
1858
-     *
1859
-     * @return \EE_Registration[]
1860
-     * @throws EE_Error
1861
-     */
1862
-    public function payments($query_params = array())
1863
-    {
1864
-        return $this->get_many_related('Payment', $query_params);
1865
-    }
1866
-
1867
-
1868
-    /**
1869
-     * @param array $query_params
1870
-     *
1871
-     * @return \EE_Registration_Payment[]
1872
-     * @throws EE_Error
1873
-     */
1874
-    public function registration_payments($query_params = array())
1875
-    {
1876
-        return $this->get_many_related('Registration_Payment', $query_params);
1877
-    }
1878
-
1879
-
1880
-    /**
1881
-     * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1882
-     * Note: if there are no payments on the registration there will be no payment method returned.
1883
-     *
1884
-     * @return EE_Payment_Method|null
1885
-     */
1886
-    public function payment_method()
1887
-    {
1888
-        return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1889
-    }
1890
-
1891
-
1892
-    /**
1893
-     * @return \EE_Line_Item
1894
-     * @throws EntityNotFoundException
1895
-     * @throws EE_Error
1896
-     */
1897
-    public function ticket_line_item()
1898
-    {
1899
-        $ticket = $this->ticket();
1900
-        $transaction = $this->transaction();
1901
-        $line_item = null;
1902
-        $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1903
-            $transaction->total_line_item(),
1904
-            'Ticket',
1905
-            array($ticket->ID())
1906
-        );
1907
-        foreach ($ticket_line_items as $ticket_line_item) {
1908
-            if ($ticket_line_item instanceof \EE_Line_Item
1909
-                && $ticket_line_item->OBJ_type() === 'Ticket'
1910
-                && $ticket_line_item->OBJ_ID() === $ticket->ID()
1911
-            ) {
1912
-                $line_item = $ticket_line_item;
1913
-                break;
1914
-            }
1915
-        }
1916
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1917
-            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1918
-        }
1919
-        return $line_item;
1920
-    }
1921
-
1922
-
1923
-    /**
1924
-     * Soft Deletes this model object.
1925
-     *
1926
-     * @return boolean | int
1927
-     * @throws RuntimeException
1928
-     * @throws EE_Error
1929
-     */
1930
-    public function delete()
1931
-    {
1932
-        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1933
-            $this->set_status(EEM_Registration::status_id_cancelled);
1934
-        }
1935
-        return parent::delete();
1936
-    }
1937
-
1938
-
1939
-    /**
1940
-     * Restores whatever the previous status was on a registration before it was trashed (if possible)
1941
-     *
1942
-     * @throws EE_Error
1943
-     * @throws RuntimeException
1944
-     */
1945
-    public function restore()
1946
-    {
1947
-        $previous_status = $this->get_extra_meta(
1948
-            EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1949
-            true,
1950
-            EEM_Registration::status_id_cancelled
1951
-        );
1952
-        if ($previous_status) {
1953
-            $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1954
-            $this->set_status($previous_status);
1955
-        }
1956
-        return parent::restore();
1957
-    }
1958
-
1959
-
1960
-    /**
1961
-     * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price
1962
-     *
1963
-     * @param  boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic
1964
-     *                                           depending on whether the reg status changes to or from "Approved"
1965
-     * @return boolean whether the Registration status was updated
1966
-     * @throws EE_Error
1967
-     * @throws RuntimeException
1968
-     */
1969
-    public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true)
1970
-    {
1971
-        $paid = $this->paid();
1972
-        $price = $this->final_price();
1973
-        switch (true) {
1974
-            // overpaid or paid
1975
-            case EEH_Money::compare_floats($paid, $price, '>'):
1976
-            case EEH_Money::compare_floats($paid, $price):
1977
-                $new_status = EEM_Registration::status_id_approved;
1978
-                break;
1979
-            //  underpaid
1980
-            case EEH_Money::compare_floats($paid, $price, '<'):
1981
-                $new_status = EEM_Registration::status_id_pending_payment;
1982
-                break;
1983
-            // uhhh Houston...
1984
-            default:
1985
-                throw new RuntimeException(
1986
-                    esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso')
1987
-                );
1988
-        }
1989
-        if ($new_status !== $this->status_ID()) {
1990
-            if ($trigger_set_status_logic) {
1991
-                return $this->set_status($new_status);
1992
-            }
1993
-            parent::set('STS_ID', $new_status);
1994
-            return true;
1995
-        }
1996
-        return false;
1997
-    }
1998
-
1999
-
2000
-    /*************************** DEPRECATED ***************************/
2001
-
2002
-
2003
-    /**
2004
-     * @deprecated
2005
-     * @since     4.7.0
2006
-     * @access    public
2007
-     */
2008
-    public function price_paid()
2009
-    {
2010
-        EE_Error::doing_it_wrong(
2011
-            'EE_Registration::price_paid()',
2012
-            esc_html__(
2013
-                'This method is deprecated, please use EE_Registration::final_price() instead.',
2014
-                'event_espresso'
2015
-            ),
2016
-            '4.7.0'
2017
-        );
2018
-        return $this->final_price();
2019
-    }
2020
-
2021
-
2022
-    /**
2023
-     * @deprecated
2024
-     * @since     4.7.0
2025
-     * @access    public
2026
-     * @param    float $REG_final_price
2027
-     * @throws EE_Error
2028
-     * @throws RuntimeException
2029
-     */
2030
-    public function set_price_paid($REG_final_price = 0.00)
2031
-    {
2032
-        EE_Error::doing_it_wrong(
2033
-            'EE_Registration::set_price_paid()',
2034
-            esc_html__(
2035
-                'This method is deprecated, please use EE_Registration::set_final_price() instead.',
2036
-                'event_espresso'
2037
-            ),
2038
-            '4.7.0'
2039
-        );
2040
-        $this->set_final_price($REG_final_price);
2041
-    }
2042
-
2043
-
2044
-    /**
2045
-     * @deprecated
2046
-     * @since 4.7.0
2047
-     * @return string
2048
-     * @throws EE_Error
2049
-     */
2050
-    public function pretty_price_paid()
2051
-    {
2052
-        EE_Error::doing_it_wrong(
2053
-            'EE_Registration::pretty_price_paid()',
2054
-            esc_html__(
2055
-                'This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
2056
-                'event_espresso'
2057
-            ),
2058
-            '4.7.0'
2059
-        );
2060
-        return $this->pretty_final_price();
2061
-    }
2062
-
2063
-
2064
-    /**
2065
-     * Gets the primary datetime related to this registration via the related Event to this registration
2066
-     *
2067
-     * @deprecated 4.9.17
2068
-     * @return EE_Datetime
2069
-     * @throws EE_Error
2070
-     * @throws EntityNotFoundException
2071
-     */
2072
-    public function get_related_primary_datetime()
2073
-    {
2074
-        EE_Error::doing_it_wrong(
2075
-            __METHOD__,
2076
-            esc_html__(
2077
-                'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
2078
-                'event_espresso'
2079
-            ),
2080
-            '4.9.17',
2081
-            '5.0.0'
2082
-        );
2083
-        return $this->event()->primary_datetime();
2084
-    }
20
+	/**
21
+	 * Used to reference when a registration has never been checked in.
22
+	 *
23
+	 * @deprecated use \EE_Checkin::status_checked_never instead
24
+	 * @type int
25
+	 */
26
+	const checkin_status_never = 2;
27
+
28
+	/**
29
+	 * Used to reference when a registration has been checked in.
30
+	 *
31
+	 * @deprecated use \EE_Checkin::status_checked_in instead
32
+	 * @type int
33
+	 */
34
+	const checkin_status_in = 1;
35
+
36
+
37
+	/**
38
+	 * Used to reference when a registration has been checked out.
39
+	 *
40
+	 * @deprecated use \EE_Checkin::status_checked_out instead
41
+	 * @type int
42
+	 */
43
+	const checkin_status_out = 0;
44
+
45
+
46
+	/**
47
+	 * extra meta key for tracking reg status os trashed registrations
48
+	 *
49
+	 * @type string
50
+	 */
51
+	const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
52
+
53
+
54
+	/**
55
+	 * extra meta key for tracking if registration has reserved ticket
56
+	 *
57
+	 * @type string
58
+	 */
59
+	const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
60
+
61
+
62
+	/**
63
+	 * @param array  $props_n_values          incoming values
64
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
65
+	 *                                        used.)
66
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
67
+	 *                                        date_format and the second value is the time format
68
+	 * @return EE_Registration
69
+	 * @throws EE_Error
70
+	 */
71
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
72
+	{
73
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
74
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
75
+	}
76
+
77
+
78
+	/**
79
+	 * @param array  $props_n_values  incoming values from the database
80
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
81
+	 *                                the website will be used.
82
+	 * @return EE_Registration
83
+	 */
84
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
85
+	{
86
+		return new self($props_n_values, true, $timezone);
87
+	}
88
+
89
+
90
+	/**
91
+	 *        Set Event ID
92
+	 *
93
+	 * @param        int $EVT_ID Event ID
94
+	 * @throws EE_Error
95
+	 * @throws RuntimeException
96
+	 */
97
+	public function set_event($EVT_ID = 0)
98
+	{
99
+		$this->set('EVT_ID', $EVT_ID);
100
+	}
101
+
102
+
103
+	/**
104
+	 * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
105
+	 * be routed to internal methods
106
+	 *
107
+	 * @param string $field_name
108
+	 * @param mixed  $field_value
109
+	 * @param bool   $use_default
110
+	 * @throws EE_Error
111
+	 * @throws EntityNotFoundException
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 * @throws ReflectionException
116
+	 * @throws RuntimeException
117
+	 */
118
+	public function set($field_name, $field_value, $use_default = false)
119
+	{
120
+		switch ($field_name) {
121
+			case 'REG_code':
122
+				if (! empty($field_value) && $this->reg_code() === null) {
123
+					$this->set_reg_code($field_value, $use_default);
124
+				}
125
+				break;
126
+			case 'STS_ID':
127
+				$this->set_status($field_value, $use_default);
128
+				break;
129
+			default:
130
+				parent::set($field_name, $field_value, $use_default);
131
+		}
132
+	}
133
+
134
+
135
+	/**
136
+	 * Set Status ID
137
+	 * updates the registration status and ALSO...
138
+	 * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
139
+	 * calls release_registration_space() if the reg status changes FROM approved to any other reg status
140
+	 *
141
+	 * @param string                $new_STS_ID
142
+	 * @param boolean               $use_default
143
+	 * @param ContextInterface|null $context
144
+	 * @return bool
145
+	 * @throws DomainException
146
+	 * @throws EE_Error
147
+	 * @throws EntityNotFoundException
148
+	 * @throws InvalidArgumentException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidInterfaceException
151
+	 * @throws ReflectionException
152
+	 * @throws RuntimeException
153
+	 * @throws UnexpectedEntityException
154
+	 */
155
+	public function set_status($new_STS_ID = null, $use_default = false, ContextInterface $context = null)
156
+	{
157
+		// get current REG_Status
158
+		$old_STS_ID = $this->status_ID();
159
+		// if status has changed
160
+		if ($old_STS_ID !== $new_STS_ID // and that status has actually changed
161
+			&& ! empty($old_STS_ID) // and that old status is actually set
162
+			&& ! empty($new_STS_ID) // as well as the new status
163
+			&& $this->ID() // ensure registration is in the db
164
+		) {
165
+			// update internal status first
166
+			parent::set('STS_ID', $new_STS_ID, $use_default);
167
+			// THEN handle other changes that occur when reg status changes
168
+			// TO approved
169
+			if ($new_STS_ID === EEM_Registration::status_id_approved) {
170
+				// reserve a space by incrementing ticket and datetime sold values
171
+				$this->reserveRegistrationSpace();
172
+				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context);
173
+				// OR FROM  approved
174
+			} elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
175
+				// release a space by decrementing ticket and datetime sold values
176
+				$this->releaseRegistrationSpace();
177
+				do_action(
178
+					'AHEE__EE_Registration__set_status__from_approved',
179
+					$this,
180
+					$old_STS_ID,
181
+					$new_STS_ID,
182
+					$context
183
+				);
184
+			}
185
+			// update status
186
+			parent::set('STS_ID', $new_STS_ID, $use_default);
187
+			$this->updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, $context);
188
+			if ($this->statusChangeUpdatesTransaction($context)) {
189
+				$this->updateTransactionAfterStatusChange();
190
+			}
191
+			do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context);
192
+			return true;
193
+		}
194
+		// even though the old value matches the new value, it's still good to
195
+		// allow the parent set method to have a say
196
+		parent::set('STS_ID', $new_STS_ID, $use_default);
197
+		return true;
198
+	}
199
+
200
+
201
+	/**
202
+	 * update REGs and TXN when cancelled or declined registrations involved
203
+	 *
204
+	 * @param string                $new_STS_ID
205
+	 * @param string                $old_STS_ID
206
+	 * @param ContextInterface|null $context
207
+	 * @throws EE_Error
208
+	 * @throws InvalidArgumentException
209
+	 * @throws InvalidDataTypeException
210
+	 * @throws InvalidInterfaceException
211
+	 * @throws ReflectionException
212
+	 * @throws RuntimeException
213
+	 */
214
+	private function updateIfCanceledOrReinstated($new_STS_ID, $old_STS_ID, ContextInterface $context = null)
215
+	{
216
+		// these reg statuses should not be considered in any calculations involving monies owing
217
+		$closed_reg_statuses = EEM_Registration::closed_reg_statuses();
218
+		// true if registration has been cancelled or declined
219
+		$this->updateIfCanceled(
220
+			$closed_reg_statuses,
221
+			$new_STS_ID,
222
+			$old_STS_ID,
223
+			$context
224
+		);
225
+		$this->updateIfReinstated(
226
+			$closed_reg_statuses,
227
+			$new_STS_ID,
228
+			$old_STS_ID,
229
+			$context
230
+		);
231
+	}
232
+
233
+
234
+	/**
235
+	 * update REGs and TXN when cancelled or declined registrations involved
236
+	 *
237
+	 * @param array                 $closed_reg_statuses
238
+	 * @param string                $new_STS_ID
239
+	 * @param string                $old_STS_ID
240
+	 * @param ContextInterface|null $context
241
+	 * @throws EE_Error
242
+	 * @throws InvalidArgumentException
243
+	 * @throws InvalidDataTypeException
244
+	 * @throws InvalidInterfaceException
245
+	 * @throws ReflectionException
246
+	 * @throws RuntimeException
247
+	 */
248
+	private function updateIfCanceled(
249
+		array $closed_reg_statuses,
250
+		$new_STS_ID,
251
+		$old_STS_ID,
252
+		ContextInterface $context = null
253
+	) {
254
+		// true if registration has been cancelled or declined
255
+		if (in_array($new_STS_ID, $closed_reg_statuses, true)
256
+			&& ! in_array($old_STS_ID, $closed_reg_statuses, true)
257
+		) {
258
+			/** @type EE_Registration_Processor $registration_processor */
259
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
260
+			/** @type EE_Transaction_Processor $transaction_processor */
261
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
262
+			// cancelled or declined registration
263
+			$registration_processor->update_registration_after_being_canceled_or_declined(
264
+				$this,
265
+				$closed_reg_statuses
266
+			);
267
+			$transaction_processor->update_transaction_after_canceled_or_declined_registration(
268
+				$this,
269
+				$closed_reg_statuses,
270
+				false
271
+			);
272
+			do_action(
273
+				'AHEE__EE_Registration__set_status__canceled_or_declined',
274
+				$this,
275
+				$old_STS_ID,
276
+				$new_STS_ID,
277
+				$context
278
+			);
279
+			return;
280
+		}
281
+	}
282
+
283
+
284
+	/**
285
+	 * update REGs and TXN when cancelled or declined registrations involved
286
+	 *
287
+	 * @param array                 $closed_reg_statuses
288
+	 * @param string                $new_STS_ID
289
+	 * @param string                $old_STS_ID
290
+	 * @param ContextInterface|null $context
291
+	 * @throws EE_Error
292
+	 * @throws InvalidArgumentException
293
+	 * @throws InvalidDataTypeException
294
+	 * @throws InvalidInterfaceException
295
+	 * @throws ReflectionException
296
+	 */
297
+	private function updateIfReinstated(
298
+		array $closed_reg_statuses,
299
+		$new_STS_ID,
300
+		$old_STS_ID,
301
+		ContextInterface $context = null
302
+	) {
303
+		// true if reinstating cancelled or declined registration
304
+		if (in_array($old_STS_ID, $closed_reg_statuses, true)
305
+			&& ! in_array($new_STS_ID, $closed_reg_statuses, true)
306
+		) {
307
+			/** @type EE_Registration_Processor $registration_processor */
308
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
309
+			/** @type EE_Transaction_Processor $transaction_processor */
310
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
311
+			// reinstating cancelled or declined registration
312
+			$registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
313
+				$this,
314
+				$closed_reg_statuses
315
+			);
316
+			$transaction_processor->update_transaction_after_reinstating_canceled_registration(
317
+				$this,
318
+				$closed_reg_statuses,
319
+				false
320
+			);
321
+			do_action(
322
+				'AHEE__EE_Registration__set_status__after_reinstated',
323
+				$this,
324
+				$old_STS_ID,
325
+				$new_STS_ID,
326
+				$context
327
+			);
328
+		}
329
+	}
330
+
331
+
332
+	/**
333
+	 * @param ContextInterface|null $context
334
+	 * @return bool
335
+	 */
336
+	private function statusChangeUpdatesTransaction(ContextInterface $context = null)
337
+	{
338
+		$contexts_that_do_not_update_transaction = (array) apply_filters(
339
+			'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction',
340
+			array('spco_reg_step_attendee_information_process_registrations'),
341
+			$context,
342
+			$this
343
+		);
344
+		return ! (
345
+			$context instanceof ContextInterface
346
+			&& in_array($context->slug(), $contexts_that_do_not_update_transaction, true)
347
+		);
348
+	}
349
+
350
+
351
+	/**
352
+	 * @throws EE_Error
353
+	 * @throws EntityNotFoundException
354
+	 * @throws InvalidArgumentException
355
+	 * @throws InvalidDataTypeException
356
+	 * @throws InvalidInterfaceException
357
+	 * @throws ReflectionException
358
+	 * @throws RuntimeException
359
+	 */
360
+	private function updateTransactionAfterStatusChange()
361
+	{
362
+		/** @type EE_Transaction_Payments $transaction_payments */
363
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
364
+		$transaction_payments->recalculate_transaction_total($this->transaction(), false);
365
+		$this->transaction()->update_status_based_on_total_paid(true);
366
+	}
367
+
368
+
369
+	/**
370
+	 *        get Status ID
371
+	 */
372
+	public function status_ID()
373
+	{
374
+		return $this->get('STS_ID');
375
+	}
376
+
377
+
378
+	/**
379
+	 * Gets the ticket this registration is for
380
+	 *
381
+	 * @param boolean $include_archived whether to include archived tickets or not.
382
+	 *
383
+	 * @return EE_Ticket|EE_Base_Class
384
+	 * @throws EE_Error
385
+	 */
386
+	public function ticket($include_archived = true)
387
+	{
388
+		$query_params = array();
389
+		if ($include_archived) {
390
+			$query_params['default_where_conditions'] = 'none';
391
+		}
392
+		return $this->get_first_related('Ticket', $query_params);
393
+	}
394
+
395
+
396
+	/**
397
+	 * Gets the event this registration is for
398
+	 *
399
+	 * @return EE_Event
400
+	 * @throws EE_Error
401
+	 * @throws EntityNotFoundException
402
+	 */
403
+	public function event()
404
+	{
405
+		$event = $this->get_first_related('Event');
406
+		if (! $event instanceof \EE_Event) {
407
+			throw new EntityNotFoundException('Event ID', $this->event_ID());
408
+		}
409
+		return $event;
410
+	}
411
+
412
+
413
+	/**
414
+	 * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
415
+	 * with the author of the event this registration is for.
416
+	 *
417
+	 * @since 4.5.0
418
+	 * @return int
419
+	 * @throws EE_Error
420
+	 * @throws EntityNotFoundException
421
+	 */
422
+	public function wp_user()
423
+	{
424
+		$event = $this->event();
425
+		if ($event instanceof EE_Event) {
426
+			return $event->wp_user();
427
+		}
428
+		return 0;
429
+	}
430
+
431
+
432
+	/**
433
+	 * increments this registration's related ticket sold and corresponding datetime sold values
434
+	 *
435
+	 * @return void
436
+	 * @throws DomainException
437
+	 * @throws EE_Error
438
+	 * @throws EntityNotFoundException
439
+	 * @throws InvalidArgumentException
440
+	 * @throws InvalidDataTypeException
441
+	 * @throws InvalidInterfaceException
442
+	 * @throws ReflectionException
443
+	 * @throws UnexpectedEntityException
444
+	 */
445
+	private function reserveRegistrationSpace()
446
+	{
447
+		// reserved ticket and datetime counts will be decremented as sold counts are incremented
448
+		// so stop tracking that this reg has a ticket reserved
449
+		$this->release_reserved_ticket(false, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
450
+		$ticket = $this->ticket();
451
+		$ticket->increaseSold();
452
+		// possibly set event status to sold out
453
+		$this->event()->perform_sold_out_status_check();
454
+	}
455
+
456
+
457
+	/**
458
+	 * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
459
+	 *
460
+	 * @return void
461
+	 * @throws DomainException
462
+	 * @throws EE_Error
463
+	 * @throws EntityNotFoundException
464
+	 * @throws InvalidArgumentException
465
+	 * @throws InvalidDataTypeException
466
+	 * @throws InvalidInterfaceException
467
+	 * @throws ReflectionException
468
+	 * @throws UnexpectedEntityException
469
+	 */
470
+	private function releaseRegistrationSpace()
471
+	{
472
+		$ticket = $this->ticket();
473
+		$ticket->decreaseSold();
474
+		// possibly change event status from sold out back to previous status
475
+		$this->event()->perform_sold_out_status_check();
476
+	}
477
+
478
+
479
+	/**
480
+	 * tracks this registration's ticket reservation in extra meta
481
+	 * and can increment related ticket reserved and corresponding datetime reserved values
482
+	 *
483
+	 * @param bool $update_ticket if true, will increment ticket and datetime reserved count
484
+	 * @return void
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws InvalidDataTypeException
488
+	 * @throws InvalidInterfaceException
489
+	 * @throws ReflectionException
490
+	 */
491
+	public function reserve_ticket($update_ticket = false, $source = 'unknown')
492
+	{
493
+		// only reserve ticket if space is not currently reserved
494
+		if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) !== true) {
495
+			$this->update_extra_meta('reserve_ticket', "{$this->ticket_ID()} from {$source}");
496
+			// IMPORTANT !!!
497
+			// although checking $update_ticket first would be more efficient,
498
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
499
+			if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true)
500
+				&& $update_ticket
501
+			) {
502
+				$ticket = $this->ticket();
503
+				$ticket->increaseReserved(1, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
504
+				$ticket->save();
505
+			}
506
+		}
507
+	}
508
+
509
+
510
+	/**
511
+	 * stops tracking this registration's ticket reservation in extra meta
512
+	 * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
513
+	 *
514
+	 * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
515
+	 * @return void
516
+	 * @throws EE_Error
517
+	 * @throws InvalidArgumentException
518
+	 * @throws InvalidDataTypeException
519
+	 * @throws InvalidInterfaceException
520
+	 * @throws ReflectionException
521
+	 */
522
+	public function release_reserved_ticket($update_ticket = false, $source = 'unknown')
523
+	{
524
+		// only release ticket if space is currently reserved
525
+		if ((bool) $this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true) === true) {
526
+			$this->update_extra_meta('release_reserved_ticket', "{$this->ticket_ID()} from {$source}");
527
+			// IMPORTANT !!!
528
+			// although checking $update_ticket first would be more efficient,
529
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
530
+			if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, false)
531
+				&& $update_ticket
532
+			) {
533
+				$ticket = $this->ticket();
534
+				$ticket->decreaseReserved(1, true, "REG: {$this->ID()} (ln:" . __LINE__ . ')');
535
+			}
536
+		}
537
+	}
538
+
539
+
540
+	/**
541
+	 * Set Attendee ID
542
+	 *
543
+	 * @param        int $ATT_ID Attendee ID
544
+	 * @throws EE_Error
545
+	 * @throws RuntimeException
546
+	 */
547
+	public function set_attendee_id($ATT_ID = 0)
548
+	{
549
+		$this->set('ATT_ID', $ATT_ID);
550
+	}
551
+
552
+
553
+	/**
554
+	 *        Set Transaction ID
555
+	 *
556
+	 * @param        int $TXN_ID Transaction ID
557
+	 * @throws EE_Error
558
+	 * @throws RuntimeException
559
+	 */
560
+	public function set_transaction_id($TXN_ID = 0)
561
+	{
562
+		$this->set('TXN_ID', $TXN_ID);
563
+	}
564
+
565
+
566
+	/**
567
+	 *        Set Session
568
+	 *
569
+	 * @param    string $REG_session PHP Session ID
570
+	 * @throws EE_Error
571
+	 * @throws RuntimeException
572
+	 */
573
+	public function set_session($REG_session = '')
574
+	{
575
+		$this->set('REG_session', $REG_session);
576
+	}
577
+
578
+
579
+	/**
580
+	 *        Set Registration URL Link
581
+	 *
582
+	 * @param    string $REG_url_link Registration URL Link
583
+	 * @throws EE_Error
584
+	 * @throws RuntimeException
585
+	 */
586
+	public function set_reg_url_link($REG_url_link = '')
587
+	{
588
+		$this->set('REG_url_link', $REG_url_link);
589
+	}
590
+
591
+
592
+	/**
593
+	 *        Set Attendee Counter
594
+	 *
595
+	 * @param        int $REG_count Primary Attendee
596
+	 * @throws EE_Error
597
+	 * @throws RuntimeException
598
+	 */
599
+	public function set_count($REG_count = 1)
600
+	{
601
+		$this->set('REG_count', $REG_count);
602
+	}
603
+
604
+
605
+	/**
606
+	 *        Set Group Size
607
+	 *
608
+	 * @param        boolean $REG_group_size Group Registration
609
+	 * @throws EE_Error
610
+	 * @throws RuntimeException
611
+	 */
612
+	public function set_group_size($REG_group_size = false)
613
+	{
614
+		$this->set('REG_group_size', $REG_group_size);
615
+	}
616
+
617
+
618
+	/**
619
+	 *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
620
+	 *    EEM_Registration::status_id_not_approved
621
+	 *
622
+	 * @return        boolean
623
+	 */
624
+	public function is_not_approved()
625
+	{
626
+		return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
627
+	}
628
+
629
+
630
+	/**
631
+	 *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
632
+	 *    EEM_Registration::status_id_pending_payment
633
+	 *
634
+	 * @return        boolean
635
+	 */
636
+	public function is_pending_payment()
637
+	{
638
+		return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
639
+	}
640
+
641
+
642
+	/**
643
+	 *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
644
+	 *
645
+	 * @return        boolean
646
+	 */
647
+	public function is_approved()
648
+	{
649
+		return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
650
+	}
651
+
652
+
653
+	/**
654
+	 *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
655
+	 *
656
+	 * @return        boolean
657
+	 */
658
+	public function is_cancelled()
659
+	{
660
+		return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
661
+	}
662
+
663
+
664
+	/**
665
+	 *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
666
+	 *
667
+	 * @return        boolean
668
+	 */
669
+	public function is_declined()
670
+	{
671
+		return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
672
+	}
673
+
674
+
675
+	/**
676
+	 *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
677
+	 *    EEM_Registration::status_id_incomplete
678
+	 *
679
+	 * @return        boolean
680
+	 */
681
+	public function is_incomplete()
682
+	{
683
+		return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
684
+	}
685
+
686
+
687
+	/**
688
+	 *        Set Registration Date
689
+	 *
690
+	 * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
691
+	 *                                                 Date
692
+	 * @throws EE_Error
693
+	 * @throws RuntimeException
694
+	 */
695
+	public function set_reg_date($REG_date = false)
696
+	{
697
+		$this->set('REG_date', $REG_date);
698
+	}
699
+
700
+
701
+	/**
702
+	 *    Set final price owing for this registration after all ticket/price modifications
703
+	 *
704
+	 * @access    public
705
+	 * @param    float $REG_final_price
706
+	 * @throws EE_Error
707
+	 * @throws RuntimeException
708
+	 */
709
+	public function set_final_price($REG_final_price = 0.00)
710
+	{
711
+		$this->set('REG_final_price', $REG_final_price);
712
+	}
713
+
714
+
715
+	/**
716
+	 *    Set amount paid towards this registration's final price
717
+	 *
718
+	 * @access    public
719
+	 * @param    float $REG_paid
720
+	 * @throws EE_Error
721
+	 * @throws RuntimeException
722
+	 */
723
+	public function set_paid($REG_paid = 0.00)
724
+	{
725
+		$this->set('REG_paid', $REG_paid);
726
+	}
727
+
728
+
729
+	/**
730
+	 *        Attendee Is Going
731
+	 *
732
+	 * @param        boolean $REG_att_is_going Attendee Is Going
733
+	 * @throws EE_Error
734
+	 * @throws RuntimeException
735
+	 */
736
+	public function set_att_is_going($REG_att_is_going = false)
737
+	{
738
+		$this->set('REG_att_is_going', $REG_att_is_going);
739
+	}
740
+
741
+
742
+	/**
743
+	 * Gets the related attendee
744
+	 *
745
+	 * @return EE_Attendee
746
+	 * @throws EE_Error
747
+	 */
748
+	public function attendee()
749
+	{
750
+		return $this->get_first_related('Attendee');
751
+	}
752
+
753
+
754
+	/**
755
+	 *        get Event ID
756
+	 */
757
+	public function event_ID()
758
+	{
759
+		return $this->get('EVT_ID');
760
+	}
761
+
762
+
763
+	/**
764
+	 *        get Event ID
765
+	 */
766
+	public function event_name()
767
+	{
768
+		$event = $this->event_obj();
769
+		if ($event) {
770
+			return $event->name();
771
+		} else {
772
+			return null;
773
+		}
774
+	}
775
+
776
+
777
+	/**
778
+	 * Fetches the event this registration is for
779
+	 *
780
+	 * @return EE_Event
781
+	 * @throws EE_Error
782
+	 */
783
+	public function event_obj()
784
+	{
785
+		return $this->get_first_related('Event');
786
+	}
787
+
788
+
789
+	/**
790
+	 *        get Attendee ID
791
+	 */
792
+	public function attendee_ID()
793
+	{
794
+		return $this->get('ATT_ID');
795
+	}
796
+
797
+
798
+	/**
799
+	 *        get PHP Session ID
800
+	 */
801
+	public function session_ID()
802
+	{
803
+		return $this->get('REG_session');
804
+	}
805
+
806
+
807
+	/**
808
+	 * Gets the string which represents the URL trigger for the receipt template in the message template system.
809
+	 *
810
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
811
+	 * @return string
812
+	 */
813
+	public function receipt_url($messenger = 'html')
814
+	{
815
+
816
+		/**
817
+		 * The below will be deprecated one version after this.  We check first if there is a custom receipt template
818
+		 * already in use on old system.  If there is then we just return the standard url for it.
819
+		 *
820
+		 * @since 4.5.0
821
+		 */
822
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
823
+		$has_custom = EEH_Template::locate_template(
824
+			$template_relative_path,
825
+			array(),
826
+			true,
827
+			true,
828
+			true
829
+		);
830
+
831
+		if ($has_custom) {
832
+			return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
833
+		}
834
+		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
835
+	}
836
+
837
+
838
+	/**
839
+	 * Gets the string which represents the URL trigger for the invoice template in the message template system.
840
+	 *
841
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
842
+	 * @return string
843
+	 * @throws EE_Error
844
+	 */
845
+	public function invoice_url($messenger = 'html')
846
+	{
847
+		/**
848
+		 * The below will be deprecated one version after this.  We check first if there is a custom invoice template
849
+		 * already in use on old system.  If there is then we just return the standard url for it.
850
+		 *
851
+		 * @since 4.5.0
852
+		 */
853
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
854
+		$has_custom = EEH_Template::locate_template(
855
+			$template_relative_path,
856
+			array(),
857
+			true,
858
+			true,
859
+			true
860
+		);
861
+
862
+		if ($has_custom) {
863
+			if ($messenger == 'html') {
864
+				return $this->invoice_url('launch');
865
+			}
866
+			$route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
867
+
868
+			$query_args = array('ee' => $route, 'id' => $this->reg_url_link());
869
+			if ($messenger == 'html') {
870
+				$query_args['html'] = true;
871
+			}
872
+			return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
873
+		}
874
+		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
875
+	}
876
+
877
+
878
+	/**
879
+	 * get Registration URL Link
880
+	 *
881
+	 * @access public
882
+	 * @return string
883
+	 * @throws EE_Error
884
+	 */
885
+	public function reg_url_link()
886
+	{
887
+		return (string) $this->get('REG_url_link');
888
+	}
889
+
890
+
891
+	/**
892
+	 * Echoes out invoice_url()
893
+	 *
894
+	 * @param string $type 'download','launch', or 'html' (default is 'launch')
895
+	 * @return void
896
+	 * @throws EE_Error
897
+	 */
898
+	public function e_invoice_url($type = 'launch')
899
+	{
900
+		echo $this->invoice_url($type);
901
+	}
902
+
903
+
904
+	/**
905
+	 * Echoes out payment_overview_url
906
+	 */
907
+	public function e_payment_overview_url()
908
+	{
909
+		echo $this->payment_overview_url();
910
+	}
911
+
912
+
913
+	/**
914
+	 * Gets the URL for the checkout payment options reg step
915
+	 * with this registration's REG_url_link added as a query parameter
916
+	 *
917
+	 * @param bool $clear_session Set to true when you want to clear the session on revisiting the
918
+	 *                            payment overview url.
919
+	 * @return string
920
+	 * @throws InvalidInterfaceException
921
+	 * @throws InvalidDataTypeException
922
+	 * @throws EE_Error
923
+	 * @throws InvalidArgumentException
924
+	 */
925
+	public function payment_overview_url($clear_session = false)
926
+	{
927
+		return add_query_arg(
928
+			(array) apply_filters(
929
+				'FHEE__EE_Registration__payment_overview_url__query_args',
930
+				array(
931
+					'e_reg_url_link' => $this->reg_url_link(),
932
+					'step'           => 'payment_options',
933
+					'revisit'        => true,
934
+					'clear_session'  => (bool) $clear_session,
935
+				),
936
+				$this
937
+			),
938
+			EE_Registry::instance()->CFG->core->reg_page_url()
939
+		);
940
+	}
941
+
942
+
943
+	/**
944
+	 * Gets the URL for the checkout attendee information reg step
945
+	 * with this registration's REG_url_link added as a query parameter
946
+	 *
947
+	 * @return string
948
+	 * @throws InvalidInterfaceException
949
+	 * @throws InvalidDataTypeException
950
+	 * @throws EE_Error
951
+	 * @throws InvalidArgumentException
952
+	 */
953
+	public function edit_attendee_information_url()
954
+	{
955
+		return add_query_arg(
956
+			(array) apply_filters(
957
+				'FHEE__EE_Registration__edit_attendee_information_url__query_args',
958
+				array(
959
+					'e_reg_url_link' => $this->reg_url_link(),
960
+					'step'           => 'attendee_information',
961
+					'revisit'        => true,
962
+				),
963
+				$this
964
+			),
965
+			EE_Registry::instance()->CFG->core->reg_page_url()
966
+		);
967
+	}
968
+
969
+
970
+	/**
971
+	 * Simply generates and returns the appropriate admin_url link to edit this registration
972
+	 *
973
+	 * @return string
974
+	 * @throws EE_Error
975
+	 */
976
+	public function get_admin_edit_url()
977
+	{
978
+		return EEH_URL::add_query_args_and_nonce(
979
+			array(
980
+				'page'    => 'espresso_registrations',
981
+				'action'  => 'view_registration',
982
+				'_REG_ID' => $this->ID(),
983
+			),
984
+			admin_url('admin.php')
985
+		);
986
+	}
987
+
988
+
989
+	/**
990
+	 *    is_primary_registrant?
991
+	 */
992
+	public function is_primary_registrant()
993
+	{
994
+		return $this->get('REG_count') === 1 ? true : false;
995
+	}
996
+
997
+
998
+	/**
999
+	 * This returns the primary registration object for this registration group (which may be this object).
1000
+	 *
1001
+	 * @return EE_Registration
1002
+	 * @throws EE_Error
1003
+	 */
1004
+	public function get_primary_registration()
1005
+	{
1006
+		if ($this->is_primary_registrant()) {
1007
+			return $this;
1008
+		}
1009
+
1010
+		// k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
1011
+		/** @var EE_Registration $primary_registrant */
1012
+		$primary_registrant = EEM_Registration::instance()->get_one(
1013
+			array(
1014
+				array(
1015
+					'TXN_ID'    => $this->transaction_ID(),
1016
+					'REG_count' => 1,
1017
+				),
1018
+			)
1019
+		);
1020
+		return $primary_registrant;
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 *        get  Attendee Number
1026
+	 *
1027
+	 * @access        public
1028
+	 */
1029
+	public function count()
1030
+	{
1031
+		return $this->get('REG_count');
1032
+	}
1033
+
1034
+
1035
+	/**
1036
+	 *        get Group Size
1037
+	 */
1038
+	public function group_size()
1039
+	{
1040
+		return $this->get('REG_group_size');
1041
+	}
1042
+
1043
+
1044
+	/**
1045
+	 *        get Registration Date
1046
+	 */
1047
+	public function date()
1048
+	{
1049
+		return $this->get('REG_date');
1050
+	}
1051
+
1052
+
1053
+	/**
1054
+	 * gets a pretty date
1055
+	 *
1056
+	 * @param string $date_format
1057
+	 * @param string $time_format
1058
+	 * @return string
1059
+	 * @throws EE_Error
1060
+	 */
1061
+	public function pretty_date($date_format = null, $time_format = null)
1062
+	{
1063
+		return $this->get_datetime('REG_date', $date_format, $time_format);
1064
+	}
1065
+
1066
+
1067
+	/**
1068
+	 * final_price
1069
+	 * the registration's share of the transaction total, so that the
1070
+	 * sum of all the transaction's REG_final_prices equal the transaction's total
1071
+	 *
1072
+	 * @return float
1073
+	 * @throws EE_Error
1074
+	 */
1075
+	public function final_price()
1076
+	{
1077
+		return $this->get('REG_final_price');
1078
+	}
1079
+
1080
+
1081
+	/**
1082
+	 * pretty_final_price
1083
+	 *  final price as formatted string, with correct decimal places and currency symbol
1084
+	 *
1085
+	 * @return string
1086
+	 * @throws EE_Error
1087
+	 */
1088
+	public function pretty_final_price()
1089
+	{
1090
+		return $this->get_pretty('REG_final_price');
1091
+	}
1092
+
1093
+
1094
+	/**
1095
+	 * get paid (yeah)
1096
+	 *
1097
+	 * @return float
1098
+	 * @throws EE_Error
1099
+	 */
1100
+	public function paid()
1101
+	{
1102
+		return $this->get('REG_paid');
1103
+	}
1104
+
1105
+
1106
+	/**
1107
+	 * pretty_paid
1108
+	 *
1109
+	 * @return float
1110
+	 * @throws EE_Error
1111
+	 */
1112
+	public function pretty_paid()
1113
+	{
1114
+		return $this->get_pretty('REG_paid');
1115
+	}
1116
+
1117
+
1118
+	/**
1119
+	 * owes_monies_and_can_pay
1120
+	 * whether or not this registration has monies owing and it's' status allows payment
1121
+	 *
1122
+	 * @param array $requires_payment
1123
+	 * @return bool
1124
+	 * @throws EE_Error
1125
+	 */
1126
+	public function owes_monies_and_can_pay($requires_payment = array())
1127
+	{
1128
+		// these reg statuses require payment (if event is not free)
1129
+		$requires_payment = ! empty($requires_payment)
1130
+			? $requires_payment
1131
+			: EEM_Registration::reg_statuses_that_allow_payment();
1132
+		if (in_array($this->status_ID(), $requires_payment) &&
1133
+			$this->final_price() != 0 &&
1134
+			$this->final_price() != $this->paid()
1135
+		) {
1136
+			return true;
1137
+		} else {
1138
+			return false;
1139
+		}
1140
+	}
1141
+
1142
+
1143
+	/**
1144
+	 * Prints out the return value of $this->pretty_status()
1145
+	 *
1146
+	 * @param bool $show_icons
1147
+	 * @return void
1148
+	 * @throws EE_Error
1149
+	 */
1150
+	public function e_pretty_status($show_icons = false)
1151
+	{
1152
+		echo $this->pretty_status($show_icons);
1153
+	}
1154
+
1155
+
1156
+	/**
1157
+	 * Returns a nice version of the status for displaying to customers
1158
+	 *
1159
+	 * @param bool $show_icons
1160
+	 * @return string
1161
+	 * @throws EE_Error
1162
+	 */
1163
+	public function pretty_status($show_icons = false)
1164
+	{
1165
+		$status = EEM_Status::instance()->localized_status(
1166
+			array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
1167
+			false,
1168
+			'sentence'
1169
+		);
1170
+		$icon = '';
1171
+		switch ($this->status_ID()) {
1172
+			case EEM_Registration::status_id_approved:
1173
+				$icon = $show_icons
1174
+					? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
1175
+					: '';
1176
+				break;
1177
+			case EEM_Registration::status_id_pending_payment:
1178
+				$icon = $show_icons
1179
+					? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
1180
+					: '';
1181
+				break;
1182
+			case EEM_Registration::status_id_not_approved:
1183
+				$icon = $show_icons
1184
+					? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
1185
+					: '';
1186
+				break;
1187
+			case EEM_Registration::status_id_cancelled:
1188
+				$icon = $show_icons
1189
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
1190
+					: '';
1191
+				break;
1192
+			case EEM_Registration::status_id_incomplete:
1193
+				$icon = $show_icons
1194
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1195
+					: '';
1196
+				break;
1197
+			case EEM_Registration::status_id_declined:
1198
+				$icon = $show_icons
1199
+					? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1200
+					: '';
1201
+				break;
1202
+			case EEM_Registration::status_id_wait_list:
1203
+				$icon = $show_icons
1204
+					? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1205
+					: '';
1206
+				break;
1207
+		}
1208
+		return $icon . $status[ $this->status_ID() ];
1209
+	}
1210
+
1211
+
1212
+	/**
1213
+	 *        get Attendee Is Going
1214
+	 */
1215
+	public function att_is_going()
1216
+	{
1217
+		return $this->get('REG_att_is_going');
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 * Gets related answers
1223
+	 *
1224
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1225
+	 * @return EE_Answer[]
1226
+	 * @throws EE_Error
1227
+	 */
1228
+	public function answers($query_params = null)
1229
+	{
1230
+		return $this->get_many_related('Answer', $query_params);
1231
+	}
1232
+
1233
+
1234
+	/**
1235
+	 * Gets the registration's answer value to the specified question
1236
+	 * (either the question's ID or a question object)
1237
+	 *
1238
+	 * @param EE_Question|int $question
1239
+	 * @param bool            $pretty_value
1240
+	 * @return array|string if pretty_value= true, the result will always be a string
1241
+	 * (because the answer might be an array of answer values, so passing pretty_value=true
1242
+	 * will convert it into some kind of string)
1243
+	 * @throws EE_Error
1244
+	 */
1245
+	public function answer_value_to_question($question, $pretty_value = true)
1246
+	{
1247
+		$question_id = EEM_Question::instance()->ensure_is_ID($question);
1248
+		return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1249
+	}
1250
+
1251
+
1252
+	/**
1253
+	 * question_groups
1254
+	 * returns an array of EE_Question_Group objects for this registration
1255
+	 *
1256
+	 * @return EE_Question_Group[]
1257
+	 * @throws EE_Error
1258
+	 * @throws InvalidArgumentException
1259
+	 * @throws InvalidDataTypeException
1260
+	 * @throws InvalidInterfaceException
1261
+	 * @throws ReflectionException
1262
+	 */
1263
+	public function question_groups()
1264
+	{
1265
+		return EEM_Event::instance()->get_question_groups_for_event($this->event_ID(), $this);
1266
+	}
1267
+
1268
+
1269
+	/**
1270
+	 * count_question_groups
1271
+	 * returns a count of the number of EE_Question_Group objects for this registration
1272
+	 *
1273
+	 * @return int
1274
+	 * @throws EE_Error
1275
+	 * @throws EntityNotFoundException
1276
+	 * @throws InvalidArgumentException
1277
+	 * @throws InvalidDataTypeException
1278
+	 * @throws InvalidInterfaceException
1279
+	 * @throws ReflectionException
1280
+	 */
1281
+	public function count_question_groups()
1282
+	{
1283
+		return EEM_Event::instance()->count_related(
1284
+			$this->event_ID(),
1285
+			'Question_Group',
1286
+			[
1287
+				[
1288
+					'Event_Question_Group.'
1289
+					. EEM_Event_Question_Group::instance()->fieldNameForContext($this->is_primary_registrant()) => true,
1290
+				]
1291
+			]
1292
+		);
1293
+	}
1294
+
1295
+
1296
+	/**
1297
+	 * Returns the registration date in the 'standard' string format
1298
+	 * (function may be improved in the future to allow for different formats and timezones)
1299
+	 *
1300
+	 * @return string
1301
+	 * @throws EE_Error
1302
+	 */
1303
+	public function reg_date()
1304
+	{
1305
+		return $this->get_datetime('REG_date');
1306
+	}
1307
+
1308
+
1309
+	/**
1310
+	 * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1311
+	 * the ticket this registration purchased, or the datetime they have registered
1312
+	 * to attend)
1313
+	 *
1314
+	 * @return EE_Datetime_Ticket
1315
+	 * @throws EE_Error
1316
+	 */
1317
+	public function datetime_ticket()
1318
+	{
1319
+		return $this->get_first_related('Datetime_Ticket');
1320
+	}
1321
+
1322
+
1323
+	/**
1324
+	 * Sets the registration's datetime_ticket.
1325
+	 *
1326
+	 * @param EE_Datetime_Ticket $datetime_ticket
1327
+	 * @return EE_Datetime_Ticket
1328
+	 * @throws EE_Error
1329
+	 */
1330
+	public function set_datetime_ticket($datetime_ticket)
1331
+	{
1332
+		return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1333
+	}
1334
+
1335
+	/**
1336
+	 * Gets deleted
1337
+	 *
1338
+	 * @return bool
1339
+	 * @throws EE_Error
1340
+	 */
1341
+	public function deleted()
1342
+	{
1343
+		return $this->get('REG_deleted');
1344
+	}
1345
+
1346
+	/**
1347
+	 * Sets deleted
1348
+	 *
1349
+	 * @param boolean $deleted
1350
+	 * @return bool
1351
+	 * @throws EE_Error
1352
+	 * @throws RuntimeException
1353
+	 */
1354
+	public function set_deleted($deleted)
1355
+	{
1356
+		if ($deleted) {
1357
+			$this->delete();
1358
+		} else {
1359
+			$this->restore();
1360
+		}
1361
+	}
1362
+
1363
+
1364
+	/**
1365
+	 * Get the status object of this object
1366
+	 *
1367
+	 * @return EE_Status
1368
+	 * @throws EE_Error
1369
+	 */
1370
+	public function status_obj()
1371
+	{
1372
+		return $this->get_first_related('Status');
1373
+	}
1374
+
1375
+
1376
+	/**
1377
+	 * Returns the number of times this registration has checked into any of the datetimes
1378
+	 * its available for
1379
+	 *
1380
+	 * @return int
1381
+	 * @throws EE_Error
1382
+	 */
1383
+	public function count_checkins()
1384
+	{
1385
+		return $this->get_model()->count_related($this, 'Checkin');
1386
+	}
1387
+
1388
+
1389
+	/**
1390
+	 * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1391
+	 * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1392
+	 *
1393
+	 * @return int
1394
+	 * @throws EE_Error
1395
+	 */
1396
+	public function count_checkins_not_checkedout()
1397
+	{
1398
+		return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1399
+	}
1400
+
1401
+
1402
+	/**
1403
+	 * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1404
+	 *
1405
+	 * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1406
+	 * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1407
+	 *                                          consider registration status as well as datetime access.
1408
+	 * @return bool
1409
+	 * @throws EE_Error
1410
+	 */
1411
+	public function can_checkin($DTT_OR_ID, $check_approved = true)
1412
+	{
1413
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1414
+
1415
+		// first check registration status
1416
+		if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1417
+			return false;
1418
+		}
1419
+		// is there a datetime ticket that matches this dtt_ID?
1420
+		if (! (EEM_Datetime_Ticket::instance()->exists(
1421
+			array(
1422
+				array(
1423
+					'TKT_ID' => $this->get('TKT_ID'),
1424
+					'DTT_ID' => $DTT_ID,
1425
+				),
1426
+			)
1427
+		))
1428
+		) {
1429
+			return false;
1430
+		}
1431
+
1432
+		// final check is against TKT_uses
1433
+		return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1434
+	}
1435
+
1436
+
1437
+	/**
1438
+	 * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1439
+	 * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1440
+	 * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1441
+	 * then return false.  Otherwise return true.
1442
+	 *
1443
+	 * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1444
+	 * @return bool true means can checkin.  false means cannot checkin.
1445
+	 * @throws EE_Error
1446
+	 */
1447
+	public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1448
+	{
1449
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1450
+
1451
+		if (! $DTT_ID) {
1452
+			return false;
1453
+		}
1454
+
1455
+		$max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1456
+
1457
+		// if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1458
+		// check-in or not.
1459
+		if (! $max_uses || $max_uses === EE_INF) {
1460
+			return true;
1461
+		}
1462
+
1463
+		// does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1464
+		// go ahead and toggle.
1465
+		if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1466
+			return true;
1467
+		}
1468
+
1469
+		// made it here so the last check is whether the number of checkins per unique datetime on this registration
1470
+		// disallows further check-ins.
1471
+		$count_unique_dtt_checkins = EEM_Checkin::instance()->count(
1472
+			array(
1473
+				array(
1474
+					'REG_ID' => $this->ID(),
1475
+					'CHK_in' => true,
1476
+				),
1477
+			),
1478
+			'DTT_ID',
1479
+			true
1480
+		);
1481
+		// checkins have already reached their max number of uses
1482
+		// so registrant can NOT checkin
1483
+		if ($count_unique_dtt_checkins >= $max_uses) {
1484
+			EE_Error::add_error(
1485
+				esc_html__(
1486
+					'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1487
+					'event_espresso'
1488
+				),
1489
+				__FILE__,
1490
+				__FUNCTION__,
1491
+				__LINE__
1492
+			);
1493
+			return false;
1494
+		}
1495
+		return true;
1496
+	}
1497
+
1498
+
1499
+	/**
1500
+	 * toggle Check-in status for this registration
1501
+	 * Check-ins are toggled in the following order:
1502
+	 * never checked in -> checked in
1503
+	 * checked in -> checked out
1504
+	 * checked out -> checked in
1505
+	 *
1506
+	 * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1507
+	 *                      If not included or null, then it is assumed latest datetime is being toggled.
1508
+	 * @param bool $verify  If true then can_checkin() is used to verify whether the person
1509
+	 *                      can be checked in or not.  Otherwise this forces change in checkin status.
1510
+	 * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1511
+	 * @throws EE_Error
1512
+	 */
1513
+	public function toggle_checkin_status($DTT_ID = null, $verify = false)
1514
+	{
1515
+		if (empty($DTT_ID)) {
1516
+			$datetime = $this->get_latest_related_datetime();
1517
+			$DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1518
+			// verify the registration can checkin for the given DTT_ID
1519
+		} elseif (! $this->can_checkin($DTT_ID, $verify)) {
1520
+			EE_Error::add_error(
1521
+				sprintf(
1522
+					esc_html__(
1523
+						'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1524
+						'event_espresso'
1525
+					),
1526
+					$this->ID(),
1527
+					$DTT_ID
1528
+				),
1529
+				__FILE__,
1530
+				__FUNCTION__,
1531
+				__LINE__
1532
+			);
1533
+			return false;
1534
+		}
1535
+		$status_paths = array(
1536
+			EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1537
+			EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1538
+			EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1539
+		);
1540
+		// start by getting the current status so we know what status we'll be changing to.
1541
+		$cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1542
+		$status_to = $status_paths[ $cur_status ];
1543
+		// database only records true for checked IN or false for checked OUT
1544
+		// no record ( null ) means checked in NEVER, but we obviously don't save that
1545
+		$new_status = $status_to === EE_Checkin::status_checked_in ? true : false;
1546
+		// add relation - note Check-ins are always creating new rows
1547
+		// because we are keeping track of Check-ins over time.
1548
+		// Eventually we'll probably want to show a list table
1549
+		// for the individual Check-ins so that they can be managed.
1550
+		$checkin = EE_Checkin::new_instance(
1551
+			array(
1552
+				'REG_ID' => $this->ID(),
1553
+				'DTT_ID' => $DTT_ID,
1554
+				'CHK_in' => $new_status,
1555
+			)
1556
+		);
1557
+		// if the record could not be saved then return false
1558
+		if ($checkin->save() === 0) {
1559
+			if (WP_DEBUG) {
1560
+				global $wpdb;
1561
+				$error = sprintf(
1562
+					esc_html__(
1563
+						'Registration check in update failed because of the following database error: %1$s%2$s',
1564
+						'event_espresso'
1565
+					),
1566
+					'<br />',
1567
+					$wpdb->last_error
1568
+				);
1569
+			} else {
1570
+				$error = esc_html__(
1571
+					'Registration check in update failed because of an unknown database error',
1572
+					'event_espresso'
1573
+				);
1574
+			}
1575
+			EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1576
+			return false;
1577
+		}
1578
+		return $status_to;
1579
+	}
1580
+
1581
+
1582
+	/**
1583
+	 * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1584
+	 * "Latest" is defined by the `DTT_EVT_start` column.
1585
+	 *
1586
+	 * @return EE_Datetime|null
1587
+	 * @throws EE_Error
1588
+	 */
1589
+	public function get_latest_related_datetime()
1590
+	{
1591
+		return EEM_Datetime::instance()->get_one(
1592
+			array(
1593
+				array(
1594
+					'Ticket.Registration.REG_ID' => $this->ID(),
1595
+				),
1596
+				'order_by' => array('DTT_EVT_start' => 'DESC'),
1597
+			)
1598
+		);
1599
+	}
1600
+
1601
+
1602
+	/**
1603
+	 * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1604
+	 * "Earliest" is defined by the `DTT_EVT_start` column.
1605
+	 *
1606
+	 * @throws EE_Error
1607
+	 */
1608
+	public function get_earliest_related_datetime()
1609
+	{
1610
+		return EEM_Datetime::instance()->get_one(
1611
+			array(
1612
+				array(
1613
+					'Ticket.Registration.REG_ID' => $this->ID(),
1614
+				),
1615
+				'order_by' => array('DTT_EVT_start' => 'ASC'),
1616
+			)
1617
+		);
1618
+	}
1619
+
1620
+
1621
+	/**
1622
+	 * This method simply returns the check-in status for this registration and the given datetime.
1623
+	 * If neither the datetime nor the checkin values are provided as arguments,
1624
+	 * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1625
+	 *
1626
+	 * @param  int       $DTT_ID  The ID of the datetime we're checking against
1627
+	 *                            (if empty we'll get the primary datetime for
1628
+	 *                            this registration (via event) and use it's ID);
1629
+	 * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1630
+	 *
1631
+	 * @return int                Integer representing Check-in status.
1632
+	 * @throws EE_Error
1633
+	 */
1634
+	public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1635
+	{
1636
+		$checkin_query_params = array(
1637
+			'order_by' => array('CHK_timestamp' => 'DESC'),
1638
+		);
1639
+
1640
+		if ($DTT_ID > 0) {
1641
+			$checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1642
+		}
1643
+
1644
+		// get checkin object (if exists)
1645
+		$checkin = $checkin instanceof EE_Checkin
1646
+			? $checkin
1647
+			: $this->get_first_related('Checkin', $checkin_query_params);
1648
+		if ($checkin instanceof EE_Checkin) {
1649
+			if ($checkin->get('CHK_in')) {
1650
+				return EE_Checkin::status_checked_in; // checked in
1651
+			}
1652
+			return EE_Checkin::status_checked_out; // had checked in but is now checked out.
1653
+		}
1654
+		return EE_Checkin::status_checked_never; // never been checked in
1655
+	}
1656
+
1657
+
1658
+	/**
1659
+	 * This method returns a localized message for the toggled Check-in message.
1660
+	 *
1661
+	 * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1662
+	 *                     then it is assumed Check-in for primary datetime was toggled.
1663
+	 * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1664
+	 *                     message can be customized with the attendee name.
1665
+	 * @return string internationalized message
1666
+	 * @throws EE_Error
1667
+	 */
1668
+	public function get_checkin_msg($DTT_ID, $error = false)
1669
+	{
1670
+		// let's get the attendee first so we can include the name of the attendee
1671
+		$attendee = $this->get_first_related('Attendee');
1672
+		if ($attendee instanceof EE_Attendee) {
1673
+			if ($error) {
1674
+				return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1675
+			}
1676
+			$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1677
+			// what is the status message going to be?
1678
+			switch ($cur_status) {
1679
+				case EE_Checkin::status_checked_never:
1680
+					return sprintf(
1681
+						__("%s has been removed from Check-in records", "event_espresso"),
1682
+						$attendee->full_name()
1683
+					);
1684
+					break;
1685
+				case EE_Checkin::status_checked_in:
1686
+					return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1687
+					break;
1688
+				case EE_Checkin::status_checked_out:
1689
+					return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1690
+					break;
1691
+			}
1692
+		}
1693
+		return esc_html__("The check-in status could not be determined.", "event_espresso");
1694
+	}
1695
+
1696
+
1697
+	/**
1698
+	 * Returns the related EE_Transaction to this registration
1699
+	 *
1700
+	 * @return EE_Transaction
1701
+	 * @throws EE_Error
1702
+	 * @throws EntityNotFoundException
1703
+	 */
1704
+	public function transaction()
1705
+	{
1706
+		$transaction = $this->get_first_related('Transaction');
1707
+		if (! $transaction instanceof \EE_Transaction) {
1708
+			throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1709
+		}
1710
+		return $transaction;
1711
+	}
1712
+
1713
+
1714
+	/**
1715
+	 *        get Registration Code
1716
+	 */
1717
+	public function reg_code()
1718
+	{
1719
+		return $this->get('REG_code');
1720
+	}
1721
+
1722
+
1723
+	/**
1724
+	 *        get Transaction ID
1725
+	 */
1726
+	public function transaction_ID()
1727
+	{
1728
+		return $this->get('TXN_ID');
1729
+	}
1730
+
1731
+
1732
+	/**
1733
+	 * @return int
1734
+	 * @throws EE_Error
1735
+	 */
1736
+	public function ticket_ID()
1737
+	{
1738
+		return $this->get('TKT_ID');
1739
+	}
1740
+
1741
+
1742
+	/**
1743
+	 *        Set Registration Code
1744
+	 *
1745
+	 * @access    public
1746
+	 * @param    string  $REG_code Registration Code
1747
+	 * @param    boolean $use_default
1748
+	 * @throws EE_Error
1749
+	 */
1750
+	public function set_reg_code($REG_code, $use_default = false)
1751
+	{
1752
+		if (empty($REG_code)) {
1753
+			EE_Error::add_error(
1754
+				esc_html__('REG_code can not be empty.', 'event_espresso'),
1755
+				__FILE__,
1756
+				__FUNCTION__,
1757
+				__LINE__
1758
+			);
1759
+			return;
1760
+		}
1761
+		if (! $this->reg_code()) {
1762
+			parent::set('REG_code', $REG_code, $use_default);
1763
+		} else {
1764
+			EE_Error::doing_it_wrong(
1765
+				__CLASS__ . '::' . __FUNCTION__,
1766
+				esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1767
+				'4.6.0'
1768
+			);
1769
+		}
1770
+	}
1771
+
1772
+
1773
+	/**
1774
+	 * Returns all other registrations in the same group as this registrant who have the same ticket option.
1775
+	 * Note, if you want to just get all registrations in the same transaction (group), use:
1776
+	 *    $registration->transaction()->registrations();
1777
+	 *
1778
+	 * @since 4.5.0
1779
+	 * @return EE_Registration[] or empty array if this isn't a group registration.
1780
+	 * @throws EE_Error
1781
+	 */
1782
+	public function get_all_other_registrations_in_group()
1783
+	{
1784
+		if ($this->group_size() < 2) {
1785
+			return array();
1786
+		}
1787
+
1788
+		$query[0] = array(
1789
+			'TXN_ID' => $this->transaction_ID(),
1790
+			'REG_ID' => array('!=', $this->ID()),
1791
+			'TKT_ID' => $this->ticket_ID(),
1792
+		);
1793
+		/** @var EE_Registration[] $registrations */
1794
+		$registrations = $this->get_model()->get_all($query);
1795
+		return $registrations;
1796
+	}
1797
+
1798
+	/**
1799
+	 * Return the link to the admin details for the object.
1800
+	 *
1801
+	 * @return string
1802
+	 * @throws EE_Error
1803
+	 */
1804
+	public function get_admin_details_link()
1805
+	{
1806
+		EE_Registry::instance()->load_helper('URL');
1807
+		return EEH_URL::add_query_args_and_nonce(
1808
+			array(
1809
+				'page'    => 'espresso_registrations',
1810
+				'action'  => 'view_registration',
1811
+				'_REG_ID' => $this->ID(),
1812
+			),
1813
+			admin_url('admin.php')
1814
+		);
1815
+	}
1816
+
1817
+	/**
1818
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1819
+	 *
1820
+	 * @return string
1821
+	 * @throws EE_Error
1822
+	 */
1823
+	public function get_admin_edit_link()
1824
+	{
1825
+		return $this->get_admin_details_link();
1826
+	}
1827
+
1828
+	/**
1829
+	 * Returns the link to a settings page for the object.
1830
+	 *
1831
+	 * @return string
1832
+	 * @throws EE_Error
1833
+	 */
1834
+	public function get_admin_settings_link()
1835
+	{
1836
+		return $this->get_admin_details_link();
1837
+	}
1838
+
1839
+	/**
1840
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
1841
+	 *
1842
+	 * @return string
1843
+	 */
1844
+	public function get_admin_overview_link()
1845
+	{
1846
+		EE_Registry::instance()->load_helper('URL');
1847
+		return EEH_URL::add_query_args_and_nonce(
1848
+			array(
1849
+				'page' => 'espresso_registrations',
1850
+			),
1851
+			admin_url('admin.php')
1852
+		);
1853
+	}
1854
+
1855
+
1856
+	/**
1857
+	 * @param array $query_params
1858
+	 *
1859
+	 * @return \EE_Registration[]
1860
+	 * @throws EE_Error
1861
+	 */
1862
+	public function payments($query_params = array())
1863
+	{
1864
+		return $this->get_many_related('Payment', $query_params);
1865
+	}
1866
+
1867
+
1868
+	/**
1869
+	 * @param array $query_params
1870
+	 *
1871
+	 * @return \EE_Registration_Payment[]
1872
+	 * @throws EE_Error
1873
+	 */
1874
+	public function registration_payments($query_params = array())
1875
+	{
1876
+		return $this->get_many_related('Registration_Payment', $query_params);
1877
+	}
1878
+
1879
+
1880
+	/**
1881
+	 * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1882
+	 * Note: if there are no payments on the registration there will be no payment method returned.
1883
+	 *
1884
+	 * @return EE_Payment_Method|null
1885
+	 */
1886
+	public function payment_method()
1887
+	{
1888
+		return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1889
+	}
1890
+
1891
+
1892
+	/**
1893
+	 * @return \EE_Line_Item
1894
+	 * @throws EntityNotFoundException
1895
+	 * @throws EE_Error
1896
+	 */
1897
+	public function ticket_line_item()
1898
+	{
1899
+		$ticket = $this->ticket();
1900
+		$transaction = $this->transaction();
1901
+		$line_item = null;
1902
+		$ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1903
+			$transaction->total_line_item(),
1904
+			'Ticket',
1905
+			array($ticket->ID())
1906
+		);
1907
+		foreach ($ticket_line_items as $ticket_line_item) {
1908
+			if ($ticket_line_item instanceof \EE_Line_Item
1909
+				&& $ticket_line_item->OBJ_type() === 'Ticket'
1910
+				&& $ticket_line_item->OBJ_ID() === $ticket->ID()
1911
+			) {
1912
+				$line_item = $ticket_line_item;
1913
+				break;
1914
+			}
1915
+		}
1916
+		if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1917
+			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1918
+		}
1919
+		return $line_item;
1920
+	}
1921
+
1922
+
1923
+	/**
1924
+	 * Soft Deletes this model object.
1925
+	 *
1926
+	 * @return boolean | int
1927
+	 * @throws RuntimeException
1928
+	 * @throws EE_Error
1929
+	 */
1930
+	public function delete()
1931
+	{
1932
+		if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1933
+			$this->set_status(EEM_Registration::status_id_cancelled);
1934
+		}
1935
+		return parent::delete();
1936
+	}
1937
+
1938
+
1939
+	/**
1940
+	 * Restores whatever the previous status was on a registration before it was trashed (if possible)
1941
+	 *
1942
+	 * @throws EE_Error
1943
+	 * @throws RuntimeException
1944
+	 */
1945
+	public function restore()
1946
+	{
1947
+		$previous_status = $this->get_extra_meta(
1948
+			EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1949
+			true,
1950
+			EEM_Registration::status_id_cancelled
1951
+		);
1952
+		if ($previous_status) {
1953
+			$this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1954
+			$this->set_status($previous_status);
1955
+		}
1956
+		return parent::restore();
1957
+	}
1958
+
1959
+
1960
+	/**
1961
+	 * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price
1962
+	 *
1963
+	 * @param  boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic
1964
+	 *                                           depending on whether the reg status changes to or from "Approved"
1965
+	 * @return boolean whether the Registration status was updated
1966
+	 * @throws EE_Error
1967
+	 * @throws RuntimeException
1968
+	 */
1969
+	public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true)
1970
+	{
1971
+		$paid = $this->paid();
1972
+		$price = $this->final_price();
1973
+		switch (true) {
1974
+			// overpaid or paid
1975
+			case EEH_Money::compare_floats($paid, $price, '>'):
1976
+			case EEH_Money::compare_floats($paid, $price):
1977
+				$new_status = EEM_Registration::status_id_approved;
1978
+				break;
1979
+			//  underpaid
1980
+			case EEH_Money::compare_floats($paid, $price, '<'):
1981
+				$new_status = EEM_Registration::status_id_pending_payment;
1982
+				break;
1983
+			// uhhh Houston...
1984
+			default:
1985
+				throw new RuntimeException(
1986
+					esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso')
1987
+				);
1988
+		}
1989
+		if ($new_status !== $this->status_ID()) {
1990
+			if ($trigger_set_status_logic) {
1991
+				return $this->set_status($new_status);
1992
+			}
1993
+			parent::set('STS_ID', $new_status);
1994
+			return true;
1995
+		}
1996
+		return false;
1997
+	}
1998
+
1999
+
2000
+	/*************************** DEPRECATED ***************************/
2001
+
2002
+
2003
+	/**
2004
+	 * @deprecated
2005
+	 * @since     4.7.0
2006
+	 * @access    public
2007
+	 */
2008
+	public function price_paid()
2009
+	{
2010
+		EE_Error::doing_it_wrong(
2011
+			'EE_Registration::price_paid()',
2012
+			esc_html__(
2013
+				'This method is deprecated, please use EE_Registration::final_price() instead.',
2014
+				'event_espresso'
2015
+			),
2016
+			'4.7.0'
2017
+		);
2018
+		return $this->final_price();
2019
+	}
2020
+
2021
+
2022
+	/**
2023
+	 * @deprecated
2024
+	 * @since     4.7.0
2025
+	 * @access    public
2026
+	 * @param    float $REG_final_price
2027
+	 * @throws EE_Error
2028
+	 * @throws RuntimeException
2029
+	 */
2030
+	public function set_price_paid($REG_final_price = 0.00)
2031
+	{
2032
+		EE_Error::doing_it_wrong(
2033
+			'EE_Registration::set_price_paid()',
2034
+			esc_html__(
2035
+				'This method is deprecated, please use EE_Registration::set_final_price() instead.',
2036
+				'event_espresso'
2037
+			),
2038
+			'4.7.0'
2039
+		);
2040
+		$this->set_final_price($REG_final_price);
2041
+	}
2042
+
2043
+
2044
+	/**
2045
+	 * @deprecated
2046
+	 * @since 4.7.0
2047
+	 * @return string
2048
+	 * @throws EE_Error
2049
+	 */
2050
+	public function pretty_price_paid()
2051
+	{
2052
+		EE_Error::doing_it_wrong(
2053
+			'EE_Registration::pretty_price_paid()',
2054
+			esc_html__(
2055
+				'This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
2056
+				'event_espresso'
2057
+			),
2058
+			'4.7.0'
2059
+		);
2060
+		return $this->pretty_final_price();
2061
+	}
2062
+
2063
+
2064
+	/**
2065
+	 * Gets the primary datetime related to this registration via the related Event to this registration
2066
+	 *
2067
+	 * @deprecated 4.9.17
2068
+	 * @return EE_Datetime
2069
+	 * @throws EE_Error
2070
+	 * @throws EntityNotFoundException
2071
+	 */
2072
+	public function get_related_primary_datetime()
2073
+	{
2074
+		EE_Error::doing_it_wrong(
2075
+			__METHOD__,
2076
+			esc_html__(
2077
+				'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
2078
+				'event_espresso'
2079
+			),
2080
+			'4.9.17',
2081
+			'5.0.0'
2082
+		);
2083
+		return $this->event()->primary_datetime();
2084
+	}
2085 2085
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Message_Template_Group.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@
 block discarded – undo
211 211
      * appropriately.
212 212
      *
213 213
      * @throws EE_Error
214
-     * @return EE_message_type|false if exception thrown.
214
+     * @return null|EE_message_type if exception thrown.
215 215
      */
216 216
     public function message_type_obj()
217 217
     {
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function set_message_type($message_type = false)
50 50
     {
51
-        if (! $message_type) {
51
+        if ( ! $message_type) {
52 52
             throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso'));
53 53
         }
54 54
         $this->set('MTP_message_type', $message_type);
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function set_messenger($messenger = false)
63 63
     {
64
-        if (! $messenger) {
64
+        if ( ! $messenger) {
65 65
             throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso'));
66 66
         }
67 67
         $this->set('MTP_messenger', $messenger);
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     public function set_group_template_id($GRP_ID = false)
76 76
     {
77
-        if (! $GRP_ID) {
77
+        if ( ! $GRP_ID) {
78 78
             throw new EE_Error(
79 79
                 esc_html__(
80 80
                     'Missing required value for the message template group id',
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         }
291 291
         // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field.
292 292
         foreach ($mtps as $mtp) {
293
-            $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp;
293
+            $mtps_arr[$mtp->get('MTP_context')][$mtp->get('MTP_template_field')] = $mtp;
294 294
         }
295 295
         return $mtps_arr;
296 296
     }
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
     public function deactivate_context($context)
431 431
     {
432 432
         $this->validate_context($context);
433
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false);
433
+        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, false);
434 434
     }
435 435
 
436 436
 
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
     public function activate_context($context)
446 446
     {
447 447
         $this->validate_context($context);
448
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true);
448
+        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true);
449 449
     }
450 450
 
451 451
 
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
     {
466 466
         $this->validate_context($context);
467 467
         return filter_var(
468
-            $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true),
468
+            $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX.$context, true, true),
469 469
             FILTER_VALIDATE_BOOLEAN
470 470
         );
471 471
     }
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
     public function validate_context($context)
482 482
     {
483 483
         $contexts = $this->contexts_config();
484
-        if (! isset($contexts[ $context ])) {
484
+        if ( ! isset($contexts[$context])) {
485 485
             throw new InvalidIdentifierException(
486 486
                 '',
487 487
                 '',
Please login to merge, or discard this patch.
Indentation   +483 added lines, -483 removed lines patch added patch discarded remove patch
@@ -13,487 +13,487 @@
 block discarded – undo
13 13
 class EE_Message_Template_Group extends EE_Soft_Delete_Base_Class
14 14
 {
15 15
 
16
-    /**
17
-     * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not.
18
-     */
19
-    const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_';
20
-
21
-    /**
22
-     * @param array  $props_n_values
23
-     * @param string $timezone
24
-     * @return EE_Message_Template_Group|mixed
25
-     * @throws EE_Error
26
-     */
27
-    public static function new_instance($props_n_values = array(), $timezone = '')
28
-    {
29
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
30
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone);
31
-    }
32
-
33
-
34
-    /**
35
-     * @param array  $props_n_values
36
-     * @param string $timezone
37
-     * @return EE_Message_Template_Group
38
-     */
39
-    public static function new_instance_from_db($props_n_values = array(), $timezone = '')
40
-    {
41
-        return new self($props_n_values, true, $timezone);
42
-    }
43
-
44
-
45
-    /**
46
-     * @param bool $message_type
47
-     * @throws EE_Error
48
-     */
49
-    public function set_message_type($message_type = false)
50
-    {
51
-        if (! $message_type) {
52
-            throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso'));
53
-        }
54
-        $this->set('MTP_message_type', $message_type);
55
-    }
56
-
57
-
58
-    /**
59
-     * @param bool $messenger
60
-     * @throws EE_Error
61
-     */
62
-    public function set_messenger($messenger = false)
63
-    {
64
-        if (! $messenger) {
65
-            throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso'));
66
-        }
67
-        $this->set('MTP_messenger', $messenger);
68
-    }
69
-
70
-
71
-    /**
72
-     * @param bool $GRP_ID
73
-     * @throws EE_Error
74
-     */
75
-    public function set_group_template_id($GRP_ID = false)
76
-    {
77
-        if (! $GRP_ID) {
78
-            throw new EE_Error(
79
-                esc_html__(
80
-                    'Missing required value for the message template group id',
81
-                    'event_espresso'
82
-                )
83
-            );
84
-        }
85
-        $this->set('GRP_ID', $GRP_ID);
86
-    }
87
-
88
-
89
-    /**
90
-     * get Group ID
91
-     *
92
-     * @access public
93
-     * @return int
94
-     * @throws EE_Error
95
-     */
96
-    public function GRP_ID()
97
-    {
98
-        return $this->get('GRP_ID');
99
-    }
100
-
101
-
102
-    /**
103
-     * get User ID
104
-     *
105
-     * @access public
106
-     * @return int
107
-     * @throws EE_Error
108
-     */
109
-    public function user()
110
-    {
111
-        $user_id = $this->get('MTP_user_id');
112
-        return empty($user_id) ? get_current_user_id() : $user_id;
113
-    }
114
-
115
-
116
-    /**
117
-     * Wrapper for the user function() (preserve backward compat)
118
-     *
119
-     * @since  4.5.0
120
-     * @return int
121
-     * @throws EE_Error
122
-     */
123
-    public function wp_user()
124
-    {
125
-        return $this->user();
126
-    }
127
-
128
-
129
-    /**
130
-     * This simply returns a count of all related events to this message template group
131
-     *
132
-     * @return int
133
-     */
134
-    public function count_events()
135
-    {
136
-        return $this->count_related('Event');
137
-    }
138
-
139
-
140
-    /**
141
-     * returns the name saved in the db for this template
142
-     *
143
-     * @return string
144
-     * @throws EE_Error
145
-     */
146
-    public function name()
147
-    {
148
-        return $this->get('MTP_name');
149
-    }
150
-
151
-
152
-    /**
153
-     * Returns the description saved in the db for this template group
154
-     *
155
-     * @return string
156
-     * @throws EE_Error
157
-     */
158
-    public function description()
159
-    {
160
-        return $this->get('MTP_description');
161
-    }
162
-
163
-
164
-    /**
165
-     * returns all related EE_Message_Template objects
166
-     *
167
-     * @param  array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
168
-     * @return EE_Message_Template[]
169
-     * @throws EE_Error
170
-     */
171
-    public function message_templates($query_params = array())
172
-    {
173
-        return $this->get_many_related('Message_Template', $query_params);
174
-    }
175
-
176
-
177
-    /**
178
-     * get Message Messenger
179
-     *
180
-     * @access public
181
-     * @return string
182
-     * @throws EE_Error
183
-     */
184
-    public function messenger()
185
-    {
186
-        return $this->get('MTP_messenger');
187
-    }
188
-
189
-
190
-    /**
191
-     * get Message Messenger OBJECT
192
-     * If an attempt to get the corresponding messenger object fails, then we set this message
193
-     * template group to inactive, and save to db.  Then return null so client code can handle
194
-     * appropriately.
195
-     *
196
-     * @return EE_messenger
197
-     * @throws EE_Error
198
-     */
199
-    public function messenger_obj()
200
-    {
201
-        $messenger = $this->messenger();
202
-        try {
203
-            $messenger = EEH_MSG_Template::messenger_obj($messenger);
204
-        } catch (EE_Error $e) {
205
-            // if an exception was thrown then let's deactivate this message template group because it means there is no
206
-            // class for this messenger in this group.
207
-            $this->set('MTP_is_active', false);
208
-            $this->save();
209
-            return null;
210
-        }
211
-        return $messenger;
212
-    }
213
-
214
-
215
-    /**
216
-     * get Message Type
217
-     *
218
-     * @access public
219
-     * @return string
220
-     * @throws EE_Error
221
-     */
222
-    public function message_type()
223
-    {
224
-        return $this->get('MTP_message_type');
225
-    }
226
-
227
-
228
-    /**
229
-     * get Message type OBJECT
230
-     * If an attempt to get the corresponding message type object fails, then we set this message
231
-     * template group to inactive, and save to db.  Then return null so client code can handle
232
-     * appropriately.
233
-     *
234
-     * @throws EE_Error
235
-     * @return EE_message_type|false if exception thrown.
236
-     */
237
-    public function message_type_obj()
238
-    {
239
-        $message_type = $this->message_type();
240
-        try {
241
-            $message_type = EEH_MSG_Template::message_type_obj($message_type);
242
-        } catch (EE_Error $e) {
243
-            // if an exception was thrown then let's deactivate this message template group because it means there is no
244
-            // class for the message type in this group.
245
-            $this->set('MTP_is_active', false);
246
-            $this->save();
247
-            return null;
248
-        }
249
-        return $message_type;
250
-    }
251
-
252
-
253
-    /**
254
-     * @return array
255
-     * @throws EE_Error
256
-     */
257
-    public function contexts_config()
258
-    {
259
-        return $this->message_type_obj()->get_contexts();
260
-    }
261
-
262
-
263
-    /**
264
-     * This returns the context_label for contexts as set in the message type object
265
-     * Note this is an array with singular and plural keys
266
-     *
267
-     * @access public
268
-     * @return array labels for "context"
269
-     * @throws EE_Error
270
-     */
271
-    public function context_label()
272
-    {
273
-        $obj = $this->message_type_obj();
274
-        return $obj->get_context_label();
275
-    }
276
-
277
-
278
-    /**
279
-     * This returns an array of EE_Message_Template objects indexed by context and field.
280
-     *
281
-     * @return array ()
282
-     * @throws EE_Error
283
-     */
284
-    public function context_templates()
285
-    {
286
-        $mtps_arr = array();
287
-        $mtps = $this->get_many_related('Message_Template');
288
-        if (empty($mtps)) {
289
-            return array();
290
-        }
291
-        // note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field.
292
-        foreach ($mtps as $mtp) {
293
-            $mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp;
294
-        }
295
-        return $mtps_arr;
296
-    }
297
-
298
-
299
-    /**
300
-     * this returns if the template group this template belongs to is global
301
-     *
302
-     * @return bool true if it is, false if it isn't
303
-     * @throws EE_Error
304
-     */
305
-    public function is_global()
306
-    {
307
-        return $this->get('MTP_is_global');
308
-    }
309
-
310
-
311
-    /**
312
-     * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
313
-     *
314
-     * @return bool true if it is, false if it isn't
315
-     * @throws EE_Error
316
-     */
317
-    public function is_active()
318
-    {
319
-        return $this->get('MTP_is_active');
320
-    }
321
-
322
-
323
-    /**
324
-     * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
325
-     * this template.
326
-     *
327
-     * @since 4.3.0
328
-     * @uses  EEH_MSG_Template::get_shortcodes()
329
-     * @param string $context what context we're going to return shortcodes for
330
-     * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
331
-     *                        to be returned.
332
-     * @param bool   $merged  If TRUE then we don't return shortcodes indexed by field but instead an array of the
333
-     *                        unique shortcodes for all the given (or all) fields.
334
-     * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
335
-     *                        shortcodes found.
336
-     * @throws EE_Error
337
-     */
338
-    public function get_shortcodes($context, $fields = array(), $merged = false)
339
-    {
340
-        $messenger = $this->messenger();
341
-        $message_type = $this->message_type();
342
-        return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged);
343
-    }
344
-
345
-
346
-    /**
347
-     * This just gets the template pack name assigned to this message template group.  If it's not set, then we just
348
-     * use the default template pack.
349
-     *
350
-     * @since 4.5.0
351
-     * @return string
352
-     * @throws EE_Error
353
-     */
354
-    public function get_template_pack_name()
355
-    {
356
-        return $this->get_extra_meta('MTP_template_pack', true, 'default');
357
-    }
358
-
359
-
360
-    /**
361
-     * This returns the specific template pack object referenced by the template pack name attached to this message
362
-     * template group.  If no template pack is assigned then the default template pack is retrieved.
363
-     *
364
-     * @since 4.5.0
365
-     * @return EE_Messages_Template_Pack
366
-     * @throws EE_Error
367
-     * @throws InvalidArgumentException
368
-     * @throws ReflectionException
369
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
370
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
371
-     */
372
-    public function get_template_pack()
373
-    {
374
-        $pack_name = $this->get_template_pack_name();
375
-        EE_Registry::instance()->load_helper('MSG_Template');
376
-        return EEH_MSG_Template::get_template_pack($pack_name);
377
-    }
378
-
379
-
380
-    /**
381
-     * This retrieves the template variation assigned to this message template group.  If it's not set, then we just
382
-     * use the default template variation.
383
-     *
384
-     * @since 4.5.0
385
-     * @return string
386
-     * @throws EE_Error
387
-     */
388
-    public function get_template_pack_variation()
389
-    {
390
-        return $this->get_extra_meta('MTP_variation', true, 'default');
391
-    }
392
-
393
-
394
-    /**
395
-     * This just sets the template pack name attached to this message template group.
396
-     *
397
-     * @since 4.5.0
398
-     * @param string $template_pack_name What message template pack is assigned.
399
-     * @return int
400
-     * @throws EE_Error
401
-     */
402
-    public function set_template_pack_name($template_pack_name)
403
-    {
404
-        return $this->update_extra_meta('MTP_template_pack', $template_pack_name);
405
-    }
406
-
407
-
408
-    /**
409
-     * This just sets the template pack variation attached to this message template group.
410
-     *
411
-     * @since 4.5.0
412
-     * @param string $variation What variation is being set on the message template group.
413
-     * @return int
414
-     * @throws EE_Error
415
-     */
416
-    public function set_template_pack_variation($variation)
417
-    {
418
-        return $this->update_extra_meta('MTP_variation', $variation);
419
-    }
420
-
421
-
422
-    /**
423
-     * Deactivates the given context.
424
-     *
425
-     * @param $context
426
-     * @return bool|int
427
-     * @throws EE_Error
428
-     * @throws InvalidIdentifierException
429
-     */
430
-    public function deactivate_context($context)
431
-    {
432
-        $this->validate_context($context);
433
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false);
434
-    }
435
-
436
-
437
-    /**
438
-     * Activates the given context.
439
-     *
440
-     * @param $context
441
-     * @return bool|int
442
-     * @throws EE_Error
443
-     * @throws InvalidIdentifierException
444
-     */
445
-    public function activate_context($context)
446
-    {
447
-        $this->validate_context($context);
448
-        return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true);
449
-    }
450
-
451
-
452
-    /**
453
-     * Returns whether the context is active or not.
454
-     * Note, this will default to true if the extra meta record doesn't exist.
455
-     * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field
456
-     * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of
457
-     * whether a context is "active" or not.
458
-     *
459
-     * @param $context
460
-     * @return bool
461
-     * @throws EE_Error
462
-     * @throws InvalidIdentifierException
463
-     */
464
-    public function is_context_active($context)
465
-    {
466
-        $this->validate_context($context);
467
-        return filter_var(
468
-            $this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true),
469
-            FILTER_VALIDATE_BOOLEAN
470
-        );
471
-    }
472
-
473
-
474
-    /**
475
-     * Validates the incoming context to verify it matches a registered context for the related message type.
476
-     *
477
-     * @param string $context
478
-     * @throws EE_Error
479
-     * @throws InvalidIdentifierException
480
-     */
481
-    public function validate_context($context)
482
-    {
483
-        $contexts = $this->contexts_config();
484
-        if (! isset($contexts[ $context ])) {
485
-            throw new InvalidIdentifierException(
486
-                '',
487
-                '',
488
-                sprintf(
489
-                    esc_html__(
490
-                        'An invalid string identifying a context was provided.  "%1$s" was received, and one of "%2$s" was expected.',
491
-                        'event_espresso'
492
-                    ),
493
-                    $context,
494
-                    implode(',', array_keys($contexts))
495
-                )
496
-            );
497
-        }
498
-    }
16
+	/**
17
+	 * Extra Meta key prefix for whether a given context for this message tmeplate group is active or not.
18
+	 */
19
+	const ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX = 'active_context_';
20
+
21
+	/**
22
+	 * @param array  $props_n_values
23
+	 * @param string $timezone
24
+	 * @return EE_Message_Template_Group|mixed
25
+	 * @throws EE_Error
26
+	 */
27
+	public static function new_instance($props_n_values = array(), $timezone = '')
28
+	{
29
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone);
30
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone);
31
+	}
32
+
33
+
34
+	/**
35
+	 * @param array  $props_n_values
36
+	 * @param string $timezone
37
+	 * @return EE_Message_Template_Group
38
+	 */
39
+	public static function new_instance_from_db($props_n_values = array(), $timezone = '')
40
+	{
41
+		return new self($props_n_values, true, $timezone);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @param bool $message_type
47
+	 * @throws EE_Error
48
+	 */
49
+	public function set_message_type($message_type = false)
50
+	{
51
+		if (! $message_type) {
52
+			throw new EE_Error(esc_html__('Missing required value for the message_type parameter', 'event_espresso'));
53
+		}
54
+		$this->set('MTP_message_type', $message_type);
55
+	}
56
+
57
+
58
+	/**
59
+	 * @param bool $messenger
60
+	 * @throws EE_Error
61
+	 */
62
+	public function set_messenger($messenger = false)
63
+	{
64
+		if (! $messenger) {
65
+			throw new EE_Error(esc_html__('Missing required value for the messenger parameter', 'event_espresso'));
66
+		}
67
+		$this->set('MTP_messenger', $messenger);
68
+	}
69
+
70
+
71
+	/**
72
+	 * @param bool $GRP_ID
73
+	 * @throws EE_Error
74
+	 */
75
+	public function set_group_template_id($GRP_ID = false)
76
+	{
77
+		if (! $GRP_ID) {
78
+			throw new EE_Error(
79
+				esc_html__(
80
+					'Missing required value for the message template group id',
81
+					'event_espresso'
82
+				)
83
+			);
84
+		}
85
+		$this->set('GRP_ID', $GRP_ID);
86
+	}
87
+
88
+
89
+	/**
90
+	 * get Group ID
91
+	 *
92
+	 * @access public
93
+	 * @return int
94
+	 * @throws EE_Error
95
+	 */
96
+	public function GRP_ID()
97
+	{
98
+		return $this->get('GRP_ID');
99
+	}
100
+
101
+
102
+	/**
103
+	 * get User ID
104
+	 *
105
+	 * @access public
106
+	 * @return int
107
+	 * @throws EE_Error
108
+	 */
109
+	public function user()
110
+	{
111
+		$user_id = $this->get('MTP_user_id');
112
+		return empty($user_id) ? get_current_user_id() : $user_id;
113
+	}
114
+
115
+
116
+	/**
117
+	 * Wrapper for the user function() (preserve backward compat)
118
+	 *
119
+	 * @since  4.5.0
120
+	 * @return int
121
+	 * @throws EE_Error
122
+	 */
123
+	public function wp_user()
124
+	{
125
+		return $this->user();
126
+	}
127
+
128
+
129
+	/**
130
+	 * This simply returns a count of all related events to this message template group
131
+	 *
132
+	 * @return int
133
+	 */
134
+	public function count_events()
135
+	{
136
+		return $this->count_related('Event');
137
+	}
138
+
139
+
140
+	/**
141
+	 * returns the name saved in the db for this template
142
+	 *
143
+	 * @return string
144
+	 * @throws EE_Error
145
+	 */
146
+	public function name()
147
+	{
148
+		return $this->get('MTP_name');
149
+	}
150
+
151
+
152
+	/**
153
+	 * Returns the description saved in the db for this template group
154
+	 *
155
+	 * @return string
156
+	 * @throws EE_Error
157
+	 */
158
+	public function description()
159
+	{
160
+		return $this->get('MTP_description');
161
+	}
162
+
163
+
164
+	/**
165
+	 * returns all related EE_Message_Template objects
166
+	 *
167
+	 * @param  array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
168
+	 * @return EE_Message_Template[]
169
+	 * @throws EE_Error
170
+	 */
171
+	public function message_templates($query_params = array())
172
+	{
173
+		return $this->get_many_related('Message_Template', $query_params);
174
+	}
175
+
176
+
177
+	/**
178
+	 * get Message Messenger
179
+	 *
180
+	 * @access public
181
+	 * @return string
182
+	 * @throws EE_Error
183
+	 */
184
+	public function messenger()
185
+	{
186
+		return $this->get('MTP_messenger');
187
+	}
188
+
189
+
190
+	/**
191
+	 * get Message Messenger OBJECT
192
+	 * If an attempt to get the corresponding messenger object fails, then we set this message
193
+	 * template group to inactive, and save to db.  Then return null so client code can handle
194
+	 * appropriately.
195
+	 *
196
+	 * @return EE_messenger
197
+	 * @throws EE_Error
198
+	 */
199
+	public function messenger_obj()
200
+	{
201
+		$messenger = $this->messenger();
202
+		try {
203
+			$messenger = EEH_MSG_Template::messenger_obj($messenger);
204
+		} catch (EE_Error $e) {
205
+			// if an exception was thrown then let's deactivate this message template group because it means there is no
206
+			// class for this messenger in this group.
207
+			$this->set('MTP_is_active', false);
208
+			$this->save();
209
+			return null;
210
+		}
211
+		return $messenger;
212
+	}
213
+
214
+
215
+	/**
216
+	 * get Message Type
217
+	 *
218
+	 * @access public
219
+	 * @return string
220
+	 * @throws EE_Error
221
+	 */
222
+	public function message_type()
223
+	{
224
+		return $this->get('MTP_message_type');
225
+	}
226
+
227
+
228
+	/**
229
+	 * get Message type OBJECT
230
+	 * If an attempt to get the corresponding message type object fails, then we set this message
231
+	 * template group to inactive, and save to db.  Then return null so client code can handle
232
+	 * appropriately.
233
+	 *
234
+	 * @throws EE_Error
235
+	 * @return EE_message_type|false if exception thrown.
236
+	 */
237
+	public function message_type_obj()
238
+	{
239
+		$message_type = $this->message_type();
240
+		try {
241
+			$message_type = EEH_MSG_Template::message_type_obj($message_type);
242
+		} catch (EE_Error $e) {
243
+			// if an exception was thrown then let's deactivate this message template group because it means there is no
244
+			// class for the message type in this group.
245
+			$this->set('MTP_is_active', false);
246
+			$this->save();
247
+			return null;
248
+		}
249
+		return $message_type;
250
+	}
251
+
252
+
253
+	/**
254
+	 * @return array
255
+	 * @throws EE_Error
256
+	 */
257
+	public function contexts_config()
258
+	{
259
+		return $this->message_type_obj()->get_contexts();
260
+	}
261
+
262
+
263
+	/**
264
+	 * This returns the context_label for contexts as set in the message type object
265
+	 * Note this is an array with singular and plural keys
266
+	 *
267
+	 * @access public
268
+	 * @return array labels for "context"
269
+	 * @throws EE_Error
270
+	 */
271
+	public function context_label()
272
+	{
273
+		$obj = $this->message_type_obj();
274
+		return $obj->get_context_label();
275
+	}
276
+
277
+
278
+	/**
279
+	 * This returns an array of EE_Message_Template objects indexed by context and field.
280
+	 *
281
+	 * @return array ()
282
+	 * @throws EE_Error
283
+	 */
284
+	public function context_templates()
285
+	{
286
+		$mtps_arr = array();
287
+		$mtps = $this->get_many_related('Message_Template');
288
+		if (empty($mtps)) {
289
+			return array();
290
+		}
291
+		// note contexts could have CHECKBOX fields per context. So we return the objects indexed by context AND field.
292
+		foreach ($mtps as $mtp) {
293
+			$mtps_arr[ $mtp->get('MTP_context') ][ $mtp->get('MTP_template_field') ] = $mtp;
294
+		}
295
+		return $mtps_arr;
296
+	}
297
+
298
+
299
+	/**
300
+	 * this returns if the template group this template belongs to is global
301
+	 *
302
+	 * @return bool true if it is, false if it isn't
303
+	 * @throws EE_Error
304
+	 */
305
+	public function is_global()
306
+	{
307
+		return $this->get('MTP_is_global');
308
+	}
309
+
310
+
311
+	/**
312
+	 * this returns if the template group this template belongs to is active (i.e. turned "on" or not)
313
+	 *
314
+	 * @return bool true if it is, false if it isn't
315
+	 * @throws EE_Error
316
+	 */
317
+	public function is_active()
318
+	{
319
+		return $this->get('MTP_is_active');
320
+	}
321
+
322
+
323
+	/**
324
+	 * This will return an array of shortcodes => labels from the messenger and message_type objects associated with
325
+	 * this template.
326
+	 *
327
+	 * @since 4.3.0
328
+	 * @uses  EEH_MSG_Template::get_shortcodes()
329
+	 * @param string $context what context we're going to return shortcodes for
330
+	 * @param array  $fields  what fields we're returning valid shortcodes for.  If empty then we assume all fields are
331
+	 *                        to be returned.
332
+	 * @param bool   $merged  If TRUE then we don't return shortcodes indexed by field but instead an array of the
333
+	 *                        unique shortcodes for all the given (or all) fields.
334
+	 * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no
335
+	 *                        shortcodes found.
336
+	 * @throws EE_Error
337
+	 */
338
+	public function get_shortcodes($context, $fields = array(), $merged = false)
339
+	{
340
+		$messenger = $this->messenger();
341
+		$message_type = $this->message_type();
342
+		return EEH_MSG_Template::get_shortcodes($message_type, $messenger, $fields, $context, $merged);
343
+	}
344
+
345
+
346
+	/**
347
+	 * This just gets the template pack name assigned to this message template group.  If it's not set, then we just
348
+	 * use the default template pack.
349
+	 *
350
+	 * @since 4.5.0
351
+	 * @return string
352
+	 * @throws EE_Error
353
+	 */
354
+	public function get_template_pack_name()
355
+	{
356
+		return $this->get_extra_meta('MTP_template_pack', true, 'default');
357
+	}
358
+
359
+
360
+	/**
361
+	 * This returns the specific template pack object referenced by the template pack name attached to this message
362
+	 * template group.  If no template pack is assigned then the default template pack is retrieved.
363
+	 *
364
+	 * @since 4.5.0
365
+	 * @return EE_Messages_Template_Pack
366
+	 * @throws EE_Error
367
+	 * @throws InvalidArgumentException
368
+	 * @throws ReflectionException
369
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
370
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
371
+	 */
372
+	public function get_template_pack()
373
+	{
374
+		$pack_name = $this->get_template_pack_name();
375
+		EE_Registry::instance()->load_helper('MSG_Template');
376
+		return EEH_MSG_Template::get_template_pack($pack_name);
377
+	}
378
+
379
+
380
+	/**
381
+	 * This retrieves the template variation assigned to this message template group.  If it's not set, then we just
382
+	 * use the default template variation.
383
+	 *
384
+	 * @since 4.5.0
385
+	 * @return string
386
+	 * @throws EE_Error
387
+	 */
388
+	public function get_template_pack_variation()
389
+	{
390
+		return $this->get_extra_meta('MTP_variation', true, 'default');
391
+	}
392
+
393
+
394
+	/**
395
+	 * This just sets the template pack name attached to this message template group.
396
+	 *
397
+	 * @since 4.5.0
398
+	 * @param string $template_pack_name What message template pack is assigned.
399
+	 * @return int
400
+	 * @throws EE_Error
401
+	 */
402
+	public function set_template_pack_name($template_pack_name)
403
+	{
404
+		return $this->update_extra_meta('MTP_template_pack', $template_pack_name);
405
+	}
406
+
407
+
408
+	/**
409
+	 * This just sets the template pack variation attached to this message template group.
410
+	 *
411
+	 * @since 4.5.0
412
+	 * @param string $variation What variation is being set on the message template group.
413
+	 * @return int
414
+	 * @throws EE_Error
415
+	 */
416
+	public function set_template_pack_variation($variation)
417
+	{
418
+		return $this->update_extra_meta('MTP_variation', $variation);
419
+	}
420
+
421
+
422
+	/**
423
+	 * Deactivates the given context.
424
+	 *
425
+	 * @param $context
426
+	 * @return bool|int
427
+	 * @throws EE_Error
428
+	 * @throws InvalidIdentifierException
429
+	 */
430
+	public function deactivate_context($context)
431
+	{
432
+		$this->validate_context($context);
433
+		return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, false);
434
+	}
435
+
436
+
437
+	/**
438
+	 * Activates the given context.
439
+	 *
440
+	 * @param $context
441
+	 * @return bool|int
442
+	 * @throws EE_Error
443
+	 * @throws InvalidIdentifierException
444
+	 */
445
+	public function activate_context($context)
446
+	{
447
+		$this->validate_context($context);
448
+		return $this->update_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true);
449
+	}
450
+
451
+
452
+	/**
453
+	 * Returns whether the context is active or not.
454
+	 * Note, this will default to true if the extra meta record doesn't exist.
455
+	 * Also, this does NOT account for whether the "To" field is empty or not. Some messengers may allow the "To" field
456
+	 * to be empty (@see EE_Messenger::allow_empty_to_field()) so an empty "To" field is not always an indicator of
457
+	 * whether a context is "active" or not.
458
+	 *
459
+	 * @param $context
460
+	 * @return bool
461
+	 * @throws EE_Error
462
+	 * @throws InvalidIdentifierException
463
+	 */
464
+	public function is_context_active($context)
465
+	{
466
+		$this->validate_context($context);
467
+		return filter_var(
468
+			$this->get_extra_meta(self::ACTIVE_CONTEXT_RECORD_META_KEY_PREFIX . $context, true, true),
469
+			FILTER_VALIDATE_BOOLEAN
470
+		);
471
+	}
472
+
473
+
474
+	/**
475
+	 * Validates the incoming context to verify it matches a registered context for the related message type.
476
+	 *
477
+	 * @param string $context
478
+	 * @throws EE_Error
479
+	 * @throws InvalidIdentifierException
480
+	 */
481
+	public function validate_context($context)
482
+	{
483
+		$contexts = $this->contexts_config();
484
+		if (! isset($contexts[ $context ])) {
485
+			throw new InvalidIdentifierException(
486
+				'',
487
+				'',
488
+				sprintf(
489
+					esc_html__(
490
+						'An invalid string identifying a context was provided.  "%1$s" was received, and one of "%2$s" was expected.',
491
+						'event_espresso'
492
+					),
493
+					$context,
494
+					implode(',', array_keys($contexts))
495
+				)
496
+			);
497
+		}
498
+	}
499 499
 }
Please login to merge, or discard this patch.
messages/templates/ee_msg_editor_active_context_element.template.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@  discard block
 block discarded – undo
10 10
  * @var int    $message_template_group_id The ID for the message template group this context belongs to.
11 11
  */
12 12
 $active_message = sprintf(
13
-    esc_html__(
14
-        'The template for %1$s is currently %2$sactive%3$s.',
15
-        'event_espresso'
16
-    ),
17
-    $context_label,
18
-    '<strong>',
19
-    '</strong>'
13
+	esc_html__(
14
+		'The template for %1$s is currently %2$sactive%3$s.',
15
+		'event_espresso'
16
+	),
17
+	$context_label,
18
+	'<strong>',
19
+	'</strong>'
20 20
 );
21 21
 $inactive_message = sprintf(
22
-    esc_html__(
23
-        'The template for %1$s is currently %2$sinactive%3$s.',
24
-        'event_espresso'
25
-    ),
26
-    $context_label,
27
-    '<strong>',
28
-    '</strong>'
22
+	esc_html__(
23
+		'The template for %1$s is currently %2$sinactive%3$s.',
24
+		'event_espresso'
25
+	),
26
+	$context_label,
27
+	'<strong>',
28
+	'</strong>'
29 29
 );
30 30
 ?>
31 31
 <div class="context-active-control-container">
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
         <span id="on-off-nonce-<?php echo $context; ?>" class="hidden"><?php echo $nonce; ?></span>
35 35
         <span class="ee-on-off-toggle-label">
36 36
             <?php
37
-            echo $is_active ? $active_message : $inactive_message;
38
-            ?>
37
+			echo $is_active ? $active_message : $inactive_message;
38
+			?>
39 39
         </span>
40 40
         <div class="hidden js-data">
41 41
             <span class="ee-active-message"><?php echo $active_message; ?></span>
@@ -43,8 +43,8 @@  discard block
 block discarded – undo
43 43
         </div>
44 44
         <div class="switch">
45 45
             <?php
46
-            $checked = $is_active ? ' checked="checked"' : '';
47
-            ?>
46
+			$checked = $is_active ? ' checked="checked"' : '';
47
+			?>
48 48
             <input data-grpid="<?php echo $message_template_group_id; ?>" id="ee-on-off-toggle-<?php echo $context; ?>" type="checkbox" class="ee-on-off-toggle ee-toggle-round-flat"<?php echo $checked; ?> value="<?php echo $on_off_action; ?>">
49 49
             <label for="ee-on-off-toggle-<?php echo $context; ?>"></label>
50 50
         </div>
Please login to merge, or discard this patch.
acceptance_tests/tests/e-TestContextActivationToggleCept.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@  discard block
 block discarded – undo
8 8
 $event_label = 'Testing Context Deactivation';
9 9
 
10 10
 $I->wantTo(
11
-    'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
-    . ' expected'
11
+	'Test that the context activation toggle for turning on or off specific contexts for message sending works as'
12
+	. ' expected'
13 13
 );
14 14
 
15 15
 $I->loginAsAdmin();
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 $I->see('The template for Primary Registrant Recipient is currently inactive.');
35 35
 
36 36
 $I->amGoingTo(
37
-    'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
37
+	'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.'
38 38
 );
39 39
 $I->amOnDefaultEventsListTablePage();
40 40
 $I->click(EventsAdmin::ADD_NEW_EVENT_BUTTON_SELECTOR);
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 $event_link = $I->observeLinkUrlAt(EventsAdmin::EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR);
45 45
 $event_id = $I->observeValueFromInputAt(EventsAdmin::EVENT_EDITOR_EVT_ID_SELECTOR);
46 46
 $test_registration_details = array(
47
-    'fname' => 'ContextTestGuy',
48
-    'lname' => 'ContextTestDude',
49
-    'email' => '[email protected]',
47
+	'fname' => 'ContextTestGuy',
48
+	'lname' => 'ContextTestDude',
49
+	'email' => '[email protected]',
50 50
 );
51 51
 $I->logOut();
52 52
 $I->amOnUrl($event_link);
@@ -63,48 +63,48 @@  discard block
 block discarded – undo
63 63
 $I->amOnMessagesActivityListTablePage();
64 64
 //verify registrant context
65 65
 $I->see(
66
-    $test_registration_details['email'],
67
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
-        'to',
69
-        'Registration Approved',
70
-        MessagesAdmin::MESSAGE_STATUS_SENT,
71
-        '',
72
-        'Registrant'
73
-    )
66
+	$test_registration_details['email'],
67
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
68
+		'to',
69
+		'Registration Approved',
70
+		MessagesAdmin::MESSAGE_STATUS_SENT,
71
+		'',
72
+		'Registrant'
73
+	)
74 74
 );
75 75
 $I->deleteMessageInMessagesListTableFor(
76
-    'Registration Approved',
77
-    MessagesAdmin::MESSAGE_STATUS_SENT,
78
-    'Email',
79
-    'Registrant'
76
+	'Registration Approved',
77
+	MessagesAdmin::MESSAGE_STATUS_SENT,
78
+	'Email',
79
+	'Registrant'
80 80
 );
81 81
 //verify admin context
82 82
 $I->see(
83
-    '[email protected]',
84
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
-        'to',
86
-        'Registration Approved',
87
-        MessagesAdmin::MESSAGE_STATUS_SENT
88
-    )
83
+	'[email protected]',
84
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
85
+		'to',
86
+		'Registration Approved',
87
+		MessagesAdmin::MESSAGE_STATUS_SENT
88
+	)
89 89
 );
90 90
 $I->deleteMessageInMessagesListTableFor(
91
-    'Registration Approved'
91
+	'Registration Approved'
92 92
 );
93 93
 //verify primary registrant context is NOT present.
94 94
 $I->dontSee(
95
-    $test_registration_details['email'],
96
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
-        'to',
98
-        'Registration Approved',
99
-        MessagesAdmin::MESSAGE_STATUS_SENT,
100
-        '',
101
-        'Primary Registrant'
102
-    )
95
+	$test_registration_details['email'],
96
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
97
+		'to',
98
+		'Registration Approved',
99
+		MessagesAdmin::MESSAGE_STATUS_SENT,
100
+		'',
101
+		'Primary Registrant'
102
+	)
103 103
 );
104 104
 
105 105
 $I->amGoingTo(
106
-    'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
-    . ' field to an empty string to verify the message does not send for that context.'
106
+	'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"'
107
+	. ' field to an empty string to verify the message does not send for that context.'
108 108
 );
109 109
 $I->amOnDefaultMessageTemplateListTablePage();
110 110
 $I->clickToEditMessageTemplateByMessageType('registration', 'primary_attendee');
@@ -128,41 +128,41 @@  discard block
 block discarded – undo
128 128
 $I->amOnMessagesActivityListTablePage();
129 129
 //verify registrant context
130 130
 $I->see(
131
-    $test_registration_details['email'],
132
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
-        'to',
134
-        'Registration Approved',
135
-        MessagesAdmin::MESSAGE_STATUS_SENT,
136
-        '',
137
-        'Registrant'
138
-    )
131
+	$test_registration_details['email'],
132
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
133
+		'to',
134
+		'Registration Approved',
135
+		MessagesAdmin::MESSAGE_STATUS_SENT,
136
+		'',
137
+		'Registrant'
138
+	)
139 139
 );
140 140
 $I->deleteMessageInMessagesListTableFor(
141
-    'Registration Approved',
142
-    MessagesAdmin::MESSAGE_STATUS_SENT,
143
-    'Email',
144
-    'Registrant'
141
+	'Registration Approved',
142
+	MessagesAdmin::MESSAGE_STATUS_SENT,
143
+	'Email',
144
+	'Registrant'
145 145
 );
146 146
 //verify admin context
147 147
 $I->see(
148
-    '[email protected]',
149
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
-        'to',
151
-        'Registration Approved',
152
-        MessagesAdmin::MESSAGE_STATUS_SENT
153
-    )
148
+	'[email protected]',
149
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
150
+		'to',
151
+		'Registration Approved',
152
+		MessagesAdmin::MESSAGE_STATUS_SENT
153
+	)
154 154
 );
155 155
 $I->deleteMessageInMessagesListTableFor(
156
-    'Registration Approved'
156
+	'Registration Approved'
157 157
 );
158 158
 //verify primary registrant context is NOT present.
159 159
 $I->dontSee(
160
-    $test_registration_details['email'],
161
-    MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
-        'to',
163
-        'Registration Approved',
164
-        MessagesAdmin::MESSAGE_STATUS_SENT,
165
-        '',
166
-        'Primary Registrant'
167
-    )
160
+	$test_registration_details['email'],
161
+	MessagesAdmin::messagesActivityListTableCellSelectorFor(
162
+		'to',
163
+		'Registration Approved',
164
+		MessagesAdmin::MESSAGE_STATUS_SENT,
165
+		'',
166
+		'Primary Registrant'
167
+	)
168 168
 );
169 169
\ No newline at end of file
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/functions.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@  discard block
 block discarded – undo
9 9
  * @ link			http://www.eventespresso.com
10 10
  * @ version		4+
11 11
  */
12
-define( 'EE_THEME_FUNCTIONS_LOADED', TRUE );
12
+define('EE_THEME_FUNCTIONS_LOADED', TRUE);
13 13
 
14
-if ( ! function_exists( 'espresso_pagination' ) ) {
14
+if ( ! function_exists('espresso_pagination')) {
15 15
 	/**
16 16
 	 *    espresso_pagination
17 17
 	 *
@@ -23,21 +23,21 @@  discard block
 block discarded – undo
23 23
 		$big = 999999999; // need an unlikely integer
24 24
 		$pagination = paginate_links(
25 25
 			array(
26
-				'base'         => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
26
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
27 27
 				'format'       => '?paged=%#%',
28
-				'current'      => max( 1, get_query_var( 'paged' ) ),
28
+				'current'      => max(1, get_query_var('paged')),
29 29
 				'total'        => $wp_query->max_num_pages,
30 30
 				'show_all'     => true,
31 31
 				'end_size'     => 10,
32 32
 				'mid_size'     => 6,
33 33
 				'prev_next'    => true,
34
-				'prev_text'    => __( '&lsaquo; PREV', 'event_espresso' ),
35
-				'next_text'    => __( 'NEXT &rsaquo;', 'event_espresso' ),
34
+				'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
35
+				'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
36 36
 				'type'         => 'plain',
37 37
 				'add_args'     => false,
38 38
 				'add_fragment' => ''
39 39
 			)
40 40
 		);
41
-		echo ! empty( $pagination ) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : '';
41
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : '';
42 42
 	}
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/messages/help_tabs/messages_settings_messengers.help_tab.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,79 +3,79 @@
 block discarded – undo
3 3
 </p>
4 4
 <p>
5 5
     <?php esc_html_e(
6
-        'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
-        'event_espresso'
8
-    ); ?>
6
+		'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab.  When you click one of those tabs it will display that messenger.',
7
+		'event_espresso'
8
+	); ?>
9 9
 </p>
10 10
 <p>
11 11
     <?php esc_html_e(
12
-        'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
-        'event_espresso'
14
-    ); ?>
12
+		'There are two ways to determine whether a messenger is active or not.  The first way is via the messenger tab itself.',
13
+		'event_espresso'
14
+	); ?>
15 15
 </p>
16 16
 <p>
17 17
     <?php printf(
18
-        esc_html__(
19
-            'The green colored gear %s indicates that this messenger is currently active.',
20
-            'event_espresso'
21
-        ),
22
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
-        . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
-    );
25
-    printf(
26
-        esc_html__(
27
-            ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
-            'event_espresso'
29
-        ),
30
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
-        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
-    ); ?>
18
+		esc_html__(
19
+			'The green colored gear %s indicates that this messenger is currently active.',
20
+			'event_espresso'
21
+		),
22
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
+		. ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
24
+	);
25
+	printf(
26
+		esc_html__(
27
+			' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28
+			'event_espresso'
29
+		),
30
+		'<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
+		. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
32
+	); ?>
33 33
 </p>
34 34
 <p>
35 35
     <?php esc_html_e(
36
-        'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
-        'event_espresso'
38
-    ); ?>
36
+		'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:',
37
+		'event_espresso'
38
+	); ?>
39 39
 </p>
40 40
 <p>
41 41
     <?php printf(
42
-        esc_html__(
43
-            '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
-            'event_espresso'
45
-        ),
46
-        '<div class="switch">'
47
-            . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>'
48
-            . '<label for="ee-on-off-toggle-on"></label>'
49
-        . '</div>',
50
-        '<div class="switch">'
51
-            . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
-            . '<label for="ee-on-off-toggle-on"></label>'
53
-        . '</div>'
54
-    ); ?>
42
+		esc_html__(
43
+			'%1$s means of course that the messenger is active and %2$s means the messenger is inactive.',
44
+			'event_espresso'
45
+		),
46
+		'<div class="switch">'
47
+			. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>'
48
+			. '<label for="ee-on-off-toggle-on"></label>'
49
+		. '</div>',
50
+		'<div class="switch">'
51
+			. '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>'
52
+			. '<label for="ee-on-off-toggle-on"></label>'
53
+		. '</div>'
54
+	); ?>
55 55
 </p>
56 56
 <p>
57 57
     <?php
58
-        esc_html_e(
59
-            'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
-            'event_espresso'
61
-        ); ?>
58
+		esc_html_e(
59
+			'The on/off toggle is also what you use to activate or deactivate a messenger.',
60
+			'event_espresso'
61
+		); ?>
62 62
 </p>
63 63
 <p>
64 64
     <?php esc_html_e(
65
-        'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
-        'event_espresso'
67
-    ); ?>
65
+		'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger.  Then, if there are any default settings for either the messenger or message types those settings are saved.  Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated).  Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.',
66
+		'event_espresso'
67
+	); ?>
68 68
 </p>
69 69
 <p>
70 70
     <?php esc_html_e(
71
-        'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
-        'event_espresso'
73
-    ); ?>
71
+		'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate.  If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.',
72
+		'event_espresso'
73
+	); ?>
74 74
 </p>
75 75
 <p>
76 76
     <strong><?php esc_html_e('Important', 'event_espresso'); ?></strong><br/>
77 77
     <?php esc_html_e(
78
-        'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
-        'event_espresso'
80
-    ); ?>
78
+		'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation.  Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.',
79
+		'event_espresso'
80
+	); ?>
81 81
 </p>
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -19,16 +19,16 @@
 block discarded – undo
19 19
             'The green colored gear %s indicates that this messenger is currently active.',
20 20
             'event_espresso'
21 21
         ),
22
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"'
23
-        . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />'
22
+        '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'"'
23
+        . ' alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />'
24 24
     );
25 25
     printf(
26 26
         esc_html__(
27 27
             ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.',
28 28
             'event_espresso'
29 29
         ),
30
-        '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
31
-        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />'
30
+        '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png'
31
+        . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />'
32 32
     ); ?>
33 33
 </p>
34 34
 <p>
Please login to merge, or discard this patch.