Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
created
core/libraries/messages/data_class/EE_Messages_incoming_data.core.php 2 patches
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
         $answers            = $questions = $attendees = $line_items = $registrations = array();
333 333
         $total_ticket_count = 0;
334 334
 
335
-        if (! empty($this->reg_objs)) {
335
+        if ( ! empty($this->reg_objs)) {
336 336
             $event_attendee_count = array();
337 337
             /** @var EE_Registration $reg */
338 338
             foreach ($this->reg_objs as $reg) {
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 
345 345
                 $evt_id = $reg->event_ID();
346 346
                 /** @type EE_Ticket $ticket */
347
-                $ticket          = $reg->get_first_related('Ticket');
347
+                $ticket = $reg->get_first_related('Ticket');
348 348
                 $attendee = $reg->attendee();
349 349
                 $event = $reg->event();
350 350
                 // if none of the following entities are available, then we can't setup other data reliably,
@@ -358,67 +358,67 @@  discard block
 block discarded – undo
358 358
                 }
359 359
                 $relateddatetime = $ticket->datetimes();
360 360
                 $total_ticket_count++;
361
-                $tickets[ $ticket->ID() ]['ticket']                        = $ticket;
362
-                $tickets[ $ticket->ID() ]['count']                         = is_array($tickets[ $ticket->ID() ])
363
-                                                                           && isset($tickets[ $ticket->ID() ]['count'])
364
-                    ? $tickets[ $ticket->ID() ]['count'] + 1
361
+                $tickets[$ticket->ID()]['ticket']                        = $ticket;
362
+                $tickets[$ticket->ID()]['count']                         = is_array($tickets[$ticket->ID()])
363
+                                                                           && isset($tickets[$ticket->ID()]['count'])
364
+                    ? $tickets[$ticket->ID()]['count'] + 1
365 365
                     : 1;
366
-                $tickets[ $ticket->ID() ]['att_objs'][ $attendee->ID() ] = $attendee;
367
-                $tickets[ $ticket->ID() ]['dtt_objs']                      = $relateddatetime;
368
-                $tickets[ $ticket->ID() ]['reg_objs'][ $reg->ID() ]          = $reg;
369
-                $tickets[ $ticket->ID() ]['EE_Event']                      = $event;
370
-                $evtcache[ $evt_id ]                                       = $event;
371
-                $eventsetup[ $evt_id ]['reg_objs'][ $reg->ID() ]             = $reg;
372
-                $eventsetup[ $evt_id ]['tkt_objs'][ $ticket->ID() ]          = $ticket;
373
-                $eventsetup[ $evt_id ]['att_objs'][ $attendee->ID() ]    = $attendee;
374
-                $event_attendee_count[ $evt_id ]                           = isset($event_attendee_count[ $evt_id ])
375
-                    ? $event_attendee_count[ $evt_id ] + 1
366
+                $tickets[$ticket->ID()]['att_objs'][$attendee->ID()] = $attendee;
367
+                $tickets[$ticket->ID()]['dtt_objs']                      = $relateddatetime;
368
+                $tickets[$ticket->ID()]['reg_objs'][$reg->ID()]          = $reg;
369
+                $tickets[$ticket->ID()]['EE_Event']                      = $event;
370
+                $evtcache[$evt_id]                                       = $event;
371
+                $eventsetup[$evt_id]['reg_objs'][$reg->ID()]             = $reg;
372
+                $eventsetup[$evt_id]['tkt_objs'][$ticket->ID()]          = $ticket;
373
+                $eventsetup[$evt_id]['att_objs'][$attendee->ID()] = $attendee;
374
+                $event_attendee_count[$evt_id]                           = isset($event_attendee_count[$evt_id])
375
+                    ? $event_attendee_count[$evt_id] + 1
376 376
                     : 0;
377
-                $attendees[ $reg->attendee_ID() ]['line_ref'][]            = $evt_id;
378
-                $attendees[ $reg->attendee_ID() ]['att_obj']               = $attendee;
379
-                $attendees[ $reg->attendee_ID() ]['reg_objs'][ $reg->ID() ]  = $reg;
377
+                $attendees[$reg->attendee_ID()]['line_ref'][]            = $evt_id;
378
+                $attendees[$reg->attendee_ID()]['att_obj']               = $attendee;
379
+                $attendees[$reg->attendee_ID()]['reg_objs'][$reg->ID()]  = $reg;
380 380
                 // $attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
381
-                $attendees[ $reg->attendee_ID() ]['attendee_email']          = $attendee->email();
382
-                $attendees[ $reg->attendee_ID() ]['tkt_objs'][ $ticket->ID() ] = $ticket;
383
-                $attendees[ $reg->attendee_ID() ]['evt_objs'][ $evt_id ]       = $event;
381
+                $attendees[$reg->attendee_ID()]['attendee_email']          = $attendee->email();
382
+                $attendees[$reg->attendee_ID()]['tkt_objs'][$ticket->ID()] = $ticket;
383
+                $attendees[$reg->attendee_ID()]['evt_objs'][$evt_id]       = $event;
384 384
 
385 385
                 // registrations
386
-                $registrations[ $reg->ID() ]['tkt_obj'] = $ticket;
387
-                $registrations[ $reg->ID() ]['evt_obj'] = $event;
388
-                $registrations[ $reg->ID() ]['reg_obj'] = $reg;
389
-                $registrations[ $reg->ID() ]['att_obj'] = $attendee;
386
+                $registrations[$reg->ID()]['tkt_obj'] = $ticket;
387
+                $registrations[$reg->ID()]['evt_obj'] = $event;
388
+                $registrations[$reg->ID()]['reg_obj'] = $reg;
389
+                $registrations[$reg->ID()]['att_obj'] = $attendee;
390 390
 
391 391
                 // set up answer objects
392 392
                 $rel_ans = $reg->get_many_related('Answer');
393 393
                 foreach ($rel_ans as $ansid => $answer) {
394
-                    if (! isset($questions[ $ansid ])) {
395
-                        $questions[ $ansid ] = $answer->get_first_related('Question');
394
+                    if ( ! isset($questions[$ansid])) {
395
+                        $questions[$ansid] = $answer->get_first_related('Question');
396 396
                     }
397
-                    $answers[ $ansid ]                               = $answer;
398
-                    $registrations[ $reg->ID() ]['ans_objs'][ $ansid ] = $answer;
397
+                    $answers[$ansid] = $answer;
398
+                    $registrations[$reg->ID()]['ans_objs'][$ansid] = $answer;
399 399
                 }
400 400
                 /**
401 401
                  * @var int $dtt_id
402 402
                  * @var EE_Datetime $datetime
403 403
                  */
404 404
                 foreach ($relateddatetime as $dtt_id => $datetime) {
405
-                    $eventsetup[ $evt_id ]['dtt_objs'][ $dtt_id ]       = $datetime;
406
-                    $registrations[ $reg->ID() ]['dtt_objs'][ $dtt_id ] = $datetime;
405
+                    $eventsetup[$evt_id]['dtt_objs'][$dtt_id]       = $datetime;
406
+                    $registrations[$reg->ID()]['dtt_objs'][$dtt_id] = $datetime;
407 407
 
408
-                    if (isset($datetimes[ $dtt_id ])) {
408
+                    if (isset($datetimes[$dtt_id])) {
409 409
                         continue; // already have this info in the datetimes array.
410 410
                     }
411 411
 
412
-                    $datetimes[ $dtt_id ]['tkt_objs'][]           = $ticket;
413
-                    $datetimes[ $dtt_id ]['datetime']             = $datetime;
414
-                    $datetimes[ $dtt_id ]['evt_objs'][ $evt_id ]    = $event;
415
-                    $datetimes[ $dtt_id ]['reg_objs'][ $reg->ID() ] = $reg;
412
+                    $datetimes[$dtt_id]['tkt_objs'][]           = $ticket;
413
+                    $datetimes[$dtt_id]['datetime']             = $datetime;
414
+                    $datetimes[$dtt_id]['evt_objs'][$evt_id]    = $event;
415
+                    $datetimes[$dtt_id]['reg_objs'][$reg->ID()] = $reg;
416 416
                 }
417 417
             }
418 418
 
419 419
             // let's loop through the unique event=>reg items and setup data on them
420 420
 
421
-            if (! empty($eventsetup)) {
421
+            if ( ! empty($eventsetup)) {
422 422
                 foreach ($eventsetup as $evt_id => $items) {
423 423
                     $ticket_line_items_for_event = array();
424 424
                     if ($this->txn instanceof EE_Transaction) {
@@ -432,11 +432,11 @@  discard block
 block discarded – undo
432 432
                             )
433 433
                         );
434 434
                     }
435
-                    $events[ $evt_id ] = array(
435
+                    $events[$evt_id] = array(
436 436
                         'ID'              => $evt_id,
437
-                        'event'           => $evtcache[ $evt_id ],
438
-                        'name'            => $evtcache[ $evt_id ] instanceof EE_Event ? $evtcache[ $evt_id ]->name() : '',
439
-                        'total_attendees' => $event_attendee_count[ $evt_id ],
437
+                        'event'           => $evtcache[$evt_id],
438
+                        'name'            => $evtcache[$evt_id] instanceof EE_Event ? $evtcache[$evt_id]->name() : '',
439
+                        'total_attendees' => $event_attendee_count[$evt_id],
440 440
                         'reg_objs'        => $items['reg_objs'],
441 441
                         'tkt_objs'        => $items['tkt_objs'],
442 442
                         'att_objs'        => $items['att_objs'],
@@ -447,11 +447,11 @@  discard block
 block discarded – undo
447 447
                     // make sure the tickets have the line items setup for them.
448 448
                     foreach ($ticket_line_items_for_event as $line_id => $line_item) {
449 449
                         // only add the ticket line items if we already have this ticket in the $tickets array.
450
-                        if ($line_item instanceof EE_Line_Item && isset($tickets[ $line_item->ticket()->ID() ])) {
451
-                            $tickets[ $line_item->ticket()->ID() ]['line_item']      = $line_item;
452
-                            $tickets[ $line_item->ticket()->ID() ]['sub_line_items'] = $line_item->children();
453
-                            $line_items[ $line_item->ID() ]['children']              = $line_item->children();
454
-                            $line_items[ $line_item->ID() ]['EE_Ticket']             = $line_item->ticket();
450
+                        if ($line_item instanceof EE_Line_Item && isset($tickets[$line_item->ticket()->ID()])) {
451
+                            $tickets[$line_item->ticket()->ID()]['line_item']      = $line_item;
452
+                            $tickets[$line_item->ticket()->ID()]['sub_line_items'] = $line_item->children();
453
+                            $line_items[$line_item->ID()]['children']              = $line_item->children();
454
+                            $line_items[$line_item->ID()]['EE_Ticket']             = $line_item->ticket();
455 455
                         }
456 456
                     }
457 457
                 }
Please login to merge, or discard this patch.
Indentation   +518 added lines, -518 removed lines patch added patch discarded remove patch
@@ -16,522 +16,522 @@
 block discarded – undo
16 16
  */
17 17
 abstract class EE_Messages_incoming_data
18 18
 {
19
-    /**
20
-     * user id for logged in user when data collected
21
-     *
22
-     * @var string $user_id
23
-     */
24
-    public $user_id;
25
-
26
-    /**
27
-     * IP Address of browser used
28
-     *
29
-     * @var string $ip_address
30
-     */
31
-    public $ip_address;
32
-
33
-    /**
34
-     * browser
35
-     *
36
-     * @var string $user_agent
37
-     */
38
-    public $user_agent;
39
-
40
-    /**
41
-     * Unix timestamp
42
-     *
43
-     * @var string $init_access
44
-     */
45
-    public $init_access;
46
-
47
-    /**
48
-     * Unix timestamp
49
-     *
50
-     * @var string $last_access
51
-     */
52
-    public $last_access;
53
-
54
-    /**
55
-     * The registrations details from the cart
56
-     *
57
-     * @var array $reg_info
58
-     */
59
-    public $reg_info;
60
-
61
-    /**
62
-     * Some data handlers can set what reg status all the registrations are filtered by.
63
-     * The status should match a EEM_Registration status constant.
64
-     *
65
-     * @var string $filtered_reg_status
66
-     */
67
-    public $filtered_reg_status;
68
-
69
-    /**
70
-     * will hold an array of events assembled from $reg_info
71
-     *
72
-     * @var EE_Event[] $events
73
-     */
74
-    public $events;
75
-
76
-    /**
77
-     * holds an array of datetimes assembled from the incoming data.
78
-     *
79
-     * @var EE_Datetime[] $datetimes
80
-     */
81
-    public $datetimes;
82
-
83
-    /**
84
-     * holds an array of tickets assembled from the incoming data.
85
-     *
86
-     * @var EE_Ticket[] $tickets
87
-     */
88
-    public $tickets;
89
-
90
-    /**
91
-     * holds an array with a key of parent line item and values are an array of children of that line item.
92
-     *
93
-     * @since 4.5.0
94
-     * @var EE_Line_Item[] $line_items_with_children
95
-     */
96
-    public $line_items_with_children;
97
-
98
-    /**
99
-     * will hold an array of attendees assembled from the $reg_info
100
-     *
101
-     * @var EE_Attendee[] $attendees
102
-     */
103
-    public $attendees;
104
-
105
-    /**
106
-     * will hold an array of cached registration objects and info assembled from reg_info
107
-     *
108
-     * @var array $registrations
109
-     */
110
-    public $registrations;
111
-
112
-    /**
113
-     * will hold an array of answers assembled from the $reg_info
114
-     *
115
-     * @var EE_Answer[] $answers
116
-     */
117
-    public $answers;
118
-
119
-    /**
120
-     * will hold an array of questions assembled from the $reg_info (indexed by Answer ID);
121
-     *
122
-     * @var EE_Question[] $questions
123
-     */
124
-    public $questions;
125
-
126
-    /**
127
-     * Will hold billing data assembled from $billing_info (if present)
128
-     *
129
-     * @var mixed (array|null) $billing
130
-     */
131
-    public $billing;
132
-
133
-    /**
134
-     * The total amount of tax for the transaction
135
-     *
136
-     * @var float $taxes
137
-     */
138
-    public $taxes;
139
-
140
-    /**
141
-     * Holds the line items related to taxes
142
-     *
143
-     * @since 4.5.0
144
-     * @var EE_Line_Item[] $tax_line_items
145
-     */
146
-    public $tax_line_items;
147
-
148
-    /**
149
-     * Hold the line items which aren't taxes and don't relate
150
-     * to tickets. So: promotions and miscellaneous charges
151
-     *
152
-     * @since 4.5
153
-     * @var EE_Line_Item[] $additional_line_items
154
-     */
155
-    public $additional_line_items;
156
-
157
-    /**
158
-     * Holds the grand total EE_Line_Item
159
-     *
160
-     * @var EE_Line_Item $grand_total_line_item
161
-     */
162
-    public $grand_total_line_item;
163
-
164
-    /**
165
-     * holds the grand total price object
166
-     * currently not used.
167
-     *
168
-     * @var null $grand_total_price_object
169
-     */
170
-    public $grand_total_price_object;
171
-
172
-    /**
173
-     * total number of tickets
174
-     *
175
-     * @var int $total_ticket_count
176
-     */
177
-    public $total_ticket_count;
178
-
179
-    /**
180
-     * Will hold the final transaction object (EE_Transaction)
181
-     *
182
-     * @var EE_Transaction $txn
183
-     */
184
-    public $txn;
185
-
186
-    /**
187
-     * Holds the payments related to a transaction
188
-     *
189
-     * @since 4.5.0
190
-     * @var EE_Payment[] $payments
191
-     */
192
-    public $payments;
193
-
194
-    /**
195
-     * Holds the first related payment related for a transaction
196
-     *
197
-     * @since 4.5.0
198
-     * @var EE_Payment $payment
199
-     */
200
-    public $payment;
201
-
202
-    /**
203
-     * Will hold the label for the txn status
204
-     *
205
-     * @var string $txn_status
206
-     */
207
-    public $txn_status;
208
-
209
-    /**
210
-     * Will hold the final registration object (EE_Registration)
211
-     *
212
-     * @var EE_Registration[] $reg_objs
213
-     */
214
-    public $reg_objs;
215
-
216
-    /**
217
-     * Will hold an array of primary attendee data (if present)
218
-     *
219
-     * @var array $primary_attendee_data
220
-     */
221
-    public $primary_attendee_data;
222
-
223
-    /**
224
-     * This is just an internal object used for passing around the incoming data.
225
-     *
226
-     * @var mixed $_data
227
-     */
228
-    protected $_data;
229
-
230
-    /**
231
-     * This is just an internal object used for passing around the incoming data.
232
-     *
233
-     * @var mixed $incoming_data
234
-     */
235
-    public $incoming_data;
236
-
237
-    /**
238
-     * hold objects that might be created
239
-     *
240
-     * @type EE_Registration $reg_obj
241
-     */
242
-    public $reg_obj;
243
-
244
-
245
-    /**
246
-     * constructor
247
-     *
248
-     * @param mixed $data incoming data object|array.  Suggested that child classes use type hinting for expected
249
-     *                    data object.  But here parent will be generic because we don't know what's coming in.
250
-     */
251
-    public function __construct($data)
252
-    {
253
-        $this->_data = $data;
254
-        $this->_setup_data();
255
-    }
256
-
257
-
258
-    /**
259
-     * Every child class has to setup the data object !
260
-     *
261
-     * @return void
262
-     */
263
-    abstract protected function _setup_data();
264
-
265
-
266
-    /**
267
-     * Returns database safe representation of the data later used to when instantiating this object.
268
-     *
269
-     * @param mixed $data The incoming data to be prepped.
270
-     * @return mixed   The prepped data for db
271
-     */
272
-    public static function convert_data_for_persistent_storage($data)
273
-    {
274
-        return $data;
275
-    }
276
-
277
-
278
-    /**
279
-     * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
280
-     * can be sent into this method and converted back into the format used for instantiating with this data handler.
281
-     *
282
-     * @param $data
283
-     * @return mixed
284
-     */
285
-    public static function convert_data_from_persistent_storage($data)
286
-    {
287
-        return $data;
288
-    }
289
-
290
-
291
-    /**
292
-     * only purpose is to return the data
293
-     *
294
-     * @access public
295
-     * @return mixed the formatted data object!
296
-     */
297
-    public function data()
298
-    {
299
-        return $this->_data;
300
-    }
301
-
302
-
303
-    /**
304
-     * This helper method can be used by any incoming data handlers to setup the data correctly.  All that is required
305
-     * is that $this->reg_objs be set.
306
-     *
307
-     * @throws EE_Error
308
-     * @throws InvalidDataTypeException
309
-     * @throws InvalidInterfaceException
310
-     * @throws InvalidArgumentException
311
-     * @throws EntityNotFoundException
312
-     */
313
-    protected function _assemble_data()
314
-    {
315
-        // verify that reg_objs is set
316
-        if (
317
-            ! is_array($this->reg_objs)
318
-            && ! reset($this->reg_objs) instanceof EE_Registration
319
-        ) {
320
-            throw new EE_Error(
321
-                esc_html__(
322
-                    'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects',
323
-                    'event_espresso'
324
-                )
325
-            );
326
-        }
327
-
328
-        // get all attendee and events associated with the registrations in this transaction
329
-        $events             = $event_setup = $evtcache = $tickets = $datetimes = array();
330
-        $answers            = $questions = $attendees = $line_items = $registrations = array();
331
-        $total_ticket_count = 0;
332
-
333
-        if (! empty($this->reg_objs)) {
334
-            $event_attendee_count = array();
335
-            /** @var EE_Registration $reg */
336
-            foreach ($this->reg_objs as $reg) {
337
-                if (
338
-                    $this->_skip_registration_for_processing($reg)
339
-                ) {
340
-                    continue;
341
-                }
342
-
343
-                $evt_id = $reg->event_ID();
344
-                /** @type EE_Ticket $ticket */
345
-                $ticket          = $reg->get_first_related('Ticket');
346
-                $attendee = $reg->attendee();
347
-                $event = $reg->event();
348
-                // if none of the following entities are available, then we can't setup other data reliably,
349
-                // so let's just skip.
350
-                if (
351
-                    ! $ticket instanceof EE_Ticket
352
-                    || ! $attendee instanceof EE_Attendee
353
-                    || ! $event instanceof EE_Event
354
-                ) {
355
-                    continue;
356
-                }
357
-                $relateddatetime = $ticket->datetimes();
358
-                $total_ticket_count++;
359
-                $tickets[ $ticket->ID() ]['ticket']                        = $ticket;
360
-                $tickets[ $ticket->ID() ]['count']                         = is_array($tickets[ $ticket->ID() ])
361
-                                                                           && isset($tickets[ $ticket->ID() ]['count'])
362
-                    ? $tickets[ $ticket->ID() ]['count'] + 1
363
-                    : 1;
364
-                $tickets[ $ticket->ID() ]['att_objs'][ $attendee->ID() ] = $attendee;
365
-                $tickets[ $ticket->ID() ]['dtt_objs']                      = $relateddatetime;
366
-                $tickets[ $ticket->ID() ]['reg_objs'][ $reg->ID() ]          = $reg;
367
-                $tickets[ $ticket->ID() ]['EE_Event']                      = $event;
368
-                $evtcache[ $evt_id ]                                       = $event;
369
-                $eventsetup[ $evt_id ]['reg_objs'][ $reg->ID() ]             = $reg;
370
-                $eventsetup[ $evt_id ]['tkt_objs'][ $ticket->ID() ]          = $ticket;
371
-                $eventsetup[ $evt_id ]['att_objs'][ $attendee->ID() ]    = $attendee;
372
-                $event_attendee_count[ $evt_id ]                           = isset($event_attendee_count[ $evt_id ])
373
-                    ? $event_attendee_count[ $evt_id ] + 1
374
-                    : 0;
375
-                $attendees[ $reg->attendee_ID() ]['line_ref'][]            = $evt_id;
376
-                $attendees[ $reg->attendee_ID() ]['att_obj']               = $attendee;
377
-                $attendees[ $reg->attendee_ID() ]['reg_objs'][ $reg->ID() ]  = $reg;
378
-                // $attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
379
-                $attendees[ $reg->attendee_ID() ]['attendee_email']          = $attendee->email();
380
-                $attendees[ $reg->attendee_ID() ]['tkt_objs'][ $ticket->ID() ] = $ticket;
381
-                $attendees[ $reg->attendee_ID() ]['evt_objs'][ $evt_id ]       = $event;
382
-
383
-                // registrations
384
-                $registrations[ $reg->ID() ]['tkt_obj'] = $ticket;
385
-                $registrations[ $reg->ID() ]['evt_obj'] = $event;
386
-                $registrations[ $reg->ID() ]['reg_obj'] = $reg;
387
-                $registrations[ $reg->ID() ]['att_obj'] = $attendee;
388
-
389
-                // set up answer objects
390
-                $rel_ans = $reg->get_many_related('Answer');
391
-                foreach ($rel_ans as $ansid => $answer) {
392
-                    if (! isset($questions[ $ansid ])) {
393
-                        $questions[ $ansid ] = $answer->get_first_related('Question');
394
-                    }
395
-                    $answers[ $ansid ]                               = $answer;
396
-                    $registrations[ $reg->ID() ]['ans_objs'][ $ansid ] = $answer;
397
-                }
398
-                /**
399
-                 * @var int $dtt_id
400
-                 * @var EE_Datetime $datetime
401
-                 */
402
-                foreach ($relateddatetime as $dtt_id => $datetime) {
403
-                    $eventsetup[ $evt_id ]['dtt_objs'][ $dtt_id ]       = $datetime;
404
-                    $registrations[ $reg->ID() ]['dtt_objs'][ $dtt_id ] = $datetime;
405
-
406
-                    if (isset($datetimes[ $dtt_id ])) {
407
-                        continue; // already have this info in the datetimes array.
408
-                    }
409
-
410
-                    $datetimes[ $dtt_id ]['tkt_objs'][]           = $ticket;
411
-                    $datetimes[ $dtt_id ]['datetime']             = $datetime;
412
-                    $datetimes[ $dtt_id ]['evt_objs'][ $evt_id ]    = $event;
413
-                    $datetimes[ $dtt_id ]['reg_objs'][ $reg->ID() ] = $reg;
414
-                }
415
-            }
416
-
417
-            // let's loop through the unique event=>reg items and setup data on them
418
-
419
-            if (! empty($eventsetup)) {
420
-                foreach ($eventsetup as $evt_id => $items) {
421
-                    $ticket_line_items_for_event = array();
422
-                    if ($this->txn instanceof EE_Transaction) {
423
-                        $ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(
424
-                            array(
425
-                                array(
426
-                                    'Ticket.Datetime.EVT_ID' => $evt_id,
427
-                                    'TXN_ID'                 => $this->txn->ID(),
428
-                                ),
429
-                                'default_where_conditions' => 'none',
430
-                            )
431
-                        );
432
-                    }
433
-                    $events[ $evt_id ] = array(
434
-                        'ID'              => $evt_id,
435
-                        'event'           => $evtcache[ $evt_id ],
436
-                        'name'            => $evtcache[ $evt_id ] instanceof EE_Event ? $evtcache[ $evt_id ]->name() : '',
437
-                        'total_attendees' => $event_attendee_count[ $evt_id ],
438
-                        'reg_objs'        => $items['reg_objs'],
439
-                        'tkt_objs'        => $items['tkt_objs'],
440
-                        'att_objs'        => $items['att_objs'],
441
-                        'dtt_objs'        => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(),
442
-                        'line_items'      => $ticket_line_items_for_event,
443
-                    );
444
-
445
-                    // make sure the tickets have the line items setup for them.
446
-                    foreach ($ticket_line_items_for_event as $line_id => $line_item) {
447
-                        // only add the ticket line items if we already have this ticket in the $tickets array.
448
-                        if ($line_item instanceof EE_Line_Item && isset($tickets[ $line_item->ticket()->ID() ])) {
449
-                            $tickets[ $line_item->ticket()->ID() ]['line_item']      = $line_item;
450
-                            $tickets[ $line_item->ticket()->ID() ]['sub_line_items'] = $line_item->children();
451
-                            $line_items[ $line_item->ID() ]['children']              = $line_item->children();
452
-                            $line_items[ $line_item->ID() ]['EE_Ticket']             = $line_item->ticket();
453
-                        }
454
-                    }
455
-                }
456
-            }
457
-
458
-            $this->grand_total_line_item = $this->txn instanceof EE_Transaction
459
-                ? $this->txn->total_line_item()
460
-                : null;
461
-        }
462
-
463
-        // lets set the attendees and events properties
464
-        $this->attendees                = $attendees;
465
-        $this->events                   = $events;
466
-        $this->tickets                  = $tickets;
467
-        $this->line_items_with_children = $line_items;
468
-        $this->datetimes                = $datetimes;
469
-        $this->questions                = $questions;
470
-        $this->answers                  = $answers;
471
-        $this->total_ticket_count       = $total_ticket_count;
472
-        $this->registrations            = $registrations;
473
-
474
-        if ($this->txn instanceof EE_Transaction) {
475
-            $this->tax_line_items        = $this->txn->tax_items();
476
-            $this->additional_line_items = $this->txn->non_ticket_line_items();
477
-            $this->payments              = $this->txn->payments();
478
-
479
-            // setup primary registration if we have a single transaction object to work with
480
-
481
-            // let's get just the primary_attendee_data!  First we get the primary registration object.
482
-            $primary_reg = $this->txn->primary_registration();
483
-            // verify
484
-            if ($primary_reg instanceof EE_Registration) {
485
-                // get attendee object
486
-                if ($primary_reg->attendee() instanceof EE_Attendee) {
487
-                    // now we can setup the primary_attendee_data array
488
-                    $this->primary_attendee_data = array(
489
-                        'registration_id' => $primary_reg->ID(),
490
-                        'att_obj'         => $primary_reg->attendee(),
491
-                        'reg_obj'         => $primary_reg,
492
-                        'primary_att_obj' => $primary_reg->attendee(),
493
-                        'primary_reg_obj' => $primary_reg,
494
-                    );
495
-                } else {
496
-                    EE_Error::add_error(
497
-                        esc_html__(
498
-                            'Incoming data does not have a valid Attendee object for the primary registrant.',
499
-                            'event_espresso'
500
-                        ),
501
-                        __FILE__,
502
-                        __FUNCTION__,
503
-                        __LINE__
504
-                    );
505
-                }
506
-            } else {
507
-                EE_Error::add_error(
508
-                    esc_html__(
509
-                        'Incoming data does not have a valid Registration object for the primary registrant.',
510
-                        'event_espresso'
511
-                    ),
512
-                    __FILE__,
513
-                    __FUNCTION__,
514
-                    __LINE__
515
-                );
516
-            }
517
-        }
518
-    }
519
-
520
-    /**
521
-     * This simply considers whether the given registration should be processed or not based on comparison with the
522
-     * filtered_reg_status property.
523
-     *
524
-     * @param EE_Registration $registration
525
-     * @return bool  returning true means we DO want to skip processing.  returning false means we DON'T want to skip
526
-     *               processing
527
-     */
528
-    protected function _skip_registration_for_processing(EE_Registration $registration)
529
-    {
530
-        if (empty($this->filtered_reg_status)) {
531
-            return false;
532
-        }
533
-
534
-        // if we made it here then we just compare the filtered_reg_status with the registration status and return that
535
-        return $this->filtered_reg_status !== $registration->status_ID();
536
-    }
19
+	/**
20
+	 * user id for logged in user when data collected
21
+	 *
22
+	 * @var string $user_id
23
+	 */
24
+	public $user_id;
25
+
26
+	/**
27
+	 * IP Address of browser used
28
+	 *
29
+	 * @var string $ip_address
30
+	 */
31
+	public $ip_address;
32
+
33
+	/**
34
+	 * browser
35
+	 *
36
+	 * @var string $user_agent
37
+	 */
38
+	public $user_agent;
39
+
40
+	/**
41
+	 * Unix timestamp
42
+	 *
43
+	 * @var string $init_access
44
+	 */
45
+	public $init_access;
46
+
47
+	/**
48
+	 * Unix timestamp
49
+	 *
50
+	 * @var string $last_access
51
+	 */
52
+	public $last_access;
53
+
54
+	/**
55
+	 * The registrations details from the cart
56
+	 *
57
+	 * @var array $reg_info
58
+	 */
59
+	public $reg_info;
60
+
61
+	/**
62
+	 * Some data handlers can set what reg status all the registrations are filtered by.
63
+	 * The status should match a EEM_Registration status constant.
64
+	 *
65
+	 * @var string $filtered_reg_status
66
+	 */
67
+	public $filtered_reg_status;
68
+
69
+	/**
70
+	 * will hold an array of events assembled from $reg_info
71
+	 *
72
+	 * @var EE_Event[] $events
73
+	 */
74
+	public $events;
75
+
76
+	/**
77
+	 * holds an array of datetimes assembled from the incoming data.
78
+	 *
79
+	 * @var EE_Datetime[] $datetimes
80
+	 */
81
+	public $datetimes;
82
+
83
+	/**
84
+	 * holds an array of tickets assembled from the incoming data.
85
+	 *
86
+	 * @var EE_Ticket[] $tickets
87
+	 */
88
+	public $tickets;
89
+
90
+	/**
91
+	 * holds an array with a key of parent line item and values are an array of children of that line item.
92
+	 *
93
+	 * @since 4.5.0
94
+	 * @var EE_Line_Item[] $line_items_with_children
95
+	 */
96
+	public $line_items_with_children;
97
+
98
+	/**
99
+	 * will hold an array of attendees assembled from the $reg_info
100
+	 *
101
+	 * @var EE_Attendee[] $attendees
102
+	 */
103
+	public $attendees;
104
+
105
+	/**
106
+	 * will hold an array of cached registration objects and info assembled from reg_info
107
+	 *
108
+	 * @var array $registrations
109
+	 */
110
+	public $registrations;
111
+
112
+	/**
113
+	 * will hold an array of answers assembled from the $reg_info
114
+	 *
115
+	 * @var EE_Answer[] $answers
116
+	 */
117
+	public $answers;
118
+
119
+	/**
120
+	 * will hold an array of questions assembled from the $reg_info (indexed by Answer ID);
121
+	 *
122
+	 * @var EE_Question[] $questions
123
+	 */
124
+	public $questions;
125
+
126
+	/**
127
+	 * Will hold billing data assembled from $billing_info (if present)
128
+	 *
129
+	 * @var mixed (array|null) $billing
130
+	 */
131
+	public $billing;
132
+
133
+	/**
134
+	 * The total amount of tax for the transaction
135
+	 *
136
+	 * @var float $taxes
137
+	 */
138
+	public $taxes;
139
+
140
+	/**
141
+	 * Holds the line items related to taxes
142
+	 *
143
+	 * @since 4.5.0
144
+	 * @var EE_Line_Item[] $tax_line_items
145
+	 */
146
+	public $tax_line_items;
147
+
148
+	/**
149
+	 * Hold the line items which aren't taxes and don't relate
150
+	 * to tickets. So: promotions and miscellaneous charges
151
+	 *
152
+	 * @since 4.5
153
+	 * @var EE_Line_Item[] $additional_line_items
154
+	 */
155
+	public $additional_line_items;
156
+
157
+	/**
158
+	 * Holds the grand total EE_Line_Item
159
+	 *
160
+	 * @var EE_Line_Item $grand_total_line_item
161
+	 */
162
+	public $grand_total_line_item;
163
+
164
+	/**
165
+	 * holds the grand total price object
166
+	 * currently not used.
167
+	 *
168
+	 * @var null $grand_total_price_object
169
+	 */
170
+	public $grand_total_price_object;
171
+
172
+	/**
173
+	 * total number of tickets
174
+	 *
175
+	 * @var int $total_ticket_count
176
+	 */
177
+	public $total_ticket_count;
178
+
179
+	/**
180
+	 * Will hold the final transaction object (EE_Transaction)
181
+	 *
182
+	 * @var EE_Transaction $txn
183
+	 */
184
+	public $txn;
185
+
186
+	/**
187
+	 * Holds the payments related to a transaction
188
+	 *
189
+	 * @since 4.5.0
190
+	 * @var EE_Payment[] $payments
191
+	 */
192
+	public $payments;
193
+
194
+	/**
195
+	 * Holds the first related payment related for a transaction
196
+	 *
197
+	 * @since 4.5.0
198
+	 * @var EE_Payment $payment
199
+	 */
200
+	public $payment;
201
+
202
+	/**
203
+	 * Will hold the label for the txn status
204
+	 *
205
+	 * @var string $txn_status
206
+	 */
207
+	public $txn_status;
208
+
209
+	/**
210
+	 * Will hold the final registration object (EE_Registration)
211
+	 *
212
+	 * @var EE_Registration[] $reg_objs
213
+	 */
214
+	public $reg_objs;
215
+
216
+	/**
217
+	 * Will hold an array of primary attendee data (if present)
218
+	 *
219
+	 * @var array $primary_attendee_data
220
+	 */
221
+	public $primary_attendee_data;
222
+
223
+	/**
224
+	 * This is just an internal object used for passing around the incoming data.
225
+	 *
226
+	 * @var mixed $_data
227
+	 */
228
+	protected $_data;
229
+
230
+	/**
231
+	 * This is just an internal object used for passing around the incoming data.
232
+	 *
233
+	 * @var mixed $incoming_data
234
+	 */
235
+	public $incoming_data;
236
+
237
+	/**
238
+	 * hold objects that might be created
239
+	 *
240
+	 * @type EE_Registration $reg_obj
241
+	 */
242
+	public $reg_obj;
243
+
244
+
245
+	/**
246
+	 * constructor
247
+	 *
248
+	 * @param mixed $data incoming data object|array.  Suggested that child classes use type hinting for expected
249
+	 *                    data object.  But here parent will be generic because we don't know what's coming in.
250
+	 */
251
+	public function __construct($data)
252
+	{
253
+		$this->_data = $data;
254
+		$this->_setup_data();
255
+	}
256
+
257
+
258
+	/**
259
+	 * Every child class has to setup the data object !
260
+	 *
261
+	 * @return void
262
+	 */
263
+	abstract protected function _setup_data();
264
+
265
+
266
+	/**
267
+	 * Returns database safe representation of the data later used to when instantiating this object.
268
+	 *
269
+	 * @param mixed $data The incoming data to be prepped.
270
+	 * @return mixed   The prepped data for db
271
+	 */
272
+	public static function convert_data_for_persistent_storage($data)
273
+	{
274
+		return $data;
275
+	}
276
+
277
+
278
+	/**
279
+	 * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage
280
+	 * can be sent into this method and converted back into the format used for instantiating with this data handler.
281
+	 *
282
+	 * @param $data
283
+	 * @return mixed
284
+	 */
285
+	public static function convert_data_from_persistent_storage($data)
286
+	{
287
+		return $data;
288
+	}
289
+
290
+
291
+	/**
292
+	 * only purpose is to return the data
293
+	 *
294
+	 * @access public
295
+	 * @return mixed the formatted data object!
296
+	 */
297
+	public function data()
298
+	{
299
+		return $this->_data;
300
+	}
301
+
302
+
303
+	/**
304
+	 * This helper method can be used by any incoming data handlers to setup the data correctly.  All that is required
305
+	 * is that $this->reg_objs be set.
306
+	 *
307
+	 * @throws EE_Error
308
+	 * @throws InvalidDataTypeException
309
+	 * @throws InvalidInterfaceException
310
+	 * @throws InvalidArgumentException
311
+	 * @throws EntityNotFoundException
312
+	 */
313
+	protected function _assemble_data()
314
+	{
315
+		// verify that reg_objs is set
316
+		if (
317
+			! is_array($this->reg_objs)
318
+			&& ! reset($this->reg_objs) instanceof EE_Registration
319
+		) {
320
+			throw new EE_Error(
321
+				esc_html__(
322
+					'In order to assemble the data correctly, the "reg_objs" property must be an array of EE_Registration objects',
323
+					'event_espresso'
324
+				)
325
+			);
326
+		}
327
+
328
+		// get all attendee and events associated with the registrations in this transaction
329
+		$events             = $event_setup = $evtcache = $tickets = $datetimes = array();
330
+		$answers            = $questions = $attendees = $line_items = $registrations = array();
331
+		$total_ticket_count = 0;
332
+
333
+		if (! empty($this->reg_objs)) {
334
+			$event_attendee_count = array();
335
+			/** @var EE_Registration $reg */
336
+			foreach ($this->reg_objs as $reg) {
337
+				if (
338
+					$this->_skip_registration_for_processing($reg)
339
+				) {
340
+					continue;
341
+				}
342
+
343
+				$evt_id = $reg->event_ID();
344
+				/** @type EE_Ticket $ticket */
345
+				$ticket          = $reg->get_first_related('Ticket');
346
+				$attendee = $reg->attendee();
347
+				$event = $reg->event();
348
+				// if none of the following entities are available, then we can't setup other data reliably,
349
+				// so let's just skip.
350
+				if (
351
+					! $ticket instanceof EE_Ticket
352
+					|| ! $attendee instanceof EE_Attendee
353
+					|| ! $event instanceof EE_Event
354
+				) {
355
+					continue;
356
+				}
357
+				$relateddatetime = $ticket->datetimes();
358
+				$total_ticket_count++;
359
+				$tickets[ $ticket->ID() ]['ticket']                        = $ticket;
360
+				$tickets[ $ticket->ID() ]['count']                         = is_array($tickets[ $ticket->ID() ])
361
+																		   && isset($tickets[ $ticket->ID() ]['count'])
362
+					? $tickets[ $ticket->ID() ]['count'] + 1
363
+					: 1;
364
+				$tickets[ $ticket->ID() ]['att_objs'][ $attendee->ID() ] = $attendee;
365
+				$tickets[ $ticket->ID() ]['dtt_objs']                      = $relateddatetime;
366
+				$tickets[ $ticket->ID() ]['reg_objs'][ $reg->ID() ]          = $reg;
367
+				$tickets[ $ticket->ID() ]['EE_Event']                      = $event;
368
+				$evtcache[ $evt_id ]                                       = $event;
369
+				$eventsetup[ $evt_id ]['reg_objs'][ $reg->ID() ]             = $reg;
370
+				$eventsetup[ $evt_id ]['tkt_objs'][ $ticket->ID() ]          = $ticket;
371
+				$eventsetup[ $evt_id ]['att_objs'][ $attendee->ID() ]    = $attendee;
372
+				$event_attendee_count[ $evt_id ]                           = isset($event_attendee_count[ $evt_id ])
373
+					? $event_attendee_count[ $evt_id ] + 1
374
+					: 0;
375
+				$attendees[ $reg->attendee_ID() ]['line_ref'][]            = $evt_id;
376
+				$attendees[ $reg->attendee_ID() ]['att_obj']               = $attendee;
377
+				$attendees[ $reg->attendee_ID() ]['reg_objs'][ $reg->ID() ]  = $reg;
378
+				// $attendees[ $reg->attendee_ID() ]['registration_id'] = $reg->ID();
379
+				$attendees[ $reg->attendee_ID() ]['attendee_email']          = $attendee->email();
380
+				$attendees[ $reg->attendee_ID() ]['tkt_objs'][ $ticket->ID() ] = $ticket;
381
+				$attendees[ $reg->attendee_ID() ]['evt_objs'][ $evt_id ]       = $event;
382
+
383
+				// registrations
384
+				$registrations[ $reg->ID() ]['tkt_obj'] = $ticket;
385
+				$registrations[ $reg->ID() ]['evt_obj'] = $event;
386
+				$registrations[ $reg->ID() ]['reg_obj'] = $reg;
387
+				$registrations[ $reg->ID() ]['att_obj'] = $attendee;
388
+
389
+				// set up answer objects
390
+				$rel_ans = $reg->get_many_related('Answer');
391
+				foreach ($rel_ans as $ansid => $answer) {
392
+					if (! isset($questions[ $ansid ])) {
393
+						$questions[ $ansid ] = $answer->get_first_related('Question');
394
+					}
395
+					$answers[ $ansid ]                               = $answer;
396
+					$registrations[ $reg->ID() ]['ans_objs'][ $ansid ] = $answer;
397
+				}
398
+				/**
399
+				 * @var int $dtt_id
400
+				 * @var EE_Datetime $datetime
401
+				 */
402
+				foreach ($relateddatetime as $dtt_id => $datetime) {
403
+					$eventsetup[ $evt_id ]['dtt_objs'][ $dtt_id ]       = $datetime;
404
+					$registrations[ $reg->ID() ]['dtt_objs'][ $dtt_id ] = $datetime;
405
+
406
+					if (isset($datetimes[ $dtt_id ])) {
407
+						continue; // already have this info in the datetimes array.
408
+					}
409
+
410
+					$datetimes[ $dtt_id ]['tkt_objs'][]           = $ticket;
411
+					$datetimes[ $dtt_id ]['datetime']             = $datetime;
412
+					$datetimes[ $dtt_id ]['evt_objs'][ $evt_id ]    = $event;
413
+					$datetimes[ $dtt_id ]['reg_objs'][ $reg->ID() ] = $reg;
414
+				}
415
+			}
416
+
417
+			// let's loop through the unique event=>reg items and setup data on them
418
+
419
+			if (! empty($eventsetup)) {
420
+				foreach ($eventsetup as $evt_id => $items) {
421
+					$ticket_line_items_for_event = array();
422
+					if ($this->txn instanceof EE_Transaction) {
423
+						$ticket_line_items_for_event = EEM_Line_Item::instance()->get_all(
424
+							array(
425
+								array(
426
+									'Ticket.Datetime.EVT_ID' => $evt_id,
427
+									'TXN_ID'                 => $this->txn->ID(),
428
+								),
429
+								'default_where_conditions' => 'none',
430
+							)
431
+						);
432
+					}
433
+					$events[ $evt_id ] = array(
434
+						'ID'              => $evt_id,
435
+						'event'           => $evtcache[ $evt_id ],
436
+						'name'            => $evtcache[ $evt_id ] instanceof EE_Event ? $evtcache[ $evt_id ]->name() : '',
437
+						'total_attendees' => $event_attendee_count[ $evt_id ],
438
+						'reg_objs'        => $items['reg_objs'],
439
+						'tkt_objs'        => $items['tkt_objs'],
440
+						'att_objs'        => $items['att_objs'],
441
+						'dtt_objs'        => isset($items['dtt_objs']) ? $items['dtt_objs'] : array(),
442
+						'line_items'      => $ticket_line_items_for_event,
443
+					);
444
+
445
+					// make sure the tickets have the line items setup for them.
446
+					foreach ($ticket_line_items_for_event as $line_id => $line_item) {
447
+						// only add the ticket line items if we already have this ticket in the $tickets array.
448
+						if ($line_item instanceof EE_Line_Item && isset($tickets[ $line_item->ticket()->ID() ])) {
449
+							$tickets[ $line_item->ticket()->ID() ]['line_item']      = $line_item;
450
+							$tickets[ $line_item->ticket()->ID() ]['sub_line_items'] = $line_item->children();
451
+							$line_items[ $line_item->ID() ]['children']              = $line_item->children();
452
+							$line_items[ $line_item->ID() ]['EE_Ticket']             = $line_item->ticket();
453
+						}
454
+					}
455
+				}
456
+			}
457
+
458
+			$this->grand_total_line_item = $this->txn instanceof EE_Transaction
459
+				? $this->txn->total_line_item()
460
+				: null;
461
+		}
462
+
463
+		// lets set the attendees and events properties
464
+		$this->attendees                = $attendees;
465
+		$this->events                   = $events;
466
+		$this->tickets                  = $tickets;
467
+		$this->line_items_with_children = $line_items;
468
+		$this->datetimes                = $datetimes;
469
+		$this->questions                = $questions;
470
+		$this->answers                  = $answers;
471
+		$this->total_ticket_count       = $total_ticket_count;
472
+		$this->registrations            = $registrations;
473
+
474
+		if ($this->txn instanceof EE_Transaction) {
475
+			$this->tax_line_items        = $this->txn->tax_items();
476
+			$this->additional_line_items = $this->txn->non_ticket_line_items();
477
+			$this->payments              = $this->txn->payments();
478
+
479
+			// setup primary registration if we have a single transaction object to work with
480
+
481
+			// let's get just the primary_attendee_data!  First we get the primary registration object.
482
+			$primary_reg = $this->txn->primary_registration();
483
+			// verify
484
+			if ($primary_reg instanceof EE_Registration) {
485
+				// get attendee object
486
+				if ($primary_reg->attendee() instanceof EE_Attendee) {
487
+					// now we can setup the primary_attendee_data array
488
+					$this->primary_attendee_data = array(
489
+						'registration_id' => $primary_reg->ID(),
490
+						'att_obj'         => $primary_reg->attendee(),
491
+						'reg_obj'         => $primary_reg,
492
+						'primary_att_obj' => $primary_reg->attendee(),
493
+						'primary_reg_obj' => $primary_reg,
494
+					);
495
+				} else {
496
+					EE_Error::add_error(
497
+						esc_html__(
498
+							'Incoming data does not have a valid Attendee object for the primary registrant.',
499
+							'event_espresso'
500
+						),
501
+						__FILE__,
502
+						__FUNCTION__,
503
+						__LINE__
504
+					);
505
+				}
506
+			} else {
507
+				EE_Error::add_error(
508
+					esc_html__(
509
+						'Incoming data does not have a valid Registration object for the primary registrant.',
510
+						'event_espresso'
511
+					),
512
+					__FILE__,
513
+					__FUNCTION__,
514
+					__LINE__
515
+				);
516
+			}
517
+		}
518
+	}
519
+
520
+	/**
521
+	 * This simply considers whether the given registration should be processed or not based on comparison with the
522
+	 * filtered_reg_status property.
523
+	 *
524
+	 * @param EE_Registration $registration
525
+	 * @return bool  returning true means we DO want to skip processing.  returning false means we DON'T want to skip
526
+	 *               processing
527
+	 */
528
+	protected function _skip_registration_for_processing(EE_Registration $registration)
529
+	{
530
+		if (empty($this->filtered_reg_status)) {
531
+			return false;
532
+		}
533
+
534
+		// if we made it here then we just compare the filtered_reg_status with the registration status and return that
535
+		return $this->filtered_reg_status !== $registration->status_ID();
536
+	}
537 537
 }
Please login to merge, or discard this patch.
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 2 patches
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     public static function instance()
75 75
     {
76 76
         // check if class object is instantiated, and instantiated properly
77
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
77
+        if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
78 78
             EE_Registry::instance()->load_lib('PMT_Base');
79 79
             self::$_instance = new self();
80 80
         }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public function maybe_register_payment_methods($force_recheck = false)
107 107
     {
108
-        if (! $this->_payment_method_types || $force_recheck) {
108
+        if ( ! $this->_payment_method_types || $force_recheck) {
109 109
             $this->_register_payment_methods();
110 110
         }
111 111
     }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     protected function _register_payment_methods()
120 120
     {
121 121
         // grab list of installed modules
122
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
122
+        $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR);
123 123
         // filter list of modules to register
124 124
         $pm_to_register = apply_filters(
125 125
             'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
         // create class name from module directory name
160 160
         $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
161 161
         // add class prefix
162
-        $module_class = 'EE_PMT_' . $module;
162
+        $module_class = 'EE_PMT_'.$module;
163 163
         // does the module exist ?
164
-        if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
164
+        if ( ! is_readable($payment_method_path.'/'.$module_class.$module_ext)) {
165 165
             $msg = sprintf(
166 166
                 esc_html__(
167 167
                     'The requested %s payment method file could not be found or is not readable due to file permissions.',
@@ -169,22 +169,22 @@  discard block
 block discarded – undo
169 169
                 ),
170 170
                 $module
171 171
             );
172
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
172
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
173 173
             return false;
174 174
         }
175 175
         // load the module class file
176
-        require_once($payment_method_path . '/' . $module_class . $module_ext);
176
+        require_once($payment_method_path.'/'.$module_class.$module_ext);
177 177
         // verify that class exists
178
-        if (! class_exists($module_class)) {
178
+        if ( ! class_exists($module_class)) {
179 179
             $msg = sprintf(
180 180
                 esc_html__('The requested %s module class does not exist.', 'event_espresso'),
181 181
                 $module_class
182 182
             );
183
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
183
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
184 184
             return false;
185 185
         }
186 186
         // add to array of registered modules
187
-        $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
187
+        $this->_payment_method_types[$module] = $payment_method_path.'/'.$module_class.$module_ext;
188 188
         ksort($this->_payment_method_types);
189 189
         return true;
190 190
     }
@@ -202,12 +202,12 @@  discard block
 block discarded – undo
202 202
         if (
203 203
             $force_recheck
204 204
             || ! is_array($this->_payment_method_types)
205
-            || ! isset($this->_payment_method_types[ $payment_method_name ])
205
+            || ! isset($this->_payment_method_types[$payment_method_name])
206 206
         ) {
207 207
             $this->maybe_register_payment_methods($force_recheck);
208 208
         }
209
-        if (isset($this->_payment_method_types[ $payment_method_name ])) {
210
-            require_once($this->_payment_method_types[ $payment_method_name ]);
209
+        if (isset($this->_payment_method_types[$payment_method_name])) {
210
+            require_once($this->_payment_method_types[$payment_method_name]);
211 211
             return true;
212 212
         }
213 213
         return false;
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
         if ($force_recheck || empty($this->payment_method_objects)) {
250 250
             $this->maybe_register_payment_methods($force_recheck);
251 251
             foreach ($this->payment_method_type_names(true) as $classname) {
252
-                if (! isset($this->payment_method_objects[ $classname ])) {
253
-                    $this->payment_method_objects[ $classname ] = new $classname();
252
+                if ( ! isset($this->payment_method_objects[$classname])) {
253
+                    $this->payment_method_objects[$classname] = new $classname();
254 254
                 }
255 255
             }
256 256
         }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      */
280 280
     public function payment_method_class_from_type($type)
281 281
     {
282
-        return 'EE_PMT_' . $type;
282
+        return 'EE_PMT_'.$type;
283 283
     }
284 284
 
285 285
 
@@ -295,13 +295,13 @@  discard block
 block discarded – undo
295 295
     {
296 296
         $this->maybe_register_payment_methods();
297 297
         $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
298
-        if (! $payment_method instanceof EE_Payment_Method) {
298
+        if ( ! $payment_method instanceof EE_Payment_Method) {
299 299
             $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
300 300
             if (class_exists($pm_type_class)) {
301 301
                 /** @var $pm_type_obj EE_PMT_Base */
302 302
                 $pm_type_obj = new $pm_type_class();
303 303
                 $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
304
-                if (! $payment_method) {
304
+                if ( ! $payment_method) {
305 305
                     $payment_method = $this->create_payment_method_of_type($pm_type_obj);
306 306
                 }
307 307
                 $payment_method->set_type($payment_method_type);
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
                         'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
339 339
                         'event_espresso'
340 340
                     ),
341
-                    '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
341
+                    '<a href="'.admin_url('admin.php?page=espresso_messages&action=settings').'">',
342 342
                     '</a>'
343 343
                 ),
344 344
                 true
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
                 'PMD_type'       => $pm_type_obj->system_name(),
365 365
                 'PMD_name'       => $pm_type_obj->defaultFrontendName(),
366 366
                 'PMD_admin_name' => $pm_type_obj->pretty_name(),
367
-                'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
367
+                'PMD_slug'       => $pm_type_obj->system_name(), // automatically converted to slug
368 368
                 'PMD_wp_user'    => $current_user->ID,
369 369
                 'PMD_order'      => EEM_Payment_Method::instance()->count(
370 370
                     array(array('PMD_type' => array('!=', 'Admin_Only')))
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
     {
387 387
         $pm_type_obj = $payment_method->type_obj();
388 388
         $payment_method->set_description($pm_type_obj->default_description());
389
-        if (! $payment_method->button_url()) {
389
+        if ( ! $payment_method->button_url()) {
390 390
             $payment_method->set_button_url($pm_type_obj->default_button_url());
391 391
         }
392 392
         // now add setup its default extra meta properties
393 393
         $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
394
-        if (! empty($extra_metas)) {
394
+        if ( ! empty($extra_metas)) {
395 395
             // verify the payment method has an ID before adding extra meta
396
-            if (! $payment_method->ID()) {
396
+            if ( ! $payment_method->ID()) {
397 397
                 $payment_method->save();
398 398
             }
399 399
             foreach ($extra_metas as $meta_name => $input) {
@@ -536,10 +536,10 @@  discard block
 block discarded – undo
536 536
                 )
537 537
             );
538 538
         }
539
-        if (! isset($payment_method_caps[ $role ])) {
540
-            $payment_method_caps[ $role ] = array();
539
+        if ( ! isset($payment_method_caps[$role])) {
540
+            $payment_method_caps[$role] = array();
541 541
         }
542
-        $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
542
+        $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
543 543
                                           . strtolower($payment_method_name);
544 544
         return $payment_method_caps;
545 545
     }
Please login to merge, or discard this patch.
Indentation   +557 added lines, -557 removed lines patch added patch discarded remove patch
@@ -16,561 +16,561 @@
 block discarded – undo
16 16
  */
17 17
 class EE_Payment_Method_Manager implements ResettableInterface
18 18
 {
19
-    /**
20
-     * prefix added to all payment method capabilities names
21
-     */
22
-    const   CAPABILITIES_PREFIX = 'ee_payment_method_';
23
-
24
-    /**
25
-     * @var EE_Payment_Method_Manager $_instance
26
-     */
27
-    private static $_instance;
28
-
29
-    /**
30
-     * @var boolean
31
-     */
32
-    protected $payment_method_caps_initialized = false;
33
-
34
-    /**
35
-     * @var array keys are class names without 'EE_PMT_', values are their filepaths
36
-     */
37
-    protected $_payment_method_types = array();
38
-
39
-    /**
40
-     * @var EE_PMT_Base[]
41
-     */
42
-    protected $payment_method_objects = array();
43
-
44
-
45
-    /**
46
-     * EE_Payment_Method_Manager constructor.
47
-     *
48
-     * @throws EE_Error
49
-     * @throws DomainException
50
-     */
51
-    public function __construct()
52
-    {
53
-        // if in admin lets ensure caps are set.
54
-        if (is_admin()) {
55
-            $this->_register_payment_methods();
56
-            // set them immediately
57
-            $this->initializePaymentMethodCaps();
58
-            // plus any time they get reset
59
-            add_filter(
60
-                'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
61
-                array($this, 'addPaymentMethodCapsDuringReset')
62
-            );
63
-        }
64
-    }
65
-
66
-
67
-    /**
68
-     * @singleton method used to instantiate class object
69
-     * @return EE_Payment_Method_Manager instance
70
-     * @throws DomainException
71
-     * @throws EE_Error
72
-     */
73
-    public static function instance()
74
-    {
75
-        // check if class object is instantiated, and instantiated properly
76
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
77
-            EE_Registry::instance()->load_lib('PMT_Base');
78
-            self::$_instance = new self();
79
-        }
80
-        return self::$_instance;
81
-    }
82
-
83
-
84
-    /**
85
-     * Resets the instance and returns a new one
86
-     *
87
-     * @return EE_Payment_Method_Manager
88
-     * @throws DomainException
89
-     * @throws EE_Error
90
-     */
91
-    public static function reset()
92
-    {
93
-        self::$_instance = null;
94
-        return self::instance();
95
-    }
96
-
97
-
98
-    /**
99
-     * If necessary, re-register payment methods
100
-     *
101
-     * @param boolean $force_recheck whether to recheck for payment method types,
102
-     *                               or just re-use the PMTs we found last time we checked during this request (if
103
-     *                               we have not yet checked during this request, then we need to check anyways)
104
-     */
105
-    public function maybe_register_payment_methods($force_recheck = false)
106
-    {
107
-        if (! $this->_payment_method_types || $force_recheck) {
108
-            $this->_register_payment_methods();
109
-        }
110
-    }
111
-
112
-
113
-    /**
114
-     * register_payment_methods
115
-     *
116
-     * @return array
117
-     */
118
-    protected function _register_payment_methods()
119
-    {
120
-        // grab list of installed modules
121
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
122
-        // filter list of modules to register
123
-        $pm_to_register = apply_filters(
124
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
125
-            $pm_to_register
126
-        );
127
-        // remove any duplicates if that should happen for some reason
128
-        $pm_to_register = array_unique($pm_to_register);
129
-        // loop through folders
130
-        foreach ($pm_to_register as $pm_path) {
131
-            $this->register_payment_method($pm_path);
132
-        }
133
-        do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
134
-        // filter list of installed modules
135
-        // keep them organized alphabetically by the payment method type's name
136
-        ksort($this->_payment_method_types);
137
-        return apply_filters(
138
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
139
-            $this->_payment_method_types
140
-        );
141
-    }
142
-
143
-
144
-    /**
145
-     * register_payment_method- makes core aware of this payment method
146
-     *
147
-     * @param string $payment_method_path - full path up to and including payment method folder
148
-     * @return boolean
149
-     */
150
-    public function register_payment_method($payment_method_path = '')
151
-    {
152
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
153
-        $module_ext = '.pm.php';
154
-        // make all separators match
155
-        $payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/');
156
-        // grab and sanitize module name
157
-        $module_dir = basename($payment_method_path);
158
-        // create class name from module directory name
159
-        $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
160
-        // add class prefix
161
-        $module_class = 'EE_PMT_' . $module;
162
-        // does the module exist ?
163
-        if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
164
-            $msg = sprintf(
165
-                esc_html__(
166
-                    'The requested %s payment method file could not be found or is not readable due to file permissions.',
167
-                    'event_espresso'
168
-                ),
169
-                $module
170
-            );
171
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
172
-            return false;
173
-        }
174
-        // load the module class file
175
-        require_once($payment_method_path . '/' . $module_class . $module_ext);
176
-        // verify that class exists
177
-        if (! class_exists($module_class)) {
178
-            $msg = sprintf(
179
-                esc_html__('The requested %s module class does not exist.', 'event_espresso'),
180
-                $module_class
181
-            );
182
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
183
-            return false;
184
-        }
185
-        // add to array of registered modules
186
-        $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
187
-        ksort($this->_payment_method_types);
188
-        return true;
189
-    }
190
-
191
-
192
-    /**
193
-     * Checks if a payment method has been registered, and if so includes it
194
-     *
195
-     * @param string  $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_')
196
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
197
-     * @return boolean
198
-     */
199
-    public function payment_method_type_exists($payment_method_name, $force_recheck = false)
200
-    {
201
-        if (
202
-            $force_recheck
203
-            || ! is_array($this->_payment_method_types)
204
-            || ! isset($this->_payment_method_types[ $payment_method_name ])
205
-        ) {
206
-            $this->maybe_register_payment_methods($force_recheck);
207
-        }
208
-        if (isset($this->_payment_method_types[ $payment_method_name ])) {
209
-            require_once($this->_payment_method_types[ $payment_method_name ]);
210
-            return true;
211
-        }
212
-        return false;
213
-    }
214
-
215
-
216
-    /**
217
-     * Returns all the class names of the various payment method types
218
-     *
219
-     * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
220
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
221
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
222
-     * @return array
223
-     */
224
-    public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
225
-    {
226
-        $this->maybe_register_payment_methods($force_recheck);
227
-        if ($with_prefixes) {
228
-            $classnames = array_keys($this->_payment_method_types);
229
-            $payment_methods = array();
230
-            foreach ($classnames as $classname) {
231
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
232
-            }
233
-            return $payment_methods;
234
-        }
235
-        return array_keys($this->_payment_method_types);
236
-    }
237
-
238
-
239
-    /**
240
-     * Gets an object of each payment method type, none of which are bound to a
241
-     * payment method instance
242
-     *
243
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
244
-     * @return EE_PMT_Base[]
245
-     */
246
-    public function payment_method_types($force_recheck = false)
247
-    {
248
-        if ($force_recheck || empty($this->payment_method_objects)) {
249
-            $this->maybe_register_payment_methods($force_recheck);
250
-            foreach ($this->payment_method_type_names(true) as $classname) {
251
-                if (! isset($this->payment_method_objects[ $classname ])) {
252
-                    $this->payment_method_objects[ $classname ] = new $classname();
253
-                }
254
-            }
255
-        }
256
-        return $this->payment_method_objects;
257
-    }
258
-
259
-
260
-    /**
261
-     * Changes the payment method's class name into the payment method type's name
262
-     * (as used on the payment method's table's PMD_type field)
263
-     *
264
-     * @param string $classname
265
-     * @return string
266
-     */
267
-    public function payment_method_type_sans_class_prefix($classname)
268
-    {
269
-        return str_replace('EE_PMT_', '', $classname);
270
-    }
271
-
272
-
273
-    /**
274
-     * Does the opposite of payment-method_type_sans_prefix
275
-     *
276
-     * @param string $type
277
-     * @return string
278
-     */
279
-    public function payment_method_class_from_type($type)
280
-    {
281
-        return 'EE_PMT_' . $type;
282
-    }
283
-
284
-
285
-    /**
286
-     * Activates a payment method of the given type.
287
-     *
288
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
289
-     * @return EE_Payment_Method
290
-     * @throws InvalidDataTypeException
291
-     * @throws EE_Error
292
-     */
293
-    public function activate_a_payment_method_of_type($payment_method_type)
294
-    {
295
-        $this->maybe_register_payment_methods();
296
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
297
-        if (! $payment_method instanceof EE_Payment_Method) {
298
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
299
-            if (class_exists($pm_type_class)) {
300
-                /** @var $pm_type_obj EE_PMT_Base */
301
-                $pm_type_obj = new $pm_type_class();
302
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
303
-                if (! $payment_method) {
304
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
305
-                }
306
-                $payment_method->set_type($payment_method_type);
307
-                $this->initialize_payment_method($payment_method);
308
-            } else {
309
-                throw new EE_Error(
310
-                    sprintf(
311
-                        esc_html__(
312
-                            'There is no payment method of type %1$s, so it could not be activated',
313
-                            'event_espresso'
314
-                        ),
315
-                        $pm_type_class
316
-                    )
317
-                );
318
-            }
319
-        }
320
-        $payment_method->set_active();
321
-        $payment_method->save();
322
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
323
-        // if this was the invoice message type, make sure users can view their invoices
324
-        if (
325
-            $payment_method->type() === 'Invoice'
326
-            && (
327
-            ! EEH_MSG_Template::is_mt_active('invoice')
328
-            )
329
-        ) {
330
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
331
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
332
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
333
-            new PersistentAdminNotice(
334
-                'invoice_pm_requirements_notice',
335
-                sprintf(
336
-                    esc_html__(
337
-                        'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
338
-                        'event_espresso'
339
-                    ),
340
-                    '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
341
-                    '</a>'
342
-                ),
343
-                true
344
-            );
345
-        }
346
-        return $payment_method;
347
-    }
348
-
349
-
350
-    /**
351
-     * Creates a payment method of the specified type. Does not save it.
352
-     *
353
-     * @global WP_User    $current_user
354
-     * @param EE_PMT_Base $pm_type_obj
355
-     * @return EE_Payment_Method
356
-     * @throws EE_Error
357
-     */
358
-    public function create_payment_method_of_type($pm_type_obj)
359
-    {
360
-        global $current_user;
361
-        $payment_method = EE_Payment_Method::new_instance(
362
-            array(
363
-                'PMD_type'       => $pm_type_obj->system_name(),
364
-                'PMD_name'       => $pm_type_obj->defaultFrontendName(),
365
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
366
-                'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
367
-                'PMD_wp_user'    => $current_user->ID,
368
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
369
-                    array(array('PMD_type' => array('!=', 'Admin_Only')))
370
-                ) * 10,
371
-            )
372
-        );
373
-        return $payment_method;
374
-    }
375
-
376
-
377
-    /**
378
-     * Sets the initial payment method properties (including extra meta)
379
-     *
380
-     * @param EE_Payment_Method $payment_method
381
-     * @return EE_Payment_Method
382
-     * @throws EE_Error
383
-     */
384
-    public function initialize_payment_method($payment_method)
385
-    {
386
-        $pm_type_obj = $payment_method->type_obj();
387
-        $payment_method->set_description($pm_type_obj->default_description());
388
-        if (! $payment_method->button_url()) {
389
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
390
-        }
391
-        // now add setup its default extra meta properties
392
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
393
-        if (! empty($extra_metas)) {
394
-            // verify the payment method has an ID before adding extra meta
395
-            if (! $payment_method->ID()) {
396
-                $payment_method->save();
397
-            }
398
-            foreach ($extra_metas as $meta_name => $input) {
399
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
400
-            }
401
-        }
402
-        return $payment_method;
403
-    }
404
-
405
-
406
-    /**
407
-     * Makes sure the payment method is related to the specified payment method
408
-     *
409
-     * @deprecated in 4.9.40 because the currency payment method table is being deprecated
410
-     * @param EE_Payment_Method $payment_method
411
-     * @return EE_Payment_Method
412
-     * @throws EE_Error
413
-     */
414
-    public function set_usable_currencies_on_payment_method($payment_method)
415
-    {
416
-        EE_Error::doing_it_wrong(
417
-            'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
418
-            esc_html__(
419
-                'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
420
-                'event_espresso'
421
-            ),
422
-            '4.9.40'
423
-        );
424
-        return $payment_method;
425
-    }
426
-
427
-
428
-    /**
429
-     * Deactivates a payment method of the given payment method slug.
430
-     *
431
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
432
-     * @return int count of rows updated.
433
-     * @throws EE_Error
434
-     */
435
-    public function deactivate_payment_method($payment_method_slug)
436
-    {
437
-        EE_Log::instance()->log(
438
-            __FILE__,
439
-            __FUNCTION__,
440
-            sprintf(
441
-                esc_html__(
442
-                    'Payment method with slug %1$s is being deactivated by site admin',
443
-                    'event_espresso'
444
-                ),
445
-                $payment_method_slug
446
-            ),
447
-            'payment_method_change'
448
-        );
449
-        $count_updated = EEM_Payment_Method::instance()->update(
450
-            array('PMD_scope' => array()),
451
-            array(array('PMD_slug' => $payment_method_slug))
452
-        );
453
-        do_action(
454
-            'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method',
455
-            $payment_method_slug,
456
-            $count_updated
457
-        );
458
-        return $count_updated;
459
-    }
460
-
461
-
462
-    /**
463
-     * initializes payment method access caps via EE_Capabilities::init_role_caps()
464
-     * upon EE_Payment_Method_Manager construction
465
-     *
466
-     * @throws EE_Error
467
-     * @throws DomainException
468
-     */
469
-    protected function initializePaymentMethodCaps()
470
-    {
471
-        // don't do this twice
472
-        if ($this->payment_method_caps_initialized) {
473
-            return;
474
-        }
475
-        EE_Capabilities::instance()->addCaps(
476
-            $this->getPaymentMethodCaps()
477
-        );
478
-        $this->payment_method_caps_initialized = true;
479
-    }
480
-
481
-
482
-    /**
483
-     * array  of dynamic payment method access caps.
484
-     * at the time of writing, october 20 2014, these are the caps added:
485
-     *  ee_payment_method_admin_only
486
-     *  ee_payment_method_aim
487
-     *  ee_payment_method_bank
488
-     *  ee_payment_method_check
489
-     *  ee_payment_method_invoice
490
-     *  ee_payment_method_mijireh
491
-     *  ee_payment_method_paypal_pro
492
-     *  ee_payment_method_paypal_standard
493
-     * Any other payment methods added to core or via addons will also get
494
-     * their related capability automatically added too, so long as they are
495
-     * registered properly using EE_Register_Payment_Method::register()
496
-     *
497
-     * @return array
498
-     * @throws DomainException
499
-     */
500
-    protected function getPaymentMethodCaps()
501
-    {
502
-        $caps = array();
503
-        foreach ($this->payment_method_type_names() as $payment_method_name) {
504
-            $caps = $this->addPaymentMethodCap($payment_method_name, $caps);
505
-        }
506
-        return $caps;
507
-    }
508
-
509
-
510
-    /**
511
-     * @param string $payment_method_name
512
-     * @param array  $payment_method_caps
513
-     * @param string $role
514
-     * @return array
515
-     * @throws DomainException
516
-     */
517
-    public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator')
518
-    {
519
-        if (empty($payment_method_name)) {
520
-            throw new DomainException(
521
-                esc_html__(
522
-                    'The name of a payment method must be specified to add capabilities.',
523
-                    'event_espresso'
524
-                )
525
-            );
526
-        }
527
-        if (empty($role)) {
528
-            throw new DomainException(
529
-                sprintf(
530
-                    esc_html__(
531
-                        'No role was supplied while trying to add capabilities for the %1$s payment method.',
532
-                        'event_espresso'
533
-                    ),
534
-                    $payment_method_name
535
-                )
536
-            );
537
-        }
538
-        if (! isset($payment_method_caps[ $role ])) {
539
-            $payment_method_caps[ $role ] = array();
540
-        }
541
-        $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
542
-                                          . strtolower($payment_method_name);
543
-        return $payment_method_caps;
544
-    }
545
-
546
-
547
-    /**
548
-     * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter
549
-     * to add dynamic payment method access caps when capabilities are reset
550
-     * (or if that filter is called and PM caps are not already set)
551
-     *
552
-     * @param array $caps capabilities being filtered
553
-     * @param bool  $reset
554
-     * @return array
555
-     * @throws DomainException
556
-     */
557
-    public function addPaymentMethodCapsDuringReset(array $caps, $reset = false)
558
-    {
559
-        if ($reset || ! $this->payment_method_caps_initialized) {
560
-            $this->payment_method_caps_initialized = true;
561
-            $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps());
562
-        }
563
-        return $caps;
564
-    }
565
-
566
-
567
-    /**
568
-     * @deprecated 4.9.42
569
-     * @param $caps
570
-     * @return mixed
571
-     */
572
-    public function add_payment_method_caps($caps)
573
-    {
574
-        return $caps;
575
-    }
19
+	/**
20
+	 * prefix added to all payment method capabilities names
21
+	 */
22
+	const   CAPABILITIES_PREFIX = 'ee_payment_method_';
23
+
24
+	/**
25
+	 * @var EE_Payment_Method_Manager $_instance
26
+	 */
27
+	private static $_instance;
28
+
29
+	/**
30
+	 * @var boolean
31
+	 */
32
+	protected $payment_method_caps_initialized = false;
33
+
34
+	/**
35
+	 * @var array keys are class names without 'EE_PMT_', values are their filepaths
36
+	 */
37
+	protected $_payment_method_types = array();
38
+
39
+	/**
40
+	 * @var EE_PMT_Base[]
41
+	 */
42
+	protected $payment_method_objects = array();
43
+
44
+
45
+	/**
46
+	 * EE_Payment_Method_Manager constructor.
47
+	 *
48
+	 * @throws EE_Error
49
+	 * @throws DomainException
50
+	 */
51
+	public function __construct()
52
+	{
53
+		// if in admin lets ensure caps are set.
54
+		if (is_admin()) {
55
+			$this->_register_payment_methods();
56
+			// set them immediately
57
+			$this->initializePaymentMethodCaps();
58
+			// plus any time they get reset
59
+			add_filter(
60
+				'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
61
+				array($this, 'addPaymentMethodCapsDuringReset')
62
+			);
63
+		}
64
+	}
65
+
66
+
67
+	/**
68
+	 * @singleton method used to instantiate class object
69
+	 * @return EE_Payment_Method_Manager instance
70
+	 * @throws DomainException
71
+	 * @throws EE_Error
72
+	 */
73
+	public static function instance()
74
+	{
75
+		// check if class object is instantiated, and instantiated properly
76
+		if (! self::$_instance instanceof EE_Payment_Method_Manager) {
77
+			EE_Registry::instance()->load_lib('PMT_Base');
78
+			self::$_instance = new self();
79
+		}
80
+		return self::$_instance;
81
+	}
82
+
83
+
84
+	/**
85
+	 * Resets the instance and returns a new one
86
+	 *
87
+	 * @return EE_Payment_Method_Manager
88
+	 * @throws DomainException
89
+	 * @throws EE_Error
90
+	 */
91
+	public static function reset()
92
+	{
93
+		self::$_instance = null;
94
+		return self::instance();
95
+	}
96
+
97
+
98
+	/**
99
+	 * If necessary, re-register payment methods
100
+	 *
101
+	 * @param boolean $force_recheck whether to recheck for payment method types,
102
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
103
+	 *                               we have not yet checked during this request, then we need to check anyways)
104
+	 */
105
+	public function maybe_register_payment_methods($force_recheck = false)
106
+	{
107
+		if (! $this->_payment_method_types || $force_recheck) {
108
+			$this->_register_payment_methods();
109
+		}
110
+	}
111
+
112
+
113
+	/**
114
+	 * register_payment_methods
115
+	 *
116
+	 * @return array
117
+	 */
118
+	protected function _register_payment_methods()
119
+	{
120
+		// grab list of installed modules
121
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
122
+		// filter list of modules to register
123
+		$pm_to_register = apply_filters(
124
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
125
+			$pm_to_register
126
+		);
127
+		// remove any duplicates if that should happen for some reason
128
+		$pm_to_register = array_unique($pm_to_register);
129
+		// loop through folders
130
+		foreach ($pm_to_register as $pm_path) {
131
+			$this->register_payment_method($pm_path);
132
+		}
133
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
134
+		// filter list of installed modules
135
+		// keep them organized alphabetically by the payment method type's name
136
+		ksort($this->_payment_method_types);
137
+		return apply_filters(
138
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
139
+			$this->_payment_method_types
140
+		);
141
+	}
142
+
143
+
144
+	/**
145
+	 * register_payment_method- makes core aware of this payment method
146
+	 *
147
+	 * @param string $payment_method_path - full path up to and including payment method folder
148
+	 * @return boolean
149
+	 */
150
+	public function register_payment_method($payment_method_path = '')
151
+	{
152
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
153
+		$module_ext = '.pm.php';
154
+		// make all separators match
155
+		$payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/');
156
+		// grab and sanitize module name
157
+		$module_dir = basename($payment_method_path);
158
+		// create class name from module directory name
159
+		$module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
160
+		// add class prefix
161
+		$module_class = 'EE_PMT_' . $module;
162
+		// does the module exist ?
163
+		if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
164
+			$msg = sprintf(
165
+				esc_html__(
166
+					'The requested %s payment method file could not be found or is not readable due to file permissions.',
167
+					'event_espresso'
168
+				),
169
+				$module
170
+			);
171
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
172
+			return false;
173
+		}
174
+		// load the module class file
175
+		require_once($payment_method_path . '/' . $module_class . $module_ext);
176
+		// verify that class exists
177
+		if (! class_exists($module_class)) {
178
+			$msg = sprintf(
179
+				esc_html__('The requested %s module class does not exist.', 'event_espresso'),
180
+				$module_class
181
+			);
182
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
183
+			return false;
184
+		}
185
+		// add to array of registered modules
186
+		$this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
187
+		ksort($this->_payment_method_types);
188
+		return true;
189
+	}
190
+
191
+
192
+	/**
193
+	 * Checks if a payment method has been registered, and if so includes it
194
+	 *
195
+	 * @param string  $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_')
196
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
197
+	 * @return boolean
198
+	 */
199
+	public function payment_method_type_exists($payment_method_name, $force_recheck = false)
200
+	{
201
+		if (
202
+			$force_recheck
203
+			|| ! is_array($this->_payment_method_types)
204
+			|| ! isset($this->_payment_method_types[ $payment_method_name ])
205
+		) {
206
+			$this->maybe_register_payment_methods($force_recheck);
207
+		}
208
+		if (isset($this->_payment_method_types[ $payment_method_name ])) {
209
+			require_once($this->_payment_method_types[ $payment_method_name ]);
210
+			return true;
211
+		}
212
+		return false;
213
+	}
214
+
215
+
216
+	/**
217
+	 * Returns all the class names of the various payment method types
218
+	 *
219
+	 * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
220
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
221
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
222
+	 * @return array
223
+	 */
224
+	public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
225
+	{
226
+		$this->maybe_register_payment_methods($force_recheck);
227
+		if ($with_prefixes) {
228
+			$classnames = array_keys($this->_payment_method_types);
229
+			$payment_methods = array();
230
+			foreach ($classnames as $classname) {
231
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
232
+			}
233
+			return $payment_methods;
234
+		}
235
+		return array_keys($this->_payment_method_types);
236
+	}
237
+
238
+
239
+	/**
240
+	 * Gets an object of each payment method type, none of which are bound to a
241
+	 * payment method instance
242
+	 *
243
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
244
+	 * @return EE_PMT_Base[]
245
+	 */
246
+	public function payment_method_types($force_recheck = false)
247
+	{
248
+		if ($force_recheck || empty($this->payment_method_objects)) {
249
+			$this->maybe_register_payment_methods($force_recheck);
250
+			foreach ($this->payment_method_type_names(true) as $classname) {
251
+				if (! isset($this->payment_method_objects[ $classname ])) {
252
+					$this->payment_method_objects[ $classname ] = new $classname();
253
+				}
254
+			}
255
+		}
256
+		return $this->payment_method_objects;
257
+	}
258
+
259
+
260
+	/**
261
+	 * Changes the payment method's class name into the payment method type's name
262
+	 * (as used on the payment method's table's PMD_type field)
263
+	 *
264
+	 * @param string $classname
265
+	 * @return string
266
+	 */
267
+	public function payment_method_type_sans_class_prefix($classname)
268
+	{
269
+		return str_replace('EE_PMT_', '', $classname);
270
+	}
271
+
272
+
273
+	/**
274
+	 * Does the opposite of payment-method_type_sans_prefix
275
+	 *
276
+	 * @param string $type
277
+	 * @return string
278
+	 */
279
+	public function payment_method_class_from_type($type)
280
+	{
281
+		return 'EE_PMT_' . $type;
282
+	}
283
+
284
+
285
+	/**
286
+	 * Activates a payment method of the given type.
287
+	 *
288
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
289
+	 * @return EE_Payment_Method
290
+	 * @throws InvalidDataTypeException
291
+	 * @throws EE_Error
292
+	 */
293
+	public function activate_a_payment_method_of_type($payment_method_type)
294
+	{
295
+		$this->maybe_register_payment_methods();
296
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
297
+		if (! $payment_method instanceof EE_Payment_Method) {
298
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
299
+			if (class_exists($pm_type_class)) {
300
+				/** @var $pm_type_obj EE_PMT_Base */
301
+				$pm_type_obj = new $pm_type_class();
302
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
303
+				if (! $payment_method) {
304
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
305
+				}
306
+				$payment_method->set_type($payment_method_type);
307
+				$this->initialize_payment_method($payment_method);
308
+			} else {
309
+				throw new EE_Error(
310
+					sprintf(
311
+						esc_html__(
312
+							'There is no payment method of type %1$s, so it could not be activated',
313
+							'event_espresso'
314
+						),
315
+						$pm_type_class
316
+					)
317
+				);
318
+			}
319
+		}
320
+		$payment_method->set_active();
321
+		$payment_method->save();
322
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
323
+		// if this was the invoice message type, make sure users can view their invoices
324
+		if (
325
+			$payment_method->type() === 'Invoice'
326
+			&& (
327
+			! EEH_MSG_Template::is_mt_active('invoice')
328
+			)
329
+		) {
330
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
331
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
332
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
333
+			new PersistentAdminNotice(
334
+				'invoice_pm_requirements_notice',
335
+				sprintf(
336
+					esc_html__(
337
+						'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
338
+						'event_espresso'
339
+					),
340
+					'<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
341
+					'</a>'
342
+				),
343
+				true
344
+			);
345
+		}
346
+		return $payment_method;
347
+	}
348
+
349
+
350
+	/**
351
+	 * Creates a payment method of the specified type. Does not save it.
352
+	 *
353
+	 * @global WP_User    $current_user
354
+	 * @param EE_PMT_Base $pm_type_obj
355
+	 * @return EE_Payment_Method
356
+	 * @throws EE_Error
357
+	 */
358
+	public function create_payment_method_of_type($pm_type_obj)
359
+	{
360
+		global $current_user;
361
+		$payment_method = EE_Payment_Method::new_instance(
362
+			array(
363
+				'PMD_type'       => $pm_type_obj->system_name(),
364
+				'PMD_name'       => $pm_type_obj->defaultFrontendName(),
365
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
366
+				'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
367
+				'PMD_wp_user'    => $current_user->ID,
368
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
369
+					array(array('PMD_type' => array('!=', 'Admin_Only')))
370
+				) * 10,
371
+			)
372
+		);
373
+		return $payment_method;
374
+	}
375
+
376
+
377
+	/**
378
+	 * Sets the initial payment method properties (including extra meta)
379
+	 *
380
+	 * @param EE_Payment_Method $payment_method
381
+	 * @return EE_Payment_Method
382
+	 * @throws EE_Error
383
+	 */
384
+	public function initialize_payment_method($payment_method)
385
+	{
386
+		$pm_type_obj = $payment_method->type_obj();
387
+		$payment_method->set_description($pm_type_obj->default_description());
388
+		if (! $payment_method->button_url()) {
389
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
390
+		}
391
+		// now add setup its default extra meta properties
392
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
393
+		if (! empty($extra_metas)) {
394
+			// verify the payment method has an ID before adding extra meta
395
+			if (! $payment_method->ID()) {
396
+				$payment_method->save();
397
+			}
398
+			foreach ($extra_metas as $meta_name => $input) {
399
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
400
+			}
401
+		}
402
+		return $payment_method;
403
+	}
404
+
405
+
406
+	/**
407
+	 * Makes sure the payment method is related to the specified payment method
408
+	 *
409
+	 * @deprecated in 4.9.40 because the currency payment method table is being deprecated
410
+	 * @param EE_Payment_Method $payment_method
411
+	 * @return EE_Payment_Method
412
+	 * @throws EE_Error
413
+	 */
414
+	public function set_usable_currencies_on_payment_method($payment_method)
415
+	{
416
+		EE_Error::doing_it_wrong(
417
+			'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
418
+			esc_html__(
419
+				'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
420
+				'event_espresso'
421
+			),
422
+			'4.9.40'
423
+		);
424
+		return $payment_method;
425
+	}
426
+
427
+
428
+	/**
429
+	 * Deactivates a payment method of the given payment method slug.
430
+	 *
431
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
432
+	 * @return int count of rows updated.
433
+	 * @throws EE_Error
434
+	 */
435
+	public function deactivate_payment_method($payment_method_slug)
436
+	{
437
+		EE_Log::instance()->log(
438
+			__FILE__,
439
+			__FUNCTION__,
440
+			sprintf(
441
+				esc_html__(
442
+					'Payment method with slug %1$s is being deactivated by site admin',
443
+					'event_espresso'
444
+				),
445
+				$payment_method_slug
446
+			),
447
+			'payment_method_change'
448
+		);
449
+		$count_updated = EEM_Payment_Method::instance()->update(
450
+			array('PMD_scope' => array()),
451
+			array(array('PMD_slug' => $payment_method_slug))
452
+		);
453
+		do_action(
454
+			'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method',
455
+			$payment_method_slug,
456
+			$count_updated
457
+		);
458
+		return $count_updated;
459
+	}
460
+
461
+
462
+	/**
463
+	 * initializes payment method access caps via EE_Capabilities::init_role_caps()
464
+	 * upon EE_Payment_Method_Manager construction
465
+	 *
466
+	 * @throws EE_Error
467
+	 * @throws DomainException
468
+	 */
469
+	protected function initializePaymentMethodCaps()
470
+	{
471
+		// don't do this twice
472
+		if ($this->payment_method_caps_initialized) {
473
+			return;
474
+		}
475
+		EE_Capabilities::instance()->addCaps(
476
+			$this->getPaymentMethodCaps()
477
+		);
478
+		$this->payment_method_caps_initialized = true;
479
+	}
480
+
481
+
482
+	/**
483
+	 * array  of dynamic payment method access caps.
484
+	 * at the time of writing, october 20 2014, these are the caps added:
485
+	 *  ee_payment_method_admin_only
486
+	 *  ee_payment_method_aim
487
+	 *  ee_payment_method_bank
488
+	 *  ee_payment_method_check
489
+	 *  ee_payment_method_invoice
490
+	 *  ee_payment_method_mijireh
491
+	 *  ee_payment_method_paypal_pro
492
+	 *  ee_payment_method_paypal_standard
493
+	 * Any other payment methods added to core or via addons will also get
494
+	 * their related capability automatically added too, so long as they are
495
+	 * registered properly using EE_Register_Payment_Method::register()
496
+	 *
497
+	 * @return array
498
+	 * @throws DomainException
499
+	 */
500
+	protected function getPaymentMethodCaps()
501
+	{
502
+		$caps = array();
503
+		foreach ($this->payment_method_type_names() as $payment_method_name) {
504
+			$caps = $this->addPaymentMethodCap($payment_method_name, $caps);
505
+		}
506
+		return $caps;
507
+	}
508
+
509
+
510
+	/**
511
+	 * @param string $payment_method_name
512
+	 * @param array  $payment_method_caps
513
+	 * @param string $role
514
+	 * @return array
515
+	 * @throws DomainException
516
+	 */
517
+	public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator')
518
+	{
519
+		if (empty($payment_method_name)) {
520
+			throw new DomainException(
521
+				esc_html__(
522
+					'The name of a payment method must be specified to add capabilities.',
523
+					'event_espresso'
524
+				)
525
+			);
526
+		}
527
+		if (empty($role)) {
528
+			throw new DomainException(
529
+				sprintf(
530
+					esc_html__(
531
+						'No role was supplied while trying to add capabilities for the %1$s payment method.',
532
+						'event_espresso'
533
+					),
534
+					$payment_method_name
535
+				)
536
+			);
537
+		}
538
+		if (! isset($payment_method_caps[ $role ])) {
539
+			$payment_method_caps[ $role ] = array();
540
+		}
541
+		$payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
542
+										  . strtolower($payment_method_name);
543
+		return $payment_method_caps;
544
+	}
545
+
546
+
547
+	/**
548
+	 * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter
549
+	 * to add dynamic payment method access caps when capabilities are reset
550
+	 * (or if that filter is called and PM caps are not already set)
551
+	 *
552
+	 * @param array $caps capabilities being filtered
553
+	 * @param bool  $reset
554
+	 * @return array
555
+	 * @throws DomainException
556
+	 */
557
+	public function addPaymentMethodCapsDuringReset(array $caps, $reset = false)
558
+	{
559
+		if ($reset || ! $this->payment_method_caps_initialized) {
560
+			$this->payment_method_caps_initialized = true;
561
+			$caps = array_merge_recursive($caps, $this->getPaymentMethodCaps());
562
+		}
563
+		return $caps;
564
+	}
565
+
566
+
567
+	/**
568
+	 * @deprecated 4.9.42
569
+	 * @param $caps
570
+	 * @return mixed
571
+	 */
572
+	public function add_payment_method_caps($caps)
573
+	{
574
+		return $caps;
575
+	}
576 576
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Recipient_Details_Shortcodes.lib.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -116,17 +116,17 @@  discard block
 block discarded – undo
116 116
             ? $this->_extra_data['data']
117 117
             : $this->_recipient;
118 118
 
119
-        if (! $this->_recipient instanceof EE_Messages_Addressee) {
119
+        if ( ! $this->_recipient instanceof EE_Messages_Addressee) {
120 120
             return '';
121 121
         }
122 122
 
123 123
         $attendee = $this->_recipient->att_obj;
124
-        if (! $attendee instanceof EE_Attendee) {
124
+        if ( ! $attendee instanceof EE_Attendee) {
125 125
             return '';
126 126
         }
127 127
 
128
-        $this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs'])
129
-            ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs']
128
+        $this->_registrations_for_recipient = isset($this->_recipient->attendees[$attendee->ID()]['reg_objs'])
129
+            ? $this->_recipient->attendees[$attendee->ID()]['reg_objs']
130 130
             : array();
131 131
 
132 132
         switch ($shortcode) {
@@ -143,21 +143,21 @@  discard block
 block discarded – undo
143 143
                 break;
144 144
 
145 145
             case '[RECIPIENT_REGISTRATION_ID]':
146
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
146
+                if ( ! $this->_recipient->reg_obj instanceof EE_Registration) {
147 147
                     return '';
148 148
                 }
149 149
                 return $this->_get_reg_id();
150 150
                 break;
151 151
 
152 152
             case '[RECIPIENT_REGISTRATION_CODE]':
153
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
153
+                if ( ! $this->_recipient->reg_obj instanceof EE_Registration) {
154 154
                     return '';
155 155
                 }
156 156
                 return $this->_get_reg_code();
157 157
                 break;
158 158
 
159 159
             case '[RECIPIENT_EDIT_REGISTRATION_LINK]':
160
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
160
+                if ( ! $this->_recipient->reg_obj instanceof EE_Registration) {
161 161
                     return '';
162 162
                 }
163 163
                 return $this->_recipient->reg_obj->edit_attendee_information_url();
@@ -213,9 +213,9 @@  discard block
 block discarded – undo
213 213
                 if (
214 214
                     $question instanceof EE_Question
215 215
                     && trim($question->display_text()) === trim($shortcode)
216
-                    && isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ])
216
+                    && isset($this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid])
217 217
                 ) {
218
-                    $recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ];
218
+                    $recipient_ansid = $this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid];
219 219
 
220 220
                     // what we show for the answer depends on the question type!
221 221
                     switch ($question->get('QST_type')) {
Please login to merge, or discard this patch.
Indentation   +351 added lines, -351 removed lines patch added patch discarded remove patch
@@ -18,355 +18,355 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Recipient_Details_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    protected $_recipient;
22
-
23
-    protected $_registrations_for_recipient;
24
-
25
-
26
-    protected function _init_props()
27
-    {
28
-        $this->label = esc_html__('Recipient Details Shortcodes', 'event_espresso');
29
-        $this->description = esc_html__('All shortcodes specific to recipient registration data', 'event_espresso');
30
-        $this->_shortcodes = array(
31
-            '[RECIPIENT_FNAME]'                  => esc_html__(
32
-                'Parses to the first name of the recipient for the message.',
33
-                'event_espresso'
34
-            ),
35
-            '[RECIPIENT_LNAME]'                  => esc_html__(
36
-                'Parses to the last name of the recipient for the message.',
37
-                'event_espresso'
38
-            ),
39
-            '[RECIPIENT_EMAIL]'                  => esc_html__(
40
-                'Parses to the email address of the recipient for the message.',
41
-                'event_espresso'
42
-            ),
43
-            '[RECIPIENT_REGISTRATION_ID]'        => esc_html__(
44
-                'Parses to the registration ID of the recipient for the message.',
45
-                'event_espresso'
46
-            ),
47
-            '[RECIPIENT_REGISTRATION_CODE]'      => esc_html__(
48
-                'Parses to the registration code of the recipient for the message.',
49
-                'event_espresso'
50
-            ),
51
-            '[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__(
52
-                'Parses to a link for frontend editing of the registration for the recipient.',
53
-                'event_espresso'
54
-            ),
55
-            '[RECIPIENT_PHONE_NUMBER]'           => esc_html__(
56
-                'The Phone Number for the recipient of the message.',
57
-                'event_espresso'
58
-            ),
59
-            '[RECIPIENT_ADDRESS]'                => esc_html__(
60
-                'The Address for the recipient of the message.',
61
-                'event_espresso'
62
-            ),
63
-            '[RECIPIENT_ADDRESS2]'               => esc_html__(
64
-                'Whatever was in the address 2 field for the recipient of the message.',
65
-                'event_espresso'
66
-            ),
67
-            '[RECIPIENT_CITY]'                   => esc_html__(
68
-                'The city for the recipient of the message.',
69
-                'event_espresso'
70
-            ),
71
-            '[RECIPIENT_ZIP_PC]'                 => esc_html__(
72
-                'The ZIP (or Postal) Code for the recipient of the message.',
73
-                'event_espresso'
74
-            ),
75
-            '[RECIPIENT_ADDRESS_STATE]'          => esc_html__(
76
-                'The state/province for the recipient of the message.',
77
-                'event_espresso'
78
-            ),
79
-            '[RECIPIENT_COUNTRY]'                => esc_html__(
80
-                'The country for the recipient of the message.',
81
-                'event_espresso'
82
-            ),
83
-            '[RECIPIENT_ANSWER_*]'               => esc_html__(
84
-                'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.',
85
-                'event_espresso'
86
-            ),
87
-            '[RECIPIENT_TOTAL_AMOUNT_PAID]'      => esc_html__(
88
-                'If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient.  Otherwise the value of 0 is printed.',
89
-                'event_espresso'
90
-            ),
91
-        );
92
-    }
93
-
94
-
95
-    /**
96
-     * @access protected
97
-     * @param  string $shortcode the shortcode to be parsed.
98
-     * @return string parsed shortcode
99
-     */
100
-    protected function _parser($shortcode)
101
-    {
102
-
103
-        // make sure we end up with a copy of the EE_Messages_Addressee object
104
-        $this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
105
-        $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
106
-                            && is_array($this->_data)
107
-                            && isset($this->_data['data'])
108
-                            && $this->_data['data'] instanceof EE_Messages_Addressee
109
-            ? $this->_data['data']
110
-            :
111
-            $this->_recipient;
112
-        $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
113
-                            && ! empty($this->_extra_data['data'])
114
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
115
-            ? $this->_extra_data['data']
116
-            : $this->_recipient;
117
-
118
-        if (! $this->_recipient instanceof EE_Messages_Addressee) {
119
-            return '';
120
-        }
121
-
122
-        $attendee = $this->_recipient->att_obj;
123
-        if (! $attendee instanceof EE_Attendee) {
124
-            return '';
125
-        }
126
-
127
-        $this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs'])
128
-            ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs']
129
-            : array();
130
-
131
-        switch ($shortcode) {
132
-            case '[RECIPIENT_FNAME]':
133
-                return $attendee->fname();
134
-                break;
135
-
136
-            case '[RECIPIENT_LNAME]':
137
-                return $attendee->lname();
138
-                break;
139
-
140
-            case '[RECIPIENT_EMAIL]':
141
-                return $attendee->email();
142
-                break;
143
-
144
-            case '[RECIPIENT_REGISTRATION_ID]':
145
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
146
-                    return '';
147
-                }
148
-                return $this->_get_reg_id();
149
-                break;
150
-
151
-            case '[RECIPIENT_REGISTRATION_CODE]':
152
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
153
-                    return '';
154
-                }
155
-                return $this->_get_reg_code();
156
-                break;
157
-
158
-            case '[RECIPIENT_EDIT_REGISTRATION_LINK]':
159
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
160
-                    return '';
161
-                }
162
-                return $this->_recipient->reg_obj->edit_attendee_information_url();
163
-                break;
164
-
165
-            case '[RECIPIENT_PHONE_NUMBER]':
166
-                return $attendee->phone();
167
-                break;
168
-
169
-            case '[RECIPIENT_ADDRESS]':
170
-                return $attendee->address();
171
-                break;
172
-
173
-            case '[RECIPIENT_ADDRESS2]':
174
-                return $attendee->address2();
175
-                break;
176
-
177
-            case '[RECIPIENT_CITY]':
178
-                return $attendee->city();
179
-                break;
180
-
181
-            case '[RECIPIENT_ZIP_PC]':
182
-                return $attendee->zip();
183
-                break;
184
-
185
-            case '[RECIPIENT_ADDRESS_STATE]':
186
-                $state_obj = $attendee->state_obj();
187
-                return $state_obj instanceof EE_State ? $state_obj->name() : '';
188
-                break;
189
-
190
-            case '[RECIPIENT_COUNTRY]':
191
-                $country_obj = $attendee->country_obj();
192
-                return $country_obj instanceof EE_Country ? $country_obj->name() : '';
193
-                break;
194
-            case '[RECIPIENT_TOTAL_AMOUNT_PAID]':
195
-                return $this->_recipient->reg_obj instanceof EE_Registration
196
-                    ? $this->_recipient->reg_obj->pretty_paid()
197
-                    : 0;
198
-                break;
199
-        }
200
-
201
-        if (strpos($shortcode, '[RECIPIENT_ANSWER_*') !== false) {
202
-            $shortcode = str_replace('[RECIPIENT_ANSWER_*', '', $shortcode);
203
-            $shortcode = trim(str_replace(']', '', $shortcode));
204
-
205
-
206
-            // now let's figure out what question has this text
207
-            if (empty($this->_recipient->questions) || ! $this->_recipient->reg_obj instanceof EE_Registration) {
208
-                return '';
209
-            }
210
-
211
-            foreach ($this->_recipient->questions as $ansid => $question) {
212
-                if (
213
-                    $question instanceof EE_Question
214
-                    && trim($question->display_text()) === trim($shortcode)
215
-                    && isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ])
216
-                ) {
217
-                    $recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ];
218
-
219
-                    // what we show for the answer depends on the question type!
220
-                    switch ($question->get('QST_type')) {
221
-                        case EEM_Question::QST_type_state:
222
-                            $state = EEM_State::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
223
-                            $answer = $state instanceof EE_State ? $state->name() : '';
224
-                            break;
225
-
226
-                        case EEM_Question::QST_type_country:
227
-                            $country = EEM_Country::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
228
-                            $answer = $country instanceof EE_Country ? $country->name() : '';
229
-                            break;
230
-
231
-                        default:
232
-                            $answer = $recipient_ansid->get_pretty('ANS_value', 'no_wpautop');
233
-                            break;
234
-                    }
235
-
236
-                    return $answer;
237
-                    break;
238
-                }
239
-            }
240
-        }
241
-
242
-        return '';
243
-    }
244
-
245
-
246
-    /**
247
-     * Returns the EE_Messages_Addressee object for the recipient.
248
-     *
249
-     * @since 4.5.0
250
-     *
251
-     * @return EE_Messages_Addressee
252
-     */
253
-    public function get_recipient()
254
-    {
255
-        return $this->_recipient;
256
-    }
257
-
258
-
259
-    /**
260
-     * returns the reg code for the recipient depending on the context and whether the recipient has multiple
261
-     * registrations or not.
262
-     *
263
-     * @return string
264
-     */
265
-    protected function _get_reg_code()
266
-    {
267
-
268
-        // if only one related registration for the recipient then just return that reg code.
269
-        if (count($this->_registrations_for_recipient) <= 1) {
270
-            return $this->_recipient->reg_obj->reg_code();
271
-        }
272
-
273
-        // k more than one registration so let's see if we can get specific to context
274
-        // are we parsing event_list?
275
-        if ($this->_data instanceof EE_Event) {
276
-            $reg_code = array();
277
-            // loop through registrations for recipient and see if there is a match for this event
278
-            foreach ($this->_registrations_for_recipient as $reg) {
279
-                if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
280
-                    $reg_code[] = $reg->reg_code();
281
-                }
282
-            }
283
-            return implode(', ', $reg_code);
284
-        }
285
-
286
-        // are we parsing ticket list?
287
-        if ($this->_data instanceof EE_Ticket) {
288
-            $reg_code = array();
289
-            // loop through each registration for recipient and see if there is a match for this ticket
290
-            foreach ($this->_registrations_for_recipient as $reg) {
291
-                if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
292
-                    $reg_code = $reg->reg_code();
293
-                }
294
-            }
295
-            return implode(', ', $reg_code);
296
-        }
297
-
298
-        // do we have a specific reg_obj?  Let's use it
299
-        if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
300
-            return $this->_data->reg_obj->reg_code();
301
-        }
302
-
303
-        // do we have a specific reg_obj?  Let's use it
304
-        if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
305
-            return $this->_data->reg_obj->reg_code();
306
-        }
307
-
308
-        // not able to determine the single reg code so let's return a comma delimited list of reg codes.
309
-        $reg_code = array();
310
-        foreach ($this->_registrations_for_recipient as $reg) {
311
-            if ($reg instanceof EE_Registration) {
312
-                $reg_code[] = $reg->reg_code();
313
-            }
314
-        }
315
-        return implode(', ', $reg_code);
316
-    }
317
-
318
-
319
-    /**
320
-     * returns the reg ID for the recipient depending on the context and whether the recipient has multiple
321
-     * registrations or not.
322
-     *
323
-     * @return int|string
324
-     */
325
-    protected function _get_reg_id()
326
-    {
327
-
328
-        // if only one related registration for the recipient then just return that reg code.
329
-        if (count($this->_registrations_for_recipient) <= 1) {
330
-            return $this->_recipient->reg_obj->ID();
331
-        }
332
-
333
-        // k more than one registration so let's see if we can get specific to context
334
-        // are we parsing event_list?
335
-        if ($this->_data instanceof EE_Event) {
336
-            $registration_ids = array();
337
-            // loop through registrations for recipient and see if there is a match for this event
338
-            foreach ($this->_registrations_for_recipient as $reg) {
339
-                if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
340
-                    $registration_ids[] = $reg->ID();
341
-                }
342
-            }
343
-            return implode(', ', $registration_ids);
344
-        }
345
-
346
-        // are we parsing ticket list?
347
-        if ($this->_data instanceof EE_Ticket) {
348
-            $registration_ids = array();
349
-            // loop through each registration for recipient and see if there is a match for this ticket
350
-            foreach ($this->_registrations_for_recipient as $reg) {
351
-                if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
352
-                    $registration_ids = $reg->ID();
353
-                }
354
-            }
355
-            return implode(', ', $registration_ids);
356
-        }
357
-
358
-        // do we have a specific reg_obj?  Let's use it
359
-        if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
360
-            return $this->_data->reg_obj->ID();
361
-        }
362
-
363
-        // not able to determine the single reg code so let's return a comma delimited list of reg codes.
364
-        $registration_ids = array();
365
-        foreach ($this->_registrations_for_recipient as $reg) {
366
-            if ($reg instanceof EE_Registration) {
367
-                $registration_ids[] = $reg->ID();
368
-            }
369
-        }
370
-        return implode(', ', $registration_ids);
371
-    }
21
+	protected $_recipient;
22
+
23
+	protected $_registrations_for_recipient;
24
+
25
+
26
+	protected function _init_props()
27
+	{
28
+		$this->label = esc_html__('Recipient Details Shortcodes', 'event_espresso');
29
+		$this->description = esc_html__('All shortcodes specific to recipient registration data', 'event_espresso');
30
+		$this->_shortcodes = array(
31
+			'[RECIPIENT_FNAME]'                  => esc_html__(
32
+				'Parses to the first name of the recipient for the message.',
33
+				'event_espresso'
34
+			),
35
+			'[RECIPIENT_LNAME]'                  => esc_html__(
36
+				'Parses to the last name of the recipient for the message.',
37
+				'event_espresso'
38
+			),
39
+			'[RECIPIENT_EMAIL]'                  => esc_html__(
40
+				'Parses to the email address of the recipient for the message.',
41
+				'event_espresso'
42
+			),
43
+			'[RECIPIENT_REGISTRATION_ID]'        => esc_html__(
44
+				'Parses to the registration ID of the recipient for the message.',
45
+				'event_espresso'
46
+			),
47
+			'[RECIPIENT_REGISTRATION_CODE]'      => esc_html__(
48
+				'Parses to the registration code of the recipient for the message.',
49
+				'event_espresso'
50
+			),
51
+			'[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__(
52
+				'Parses to a link for frontend editing of the registration for the recipient.',
53
+				'event_espresso'
54
+			),
55
+			'[RECIPIENT_PHONE_NUMBER]'           => esc_html__(
56
+				'The Phone Number for the recipient of the message.',
57
+				'event_espresso'
58
+			),
59
+			'[RECIPIENT_ADDRESS]'                => esc_html__(
60
+				'The Address for the recipient of the message.',
61
+				'event_espresso'
62
+			),
63
+			'[RECIPIENT_ADDRESS2]'               => esc_html__(
64
+				'Whatever was in the address 2 field for the recipient of the message.',
65
+				'event_espresso'
66
+			),
67
+			'[RECIPIENT_CITY]'                   => esc_html__(
68
+				'The city for the recipient of the message.',
69
+				'event_espresso'
70
+			),
71
+			'[RECIPIENT_ZIP_PC]'                 => esc_html__(
72
+				'The ZIP (or Postal) Code for the recipient of the message.',
73
+				'event_espresso'
74
+			),
75
+			'[RECIPIENT_ADDRESS_STATE]'          => esc_html__(
76
+				'The state/province for the recipient of the message.',
77
+				'event_espresso'
78
+			),
79
+			'[RECIPIENT_COUNTRY]'                => esc_html__(
80
+				'The country for the recipient of the message.',
81
+				'event_espresso'
82
+			),
83
+			'[RECIPIENT_ANSWER_*]'               => esc_html__(
84
+				'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.',
85
+				'event_espresso'
86
+			),
87
+			'[RECIPIENT_TOTAL_AMOUNT_PAID]'      => esc_html__(
88
+				'If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient.  Otherwise the value of 0 is printed.',
89
+				'event_espresso'
90
+			),
91
+		);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @access protected
97
+	 * @param  string $shortcode the shortcode to be parsed.
98
+	 * @return string parsed shortcode
99
+	 */
100
+	protected function _parser($shortcode)
101
+	{
102
+
103
+		// make sure we end up with a copy of the EE_Messages_Addressee object
104
+		$this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
105
+		$this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
106
+							&& is_array($this->_data)
107
+							&& isset($this->_data['data'])
108
+							&& $this->_data['data'] instanceof EE_Messages_Addressee
109
+			? $this->_data['data']
110
+			:
111
+			$this->_recipient;
112
+		$this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
113
+							&& ! empty($this->_extra_data['data'])
114
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
115
+			? $this->_extra_data['data']
116
+			: $this->_recipient;
117
+
118
+		if (! $this->_recipient instanceof EE_Messages_Addressee) {
119
+			return '';
120
+		}
121
+
122
+		$attendee = $this->_recipient->att_obj;
123
+		if (! $attendee instanceof EE_Attendee) {
124
+			return '';
125
+		}
126
+
127
+		$this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs'])
128
+			? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs']
129
+			: array();
130
+
131
+		switch ($shortcode) {
132
+			case '[RECIPIENT_FNAME]':
133
+				return $attendee->fname();
134
+				break;
135
+
136
+			case '[RECIPIENT_LNAME]':
137
+				return $attendee->lname();
138
+				break;
139
+
140
+			case '[RECIPIENT_EMAIL]':
141
+				return $attendee->email();
142
+				break;
143
+
144
+			case '[RECIPIENT_REGISTRATION_ID]':
145
+				if (! $this->_recipient->reg_obj instanceof EE_Registration) {
146
+					return '';
147
+				}
148
+				return $this->_get_reg_id();
149
+				break;
150
+
151
+			case '[RECIPIENT_REGISTRATION_CODE]':
152
+				if (! $this->_recipient->reg_obj instanceof EE_Registration) {
153
+					return '';
154
+				}
155
+				return $this->_get_reg_code();
156
+				break;
157
+
158
+			case '[RECIPIENT_EDIT_REGISTRATION_LINK]':
159
+				if (! $this->_recipient->reg_obj instanceof EE_Registration) {
160
+					return '';
161
+				}
162
+				return $this->_recipient->reg_obj->edit_attendee_information_url();
163
+				break;
164
+
165
+			case '[RECIPIENT_PHONE_NUMBER]':
166
+				return $attendee->phone();
167
+				break;
168
+
169
+			case '[RECIPIENT_ADDRESS]':
170
+				return $attendee->address();
171
+				break;
172
+
173
+			case '[RECIPIENT_ADDRESS2]':
174
+				return $attendee->address2();
175
+				break;
176
+
177
+			case '[RECIPIENT_CITY]':
178
+				return $attendee->city();
179
+				break;
180
+
181
+			case '[RECIPIENT_ZIP_PC]':
182
+				return $attendee->zip();
183
+				break;
184
+
185
+			case '[RECIPIENT_ADDRESS_STATE]':
186
+				$state_obj = $attendee->state_obj();
187
+				return $state_obj instanceof EE_State ? $state_obj->name() : '';
188
+				break;
189
+
190
+			case '[RECIPIENT_COUNTRY]':
191
+				$country_obj = $attendee->country_obj();
192
+				return $country_obj instanceof EE_Country ? $country_obj->name() : '';
193
+				break;
194
+			case '[RECIPIENT_TOTAL_AMOUNT_PAID]':
195
+				return $this->_recipient->reg_obj instanceof EE_Registration
196
+					? $this->_recipient->reg_obj->pretty_paid()
197
+					: 0;
198
+				break;
199
+		}
200
+
201
+		if (strpos($shortcode, '[RECIPIENT_ANSWER_*') !== false) {
202
+			$shortcode = str_replace('[RECIPIENT_ANSWER_*', '', $shortcode);
203
+			$shortcode = trim(str_replace(']', '', $shortcode));
204
+
205
+
206
+			// now let's figure out what question has this text
207
+			if (empty($this->_recipient->questions) || ! $this->_recipient->reg_obj instanceof EE_Registration) {
208
+				return '';
209
+			}
210
+
211
+			foreach ($this->_recipient->questions as $ansid => $question) {
212
+				if (
213
+					$question instanceof EE_Question
214
+					&& trim($question->display_text()) === trim($shortcode)
215
+					&& isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ])
216
+				) {
217
+					$recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ];
218
+
219
+					// what we show for the answer depends on the question type!
220
+					switch ($question->get('QST_type')) {
221
+						case EEM_Question::QST_type_state:
222
+							$state = EEM_State::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
223
+							$answer = $state instanceof EE_State ? $state->name() : '';
224
+							break;
225
+
226
+						case EEM_Question::QST_type_country:
227
+							$country = EEM_Country::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
228
+							$answer = $country instanceof EE_Country ? $country->name() : '';
229
+							break;
230
+
231
+						default:
232
+							$answer = $recipient_ansid->get_pretty('ANS_value', 'no_wpautop');
233
+							break;
234
+					}
235
+
236
+					return $answer;
237
+					break;
238
+				}
239
+			}
240
+		}
241
+
242
+		return '';
243
+	}
244
+
245
+
246
+	/**
247
+	 * Returns the EE_Messages_Addressee object for the recipient.
248
+	 *
249
+	 * @since 4.5.0
250
+	 *
251
+	 * @return EE_Messages_Addressee
252
+	 */
253
+	public function get_recipient()
254
+	{
255
+		return $this->_recipient;
256
+	}
257
+
258
+
259
+	/**
260
+	 * returns the reg code for the recipient depending on the context and whether the recipient has multiple
261
+	 * registrations or not.
262
+	 *
263
+	 * @return string
264
+	 */
265
+	protected function _get_reg_code()
266
+	{
267
+
268
+		// if only one related registration for the recipient then just return that reg code.
269
+		if (count($this->_registrations_for_recipient) <= 1) {
270
+			return $this->_recipient->reg_obj->reg_code();
271
+		}
272
+
273
+		// k more than one registration so let's see if we can get specific to context
274
+		// are we parsing event_list?
275
+		if ($this->_data instanceof EE_Event) {
276
+			$reg_code = array();
277
+			// loop through registrations for recipient and see if there is a match for this event
278
+			foreach ($this->_registrations_for_recipient as $reg) {
279
+				if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
280
+					$reg_code[] = $reg->reg_code();
281
+				}
282
+			}
283
+			return implode(', ', $reg_code);
284
+		}
285
+
286
+		// are we parsing ticket list?
287
+		if ($this->_data instanceof EE_Ticket) {
288
+			$reg_code = array();
289
+			// loop through each registration for recipient and see if there is a match for this ticket
290
+			foreach ($this->_registrations_for_recipient as $reg) {
291
+				if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
292
+					$reg_code = $reg->reg_code();
293
+				}
294
+			}
295
+			return implode(', ', $reg_code);
296
+		}
297
+
298
+		// do we have a specific reg_obj?  Let's use it
299
+		if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
300
+			return $this->_data->reg_obj->reg_code();
301
+		}
302
+
303
+		// do we have a specific reg_obj?  Let's use it
304
+		if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
305
+			return $this->_data->reg_obj->reg_code();
306
+		}
307
+
308
+		// not able to determine the single reg code so let's return a comma delimited list of reg codes.
309
+		$reg_code = array();
310
+		foreach ($this->_registrations_for_recipient as $reg) {
311
+			if ($reg instanceof EE_Registration) {
312
+				$reg_code[] = $reg->reg_code();
313
+			}
314
+		}
315
+		return implode(', ', $reg_code);
316
+	}
317
+
318
+
319
+	/**
320
+	 * returns the reg ID for the recipient depending on the context and whether the recipient has multiple
321
+	 * registrations or not.
322
+	 *
323
+	 * @return int|string
324
+	 */
325
+	protected function _get_reg_id()
326
+	{
327
+
328
+		// if only one related registration for the recipient then just return that reg code.
329
+		if (count($this->_registrations_for_recipient) <= 1) {
330
+			return $this->_recipient->reg_obj->ID();
331
+		}
332
+
333
+		// k more than one registration so let's see if we can get specific to context
334
+		// are we parsing event_list?
335
+		if ($this->_data instanceof EE_Event) {
336
+			$registration_ids = array();
337
+			// loop through registrations for recipient and see if there is a match for this event
338
+			foreach ($this->_registrations_for_recipient as $reg) {
339
+				if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
340
+					$registration_ids[] = $reg->ID();
341
+				}
342
+			}
343
+			return implode(', ', $registration_ids);
344
+		}
345
+
346
+		// are we parsing ticket list?
347
+		if ($this->_data instanceof EE_Ticket) {
348
+			$registration_ids = array();
349
+			// loop through each registration for recipient and see if there is a match for this ticket
350
+			foreach ($this->_registrations_for_recipient as $reg) {
351
+				if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
352
+					$registration_ids = $reg->ID();
353
+				}
354
+			}
355
+			return implode(', ', $registration_ids);
356
+		}
357
+
358
+		// do we have a specific reg_obj?  Let's use it
359
+		if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
360
+			return $this->_data->reg_obj->ID();
361
+		}
362
+
363
+		// not able to determine the single reg code so let's return a comma delimited list of reg codes.
364
+		$registration_ids = array();
365
+		foreach ($this->_registrations_for_recipient as $reg) {
366
+			if ($reg instanceof EE_Registration) {
367
+				$registration_ids[] = $reg->ID();
368
+			}
369
+		}
370
+		return implode(', ', $registration_ids);
371
+	}
372 372
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Event_Shortcodes.lib.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 
136 136
         // If there is no event objecdt by now then get out.
137
-        if (! $this->_event instanceof EE_Event) {
137
+        if ( ! $this->_event instanceof EE_Event) {
138 138
             return '';
139 139
         }
140 140
 
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
                 $image = $this->_event->feature_image_url(array(600, 300));
188 188
                 // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189 189
                 return ! empty($image)
190
-                    ? '<img src="' . $image . '" alt="'
190
+                    ? '<img src="'.$image.'" alt="'
191 191
                       . sprintf(
192 192
                           esc_attr__('%s Feature Image', 'event_espresso'),
193 193
                           $this->_event->get('EVT_name')
194
-                      ) . '" />'
194
+                      ).'" />'
195 195
                     : '';
196 196
                 break;
197 197
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
             // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
254 254
             if (
255 255
                 apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
256
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
256
+                || ! empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
257 257
             ) {
258 258
                 return do_shortcode($event_meta);
259 259
             }
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
 
272 272
         if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
273 273
             $attrs = $this->_get_shortcode_attrs($shortcode);
274
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
275
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
274
+            $width = empty($attrs['width']) ? '' : ' width="'.$attrs['width'].'"';
275
+            $height = empty($attrs['height']) ? '' : ' height="'.$attrs['height'].'"';
276 276
 
277 277
             // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
278
-            if (! empty($attrs['size'])) {
278
+            if ( ! empty($attrs['size'])) {
279 279
                 $size = explode(',', $attrs['size']);
280 280
                 if (count($size) === 1) {
281 281
                     $size = $size[0];
@@ -287,11 +287,11 @@  discard block
 block discarded – undo
287 287
             $image = $this->_event->feature_image_url($size);
288 288
 
289 289
             return ! empty($image)
290
-                ? '<img src="' . $image . '" alt="'
290
+                ? '<img src="'.$image.'" alt="'
291 291
                   . sprintf(
292 292
                       esc_attr__('%s Feature Image', 'event_espresso'),
293 293
                       $this->_event->get('EVT_name')
294
-                  ) . '"' . $width . $height . '/>'
294
+                  ).'"'.$width.$height.'/>'
295 295
                 : '';
296 296
         }
297 297
 
@@ -310,6 +310,6 @@  discard block
 block discarded – undo
310 310
     {
311 311
         $url = get_permalink($event->ID());
312 312
 
313
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
313
+        return $full_link ? '<a href="'.$url.'">'.$event->get('EVT_name').'</a>' : $url;
314 314
     }
315 315
 }
Please login to merge, or discard this patch.
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -17,297 +17,297 @@
 block discarded – undo
17 17
  */
18 18
 class EE_Event_Shortcodes extends EE_Shortcodes
19 19
 {
20
-    /**
21
-     * Will hold the EE_Event if available
22
-     *
23
-     * @var EE_Event
24
-     */
25
-    protected $_event;
26
-
27
-
28
-    public function __construct()
29
-    {
30
-        parent::__construct();
31
-    }
32
-
33
-
34
-    protected function _init_props()
35
-    {
36
-        $this->label = esc_html__('Event Shortcodes', 'event_espresso');
37
-        $this->description = esc_html__('All shortcodes specific to event related data', 'event_espresso');
38
-        $this->_shortcodes = array(
39
-            '[EVENT_ID]'                              => esc_html__(
40
-                'Will be replaced by the event ID of an event',
41
-                'event_espresso'
42
-            ),
43
-            '[EVENT]'                                 => esc_html__('The name of the event', 'event_espresso'),
44
-            '[EVENT_NAME]'                            => esc_html__(
45
-                "This also can be used for the name of the event",
46
-                'event_espresso'
47
-            ),
48
-            '[EVENT_PHONE]'                           => esc_html__(
49
-                'The phone number for the event (usually an info number)',
50
-                'event_espresso'
51
-            ),
52
-            '[EVENT_DESCRIPTION]'                     => esc_html__('The description of the event', 'event_espresso'),
53
-            '[EVENT_EXCERPT]'                         => esc_html__(
54
-                'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.',
55
-                'event_espresso'
56
-            ),
57
-            '[EVENT_LINK]'                            => esc_html__('A link associated with the event', 'event_espresso'),
58
-            '[EVENT_URL]'                             => esc_html__(
59
-                'A link to the event set up on the host site.',
60
-                'event_espresso'
61
-            ),
62
-            '[VIRTUAL_URL]'                           => esc_html__(
63
-                'What was used for the "URL of Event" field in the Venue settings',
64
-                'event_espresso'
65
-            ),
66
-            '[VIRTUAL_PHONE]'                         => esc_html__(
67
-                'An alternate phone number for the event. Typically used as a "call-in" number',
68
-                'event_espresso'
69
-            ),
70
-            '[EVENT_IMAGE]'                           => esc_html__(
71
-                'This will parse to the Feature image for the event.',
72
-                'event_espresso'
73
-            ),
74
-            '[EVENT_IMAGE_*]'                         => sprintf(
75
-                esc_html__(
76
-                    'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.',
77
-                    'event_espresso'
78
-                ),
79
-                '<code>',
80
-                '</code>'
81
-            ),
82
-            '[EVENT_TOTAL_AVAILABLE_SPACES_*]'        => sprintf(
83
-                esc_html__(
84
-                    'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event.  There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode).  %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.',
85
-                    'event_espresso'
86
-                ),
87
-                '<code>',
88
-                '</code>'
89
-            ),
90
-            '[EVENT_TOTAL_SPOTS_TAKEN]'               => esc_html__(
91
-                'This shortcode will parse to the output the total approved registrations for this event',
92
-                'event_espresso'
93
-            ),
94
-            '[EVENT_FACEBOOK_URL]'                    => esc_html__(
95
-                'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.',
96
-                'event_espresso'
97
-            ),
98
-            '[EVENT_TWITTER_URL]'                     => esc_html__(
99
-                'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url',
100
-                'event_espresso'
101
-            ),
102
-            '[EVENT_META_*]'                          => sprintf(
103
-                esc_html__(
104
-                    'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ',
105
-                    'event_espresso'
106
-                ),
107
-                '<code>',
108
-                '</code>'
109
-            ),
110
-            '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => esc_html__(
111
-                'This parses to the url for the registration list table filtered by registrations for this event.',
112
-                'event_espresso'
113
-            ),
114
-        );
115
-    }
116
-
117
-
118
-    protected function _parser($shortcode)
119
-    {
120
-
121
-
122
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
123
-
124
-        // if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
125
-        if (empty($this->_event)) {
126
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
127
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
128
-
129
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
130
-                ? $aee->reg_obj->event() : null;
131
-        }
132
-
133
-
134
-        // If there is no event objecdt by now then get out.
135
-        if (! $this->_event instanceof EE_Event) {
136
-            return '';
137
-        }
138
-
139
-        switch ($shortcode) {
140
-            case '[EVENT_ID]':
141
-                return $this->_event->ID();
142
-                break;
143
-
144
-            case '[EVENT]':
145
-            case '[EVENT_NAME]':
146
-                return $this->_event->get('EVT_name');
147
-                break;
148
-
149
-            case '[EVENT_PHONE]':
150
-                return $this->_event->get('EVT_phone');
151
-                break;
152
-
153
-            case '[EVENT_DESCRIPTION]':
154
-                return $this->_event->get('EVT_desc');
155
-                break;
156
-
157
-            case '[EVENT_EXCERPT]':
158
-                return $this->_event->get('EVT_short_desc');
159
-                break;
160
-
161
-            case '[EVENT_LINK]':
162
-                return $this->_get_event_link($this->_event);
163
-                break;
164
-
165
-            case '[EVENT_URL]':
166
-                return $this->_get_event_link($this->_event, false);
167
-                break;
168
-
169
-            case '[VIRTUAL_URL]':
170
-                $venue = $this->_event->get_first_related('Venue');
171
-                if (empty($venue)) {
172
-                    return '';
173
-                }
174
-                return $venue->get('VNU_virtual_url');
175
-
176
-            case '[VIRTUAL_PHONE]':
177
-                $venue = $this->_event->get_first_related('Venue');
178
-                if (empty($venue)) {
179
-                    return '';
180
-                }
181
-                return $venue->get('VNU_virtual_phone');
182
-                break;
183
-
184
-            case '[EVENT_IMAGE]':
185
-                $image = $this->_event->feature_image_url(array(600, 300));
186
-                // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
187
-                return ! empty($image)
188
-                    ? '<img src="' . $image . '" alt="'
189
-                      . sprintf(
190
-                          esc_attr__('%s Feature Image', 'event_espresso'),
191
-                          $this->_event->get('EVT_name')
192
-                      ) . '" />'
193
-                    : '';
194
-                break;
195
-
196
-            case '[EVENT_FACEBOOK_URL]':
197
-                $facebook_url = $this->_event->get_post_meta('event_facebook', true);
198
-                return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
199
-                    : $facebook_url;
200
-                break;
201
-
202
-            case '[EVENT_TWITTER_URL]':
203
-                $twitter_url = $this->_event->get_post_meta('event_twitter', true);
204
-                return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
205
-                    : $twitter_url;
206
-                break;
207
-
208
-            case '[EVENT_AUTHOR_EMAIL]':
209
-                $author_id = $this->_event->get('EVT_wp_user');
210
-                $user_data = get_userdata((int) $author_id);
211
-                return $user_data->user_email;
212
-                break;
213
-
214
-            case '[EVENT_TOTAL_SPOTS_TAKEN]':
215
-                return EEM_Registration::instance()->count(
216
-                    array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)),
217
-                    'REG_ID',
218
-                    true
219
-                );
220
-                break;
221
-
222
-            case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]':
223
-                return EEH_URL::add_query_args_and_nonce(
224
-                    array(
225
-                        'event_id' => $this->_event->ID(),
226
-                        'page'     => 'espresso_registrations',
227
-                        'action'   => 'default',
228
-                    ),
229
-                    admin_url('admin.php'),
230
-                    true
231
-                );
232
-                break;
233
-        }
234
-
235
-        if (strpos($shortcode, '[EVENT_META_*') !== false) {
236
-            // Strip the shortcode itself from $shortcode leaving any attributes set.
237
-            // Removing the * is correct here as _* is used to indiciate a dynamic shortcode.
238
-            $shortcode = str_replace('[EVENT_META_*', '', $shortcode);
239
-            $shortcode = trim(str_replace(']', '', $shortcode));
240
-            // Get any attributes set on this shortcode.
241
-            $attrs = $this->_get_shortcode_attrs($shortcode);
242
-            // The meta_key set on the shortcode should always be the first value in the array.
243
-            $meta_key = $attrs[0];
244
-            // Pull the meta value from the event post.
245
-            $event_meta = $this->_event->get_post_meta($meta_key, true);
246
-            // If we have no event_meta, just return an empty string.
247
-            if (empty($event_meta)) {
248
-                return '';
249
-            }
250
-            // Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
251
-            // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
252
-            if (
253
-                apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
254
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
255
-            ) {
256
-                return do_shortcode($event_meta);
257
-            }
258
-            // Still here? We just need to return the event_meta value as is.
259
-            return $event_meta;
260
-        }
261
-
262
-        if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
263
-            $attrs = $this->_get_shortcode_attrs($shortcode);
264
-            $method = empty($attrs['method']) ? 'current' : $attrs['method'];
265
-            $method = $method === 'current';
266
-            $available = $this->_event->total_available_spaces($method);
267
-            return $available === EE_INF ? '&infin;' : $available;
268
-        }
269
-
270
-        if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
271
-            $attrs = $this->_get_shortcode_attrs($shortcode);
272
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
273
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
274
-
275
-            // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
276
-            if (! empty($attrs['size'])) {
277
-                $size = explode(',', $attrs['size']);
278
-                if (count($size) === 1) {
279
-                    $size = $size[0];
280
-                }
281
-            } else {
282
-                $size = 'thumbnail';
283
-            }
284
-
285
-            $image = $this->_event->feature_image_url($size);
286
-
287
-            return ! empty($image)
288
-                ? '<img src="' . $image . '" alt="'
289
-                  . sprintf(
290
-                      esc_attr__('%s Feature Image', 'event_espresso'),
291
-                      $this->_event->get('EVT_name')
292
-                  ) . '"' . $width . $height . '/>'
293
-                : '';
294
-        }
295
-
296
-        return '';
297
-    }
298
-
299
-
300
-    /**
301
-     * returns the link to the event
302
-     *
303
-     * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
304
-     *                            Otherwise we just return the url of the event.
305
-     * @return string
306
-     */
307
-    private function _get_event_link($event, $full_link = true)
308
-    {
309
-        $url = get_permalink($event->ID());
310
-
311
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
312
-    }
20
+	/**
21
+	 * Will hold the EE_Event if available
22
+	 *
23
+	 * @var EE_Event
24
+	 */
25
+	protected $_event;
26
+
27
+
28
+	public function __construct()
29
+	{
30
+		parent::__construct();
31
+	}
32
+
33
+
34
+	protected function _init_props()
35
+	{
36
+		$this->label = esc_html__('Event Shortcodes', 'event_espresso');
37
+		$this->description = esc_html__('All shortcodes specific to event related data', 'event_espresso');
38
+		$this->_shortcodes = array(
39
+			'[EVENT_ID]'                              => esc_html__(
40
+				'Will be replaced by the event ID of an event',
41
+				'event_espresso'
42
+			),
43
+			'[EVENT]'                                 => esc_html__('The name of the event', 'event_espresso'),
44
+			'[EVENT_NAME]'                            => esc_html__(
45
+				"This also can be used for the name of the event",
46
+				'event_espresso'
47
+			),
48
+			'[EVENT_PHONE]'                           => esc_html__(
49
+				'The phone number for the event (usually an info number)',
50
+				'event_espresso'
51
+			),
52
+			'[EVENT_DESCRIPTION]'                     => esc_html__('The description of the event', 'event_espresso'),
53
+			'[EVENT_EXCERPT]'                         => esc_html__(
54
+				'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.',
55
+				'event_espresso'
56
+			),
57
+			'[EVENT_LINK]'                            => esc_html__('A link associated with the event', 'event_espresso'),
58
+			'[EVENT_URL]'                             => esc_html__(
59
+				'A link to the event set up on the host site.',
60
+				'event_espresso'
61
+			),
62
+			'[VIRTUAL_URL]'                           => esc_html__(
63
+				'What was used for the "URL of Event" field in the Venue settings',
64
+				'event_espresso'
65
+			),
66
+			'[VIRTUAL_PHONE]'                         => esc_html__(
67
+				'An alternate phone number for the event. Typically used as a "call-in" number',
68
+				'event_espresso'
69
+			),
70
+			'[EVENT_IMAGE]'                           => esc_html__(
71
+				'This will parse to the Feature image for the event.',
72
+				'event_espresso'
73
+			),
74
+			'[EVENT_IMAGE_*]'                         => sprintf(
75
+				esc_html__(
76
+					'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.',
77
+					'event_espresso'
78
+				),
79
+				'<code>',
80
+				'</code>'
81
+			),
82
+			'[EVENT_TOTAL_AVAILABLE_SPACES_*]'        => sprintf(
83
+				esc_html__(
84
+					'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event.  There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode).  %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.',
85
+					'event_espresso'
86
+				),
87
+				'<code>',
88
+				'</code>'
89
+			),
90
+			'[EVENT_TOTAL_SPOTS_TAKEN]'               => esc_html__(
91
+				'This shortcode will parse to the output the total approved registrations for this event',
92
+				'event_espresso'
93
+			),
94
+			'[EVENT_FACEBOOK_URL]'                    => esc_html__(
95
+				'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.',
96
+				'event_espresso'
97
+			),
98
+			'[EVENT_TWITTER_URL]'                     => esc_html__(
99
+				'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url',
100
+				'event_espresso'
101
+			),
102
+			'[EVENT_META_*]'                          => sprintf(
103
+				esc_html__(
104
+					'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ',
105
+					'event_espresso'
106
+				),
107
+				'<code>',
108
+				'</code>'
109
+			),
110
+			'[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => esc_html__(
111
+				'This parses to the url for the registration list table filtered by registrations for this event.',
112
+				'event_espresso'
113
+			),
114
+		);
115
+	}
116
+
117
+
118
+	protected function _parser($shortcode)
119
+	{
120
+
121
+
122
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
123
+
124
+		// if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
125
+		if (empty($this->_event)) {
126
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
127
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
128
+
129
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
130
+				? $aee->reg_obj->event() : null;
131
+		}
132
+
133
+
134
+		// If there is no event objecdt by now then get out.
135
+		if (! $this->_event instanceof EE_Event) {
136
+			return '';
137
+		}
138
+
139
+		switch ($shortcode) {
140
+			case '[EVENT_ID]':
141
+				return $this->_event->ID();
142
+				break;
143
+
144
+			case '[EVENT]':
145
+			case '[EVENT_NAME]':
146
+				return $this->_event->get('EVT_name');
147
+				break;
148
+
149
+			case '[EVENT_PHONE]':
150
+				return $this->_event->get('EVT_phone');
151
+				break;
152
+
153
+			case '[EVENT_DESCRIPTION]':
154
+				return $this->_event->get('EVT_desc');
155
+				break;
156
+
157
+			case '[EVENT_EXCERPT]':
158
+				return $this->_event->get('EVT_short_desc');
159
+				break;
160
+
161
+			case '[EVENT_LINK]':
162
+				return $this->_get_event_link($this->_event);
163
+				break;
164
+
165
+			case '[EVENT_URL]':
166
+				return $this->_get_event_link($this->_event, false);
167
+				break;
168
+
169
+			case '[VIRTUAL_URL]':
170
+				$venue = $this->_event->get_first_related('Venue');
171
+				if (empty($venue)) {
172
+					return '';
173
+				}
174
+				return $venue->get('VNU_virtual_url');
175
+
176
+			case '[VIRTUAL_PHONE]':
177
+				$venue = $this->_event->get_first_related('Venue');
178
+				if (empty($venue)) {
179
+					return '';
180
+				}
181
+				return $venue->get('VNU_virtual_phone');
182
+				break;
183
+
184
+			case '[EVENT_IMAGE]':
185
+				$image = $this->_event->feature_image_url(array(600, 300));
186
+				// @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
187
+				return ! empty($image)
188
+					? '<img src="' . $image . '" alt="'
189
+					  . sprintf(
190
+						  esc_attr__('%s Feature Image', 'event_espresso'),
191
+						  $this->_event->get('EVT_name')
192
+					  ) . '" />'
193
+					: '';
194
+				break;
195
+
196
+			case '[EVENT_FACEBOOK_URL]':
197
+				$facebook_url = $this->_event->get_post_meta('event_facebook', true);
198
+				return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
199
+					: $facebook_url;
200
+				break;
201
+
202
+			case '[EVENT_TWITTER_URL]':
203
+				$twitter_url = $this->_event->get_post_meta('event_twitter', true);
204
+				return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
205
+					: $twitter_url;
206
+				break;
207
+
208
+			case '[EVENT_AUTHOR_EMAIL]':
209
+				$author_id = $this->_event->get('EVT_wp_user');
210
+				$user_data = get_userdata((int) $author_id);
211
+				return $user_data->user_email;
212
+				break;
213
+
214
+			case '[EVENT_TOTAL_SPOTS_TAKEN]':
215
+				return EEM_Registration::instance()->count(
216
+					array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)),
217
+					'REG_ID',
218
+					true
219
+				);
220
+				break;
221
+
222
+			case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]':
223
+				return EEH_URL::add_query_args_and_nonce(
224
+					array(
225
+						'event_id' => $this->_event->ID(),
226
+						'page'     => 'espresso_registrations',
227
+						'action'   => 'default',
228
+					),
229
+					admin_url('admin.php'),
230
+					true
231
+				);
232
+				break;
233
+		}
234
+
235
+		if (strpos($shortcode, '[EVENT_META_*') !== false) {
236
+			// Strip the shortcode itself from $shortcode leaving any attributes set.
237
+			// Removing the * is correct here as _* is used to indiciate a dynamic shortcode.
238
+			$shortcode = str_replace('[EVENT_META_*', '', $shortcode);
239
+			$shortcode = trim(str_replace(']', '', $shortcode));
240
+			// Get any attributes set on this shortcode.
241
+			$attrs = $this->_get_shortcode_attrs($shortcode);
242
+			// The meta_key set on the shortcode should always be the first value in the array.
243
+			$meta_key = $attrs[0];
244
+			// Pull the meta value from the event post.
245
+			$event_meta = $this->_event->get_post_meta($meta_key, true);
246
+			// If we have no event_meta, just return an empty string.
247
+			if (empty($event_meta)) {
248
+				return '';
249
+			}
250
+			// Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
251
+			// Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
252
+			if (
253
+				apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
254
+				|| !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
255
+			) {
256
+				return do_shortcode($event_meta);
257
+			}
258
+			// Still here? We just need to return the event_meta value as is.
259
+			return $event_meta;
260
+		}
261
+
262
+		if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
263
+			$attrs = $this->_get_shortcode_attrs($shortcode);
264
+			$method = empty($attrs['method']) ? 'current' : $attrs['method'];
265
+			$method = $method === 'current';
266
+			$available = $this->_event->total_available_spaces($method);
267
+			return $available === EE_INF ? '&infin;' : $available;
268
+		}
269
+
270
+		if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
271
+			$attrs = $this->_get_shortcode_attrs($shortcode);
272
+			$width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
273
+			$height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
274
+
275
+			// Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
276
+			if (! empty($attrs['size'])) {
277
+				$size = explode(',', $attrs['size']);
278
+				if (count($size) === 1) {
279
+					$size = $size[0];
280
+				}
281
+			} else {
282
+				$size = 'thumbnail';
283
+			}
284
+
285
+			$image = $this->_event->feature_image_url($size);
286
+
287
+			return ! empty($image)
288
+				? '<img src="' . $image . '" alt="'
289
+				  . sprintf(
290
+					  esc_attr__('%s Feature Image', 'event_espresso'),
291
+					  $this->_event->get('EVT_name')
292
+				  ) . '"' . $width . $height . '/>'
293
+				: '';
294
+		}
295
+
296
+		return '';
297
+	}
298
+
299
+
300
+	/**
301
+	 * returns the link to the event
302
+	 *
303
+	 * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
304
+	 *                            Otherwise we just return the url of the event.
305
+	 * @return string
306
+	 */
307
+	private function _get_event_link($event, $full_link = true)
308
+	{
309
+		$url = get_permalink($event->ID());
310
+
311
+		return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
312
+	}
313 313
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Primary_Registration_List_Shortcodes.lib.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data, $primary = false)
84 84
     {
85 85
         $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
86
-        if (! $registration instanceof EE_Registration) {
86
+        if ( ! $registration instanceof EE_Registration) {
87 87
             return '';
88 88
         }
89 89
         // setup valid shortcodes depending on what the status of the $this->_data property is
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
                 'attendee',
98 98
             );
99 99
             $template = $this->_data['template'];
100
-            $tkts = array($data->registrations[ $registration->ID() ]['tkt_obj']);
100
+            $tkts = array($data->registrations[$registration->ID()]['tkt_obj']);
101 101
             $data = $this->_data;
102 102
         } elseif ($this->_data['data'] instanceof EE_Event) {
103 103
             $valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee');
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 
128 128
     private function _get_tickets_from_event(EE_Event $event, $reg = null)
129 129
     {
130
-        $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
131
-        ) ]['tkt_objs'] : array();
130
+        $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID(
131
+        )]['tkt_objs'] : array();
132 132
 
133 133
         if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
134 134
             $adj_tkts = array();
135 135
             // return only tickets for the given attendee
136 136
             foreach ($evt_tkts as $tkt) {
137 137
                 if (
138
-                    isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
139
-                    && $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
138
+                    isset($this->_extra_data['data']->registrations[$reg->ID()]['tkt_obj'])
139
+                    && $this->_extra_data['data']->registrations[$reg->ID()]['tkt_obj']->ID() == $tkt->ID()
140 140
                 ) {
141 141
                     $adj_tkts[] = $tkt;
142 142
                 }
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
     private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
173 173
     {
174 174
         $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
175
-        if (! $registration instanceof EE_Registration) {
175
+        if ( ! $registration instanceof EE_Registration) {
176 176
             return '';
177 177
         }
178 178
         // setup valid shortcodes depending on what the status of the $this->_data property is
179 179
         if ($this->_data['data'] instanceof EE_Messages_Addressee) {
180 180
             $valid_shortcodes = array('datetime', 'attendee');
181 181
             $template = $this->_data['template'];
182
-            $dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
182
+            $dtts = $data->registrations[$registration->ID()]['dtt_objs'];
183 183
             $data = $this->_data;
184 184
         } elseif ($this->_data['data'] instanceof EE_Event) {
185 185
             $valid_shortcodes = array('datetime', 'attendee');
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
 
207 207
     private function _get_datetimes_from_event(EE_Event $event, $reg = null)
208 208
     {
209
-        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
210
-        ) ]['dtt_objs'] : array();
209
+        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID(
210
+        )]['dtt_objs'] : array();
211 211
 
212 212
         if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
213 213
             $adj_dtts = array();
214 214
             // return only dtts for the given attendee
215 215
             foreach ($evt_dtts as $dtt) {
216
-                if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
216
+                if (isset($this->_extra_data['data']->registrations[$reg->ID()]['dtt_objs'][$dtt->ID()])) {
217 217
                     $adj_dtts[] = $dtt;
218 218
                 }
219 219
             }
Please login to merge, or discard this patch.
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -18,206 +18,206 @@
 block discarded – undo
18 18
  */
19 19
 class EE_Primary_Registration_List_Shortcodes extends EE_Shortcodes
20 20
 {
21
-    public function __construct()
22
-    {
23
-        parent::__construct();
24
-    }
25
-
26
-
27
-    protected function _init_props()
28
-    {
29
-        $this->label = esc_html__('Primary Registrant List Shortcodes', 'event_espresso');
30
-        $this->description = esc_html__(
31
-            'All shortcodes specific primary registrant recipients list type data.',
32
-            'event_espresso'
33
-        );
34
-        $this->_shortcodes = array(
35
-            '[PRIMARY_REGISTRANT_TICKET_LIST]' => esc_html__(
36
-                'Will output a list of tickets that the primary registration received.',
37
-                'event_espresso'
38
-            ),
39
-            '[PRIMARY_REGISTRANT_DATETIME_LIST]' => esc_html__(
40
-                'Will output a list of datetimes that the primary registrant for the transaction has been registered for.',
41
-                'event_espresso'
42
-            ),
43
-        );
44
-    }
45
-
46
-
47
-    protected function _parser($shortcode)
48
-    {
49
-        switch ($shortcode) {
50
-            case '[PRIMARY_REGISTRANT_TICKET_LIST]':
51
-                return $this->_get_recipient_ticket_list(true);
52
-                break;
53
-
54
-            case '[PRIMARY_REGISTRANT_DATETIME_LIST]':
55
-                return $this->_get_recipient_datetime_list(true);
56
-                break;
57
-        }
58
-        return '';
59
-    }
60
-
61
-
62
-    /**
63
-     * figure out what the incoming data is and then return the appropriate parsed value
64
-     *
65
-     * @param  boolean $primary whether we're getting the primary registrant ticket_list.
66
-     * @return string
67
-     */
68
-    private function _get_recipient_ticket_list($primary = false)
69
-    {
70
-        $this->_validate_list_requirements();
71
-
72
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
73
-            return $this->_get_recipient_ticket_list_parsed($this->_data['data'], $primary);
74
-        } elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
75
-            return $this->_get_recipient_ticket_list_parsed($this->_extra_data['data'], $primary);
76
-        } else {
77
-            return '';
78
-        }
79
-    }
80
-
81
-
82
-    private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data, $primary = false)
83
-    {
84
-        $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
85
-        if (! $registration instanceof EE_Registration) {
86
-            return '';
87
-        }
88
-        // setup valid shortcodes depending on what the status of the $this->_data property is
89
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
90
-            $valid_shortcodes = array(
91
-                'ticket',
92
-                'event_list',
93
-                'attendee_list',
94
-                'datetime_list',
95
-                'registration_details',
96
-                'attendee',
97
-            );
98
-            $template = $this->_data['template'];
99
-            $tkts = array($data->registrations[ $registration->ID() ]['tkt_obj']);
100
-            $data = $this->_data;
101
-        } elseif ($this->_data['data'] instanceof EE_Event) {
102
-            $valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee');
103
-            $template = is_array($this->_data['template']) && isset($this->_data['template']['ticket_list'])
104
-                ? $this->_data['template']['ticket_list'] : $this->_extra_data['template']['ticket_list'];
105
-            // let's remove any existing [EVENT_LIST] shortcode from the ticket list template so that we don't get recursion.
106
-            $template = str_replace('[EVENT_LIST]', '', $template);
107
-            // data will be tickets for this event for this recipient.
108
-            $tkts = $this->_get_tickets_from_event($this->_data['data'], $registration);
109
-            $data = $this->_extra_data;
110
-        } else {
111
-            return '';
112
-        }
113
-
114
-        $tktparsed = '';
115
-        foreach ($tkts as $ticket) {
116
-            $tktparsed .= $this->_shortcode_helper->parse_ticket_list_template(
117
-                $template,
118
-                $ticket,
119
-                $valid_shortcodes,
120
-                $data
121
-            );
122
-        }
123
-        return $tktparsed;
124
-    }
125
-
126
-
127
-    private function _get_tickets_from_event(EE_Event $event, $reg = null)
128
-    {
129
-        $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
130
-        ) ]['tkt_objs'] : array();
131
-
132
-        if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
133
-            $adj_tkts = array();
134
-            // return only tickets for the given attendee
135
-            foreach ($evt_tkts as $tkt) {
136
-                if (
137
-                    isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
138
-                    && $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
139
-                ) {
140
-                    $adj_tkts[] = $tkt;
141
-                }
142
-            }
143
-            $evt_tkts = $adj_tkts;
144
-        }
145
-        return $evt_tkts;
146
-    }
147
-
148
-
149
-    /**
150
-     * figure out what the incoming data is and then return the appropriate parsed value
151
-     *
152
-     * @param  boolean $primary whether we're getting the primary registrant ticket_list.
153
-     * @return string
154
-     */
155
-    private function _get_recipient_datetime_list($primary = false)
156
-    {
157
-        $this->_validate_list_requirements();
158
-
159
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
160
-            return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
161
-        } elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
162
-            return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data'], $primary);
163
-        } else {
164
-            return '';
165
-        }
166
-
167
-        return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
168
-    }
169
-
170
-
171
-    private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
172
-    {
173
-        $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
174
-        if (! $registration instanceof EE_Registration) {
175
-            return '';
176
-        }
177
-        // setup valid shortcodes depending on what the status of the $this->_data property is
178
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
179
-            $valid_shortcodes = array('datetime', 'attendee');
180
-            $template = $this->_data['template'];
181
-            $dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
182
-            $data = $this->_data;
183
-        } elseif ($this->_data['data'] instanceof EE_Event) {
184
-            $valid_shortcodes = array('datetime', 'attendee');
185
-            $template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
186
-                ? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
187
-            $dtts = $this->_get_datetimes_from_event($this->_data['data'], $registration);
188
-            $data = $this->_extra_data;
189
-        } else {
190
-            return '';
191
-        }
192
-
193
-        $dtt_parsed = '';
194
-        foreach ($dtts as $datetime) {
195
-            $dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
196
-                $template,
197
-                $datetime,
198
-                $valid_shortcodes,
199
-                $this->_extra_data
200
-            );
201
-        }
202
-        return $dtt_parsed;
203
-    }
204
-
205
-
206
-    private function _get_datetimes_from_event(EE_Event $event, $reg = null)
207
-    {
208
-        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
209
-        ) ]['dtt_objs'] : array();
210
-
211
-        if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
212
-            $adj_dtts = array();
213
-            // return only dtts for the given attendee
214
-            foreach ($evt_dtts as $dtt) {
215
-                if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
216
-                    $adj_dtts[] = $dtt;
217
-                }
218
-            }
219
-            $evt_dtts = $adj_dtts;
220
-        }
221
-        return $evt_dtts;
222
-    }
21
+	public function __construct()
22
+	{
23
+		parent::__construct();
24
+	}
25
+
26
+
27
+	protected function _init_props()
28
+	{
29
+		$this->label = esc_html__('Primary Registrant List Shortcodes', 'event_espresso');
30
+		$this->description = esc_html__(
31
+			'All shortcodes specific primary registrant recipients list type data.',
32
+			'event_espresso'
33
+		);
34
+		$this->_shortcodes = array(
35
+			'[PRIMARY_REGISTRANT_TICKET_LIST]' => esc_html__(
36
+				'Will output a list of tickets that the primary registration received.',
37
+				'event_espresso'
38
+			),
39
+			'[PRIMARY_REGISTRANT_DATETIME_LIST]' => esc_html__(
40
+				'Will output a list of datetimes that the primary registrant for the transaction has been registered for.',
41
+				'event_espresso'
42
+			),
43
+		);
44
+	}
45
+
46
+
47
+	protected function _parser($shortcode)
48
+	{
49
+		switch ($shortcode) {
50
+			case '[PRIMARY_REGISTRANT_TICKET_LIST]':
51
+				return $this->_get_recipient_ticket_list(true);
52
+				break;
53
+
54
+			case '[PRIMARY_REGISTRANT_DATETIME_LIST]':
55
+				return $this->_get_recipient_datetime_list(true);
56
+				break;
57
+		}
58
+		return '';
59
+	}
60
+
61
+
62
+	/**
63
+	 * figure out what the incoming data is and then return the appropriate parsed value
64
+	 *
65
+	 * @param  boolean $primary whether we're getting the primary registrant ticket_list.
66
+	 * @return string
67
+	 */
68
+	private function _get_recipient_ticket_list($primary = false)
69
+	{
70
+		$this->_validate_list_requirements();
71
+
72
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
73
+			return $this->_get_recipient_ticket_list_parsed($this->_data['data'], $primary);
74
+		} elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
75
+			return $this->_get_recipient_ticket_list_parsed($this->_extra_data['data'], $primary);
76
+		} else {
77
+			return '';
78
+		}
79
+	}
80
+
81
+
82
+	private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data, $primary = false)
83
+	{
84
+		$registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
85
+		if (! $registration instanceof EE_Registration) {
86
+			return '';
87
+		}
88
+		// setup valid shortcodes depending on what the status of the $this->_data property is
89
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
90
+			$valid_shortcodes = array(
91
+				'ticket',
92
+				'event_list',
93
+				'attendee_list',
94
+				'datetime_list',
95
+				'registration_details',
96
+				'attendee',
97
+			);
98
+			$template = $this->_data['template'];
99
+			$tkts = array($data->registrations[ $registration->ID() ]['tkt_obj']);
100
+			$data = $this->_data;
101
+		} elseif ($this->_data['data'] instanceof EE_Event) {
102
+			$valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee');
103
+			$template = is_array($this->_data['template']) && isset($this->_data['template']['ticket_list'])
104
+				? $this->_data['template']['ticket_list'] : $this->_extra_data['template']['ticket_list'];
105
+			// let's remove any existing [EVENT_LIST] shortcode from the ticket list template so that we don't get recursion.
106
+			$template = str_replace('[EVENT_LIST]', '', $template);
107
+			// data will be tickets for this event for this recipient.
108
+			$tkts = $this->_get_tickets_from_event($this->_data['data'], $registration);
109
+			$data = $this->_extra_data;
110
+		} else {
111
+			return '';
112
+		}
113
+
114
+		$tktparsed = '';
115
+		foreach ($tkts as $ticket) {
116
+			$tktparsed .= $this->_shortcode_helper->parse_ticket_list_template(
117
+				$template,
118
+				$ticket,
119
+				$valid_shortcodes,
120
+				$data
121
+			);
122
+		}
123
+		return $tktparsed;
124
+	}
125
+
126
+
127
+	private function _get_tickets_from_event(EE_Event $event, $reg = null)
128
+	{
129
+		$evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
130
+		) ]['tkt_objs'] : array();
131
+
132
+		if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
133
+			$adj_tkts = array();
134
+			// return only tickets for the given attendee
135
+			foreach ($evt_tkts as $tkt) {
136
+				if (
137
+					isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
138
+					&& $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
139
+				) {
140
+					$adj_tkts[] = $tkt;
141
+				}
142
+			}
143
+			$evt_tkts = $adj_tkts;
144
+		}
145
+		return $evt_tkts;
146
+	}
147
+
148
+
149
+	/**
150
+	 * figure out what the incoming data is and then return the appropriate parsed value
151
+	 *
152
+	 * @param  boolean $primary whether we're getting the primary registrant ticket_list.
153
+	 * @return string
154
+	 */
155
+	private function _get_recipient_datetime_list($primary = false)
156
+	{
157
+		$this->_validate_list_requirements();
158
+
159
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
160
+			return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
161
+		} elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
162
+			return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data'], $primary);
163
+		} else {
164
+			return '';
165
+		}
166
+
167
+		return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
168
+	}
169
+
170
+
171
+	private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
172
+	{
173
+		$registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
174
+		if (! $registration instanceof EE_Registration) {
175
+			return '';
176
+		}
177
+		// setup valid shortcodes depending on what the status of the $this->_data property is
178
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
179
+			$valid_shortcodes = array('datetime', 'attendee');
180
+			$template = $this->_data['template'];
181
+			$dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
182
+			$data = $this->_data;
183
+		} elseif ($this->_data['data'] instanceof EE_Event) {
184
+			$valid_shortcodes = array('datetime', 'attendee');
185
+			$template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
186
+				? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
187
+			$dtts = $this->_get_datetimes_from_event($this->_data['data'], $registration);
188
+			$data = $this->_extra_data;
189
+		} else {
190
+			return '';
191
+		}
192
+
193
+		$dtt_parsed = '';
194
+		foreach ($dtts as $datetime) {
195
+			$dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
196
+				$template,
197
+				$datetime,
198
+				$valid_shortcodes,
199
+				$this->_extra_data
200
+			);
201
+		}
202
+		return $dtt_parsed;
203
+	}
204
+
205
+
206
+	private function _get_datetimes_from_event(EE_Event $event, $reg = null)
207
+	{
208
+		$evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
209
+		) ]['dtt_objs'] : array();
210
+
211
+		if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
212
+			$adj_dtts = array();
213
+			// return only dtts for the given attendee
214
+			foreach ($evt_dtts as $dtt) {
215
+				if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
216
+					$adj_dtts[] = $dtt;
217
+				}
218
+			}
219
+			$evt_dtts = $adj_dtts;
220
+		}
221
+		return $evt_dtts;
222
+	}
223 223
 }
Please login to merge, or discard this patch.
libraries/shortcodes/EE_Primary_Registration_Details_Shortcodes.lib.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
         $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
100 100
             ? $this->_extra_data['data'] : $primary_registration;
101 101
 
102
-        if (! $primary_registration instanceof EE_Messages_Addressee) {
102
+        if ( ! $primary_registration instanceof EE_Messages_Addressee) {
103 103
             return '';
104 104
         }
105 105
 
106 106
         $attendee = $primary_registration->primary_att_obj;
107 107
         $primary_reg = $primary_registration->primary_reg_obj;
108 108
 
109
-        if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
109
+        if ( ! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
110 110
             return '';
111 111
         }
112 112
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
                 break;
163 163
 
164 164
             case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]':
165
-                if (! $primary_registration->primary_reg_obj instanceof EE_Registration) {
165
+                if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration) {
166 166
                     return '';
167 167
                 }
168 168
                 return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format'));
@@ -187,9 +187,9 @@  discard block
 block discarded – undo
187 187
                 if (
188 188
                     $question instanceof EE_Question
189 189
                     && trim($question->get('QST_display_text')) === trim($shortcode)
190
-                    && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ])
190
+                    && isset($primary_registration->registrations[$primary_reg->ID()]['ans_objs'][$ansid])
191 191
                 ) {
192
-                    $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ];
192
+                    $primary_reg_ansid = $primary_registration->registrations[$primary_reg->ID()]['ans_objs'][$ansid];
193 193
 
194 194
                     // what we show for the answer depends on the question type!
195 195
                     switch ($question->get('QST_type')) {
Please login to merge, or discard this patch.
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -17,201 +17,201 @@
 block discarded – undo
17 17
  */
18 18
 class EE_Primary_Registration_Details_Shortcodes extends EE_Shortcodes
19 19
 {
20
-    protected function _init_props()
21
-    {
22
-        $this->label = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso');
23
-        $this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso');
24
-        $this->_shortcodes = array(
25
-            '[PRIMARY_REGISTRANT_FNAME]'                  => esc_html__(
26
-                'Parses to the first name of the primary registration for the transaction.',
27
-                'event_espresso'
28
-            ),
29
-            '[PRIMARY_REGISTRANT_LNAME]'                  => esc_html__(
30
-                'Parses to the last name of the primary registration for the transaction.',
31
-                'event_espresso'
32
-            ),
33
-            '[PRIMARY_REGISTRANT_EMAIL]'                  => esc_html__(
34
-                'Parses to the email address of the primary registration for the transaction.',
35
-                'event_espresso'
36
-            ),
37
-            '[PRIMARY_REGISTRANT_REGISTRATION_ID]'        => esc_html__(
38
-                'Parses to the registration ID of the primary registrant for the transaction.',
39
-                'event_espresso'
40
-            ),
41
-            '[PRIMARY_REGISTRANT_REGISTRATION_CODE]'      => esc_html__(
42
-                'Parses to the registration code of the primary registrant for the transaction.',
43
-                'event_espresso'
44
-            ),
45
-            '[PRIMARY_REGISTRANT_PHONE_NUMBER]'           => esc_html__(
46
-                'The Phone Number for the primary registrant for the transaction.',
47
-                'event_espresso'
48
-            ),
49
-            '[PRIMARY_REGISTRANT_ADDRESS]'                => esc_html__(
50
-                'The Address for the primary registrant for the transaction.',
51
-                'event_espresso'
52
-            ),
53
-            '[PRIMARY_REGISTRANT_ADDRESS2]'               => esc_html__(
54
-                'Whatever was in the address 2 field for the primary registrant for the transaction.',
55
-                'event_espresso'
56
-            ),
57
-            '[PRIMARY_REGISTRANT_CITY]'                   => esc_html__(
58
-                'The city for the primary registrant for the transaction.',
59
-                'event_espresso'
60
-            ),
61
-            '[PRIMARY_REGISTRANT_ZIP_PC]'                 => esc_html__(
62
-                'The ZIP (or Postal) Code for the primary registrant for the transaction.',
63
-                'event_espresso'
64
-            ),
65
-            '[PRIMARY_REGISTRANT_ADDRESS_STATE]'          => esc_html__(
66
-                'The state/province for the primary registrant for the transaction.',
67
-                'event_espresso'
68
-            ),
69
-            '[PRIMARY_REGISTRANT_COUNTRY]'                => esc_html__(
70
-                'The country for the primary registrant for the transaction.',
71
-                'event_espresso'
72
-            ),
73
-            '[PRIMARY_REGISTRANT_REGISTRATION_DATE]'      => esc_html__(
74
-                'The date the registration occured for the primary registration.',
75
-                'event_espresso'
76
-            ),
77
-            '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__(
78
-                'Generates a link for the given registration to edit this registration details on the frontend.',
79
-                'event_espresso'
80
-            ),
81
-            '[PRIMARY_REGISTRANT_ANSWER_*]'               => esc_html__(
82
-                'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.',
83
-                'event_espresso'
84
-            ),
85
-        );
86
-    }
87
-
88
-
89
-    protected function _parser($shortcode)
90
-    {
91
-        // make sure we end up with a copy of the EE_Messages_Addressee object
92
-        $primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
93
-        $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && is_array(
94
-            $this->_data
95
-        ) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data']
96
-            : $primary_registration;
97
-        $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
98
-            ? $this->_extra_data['data'] : $primary_registration;
99
-
100
-        if (! $primary_registration instanceof EE_Messages_Addressee) {
101
-            return '';
102
-        }
103
-
104
-        $attendee = $primary_registration->primary_att_obj;
105
-        $primary_reg = $primary_registration->primary_reg_obj;
106
-
107
-        if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
108
-            return '';
109
-        }
110
-
111
-        switch ($shortcode) {
112
-            case '[PRIMARY_REGISTRANT_FNAME]':
113
-                return $attendee->fname();
114
-                break;
115
-
116
-            case '[PRIMARY_REGISTRANT_LNAME]':
117
-                return $attendee->lname();
118
-                break;
119
-
120
-            case '[PRIMARY_REGISTRANT_EMAIL]':
121
-                return $attendee->email();
122
-                break;
123
-
124
-            case '[PRIMARY_REGISTRANT_REGISTRATION_ID]':
125
-                return $primary_reg->ID();
126
-                break;
127
-
128
-            case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]':
129
-                return $primary_reg->reg_code();
130
-                break;
131
-
132
-            case '[PRIMARY_REGISTRANT_PHONE_NUMBER]':
133
-                return $attendee->phone();
134
-                break;
135
-
136
-            case '[PRIMARY_REGISTRANT_ADDRESS]':
137
-                return $attendee->address();
138
-                break;
139
-
140
-            case '[PRIMARY_REGISTRANT_ADDRESS2]':
141
-                return $attendee->address2();
142
-                break;
143
-
144
-            case '[PRIMARY_REGISTRANT_CITY]':
145
-                return $attendee->city();
146
-                break;
147
-
148
-            case '[PRIMARY_REGISTRANT_ZIP_PC]':
149
-                return $attendee->zip();
150
-                break;
151
-
152
-            case '[PRIMARY_REGISTRANT_ADDRESS_STATE]':
153
-                $state_obj = $attendee->state_obj();
154
-                return $state_obj instanceof EE_State ? $state_obj->name() : '';
155
-                break;
156
-
157
-            case '[PRIMARY_REGISTRANT_COUNTRY]':
158
-                $country_obj = $attendee->country_obj();
159
-                return $country_obj instanceof EE_Country ? $country_obj->name() : '';
160
-                break;
161
-
162
-            case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]':
163
-                if (! $primary_registration->primary_reg_obj instanceof EE_Registration) {
164
-                    return '';
165
-                }
166
-                return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format'));
167
-                break;
168
-
169
-            case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]':
170
-                return $primary_reg->edit_attendee_information_url();
171
-                break;
172
-        }
173
-
174
-        if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) {
175
-            $shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode);
176
-            $shortcode = trim(str_replace(']', '', $shortcode));
177
-
178
-
179
-            // now let's figure out what question has this text
180
-            if (empty($primary_registration->questions)) {
181
-                return '';
182
-            }
183
-
184
-            foreach ($primary_registration->questions as $ansid => $question) {
185
-                if (
186
-                    $question instanceof EE_Question
187
-                    && trim($question->get('QST_display_text')) === trim($shortcode)
188
-                    && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ])
189
-                ) {
190
-                    $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ];
191
-
192
-                    // what we show for the answer depends on the question type!
193
-                    switch ($question->get('QST_type')) {
194
-                        case EEM_Question::QST_type_state:
195
-                            $state = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
196
-                            $answer = $state instanceof EE_State ? $state->name() : '';
197
-                            break;
198
-
199
-                        case EEM_Question::QST_type_country:
200
-                            $country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
201
-                            $answer = $country instanceof EE_Country ? $country->name() : '';
202
-                            break;
203
-
204
-                        default:
205
-                            $answer = $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop');
206
-                            break;
207
-                    }
208
-
209
-                    return $answer;
210
-                    break;
211
-                }
212
-            }
213
-        }
214
-
215
-        return '';
216
-    }
20
+	protected function _init_props()
21
+	{
22
+		$this->label = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso');
23
+		$this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso');
24
+		$this->_shortcodes = array(
25
+			'[PRIMARY_REGISTRANT_FNAME]'                  => esc_html__(
26
+				'Parses to the first name of the primary registration for the transaction.',
27
+				'event_espresso'
28
+			),
29
+			'[PRIMARY_REGISTRANT_LNAME]'                  => esc_html__(
30
+				'Parses to the last name of the primary registration for the transaction.',
31
+				'event_espresso'
32
+			),
33
+			'[PRIMARY_REGISTRANT_EMAIL]'                  => esc_html__(
34
+				'Parses to the email address of the primary registration for the transaction.',
35
+				'event_espresso'
36
+			),
37
+			'[PRIMARY_REGISTRANT_REGISTRATION_ID]'        => esc_html__(
38
+				'Parses to the registration ID of the primary registrant for the transaction.',
39
+				'event_espresso'
40
+			),
41
+			'[PRIMARY_REGISTRANT_REGISTRATION_CODE]'      => esc_html__(
42
+				'Parses to the registration code of the primary registrant for the transaction.',
43
+				'event_espresso'
44
+			),
45
+			'[PRIMARY_REGISTRANT_PHONE_NUMBER]'           => esc_html__(
46
+				'The Phone Number for the primary registrant for the transaction.',
47
+				'event_espresso'
48
+			),
49
+			'[PRIMARY_REGISTRANT_ADDRESS]'                => esc_html__(
50
+				'The Address for the primary registrant for the transaction.',
51
+				'event_espresso'
52
+			),
53
+			'[PRIMARY_REGISTRANT_ADDRESS2]'               => esc_html__(
54
+				'Whatever was in the address 2 field for the primary registrant for the transaction.',
55
+				'event_espresso'
56
+			),
57
+			'[PRIMARY_REGISTRANT_CITY]'                   => esc_html__(
58
+				'The city for the primary registrant for the transaction.',
59
+				'event_espresso'
60
+			),
61
+			'[PRIMARY_REGISTRANT_ZIP_PC]'                 => esc_html__(
62
+				'The ZIP (or Postal) Code for the primary registrant for the transaction.',
63
+				'event_espresso'
64
+			),
65
+			'[PRIMARY_REGISTRANT_ADDRESS_STATE]'          => esc_html__(
66
+				'The state/province for the primary registrant for the transaction.',
67
+				'event_espresso'
68
+			),
69
+			'[PRIMARY_REGISTRANT_COUNTRY]'                => esc_html__(
70
+				'The country for the primary registrant for the transaction.',
71
+				'event_espresso'
72
+			),
73
+			'[PRIMARY_REGISTRANT_REGISTRATION_DATE]'      => esc_html__(
74
+				'The date the registration occured for the primary registration.',
75
+				'event_espresso'
76
+			),
77
+			'[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__(
78
+				'Generates a link for the given registration to edit this registration details on the frontend.',
79
+				'event_espresso'
80
+			),
81
+			'[PRIMARY_REGISTRANT_ANSWER_*]'               => esc_html__(
82
+				'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.',
83
+				'event_espresso'
84
+			),
85
+		);
86
+	}
87
+
88
+
89
+	protected function _parser($shortcode)
90
+	{
91
+		// make sure we end up with a copy of the EE_Messages_Addressee object
92
+		$primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
93
+		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && is_array(
94
+			$this->_data
95
+		) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data']
96
+			: $primary_registration;
97
+		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
98
+			? $this->_extra_data['data'] : $primary_registration;
99
+
100
+		if (! $primary_registration instanceof EE_Messages_Addressee) {
101
+			return '';
102
+		}
103
+
104
+		$attendee = $primary_registration->primary_att_obj;
105
+		$primary_reg = $primary_registration->primary_reg_obj;
106
+
107
+		if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
108
+			return '';
109
+		}
110
+
111
+		switch ($shortcode) {
112
+			case '[PRIMARY_REGISTRANT_FNAME]':
113
+				return $attendee->fname();
114
+				break;
115
+
116
+			case '[PRIMARY_REGISTRANT_LNAME]':
117
+				return $attendee->lname();
118
+				break;
119
+
120
+			case '[PRIMARY_REGISTRANT_EMAIL]':
121
+				return $attendee->email();
122
+				break;
123
+
124
+			case '[PRIMARY_REGISTRANT_REGISTRATION_ID]':
125
+				return $primary_reg->ID();
126
+				break;
127
+
128
+			case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]':
129
+				return $primary_reg->reg_code();
130
+				break;
131
+
132
+			case '[PRIMARY_REGISTRANT_PHONE_NUMBER]':
133
+				return $attendee->phone();
134
+				break;
135
+
136
+			case '[PRIMARY_REGISTRANT_ADDRESS]':
137
+				return $attendee->address();
138
+				break;
139
+
140
+			case '[PRIMARY_REGISTRANT_ADDRESS2]':
141
+				return $attendee->address2();
142
+				break;
143
+
144
+			case '[PRIMARY_REGISTRANT_CITY]':
145
+				return $attendee->city();
146
+				break;
147
+
148
+			case '[PRIMARY_REGISTRANT_ZIP_PC]':
149
+				return $attendee->zip();
150
+				break;
151
+
152
+			case '[PRIMARY_REGISTRANT_ADDRESS_STATE]':
153
+				$state_obj = $attendee->state_obj();
154
+				return $state_obj instanceof EE_State ? $state_obj->name() : '';
155
+				break;
156
+
157
+			case '[PRIMARY_REGISTRANT_COUNTRY]':
158
+				$country_obj = $attendee->country_obj();
159
+				return $country_obj instanceof EE_Country ? $country_obj->name() : '';
160
+				break;
161
+
162
+			case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]':
163
+				if (! $primary_registration->primary_reg_obj instanceof EE_Registration) {
164
+					return '';
165
+				}
166
+				return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format'));
167
+				break;
168
+
169
+			case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]':
170
+				return $primary_reg->edit_attendee_information_url();
171
+				break;
172
+		}
173
+
174
+		if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) {
175
+			$shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode);
176
+			$shortcode = trim(str_replace(']', '', $shortcode));
177
+
178
+
179
+			// now let's figure out what question has this text
180
+			if (empty($primary_registration->questions)) {
181
+				return '';
182
+			}
183
+
184
+			foreach ($primary_registration->questions as $ansid => $question) {
185
+				if (
186
+					$question instanceof EE_Question
187
+					&& trim($question->get('QST_display_text')) === trim($shortcode)
188
+					&& isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ])
189
+				) {
190
+					$primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ];
191
+
192
+					// what we show for the answer depends on the question type!
193
+					switch ($question->get('QST_type')) {
194
+						case EEM_Question::QST_type_state:
195
+							$state = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
196
+							$answer = $state instanceof EE_State ? $state->name() : '';
197
+							break;
198
+
199
+						case EEM_Question::QST_type_country:
200
+							$country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
201
+							$answer = $country instanceof EE_Country ? $country->name() : '';
202
+							break;
203
+
204
+						default:
205
+							$answer = $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop');
206
+							break;
207
+					}
208
+
209
+					return $answer;
210
+					break;
211
+				}
212
+			}
213
+		}
214
+
215
+		return '';
216
+	}
217 217
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Currency_Input.input.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,13 +21,13 @@
 block discarded – undo
21 21
     {
22 22
         $query_params = array('order_by' => array('CNT_name' => 'asc'));
23 23
         if ($only_specific_currency_codes) {
24
-            $query_params[0]['CNT_cur_code'] = array('IN',$only_specific_currency_codes);
24
+            $query_params[0]['CNT_cur_code'] = array('IN', $only_specific_currency_codes);
25 25
         }
26 26
         $all_countries = EEM_Country::instance()->get_all($query_params);
27 27
         $country_options = array();
28 28
         foreach ($all_countries as $country) {
29 29
             /* @var $country EE_Country */
30
-            $country_options[ $country->currency_code() ] = $country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
30
+            $country_options[$country->currency_code()] = $country->name().": ".$country->currency_name_single()." (".$country->currency_sign().")";
31 31
         }
32 32
         parent::__construct($country_options, 'int', $input_settings);
33 33
     }
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,23 +11,23 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Currency_Input extends EE_Select_Input
13 13
 {
14
-    /**
15
-     *
16
-     * @param array $only_specific_currency_codes numerically-indexed array of allowed currency codes. By default, all are allowed
17
-     * @param array $input_settings
18
-     */
19
-    public function __construct($only_specific_currency_codes = array(), $input_settings = array())
20
-    {
21
-        $query_params = array('order_by' => array('CNT_name' => 'asc'));
22
-        if ($only_specific_currency_codes) {
23
-            $query_params[0]['CNT_cur_code'] = array('IN',$only_specific_currency_codes);
24
-        }
25
-        $all_countries = EEM_Country::instance()->get_all($query_params);
26
-        $country_options = array();
27
-        foreach ($all_countries as $country) {
28
-            /* @var $country EE_Country */
29
-            $country_options[ $country->currency_code() ] = $country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
30
-        }
31
-        parent::__construct($country_options, 'int', $input_settings);
32
-    }
14
+	/**
15
+	 *
16
+	 * @param array $only_specific_currency_codes numerically-indexed array of allowed currency codes. By default, all are allowed
17
+	 * @param array $input_settings
18
+	 */
19
+	public function __construct($only_specific_currency_codes = array(), $input_settings = array())
20
+	{
21
+		$query_params = array('order_by' => array('CNT_name' => 'asc'));
22
+		if ($only_specific_currency_codes) {
23
+			$query_params[0]['CNT_cur_code'] = array('IN',$only_specific_currency_codes);
24
+		}
25
+		$all_countries = EEM_Country::instance()->get_all($query_params);
26
+		$country_options = array();
27
+		foreach ($all_countries as $country) {
28
+			/* @var $country EE_Country */
29
+			$country_options[ $country->currency_code() ] = $country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
30
+		}
31
+		parent::__construct($country_options, 'int', $input_settings);
32
+	}
33 33
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Select_Reveal_Input.input.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
             if (empty($sibling_section_name)) {
46 46
                 continue;
47 47
             }
48
-            $sibling_section = $this->find_section_from_path('../' . $sibling_section_name);
48
+            $sibling_section = $this->find_section_from_path('../'.$sibling_section_name);
49 49
             if (
50 50
                 $sibling_section instanceof EE_Form_Section_Base
51 51
                 && ! empty($sibling_section_name)
52 52
             ) {
53
-                $sibling_sections[ $sibling_section_name ] = $sibling_section;
53
+                $sibling_sections[$sibling_section_name] = $sibling_section;
54 54
             }
55 55
         }
56 56
         return $sibling_sections;
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
     public function get_other_js_data($form_other_js_data = array())
67 67
     {
68 68
         $form_other_js_data = parent::get_other_js_data($form_other_js_data);
69
-        if (! isset($form_other_js_data['select_reveal_inputs'])) {
69
+        if ( ! isset($form_other_js_data['select_reveal_inputs'])) {
70 70
             $form_other_js_data['select_reveal_inputs'] = array();
71 71
         }
72 72
         $sibling_input_to_html_id_map = array();
73 73
         foreach ($this->sibling_sections_controlled() as $sibling_section_path => $sibling_section) {
74
-            $sibling_input_to_html_id_map[ $sibling_section_path ] = $sibling_section->html_id();
74
+            $sibling_input_to_html_id_map[$sibling_section_path] = $sibling_section->html_id();
75 75
         }
76
-        $form_other_js_data['select_reveal_inputs'][ $this->html_id() ] = $sibling_input_to_html_id_map;
76
+        $form_other_js_data['select_reveal_inputs'][$this->html_id()] = $sibling_input_to_html_id_map;
77 77
         return $form_other_js_data;
78 78
     }
79 79
 }
Please login to merge, or discard this patch.
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -14,65 +14,65 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Select_Reveal_Input extends EE_Select_Input
16 16
 {
17
-    /**
18
-     * @param array $answer_options Array keys which match a sibling section's name
19
-     *              will show/unhide that sibling subsection. Otherwise, siblings whose names
20
-     *              match array keys of $answer_options are hidden.
21
-     *              Note: internally each array key is considered a relative form input path
22
-     *              (see EE_Form_Section_Base::find_section_from_path) but relative
23
-     *              to THIS INPUT's PARENT section, not this input itself. ie,
24
-     *              a '../' is automatically added onto each each array key, to produce
25
-     *              the relative form input path.
26
-     *              Note however: array keys which are an EMPTY STRING are left as-is
27
-     *
28
-     * @param array $input_settings
29
-     */
30
-    public function __construct($answer_options, $input_settings = array())
31
-    {
32
-        parent::__construct($answer_options, $input_settings);
33
-    }
17
+	/**
18
+	 * @param array $answer_options Array keys which match a sibling section's name
19
+	 *              will show/unhide that sibling subsection. Otherwise, siblings whose names
20
+	 *              match array keys of $answer_options are hidden.
21
+	 *              Note: internally each array key is considered a relative form input path
22
+	 *              (see EE_Form_Section_Base::find_section_from_path) but relative
23
+	 *              to THIS INPUT's PARENT section, not this input itself. ie,
24
+	 *              a '../' is automatically added onto each each array key, to produce
25
+	 *              the relative form input path.
26
+	 *              Note however: array keys which are an EMPTY STRING are left as-is
27
+	 *
28
+	 * @param array $input_settings
29
+	 */
30
+	public function __construct($answer_options, $input_settings = array())
31
+	{
32
+		parent::__construct($answer_options, $input_settings);
33
+	}
34 34
 
35
-    /**
36
-     * Gets all the sibling sections controlled by this reveal select input
37
-     * @return \EE_Form_Section_Base[] keys are their form section paths
38
-     */
39
-    public function sibling_sections_controlled()
40
-    {
41
-        $sibling_sections = array();
42
-        foreach ($this->options() as $sibling_section_name => $sibling_section) {
43
-            // if it's an empty string just leave it alone
44
-            if (empty($sibling_section_name)) {
45
-                continue;
46
-            }
47
-            $sibling_section = $this->find_section_from_path('../' . $sibling_section_name);
48
-            if (
49
-                $sibling_section instanceof EE_Form_Section_Base
50
-                && ! empty($sibling_section_name)
51
-            ) {
52
-                $sibling_sections[ $sibling_section_name ] = $sibling_section;
53
-            }
54
-        }
55
-        return $sibling_sections;
56
-    }
35
+	/**
36
+	 * Gets all the sibling sections controlled by this reveal select input
37
+	 * @return \EE_Form_Section_Base[] keys are their form section paths
38
+	 */
39
+	public function sibling_sections_controlled()
40
+	{
41
+		$sibling_sections = array();
42
+		foreach ($this->options() as $sibling_section_name => $sibling_section) {
43
+			// if it's an empty string just leave it alone
44
+			if (empty($sibling_section_name)) {
45
+				continue;
46
+			}
47
+			$sibling_section = $this->find_section_from_path('../' . $sibling_section_name);
48
+			if (
49
+				$sibling_section instanceof EE_Form_Section_Base
50
+				&& ! empty($sibling_section_name)
51
+			) {
52
+				$sibling_sections[ $sibling_section_name ] = $sibling_section;
53
+			}
54
+		}
55
+		return $sibling_sections;
56
+	}
57 57
 
58
-    /**
59
-     * Adds an entry of 'select_reveal_inputs' to the js data, which is an array
60
-     * whose top-level keys are select reveal input html ids; values are arrays
61
-     * whose keys are select option values and values are the sections they reveal
62
-     * @param array $form_other_js_data
63
-     * @return array
64
-     */
65
-    public function get_other_js_data($form_other_js_data = array())
66
-    {
67
-        $form_other_js_data = parent::get_other_js_data($form_other_js_data);
68
-        if (! isset($form_other_js_data['select_reveal_inputs'])) {
69
-            $form_other_js_data['select_reveal_inputs'] = array();
70
-        }
71
-        $sibling_input_to_html_id_map = array();
72
-        foreach ($this->sibling_sections_controlled() as $sibling_section_path => $sibling_section) {
73
-            $sibling_input_to_html_id_map[ $sibling_section_path ] = $sibling_section->html_id();
74
-        }
75
-        $form_other_js_data['select_reveal_inputs'][ $this->html_id() ] = $sibling_input_to_html_id_map;
76
-        return $form_other_js_data;
77
-    }
58
+	/**
59
+	 * Adds an entry of 'select_reveal_inputs' to the js data, which is an array
60
+	 * whose top-level keys are select reveal input html ids; values are arrays
61
+	 * whose keys are select option values and values are the sections they reveal
62
+	 * @param array $form_other_js_data
63
+	 * @return array
64
+	 */
65
+	public function get_other_js_data($form_other_js_data = array())
66
+	{
67
+		$form_other_js_data = parent::get_other_js_data($form_other_js_data);
68
+		if (! isset($form_other_js_data['select_reveal_inputs'])) {
69
+			$form_other_js_data['select_reveal_inputs'] = array();
70
+		}
71
+		$sibling_input_to_html_id_map = array();
72
+		foreach ($this->sibling_sections_controlled() as $sibling_section_path => $sibling_section) {
73
+			$sibling_input_to_html_id_map[ $sibling_section_path ] = $sibling_section->html_id();
74
+		}
75
+		$form_other_js_data['select_reveal_inputs'][ $this->html_id() ] = $sibling_input_to_html_id_map;
76
+		return $form_other_js_data;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_CVV_Input.input.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
         $this->_add_validation_strategy(
24 24
             new EE_Text_Validation_Strategy(
25 25
                 isset($input_settings['validation_error_message'])
26
-                    ?  $input_settings['validation_error_message']
26
+                    ? $input_settings['validation_error_message']
27 27
                     : esc_html__(
28 28
                         'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
29 29
                         'event_espresso'
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -11,43 +11,43 @@
 block discarded – undo
11 11
  */
12 12
 class EE_CVV_Input extends EE_Text_Input
13 13
 {
14
-    /**
15
-     * @param array $input_settings {
16
-     *  @type boolean $include_whats_this_link defaults to true
17
-     * }
18
-     */
19
-    public function __construct($input_settings = array())
20
-    {
21
-        $this->set_sensitive_data_removal_strategy(new EE_CCV_Sensitive_Data_Removal());
22
-        $this->_add_validation_strategy(
23
-            new EE_Text_Validation_Strategy(
24
-                isset($input_settings['validation_error_message'])
25
-                    ?  $input_settings['validation_error_message']
26
-                    : esc_html__(
27
-                        'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
28
-                        'event_espresso'
29
-                    ),
30
-                '~^\d{3,4}$~'
31
-            )
32
-        );
33
-        parent::__construct($input_settings);
34
-        if (
35
-            ! isset($input_settings['include_whats_this_link'])
36
-            || (
37
-                isset($input_settings['include_whats_this_link'])
38
-                 && $input_settings['include_whats_this_link'] === true
39
-            )
40
-        ) {
41
-            $this->_html_label_text = sprintf(
42
-                esc_html_x(
43
-                    '%1$s %2$s(What\'s this?)%3$s',
44
-                    'CVV (What\'s this?)',
45
-                    'event_espresso'
46
-                ),
47
-                $this->_html_label_text,
48
-                '<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">',
49
-                '</a>'
50
-            );
51
-        }
52
-    }
14
+	/**
15
+	 * @param array $input_settings {
16
+	 *  @type boolean $include_whats_this_link defaults to true
17
+	 * }
18
+	 */
19
+	public function __construct($input_settings = array())
20
+	{
21
+		$this->set_sensitive_data_removal_strategy(new EE_CCV_Sensitive_Data_Removal());
22
+		$this->_add_validation_strategy(
23
+			new EE_Text_Validation_Strategy(
24
+				isset($input_settings['validation_error_message'])
25
+					?  $input_settings['validation_error_message']
26
+					: esc_html__(
27
+						'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
28
+						'event_espresso'
29
+					),
30
+				'~^\d{3,4}$~'
31
+			)
32
+		);
33
+		parent::__construct($input_settings);
34
+		if (
35
+			! isset($input_settings['include_whats_this_link'])
36
+			|| (
37
+				isset($input_settings['include_whats_this_link'])
38
+				 && $input_settings['include_whats_this_link'] === true
39
+			)
40
+		) {
41
+			$this->_html_label_text = sprintf(
42
+				esc_html_x(
43
+					'%1$s %2$s(What\'s this?)%3$s',
44
+					'CVV (What\'s this?)',
45
+					'event_espresso'
46
+				),
47
+				$this->_html_label_text,
48
+				'<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">',
49
+				'</a>'
50
+			);
51
+		}
52
+	}
53 53
 }
Please login to merge, or discard this patch.