Completed
Branch BUG/brents-suggested-tweaks-fo... (ceef0f)
by
unknown
08:41 queued 01:01
created
core/libraries/form_sections/inputs/EE_Form_Input_Base.input.php 2 patches
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
         if (isset($input_args['validation_strategies'])) {
196 196
             foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
197 197
                 if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
198
-                    $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
198
+                    $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
199 199
                 }
200 200
             }
201 201
             unset($input_args['validation_strategies']);
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
         // loop thru incoming options
207 207
         foreach ($input_args as $key => $value) {
208 208
             // add underscore to $key to match property names
209
-            $_key = '_' . $key;
209
+            $_key = '_'.$key;
210 210
             if (property_exists($this, $_key)) {
211 211
                 $this->{$_key} = $value;
212 212
             }
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
         if (isset($input_args['ignore_input'])) {
227 227
             $this->_normalization_strategy = new EE_Null_Normalization();
228 228
         }
229
-        if (! $this->_normalization_strategy) {
229
+        if ( ! $this->_normalization_strategy) {
230 230
                 $this->_normalization_strategy = new EE_Text_Normalization();
231 231
         }
232 232
         $this->_normalization_strategy->_construct_finalize($this);
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
             $this->set_default($input_args['default']);
236 236
             unset($input_args['default']);
237 237
         }
238
-        if (! $this->_sensitive_data_removal_strategy) {
238
+        if ( ! $this->_sensitive_data_removal_strategy) {
239 239
             $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
240 240
         }
241 241
         $this->_sensitive_data_removal_strategy->_construct_finalize($this);
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
      */
253 253
     protected function _set_default_html_name_if_empty()
254 254
     {
255
-        if (! $this->_html_name) {
255
+        if ( ! $this->_html_name) {
256 256
             $this->_html_name = $this->name();
257 257
             if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
258
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
258
+                $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]";
259 259
             }
260 260
         }
261 261
     }
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
     protected function _get_display_strategy()
288 288
     {
289 289
         $this->ensure_construct_finalized_called();
290
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
290
+        if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
291 291
             throw new EE_Error(
292 292
                 sprintf(
293 293
                     __(
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
             if ($validation_strategy instanceof $validation_strategy_classname
455 455
                 || is_subclass_of($validation_strategy, $validation_strategy_classname)
456 456
             ) {
457
-                unset($this->_validation_strategies[ $key ]);
457
+                unset($this->_validation_strategies[$key]);
458 458
             }
459 459
         }
460 460
     }
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
             if (is_array($raw_input)) {
666 666
                 $raw_value = array();
667 667
                 foreach ($raw_input as $key => $value) {
668
-                    $raw_value[ $key ] = $this->_sanitize($value);
668
+                    $raw_value[$key] = $this->_sanitize($value);
669 669
                 }
670 670
                 $this->_set_raw_value($raw_value);
671 671
             } else {
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
      */
699 699
     public function html_label_id()
700 700
     {
701
-        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
701
+        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id().'-lbl';
702 702
     }
703 703
 
704 704
 
@@ -848,9 +848,9 @@  discard block
 block discarded – undo
848 848
                 $validation_strategy->get_jquery_validation_rule_array()
849 849
             );
850 850
         }
851
-        if (! empty($jquery_validation_rules)) {
851
+        if ( ! empty($jquery_validation_rules)) {
852 852
             foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
853
-                $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
853
+                $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
854 854
             }
855 855
         }
856 856
         return $jquery_validation_js;
@@ -972,7 +972,7 @@  discard block
 block discarded – undo
972 972
     public function html_class($add_required = false)
973 973
     {
974 974
         return $add_required && $this->required()
975
-            ? $this->required_css_class() . ' ' . $this->_html_class
975
+            ? $this->required_css_class().' '.$this->_html_class
976 976
             : $this->_html_class;
977 977
     }
978 978
 
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
                 $button_css_attributes .= '';
1047 1047
         }
1048 1048
         $this->_button_css_attributes .= ! empty($other_attributes)
1049
-            ? $button_css_attributes . ' ' . $other_attributes
1049
+            ? $button_css_attributes.' '.$other_attributes
1050 1050
             : $button_css_attributes;
1051 1051
     }
1052 1052
 
@@ -1084,8 +1084,8 @@  discard block
 block discarded – undo
1084 1084
         // now get the value for the input
1085 1085
         $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1086 1086
         // check if this thing's name is at the TOP level of the request data
1087
-        if ($value === null && isset($req_data[ $this->name() ])) {
1088
-            $value = $req_data[ $this->name() ];
1087
+        if ($value === null && isset($req_data[$this->name()])) {
1088
+            $value = $req_data[$this->name()];
1089 1089
         }
1090 1090
         return $value;
1091 1091
     }
@@ -1126,13 +1126,13 @@  discard block
 block discarded – undo
1126 1126
     public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1127 1127
     {
1128 1128
         $first_part_to_consider = array_shift($html_name_parts);
1129
-        if (isset($req_data[ $first_part_to_consider ])) {
1129
+        if (isset($req_data[$first_part_to_consider])) {
1130 1130
             if (empty($html_name_parts)) {
1131
-                return $req_data[ $first_part_to_consider ];
1131
+                return $req_data[$first_part_to_consider];
1132 1132
             } else {
1133 1133
                 return $this->findRequestForSectionUsingNameParts(
1134 1134
                     $html_name_parts,
1135
-                    $req_data[ $first_part_to_consider ]
1135
+                    $req_data[$first_part_to_consider]
1136 1136
                 );
1137 1137
             }
1138 1138
         } else {
Please login to merge, or discard this patch.
Indentation   +1253 added lines, -1253 removed lines patch added patch discarded remove patch
@@ -11,1257 +11,1257 @@
 block discarded – undo
11 11
 abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable
12 12
 {
13 13
 
14
-    /**
15
-     * the input's name attribute
16
-     *
17
-     * @var string
18
-     */
19
-    protected $_html_name;
20
-
21
-    /**
22
-     * id for the html label tag
23
-     *
24
-     * @var string
25
-     */
26
-    protected $_html_label_id;
27
-
28
-    /**
29
-     * class for teh html label tag
30
-     *
31
-     * @var string
32
-     */
33
-    protected $_html_label_class;
34
-
35
-    /**
36
-     * style for teh html label tag
37
-     *
38
-     * @var string
39
-     */
40
-    protected $_html_label_style;
41
-
42
-    /**
43
-     * text to be placed in the html label
44
-     *
45
-     * @var string
46
-     */
47
-    protected $_html_label_text;
48
-
49
-    /**
50
-     * the full html label. If used, all other html_label_* properties are invalid
51
-     *
52
-     * @var string
53
-     */
54
-    protected $_html_label;
55
-
56
-    /**
57
-     * HTML to use for help text (normally placed below form input), in a span which normally
58
-     * has a class of 'description'
59
-     *
60
-     * @var string
61
-     */
62
-    protected $_html_help_text;
63
-
64
-    /**
65
-     * CSS classes for displaying the help span
66
-     *
67
-     * @var string
68
-     */
69
-    protected $_html_help_class = 'description';
70
-
71
-    /**
72
-     * CSS to put in the style attribute on the help span
73
-     *
74
-     * @var string
75
-     */
76
-    protected $_html_help_style;
77
-
78
-    /**
79
-     * Stores whether or not this input's response is required.
80
-     * Because certain styling elements may also want to know that this
81
-     * input is required etc.
82
-     *
83
-     * @var boolean
84
-     */
85
-    protected $_required;
86
-
87
-    /**
88
-     * css class added to required inputs
89
-     *
90
-     * @var string
91
-     */
92
-    protected $_required_css_class = 'ee-required';
93
-
94
-    /**
95
-     * css styles applied to button type inputs
96
-     *
97
-     * @var string
98
-     */
99
-    protected $_button_css_attributes;
100
-
101
-    /**
102
-     * The raw data submitted for this, like in the $_POST super global.
103
-     * Generally unsafe for usage in client code
104
-     *
105
-     * @var mixed string or array
106
-     */
107
-    protected $_raw_value;
108
-
109
-    /**
110
-     * Value normalized according to the input's normalization strategy.
111
-     * The normalization strategy dictates whether this is a string, int, float,
112
-     * boolean, or array of any of those.
113
-     *
114
-     * @var mixed
115
-     */
116
-    protected $_normalized_value;
117
-
118
-
119
-    /**
120
-     * Normalized default value either initially set on the input, or provided by calling
121
-     * set_default().
122
-     * @var mixed
123
-     */
124
-    protected $_default;
125
-
126
-    /**
127
-     * Strategy used for displaying this field.
128
-     * Child classes must use _get_display_strategy to access it.
129
-     *
130
-     * @var EE_Display_Strategy_Base
131
-     */
132
-    private $_display_strategy;
133
-
134
-    /**
135
-     * Gets all the validation strategies used on this field
136
-     *
137
-     * @var EE_Validation_Strategy_Base[]
138
-     */
139
-    private $_validation_strategies = array();
140
-
141
-    /**
142
-     * The normalization strategy for this field
143
-     *
144
-     * @var EE_Normalization_Strategy_Base
145
-     */
146
-    private $_normalization_strategy;
147
-
148
-    /**
149
-     * Strategy for removing sensitive data after we're done with the form input
150
-     *
151
-     * @var EE_Sensitive_Data_Removal_Base
152
-     */
153
-    protected $_sensitive_data_removal_strategy;
154
-
155
-    /**
156
-     * Whether this input has been disabled or not.
157
-     * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
158
-     * (Client-side code that wants to dynamically disable it must also add this hidden input).
159
-     * When the form is submitted, if the input is disabled in the PHP formsection, then input is ignored.
160
-     * If the input is missing from the $_REQUEST data but the hidden input indicating the input is disabled, then the input is again ignored.
161
-     *
162
-     * @var boolean
163
-     */
164
-    protected $disabled = false;
165
-
166
-
167
-
168
-    /**
169
-     * @param array                         $input_args       {
170
-     * @type string                         $html_name        the html name for the input
171
-     * @type string                         $html_label_id    the id attribute to give to the html label tag
172
-     * @type string                         $html_label_class the class attribute to give to the html label tag
173
-     * @type string                         $html_label_style the style attribute to give ot teh label tag
174
-     * @type string                         $html_label_text  the text to put in the label tag
175
-     * @type string                         $html_label       the full html label. If used,
176
-     *                                                        all other html_label_* args are invalid
177
-     * @type string                         $html_help_text   text to put in help element
178
-     * @type string                         $html_help_style  style attribute to give to teh help element
179
-     * @type string                         $html_help_class  class attribute to give to the help element
180
-     * @type string                         $default          default value NORMALIZED (eg, if providing the default
181
-     *       for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0')
182
-     * @type EE_Display_Strategy_Base       $display          strategy
183
-     * @type EE_Normalization_Strategy_Base $normalization_strategy
184
-     * @type EE_Validation_Strategy_Base[]  $validation_strategies
185
-     * @type boolean                        $ignore_input special argument which can be used to avoid adding any validation strategies,
186
-     *                                                    and sets the normalization strategy to the Null normalization. This is good
187
-     *                                                    when you want the input to be totally ignored server-side (like when using
188
-     *                                                    React.js form inputs)
189
-     *                                                        }
190
-     */
191
-    public function __construct($input_args = array())
192
-    {
193
-        $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
194
-        // the following properties must be cast as arrays
195
-        if (isset($input_args['validation_strategies'])) {
196
-            foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
197
-                if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
198
-                    $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
199
-                }
200
-            }
201
-            unset($input_args['validation_strategies']);
202
-        }
203
-        if (isset($input_args['ignore_input'])) {
204
-            $this->_validation_strategies = array();
205
-        }
206
-        // loop thru incoming options
207
-        foreach ($input_args as $key => $value) {
208
-            // add underscore to $key to match property names
209
-            $_key = '_' . $key;
210
-            if (property_exists($this, $_key)) {
211
-                $this->{$_key} = $value;
212
-            }
213
-        }
214
-        // ensure that "required" is set correctly
215
-        $this->set_required(
216
-            $this->_required,
217
-            isset($input_args['required_validation_error_message'])
218
-            ? $input_args['required_validation_error_message']
219
-            : null
220
-        );
221
-        // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
222
-        $this->_display_strategy->_construct_finalize($this);
223
-        foreach ($this->_validation_strategies as $validation_strategy) {
224
-            $validation_strategy->_construct_finalize($this);
225
-        }
226
-        if (isset($input_args['ignore_input'])) {
227
-            $this->_normalization_strategy = new EE_Null_Normalization();
228
-        }
229
-        if (! $this->_normalization_strategy) {
230
-                $this->_normalization_strategy = new EE_Text_Normalization();
231
-        }
232
-        $this->_normalization_strategy->_construct_finalize($this);
233
-        // at least we can use the normalization strategy to populate the default
234
-        if (isset($input_args['default'])) {
235
-            $this->set_default($input_args['default']);
236
-            unset($input_args['default']);
237
-        }
238
-        if (! $this->_sensitive_data_removal_strategy) {
239
-            $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
240
-        }
241
-        $this->_sensitive_data_removal_strategy->_construct_finalize($this);
242
-        parent::__construct($input_args);
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * Sets the html_name to its default value, if none was specified in teh constructor.
249
-     * Calculation involves using the name and the parent's html_name
250
-     *
251
-     * @throws \EE_Error
252
-     */
253
-    protected function _set_default_html_name_if_empty()
254
-    {
255
-        if (! $this->_html_name) {
256
-            $this->_html_name = $this->name();
257
-            if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
258
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
259
-            }
260
-        }
261
-    }
262
-
263
-
264
-
265
-    /**
266
-     * @param $parent_form_section
267
-     * @param $name
268
-     * @throws \EE_Error
269
-     */
270
-    public function _construct_finalize($parent_form_section, $name)
271
-    {
272
-        parent::_construct_finalize($parent_form_section, $name);
273
-        if ($this->_html_label === null && $this->_html_label_text === null) {
274
-            $this->_html_label_text = ucwords(str_replace("_", " ", $name));
275
-        }
276
-        do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * Returns the strategy for displaying this form input. If none is set, throws an exception.
283
-     *
284
-     * @return EE_Display_Strategy_Base
285
-     * @throws EE_Error
286
-     */
287
-    protected function _get_display_strategy()
288
-    {
289
-        $this->ensure_construct_finalized_called();
290
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
291
-            throw new EE_Error(
292
-                sprintf(
293
-                    __(
294
-                        "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
295
-                        "event_espresso"
296
-                    ),
297
-                    $this->html_name(),
298
-                    $this->html_id()
299
-                )
300
-            );
301
-        } else {
302
-            return $this->_display_strategy;
303
-        }
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * Sets the display strategy.
310
-     *
311
-     * @param EE_Display_Strategy_Base $strategy
312
-     */
313
-    protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
314
-    {
315
-        $this->_display_strategy = $strategy;
316
-    }
317
-
318
-
319
-
320
-    /**
321
-     * Sets the sanitization strategy
322
-     *
323
-     * @param EE_Normalization_Strategy_Base $strategy
324
-     */
325
-    protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
326
-    {
327
-        $this->_normalization_strategy = $strategy;
328
-    }
329
-
330
-
331
-
332
-    /**
333
-     * Gets sensitive_data_removal_strategy
334
-     *
335
-     * @return EE_Sensitive_Data_Removal_Base
336
-     */
337
-    public function get_sensitive_data_removal_strategy()
338
-    {
339
-        return $this->_sensitive_data_removal_strategy;
340
-    }
341
-
342
-
343
-
344
-    /**
345
-     * Sets sensitive_data_removal_strategy
346
-     *
347
-     * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
348
-     * @return boolean
349
-     */
350
-    public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
351
-    {
352
-        $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * Gets the display strategy for this input
359
-     *
360
-     * @return EE_Display_Strategy_Base
361
-     */
362
-    public function get_display_strategy()
363
-    {
364
-        return $this->_display_strategy;
365
-    }
366
-
367
-
368
-
369
-    /**
370
-     * Overwrites the display strategy
371
-     *
372
-     * @param EE_Display_Strategy_Base $display_strategy
373
-     */
374
-    public function set_display_strategy($display_strategy)
375
-    {
376
-        $this->_display_strategy = $display_strategy;
377
-        $this->_display_strategy->_construct_finalize($this);
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * Gets the normalization strategy set on this input
384
-     *
385
-     * @return EE_Normalization_Strategy_Base
386
-     */
387
-    public function get_normalization_strategy()
388
-    {
389
-        return $this->_normalization_strategy;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * Overwrites the normalization strategy
396
-     *
397
-     * @param EE_Normalization_Strategy_Base $normalization_strategy
398
-     */
399
-    public function set_normalization_strategy($normalization_strategy)
400
-    {
401
-        $this->_normalization_strategy = $normalization_strategy;
402
-        $this->_normalization_strategy->_construct_finalize($this);
403
-    }
404
-
405
-
406
-
407
-    /**
408
-     * Returns all teh validation strategies which apply to this field, numerically indexed
409
-     *
410
-     * @return EE_Validation_Strategy_Base[]
411
-     */
412
-    public function get_validation_strategies()
413
-    {
414
-        return $this->_validation_strategies;
415
-    }
416
-
417
-
418
-
419
-    /**
420
-     * Adds this strategy to the field so it will be used in both JS validation and server-side validation
421
-     *
422
-     * @param EE_Validation_Strategy_Base $validation_strategy
423
-     * @return void
424
-     */
425
-    protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
426
-    {
427
-        $validation_strategy->_construct_finalize($this);
428
-        $this->_validation_strategies[] = $validation_strategy;
429
-    }
430
-
431
-
432
-
433
-    /**
434
-     * Adds a new validation strategy onto the form input
435
-     *
436
-     * @param EE_Validation_Strategy_Base $validation_strategy
437
-     * @return void
438
-     */
439
-    public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
440
-    {
441
-        $this->_add_validation_strategy($validation_strategy);
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * The classname of the validation strategy to remove
448
-     *
449
-     * @param string $validation_strategy_classname
450
-     */
451
-    public function remove_validation_strategy($validation_strategy_classname)
452
-    {
453
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
454
-            if ($validation_strategy instanceof $validation_strategy_classname
455
-                || is_subclass_of($validation_strategy, $validation_strategy_classname)
456
-            ) {
457
-                unset($this->_validation_strategies[ $key ]);
458
-            }
459
-        }
460
-    }
461
-
462
-
463
-
464
-    /**
465
-     * returns true if input employs any of the validation strategy defined by the supplied array of classnames
466
-     *
467
-     * @param array $validation_strategy_classnames
468
-     * @return bool
469
-     */
470
-    public function has_validation_strategy($validation_strategy_classnames)
471
-    {
472
-        $validation_strategy_classnames = is_array($validation_strategy_classnames)
473
-            ? $validation_strategy_classnames
474
-            : array($validation_strategy_classnames);
475
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
476
-            if (in_array($key, $validation_strategy_classnames)) {
477
-                return true;
478
-            }
479
-        }
480
-        return false;
481
-    }
482
-
483
-
484
-
485
-    /**
486
-     * Gets the HTML
487
-     *
488
-     * @return string
489
-     */
490
-    public function get_html()
491
-    {
492
-        return $this->_parent_section->get_html_for_input($this);
493
-    }
494
-
495
-
496
-
497
-    /**
498
-     * Gets the HTML for the input itself (no label or errors) according to the
499
-     * input's display strategy
500
-     * Makes sure the JS and CSS are enqueued for it
501
-     *
502
-     * @return string
503
-     * @throws \EE_Error
504
-     */
505
-    public function get_html_for_input()
506
-    {
507
-        return $this->_form_html_filter
508
-            ? $this->_form_html_filter->filterHtml(
509
-                $this->_get_display_strategy()->display(),
510
-                $this
511
-            )
512
-            : $this->_get_display_strategy()->display();
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * @return string
519
-     */
520
-    public function html_other_attributes()
521
-    {
522
-        EE_Error::doing_it_wrong(
523
-            __METHOD__,
524
-            sprintf(
525
-                esc_html__(
526
-                    'This method is no longer in use. You should replace it by %s',
527
-                    'event_espresso'
528
-                ),
529
-                'EE_Form_Section_Base::other_html_attributes()'
530
-            ),
531
-            '4.10.2.p'
532
-        );
533
-
534
-        return $this->other_html_attributes();
535
-    }
536
-
537
-
538
-
539
-    /**
540
-     * @param string $html_other_attributes
541
-     */
542
-    public function set_html_other_attributes($html_other_attributes)
543
-    {
544
-        EE_Error::doing_it_wrong(
545
-            __METHOD__,
546
-            sprintf(
547
-                esc_html__(
548
-                    'This method is no longer in use. You should replace it by %s',
549
-                    'event_espresso'
550
-                ),
551
-                'EE_Form_Section_Base::set_other_html_attributes()'
552
-            ),
553
-            '4.10.2.p'
554
-        );
555
-
556
-        $this->set_other_html_attributes($html_other_attributes);
557
-    }
558
-
559
-
560
-
561
-    /**
562
-     * Gets the HTML for displaying the label for this form input
563
-     * according to the form section's layout strategy
564
-     *
565
-     * @return string
566
-     */
567
-    public function get_html_for_label()
568
-    {
569
-        return $this->_parent_section->get_layout_strategy()->display_label($this);
570
-    }
571
-
572
-
573
-
574
-    /**
575
-     * Gets the HTML for displaying the errors section for this form input
576
-     * according to the form section's layout strategy
577
-     *
578
-     * @return string
579
-     */
580
-    public function get_html_for_errors()
581
-    {
582
-        return $this->_parent_section->get_layout_strategy()->display_errors($this);
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     * Gets the HTML for displaying the help text for this form input
589
-     * according to the form section's layout strategy
590
-     *
591
-     * @return string
592
-     */
593
-    public function get_html_for_help()
594
-    {
595
-        return $this->_parent_section->get_layout_strategy()->display_help_text($this);
596
-    }
597
-
598
-
599
-
600
-    /**
601
-     * Validates the input's sanitized value (assumes _sanitize() has already been called)
602
-     * and returns whether or not the form input's submitted value is value
603
-     *
604
-     * @return boolean
605
-     */
606
-    protected function _validate()
607
-    {
608
-        if ($this->isDisabled()) {
609
-            return true;
610
-        }
611
-        foreach ($this->_validation_strategies as $validation_strategy) {
612
-            if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
613
-                try {
614
-                    $validation_strategy->validate($this->normalized_value());
615
-                } catch (EE_Validation_Error $e) {
616
-                    $this->add_validation_error($e);
617
-                }
618
-            }
619
-        }
620
-        if ($this->get_validation_errors()) {
621
-            return false;
622
-        } else {
623
-            return true;
624
-        }
625
-    }
626
-
627
-
628
-
629
-    /**
630
-     * Performs basic sanitization on this value. But what sanitization can be performed anyways?
631
-     * This value MIGHT be allowed to have tags, so we can't really remove them.
632
-     *
633
-     * @param string $value
634
-     * @return null|string
635
-     */
636
-    protected function _sanitize($value)
637
-    {
638
-        return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null;
639
-    }
640
-
641
-
642
-
643
-    /**
644
-     * Picks out the form value that relates to this form input,
645
-     * and stores it as the sanitized value on the form input, and sets the normalized value.
646
-     * Returns whether or not any validation errors occurred
647
-     *
648
-     * @param array $req_data like $_POST
649
-     * @return boolean whether or not there was an error
650
-     * @throws \EE_Error
651
-     */
652
-    protected function _normalize($req_data)
653
-    {
654
-        // any existing validation errors don't apply so clear them
655
-        $this->_validation_errors = array();
656
-        // if the input is disabled, ignore whatever input was sent in
657
-        if ($this->isDisabled()) {
658
-            $this->_set_raw_value(null);
659
-            $this->_set_normalized_value($this->get_default());
660
-            return false;
661
-        }
662
-        try {
663
-            $raw_input = $this->find_form_data_for_this_section($req_data);
664
-            // super simple sanitization for now
665
-            if (is_array($raw_input)) {
666
-                $raw_value = array();
667
-                foreach ($raw_input as $key => $value) {
668
-                    $raw_value[ $key ] = $this->_sanitize($value);
669
-                }
670
-                $this->_set_raw_value($raw_value);
671
-            } else {
672
-                $this->_set_raw_value($this->_sanitize($raw_input));
673
-            }
674
-            // we want to mostly leave the input alone in case we need to re-display it to the user
675
-            $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
676
-            return false;
677
-        } catch (EE_Validation_Error $e) {
678
-            $this->add_validation_error($e);
679
-            return true;
680
-        }
681
-    }
682
-
683
-
684
-
685
-    /**
686
-     * @return string
687
-     */
688
-    public function html_name()
689
-    {
690
-        $this->_set_default_html_name_if_empty();
691
-        return $this->_html_name;
692
-    }
693
-
694
-
695
-
696
-    /**
697
-     * @return string
698
-     */
699
-    public function html_label_id()
700
-    {
701
-        return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     * @return string
708
-     */
709
-    public function html_label_class()
710
-    {
711
-        return $this->_html_label_class;
712
-    }
713
-
714
-
715
-
716
-    /**
717
-     * @return string
718
-     */
719
-    public function html_label_style()
720
-    {
721
-        return $this->_html_label_style;
722
-    }
723
-
724
-
725
-
726
-    /**
727
-     * @return string
728
-     */
729
-    public function html_label_text()
730
-    {
731
-        return $this->_html_label_text;
732
-    }
733
-
734
-
735
-
736
-    /**
737
-     * @return string
738
-     */
739
-    public function html_help_text()
740
-    {
741
-        return $this->_html_help_text;
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * @return string
748
-     */
749
-    public function html_help_class()
750
-    {
751
-        return $this->_html_help_class;
752
-    }
753
-
754
-
755
-
756
-    /**
757
-     * @return string
758
-     */
759
-    public function html_help_style()
760
-    {
761
-        return $this->_html_style;
762
-    }
763
-
764
-
765
-
766
-    /**
767
-     * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
768
-     * Please note that almost all client code should instead use the normalized_value;
769
-     * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
770
-     * mostly by escaping quotes)
771
-     * Note, we do not store the exact original value sent in the user's request because
772
-     * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
773
-     * in which case, we would have stored the malicious content to our database.
774
-     *
775
-     * @return string
776
-     */
777
-    public function raw_value()
778
-    {
779
-        return $this->_raw_value;
780
-    }
781
-
782
-
783
-
784
-    /**
785
-     * Returns a string safe to usage in form inputs when displaying, because
786
-     * it escapes all html entities
787
-     *
788
-     * @return string
789
-     */
790
-    public function raw_value_in_form()
791
-    {
792
-        return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8');
793
-    }
794
-
795
-
796
-
797
-    /**
798
-     * returns the value after it's been sanitized, and then converted into it's proper type
799
-     * in PHP. Eg, a string, an int, an array,
800
-     *
801
-     * @return mixed
802
-     */
803
-    public function normalized_value()
804
-    {
805
-        return $this->_normalized_value;
806
-    }
807
-
808
-
809
-
810
-    /**
811
-     * Returns the normalized value is a presentable way. By default this is just
812
-     * the normalized value by itself, but it can be overridden for when that's not
813
-     * the best thing to display
814
-     *
815
-     * @return string
816
-     */
817
-    public function pretty_value()
818
-    {
819
-        return $this->_normalized_value;
820
-    }
821
-
822
-
823
-
824
-    /**
825
-     * When generating the JS for the jquery validation rules like<br>
826
-     * <code>$( "#myform" ).validate({
827
-     * rules: {
828
-     * password: "required",
829
-     * password_again: {
830
-     * equalTo: "#password"
831
-     * }
832
-     * }
833
-     * });</code>
834
-     * if this field had the name 'password_again', it should return
835
-     * <br><code>password_again: {
836
-     * equalTo: "#password"
837
-     * }</code>
838
-     *
839
-     * @return array
840
-     */
841
-    public function get_jquery_validation_rules()
842
-    {
843
-        $jquery_validation_js = array();
844
-        $jquery_validation_rules = array();
845
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
846
-            $jquery_validation_rules = array_replace_recursive(
847
-                $jquery_validation_rules,
848
-                $validation_strategy->get_jquery_validation_rule_array()
849
-            );
850
-        }
851
-        if (! empty($jquery_validation_rules)) {
852
-            foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
853
-                $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
854
-            }
855
-        }
856
-        return $jquery_validation_js;
857
-    }
858
-
859
-
860
-
861
-    /**
862
-     * Sets the input's default value for use in displaying in the form. Note: value should be
863
-     * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
864
-     *
865
-     * @param mixed $value
866
-     * @return void
867
-     */
868
-    public function set_default($value)
869
-    {
870
-        $this->_default = $value;
871
-        $this->_set_normalized_value($value);
872
-        $this->_set_raw_value($value);
873
-    }
874
-
875
-
876
-
877
-    /**
878
-     * Sets the normalized value on this input
879
-     *
880
-     * @param mixed $value
881
-     */
882
-    protected function _set_normalized_value($value)
883
-    {
884
-        $this->_normalized_value = $value;
885
-    }
886
-
887
-
888
-
889
-    /**
890
-     * Sets the raw value on this input (ie, exactly as the user submitted it)
891
-     *
892
-     * @param mixed $value
893
-     */
894
-    protected function _set_raw_value($value)
895
-    {
896
-        $this->_raw_value = $this->_normalization_strategy->unnormalize($value);
897
-    }
898
-
899
-
900
-
901
-    /**
902
-     * Sets the HTML label text after it has already been defined
903
-     *
904
-     * @param string $label
905
-     * @return void
906
-     */
907
-    public function set_html_label_text($label)
908
-    {
909
-        $this->_html_label_text = $label;
910
-    }
911
-
912
-
913
-
914
-    /**
915
-     * Sets whether or not this field is required, and adjusts the validation strategy.
916
-     * If you want to use the EE_Conditionally_Required_Validation_Strategy,
917
-     * please add it as a validation strategy using add_validation_strategy as normal
918
-     *
919
-     * @param boolean $required boolean
920
-     * @param null    $required_text
921
-     */
922
-    public function set_required($required = true, $required_text = null)
923
-    {
924
-        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
925
-        // whether $required is a string or a boolean, we want to add a required validation strategy
926
-        if ($required) {
927
-            $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
928
-        } else {
929
-            $this->remove_validation_strategy('EE_Required_Validation_Strategy');
930
-        }
931
-        $this->_required = $required;
932
-    }
933
-
934
-
935
-
936
-    /**
937
-     * Returns whether or not this field is required
938
-     *
939
-     * @return boolean
940
-     */
941
-    public function required()
942
-    {
943
-        return $this->_required;
944
-    }
945
-
946
-
947
-
948
-    /**
949
-     * @param string $required_css_class
950
-     */
951
-    public function set_required_css_class($required_css_class)
952
-    {
953
-        $this->_required_css_class = $required_css_class;
954
-    }
955
-
956
-
957
-
958
-    /**
959
-     * @return string
960
-     */
961
-    public function required_css_class()
962
-    {
963
-        return $this->_required_css_class;
964
-    }
965
-
966
-
967
-
968
-    /**
969
-     * @param bool $add_required
970
-     * @return string
971
-     */
972
-    public function html_class($add_required = false)
973
-    {
974
-        return $add_required && $this->required()
975
-            ? $this->required_css_class() . ' ' . $this->_html_class
976
-            : $this->_html_class;
977
-    }
978
-
979
-
980
-    /**
981
-     * Sets the help text, in case
982
-     *
983
-     * @param string $text
984
-     */
985
-    public function set_html_help_text($text)
986
-    {
987
-        $this->_html_help_text = $text;
988
-    }
989
-
990
-
991
-
992
-    /**
993
-     * Uses the sensitive data removal strategy to remove the sensitive data from this
994
-     * input. If there is any kind of sensitive data removal on this input, we clear
995
-     * out the raw value completely
996
-     *
997
-     * @return void
998
-     */
999
-    public function clean_sensitive_data()
1000
-    {
1001
-        // if we do ANY kind of sensitive data removal on this, then just clear out the raw value
1002
-        // if we need more logic than this we'll make a strategy for it
1003
-        if ($this->_sensitive_data_removal_strategy
1004
-            && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
1005
-        ) {
1006
-            $this->_set_raw_value(null);
1007
-        }
1008
-        // and clean the normalized value according to the appropriate strategy
1009
-        $this->_set_normalized_value(
1010
-            $this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
1011
-                $this->_normalized_value
1012
-            )
1013
-        );
1014
-    }
1015
-
1016
-
1017
-
1018
-    /**
1019
-     * @param bool   $primary
1020
-     * @param string $button_size
1021
-     * @param string $other_attributes
1022
-     */
1023
-    public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1024
-    {
1025
-        $button_css_attributes = 'button';
1026
-        $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary';
1027
-        switch ($button_size) {
1028
-            case 'xs':
1029
-            case 'extra-small':
1030
-                $button_css_attributes .= ' button-xs';
1031
-                break;
1032
-            case 'sm':
1033
-            case 'small':
1034
-                $button_css_attributes .= ' button-sm';
1035
-                break;
1036
-            case 'lg':
1037
-            case 'large':
1038
-                $button_css_attributes .= ' button-lg';
1039
-                break;
1040
-            case 'block':
1041
-                $button_css_attributes .= ' button-block';
1042
-                break;
1043
-            case 'md':
1044
-            case 'medium':
1045
-            default:
1046
-                $button_css_attributes .= '';
1047
-        }
1048
-        $this->_button_css_attributes .= ! empty($other_attributes)
1049
-            ? $button_css_attributes . ' ' . $other_attributes
1050
-            : $button_css_attributes;
1051
-    }
1052
-
1053
-
1054
-
1055
-    /**
1056
-     * @return string
1057
-     */
1058
-    public function button_css_attributes()
1059
-    {
1060
-        if (empty($this->_button_css_attributes)) {
1061
-            $this->set_button_css_attributes();
1062
-        }
1063
-        return $this->_button_css_attributes;
1064
-    }
1065
-
1066
-
1067
-
1068
-    /**
1069
-     * find_form_data_for_this_section
1070
-     * using this section's name and its parents, finds the value of the form data that corresponds to it.
1071
-     * For example, if this form section's HTML name is my_form[subform][form_input_1],
1072
-     * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1'].
1073
-     * (If that doesn't exist, we also check for this subsection's name
1074
-     * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].)
1075
-     * This function finds its value in the form.
1076
-     *
1077
-     * @param array $req_data
1078
-     * @return mixed whatever the raw value of this form section is in the request data
1079
-     * @throws \EE_Error
1080
-     */
1081
-    public function find_form_data_for_this_section($req_data)
1082
-    {
1083
-        $name_parts = $this->getInputNameParts();
1084
-        // now get the value for the input
1085
-        $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1086
-        // check if this thing's name is at the TOP level of the request data
1087
-        if ($value === null && isset($req_data[ $this->name() ])) {
1088
-            $value = $req_data[ $this->name() ];
1089
-        }
1090
-        return $value;
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     * If this input's name is something like "foo[bar][baz]"
1097
-     * returns an array like `array('foo','bar',baz')`
1098
-     * @return array
1099
-     */
1100
-    protected function getInputNameParts()
1101
-    {
1102
-        // break up the html name by "[]"
1103
-        if (strpos($this->html_name(), '[') !== false) {
1104
-            $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1105
-        } else {
1106
-            $before_any_brackets = $this->html_name();
1107
-        }
1108
-        // grab all of the segments
1109
-        preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1110
-        if (isset($matches[1]) && is_array($matches[1])) {
1111
-            $name_parts = $matches[1];
1112
-            array_unshift($name_parts, $before_any_brackets);
1113
-        } else {
1114
-            $name_parts = array($before_any_brackets);
1115
-        }
1116
-        return $name_parts;
1117
-    }
1118
-
1119
-
1120
-
1121
-    /**
1122
-     * @param array $html_name_parts
1123
-     * @param array $req_data
1124
-     * @return array | NULL
1125
-     */
1126
-    public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1127
-    {
1128
-        $first_part_to_consider = array_shift($html_name_parts);
1129
-        if (isset($req_data[ $first_part_to_consider ])) {
1130
-            if (empty($html_name_parts)) {
1131
-                return $req_data[ $first_part_to_consider ];
1132
-            } else {
1133
-                return $this->findRequestForSectionUsingNameParts(
1134
-                    $html_name_parts,
1135
-                    $req_data[ $first_part_to_consider ]
1136
-                );
1137
-            }
1138
-        } else {
1139
-            return null;
1140
-        }
1141
-    }
1142
-
1143
-
1144
-
1145
-    /**
1146
-     * Checks if this form input's data is in the request data
1147
-     *
1148
-     * @param array $req_data like $_POST
1149
-     * @return boolean
1150
-     * @throws \EE_Error
1151
-     */
1152
-    public function form_data_present_in($req_data = null)
1153
-    {
1154
-        if ($req_data === null) {
1155
-            $req_data = $_POST;
1156
-        }
1157
-        $checked_value = $this->find_form_data_for_this_section($req_data);
1158
-        if ($checked_value !== null) {
1159
-            return true;
1160
-        } else {
1161
-            return false;
1162
-        }
1163
-    }
1164
-
1165
-
1166
-
1167
-    /**
1168
-     * Overrides parent to add js data from validation and display strategies
1169
-     *
1170
-     * @param array $form_other_js_data
1171
-     * @return array
1172
-     */
1173
-    public function get_other_js_data($form_other_js_data = array())
1174
-    {
1175
-        $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data);
1176
-        return $form_other_js_data;
1177
-    }
1178
-
1179
-
1180
-
1181
-    /**
1182
-     * Gets other JS data for localization from this input's strategies, like
1183
-     * the validation strategies and the display strategy
1184
-     *
1185
-     * @param array $form_other_js_data
1186
-     * @return array
1187
-     */
1188
-    public function get_other_js_data_from_strategies($form_other_js_data = array())
1189
-    {
1190
-        $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1191
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1192
-            $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1193
-        }
1194
-        return $form_other_js_data;
1195
-    }
1196
-
1197
-
1198
-
1199
-    /**
1200
-     * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1201
-     *
1202
-     * @return void
1203
-     */
1204
-    public function enqueue_js()
1205
-    {
1206
-        // ask our display strategy and validation strategies if they have js to enqueue
1207
-        $this->enqueue_js_from_strategies();
1208
-    }
1209
-
1210
-
1211
-
1212
-    /**
1213
-     * Tells strategies when its ok to enqueue their js and css
1214
-     *
1215
-     * @return void
1216
-     */
1217
-    public function enqueue_js_from_strategies()
1218
-    {
1219
-        $this->get_display_strategy()->enqueue_js();
1220
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1221
-            $validation_strategy->enqueue_js();
1222
-        }
1223
-    }
1224
-
1225
-
1226
-
1227
-    /**
1228
-     * Gets the default value set on the input (not the current value, which may have been
1229
-     * changed because of a form submission). If no default was set, this us null.
1230
-     * @return mixed
1231
-     */
1232
-    public function get_default()
1233
-    {
1234
-        return $this->_default;
1235
-    }
1236
-
1237
-
1238
-
1239
-    /**
1240
-     * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1241
-     * and server-side if any input was received it will be ignored
1242
-     */
1243
-    public function disable($disable = true)
1244
-    {
1245
-        $disabled_attribute = ' disabled="disabled"';
1246
-        $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1247
-        if ($this->disabled) {
1248
-            if (strpos($this->_other_html_attributes, $disabled_attribute) === false) {
1249
-                $this->_other_html_attributes .= $disabled_attribute;
1250
-            }
1251
-            $this->_set_normalized_value($this->get_default());
1252
-        } else {
1253
-            $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes);
1254
-        }
1255
-    }
1256
-
1257
-
1258
-
1259
-    /**
1260
-     * Returns whether or not this input is currently disabled.
1261
-     * @return bool
1262
-     */
1263
-    public function isDisabled()
1264
-    {
1265
-        return $this->disabled;
1266
-    }
14
+	/**
15
+	 * the input's name attribute
16
+	 *
17
+	 * @var string
18
+	 */
19
+	protected $_html_name;
20
+
21
+	/**
22
+	 * id for the html label tag
23
+	 *
24
+	 * @var string
25
+	 */
26
+	protected $_html_label_id;
27
+
28
+	/**
29
+	 * class for teh html label tag
30
+	 *
31
+	 * @var string
32
+	 */
33
+	protected $_html_label_class;
34
+
35
+	/**
36
+	 * style for teh html label tag
37
+	 *
38
+	 * @var string
39
+	 */
40
+	protected $_html_label_style;
41
+
42
+	/**
43
+	 * text to be placed in the html label
44
+	 *
45
+	 * @var string
46
+	 */
47
+	protected $_html_label_text;
48
+
49
+	/**
50
+	 * the full html label. If used, all other html_label_* properties are invalid
51
+	 *
52
+	 * @var string
53
+	 */
54
+	protected $_html_label;
55
+
56
+	/**
57
+	 * HTML to use for help text (normally placed below form input), in a span which normally
58
+	 * has a class of 'description'
59
+	 *
60
+	 * @var string
61
+	 */
62
+	protected $_html_help_text;
63
+
64
+	/**
65
+	 * CSS classes for displaying the help span
66
+	 *
67
+	 * @var string
68
+	 */
69
+	protected $_html_help_class = 'description';
70
+
71
+	/**
72
+	 * CSS to put in the style attribute on the help span
73
+	 *
74
+	 * @var string
75
+	 */
76
+	protected $_html_help_style;
77
+
78
+	/**
79
+	 * Stores whether or not this input's response is required.
80
+	 * Because certain styling elements may also want to know that this
81
+	 * input is required etc.
82
+	 *
83
+	 * @var boolean
84
+	 */
85
+	protected $_required;
86
+
87
+	/**
88
+	 * css class added to required inputs
89
+	 *
90
+	 * @var string
91
+	 */
92
+	protected $_required_css_class = 'ee-required';
93
+
94
+	/**
95
+	 * css styles applied to button type inputs
96
+	 *
97
+	 * @var string
98
+	 */
99
+	protected $_button_css_attributes;
100
+
101
+	/**
102
+	 * The raw data submitted for this, like in the $_POST super global.
103
+	 * Generally unsafe for usage in client code
104
+	 *
105
+	 * @var mixed string or array
106
+	 */
107
+	protected $_raw_value;
108
+
109
+	/**
110
+	 * Value normalized according to the input's normalization strategy.
111
+	 * The normalization strategy dictates whether this is a string, int, float,
112
+	 * boolean, or array of any of those.
113
+	 *
114
+	 * @var mixed
115
+	 */
116
+	protected $_normalized_value;
117
+
118
+
119
+	/**
120
+	 * Normalized default value either initially set on the input, or provided by calling
121
+	 * set_default().
122
+	 * @var mixed
123
+	 */
124
+	protected $_default;
125
+
126
+	/**
127
+	 * Strategy used for displaying this field.
128
+	 * Child classes must use _get_display_strategy to access it.
129
+	 *
130
+	 * @var EE_Display_Strategy_Base
131
+	 */
132
+	private $_display_strategy;
133
+
134
+	/**
135
+	 * Gets all the validation strategies used on this field
136
+	 *
137
+	 * @var EE_Validation_Strategy_Base[]
138
+	 */
139
+	private $_validation_strategies = array();
140
+
141
+	/**
142
+	 * The normalization strategy for this field
143
+	 *
144
+	 * @var EE_Normalization_Strategy_Base
145
+	 */
146
+	private $_normalization_strategy;
147
+
148
+	/**
149
+	 * Strategy for removing sensitive data after we're done with the form input
150
+	 *
151
+	 * @var EE_Sensitive_Data_Removal_Base
152
+	 */
153
+	protected $_sensitive_data_removal_strategy;
154
+
155
+	/**
156
+	 * Whether this input has been disabled or not.
157
+	 * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
158
+	 * (Client-side code that wants to dynamically disable it must also add this hidden input).
159
+	 * When the form is submitted, if the input is disabled in the PHP formsection, then input is ignored.
160
+	 * If the input is missing from the $_REQUEST data but the hidden input indicating the input is disabled, then the input is again ignored.
161
+	 *
162
+	 * @var boolean
163
+	 */
164
+	protected $disabled = false;
165
+
166
+
167
+
168
+	/**
169
+	 * @param array                         $input_args       {
170
+	 * @type string                         $html_name        the html name for the input
171
+	 * @type string                         $html_label_id    the id attribute to give to the html label tag
172
+	 * @type string                         $html_label_class the class attribute to give to the html label tag
173
+	 * @type string                         $html_label_style the style attribute to give ot teh label tag
174
+	 * @type string                         $html_label_text  the text to put in the label tag
175
+	 * @type string                         $html_label       the full html label. If used,
176
+	 *                                                        all other html_label_* args are invalid
177
+	 * @type string                         $html_help_text   text to put in help element
178
+	 * @type string                         $html_help_style  style attribute to give to teh help element
179
+	 * @type string                         $html_help_class  class attribute to give to the help element
180
+	 * @type string                         $default          default value NORMALIZED (eg, if providing the default
181
+	 *       for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0')
182
+	 * @type EE_Display_Strategy_Base       $display          strategy
183
+	 * @type EE_Normalization_Strategy_Base $normalization_strategy
184
+	 * @type EE_Validation_Strategy_Base[]  $validation_strategies
185
+	 * @type boolean                        $ignore_input special argument which can be used to avoid adding any validation strategies,
186
+	 *                                                    and sets the normalization strategy to the Null normalization. This is good
187
+	 *                                                    when you want the input to be totally ignored server-side (like when using
188
+	 *                                                    React.js form inputs)
189
+	 *                                                        }
190
+	 */
191
+	public function __construct($input_args = array())
192
+	{
193
+		$input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
194
+		// the following properties must be cast as arrays
195
+		if (isset($input_args['validation_strategies'])) {
196
+			foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
197
+				if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
198
+					$this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
199
+				}
200
+			}
201
+			unset($input_args['validation_strategies']);
202
+		}
203
+		if (isset($input_args['ignore_input'])) {
204
+			$this->_validation_strategies = array();
205
+		}
206
+		// loop thru incoming options
207
+		foreach ($input_args as $key => $value) {
208
+			// add underscore to $key to match property names
209
+			$_key = '_' . $key;
210
+			if (property_exists($this, $_key)) {
211
+				$this->{$_key} = $value;
212
+			}
213
+		}
214
+		// ensure that "required" is set correctly
215
+		$this->set_required(
216
+			$this->_required,
217
+			isset($input_args['required_validation_error_message'])
218
+			? $input_args['required_validation_error_message']
219
+			: null
220
+		);
221
+		// $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
222
+		$this->_display_strategy->_construct_finalize($this);
223
+		foreach ($this->_validation_strategies as $validation_strategy) {
224
+			$validation_strategy->_construct_finalize($this);
225
+		}
226
+		if (isset($input_args['ignore_input'])) {
227
+			$this->_normalization_strategy = new EE_Null_Normalization();
228
+		}
229
+		if (! $this->_normalization_strategy) {
230
+				$this->_normalization_strategy = new EE_Text_Normalization();
231
+		}
232
+		$this->_normalization_strategy->_construct_finalize($this);
233
+		// at least we can use the normalization strategy to populate the default
234
+		if (isset($input_args['default'])) {
235
+			$this->set_default($input_args['default']);
236
+			unset($input_args['default']);
237
+		}
238
+		if (! $this->_sensitive_data_removal_strategy) {
239
+			$this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
240
+		}
241
+		$this->_sensitive_data_removal_strategy->_construct_finalize($this);
242
+		parent::__construct($input_args);
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * Sets the html_name to its default value, if none was specified in teh constructor.
249
+	 * Calculation involves using the name and the parent's html_name
250
+	 *
251
+	 * @throws \EE_Error
252
+	 */
253
+	protected function _set_default_html_name_if_empty()
254
+	{
255
+		if (! $this->_html_name) {
256
+			$this->_html_name = $this->name();
257
+			if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) {
258
+				$this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
259
+			}
260
+		}
261
+	}
262
+
263
+
264
+
265
+	/**
266
+	 * @param $parent_form_section
267
+	 * @param $name
268
+	 * @throws \EE_Error
269
+	 */
270
+	public function _construct_finalize($parent_form_section, $name)
271
+	{
272
+		parent::_construct_finalize($parent_form_section, $name);
273
+		if ($this->_html_label === null && $this->_html_label_text === null) {
274
+			$this->_html_label_text = ucwords(str_replace("_", " ", $name));
275
+		}
276
+		do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * Returns the strategy for displaying this form input. If none is set, throws an exception.
283
+	 *
284
+	 * @return EE_Display_Strategy_Base
285
+	 * @throws EE_Error
286
+	 */
287
+	protected function _get_display_strategy()
288
+	{
289
+		$this->ensure_construct_finalized_called();
290
+		if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
291
+			throw new EE_Error(
292
+				sprintf(
293
+					__(
294
+						"Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
295
+						"event_espresso"
296
+					),
297
+					$this->html_name(),
298
+					$this->html_id()
299
+				)
300
+			);
301
+		} else {
302
+			return $this->_display_strategy;
303
+		}
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * Sets the display strategy.
310
+	 *
311
+	 * @param EE_Display_Strategy_Base $strategy
312
+	 */
313
+	protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
314
+	{
315
+		$this->_display_strategy = $strategy;
316
+	}
317
+
318
+
319
+
320
+	/**
321
+	 * Sets the sanitization strategy
322
+	 *
323
+	 * @param EE_Normalization_Strategy_Base $strategy
324
+	 */
325
+	protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
326
+	{
327
+		$this->_normalization_strategy = $strategy;
328
+	}
329
+
330
+
331
+
332
+	/**
333
+	 * Gets sensitive_data_removal_strategy
334
+	 *
335
+	 * @return EE_Sensitive_Data_Removal_Base
336
+	 */
337
+	public function get_sensitive_data_removal_strategy()
338
+	{
339
+		return $this->_sensitive_data_removal_strategy;
340
+	}
341
+
342
+
343
+
344
+	/**
345
+	 * Sets sensitive_data_removal_strategy
346
+	 *
347
+	 * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
348
+	 * @return boolean
349
+	 */
350
+	public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
351
+	{
352
+		$this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * Gets the display strategy for this input
359
+	 *
360
+	 * @return EE_Display_Strategy_Base
361
+	 */
362
+	public function get_display_strategy()
363
+	{
364
+		return $this->_display_strategy;
365
+	}
366
+
367
+
368
+
369
+	/**
370
+	 * Overwrites the display strategy
371
+	 *
372
+	 * @param EE_Display_Strategy_Base $display_strategy
373
+	 */
374
+	public function set_display_strategy($display_strategy)
375
+	{
376
+		$this->_display_strategy = $display_strategy;
377
+		$this->_display_strategy->_construct_finalize($this);
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * Gets the normalization strategy set on this input
384
+	 *
385
+	 * @return EE_Normalization_Strategy_Base
386
+	 */
387
+	public function get_normalization_strategy()
388
+	{
389
+		return $this->_normalization_strategy;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * Overwrites the normalization strategy
396
+	 *
397
+	 * @param EE_Normalization_Strategy_Base $normalization_strategy
398
+	 */
399
+	public function set_normalization_strategy($normalization_strategy)
400
+	{
401
+		$this->_normalization_strategy = $normalization_strategy;
402
+		$this->_normalization_strategy->_construct_finalize($this);
403
+	}
404
+
405
+
406
+
407
+	/**
408
+	 * Returns all teh validation strategies which apply to this field, numerically indexed
409
+	 *
410
+	 * @return EE_Validation_Strategy_Base[]
411
+	 */
412
+	public function get_validation_strategies()
413
+	{
414
+		return $this->_validation_strategies;
415
+	}
416
+
417
+
418
+
419
+	/**
420
+	 * Adds this strategy to the field so it will be used in both JS validation and server-side validation
421
+	 *
422
+	 * @param EE_Validation_Strategy_Base $validation_strategy
423
+	 * @return void
424
+	 */
425
+	protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
426
+	{
427
+		$validation_strategy->_construct_finalize($this);
428
+		$this->_validation_strategies[] = $validation_strategy;
429
+	}
430
+
431
+
432
+
433
+	/**
434
+	 * Adds a new validation strategy onto the form input
435
+	 *
436
+	 * @param EE_Validation_Strategy_Base $validation_strategy
437
+	 * @return void
438
+	 */
439
+	public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
440
+	{
441
+		$this->_add_validation_strategy($validation_strategy);
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * The classname of the validation strategy to remove
448
+	 *
449
+	 * @param string $validation_strategy_classname
450
+	 */
451
+	public function remove_validation_strategy($validation_strategy_classname)
452
+	{
453
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
454
+			if ($validation_strategy instanceof $validation_strategy_classname
455
+				|| is_subclass_of($validation_strategy, $validation_strategy_classname)
456
+			) {
457
+				unset($this->_validation_strategies[ $key ]);
458
+			}
459
+		}
460
+	}
461
+
462
+
463
+
464
+	/**
465
+	 * returns true if input employs any of the validation strategy defined by the supplied array of classnames
466
+	 *
467
+	 * @param array $validation_strategy_classnames
468
+	 * @return bool
469
+	 */
470
+	public function has_validation_strategy($validation_strategy_classnames)
471
+	{
472
+		$validation_strategy_classnames = is_array($validation_strategy_classnames)
473
+			? $validation_strategy_classnames
474
+			: array($validation_strategy_classnames);
475
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
476
+			if (in_array($key, $validation_strategy_classnames)) {
477
+				return true;
478
+			}
479
+		}
480
+		return false;
481
+	}
482
+
483
+
484
+
485
+	/**
486
+	 * Gets the HTML
487
+	 *
488
+	 * @return string
489
+	 */
490
+	public function get_html()
491
+	{
492
+		return $this->_parent_section->get_html_for_input($this);
493
+	}
494
+
495
+
496
+
497
+	/**
498
+	 * Gets the HTML for the input itself (no label or errors) according to the
499
+	 * input's display strategy
500
+	 * Makes sure the JS and CSS are enqueued for it
501
+	 *
502
+	 * @return string
503
+	 * @throws \EE_Error
504
+	 */
505
+	public function get_html_for_input()
506
+	{
507
+		return $this->_form_html_filter
508
+			? $this->_form_html_filter->filterHtml(
509
+				$this->_get_display_strategy()->display(),
510
+				$this
511
+			)
512
+			: $this->_get_display_strategy()->display();
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * @return string
519
+	 */
520
+	public function html_other_attributes()
521
+	{
522
+		EE_Error::doing_it_wrong(
523
+			__METHOD__,
524
+			sprintf(
525
+				esc_html__(
526
+					'This method is no longer in use. You should replace it by %s',
527
+					'event_espresso'
528
+				),
529
+				'EE_Form_Section_Base::other_html_attributes()'
530
+			),
531
+			'4.10.2.p'
532
+		);
533
+
534
+		return $this->other_html_attributes();
535
+	}
536
+
537
+
538
+
539
+	/**
540
+	 * @param string $html_other_attributes
541
+	 */
542
+	public function set_html_other_attributes($html_other_attributes)
543
+	{
544
+		EE_Error::doing_it_wrong(
545
+			__METHOD__,
546
+			sprintf(
547
+				esc_html__(
548
+					'This method is no longer in use. You should replace it by %s',
549
+					'event_espresso'
550
+				),
551
+				'EE_Form_Section_Base::set_other_html_attributes()'
552
+			),
553
+			'4.10.2.p'
554
+		);
555
+
556
+		$this->set_other_html_attributes($html_other_attributes);
557
+	}
558
+
559
+
560
+
561
+	/**
562
+	 * Gets the HTML for displaying the label for this form input
563
+	 * according to the form section's layout strategy
564
+	 *
565
+	 * @return string
566
+	 */
567
+	public function get_html_for_label()
568
+	{
569
+		return $this->_parent_section->get_layout_strategy()->display_label($this);
570
+	}
571
+
572
+
573
+
574
+	/**
575
+	 * Gets the HTML for displaying the errors section for this form input
576
+	 * according to the form section's layout strategy
577
+	 *
578
+	 * @return string
579
+	 */
580
+	public function get_html_for_errors()
581
+	{
582
+		return $this->_parent_section->get_layout_strategy()->display_errors($this);
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 * Gets the HTML for displaying the help text for this form input
589
+	 * according to the form section's layout strategy
590
+	 *
591
+	 * @return string
592
+	 */
593
+	public function get_html_for_help()
594
+	{
595
+		return $this->_parent_section->get_layout_strategy()->display_help_text($this);
596
+	}
597
+
598
+
599
+
600
+	/**
601
+	 * Validates the input's sanitized value (assumes _sanitize() has already been called)
602
+	 * and returns whether or not the form input's submitted value is value
603
+	 *
604
+	 * @return boolean
605
+	 */
606
+	protected function _validate()
607
+	{
608
+		if ($this->isDisabled()) {
609
+			return true;
610
+		}
611
+		foreach ($this->_validation_strategies as $validation_strategy) {
612
+			if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
613
+				try {
614
+					$validation_strategy->validate($this->normalized_value());
615
+				} catch (EE_Validation_Error $e) {
616
+					$this->add_validation_error($e);
617
+				}
618
+			}
619
+		}
620
+		if ($this->get_validation_errors()) {
621
+			return false;
622
+		} else {
623
+			return true;
624
+		}
625
+	}
626
+
627
+
628
+
629
+	/**
630
+	 * Performs basic sanitization on this value. But what sanitization can be performed anyways?
631
+	 * This value MIGHT be allowed to have tags, so we can't really remove them.
632
+	 *
633
+	 * @param string $value
634
+	 * @return null|string
635
+	 */
636
+	protected function _sanitize($value)
637
+	{
638
+		return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null;
639
+	}
640
+
641
+
642
+
643
+	/**
644
+	 * Picks out the form value that relates to this form input,
645
+	 * and stores it as the sanitized value on the form input, and sets the normalized value.
646
+	 * Returns whether or not any validation errors occurred
647
+	 *
648
+	 * @param array $req_data like $_POST
649
+	 * @return boolean whether or not there was an error
650
+	 * @throws \EE_Error
651
+	 */
652
+	protected function _normalize($req_data)
653
+	{
654
+		// any existing validation errors don't apply so clear them
655
+		$this->_validation_errors = array();
656
+		// if the input is disabled, ignore whatever input was sent in
657
+		if ($this->isDisabled()) {
658
+			$this->_set_raw_value(null);
659
+			$this->_set_normalized_value($this->get_default());
660
+			return false;
661
+		}
662
+		try {
663
+			$raw_input = $this->find_form_data_for_this_section($req_data);
664
+			// super simple sanitization for now
665
+			if (is_array($raw_input)) {
666
+				$raw_value = array();
667
+				foreach ($raw_input as $key => $value) {
668
+					$raw_value[ $key ] = $this->_sanitize($value);
669
+				}
670
+				$this->_set_raw_value($raw_value);
671
+			} else {
672
+				$this->_set_raw_value($this->_sanitize($raw_input));
673
+			}
674
+			// we want to mostly leave the input alone in case we need to re-display it to the user
675
+			$this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
676
+			return false;
677
+		} catch (EE_Validation_Error $e) {
678
+			$this->add_validation_error($e);
679
+			return true;
680
+		}
681
+	}
682
+
683
+
684
+
685
+	/**
686
+	 * @return string
687
+	 */
688
+	public function html_name()
689
+	{
690
+		$this->_set_default_html_name_if_empty();
691
+		return $this->_html_name;
692
+	}
693
+
694
+
695
+
696
+	/**
697
+	 * @return string
698
+	 */
699
+	public function html_label_id()
700
+	{
701
+		return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl';
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 * @return string
708
+	 */
709
+	public function html_label_class()
710
+	{
711
+		return $this->_html_label_class;
712
+	}
713
+
714
+
715
+
716
+	/**
717
+	 * @return string
718
+	 */
719
+	public function html_label_style()
720
+	{
721
+		return $this->_html_label_style;
722
+	}
723
+
724
+
725
+
726
+	/**
727
+	 * @return string
728
+	 */
729
+	public function html_label_text()
730
+	{
731
+		return $this->_html_label_text;
732
+	}
733
+
734
+
735
+
736
+	/**
737
+	 * @return string
738
+	 */
739
+	public function html_help_text()
740
+	{
741
+		return $this->_html_help_text;
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * @return string
748
+	 */
749
+	public function html_help_class()
750
+	{
751
+		return $this->_html_help_class;
752
+	}
753
+
754
+
755
+
756
+	/**
757
+	 * @return string
758
+	 */
759
+	public function html_help_style()
760
+	{
761
+		return $this->_html_style;
762
+	}
763
+
764
+
765
+
766
+	/**
767
+	 * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
768
+	 * Please note that almost all client code should instead use the normalized_value;
769
+	 * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
770
+	 * mostly by escaping quotes)
771
+	 * Note, we do not store the exact original value sent in the user's request because
772
+	 * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
773
+	 * in which case, we would have stored the malicious content to our database.
774
+	 *
775
+	 * @return string
776
+	 */
777
+	public function raw_value()
778
+	{
779
+		return $this->_raw_value;
780
+	}
781
+
782
+
783
+
784
+	/**
785
+	 * Returns a string safe to usage in form inputs when displaying, because
786
+	 * it escapes all html entities
787
+	 *
788
+	 * @return string
789
+	 */
790
+	public function raw_value_in_form()
791
+	{
792
+		return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8');
793
+	}
794
+
795
+
796
+
797
+	/**
798
+	 * returns the value after it's been sanitized, and then converted into it's proper type
799
+	 * in PHP. Eg, a string, an int, an array,
800
+	 *
801
+	 * @return mixed
802
+	 */
803
+	public function normalized_value()
804
+	{
805
+		return $this->_normalized_value;
806
+	}
807
+
808
+
809
+
810
+	/**
811
+	 * Returns the normalized value is a presentable way. By default this is just
812
+	 * the normalized value by itself, but it can be overridden for when that's not
813
+	 * the best thing to display
814
+	 *
815
+	 * @return string
816
+	 */
817
+	public function pretty_value()
818
+	{
819
+		return $this->_normalized_value;
820
+	}
821
+
822
+
823
+
824
+	/**
825
+	 * When generating the JS for the jquery validation rules like<br>
826
+	 * <code>$( "#myform" ).validate({
827
+	 * rules: {
828
+	 * password: "required",
829
+	 * password_again: {
830
+	 * equalTo: "#password"
831
+	 * }
832
+	 * }
833
+	 * });</code>
834
+	 * if this field had the name 'password_again', it should return
835
+	 * <br><code>password_again: {
836
+	 * equalTo: "#password"
837
+	 * }</code>
838
+	 *
839
+	 * @return array
840
+	 */
841
+	public function get_jquery_validation_rules()
842
+	{
843
+		$jquery_validation_js = array();
844
+		$jquery_validation_rules = array();
845
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
846
+			$jquery_validation_rules = array_replace_recursive(
847
+				$jquery_validation_rules,
848
+				$validation_strategy->get_jquery_validation_rule_array()
849
+			);
850
+		}
851
+		if (! empty($jquery_validation_rules)) {
852
+			foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
853
+				$jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
854
+			}
855
+		}
856
+		return $jquery_validation_js;
857
+	}
858
+
859
+
860
+
861
+	/**
862
+	 * Sets the input's default value for use in displaying in the form. Note: value should be
863
+	 * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
864
+	 *
865
+	 * @param mixed $value
866
+	 * @return void
867
+	 */
868
+	public function set_default($value)
869
+	{
870
+		$this->_default = $value;
871
+		$this->_set_normalized_value($value);
872
+		$this->_set_raw_value($value);
873
+	}
874
+
875
+
876
+
877
+	/**
878
+	 * Sets the normalized value on this input
879
+	 *
880
+	 * @param mixed $value
881
+	 */
882
+	protected function _set_normalized_value($value)
883
+	{
884
+		$this->_normalized_value = $value;
885
+	}
886
+
887
+
888
+
889
+	/**
890
+	 * Sets the raw value on this input (ie, exactly as the user submitted it)
891
+	 *
892
+	 * @param mixed $value
893
+	 */
894
+	protected function _set_raw_value($value)
895
+	{
896
+		$this->_raw_value = $this->_normalization_strategy->unnormalize($value);
897
+	}
898
+
899
+
900
+
901
+	/**
902
+	 * Sets the HTML label text after it has already been defined
903
+	 *
904
+	 * @param string $label
905
+	 * @return void
906
+	 */
907
+	public function set_html_label_text($label)
908
+	{
909
+		$this->_html_label_text = $label;
910
+	}
911
+
912
+
913
+
914
+	/**
915
+	 * Sets whether or not this field is required, and adjusts the validation strategy.
916
+	 * If you want to use the EE_Conditionally_Required_Validation_Strategy,
917
+	 * please add it as a validation strategy using add_validation_strategy as normal
918
+	 *
919
+	 * @param boolean $required boolean
920
+	 * @param null    $required_text
921
+	 */
922
+	public function set_required($required = true, $required_text = null)
923
+	{
924
+		$required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
925
+		// whether $required is a string or a boolean, we want to add a required validation strategy
926
+		if ($required) {
927
+			$this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
928
+		} else {
929
+			$this->remove_validation_strategy('EE_Required_Validation_Strategy');
930
+		}
931
+		$this->_required = $required;
932
+	}
933
+
934
+
935
+
936
+	/**
937
+	 * Returns whether or not this field is required
938
+	 *
939
+	 * @return boolean
940
+	 */
941
+	public function required()
942
+	{
943
+		return $this->_required;
944
+	}
945
+
946
+
947
+
948
+	/**
949
+	 * @param string $required_css_class
950
+	 */
951
+	public function set_required_css_class($required_css_class)
952
+	{
953
+		$this->_required_css_class = $required_css_class;
954
+	}
955
+
956
+
957
+
958
+	/**
959
+	 * @return string
960
+	 */
961
+	public function required_css_class()
962
+	{
963
+		return $this->_required_css_class;
964
+	}
965
+
966
+
967
+
968
+	/**
969
+	 * @param bool $add_required
970
+	 * @return string
971
+	 */
972
+	public function html_class($add_required = false)
973
+	{
974
+		return $add_required && $this->required()
975
+			? $this->required_css_class() . ' ' . $this->_html_class
976
+			: $this->_html_class;
977
+	}
978
+
979
+
980
+	/**
981
+	 * Sets the help text, in case
982
+	 *
983
+	 * @param string $text
984
+	 */
985
+	public function set_html_help_text($text)
986
+	{
987
+		$this->_html_help_text = $text;
988
+	}
989
+
990
+
991
+
992
+	/**
993
+	 * Uses the sensitive data removal strategy to remove the sensitive data from this
994
+	 * input. If there is any kind of sensitive data removal on this input, we clear
995
+	 * out the raw value completely
996
+	 *
997
+	 * @return void
998
+	 */
999
+	public function clean_sensitive_data()
1000
+	{
1001
+		// if we do ANY kind of sensitive data removal on this, then just clear out the raw value
1002
+		// if we need more logic than this we'll make a strategy for it
1003
+		if ($this->_sensitive_data_removal_strategy
1004
+			&& ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
1005
+		) {
1006
+			$this->_set_raw_value(null);
1007
+		}
1008
+		// and clean the normalized value according to the appropriate strategy
1009
+		$this->_set_normalized_value(
1010
+			$this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
1011
+				$this->_normalized_value
1012
+			)
1013
+		);
1014
+	}
1015
+
1016
+
1017
+
1018
+	/**
1019
+	 * @param bool   $primary
1020
+	 * @param string $button_size
1021
+	 * @param string $other_attributes
1022
+	 */
1023
+	public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1024
+	{
1025
+		$button_css_attributes = 'button';
1026
+		$button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary';
1027
+		switch ($button_size) {
1028
+			case 'xs':
1029
+			case 'extra-small':
1030
+				$button_css_attributes .= ' button-xs';
1031
+				break;
1032
+			case 'sm':
1033
+			case 'small':
1034
+				$button_css_attributes .= ' button-sm';
1035
+				break;
1036
+			case 'lg':
1037
+			case 'large':
1038
+				$button_css_attributes .= ' button-lg';
1039
+				break;
1040
+			case 'block':
1041
+				$button_css_attributes .= ' button-block';
1042
+				break;
1043
+			case 'md':
1044
+			case 'medium':
1045
+			default:
1046
+				$button_css_attributes .= '';
1047
+		}
1048
+		$this->_button_css_attributes .= ! empty($other_attributes)
1049
+			? $button_css_attributes . ' ' . $other_attributes
1050
+			: $button_css_attributes;
1051
+	}
1052
+
1053
+
1054
+
1055
+	/**
1056
+	 * @return string
1057
+	 */
1058
+	public function button_css_attributes()
1059
+	{
1060
+		if (empty($this->_button_css_attributes)) {
1061
+			$this->set_button_css_attributes();
1062
+		}
1063
+		return $this->_button_css_attributes;
1064
+	}
1065
+
1066
+
1067
+
1068
+	/**
1069
+	 * find_form_data_for_this_section
1070
+	 * using this section's name and its parents, finds the value of the form data that corresponds to it.
1071
+	 * For example, if this form section's HTML name is my_form[subform][form_input_1],
1072
+	 * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1'].
1073
+	 * (If that doesn't exist, we also check for this subsection's name
1074
+	 * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].)
1075
+	 * This function finds its value in the form.
1076
+	 *
1077
+	 * @param array $req_data
1078
+	 * @return mixed whatever the raw value of this form section is in the request data
1079
+	 * @throws \EE_Error
1080
+	 */
1081
+	public function find_form_data_for_this_section($req_data)
1082
+	{
1083
+		$name_parts = $this->getInputNameParts();
1084
+		// now get the value for the input
1085
+		$value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1086
+		// check if this thing's name is at the TOP level of the request data
1087
+		if ($value === null && isset($req_data[ $this->name() ])) {
1088
+			$value = $req_data[ $this->name() ];
1089
+		}
1090
+		return $value;
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 * If this input's name is something like "foo[bar][baz]"
1097
+	 * returns an array like `array('foo','bar',baz')`
1098
+	 * @return array
1099
+	 */
1100
+	protected function getInputNameParts()
1101
+	{
1102
+		// break up the html name by "[]"
1103
+		if (strpos($this->html_name(), '[') !== false) {
1104
+			$before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '['));
1105
+		} else {
1106
+			$before_any_brackets = $this->html_name();
1107
+		}
1108
+		// grab all of the segments
1109
+		preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches);
1110
+		if (isset($matches[1]) && is_array($matches[1])) {
1111
+			$name_parts = $matches[1];
1112
+			array_unshift($name_parts, $before_any_brackets);
1113
+		} else {
1114
+			$name_parts = array($before_any_brackets);
1115
+		}
1116
+		return $name_parts;
1117
+	}
1118
+
1119
+
1120
+
1121
+	/**
1122
+	 * @param array $html_name_parts
1123
+	 * @param array $req_data
1124
+	 * @return array | NULL
1125
+	 */
1126
+	public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1127
+	{
1128
+		$first_part_to_consider = array_shift($html_name_parts);
1129
+		if (isset($req_data[ $first_part_to_consider ])) {
1130
+			if (empty($html_name_parts)) {
1131
+				return $req_data[ $first_part_to_consider ];
1132
+			} else {
1133
+				return $this->findRequestForSectionUsingNameParts(
1134
+					$html_name_parts,
1135
+					$req_data[ $first_part_to_consider ]
1136
+				);
1137
+			}
1138
+		} else {
1139
+			return null;
1140
+		}
1141
+	}
1142
+
1143
+
1144
+
1145
+	/**
1146
+	 * Checks if this form input's data is in the request data
1147
+	 *
1148
+	 * @param array $req_data like $_POST
1149
+	 * @return boolean
1150
+	 * @throws \EE_Error
1151
+	 */
1152
+	public function form_data_present_in($req_data = null)
1153
+	{
1154
+		if ($req_data === null) {
1155
+			$req_data = $_POST;
1156
+		}
1157
+		$checked_value = $this->find_form_data_for_this_section($req_data);
1158
+		if ($checked_value !== null) {
1159
+			return true;
1160
+		} else {
1161
+			return false;
1162
+		}
1163
+	}
1164
+
1165
+
1166
+
1167
+	/**
1168
+	 * Overrides parent to add js data from validation and display strategies
1169
+	 *
1170
+	 * @param array $form_other_js_data
1171
+	 * @return array
1172
+	 */
1173
+	public function get_other_js_data($form_other_js_data = array())
1174
+	{
1175
+		$form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data);
1176
+		return $form_other_js_data;
1177
+	}
1178
+
1179
+
1180
+
1181
+	/**
1182
+	 * Gets other JS data for localization from this input's strategies, like
1183
+	 * the validation strategies and the display strategy
1184
+	 *
1185
+	 * @param array $form_other_js_data
1186
+	 * @return array
1187
+	 */
1188
+	public function get_other_js_data_from_strategies($form_other_js_data = array())
1189
+	{
1190
+		$form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1191
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1192
+			$form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1193
+		}
1194
+		return $form_other_js_data;
1195
+	}
1196
+
1197
+
1198
+
1199
+	/**
1200
+	 * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1201
+	 *
1202
+	 * @return void
1203
+	 */
1204
+	public function enqueue_js()
1205
+	{
1206
+		// ask our display strategy and validation strategies if they have js to enqueue
1207
+		$this->enqueue_js_from_strategies();
1208
+	}
1209
+
1210
+
1211
+
1212
+	/**
1213
+	 * Tells strategies when its ok to enqueue their js and css
1214
+	 *
1215
+	 * @return void
1216
+	 */
1217
+	public function enqueue_js_from_strategies()
1218
+	{
1219
+		$this->get_display_strategy()->enqueue_js();
1220
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1221
+			$validation_strategy->enqueue_js();
1222
+		}
1223
+	}
1224
+
1225
+
1226
+
1227
+	/**
1228
+	 * Gets the default value set on the input (not the current value, which may have been
1229
+	 * changed because of a form submission). If no default was set, this us null.
1230
+	 * @return mixed
1231
+	 */
1232
+	public function get_default()
1233
+	{
1234
+		return $this->_default;
1235
+	}
1236
+
1237
+
1238
+
1239
+	/**
1240
+	 * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1241
+	 * and server-side if any input was received it will be ignored
1242
+	 */
1243
+	public function disable($disable = true)
1244
+	{
1245
+		$disabled_attribute = ' disabled="disabled"';
1246
+		$this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1247
+		if ($this->disabled) {
1248
+			if (strpos($this->_other_html_attributes, $disabled_attribute) === false) {
1249
+				$this->_other_html_attributes .= $disabled_attribute;
1250
+			}
1251
+			$this->_set_normalized_value($this->get_default());
1252
+		} else {
1253
+			$this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes);
1254
+		}
1255
+	}
1256
+
1257
+
1258
+
1259
+	/**
1260
+	 * Returns whether or not this input is currently disabled.
1261
+	 * @return bool
1262
+	 */
1263
+	public function isDisabled()
1264
+	{
1265
+		return $this->disabled;
1266
+	}
1267 1267
 }
Please login to merge, or discard this patch.
modules/add_new_state/EED_Add_New_State.module.php 2 patches
Indentation   +814 added lines, -814 removed lines patch added patch discarded remove patch
@@ -17,818 +17,818 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @return EED_Module|EED_Add_New_State
22
-     */
23
-    public static function instance()
24
-    {
25
-        return parent::get_instance(__CLASS__);
26
-    }
27
-
28
-
29
-    /**
30
-     * set_hooks - for hooking into EE Core, other modules, etc
31
-     *
32
-     * @return void
33
-     */
34
-    public static function set_hooks()
35
-    {
36
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
37
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
38
-        add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
39
-        add_filter(
40
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
41
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
42
-            1,
43
-            1
44
-        );
45
-        add_filter(
46
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
47
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
48
-            1,
49
-            1
50
-        );
51
-        add_filter(
52
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
53
-            array('EED_Add_New_State', 'unset_new_state_request_params'),
54
-            10,
55
-            1
56
-        );
57
-        add_filter(
58
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
59
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
60
-            10,
61
-            5
62
-        );
63
-        add_filter(
64
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
65
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
66
-            10,
67
-            5
68
-        );
69
-        add_filter(
70
-            'FHEE__EE_State_Select_Input____construct__state_options',
71
-            array('EED_Add_New_State', 'state_options'),
72
-            10,
73
-            1
74
-        );
75
-        add_filter(
76
-            'FHEE__EE_Country_Select_Input____construct__country_options',
77
-            array('EED_Add_New_State', 'country_options'),
78
-            10,
79
-            1
80
-        );
81
-    }
82
-
83
-
84
-    /**
85
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
86
-     *
87
-     * @return void
88
-     */
89
-    public static function set_hooks_admin()
90
-    {
91
-        add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
92
-        add_filter(
93
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
94
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
95
-            1,
96
-            1
97
-        );
98
-        add_filter(
99
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
100
-            array('EED_Add_New_State', 'display_add_new_state_micro_form'),
101
-            1,
102
-            1
103
-        );
104
-        add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
105
-        add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
106
-        add_filter(
107
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
108
-            array('EED_Add_New_State', 'unset_new_state_request_params'),
109
-            10,
110
-            1
111
-        );
112
-        add_action(
113
-            'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
114
-            array('EED_Add_New_State', 'update_country_settings'),
115
-            10,
116
-            3
117
-        );
118
-        add_action(
119
-            'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
120
-            array('EED_Add_New_State', 'update_country_settings'),
121
-            10,
122
-            3
123
-        );
124
-        add_filter(
125
-            'FHEE__EE_State_Select_Input____construct__state_options',
126
-            array('EED_Add_New_State', 'state_options'),
127
-            10,
128
-            1
129
-        );
130
-        add_filter(
131
-            'FHEE__EE_Country_Select_Input____construct__country_options',
132
-            array('EED_Add_New_State', 'country_options'),
133
-            10,
134
-            1
135
-        );
136
-        add_filter(
137
-            'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
138
-            array('EED_Add_New_State', 'filter_checkout_request_params'),
139
-            10,
140
-            1
141
-        );
142
-        add_filter(
143
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
144
-            array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
145
-            10,
146
-            5
147
-        );
148
-        add_filter(
149
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
150
-            array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
151
-            10,
152
-            5
153
-        );
154
-    }
155
-
156
-
157
-    /**
158
-     * @return void
159
-     */
160
-    public static function set_definitions()
161
-    {
162
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
163
-        define(
164
-            'ANS_TEMPLATES_PATH',
165
-            str_replace(
166
-                '\\',
167
-                '/',
168
-                plugin_dir_path(__FILE__)
169
-            ) . 'templates/'
170
-        );
171
-    }
172
-
173
-
174
-    /**
175
-     * @param WP $WP
176
-     * @return void
177
-     */
178
-    public function run($WP)
179
-    {
180
-    }
181
-
182
-
183
-    /**
184
-     * @return void
185
-     */
186
-    public static function translate_js_strings()
187
-    {
188
-        EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
189
-            'In order to proceed, you need to select the Country that your State/Province belongs to.',
190
-            'event_espresso'
191
-        );
192
-        EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
193
-            'In order to proceed, you need to enter the name of your State/Province.',
194
-            'event_espresso'
195
-        );
196
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
197
-            'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
198
-            'event_espresso'
199
-        );
200
-        EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
201
-            'The new state was successfully saved to the database.',
202
-            'event_espresso'
203
-        );
204
-        EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
205
-            'An unknown error has occurred on the server while saving the new state to the database.',
206
-            'event_espresso'
207
-        );
208
-    }
209
-
210
-
211
-    /**
212
-     * @return void
213
-     */
214
-    public static function wp_enqueue_scripts()
215
-    {
216
-        if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
217
-            wp_register_script(
218
-                'add_new_state',
219
-                ANS_ASSETS_URL . 'add_new_state.js',
220
-                array('espresso_core', 'single_page_checkout'),
221
-                EVENT_ESPRESSO_VERSION,
222
-                true
223
-            );
224
-            wp_enqueue_script('add_new_state');
225
-        }
226
-    }
227
-
228
-
229
-
230
-    /**
231
-     * display_add_new_state_micro_form
232
-     *
233
-     * @param EE_Form_Section_Proper $question_group_reg_form
234
-     * @return string
235
-     * @throws EE_Error
236
-     * @throws InvalidArgumentException
237
-     * @throws InvalidDataTypeException
238
-     * @throws InvalidInterfaceException
239
-     */
240
-    public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
241
-    {
242
-        // only add the 'new_state_micro_form' when displaying reg forms,
243
-        // not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
-        $action = EE_Registry::instance()->REQ->get('action', '');
245
-        // is the "state" question in this form section?
246
-        $input = $question_group_reg_form->get_subsection('state');
247
-        if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
-            // ok then all we need to do is make sure the input's HTML name is consistent
249
-            // by forcing it to set it now, like it did while getting the form for display
250
-            if ($input instanceof EE_State_Select_Input) {
251
-                $input->html_name();
252
-            }
253
-            return $question_group_reg_form;
254
-        }
255
-        // we're only doing this for state select inputs
256
-        if ($input instanceof EE_State_Select_Input
257
-            && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
258
-        ) {
259
-            // grab any set values from the request
260
-            $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name());
261
-            $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name());
262
-            $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
263
-            $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
264
-            $country_options = array();
265
-            $countries = EEM_Country::instance()->get_all_countries();
266
-            if (! empty($countries)) {
267
-                foreach ($countries as $country) {
268
-                    if ($country instanceof EE_Country) {
269
-                        $country_options[ $country->ID() ] = $country->name();
270
-                    }
271
-                }
272
-            }
273
-            $new_state_micro_form = new EE_Form_Section_Proper(
274
-                array(
275
-                    'name'            => 'new_state_micro_form',
276
-                    'html_id'         => 'new_state_micro_form',
277
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
278
-                    'subsections'     => array(
279
-                        // add hidden input to indicate that a new state is being added
280
-                        'add_new_state'               => new EE_Hidden_Input(
281
-                            array(
282
-                                'html_name' => str_replace(
283
-                                    'state',
284
-                                    'nsmf_add_new_state',
285
-                                    $input->html_name()
286
-                                ),
287
-                                'html_id'   => str_replace(
288
-                                    'state',
289
-                                    'nsmf_add_new_state',
290
-                                    $input->html_id()
291
-                                ),
292
-                                'default'   => 0,
293
-                            )
294
-                        ),
295
-                        // add link for displaying hidden container
296
-                        'click_here_link'             => new EE_Form_Section_HTML(
297
-                            apply_filters(
298
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
299
-                                EEH_HTML::link(
300
-                                    '',
301
-                                    esc_html__('click here to add a new state/province', 'event_espresso'),
302
-                                    '',
303
-                                    'display-' . $input->html_id(),
304
-                                    'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
305
-                                    '',
306
-                                    'data-target="' . $input->html_id() . '"'
307
-                                )
308
-                            )
309
-                        ),
310
-                        // add initial html for hidden container
311
-                        'add_new_state_micro_form'    => new EE_Form_Section_HTML(
312
-                            apply_filters(
313
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
314
-                                EEH_HTML::div(
315
-                                    '',
316
-                                    $input->html_id() . '-dv',
317
-                                    'ee-form-add-new-state-dv',
318
-                                    'display: none;'
319
-                                ) .
320
-                                EEH_HTML::h6(
321
-                                    esc_html__(
322
-                                        'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
323
-                                        'event_espresso'
324
-                                    )
325
-                                ) .
326
-                                EEH_HTML::ul() .
327
-                                EEH_HTML::li(
328
-                                    esc_html__(
329
-                                        'first select the Country that your State/Province belongs to',
330
-                                        'event_espresso'
331
-                                    )
332
-                                ) .
333
-                                EEH_HTML::li(
334
-                                    esc_html__('enter the name of your State/Province', 'event_espresso')
335
-                                ) .
336
-                                EEH_HTML::li(
337
-                                    esc_html__(
338
-                                        'enter a two to six letter abbreviation for the name of your State/Province',
339
-                                        'event_espresso'
340
-                                    )
341
-                                ) .
342
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
343
-                                EEH_HTML::ulx()
344
-                            )
345
-                        ),
346
-                        // NEW STATE COUNTRY
347
-                        'new_state_country'           => new EE_Country_Select_Input(
348
-                            $country_options,
349
-                            array(
350
-                                'html_name'       => $country_name,
351
-                                'html_id'         => str_replace(
352
-                                    'state',
353
-                                    'nsmf_new_state_country',
354
-                                    $input->html_id()
355
-                                ),
356
-                                'html_class'      => $input->html_class() . ' new-state-country',
357
-                                'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
358
-                                'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
359
-                                'required'        => false,
360
-                            )
361
-                        ),
362
-                        // NEW STATE NAME
363
-                        'new_state_name'              => new EE_Text_Input(
364
-                            array(
365
-                                'html_name'       => $state_name,
366
-                                'html_id'         => str_replace(
367
-                                    'state',
368
-                                    'nsmf_new_state_name',
369
-                                    $input->html_id()
370
-                                ),
371
-                                'html_class'      => $input->html_class() . ' new-state-state',
372
-                                'html_label_text' => esc_html__(
373
-                                    'New State/Province Name',
374
-                                    'event_espresso'
375
-                                ),
376
-                                'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
377
-                                'required'        => false,
378
-                            )
379
-                        ),
380
-                        'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
381
-                        // NEW STATE NAME
382
-                        'new_state_abbrv'             => new EE_Text_Input(
383
-                            array(
384
-                                'html_name'             => $abbrv_name,
385
-                                'html_id'               => str_replace(
386
-                                    'state',
387
-                                    'nsmf_new_state_abbrv',
388
-                                    $input->html_id()
389
-                                ),
390
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
391
-                                'html_label_text'       => esc_html__(
392
-                                    'New State/Province Abbreviation',
393
-                                    'event_espresso'
394
-                                ) . ' *',
395
-                                'other_html_attributes' => 'size="24"',
396
-                                'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
397
-                                'required'              => false,
398
-                            )
399
-                        ),
400
-                        // "submit" button
401
-                        'add_new_state_submit_button' => new EE_Form_Section_HTML(
402
-                            apply_filters(
403
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
-                                EEH_HTML::nbsp(3) .
405
-                                EEH_HTML::link(
406
-                                    '',
407
-                                    esc_html__('ADD', 'event_espresso'),
408
-                                    '',
409
-                                    'submit-' . $new_state_submit_id,
410
-                                    'ee-form-add-new-state-submit button button-secondary',
411
-                                    '',
412
-                                    'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"'
413
-                                )
414
-                            )
415
-                        ),
416
-                        // extra info
417
-                        'add_new_state_extra'         => new EE_Form_Section_HTML(
418
-                            apply_filters(
419
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
420
-                                EEH_HTML::br(2)
421
-                                .
422
-                                EEH_HTML::div('', '', 'small-text')
423
-                                .
424
-                                EEH_HTML::strong(
425
-                                    '* ' .
426
-                                    esc_html__(
427
-                                        'Don\'t know your State/Province Abbreviation?',
428
-                                        'event_espresso'
429
-                                    )
430
-                                )
431
-                                .
432
-                                EEH_HTML::br()
433
-                                .
434
-                                sprintf(
435
-                                    esc_html__(
436
-                                        'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
437
-                                        'event_espresso'
438
-                                    ),
439
-                                    EEH_HTML::link(
440
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
441
-                                        'http://en.wikipedia.org/wiki/ISO_3166-2',
442
-                                        '',
443
-                                        '',
444
-                                        'ee-form-add-new-state-wiki-lnk',
445
-                                        '',
446
-                                        'target="_blank"'
447
-                                    )
448
-                                )
449
-                                .
450
-                                EEH_HTML::divx()
451
-                                .
452
-                                EEH_HTML::br()
453
-                                .
454
-                                EEH_HTML::link(
455
-                                    '',
456
-                                    esc_html__('cancel new State/Province', 'event_espresso'),
457
-                                    '',
458
-                                    'hide-' . $input->html_id(),
459
-                                    'ee-form-cancel-new-state-lnk smaller-text',
460
-                                    '',
461
-                                    'data-target="' . $input->html_id() . '"'
462
-                                )
463
-                                .
464
-                                EEH_HTML::divx()
465
-                                .
466
-                                EEH_HTML::br()
467
-                            )
468
-                        ),
469
-                    ),
470
-                )
471
-            );
472
-            $question_group_reg_form->add_subsections(
473
-                array('new_state_micro_form' => $new_state_micro_form),
474
-                'state',
475
-                false
476
-            );
477
-        }
478
-        return $question_group_reg_form;
479
-    }
480
-
481
-
482
-    /**
483
-     * set_new_state_input_width
484
-     *
485
-     * @return int|string
486
-     * @throws EE_Error
487
-     * @throws InvalidArgumentException
488
-     * @throws InvalidDataTypeException
489
-     * @throws InvalidInterfaceException
490
-     * @throws ReflectionException
491
-     */
492
-    public static function add_new_state()
493
-    {
494
-        $REQ = EE_Registry::instance()->load_core('Request_Handler');
495
-        if (absint($REQ->get('nsmf_add_new_state')) === 1) {
496
-            EE_Registry::instance()->load_model('State');
497
-            // grab country ISO code, new state name, and new state abbreviation
498
-            $state_country = $REQ->is_set('nsmf_new_state_country')
499
-                ? sanitize_text_field($REQ->get('nsmf_new_state_country'))
500
-                : false;
501
-            $state_name = $REQ->is_set('nsmf_new_state_name')
502
-                ? sanitize_text_field($REQ->get('nsmf_new_state_name'))
503
-                : false;
504
-            $state_abbr = $REQ->is_set('nsmf_new_state_abbrv')
505
-                ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
506
-                : false;
507
-            if ($state_country && $state_name && $state_abbr) {
508
-                $new_state = EED_Add_New_State::save_new_state_to_db(
509
-                    array(
510
-                        'CNT_ISO'    => strtoupper($state_country),
511
-                        'STA_abbrev' => strtoupper($state_abbr),
512
-                        'STA_name'   => ucwords($state_name),
513
-                        'STA_active' => false,
514
-                    )
515
-                );
516
-                if ($new_state instanceof EE_State) {
517
-                    // clean house
518
-                    EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
519
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
520
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
521
-                    EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
522
-                    // get any existing new states
523
-                    $new_states = EE_Registry::instance()->SSN->get_session_data(
524
-                        'nsmf_new_states'
525
-                    );
526
-                    $new_states[ $new_state->ID() ] = $new_state;
527
-                    EE_Registry::instance()->SSN->set_session_data(
528
-                        array('nsmf_new_states' => $new_states)
529
-                    );
530
-                    if (EE_Registry::instance()->REQ->ajax) {
531
-                        echo wp_json_encode(
532
-                            array(
533
-                                'success'      => true,
534
-                                'id'           => $new_state->ID(),
535
-                                'name'         => $new_state->name(),
536
-                                'abbrev'       => $new_state->abbrev(),
537
-                                'country_iso'  => $new_state->country_iso(),
538
-                                'country_name' => $new_state->country()->name(),
539
-                            )
540
-                        );
541
-                        exit();
542
-                    }
543
-                    return $new_state->ID();
544
-                }
545
-            } else {
546
-                $error = esc_html__(
547
-                    'A new State/Province could not be added because invalid or missing data was received.',
548
-                    'event_espresso'
549
-                );
550
-                if (EE_Registry::instance()->REQ->ajax) {
551
-                    echo wp_json_encode(array('error' => $error));
552
-                    exit();
553
-                }
554
-                EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
555
-            }
556
-        }
557
-        return false;
558
-    }
559
-
560
-
561
-    /**
562
-     * recursively drills down through request params to remove any that were added by this module
563
-     *
564
-     * @param array $request_params
565
-     * @return array
566
-     */
567
-    public static function filter_checkout_request_params($request_params)
568
-    {
569
-        foreach ($request_params as $form_section) {
570
-            if (is_array($form_section)) {
571
-                EED_Add_New_State::unset_new_state_request_params($form_section);
572
-                EED_Add_New_State::filter_checkout_request_params($form_section);
573
-            }
574
-        }
575
-        return $request_params;
576
-    }
577
-
578
-
579
-    /**
580
-     * @param array $request_params
581
-     * @return array
582
-     */
583
-    public static function unset_new_state_request_params($request_params)
584
-    {
585
-        unset(
586
-            $request_params['new_state_micro_form'],
587
-            $request_params['new_state_micro_add_new_state'],
588
-            $request_params['new_state_micro_new_state_country'],
589
-            $request_params['new_state_micro_new_state_name'],
590
-            $request_params['new_state_micro_new_state_abbrv']
591
-        );
592
-        return $request_params;
593
-    }
594
-
595
-
596
-    /**
597
-     * @param array $props_n_values
598
-     * @return bool
599
-     * @throws EE_Error
600
-     * @throws InvalidArgumentException
601
-     * @throws InvalidDataTypeException
602
-     * @throws InvalidInterfaceException
603
-     */
604
-    public static function save_new_state_to_db($props_n_values = array())
605
-    {
606
-        $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
607
-        if (! empty($existing_state)) {
608
-            return array_pop($existing_state);
609
-        }
610
-        $new_state = EE_State::new_instance($props_n_values);
611
-        if ($new_state instanceof EE_State) {
612
-            $country_settings_url = add_query_arg(
613
-                array(
614
-                    'page'    => 'espresso_general_settings',
615
-                    'action'  => 'country_settings',
616
-                    'country' => $new_state->country_iso(),
617
-                ),
618
-                admin_url('admin.php')
619
-            );
620
-            // if not non-ajax admin
621
-            new PersistentAdminNotice(
622
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
623
-                sprintf(
624
-                    esc_html__(
625
-                        'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
626
-                        'event_espresso'
627
-                    ),
628
-                    '<b>' . $new_state->name() . '</b>',
629
-                    '<b>' . $new_state->abbrev() . '</b>',
630
-                    '<b>' . $new_state->country()->name() . '</b>',
631
-                    '<a href="'
632
-                    . $country_settings_url
633
-                    . '">'
634
-                    . esc_html__(
635
-                        'Event Espresso - General Settings > Countries Tab',
636
-                        'event_espresso'
637
-                    )
638
-                    . '</a>',
639
-                    '<br />'
640
-                )
641
-            );
642
-            $new_state->save();
643
-            EEM_State::instance()->reset_cached_states();
644
-            return $new_state;
645
-        }
646
-        return false;
647
-    }
648
-
649
-
650
-    /**
651
-     * @param string $CNT_ISO
652
-     * @param string $STA_ID
653
-     * @param array  $cols_n_values
654
-     * @return void
655
-     * @throws DomainException
656
-     * @throws EE_Error
657
-     * @throws InvalidArgumentException
658
-     * @throws InvalidDataTypeException
659
-     * @throws InvalidInterfaceException
660
-     */
661
-    public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
662
-    {
663
-        if (! $CNT_ISO) {
664
-            EE_Error::add_error(
665
-                esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
666
-                __FILE__,
667
-                __FUNCTION__,
668
-                __LINE__
669
-            );
670
-        }
671
-        $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
672
-            : false;
673
-        if (! $STA_abbrev && ! empty($STA_ID)) {
674
-            $state = EEM_State::instance()->get_one_by_ID($STA_ID);
675
-            if ($state instanceof EE_State) {
676
-                $STA_abbrev = $state->abbrev();
677
-            }
678
-        }
679
-        if (! $STA_abbrev) {
680
-            EE_Error::add_error(
681
-                esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
682
-                __FILE__,
683
-                __FUNCTION__,
684
-                __LINE__
685
-            );
686
-        }
687
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
688
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
689
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
690
-        );
691
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
692
-    }
693
-
694
-
695
-    /**
696
-     * @param EE_State[]                            $state_options
697
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
698
-     * @param EE_Registration                       $registration
699
-     * @param EE_Question                           $question
700
-     * @param                                       $answer
701
-     * @return array
702
-     * @throws EE_Error
703
-     * @throws InvalidArgumentException
704
-     * @throws InvalidDataTypeException
705
-     * @throws InvalidInterfaceException
706
-     */
707
-    public static function inject_new_reg_state_into_options(
708
-        $state_options = array(),
709
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
710
-        EE_Registration $registration,
711
-        EE_Question $question,
712
-        $answer
713
-    ) {
714
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
715
-            && $question->type() === EEM_Question::QST_type_state
716
-        ) {
717
-            $STA_ID = $answer->value();
718
-            if (! empty($STA_ID)) {
719
-                $state = EEM_State::instance()->get_one_by_ID($STA_ID);
720
-                if ($state instanceof EE_State) {
721
-                    $country = $state->country();
722
-                    if ($country instanceof EE_Country) {
723
-                        if (! isset($state_options[ $country->name() ])) {
724
-                            $state_options[ $country->name() ] = array();
725
-                        }
726
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
727
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
728
-                        }
729
-                    }
730
-                }
731
-            }
732
-        }
733
-        return $state_options;
734
-    }
735
-
736
-
737
-    /**
738
-     * @param EE_Country[]                          $country_options
739
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
740
-     * @param EE_Registration                       $registration
741
-     * @param EE_Question                           $question
742
-     * @param                                       $answer
743
-     * @return array
744
-     * @throws EE_Error
745
-     * @throws InvalidArgumentException
746
-     * @throws InvalidDataTypeException
747
-     * @throws InvalidInterfaceException
748
-     */
749
-    public static function inject_new_reg_country_into_options(
750
-        $country_options = array(),
751
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
752
-        EE_Registration $registration,
753
-        EE_Question $question,
754
-        $answer
755
-    ) {
756
-        if ($answer instanceof EE_Answer && $question instanceof EE_Question
757
-            && $question->type()
758
-               === EEM_Question::QST_type_country
759
-        ) {
760
-            $CNT_ISO = $answer->value();
761
-            if (! empty($CNT_ISO)) {
762
-                $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
763
-                if ($country instanceof EE_Country) {
764
-                    if (! isset($country_options[ $CNT_ISO ])) {
765
-                        $country_options[ $CNT_ISO ] = $country->name();
766
-                    }
767
-                }
768
-            }
769
-        }
770
-        return $country_options;
771
-    }
772
-
773
-
774
-    /**
775
-     * @param EE_State[] $state_options
776
-     * @return array
777
-     * @throws EE_Error
778
-     * @throws InvalidArgumentException
779
-     * @throws InvalidDataTypeException
780
-     * @throws InvalidInterfaceException
781
-     */
782
-    public static function state_options($state_options = array())
783
-    {
784
-        $new_states = EED_Add_New_State::_get_new_states();
785
-        foreach ($new_states as $new_state) {
786
-            if ($new_state instanceof EE_State
787
-                && $new_state->country() instanceof EE_Country
788
-            ) {
789
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
790
-            }
791
-        }
792
-        return $state_options;
793
-    }
794
-
795
-
796
-    /**
797
-     * @return array
798
-     * @throws InvalidArgumentException
799
-     * @throws InvalidDataTypeException
800
-     * @throws InvalidInterfaceException
801
-     */
802
-    protected static function _get_new_states()
803
-    {
804
-        $new_states = array();
805
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
806
-            $new_states = EE_Registry::instance()->SSN->get_session_data(
807
-                'nsmf_new_states'
808
-            );
809
-        }
810
-        return is_array($new_states) ? $new_states : array();
811
-    }
812
-
813
-
814
-    /**
815
-     * @param EE_Country[] $country_options
816
-     * @return array
817
-     * @throws EE_Error
818
-     * @throws InvalidArgumentException
819
-     * @throws InvalidDataTypeException
820
-     * @throws InvalidInterfaceException
821
-     */
822
-    public static function country_options($country_options = array())
823
-    {
824
-        $new_states = EED_Add_New_State::_get_new_states();
825
-        foreach ($new_states as $new_state) {
826
-            if ($new_state instanceof EE_State
827
-                && $new_state->country() instanceof EE_Country
828
-            ) {
829
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
830
-            }
831
-        }
832
-        return $country_options;
833
-    }
20
+	/**
21
+	 * @return EED_Module|EED_Add_New_State
22
+	 */
23
+	public static function instance()
24
+	{
25
+		return parent::get_instance(__CLASS__);
26
+	}
27
+
28
+
29
+	/**
30
+	 * set_hooks - for hooking into EE Core, other modules, etc
31
+	 *
32
+	 * @return void
33
+	 */
34
+	public static function set_hooks()
35
+	{
36
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
37
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0);
38
+		add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10);
39
+		add_filter(
40
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
41
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
42
+			1,
43
+			1
44
+		);
45
+		add_filter(
46
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
47
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
48
+			1,
49
+			1
50
+		);
51
+		add_filter(
52
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
53
+			array('EED_Add_New_State', 'unset_new_state_request_params'),
54
+			10,
55
+			1
56
+		);
57
+		add_filter(
58
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
59
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
60
+			10,
61
+			5
62
+		);
63
+		add_filter(
64
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
65
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
66
+			10,
67
+			5
68
+		);
69
+		add_filter(
70
+			'FHEE__EE_State_Select_Input____construct__state_options',
71
+			array('EED_Add_New_State', 'state_options'),
72
+			10,
73
+			1
74
+		);
75
+		add_filter(
76
+			'FHEE__EE_Country_Select_Input____construct__country_options',
77
+			array('EED_Add_New_State', 'country_options'),
78
+			10,
79
+			1
80
+		);
81
+	}
82
+
83
+
84
+	/**
85
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
86
+	 *
87
+	 * @return void
88
+	 */
89
+	public static function set_hooks_admin()
90
+	{
91
+		add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2);
92
+		add_filter(
93
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
94
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
95
+			1,
96
+			1
97
+		);
98
+		add_filter(
99
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
100
+			array('EED_Add_New_State', 'display_add_new_state_micro_form'),
101
+			1,
102
+			1
103
+		);
104
+		add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
105
+		add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state'));
106
+		add_filter(
107
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
108
+			array('EED_Add_New_State', 'unset_new_state_request_params'),
109
+			10,
110
+			1
111
+		);
112
+		add_action(
113
+			'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
114
+			array('EED_Add_New_State', 'update_country_settings'),
115
+			10,
116
+			3
117
+		);
118
+		add_action(
119
+			'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
120
+			array('EED_Add_New_State', 'update_country_settings'),
121
+			10,
122
+			3
123
+		);
124
+		add_filter(
125
+			'FHEE__EE_State_Select_Input____construct__state_options',
126
+			array('EED_Add_New_State', 'state_options'),
127
+			10,
128
+			1
129
+		);
130
+		add_filter(
131
+			'FHEE__EE_Country_Select_Input____construct__country_options',
132
+			array('EED_Add_New_State', 'country_options'),
133
+			10,
134
+			1
135
+		);
136
+		add_filter(
137
+			'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
138
+			array('EED_Add_New_State', 'filter_checkout_request_params'),
139
+			10,
140
+			1
141
+		);
142
+		add_filter(
143
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
144
+			array('EED_Add_New_State', 'inject_new_reg_state_into_options'),
145
+			10,
146
+			5
147
+		);
148
+		add_filter(
149
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
150
+			array('EED_Add_New_State', 'inject_new_reg_country_into_options'),
151
+			10,
152
+			5
153
+		);
154
+	}
155
+
156
+
157
+	/**
158
+	 * @return void
159
+	 */
160
+	public static function set_definitions()
161
+	{
162
+		define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
163
+		define(
164
+			'ANS_TEMPLATES_PATH',
165
+			str_replace(
166
+				'\\',
167
+				'/',
168
+				plugin_dir_path(__FILE__)
169
+			) . 'templates/'
170
+		);
171
+	}
172
+
173
+
174
+	/**
175
+	 * @param WP $WP
176
+	 * @return void
177
+	 */
178
+	public function run($WP)
179
+	{
180
+	}
181
+
182
+
183
+	/**
184
+	 * @return void
185
+	 */
186
+	public static function translate_js_strings()
187
+	{
188
+		EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
189
+			'In order to proceed, you need to select the Country that your State/Province belongs to.',
190
+			'event_espresso'
191
+		);
192
+		EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
193
+			'In order to proceed, you need to enter the name of your State/Province.',
194
+			'event_espresso'
195
+		);
196
+		EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
197
+			'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
198
+			'event_espresso'
199
+		);
200
+		EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
201
+			'The new state was successfully saved to the database.',
202
+			'event_espresso'
203
+		);
204
+		EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
205
+			'An unknown error has occurred on the server while saving the new state to the database.',
206
+			'event_espresso'
207
+		);
208
+	}
209
+
210
+
211
+	/**
212
+	 * @return void
213
+	 */
214
+	public static function wp_enqueue_scripts()
215
+	{
216
+		if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
217
+			wp_register_script(
218
+				'add_new_state',
219
+				ANS_ASSETS_URL . 'add_new_state.js',
220
+				array('espresso_core', 'single_page_checkout'),
221
+				EVENT_ESPRESSO_VERSION,
222
+				true
223
+			);
224
+			wp_enqueue_script('add_new_state');
225
+		}
226
+	}
227
+
228
+
229
+
230
+	/**
231
+	 * display_add_new_state_micro_form
232
+	 *
233
+	 * @param EE_Form_Section_Proper $question_group_reg_form
234
+	 * @return string
235
+	 * @throws EE_Error
236
+	 * @throws InvalidArgumentException
237
+	 * @throws InvalidDataTypeException
238
+	 * @throws InvalidInterfaceException
239
+	 */
240
+	public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
241
+	{
242
+		// only add the 'new_state_micro_form' when displaying reg forms,
243
+		// not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
+		$action = EE_Registry::instance()->REQ->get('action', '');
245
+		// is the "state" question in this form section?
246
+		$input = $question_group_reg_form->get_subsection('state');
247
+		if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
+			// ok then all we need to do is make sure the input's HTML name is consistent
249
+			// by forcing it to set it now, like it did while getting the form for display
250
+			if ($input instanceof EE_State_Select_Input) {
251
+				$input->html_name();
252
+			}
253
+			return $question_group_reg_form;
254
+		}
255
+		// we're only doing this for state select inputs
256
+		if ($input instanceof EE_State_Select_Input
257
+			&& ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
258
+		) {
259
+			// grab any set values from the request
260
+			$country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name());
261
+			$state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name());
262
+			$abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
263
+			$new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
264
+			$country_options = array();
265
+			$countries = EEM_Country::instance()->get_all_countries();
266
+			if (! empty($countries)) {
267
+				foreach ($countries as $country) {
268
+					if ($country instanceof EE_Country) {
269
+						$country_options[ $country->ID() ] = $country->name();
270
+					}
271
+				}
272
+			}
273
+			$new_state_micro_form = new EE_Form_Section_Proper(
274
+				array(
275
+					'name'            => 'new_state_micro_form',
276
+					'html_id'         => 'new_state_micro_form',
277
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
278
+					'subsections'     => array(
279
+						// add hidden input to indicate that a new state is being added
280
+						'add_new_state'               => new EE_Hidden_Input(
281
+							array(
282
+								'html_name' => str_replace(
283
+									'state',
284
+									'nsmf_add_new_state',
285
+									$input->html_name()
286
+								),
287
+								'html_id'   => str_replace(
288
+									'state',
289
+									'nsmf_add_new_state',
290
+									$input->html_id()
291
+								),
292
+								'default'   => 0,
293
+							)
294
+						),
295
+						// add link for displaying hidden container
296
+						'click_here_link'             => new EE_Form_Section_HTML(
297
+							apply_filters(
298
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
299
+								EEH_HTML::link(
300
+									'',
301
+									esc_html__('click here to add a new state/province', 'event_espresso'),
302
+									'',
303
+									'display-' . $input->html_id(),
304
+									'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
305
+									'',
306
+									'data-target="' . $input->html_id() . '"'
307
+								)
308
+							)
309
+						),
310
+						// add initial html for hidden container
311
+						'add_new_state_micro_form'    => new EE_Form_Section_HTML(
312
+							apply_filters(
313
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
314
+								EEH_HTML::div(
315
+									'',
316
+									$input->html_id() . '-dv',
317
+									'ee-form-add-new-state-dv',
318
+									'display: none;'
319
+								) .
320
+								EEH_HTML::h6(
321
+									esc_html__(
322
+										'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
323
+										'event_espresso'
324
+									)
325
+								) .
326
+								EEH_HTML::ul() .
327
+								EEH_HTML::li(
328
+									esc_html__(
329
+										'first select the Country that your State/Province belongs to',
330
+										'event_espresso'
331
+									)
332
+								) .
333
+								EEH_HTML::li(
334
+									esc_html__('enter the name of your State/Province', 'event_espresso')
335
+								) .
336
+								EEH_HTML::li(
337
+									esc_html__(
338
+										'enter a two to six letter abbreviation for the name of your State/Province',
339
+										'event_espresso'
340
+									)
341
+								) .
342
+								EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
343
+								EEH_HTML::ulx()
344
+							)
345
+						),
346
+						// NEW STATE COUNTRY
347
+						'new_state_country'           => new EE_Country_Select_Input(
348
+							$country_options,
349
+							array(
350
+								'html_name'       => $country_name,
351
+								'html_id'         => str_replace(
352
+									'state',
353
+									'nsmf_new_state_country',
354
+									$input->html_id()
355
+								),
356
+								'html_class'      => $input->html_class() . ' new-state-country',
357
+								'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
358
+								'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
359
+								'required'        => false,
360
+							)
361
+						),
362
+						// NEW STATE NAME
363
+						'new_state_name'              => new EE_Text_Input(
364
+							array(
365
+								'html_name'       => $state_name,
366
+								'html_id'         => str_replace(
367
+									'state',
368
+									'nsmf_new_state_name',
369
+									$input->html_id()
370
+								),
371
+								'html_class'      => $input->html_class() . ' new-state-state',
372
+								'html_label_text' => esc_html__(
373
+									'New State/Province Name',
374
+									'event_espresso'
375
+								),
376
+								'default'         => EE_Registry::instance()->REQ->get($state_name, ''),
377
+								'required'        => false,
378
+							)
379
+						),
380
+						'spacer'                      => new EE_Form_Section_HTML(EEH_HTML::br()),
381
+						// NEW STATE NAME
382
+						'new_state_abbrv'             => new EE_Text_Input(
383
+							array(
384
+								'html_name'             => $abbrv_name,
385
+								'html_id'               => str_replace(
386
+									'state',
387
+									'nsmf_new_state_abbrv',
388
+									$input->html_id()
389
+								),
390
+								'html_class'            => $input->html_class() . ' new-state-abbrv',
391
+								'html_label_text'       => esc_html__(
392
+									'New State/Province Abbreviation',
393
+									'event_espresso'
394
+								) . ' *',
395
+								'other_html_attributes' => 'size="24"',
396
+								'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
397
+								'required'              => false,
398
+							)
399
+						),
400
+						// "submit" button
401
+						'add_new_state_submit_button' => new EE_Form_Section_HTML(
402
+							apply_filters(
403
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
+								EEH_HTML::nbsp(3) .
405
+								EEH_HTML::link(
406
+									'',
407
+									esc_html__('ADD', 'event_espresso'),
408
+									'',
409
+									'submit-' . $new_state_submit_id,
410
+									'ee-form-add-new-state-submit button button-secondary',
411
+									'',
412
+									'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"'
413
+								)
414
+							)
415
+						),
416
+						// extra info
417
+						'add_new_state_extra'         => new EE_Form_Section_HTML(
418
+							apply_filters(
419
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
420
+								EEH_HTML::br(2)
421
+								.
422
+								EEH_HTML::div('', '', 'small-text')
423
+								.
424
+								EEH_HTML::strong(
425
+									'* ' .
426
+									esc_html__(
427
+										'Don\'t know your State/Province Abbreviation?',
428
+										'event_espresso'
429
+									)
430
+								)
431
+								.
432
+								EEH_HTML::br()
433
+								.
434
+								sprintf(
435
+									esc_html__(
436
+										'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
437
+										'event_espresso'
438
+									),
439
+									EEH_HTML::link(
440
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
441
+										'http://en.wikipedia.org/wiki/ISO_3166-2',
442
+										'',
443
+										'',
444
+										'ee-form-add-new-state-wiki-lnk',
445
+										'',
446
+										'target="_blank"'
447
+									)
448
+								)
449
+								.
450
+								EEH_HTML::divx()
451
+								.
452
+								EEH_HTML::br()
453
+								.
454
+								EEH_HTML::link(
455
+									'',
456
+									esc_html__('cancel new State/Province', 'event_espresso'),
457
+									'',
458
+									'hide-' . $input->html_id(),
459
+									'ee-form-cancel-new-state-lnk smaller-text',
460
+									'',
461
+									'data-target="' . $input->html_id() . '"'
462
+								)
463
+								.
464
+								EEH_HTML::divx()
465
+								.
466
+								EEH_HTML::br()
467
+							)
468
+						),
469
+					),
470
+				)
471
+			);
472
+			$question_group_reg_form->add_subsections(
473
+				array('new_state_micro_form' => $new_state_micro_form),
474
+				'state',
475
+				false
476
+			);
477
+		}
478
+		return $question_group_reg_form;
479
+	}
480
+
481
+
482
+	/**
483
+	 * set_new_state_input_width
484
+	 *
485
+	 * @return int|string
486
+	 * @throws EE_Error
487
+	 * @throws InvalidArgumentException
488
+	 * @throws InvalidDataTypeException
489
+	 * @throws InvalidInterfaceException
490
+	 * @throws ReflectionException
491
+	 */
492
+	public static function add_new_state()
493
+	{
494
+		$REQ = EE_Registry::instance()->load_core('Request_Handler');
495
+		if (absint($REQ->get('nsmf_add_new_state')) === 1) {
496
+			EE_Registry::instance()->load_model('State');
497
+			// grab country ISO code, new state name, and new state abbreviation
498
+			$state_country = $REQ->is_set('nsmf_new_state_country')
499
+				? sanitize_text_field($REQ->get('nsmf_new_state_country'))
500
+				: false;
501
+			$state_name = $REQ->is_set('nsmf_new_state_name')
502
+				? sanitize_text_field($REQ->get('nsmf_new_state_name'))
503
+				: false;
504
+			$state_abbr = $REQ->is_set('nsmf_new_state_abbrv')
505
+				? sanitize_text_field($REQ->get('nsmf_new_state_abbrv'))
506
+				: false;
507
+			if ($state_country && $state_name && $state_abbr) {
508
+				$new_state = EED_Add_New_State::save_new_state_to_db(
509
+					array(
510
+						'CNT_ISO'    => strtoupper($state_country),
511
+						'STA_abbrev' => strtoupper($state_abbr),
512
+						'STA_name'   => ucwords($state_name),
513
+						'STA_active' => false,
514
+					)
515
+				);
516
+				if ($new_state instanceof EE_State) {
517
+					// clean house
518
+					EE_Registry::instance()->REQ->un_set('nsmf_add_new_state');
519
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_country');
520
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_name');
521
+					EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv');
522
+					// get any existing new states
523
+					$new_states = EE_Registry::instance()->SSN->get_session_data(
524
+						'nsmf_new_states'
525
+					);
526
+					$new_states[ $new_state->ID() ] = $new_state;
527
+					EE_Registry::instance()->SSN->set_session_data(
528
+						array('nsmf_new_states' => $new_states)
529
+					);
530
+					if (EE_Registry::instance()->REQ->ajax) {
531
+						echo wp_json_encode(
532
+							array(
533
+								'success'      => true,
534
+								'id'           => $new_state->ID(),
535
+								'name'         => $new_state->name(),
536
+								'abbrev'       => $new_state->abbrev(),
537
+								'country_iso'  => $new_state->country_iso(),
538
+								'country_name' => $new_state->country()->name(),
539
+							)
540
+						);
541
+						exit();
542
+					}
543
+					return $new_state->ID();
544
+				}
545
+			} else {
546
+				$error = esc_html__(
547
+					'A new State/Province could not be added because invalid or missing data was received.',
548
+					'event_espresso'
549
+				);
550
+				if (EE_Registry::instance()->REQ->ajax) {
551
+					echo wp_json_encode(array('error' => $error));
552
+					exit();
553
+				}
554
+				EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
555
+			}
556
+		}
557
+		return false;
558
+	}
559
+
560
+
561
+	/**
562
+	 * recursively drills down through request params to remove any that were added by this module
563
+	 *
564
+	 * @param array $request_params
565
+	 * @return array
566
+	 */
567
+	public static function filter_checkout_request_params($request_params)
568
+	{
569
+		foreach ($request_params as $form_section) {
570
+			if (is_array($form_section)) {
571
+				EED_Add_New_State::unset_new_state_request_params($form_section);
572
+				EED_Add_New_State::filter_checkout_request_params($form_section);
573
+			}
574
+		}
575
+		return $request_params;
576
+	}
577
+
578
+
579
+	/**
580
+	 * @param array $request_params
581
+	 * @return array
582
+	 */
583
+	public static function unset_new_state_request_params($request_params)
584
+	{
585
+		unset(
586
+			$request_params['new_state_micro_form'],
587
+			$request_params['new_state_micro_add_new_state'],
588
+			$request_params['new_state_micro_new_state_country'],
589
+			$request_params['new_state_micro_new_state_name'],
590
+			$request_params['new_state_micro_new_state_abbrv']
591
+		);
592
+		return $request_params;
593
+	}
594
+
595
+
596
+	/**
597
+	 * @param array $props_n_values
598
+	 * @return bool
599
+	 * @throws EE_Error
600
+	 * @throws InvalidArgumentException
601
+	 * @throws InvalidDataTypeException
602
+	 * @throws InvalidInterfaceException
603
+	 */
604
+	public static function save_new_state_to_db($props_n_values = array())
605
+	{
606
+		$existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
607
+		if (! empty($existing_state)) {
608
+			return array_pop($existing_state);
609
+		}
610
+		$new_state = EE_State::new_instance($props_n_values);
611
+		if ($new_state instanceof EE_State) {
612
+			$country_settings_url = add_query_arg(
613
+				array(
614
+					'page'    => 'espresso_general_settings',
615
+					'action'  => 'country_settings',
616
+					'country' => $new_state->country_iso(),
617
+				),
618
+				admin_url('admin.php')
619
+			);
620
+			// if not non-ajax admin
621
+			new PersistentAdminNotice(
622
+				'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
623
+				sprintf(
624
+					esc_html__(
625
+						'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
626
+						'event_espresso'
627
+					),
628
+					'<b>' . $new_state->name() . '</b>',
629
+					'<b>' . $new_state->abbrev() . '</b>',
630
+					'<b>' . $new_state->country()->name() . '</b>',
631
+					'<a href="'
632
+					. $country_settings_url
633
+					. '">'
634
+					. esc_html__(
635
+						'Event Espresso - General Settings > Countries Tab',
636
+						'event_espresso'
637
+					)
638
+					. '</a>',
639
+					'<br />'
640
+				)
641
+			);
642
+			$new_state->save();
643
+			EEM_State::instance()->reset_cached_states();
644
+			return $new_state;
645
+		}
646
+		return false;
647
+	}
648
+
649
+
650
+	/**
651
+	 * @param string $CNT_ISO
652
+	 * @param string $STA_ID
653
+	 * @param array  $cols_n_values
654
+	 * @return void
655
+	 * @throws DomainException
656
+	 * @throws EE_Error
657
+	 * @throws InvalidArgumentException
658
+	 * @throws InvalidDataTypeException
659
+	 * @throws InvalidInterfaceException
660
+	 */
661
+	public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
662
+	{
663
+		if (! $CNT_ISO) {
664
+			EE_Error::add_error(
665
+				esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
666
+				__FILE__,
667
+				__FUNCTION__,
668
+				__LINE__
669
+			);
670
+		}
671
+		$STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
672
+			: false;
673
+		if (! $STA_abbrev && ! empty($STA_ID)) {
674
+			$state = EEM_State::instance()->get_one_by_ID($STA_ID);
675
+			if ($state instanceof EE_State) {
676
+				$STA_abbrev = $state->abbrev();
677
+			}
678
+		}
679
+		if (! $STA_abbrev) {
680
+			EE_Error::add_error(
681
+				esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
682
+				__FILE__,
683
+				__FUNCTION__,
684
+				__LINE__
685
+			);
686
+		}
687
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
688
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
689
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
690
+		);
691
+		$persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
692
+	}
693
+
694
+
695
+	/**
696
+	 * @param EE_State[]                            $state_options
697
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
698
+	 * @param EE_Registration                       $registration
699
+	 * @param EE_Question                           $question
700
+	 * @param                                       $answer
701
+	 * @return array
702
+	 * @throws EE_Error
703
+	 * @throws InvalidArgumentException
704
+	 * @throws InvalidDataTypeException
705
+	 * @throws InvalidInterfaceException
706
+	 */
707
+	public static function inject_new_reg_state_into_options(
708
+		$state_options = array(),
709
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
710
+		EE_Registration $registration,
711
+		EE_Question $question,
712
+		$answer
713
+	) {
714
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
715
+			&& $question->type() === EEM_Question::QST_type_state
716
+		) {
717
+			$STA_ID = $answer->value();
718
+			if (! empty($STA_ID)) {
719
+				$state = EEM_State::instance()->get_one_by_ID($STA_ID);
720
+				if ($state instanceof EE_State) {
721
+					$country = $state->country();
722
+					if ($country instanceof EE_Country) {
723
+						if (! isset($state_options[ $country->name() ])) {
724
+							$state_options[ $country->name() ] = array();
725
+						}
726
+						if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
727
+							$state_options[ $country->name() ][ $STA_ID ] = $state->name();
728
+						}
729
+					}
730
+				}
731
+			}
732
+		}
733
+		return $state_options;
734
+	}
735
+
736
+
737
+	/**
738
+	 * @param EE_Country[]                          $country_options
739
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
740
+	 * @param EE_Registration                       $registration
741
+	 * @param EE_Question                           $question
742
+	 * @param                                       $answer
743
+	 * @return array
744
+	 * @throws EE_Error
745
+	 * @throws InvalidArgumentException
746
+	 * @throws InvalidDataTypeException
747
+	 * @throws InvalidInterfaceException
748
+	 */
749
+	public static function inject_new_reg_country_into_options(
750
+		$country_options = array(),
751
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
752
+		EE_Registration $registration,
753
+		EE_Question $question,
754
+		$answer
755
+	) {
756
+		if ($answer instanceof EE_Answer && $question instanceof EE_Question
757
+			&& $question->type()
758
+			   === EEM_Question::QST_type_country
759
+		) {
760
+			$CNT_ISO = $answer->value();
761
+			if (! empty($CNT_ISO)) {
762
+				$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
763
+				if ($country instanceof EE_Country) {
764
+					if (! isset($country_options[ $CNT_ISO ])) {
765
+						$country_options[ $CNT_ISO ] = $country->name();
766
+					}
767
+				}
768
+			}
769
+		}
770
+		return $country_options;
771
+	}
772
+
773
+
774
+	/**
775
+	 * @param EE_State[] $state_options
776
+	 * @return array
777
+	 * @throws EE_Error
778
+	 * @throws InvalidArgumentException
779
+	 * @throws InvalidDataTypeException
780
+	 * @throws InvalidInterfaceException
781
+	 */
782
+	public static function state_options($state_options = array())
783
+	{
784
+		$new_states = EED_Add_New_State::_get_new_states();
785
+		foreach ($new_states as $new_state) {
786
+			if ($new_state instanceof EE_State
787
+				&& $new_state->country() instanceof EE_Country
788
+			) {
789
+				$state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
790
+			}
791
+		}
792
+		return $state_options;
793
+	}
794
+
795
+
796
+	/**
797
+	 * @return array
798
+	 * @throws InvalidArgumentException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws InvalidInterfaceException
801
+	 */
802
+	protected static function _get_new_states()
803
+	{
804
+		$new_states = array();
805
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
806
+			$new_states = EE_Registry::instance()->SSN->get_session_data(
807
+				'nsmf_new_states'
808
+			);
809
+		}
810
+		return is_array($new_states) ? $new_states : array();
811
+	}
812
+
813
+
814
+	/**
815
+	 * @param EE_Country[] $country_options
816
+	 * @return array
817
+	 * @throws EE_Error
818
+	 * @throws InvalidArgumentException
819
+	 * @throws InvalidDataTypeException
820
+	 * @throws InvalidInterfaceException
821
+	 */
822
+	public static function country_options($country_options = array())
823
+	{
824
+		$new_states = EED_Add_New_State::_get_new_states();
825
+		foreach ($new_states as $new_state) {
826
+			if ($new_state instanceof EE_State
827
+				&& $new_state->country() instanceof EE_Country
828
+			) {
829
+				$country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
830
+			}
831
+		}
832
+		return $country_options;
833
+	}
834 834
 }
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public static function set_definitions()
161 161
     {
162
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
162
+        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
163 163
         define(
164 164
             'ANS_TEMPLATES_PATH',
165 165
             str_replace(
166 166
                 '\\',
167 167
                 '/',
168 168
                 plugin_dir_path(__FILE__)
169
-            ) . 'templates/'
169
+            ).'templates/'
170 170
         );
171 171
     }
172 172
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
217 217
             wp_register_script(
218 218
                 'add_new_state',
219
-                ANS_ASSETS_URL . 'add_new_state.js',
219
+                ANS_ASSETS_URL.'add_new_state.js',
220 220
                 array('espresso_core', 'single_page_checkout'),
221 221
                 EVENT_ESPRESSO_VERSION,
222 222
                 true
@@ -263,10 +263,10 @@  discard block
 block discarded – undo
263 263
             $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
264 264
             $country_options = array();
265 265
             $countries = EEM_Country::instance()->get_all_countries();
266
-            if (! empty($countries)) {
266
+            if ( ! empty($countries)) {
267 267
                 foreach ($countries as $country) {
268 268
                     if ($country instanceof EE_Country) {
269
-                        $country_options[ $country->ID() ] = $country->name();
269
+                        $country_options[$country->ID()] = $country->name();
270 270
                     }
271 271
                 }
272 272
             }
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
                                     '',
301 301
                                     esc_html__('click here to add a new state/province', 'event_espresso'),
302 302
                                     '',
303
-                                    'display-' . $input->html_id(),
303
+                                    'display-'.$input->html_id(),
304 304
                                     'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
305 305
                                     '',
306
-                                    'data-target="' . $input->html_id() . '"'
306
+                                    'data-target="'.$input->html_id().'"'
307 307
                                 )
308 308
                             )
309 309
                         ),
@@ -313,33 +313,33 @@  discard block
 block discarded – undo
313 313
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
314 314
                                 EEH_HTML::div(
315 315
                                     '',
316
-                                    $input->html_id() . '-dv',
316
+                                    $input->html_id().'-dv',
317 317
                                     'ee-form-add-new-state-dv',
318 318
                                     'display: none;'
319
-                                ) .
319
+                                ).
320 320
                                 EEH_HTML::h6(
321 321
                                     esc_html__(
322 322
                                         'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
323 323
                                         'event_espresso'
324 324
                                     )
325
-                                ) .
326
-                                EEH_HTML::ul() .
325
+                                ).
326
+                                EEH_HTML::ul().
327 327
                                 EEH_HTML::li(
328 328
                                     esc_html__(
329 329
                                         'first select the Country that your State/Province belongs to',
330 330
                                         'event_espresso'
331 331
                                     )
332
-                                ) .
332
+                                ).
333 333
                                 EEH_HTML::li(
334 334
                                     esc_html__('enter the name of your State/Province', 'event_espresso')
335
-                                ) .
335
+                                ).
336 336
                                 EEH_HTML::li(
337 337
                                     esc_html__(
338 338
                                         'enter a two to six letter abbreviation for the name of your State/Province',
339 339
                                         'event_espresso'
340 340
                                     )
341
-                                ) .
342
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
341
+                                ).
342
+                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')).
343 343
                                 EEH_HTML::ulx()
344 344
                             )
345 345
                         ),
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
                                     'nsmf_new_state_country',
354 354
                                     $input->html_id()
355 355
                                 ),
356
-                                'html_class'      => $input->html_class() . ' new-state-country',
356
+                                'html_class'      => $input->html_class().' new-state-country',
357 357
                                 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
358 358
                                 'default'         => EE_Registry::instance()->REQ->get($country_name, ''),
359 359
                                 'required'        => false,
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
                                     'nsmf_new_state_name',
369 369
                                     $input->html_id()
370 370
                                 ),
371
-                                'html_class'      => $input->html_class() . ' new-state-state',
371
+                                'html_class'      => $input->html_class().' new-state-state',
372 372
                                 'html_label_text' => esc_html__(
373 373
                                     'New State/Province Name',
374 374
                                     'event_espresso'
@@ -387,11 +387,11 @@  discard block
 block discarded – undo
387 387
                                     'nsmf_new_state_abbrv',
388 388
                                     $input->html_id()
389 389
                                 ),
390
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
390
+                                'html_class'            => $input->html_class().' new-state-abbrv',
391 391
                                 'html_label_text'       => esc_html__(
392 392
                                     'New State/Province Abbreviation',
393 393
                                     'event_espresso'
394
-                                ) . ' *',
394
+                                ).' *',
395 395
                                 'other_html_attributes' => 'size="24"',
396 396
                                 'default'               => EE_Registry::instance()->REQ->get($abbrv_name, ''),
397 397
                                 'required'              => false,
@@ -401,15 +401,15 @@  discard block
 block discarded – undo
401 401
                         'add_new_state_submit_button' => new EE_Form_Section_HTML(
402 402
                             apply_filters(
403 403
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
-                                EEH_HTML::nbsp(3) .
404
+                                EEH_HTML::nbsp(3).
405 405
                                 EEH_HTML::link(
406 406
                                     '',
407 407
                                     esc_html__('ADD', 'event_espresso'),
408 408
                                     '',
409
-                                    'submit-' . $new_state_submit_id,
409
+                                    'submit-'.$new_state_submit_id,
410 410
                                     'ee-form-add-new-state-submit button button-secondary',
411 411
                                     '',
412
-                                    'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"'
412
+                                    'data-target="'.$new_state_submit_id.'" data-value-field-name="'.$input->valueFieldName().'"'
413 413
                                 )
414 414
                             )
415 415
                         ),
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
                                 EEH_HTML::div('', '', 'small-text')
423 423
                                 .
424 424
                                 EEH_HTML::strong(
425
-                                    '* ' .
425
+                                    '* '.
426 426
                                     esc_html__(
427 427
                                         'Don\'t know your State/Province Abbreviation?',
428 428
                                         'event_espresso'
@@ -455,10 +455,10 @@  discard block
 block discarded – undo
455 455
                                     '',
456 456
                                     esc_html__('cancel new State/Province', 'event_espresso'),
457 457
                                     '',
458
-                                    'hide-' . $input->html_id(),
458
+                                    'hide-'.$input->html_id(),
459 459
                                     'ee-form-cancel-new-state-lnk smaller-text',
460 460
                                     '',
461
-                                    'data-target="' . $input->html_id() . '"'
461
+                                    'data-target="'.$input->html_id().'"'
462 462
                                 )
463 463
                                 .
464 464
                                 EEH_HTML::divx()
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
                     $new_states = EE_Registry::instance()->SSN->get_session_data(
524 524
                         'nsmf_new_states'
525 525
                     );
526
-                    $new_states[ $new_state->ID() ] = $new_state;
526
+                    $new_states[$new_state->ID()] = $new_state;
527 527
                     EE_Registry::instance()->SSN->set_session_data(
528 528
                         array('nsmf_new_states' => $new_states)
529 529
                     );
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
     public static function save_new_state_to_db($props_n_values = array())
605 605
     {
606 606
         $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1));
607
-        if (! empty($existing_state)) {
607
+        if ( ! empty($existing_state)) {
608 608
             return array_pop($existing_state);
609 609
         }
610 610
         $new_state = EE_State::new_instance($props_n_values);
@@ -619,15 +619,15 @@  discard block
 block discarded – undo
619 619
             );
620 620
             // if not non-ajax admin
621 621
             new PersistentAdminNotice(
622
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
622
+                'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(),
623 623
                 sprintf(
624 624
                     esc_html__(
625 625
                         'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
626 626
                         'event_espresso'
627 627
                     ),
628
-                    '<b>' . $new_state->name() . '</b>',
629
-                    '<b>' . $new_state->abbrev() . '</b>',
630
-                    '<b>' . $new_state->country()->name() . '</b>',
628
+                    '<b>'.$new_state->name().'</b>',
629
+                    '<b>'.$new_state->abbrev().'</b>',
630
+                    '<b>'.$new_state->country()->name().'</b>',
631 631
                     '<a href="'
632 632
                     . $country_settings_url
633 633
                     . '">'
@@ -660,7 +660,7 @@  discard block
 block discarded – undo
660 660
      */
661 661
     public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array())
662 662
     {
663
-        if (! $CNT_ISO) {
663
+        if ( ! $CNT_ISO) {
664 664
             EE_Error::add_error(
665 665
                 esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
666 666
                 __FILE__,
@@ -670,13 +670,13 @@  discard block
 block discarded – undo
670 670
         }
671 671
         $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
672 672
             : false;
673
-        if (! $STA_abbrev && ! empty($STA_ID)) {
673
+        if ( ! $STA_abbrev && ! empty($STA_ID)) {
674 674
             $state = EEM_State::instance()->get_one_by_ID($STA_ID);
675 675
             if ($state instanceof EE_State) {
676 676
                 $STA_abbrev = $state->abbrev();
677 677
             }
678 678
         }
679
-        if (! $STA_abbrev) {
679
+        if ( ! $STA_abbrev) {
680 680
             EE_Error::add_error(
681 681
                 esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
682 682
                 __FILE__,
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
         $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
689 689
             'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
690 690
         );
691
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
691
+        $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true);
692 692
     }
693 693
 
694 694
 
@@ -715,16 +715,16 @@  discard block
 block discarded – undo
715 715
             && $question->type() === EEM_Question::QST_type_state
716 716
         ) {
717 717
             $STA_ID = $answer->value();
718
-            if (! empty($STA_ID)) {
718
+            if ( ! empty($STA_ID)) {
719 719
                 $state = EEM_State::instance()->get_one_by_ID($STA_ID);
720 720
                 if ($state instanceof EE_State) {
721 721
                     $country = $state->country();
722 722
                     if ($country instanceof EE_Country) {
723
-                        if (! isset($state_options[ $country->name() ])) {
724
-                            $state_options[ $country->name() ] = array();
723
+                        if ( ! isset($state_options[$country->name()])) {
724
+                            $state_options[$country->name()] = array();
725 725
                         }
726
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
727
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
726
+                        if ( ! isset($state_options[$country->name()][$STA_ID])) {
727
+                            $state_options[$country->name()][$STA_ID] = $state->name();
728 728
                         }
729 729
                     }
730 730
                 }
@@ -758,11 +758,11 @@  discard block
 block discarded – undo
758 758
                === EEM_Question::QST_type_country
759 759
         ) {
760 760
             $CNT_ISO = $answer->value();
761
-            if (! empty($CNT_ISO)) {
761
+            if ( ! empty($CNT_ISO)) {
762 762
                 $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
763 763
                 if ($country instanceof EE_Country) {
764
-                    if (! isset($country_options[ $CNT_ISO ])) {
765
-                        $country_options[ $CNT_ISO ] = $country->name();
764
+                    if ( ! isset($country_options[$CNT_ISO])) {
765
+                        $country_options[$CNT_ISO] = $country->name();
766 766
                     }
767 767
                 }
768 768
             }
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
             if ($new_state instanceof EE_State
787 787
                 && $new_state->country() instanceof EE_Country
788 788
             ) {
789
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
789
+                $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
790 790
             }
791 791
         }
792 792
         return $state_options;
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
             if ($new_state instanceof EE_State
827 827
                 && $new_state->country() instanceof EE_Country
828 828
             ) {
829
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
829
+                $country_options[$new_state->country()->ID()] = $new_state->country()->name();
830 830
             }
831 831
         }
832 832
         return $country_options;
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/espresso_events_Pricing_Hooks.class.php 1 patch
Indentation   +2134 added lines, -2134 removed lines patch added patch discarded remove patch
@@ -15,2194 +15,2194 @@
 block discarded – undo
15 15
 class espresso_events_Pricing_Hooks extends EE_Admin_Hooks
16 16
 {
17 17
 
18
-    /**
19
-     * This property is just used to hold the status of whether an event is currently being
20
-     * created (true) or edited (false)
21
-     *
22
-     * @access protected
23
-     * @var bool
24
-     */
25
-    protected $_is_creating_event;
18
+	/**
19
+	 * This property is just used to hold the status of whether an event is currently being
20
+	 * created (true) or edited (false)
21
+	 *
22
+	 * @access protected
23
+	 * @var bool
24
+	 */
25
+	protected $_is_creating_event;
26 26
 
27
-    /**
28
-     * Used to contain the format strings for date and time that will be used for php date and
29
-     * time.
30
-     * Is set in the _set_hooks_properties() method.
31
-     *
32
-     * @var array
33
-     */
34
-    protected $_date_format_strings;
27
+	/**
28
+	 * Used to contain the format strings for date and time that will be used for php date and
29
+	 * time.
30
+	 * Is set in the _set_hooks_properties() method.
31
+	 *
32
+	 * @var array
33
+	 */
34
+	protected $_date_format_strings;
35 35
 
36
-    /**
37
-     * @var string $_date_time_format
38
-     */
39
-    protected $_date_time_format;
36
+	/**
37
+	 * @var string $_date_time_format
38
+	 */
39
+	protected $_date_time_format;
40 40
 
41 41
 
42
-    /**
43
-     * @throws InvalidArgumentException
44
-     * @throws InvalidInterfaceException
45
-     * @throws InvalidDataTypeException
46
-     */
47
-    protected function _set_hooks_properties()
48
-    {
49
-        $this->_name = 'pricing';
50
-        // capability check
51
-        if (! EE_Registry::instance()->CAP->current_user_can(
52
-            'ee_read_default_prices',
53
-            'advanced_ticket_datetime_metabox'
54
-        )) {
55
-            return;
56
-        }
57
-        $this->_setup_metaboxes();
58
-        $this->_set_date_time_formats();
59
-        $this->_validate_format_strings();
60
-        $this->_set_scripts_styles();
61
-        // commented out temporarily until logic is implemented in callback
62
-        // add_action(
63
-        //     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
64
-        //     array($this, 'autosave_handling')
65
-        // );
66
-        add_filter(
67
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
68
-            array($this, 'caf_updates')
69
-        );
70
-    }
42
+	/**
43
+	 * @throws InvalidArgumentException
44
+	 * @throws InvalidInterfaceException
45
+	 * @throws InvalidDataTypeException
46
+	 */
47
+	protected function _set_hooks_properties()
48
+	{
49
+		$this->_name = 'pricing';
50
+		// capability check
51
+		if (! EE_Registry::instance()->CAP->current_user_can(
52
+			'ee_read_default_prices',
53
+			'advanced_ticket_datetime_metabox'
54
+		)) {
55
+			return;
56
+		}
57
+		$this->_setup_metaboxes();
58
+		$this->_set_date_time_formats();
59
+		$this->_validate_format_strings();
60
+		$this->_set_scripts_styles();
61
+		// commented out temporarily until logic is implemented in callback
62
+		// add_action(
63
+		//     'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page',
64
+		//     array($this, 'autosave_handling')
65
+		// );
66
+		add_filter(
67
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
68
+			array($this, 'caf_updates')
69
+		);
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * @return void
75
-     */
76
-    protected function _setup_metaboxes()
77
-    {
78
-        // if we were going to add our own metaboxes we'd use the below.
79
-        $this->_metaboxes = array(
80
-            0 => array(
81
-                'page_route' => array('edit', 'create_new'),
82
-                'func'       => 'pricing_metabox',
83
-                'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
84
-                'priority'   => 'high',
85
-                'context'    => 'normal',
86
-            ),
87
-        );
88
-        $this->_remove_metaboxes = array(
89
-            0 => array(
90
-                'page_route' => array('edit', 'create_new'),
91
-                'id'         => 'espresso_event_editor_tickets',
92
-                'context'    => 'normal',
93
-            ),
94
-        );
95
-    }
73
+	/**
74
+	 * @return void
75
+	 */
76
+	protected function _setup_metaboxes()
77
+	{
78
+		// if we were going to add our own metaboxes we'd use the below.
79
+		$this->_metaboxes = array(
80
+			0 => array(
81
+				'page_route' => array('edit', 'create_new'),
82
+				'func'       => 'pricing_metabox',
83
+				'label'      => esc_html__('Event Tickets & Datetimes', 'event_espresso'),
84
+				'priority'   => 'high',
85
+				'context'    => 'normal',
86
+			),
87
+		);
88
+		$this->_remove_metaboxes = array(
89
+			0 => array(
90
+				'page_route' => array('edit', 'create_new'),
91
+				'id'         => 'espresso_event_editor_tickets',
92
+				'context'    => 'normal',
93
+			),
94
+		);
95
+	}
96 96
 
97 97
 
98
-    /**
99
-     * @return void
100
-     */
101
-    protected function _set_date_time_formats()
102
-    {
103
-        /**
104
-         * Format strings for date and time.  Defaults are existing behaviour from 4.1.
105
-         * Note, that if you return null as the value for 'date', and 'time' in the array, then
106
-         * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
107
-         *
108
-         * @since 4.6.7
109
-         * @var array  Expected an array returned with 'date' and 'time' keys.
110
-         */
111
-        $this->_date_format_strings = apply_filters(
112
-            'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
113
-            array(
114
-                'date' => 'Y-m-d',
115
-                'time' => 'h:i a',
116
-            )
117
-        );
118
-        // validate
119
-        $this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
120
-            ? $this->_date_format_strings['date']
121
-            : null;
122
-        $this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
123
-            ? $this->_date_format_strings['time']
124
-            : null;
125
-        $this->_date_time_format = $this->_date_format_strings['date']
126
-                                   . ' '
127
-                                   . $this->_date_format_strings['time'];
128
-    }
98
+	/**
99
+	 * @return void
100
+	 */
101
+	protected function _set_date_time_formats()
102
+	{
103
+		/**
104
+		 * Format strings for date and time.  Defaults are existing behaviour from 4.1.
105
+		 * Note, that if you return null as the value for 'date', and 'time' in the array, then
106
+		 * EE will automatically use the set wp_options, 'date_format', and 'time_format'.
107
+		 *
108
+		 * @since 4.6.7
109
+		 * @var array  Expected an array returned with 'date' and 'time' keys.
110
+		 */
111
+		$this->_date_format_strings = apply_filters(
112
+			'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings',
113
+			array(
114
+				'date' => 'Y-m-d',
115
+				'time' => 'h:i a',
116
+			)
117
+		);
118
+		// validate
119
+		$this->_date_format_strings['date'] = isset($this->_date_format_strings['date'])
120
+			? $this->_date_format_strings['date']
121
+			: null;
122
+		$this->_date_format_strings['time'] = isset($this->_date_format_strings['time'])
123
+			? $this->_date_format_strings['time']
124
+			: null;
125
+		$this->_date_time_format = $this->_date_format_strings['date']
126
+								   . ' '
127
+								   . $this->_date_format_strings['time'];
128
+	}
129 129
 
130 130
 
131
-    /**
132
-     * @return void
133
-     */
134
-    protected function _validate_format_strings()
135
-    {
136
-        // validate format strings
137
-        $format_validation = EEH_DTT_Helper::validate_format_string(
138
-            $this->_date_time_format
139
-        );
140
-        if (is_array($format_validation)) {
141
-            $msg = '<p>';
142
-            $msg .= sprintf(
143
-                esc_html__(
144
-                    'The format "%s" was likely added via a filter and is invalid for the following reasons:',
145
-                    'event_espresso'
146
-                ),
147
-                $this->_date_time_format
148
-            );
149
-            $msg .= '</p><ul>';
150
-            foreach ($format_validation as $error) {
151
-                $msg .= '<li>' . $error . '</li>';
152
-            }
153
-            $msg .= '</ul><p>';
154
-            $msg .= sprintf(
155
-                esc_html__(
156
-                    '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
157
-                    'event_espresso'
158
-                ),
159
-                '<span style="color:#D54E21;">',
160
-                '</span>'
161
-            );
162
-            $msg .= '</p>';
163
-            EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
164
-            $this->_date_format_strings = array(
165
-                'date' => 'Y-m-d',
166
-                'time' => 'h:i a',
167
-            );
168
-        }
169
-    }
131
+	/**
132
+	 * @return void
133
+	 */
134
+	protected function _validate_format_strings()
135
+	{
136
+		// validate format strings
137
+		$format_validation = EEH_DTT_Helper::validate_format_string(
138
+			$this->_date_time_format
139
+		);
140
+		if (is_array($format_validation)) {
141
+			$msg = '<p>';
142
+			$msg .= sprintf(
143
+				esc_html__(
144
+					'The format "%s" was likely added via a filter and is invalid for the following reasons:',
145
+					'event_espresso'
146
+				),
147
+				$this->_date_time_format
148
+			);
149
+			$msg .= '</p><ul>';
150
+			foreach ($format_validation as $error) {
151
+				$msg .= '<li>' . $error . '</li>';
152
+			}
153
+			$msg .= '</ul><p>';
154
+			$msg .= sprintf(
155
+				esc_html__(
156
+					'%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s',
157
+					'event_espresso'
158
+				),
159
+				'<span style="color:#D54E21;">',
160
+				'</span>'
161
+			);
162
+			$msg .= '</p>';
163
+			EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
164
+			$this->_date_format_strings = array(
165
+				'date' => 'Y-m-d',
166
+				'time' => 'h:i a',
167
+			);
168
+		}
169
+	}
170 170
 
171 171
 
172
-    /**
173
-     * @return void
174
-     */
175
-    protected function _set_scripts_styles()
176
-    {
177
-        $this->_scripts_styles = array(
178
-            'registers'   => array(
179
-                'ee-tickets-datetimes-css' => array(
180
-                    'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
181
-                    'type' => 'css',
182
-                ),
183
-                'ee-dtt-ticket-metabox'    => array(
184
-                    'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
185
-                    'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
186
-                ),
187
-            ),
188
-            'deregisters' => array(
189
-                'event-editor-css'       => array('type' => 'css'),
190
-                'event-datetime-metabox' => array('type' => 'js'),
191
-            ),
192
-            'enqueues'    => array(
193
-                'ee-tickets-datetimes-css' => array('edit', 'create_new'),
194
-                'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
195
-            ),
196
-            'localize'    => array(
197
-                'ee-dtt-ticket-metabox' => array(
198
-                    'DTT_TRASH_BLOCK'       => array(
199
-                        'main_warning'            => esc_html__(
200
-                            'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
201
-                            'event_espresso'
202
-                        ),
203
-                        'after_warning'           => esc_html__(
204
-                            'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
205
-                            'event_espresso'
206
-                        ),
207
-                        'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
208
-                                                     . esc_html__('Cancel', 'event_espresso') . '</button>',
209
-                        'close_button'            => '<button class="button-secondary ee-modal-cancel">'
210
-                                                     . esc_html__('Close', 'event_espresso') . '</button>',
211
-                        'single_warning_from_tkt' => esc_html__(
212
-                            'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
213
-                            'event_espresso'
214
-                        ),
215
-                        'single_warning_from_dtt' => esc_html__(
216
-                            'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
217
-                            'event_espresso'
218
-                        ),
219
-                        'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
220
-                                                     . esc_html__('Dismiss', 'event_espresso') . '</button>',
221
-                    ),
222
-                    'DTT_ERROR_MSG'         => array(
223
-                        'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
224
-                        'dismiss_button' => '<div class="save-cancel-button-container">'
225
-                                            . '<button class="button-secondary ee-modal-cancel">'
226
-                                            . esc_html__('Dismiss', 'event_espresso')
227
-                                            . '</button></div>',
228
-                    ),
229
-                    'DTT_OVERSELL_WARNING'  => array(
230
-                        'datetime_ticket' => esc_html__(
231
-                            'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
232
-                            'event_espresso'
233
-                        ),
234
-                        'ticket_datetime' => esc_html__(
235
-                            'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
236
-                            'event_espresso'
237
-                        ),
238
-                    ),
239
-                    'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
240
-                        $this->_date_format_strings['date'],
241
-                        $this->_date_format_strings['time']
242
-                    ),
243
-                    'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
244
-                ),
245
-            ),
246
-        );
247
-    }
172
+	/**
173
+	 * @return void
174
+	 */
175
+	protected function _set_scripts_styles()
176
+	{
177
+		$this->_scripts_styles = array(
178
+			'registers'   => array(
179
+				'ee-tickets-datetimes-css' => array(
180
+					'url'  => PRICING_ASSETS_URL . 'event-tickets-datetimes.css',
181
+					'type' => 'css',
182
+				),
183
+				'ee-dtt-ticket-metabox'    => array(
184
+					'url'     => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js',
185
+					'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'),
186
+				),
187
+			),
188
+			'deregisters' => array(
189
+				'event-editor-css'       => array('type' => 'css'),
190
+				'event-datetime-metabox' => array('type' => 'js'),
191
+			),
192
+			'enqueues'    => array(
193
+				'ee-tickets-datetimes-css' => array('edit', 'create_new'),
194
+				'ee-dtt-ticket-metabox'    => array('edit', 'create_new'),
195
+			),
196
+			'localize'    => array(
197
+				'ee-dtt-ticket-metabox' => array(
198
+					'DTT_TRASH_BLOCK'       => array(
199
+						'main_warning'            => esc_html__(
200
+							'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):',
201
+							'event_espresso'
202
+						),
203
+						'after_warning'           => esc_html__(
204
+							'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.',
205
+							'event_espresso'
206
+						),
207
+						'cancel_button'           => '<button class="button-secondary ee-modal-cancel">'
208
+													 . esc_html__('Cancel', 'event_espresso') . '</button>',
209
+						'close_button'            => '<button class="button-secondary ee-modal-cancel">'
210
+													 . esc_html__('Close', 'event_espresso') . '</button>',
211
+						'single_warning_from_tkt' => esc_html__(
212
+							'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.',
213
+							'event_espresso'
214
+						),
215
+						'single_warning_from_dtt' => esc_html__(
216
+							'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket.  Tickets must always have at least one datetime assigned to them.',
217
+							'event_espresso'
218
+						),
219
+						'dismiss_button'          => '<button class="button-secondary ee-modal-cancel">'
220
+													 . esc_html__('Dismiss', 'event_espresso') . '</button>',
221
+					),
222
+					'DTT_ERROR_MSG'         => array(
223
+						'no_ticket_name' => esc_html__('General Admission', 'event_espresso'),
224
+						'dismiss_button' => '<div class="save-cancel-button-container">'
225
+											. '<button class="button-secondary ee-modal-cancel">'
226
+											. esc_html__('Dismiss', 'event_espresso')
227
+											. '</button></div>',
228
+					),
229
+					'DTT_OVERSELL_WARNING'  => array(
230
+						'datetime_ticket' => esc_html__(
231
+							'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.',
232
+							'event_espresso'
233
+						),
234
+						'ticket_datetime' => esc_html__(
235
+							'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.',
236
+							'event_espresso'
237
+						),
238
+					),
239
+					'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats(
240
+						$this->_date_format_strings['date'],
241
+						$this->_date_format_strings['time']
242
+					),
243
+					'DTT_START_OF_WEEK'     => array('dayValue' => (int) get_option('start_of_week')),
244
+				),
245
+			),
246
+		);
247
+	}
248 248
 
249 249
 
250
-    /**
251
-     * @param array $update_callbacks
252
-     * @return array
253
-     */
254
-    public function caf_updates(array $update_callbacks)
255
-    {
256
-        foreach ($update_callbacks as $key => $callback) {
257
-            if ($callback[1] === '_default_tickets_update') {
258
-                unset($update_callbacks[ $key ]);
259
-            }
260
-        }
261
-        $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
262
-        return $update_callbacks;
263
-    }
250
+	/**
251
+	 * @param array $update_callbacks
252
+	 * @return array
253
+	 */
254
+	public function caf_updates(array $update_callbacks)
255
+	{
256
+		foreach ($update_callbacks as $key => $callback) {
257
+			if ($callback[1] === '_default_tickets_update') {
258
+				unset($update_callbacks[ $key ]);
259
+			}
260
+		}
261
+		$update_callbacks[] = array($this, 'datetime_and_tickets_caf_update');
262
+		return $update_callbacks;
263
+	}
264 264
 
265 265
 
266
-    /**
267
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
268
-     *
269
-     * @param  EE_Event $event The Event object we're attaching data to
270
-     * @param  array    $data  The request data from the form
271
-     * @throws ReflectionException
272
-     * @throws Exception
273
-     * @throws InvalidInterfaceException
274
-     * @throws InvalidDataTypeException
275
-     * @throws EE_Error
276
-     * @throws InvalidArgumentException
277
-     */
278
-    public function datetime_and_tickets_caf_update($event, $data)
279
-    {
280
-        // first we need to start with datetimes cause they are the "root" items attached to events.
281
-        $saved_datetimes = $this->_update_datetimes($event, $data);
282
-        // next tackle the tickets (and prices?)
283
-        $this->_update_tickets($event, $saved_datetimes, $data);
284
-    }
266
+	/**
267
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
268
+	 *
269
+	 * @param  EE_Event $event The Event object we're attaching data to
270
+	 * @param  array    $data  The request data from the form
271
+	 * @throws ReflectionException
272
+	 * @throws Exception
273
+	 * @throws InvalidInterfaceException
274
+	 * @throws InvalidDataTypeException
275
+	 * @throws EE_Error
276
+	 * @throws InvalidArgumentException
277
+	 */
278
+	public function datetime_and_tickets_caf_update($event, $data)
279
+	{
280
+		// first we need to start with datetimes cause they are the "root" items attached to events.
281
+		$saved_datetimes = $this->_update_datetimes($event, $data);
282
+		// next tackle the tickets (and prices?)
283
+		$this->_update_tickets($event, $saved_datetimes, $data);
284
+	}
285 285
 
286 286
 
287
-    /**
288
-     * update event_datetimes
289
-     *
290
-     * @param  EE_Event $event Event being updated
291
-     * @param  array    $data  the request data from the form
292
-     * @return EE_Datetime[]
293
-     * @throws Exception
294
-     * @throws ReflectionException
295
-     * @throws InvalidInterfaceException
296
-     * @throws InvalidDataTypeException
297
-     * @throws InvalidArgumentException
298
-     * @throws EE_Error
299
-     */
300
-    protected function _update_datetimes($event, $data)
301
-    {
302
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
303
-        $saved_dtt_ids = array();
304
-        $saved_dtt_objs = array();
305
-        if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
306
-            throw new InvalidArgumentException(
307
-                esc_html__(
308
-                    'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
309
-                    'event_espresso'
310
-                )
311
-            );
312
-        }
313
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
314
-            // trim all values to ensure any excess whitespace is removed.
315
-            $datetime_data = array_map(
316
-                function ($datetime_data) {
317
-                    return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
318
-                },
319
-                $datetime_data
320
-            );
321
-            $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
322
-                                            && ! empty($datetime_data['DTT_EVT_end'])
323
-                ? $datetime_data['DTT_EVT_end']
324
-                : $datetime_data['DTT_EVT_start'];
325
-            $datetime_values = array(
326
-                'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
327
-                    ? $datetime_data['DTT_ID']
328
-                    : null,
329
-                'DTT_name'        => ! empty($datetime_data['DTT_name'])
330
-                    ? $datetime_data['DTT_name']
331
-                    : '',
332
-                'DTT_description' => ! empty($datetime_data['DTT_description'])
333
-                    ? $datetime_data['DTT_description']
334
-                    : '',
335
-                'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
336
-                'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
337
-                'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
338
-                    ? EE_INF
339
-                    : $datetime_data['DTT_reg_limit'],
340
-                'DTT_order'       => ! isset($datetime_data['DTT_order'])
341
-                    ? $row
342
-                    : $datetime_data['DTT_order'],
343
-            );
344
-            // if we have an id then let's get existing object first and then set the new values.
345
-            // Otherwise we instantiate a new object for save.
346
-            if (! empty($datetime_data['DTT_ID'])) {
347
-                $datetime = EE_Registry::instance()
348
-                                       ->load_model('Datetime', array($timezone))
349
-                                       ->get_one_by_ID($datetime_data['DTT_ID']);
350
-                // set date and time format according to what is set in this class.
351
-                $datetime->set_date_format($this->_date_format_strings['date']);
352
-                $datetime->set_time_format($this->_date_format_strings['time']);
353
-                foreach ($datetime_values as $field => $value) {
354
-                    $datetime->set($field, $value);
355
-                }
356
-                // make sure the $dtt_id here is saved just in case
357
-                // after the add_relation_to() the autosave replaces it.
358
-                // We need to do this so we dont' TRASH the parent DTT.
359
-                // (save the ID for both key and value to avoid duplications)
360
-                $saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
361
-            } else {
362
-                $datetime = EE_Registry::instance()->load_class(
363
-                    'Datetime',
364
-                    array(
365
-                        $datetime_values,
366
-                        $timezone,
367
-                        array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
368
-                    ),
369
-                    false,
370
-                    false
371
-                );
372
-                foreach ($datetime_values as $field => $value) {
373
-                    $datetime->set($field, $value);
374
-                }
375
-            }
376
-            $datetime->save();
377
-            $datetime = $event->_add_relation_to($datetime, 'Datetime');
378
-            // before going any further make sure our dates are setup correctly
379
-            // so that the end date is always equal or greater than the start date.
380
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
381
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
382
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
383
-                $datetime->save();
384
-            }
385
-            // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
386
-            // because it is possible there was a new one created for the autosave.
387
-            // (save the ID for both key and value to avoid duplications)
388
-            $DTT_ID = $datetime->ID();
389
-            $saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
390
-            $saved_dtt_objs[ $row ] = $datetime;
391
-            // @todo if ANY of these updates fail then we want the appropriate global error message.
392
-        }
393
-        $event->save();
394
-        // now we need to REMOVE any datetimes that got deleted.
395
-        // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
396
-        // So its safe to permanently delete at this point.
397
-        $old_datetimes = explode(',', $data['datetime_IDs']);
398
-        $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
399
-        if (is_array($old_datetimes)) {
400
-            $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
401
-            foreach ($datetimes_to_delete as $id) {
402
-                $id = absint($id);
403
-                if (empty($id)) {
404
-                    continue;
405
-                }
406
-                $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
407
-                // remove tkt relationships.
408
-                $related_tickets = $dtt_to_remove->get_many_related('Ticket');
409
-                foreach ($related_tickets as $tkt) {
410
-                    $dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
411
-                }
412
-                $event->_remove_relation_to($id, 'Datetime');
413
-                $dtt_to_remove->refresh_cache_of_related_objects();
414
-            }
415
-        }
416
-        return $saved_dtt_objs;
417
-    }
287
+	/**
288
+	 * update event_datetimes
289
+	 *
290
+	 * @param  EE_Event $event Event being updated
291
+	 * @param  array    $data  the request data from the form
292
+	 * @return EE_Datetime[]
293
+	 * @throws Exception
294
+	 * @throws ReflectionException
295
+	 * @throws InvalidInterfaceException
296
+	 * @throws InvalidDataTypeException
297
+	 * @throws InvalidArgumentException
298
+	 * @throws EE_Error
299
+	 */
300
+	protected function _update_datetimes($event, $data)
301
+	{
302
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
303
+		$saved_dtt_ids = array();
304
+		$saved_dtt_objs = array();
305
+		if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) {
306
+			throw new InvalidArgumentException(
307
+				esc_html__(
308
+					'The "edit_event_datetimes" array is invalid therefore the event can not be updated.',
309
+					'event_espresso'
310
+				)
311
+			);
312
+		}
313
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
314
+			// trim all values to ensure any excess whitespace is removed.
315
+			$datetime_data = array_map(
316
+				function ($datetime_data) {
317
+					return is_array($datetime_data) ? $datetime_data : trim($datetime_data);
318
+				},
319
+				$datetime_data
320
+			);
321
+			$datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end'])
322
+											&& ! empty($datetime_data['DTT_EVT_end'])
323
+				? $datetime_data['DTT_EVT_end']
324
+				: $datetime_data['DTT_EVT_start'];
325
+			$datetime_values = array(
326
+				'DTT_ID'          => ! empty($datetime_data['DTT_ID'])
327
+					? $datetime_data['DTT_ID']
328
+					: null,
329
+				'DTT_name'        => ! empty($datetime_data['DTT_name'])
330
+					? $datetime_data['DTT_name']
331
+					: '',
332
+				'DTT_description' => ! empty($datetime_data['DTT_description'])
333
+					? $datetime_data['DTT_description']
334
+					: '',
335
+				'DTT_EVT_start'   => $datetime_data['DTT_EVT_start'],
336
+				'DTT_EVT_end'     => $datetime_data['DTT_EVT_end'],
337
+				'DTT_reg_limit'   => empty($datetime_data['DTT_reg_limit'])
338
+					? EE_INF
339
+					: $datetime_data['DTT_reg_limit'],
340
+				'DTT_order'       => ! isset($datetime_data['DTT_order'])
341
+					? $row
342
+					: $datetime_data['DTT_order'],
343
+			);
344
+			// if we have an id then let's get existing object first and then set the new values.
345
+			// Otherwise we instantiate a new object for save.
346
+			if (! empty($datetime_data['DTT_ID'])) {
347
+				$datetime = EE_Registry::instance()
348
+									   ->load_model('Datetime', array($timezone))
349
+									   ->get_one_by_ID($datetime_data['DTT_ID']);
350
+				// set date and time format according to what is set in this class.
351
+				$datetime->set_date_format($this->_date_format_strings['date']);
352
+				$datetime->set_time_format($this->_date_format_strings['time']);
353
+				foreach ($datetime_values as $field => $value) {
354
+					$datetime->set($field, $value);
355
+				}
356
+				// make sure the $dtt_id here is saved just in case
357
+				// after the add_relation_to() the autosave replaces it.
358
+				// We need to do this so we dont' TRASH the parent DTT.
359
+				// (save the ID for both key and value to avoid duplications)
360
+				$saved_dtt_ids[ $datetime->ID() ] = $datetime->ID();
361
+			} else {
362
+				$datetime = EE_Registry::instance()->load_class(
363
+					'Datetime',
364
+					array(
365
+						$datetime_values,
366
+						$timezone,
367
+						array($this->_date_format_strings['date'], $this->_date_format_strings['time']),
368
+					),
369
+					false,
370
+					false
371
+				);
372
+				foreach ($datetime_values as $field => $value) {
373
+					$datetime->set($field, $value);
374
+				}
375
+			}
376
+			$datetime->save();
377
+			$datetime = $event->_add_relation_to($datetime, 'Datetime');
378
+			// before going any further make sure our dates are setup correctly
379
+			// so that the end date is always equal or greater than the start date.
380
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
381
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
382
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
383
+				$datetime->save();
384
+			}
385
+			// now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array
386
+			// because it is possible there was a new one created for the autosave.
387
+			// (save the ID for both key and value to avoid duplications)
388
+			$DTT_ID = $datetime->ID();
389
+			$saved_dtt_ids[ $DTT_ID ] = $DTT_ID;
390
+			$saved_dtt_objs[ $row ] = $datetime;
391
+			// @todo if ANY of these updates fail then we want the appropriate global error message.
392
+		}
393
+		$event->save();
394
+		// now we need to REMOVE any datetimes that got deleted.
395
+		// Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them.
396
+		// So its safe to permanently delete at this point.
397
+		$old_datetimes = explode(',', $data['datetime_IDs']);
398
+		$old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes;
399
+		if (is_array($old_datetimes)) {
400
+			$datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids);
401
+			foreach ($datetimes_to_delete as $id) {
402
+				$id = absint($id);
403
+				if (empty($id)) {
404
+					continue;
405
+				}
406
+				$dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id);
407
+				// remove tkt relationships.
408
+				$related_tickets = $dtt_to_remove->get_many_related('Ticket');
409
+				foreach ($related_tickets as $tkt) {
410
+					$dtt_to_remove->_remove_relation_to($tkt, 'Ticket');
411
+				}
412
+				$event->_remove_relation_to($id, 'Datetime');
413
+				$dtt_to_remove->refresh_cache_of_related_objects();
414
+			}
415
+		}
416
+		return $saved_dtt_objs;
417
+	}
418 418
 
419 419
 
420
-    /**
421
-     * update tickets
422
-     *
423
-     * @param  EE_Event      $event           Event object being updated
424
-     * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
425
-     * @param  array         $data            incoming request data
426
-     * @return EE_Ticket[]
427
-     * @throws Exception
428
-     * @throws ReflectionException
429
-     * @throws InvalidInterfaceException
430
-     * @throws InvalidDataTypeException
431
-     * @throws InvalidArgumentException
432
-     * @throws EE_Error
433
-     */
434
-    protected function _update_tickets($event, $saved_datetimes, $data)
435
-    {
436
-        $new_tkt = null;
437
-        $new_default = null;
438
-        // stripslashes because WP filtered the $_POST ($data) array to add slashes
439
-        $data = stripslashes_deep($data);
440
-        $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
441
-        $saved_tickets = $datetimes_on_existing = array();
442
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
443
-        if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
444
-            throw new InvalidArgumentException(
445
-                esc_html__(
446
-                    'The "edit_tickets" array is invalid therefore the event can not be updated.',
447
-                    'event_espresso'
448
-                )
449
-            );
450
-        }
451
-        foreach ($data['edit_tickets'] as $row => $tkt) {
452
-            $update_prices = $create_new_TKT = false;
453
-            // figure out what datetimes were added to the ticket
454
-            // and what datetimes were removed from the ticket in the session.
455
-            $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
456
-            $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
457
-            $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
458
-            $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
459
-            // trim inputs to ensure any excess whitespace is removed.
460
-            $tkt = array_map(
461
-                function ($ticket_data) {
462
-                    return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
463
-                },
464
-                $tkt
465
-            );
466
-            // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
467
-            // because we're doing calculations prior to using the models.
468
-            // note incoming ['TKT_price'] value is already in standard notation (via js).
469
-            $ticket_price = isset($tkt['TKT_price'])
470
-                ? round((float) $tkt['TKT_price'], 3)
471
-                : 0;
472
-            // note incoming base price needs converted from localized value.
473
-            $base_price = isset($tkt['TKT_base_price'])
474
-                ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
475
-                : 0;
476
-            // if ticket price == 0 and $base_price != 0 then ticket price == base_price
477
-            $ticket_price = $ticket_price === 0 && $base_price !== 0
478
-                ? $base_price
479
-                : $ticket_price;
480
-            $base_price_id = isset($tkt['TKT_base_price_ID'])
481
-                ? $tkt['TKT_base_price_ID']
482
-                : 0;
483
-            $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
484
-                ? $data['edit_prices'][ $row ]
485
-                : array();
486
-            $now = null;
487
-            if (empty($tkt['TKT_start_date'])) {
488
-                // lets' use now in the set timezone.
489
-                $now = new DateTime('now', new DateTimeZone($event->get_timezone()));
490
-                $tkt['TKT_start_date'] = $now->format($this->_date_time_format);
491
-            }
492
-            if (empty($tkt['TKT_end_date'])) {
493
-                /**
494
-                 * set the TKT_end_date to the first datetime attached to the ticket.
495
-                 */
496
-                $first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
497
-                $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
498
-            }
499
-            $TKT_values = array(
500
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
501
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
502
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
503
-                'TKT_description' => ! empty($tkt['TKT_description'])
504
-                                     && $tkt['TKT_description'] !== esc_html__(
505
-                                         'You can modify this description',
506
-                                         'event_espresso'
507
-                                     )
508
-                    ? $tkt['TKT_description']
509
-                    : '',
510
-                'TKT_start_date'  => $tkt['TKT_start_date'],
511
-                'TKT_end_date'    => $tkt['TKT_end_date'],
512
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
513
-                    ? EE_INF
514
-                    : $tkt['TKT_qty'],
515
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
516
-                    ? EE_INF
517
-                    : $tkt['TKT_uses'],
518
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
519
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
520
-                'TKT_row'         => $row,
521
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
522
-                'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
523
-                'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
524
-                'TKT_price'       => $ticket_price,
525
-            );
526
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
527
-            // which means in turn that the prices will become new prices as well.
528
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
529
-                $TKT_values['TKT_ID'] = 0;
530
-                $TKT_values['TKT_is_default'] = 0;
531
-                $update_prices = true;
532
-            }
533
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
534
-            // we actually do our saves ahead of doing any add_relations to
535
-            // because its entirely possible that this ticket wasn't removed or added to any datetime in the session
536
-            // but DID have it's items modified.
537
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
538
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
539
-            if (absint($TKT_values['TKT_ID'])) {
540
-                $ticket = EE_Registry::instance()
541
-                                     ->load_model('Ticket', array($timezone))
542
-                                     ->get_one_by_ID($tkt['TKT_ID']);
543
-                if ($ticket instanceof EE_Ticket) {
544
-                    $ticket = $this->_update_ticket_datetimes(
545
-                        $ticket,
546
-                        $saved_datetimes,
547
-                        $datetimes_added,
548
-                        $datetimes_removed
549
-                    );
550
-                    // are there any registrations using this ticket ?
551
-                    $tickets_sold = $ticket->count_related(
552
-                        'Registration',
553
-                        array(
554
-                            array(
555
-                                'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
556
-                            ),
557
-                        )
558
-                    );
559
-                    // set ticket formats
560
-                    $ticket->set_date_format($this->_date_format_strings['date']);
561
-                    $ticket->set_time_format($this->_date_format_strings['time']);
562
-                    // let's just check the total price for the existing ticket
563
-                    // and determine if it matches the new total price.
564
-                    // if they are different then we create a new ticket (if tickets sold)
565
-                    // if they aren't different then we go ahead and modify existing ticket.
566
-                    $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
567
-                    // set new values
568
-                    foreach ($TKT_values as $field => $value) {
569
-                        if ($field === 'TKT_qty') {
570
-                            $ticket->set_qty($value);
571
-                        } else {
572
-                            $ticket->set($field, $value);
573
-                        }
574
-                    }
575
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
576
-                    // Otherwise we have to create a new ticket.
577
-                    if ($create_new_TKT) {
578
-                        $new_tkt = $this->_duplicate_ticket(
579
-                            $ticket,
580
-                            $price_rows,
581
-                            $ticket_price,
582
-                            $base_price,
583
-                            $base_price_id
584
-                        );
585
-                    }
586
-                }
587
-            } else {
588
-                // no TKT_id so a new TKT
589
-                $ticket = EE_Ticket::new_instance(
590
-                    $TKT_values,
591
-                    $timezone,
592
-                    array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
593
-                );
594
-                if ($ticket instanceof EE_Ticket) {
595
-                    // make sure ticket has an ID of setting relations won't work
596
-                    $ticket->save();
597
-                    $ticket = $this->_update_ticket_datetimes(
598
-                        $ticket,
599
-                        $saved_datetimes,
600
-                        $datetimes_added,
601
-                        $datetimes_removed
602
-                    );
603
-                    $update_prices = true;
604
-                }
605
-            }
606
-            // make sure any current values have been saved.
607
-            // $ticket->save();
608
-            // before going any further make sure our dates are setup correctly
609
-            // so that the end date is always equal or greater than the start date.
610
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
611
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
612
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
613
-            }
614
-            // let's make sure the base price is handled
615
-            $ticket = ! $create_new_TKT
616
-                ? $this->_add_prices_to_ticket(
617
-                    array(),
618
-                    $ticket,
619
-                    $update_prices,
620
-                    $base_price,
621
-                    $base_price_id
622
-                )
623
-                : $ticket;
624
-            // add/update price_modifiers
625
-            $ticket = ! $create_new_TKT
626
-                ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
627
-                : $ticket;
628
-            // need to make sue that the TKT_price is accurate after saving the prices.
629
-            $ticket->ensure_TKT_Price_correct();
630
-            // handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
631
-            if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
632
-                $update_prices = true;
633
-                $new_default = clone $ticket;
634
-                $new_default->set('TKT_ID', 0);
635
-                $new_default->set('TKT_is_default', 1);
636
-                $new_default->set('TKT_row', 1);
637
-                $new_default->set('TKT_price', $ticket_price);
638
-                // remove any dtt relations cause we DON'T want dtt relations attached
639
-                // (note this is just removing the cached relations in the object)
640
-                $new_default->_remove_relations('Datetime');
641
-                // @todo we need to add the current attached prices as new prices to the new default ticket.
642
-                $new_default = $this->_add_prices_to_ticket(
643
-                    $price_rows,
644
-                    $new_default,
645
-                    $update_prices
646
-                );
647
-                // don't forget the base price!
648
-                $new_default = $this->_add_prices_to_ticket(
649
-                    array(),
650
-                    $new_default,
651
-                    $update_prices,
652
-                    $base_price,
653
-                    $base_price_id
654
-                );
655
-                $new_default->save();
656
-                do_action(
657
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
658
-                    $new_default,
659
-                    $row,
660
-                    $ticket,
661
-                    $data
662
-                );
663
-            }
664
-            // DO ALL dtt relationships for both current tickets and any archived tickets
665
-            // for the given dtt that are related to the current ticket.
666
-            // TODO... not sure exactly how we're going to do this considering we don't know
667
-            // what current ticket the archived tickets are related to
668
-            // (and TKT_parent is used for autosaves so that's not a field we can reliably use).
669
-            // let's assign any tickets that have been setup to the saved_tickets tracker
670
-            // save existing TKT
671
-            $ticket->save();
672
-            if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
673
-                // save new TKT
674
-                $new_tkt->save();
675
-                // add new ticket to array
676
-                $saved_tickets[ $new_tkt->ID() ] = $new_tkt;
677
-                do_action(
678
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
679
-                    $new_tkt,
680
-                    $row,
681
-                    $tkt,
682
-                    $data
683
-                );
684
-            } else {
685
-                // add tkt to saved tkts
686
-                $saved_tickets[ $ticket->ID() ] = $ticket;
687
-                do_action(
688
-                    'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
689
-                    $ticket,
690
-                    $row,
691
-                    $tkt,
692
-                    $data
693
-                );
694
-            }
695
-        }
696
-        // now we need to handle tickets actually "deleted permanently".
697
-        // There are cases where we'd want this to happen
698
-        // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
699
-        // Or a draft event was saved and in the process of editing a ticket is trashed.
700
-        // No sense in keeping all the related data in the db!
701
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
702
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
703
-        foreach ($tickets_removed as $id) {
704
-            $id = absint($id);
705
-            // get the ticket for this id
706
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
707
-            // if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
708
-            if ($tkt_to_remove->get('TKT_is_default')) {
709
-                continue;
710
-            }
711
-            // if this tkt has any registrations attached so then we just ARCHIVE
712
-            // because we don't actually permanently delete these tickets.
713
-            if ($tkt_to_remove->count_related('Registration') > 0) {
714
-                $tkt_to_remove->delete();
715
-                continue;
716
-            }
717
-            // need to get all the related datetimes on this ticket and remove from every single one of them
718
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
719
-            $datetimes = $tkt_to_remove->get_many_related('Datetime');
720
-            foreach ($datetimes as $datetime) {
721
-                $tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
722
-            }
723
-            // need to do the same for prices (except these prices can also be deleted because again,
724
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
725
-            $tkt_to_remove->delete_related_permanently('Price');
726
-            do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
727
-            // finally let's delete this ticket
728
-            // (which should not be blocked at this point b/c we've removed all our relationships)
729
-            $tkt_to_remove->delete_permanently();
730
-        }
731
-        return $saved_tickets;
732
-    }
420
+	/**
421
+	 * update tickets
422
+	 *
423
+	 * @param  EE_Event      $event           Event object being updated
424
+	 * @param  EE_Datetime[] $saved_datetimes an array of datetime ids being updated
425
+	 * @param  array         $data            incoming request data
426
+	 * @return EE_Ticket[]
427
+	 * @throws Exception
428
+	 * @throws ReflectionException
429
+	 * @throws InvalidInterfaceException
430
+	 * @throws InvalidDataTypeException
431
+	 * @throws InvalidArgumentException
432
+	 * @throws EE_Error
433
+	 */
434
+	protected function _update_tickets($event, $saved_datetimes, $data)
435
+	{
436
+		$new_tkt = null;
437
+		$new_default = null;
438
+		// stripslashes because WP filtered the $_POST ($data) array to add slashes
439
+		$data = stripslashes_deep($data);
440
+		$timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null;
441
+		$saved_tickets = $datetimes_on_existing = array();
442
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
443
+		if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) {
444
+			throw new InvalidArgumentException(
445
+				esc_html__(
446
+					'The "edit_tickets" array is invalid therefore the event can not be updated.',
447
+					'event_espresso'
448
+				)
449
+			);
450
+		}
451
+		foreach ($data['edit_tickets'] as $row => $tkt) {
452
+			$update_prices = $create_new_TKT = false;
453
+			// figure out what datetimes were added to the ticket
454
+			// and what datetimes were removed from the ticket in the session.
455
+			$starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][ $row ]);
456
+			$tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][ $row ]);
457
+			$datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows);
458
+			$datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows);
459
+			// trim inputs to ensure any excess whitespace is removed.
460
+			$tkt = array_map(
461
+				function ($ticket_data) {
462
+					return is_array($ticket_data) ? $ticket_data : trim($ticket_data);
463
+				},
464
+				$tkt
465
+			);
466
+			// note we are doing conversions to floats here instead of allowing EE_Money_Field to handle
467
+			// because we're doing calculations prior to using the models.
468
+			// note incoming ['TKT_price'] value is already in standard notation (via js).
469
+			$ticket_price = isset($tkt['TKT_price'])
470
+				? round((float) $tkt['TKT_price'], 3)
471
+				: 0;
472
+			// note incoming base price needs converted from localized value.
473
+			$base_price = isset($tkt['TKT_base_price'])
474
+				? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price'])
475
+				: 0;
476
+			// if ticket price == 0 and $base_price != 0 then ticket price == base_price
477
+			$ticket_price = $ticket_price === 0 && $base_price !== 0
478
+				? $base_price
479
+				: $ticket_price;
480
+			$base_price_id = isset($tkt['TKT_base_price_ID'])
481
+				? $tkt['TKT_base_price_ID']
482
+				: 0;
483
+			$price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][ $row ])
484
+				? $data['edit_prices'][ $row ]
485
+				: array();
486
+			$now = null;
487
+			if (empty($tkt['TKT_start_date'])) {
488
+				// lets' use now in the set timezone.
489
+				$now = new DateTime('now', new DateTimeZone($event->get_timezone()));
490
+				$tkt['TKT_start_date'] = $now->format($this->_date_time_format);
491
+			}
492
+			if (empty($tkt['TKT_end_date'])) {
493
+				/**
494
+				 * set the TKT_end_date to the first datetime attached to the ticket.
495
+				 */
496
+				$first_dtt = $saved_datetimes[ reset($tkt_dtt_rows) ];
497
+				$tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format);
498
+			}
499
+			$TKT_values = array(
500
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
501
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
502
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
503
+				'TKT_description' => ! empty($tkt['TKT_description'])
504
+									 && $tkt['TKT_description'] !== esc_html__(
505
+										 'You can modify this description',
506
+										 'event_espresso'
507
+									 )
508
+					? $tkt['TKT_description']
509
+					: '',
510
+				'TKT_start_date'  => $tkt['TKT_start_date'],
511
+				'TKT_end_date'    => $tkt['TKT_end_date'],
512
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === ''
513
+					? EE_INF
514
+					: $tkt['TKT_qty'],
515
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === ''
516
+					? EE_INF
517
+					: $tkt['TKT_uses'],
518
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
519
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
520
+				'TKT_row'         => $row,
521
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0,
522
+				'TKT_taxable'     => ! empty($tkt['TKT_taxable']) ? 1 : 0,
523
+				'TKT_required'    => ! empty($tkt['TKT_required']) ? 1 : 0,
524
+				'TKT_price'       => $ticket_price,
525
+			);
526
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
527
+			// which means in turn that the prices will become new prices as well.
528
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
529
+				$TKT_values['TKT_ID'] = 0;
530
+				$TKT_values['TKT_is_default'] = 0;
531
+				$update_prices = true;
532
+			}
533
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
534
+			// we actually do our saves ahead of doing any add_relations to
535
+			// because its entirely possible that this ticket wasn't removed or added to any datetime in the session
536
+			// but DID have it's items modified.
537
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
538
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
539
+			if (absint($TKT_values['TKT_ID'])) {
540
+				$ticket = EE_Registry::instance()
541
+									 ->load_model('Ticket', array($timezone))
542
+									 ->get_one_by_ID($tkt['TKT_ID']);
543
+				if ($ticket instanceof EE_Ticket) {
544
+					$ticket = $this->_update_ticket_datetimes(
545
+						$ticket,
546
+						$saved_datetimes,
547
+						$datetimes_added,
548
+						$datetimes_removed
549
+					);
550
+					// are there any registrations using this ticket ?
551
+					$tickets_sold = $ticket->count_related(
552
+						'Registration',
553
+						array(
554
+							array(
555
+								'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)),
556
+							),
557
+						)
558
+					);
559
+					// set ticket formats
560
+					$ticket->set_date_format($this->_date_format_strings['date']);
561
+					$ticket->set_time_format($this->_date_format_strings['time']);
562
+					// let's just check the total price for the existing ticket
563
+					// and determine if it matches the new total price.
564
+					// if they are different then we create a new ticket (if tickets sold)
565
+					// if they aren't different then we go ahead and modify existing ticket.
566
+					$create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted();
567
+					// set new values
568
+					foreach ($TKT_values as $field => $value) {
569
+						if ($field === 'TKT_qty') {
570
+							$ticket->set_qty($value);
571
+						} else {
572
+							$ticket->set($field, $value);
573
+						}
574
+					}
575
+					// if $create_new_TKT is false then we can safely update the existing ticket.
576
+					// Otherwise we have to create a new ticket.
577
+					if ($create_new_TKT) {
578
+						$new_tkt = $this->_duplicate_ticket(
579
+							$ticket,
580
+							$price_rows,
581
+							$ticket_price,
582
+							$base_price,
583
+							$base_price_id
584
+						);
585
+					}
586
+				}
587
+			} else {
588
+				// no TKT_id so a new TKT
589
+				$ticket = EE_Ticket::new_instance(
590
+					$TKT_values,
591
+					$timezone,
592
+					array($this->_date_format_strings['date'], $this->_date_format_strings['time'])
593
+				);
594
+				if ($ticket instanceof EE_Ticket) {
595
+					// make sure ticket has an ID of setting relations won't work
596
+					$ticket->save();
597
+					$ticket = $this->_update_ticket_datetimes(
598
+						$ticket,
599
+						$saved_datetimes,
600
+						$datetimes_added,
601
+						$datetimes_removed
602
+					);
603
+					$update_prices = true;
604
+				}
605
+			}
606
+			// make sure any current values have been saved.
607
+			// $ticket->save();
608
+			// before going any further make sure our dates are setup correctly
609
+			// so that the end date is always equal or greater than the start date.
610
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
611
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
612
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
613
+			}
614
+			// let's make sure the base price is handled
615
+			$ticket = ! $create_new_TKT
616
+				? $this->_add_prices_to_ticket(
617
+					array(),
618
+					$ticket,
619
+					$update_prices,
620
+					$base_price,
621
+					$base_price_id
622
+				)
623
+				: $ticket;
624
+			// add/update price_modifiers
625
+			$ticket = ! $create_new_TKT
626
+				? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices)
627
+				: $ticket;
628
+			// need to make sue that the TKT_price is accurate after saving the prices.
629
+			$ticket->ensure_TKT_Price_correct();
630
+			// handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave.
631
+			if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) {
632
+				$update_prices = true;
633
+				$new_default = clone $ticket;
634
+				$new_default->set('TKT_ID', 0);
635
+				$new_default->set('TKT_is_default', 1);
636
+				$new_default->set('TKT_row', 1);
637
+				$new_default->set('TKT_price', $ticket_price);
638
+				// remove any dtt relations cause we DON'T want dtt relations attached
639
+				// (note this is just removing the cached relations in the object)
640
+				$new_default->_remove_relations('Datetime');
641
+				// @todo we need to add the current attached prices as new prices to the new default ticket.
642
+				$new_default = $this->_add_prices_to_ticket(
643
+					$price_rows,
644
+					$new_default,
645
+					$update_prices
646
+				);
647
+				// don't forget the base price!
648
+				$new_default = $this->_add_prices_to_ticket(
649
+					array(),
650
+					$new_default,
651
+					$update_prices,
652
+					$base_price,
653
+					$base_price_id
654
+				);
655
+				$new_default->save();
656
+				do_action(
657
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket',
658
+					$new_default,
659
+					$row,
660
+					$ticket,
661
+					$data
662
+				);
663
+			}
664
+			// DO ALL dtt relationships for both current tickets and any archived tickets
665
+			// for the given dtt that are related to the current ticket.
666
+			// TODO... not sure exactly how we're going to do this considering we don't know
667
+			// what current ticket the archived tickets are related to
668
+			// (and TKT_parent is used for autosaves so that's not a field we can reliably use).
669
+			// let's assign any tickets that have been setup to the saved_tickets tracker
670
+			// save existing TKT
671
+			$ticket->save();
672
+			if ($create_new_TKT && $new_tkt instanceof EE_Ticket) {
673
+				// save new TKT
674
+				$new_tkt->save();
675
+				// add new ticket to array
676
+				$saved_tickets[ $new_tkt->ID() ] = $new_tkt;
677
+				do_action(
678
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket',
679
+					$new_tkt,
680
+					$row,
681
+					$tkt,
682
+					$data
683
+				);
684
+			} else {
685
+				// add tkt to saved tkts
686
+				$saved_tickets[ $ticket->ID() ] = $ticket;
687
+				do_action(
688
+					'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket',
689
+					$ticket,
690
+					$row,
691
+					$tkt,
692
+					$data
693
+				);
694
+			}
695
+		}
696
+		// now we need to handle tickets actually "deleted permanently".
697
+		// There are cases where we'd want this to happen
698
+		// (i.e. autosaves are happening and then in between autosaves the user trashes a ticket).
699
+		// Or a draft event was saved and in the process of editing a ticket is trashed.
700
+		// No sense in keeping all the related data in the db!
701
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets;
702
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
703
+		foreach ($tickets_removed as $id) {
704
+			$id = absint($id);
705
+			// get the ticket for this id
706
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
707
+			// if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime
708
+			if ($tkt_to_remove->get('TKT_is_default')) {
709
+				continue;
710
+			}
711
+			// if this tkt has any registrations attached so then we just ARCHIVE
712
+			// because we don't actually permanently delete these tickets.
713
+			if ($tkt_to_remove->count_related('Registration') > 0) {
714
+				$tkt_to_remove->delete();
715
+				continue;
716
+			}
717
+			// need to get all the related datetimes on this ticket and remove from every single one of them
718
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
719
+			$datetimes = $tkt_to_remove->get_many_related('Datetime');
720
+			foreach ($datetimes as $datetime) {
721
+				$tkt_to_remove->_remove_relation_to($datetime, 'Datetime');
722
+			}
723
+			// need to do the same for prices (except these prices can also be deleted because again,
724
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
725
+			$tkt_to_remove->delete_related_permanently('Price');
726
+			do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove);
727
+			// finally let's delete this ticket
728
+			// (which should not be blocked at this point b/c we've removed all our relationships)
729
+			$tkt_to_remove->delete_permanently();
730
+		}
731
+		return $saved_tickets;
732
+	}
733 733
 
734 734
 
735
-    /**
736
-     * @access  protected
737
-     * @param EE_Ticket      $ticket
738
-     * @param \EE_Datetime[] $saved_datetimes
739
-     * @param \EE_Datetime[] $added_datetimes
740
-     * @param \EE_Datetime[] $removed_datetimes
741
-     * @return EE_Ticket
742
-     * @throws EE_Error
743
-     */
744
-    protected function _update_ticket_datetimes(
745
-        EE_Ticket $ticket,
746
-        $saved_datetimes = array(),
747
-        $added_datetimes = array(),
748
-        $removed_datetimes = array()
749
-    ) {
750
-        // to start we have to add the ticket to all the datetimes its supposed to be with,
751
-        // and removing the ticket from datetimes it got removed from.
752
-        // first let's add datetimes
753
-        if (! empty($added_datetimes) && is_array($added_datetimes)) {
754
-            foreach ($added_datetimes as $row_id) {
755
-                $row_id = (int) $row_id;
756
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
757
-                    $ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
758
-                    // Is this an existing ticket (has an ID) and does it have any sold?
759
-                    // If so, then we need to add that to the DTT sold because this DTT is getting added.
760
-                    if ($ticket->ID() && $ticket->sold() > 0) {
761
-                        $saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
762
-                    }
763
-                }
764
-            }
765
-        }
766
-        // then remove datetimes
767
-        if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
768
-            foreach ($removed_datetimes as $row_id) {
769
-                $row_id = (int) $row_id;
770
-                // its entirely possible that a datetime got deleted (instead of just removed from relationship.
771
-                // So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
772
-                if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
773
-                    $ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
774
-                    // Is this an existing ticket (has an ID) and does it have any sold?
775
-                    // If so, then we need to remove it's sold from the DTT_sold.
776
-                    if ($ticket->ID() && $ticket->sold() > 0) {
777
-                        $saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
778
-                    }
779
-                }
780
-            }
781
-        }
782
-        // cap ticket qty by datetime reg limits
783
-        $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
784
-        return $ticket;
785
-    }
735
+	/**
736
+	 * @access  protected
737
+	 * @param EE_Ticket      $ticket
738
+	 * @param \EE_Datetime[] $saved_datetimes
739
+	 * @param \EE_Datetime[] $added_datetimes
740
+	 * @param \EE_Datetime[] $removed_datetimes
741
+	 * @return EE_Ticket
742
+	 * @throws EE_Error
743
+	 */
744
+	protected function _update_ticket_datetimes(
745
+		EE_Ticket $ticket,
746
+		$saved_datetimes = array(),
747
+		$added_datetimes = array(),
748
+		$removed_datetimes = array()
749
+	) {
750
+		// to start we have to add the ticket to all the datetimes its supposed to be with,
751
+		// and removing the ticket from datetimes it got removed from.
752
+		// first let's add datetimes
753
+		if (! empty($added_datetimes) && is_array($added_datetimes)) {
754
+			foreach ($added_datetimes as $row_id) {
755
+				$row_id = (int) $row_id;
756
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
757
+					$ticket->_add_relation_to($saved_datetimes[ $row_id ], 'Datetime');
758
+					// Is this an existing ticket (has an ID) and does it have any sold?
759
+					// If so, then we need to add that to the DTT sold because this DTT is getting added.
760
+					if ($ticket->ID() && $ticket->sold() > 0) {
761
+						$saved_datetimes[ $row_id ]->increaseSold($ticket->sold(), false);
762
+					}
763
+				}
764
+			}
765
+		}
766
+		// then remove datetimes
767
+		if (! empty($removed_datetimes) && is_array($removed_datetimes)) {
768
+			foreach ($removed_datetimes as $row_id) {
769
+				$row_id = (int) $row_id;
770
+				// its entirely possible that a datetime got deleted (instead of just removed from relationship.
771
+				// So make sure we skip over this if the dtt isn't in the $saved_datetimes array)
772
+				if (isset($saved_datetimes[ $row_id ]) && $saved_datetimes[ $row_id ] instanceof EE_Datetime) {
773
+					$ticket->_remove_relation_to($saved_datetimes[ $row_id ], 'Datetime');
774
+					// Is this an existing ticket (has an ID) and does it have any sold?
775
+					// If so, then we need to remove it's sold from the DTT_sold.
776
+					if ($ticket->ID() && $ticket->sold() > 0) {
777
+						$saved_datetimes[ $row_id ]->decreaseSold($ticket->sold());
778
+					}
779
+				}
780
+			}
781
+		}
782
+		// cap ticket qty by datetime reg limits
783
+		$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
784
+		return $ticket;
785
+	}
786 786
 
787 787
 
788
-    /**
789
-     * @access  protected
790
-     * @param EE_Ticket $ticket
791
-     * @param array     $price_rows
792
-     * @param int       $ticket_price
793
-     * @param int       $base_price
794
-     * @param int       $base_price_id
795
-     * @return EE_Ticket
796
-     * @throws ReflectionException
797
-     * @throws InvalidArgumentException
798
-     * @throws InvalidInterfaceException
799
-     * @throws InvalidDataTypeException
800
-     * @throws EE_Error
801
-     */
802
-    protected function _duplicate_ticket(
803
-        EE_Ticket $ticket,
804
-        $price_rows = array(),
805
-        $ticket_price = 0,
806
-        $base_price = 0,
807
-        $base_price_id = 0
808
-    ) {
809
-        // create new ticket that's a copy of the existing
810
-        // except a new id of course (and not archived)
811
-        // AND has the new TKT_price associated with it.
812
-        $new_ticket = clone $ticket;
813
-        $new_ticket->set('TKT_ID', 0);
814
-        $new_ticket->set_deleted(0);
815
-        $new_ticket->set_price($ticket_price);
816
-        $new_ticket->set_sold(0);
817
-        // let's get a new ID for this ticket
818
-        $new_ticket->save();
819
-        // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
820
-        $datetimes_on_existing = $ticket->datetimes();
821
-        $new_ticket = $this->_update_ticket_datetimes(
822
-            $new_ticket,
823
-            $datetimes_on_existing,
824
-            array_keys($datetimes_on_existing)
825
-        );
826
-        // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
827
-        // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
828
-        // available.
829
-        if ($ticket->sold() > 0) {
830
-            $new_qty = $ticket->qty() - $ticket->sold();
831
-            $new_ticket->set_qty($new_qty);
832
-        }
833
-        // now we update the prices just for this ticket
834
-        $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
835
-        // and we update the base price
836
-        $new_ticket = $this->_add_prices_to_ticket(
837
-            array(),
838
-            $new_ticket,
839
-            true,
840
-            $base_price,
841
-            $base_price_id
842
-        );
843
-        return $new_ticket;
844
-    }
788
+	/**
789
+	 * @access  protected
790
+	 * @param EE_Ticket $ticket
791
+	 * @param array     $price_rows
792
+	 * @param int       $ticket_price
793
+	 * @param int       $base_price
794
+	 * @param int       $base_price_id
795
+	 * @return EE_Ticket
796
+	 * @throws ReflectionException
797
+	 * @throws InvalidArgumentException
798
+	 * @throws InvalidInterfaceException
799
+	 * @throws InvalidDataTypeException
800
+	 * @throws EE_Error
801
+	 */
802
+	protected function _duplicate_ticket(
803
+		EE_Ticket $ticket,
804
+		$price_rows = array(),
805
+		$ticket_price = 0,
806
+		$base_price = 0,
807
+		$base_price_id = 0
808
+	) {
809
+		// create new ticket that's a copy of the existing
810
+		// except a new id of course (and not archived)
811
+		// AND has the new TKT_price associated with it.
812
+		$new_ticket = clone $ticket;
813
+		$new_ticket->set('TKT_ID', 0);
814
+		$new_ticket->set_deleted(0);
815
+		$new_ticket->set_price($ticket_price);
816
+		$new_ticket->set_sold(0);
817
+		// let's get a new ID for this ticket
818
+		$new_ticket->save();
819
+		// we also need to make sure this new ticket gets the same datetime attachments as the archived ticket
820
+		$datetimes_on_existing = $ticket->datetimes();
821
+		$new_ticket = $this->_update_ticket_datetimes(
822
+			$new_ticket,
823
+			$datetimes_on_existing,
824
+			array_keys($datetimes_on_existing)
825
+		);
826
+		// $ticket will get archived later b/c we are NOT adding it to the saved_tickets array.
827
+		// if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining
828
+		// available.
829
+		if ($ticket->sold() > 0) {
830
+			$new_qty = $ticket->qty() - $ticket->sold();
831
+			$new_ticket->set_qty($new_qty);
832
+		}
833
+		// now we update the prices just for this ticket
834
+		$new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true);
835
+		// and we update the base price
836
+		$new_ticket = $this->_add_prices_to_ticket(
837
+			array(),
838
+			$new_ticket,
839
+			true,
840
+			$base_price,
841
+			$base_price_id
842
+		);
843
+		return $new_ticket;
844
+	}
845 845
 
846 846
 
847
-    /**
848
-     * This attaches a list of given prices to a ticket.
849
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
850
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
851
-     * price info and prices are automatically "archived" via the ticket.
852
-     *
853
-     * @access  private
854
-     * @param array     $prices        Array of prices from the form.
855
-     * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
856
-     * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
857
-     * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
858
-     * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
859
-     * @return EE_Ticket
860
-     * @throws ReflectionException
861
-     * @throws InvalidArgumentException
862
-     * @throws InvalidInterfaceException
863
-     * @throws InvalidDataTypeException
864
-     * @throws EE_Error
865
-     */
866
-    protected function _add_prices_to_ticket(
867
-        $prices = array(),
868
-        EE_Ticket $ticket,
869
-        $new_prices = false,
870
-        $base_price = false,
871
-        $base_price_id = false
872
-    ) {
873
-        // let's just get any current prices that may exist on the given ticket
874
-        // so we can remove any prices that got trashed in this session.
875
-        $current_prices_on_ticket = $base_price !== false
876
-            ? $ticket->base_price(true)
877
-            : $ticket->price_modifiers();
878
-        $updated_prices = array();
879
-        // if $base_price ! FALSE then updating a base price.
880
-        if ($base_price !== false) {
881
-            $prices[1] = array(
882
-                'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
883
-                'PRT_ID'     => 1,
884
-                'PRC_amount' => $base_price,
885
-                'PRC_name'   => $ticket->get('TKT_name'),
886
-                'PRC_desc'   => $ticket->get('TKT_description'),
887
-            );
888
-        }
889
-        // possibly need to save tkt
890
-        if (! $ticket->ID()) {
891
-            $ticket->save();
892
-        }
893
-        foreach ($prices as $row => $prc) {
894
-            $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
895
-            if (empty($prt_id)) {
896
-                continue;
897
-            } //prices MUST have a price type id.
898
-            $PRC_values = array(
899
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
900
-                'PRT_ID'         => $prt_id,
901
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
902
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
903
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
904
-                'PRC_is_default' => false,
905
-                // make sure we set PRC_is_default to false for all ticket saves from event_editor
906
-                'PRC_order'      => $row,
907
-            );
908
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
909
-                $PRC_values['PRC_ID'] = 0;
910
-                $price = EE_Registry::instance()->load_class(
911
-                    'Price',
912
-                    array($PRC_values),
913
-                    false,
914
-                    false
915
-                );
916
-            } else {
917
-                $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
918
-                // update this price with new values
919
-                foreach ($PRC_values as $field => $value) {
920
-                    $price->set($field, $value);
921
-                }
922
-            }
923
-            $price->save();
924
-            $updated_prices[ $price->ID() ] = $price;
925
-            $ticket->_add_relation_to($price, 'Price');
926
-        }
927
-        // now let's remove any prices that got removed from the ticket
928
-        if (! empty($current_prices_on_ticket)) {
929
-            $current = array_keys($current_prices_on_ticket);
930
-            $updated = array_keys($updated_prices);
931
-            $prices_to_remove = array_diff($current, $updated);
932
-            if (! empty($prices_to_remove)) {
933
-                foreach ($prices_to_remove as $prc_id) {
934
-                    $p = $current_prices_on_ticket[ $prc_id ];
935
-                    $ticket->_remove_relation_to($p, 'Price');
936
-                    // delete permanently the price
937
-                    $p->delete_permanently();
938
-                }
939
-            }
940
-        }
941
-        return $ticket;
942
-    }
847
+	/**
848
+	 * This attaches a list of given prices to a ticket.
849
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
850
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
851
+	 * price info and prices are automatically "archived" via the ticket.
852
+	 *
853
+	 * @access  private
854
+	 * @param array     $prices        Array of prices from the form.
855
+	 * @param EE_Ticket $ticket        EE_Ticket object that prices are being attached to.
856
+	 * @param bool      $new_prices    Whether attach existing incoming prices or create new ones.
857
+	 * @param int|bool  $base_price    if FALSE then NOT doing a base price add.
858
+	 * @param int|bool  $base_price_id if present then this is the base_price_id being updated.
859
+	 * @return EE_Ticket
860
+	 * @throws ReflectionException
861
+	 * @throws InvalidArgumentException
862
+	 * @throws InvalidInterfaceException
863
+	 * @throws InvalidDataTypeException
864
+	 * @throws EE_Error
865
+	 */
866
+	protected function _add_prices_to_ticket(
867
+		$prices = array(),
868
+		EE_Ticket $ticket,
869
+		$new_prices = false,
870
+		$base_price = false,
871
+		$base_price_id = false
872
+	) {
873
+		// let's just get any current prices that may exist on the given ticket
874
+		// so we can remove any prices that got trashed in this session.
875
+		$current_prices_on_ticket = $base_price !== false
876
+			? $ticket->base_price(true)
877
+			: $ticket->price_modifiers();
878
+		$updated_prices = array();
879
+		// if $base_price ! FALSE then updating a base price.
880
+		if ($base_price !== false) {
881
+			$prices[1] = array(
882
+				'PRC_ID'     => $new_prices || $base_price_id === 1 ? null : $base_price_id,
883
+				'PRT_ID'     => 1,
884
+				'PRC_amount' => $base_price,
885
+				'PRC_name'   => $ticket->get('TKT_name'),
886
+				'PRC_desc'   => $ticket->get('TKT_description'),
887
+			);
888
+		}
889
+		// possibly need to save tkt
890
+		if (! $ticket->ID()) {
891
+			$ticket->save();
892
+		}
893
+		foreach ($prices as $row => $prc) {
894
+			$prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null;
895
+			if (empty($prt_id)) {
896
+				continue;
897
+			} //prices MUST have a price type id.
898
+			$PRC_values = array(
899
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
900
+				'PRT_ID'         => $prt_id,
901
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
902
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
903
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
904
+				'PRC_is_default' => false,
905
+				// make sure we set PRC_is_default to false for all ticket saves from event_editor
906
+				'PRC_order'      => $row,
907
+			);
908
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
909
+				$PRC_values['PRC_ID'] = 0;
910
+				$price = EE_Registry::instance()->load_class(
911
+					'Price',
912
+					array($PRC_values),
913
+					false,
914
+					false
915
+				);
916
+			} else {
917
+				$price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
918
+				// update this price with new values
919
+				foreach ($PRC_values as $field => $value) {
920
+					$price->set($field, $value);
921
+				}
922
+			}
923
+			$price->save();
924
+			$updated_prices[ $price->ID() ] = $price;
925
+			$ticket->_add_relation_to($price, 'Price');
926
+		}
927
+		// now let's remove any prices that got removed from the ticket
928
+		if (! empty($current_prices_on_ticket)) {
929
+			$current = array_keys($current_prices_on_ticket);
930
+			$updated = array_keys($updated_prices);
931
+			$prices_to_remove = array_diff($current, $updated);
932
+			if (! empty($prices_to_remove)) {
933
+				foreach ($prices_to_remove as $prc_id) {
934
+					$p = $current_prices_on_ticket[ $prc_id ];
935
+					$ticket->_remove_relation_to($p, 'Price');
936
+					// delete permanently the price
937
+					$p->delete_permanently();
938
+				}
939
+			}
940
+		}
941
+		return $ticket;
942
+	}
943 943
 
944 944
 
945
-    /**
946
-     * @param Events_Admin_Page $event_admin_obj
947
-     * @return Events_Admin_Page
948
-     */
949
-    public function autosave_handling(Events_Admin_Page $event_admin_obj)
950
-    {
951
-        return $event_admin_obj;
952
-        // doing nothing for the moment.
953
-        // todo when I get to this remember that I need to set the template args on the $event_admin_obj
954
-        // (use the set_template_args() method)
955
-        /**
956
-         * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
957
-         * 1. TKT_is_default_selector (visible)
958
-         * 2. TKT_is_default (hidden)
959
-         * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
960
-         * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
961
-         * this ticket to be saved as a default.
962
-         * The tricky part is, on an initial display on create or edit (or after manually updating),
963
-         * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
964
-         * if this is a create.  However, after an autosave, users will want some sort of indicator that
965
-         * the TKT HAS been saved as a default..
966
-         * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
967
-         * On Autosave:
968
-         * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
969
-         * then set the TKT_is_default to false.
970
-         * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
971
-         *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
972
-         * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
973
-         */
974
-    }
945
+	/**
946
+	 * @param Events_Admin_Page $event_admin_obj
947
+	 * @return Events_Admin_Page
948
+	 */
949
+	public function autosave_handling(Events_Admin_Page $event_admin_obj)
950
+	{
951
+		return $event_admin_obj;
952
+		// doing nothing for the moment.
953
+		// todo when I get to this remember that I need to set the template args on the $event_admin_obj
954
+		// (use the set_template_args() method)
955
+		/**
956
+		 * need to remember to handle TICKET DEFAULT saves correctly:  I've got two input fields in the dom:
957
+		 * 1. TKT_is_default_selector (visible)
958
+		 * 2. TKT_is_default (hidden)
959
+		 * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket
960
+		 * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want
961
+		 * this ticket to be saved as a default.
962
+		 * The tricky part is, on an initial display on create or edit (or after manually updating),
963
+		 * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true
964
+		 * if this is a create.  However, after an autosave, users will want some sort of indicator that
965
+		 * the TKT HAS been saved as a default..
966
+		 * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking.
967
+		 * On Autosave:
968
+		 * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements,
969
+		 * then set the TKT_is_default to false.
970
+		 * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well).
971
+		 *  We do NOT create a new default ticket.  The checkbox stays selected after autosave.
972
+		 * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket.
973
+		 */
974
+	}
975 975
 
976 976
 
977
-    /**
978
-     * @throws ReflectionException
979
-     * @throws InvalidArgumentException
980
-     * @throws InvalidInterfaceException
981
-     * @throws InvalidDataTypeException
982
-     * @throws DomainException
983
-     * @throws EE_Error
984
-     */
985
-    public function pricing_metabox()
986
-    {
987
-        $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
988
-        $event = $this->_adminpage_obj->get_cpt_model_obj();
989
-        // set is_creating_event property.
990
-        $EVT_ID = $event->ID();
991
-        $this->_is_creating_event = empty($this->_req_data['post']);
992
-        // default main template args
993
-        $main_template_args = array(
994
-            'event_datetime_help_link' => EEH_Template::get_help_tab_link(
995
-                'event_editor_event_datetimes_help_tab',
996
-                $this->_adminpage_obj->page_slug,
997
-                $this->_adminpage_obj->get_req_action(),
998
-                false,
999
-                false
1000
-            ),
1001
-            // todo need to add a filter to the template for the help text
1002
-            // in the Events_Admin_Page core file so we can add further help
1003
-            'existing_datetime_ids'    => '',
1004
-            'total_dtt_rows'           => 1,
1005
-            'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1006
-                'add_new_dtt_info',
1007
-                $this->_adminpage_obj->page_slug,
1008
-                $this->_adminpage_obj->get_req_action(),
1009
-                false,
1010
-                false
1011
-            ),
1012
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1013
-            'datetime_rows'            => '',
1014
-            'show_tickets_container'   => '',
1015
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1016
-            'ticket_rows'              => '',
1017
-            'existing_ticket_ids'      => '',
1018
-            'total_ticket_rows'        => 1,
1019
-            'ticket_js_structure'      => '',
1020
-            'ee_collapsible_status'    => ' ee-collapsible-open'
1021
-            // $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1022
-        );
1023
-        $timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1024
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1025
-        /**
1026
-         * 1. Start with retrieving Datetimes
1027
-         * 2. For each datetime get related tickets
1028
-         * 3. For each ticket get related prices
1029
-         */
1030
-        /** @var EEM_Datetime $datetime_model */
1031
-        $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1032
-        $datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1033
-        $main_template_args['total_dtt_rows'] = count($datetimes);
1034
-        /**
1035
-         * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1036
-         * for why we are counting $datetime_row and then setting that on the Datetime object
1037
-         */
1038
-        $datetime_row = 1;
1039
-        foreach ($datetimes as $datetime) {
1040
-            $DTT_ID = $datetime->get('DTT_ID');
1041
-            $datetime->set('DTT_order', $datetime_row);
1042
-            $existing_datetime_ids[] = $DTT_ID;
1043
-            // tickets attached
1044
-            $related_tickets = $datetime->ID() > 0
1045
-                ? $datetime->get_many_related(
1046
-                    'Ticket',
1047
-                    array(
1048
-                        array(
1049
-                            'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1050
-                        ),
1051
-                        'default_where_conditions' => 'none',
1052
-                        'order_by'                 => array('TKT_order' => 'ASC'),
1053
-                    )
1054
-                )
1055
-                : array();
1056
-            // if there are no related tickets this is likely a new event OR autodraft
1057
-            // event so we need to generate the default tickets because datetimes
1058
-            // ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1059
-            // datetime on the event.
1060
-            if (empty($related_tickets) && count($datetimes) < 2) {
1061
-                /** @var EEM_Ticket $ticket_model */
1062
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
1063
-                $related_tickets = $ticket_model->get_all_default_tickets();
1064
-                // this should be ordered by TKT_ID, so let's grab the first default ticket
1065
-                // (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1066
-                $default_prices = EEM_Price::instance()->get_all_default_prices();
1067
-                $main_default_ticket = reset($related_tickets);
1068
-                if ($main_default_ticket instanceof EE_Ticket) {
1069
-                    foreach ($default_prices as $default_price) {
1070
-                        if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1071
-                            continue;
1072
-                        }
1073
-                        $main_default_ticket->cache('Price', $default_price);
1074
-                    }
1075
-                }
1076
-            }
1077
-            // we can't actually setup rows in this loop yet cause we don't know all
1078
-            // the unique tickets for this event yet (tickets are linked through all datetimes).
1079
-            // So we're going to temporarily cache some of that information.
1080
-            // loop through and setup the ticket rows and make sure the order is set.
1081
-            foreach ($related_tickets as $ticket) {
1082
-                $TKT_ID = $ticket->get('TKT_ID');
1083
-                $ticket_row = $ticket->get('TKT_row');
1084
-                // we only want unique tickets in our final display!!
1085
-                if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1086
-                    $existing_ticket_ids[] = $TKT_ID;
1087
-                    $all_tickets[] = $ticket;
1088
-                }
1089
-                // temporary cache of this ticket info for this datetime for later processing of datetime rows.
1090
-                $datetime_tickets[ $DTT_ID ][] = $ticket_row;
1091
-                // temporary cache of this datetime info for this ticket for later processing of ticket rows.
1092
-                if (! isset($ticket_datetimes[ $TKT_ID ])
1093
-                    || ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1094
-                ) {
1095
-                    $ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1096
-                }
1097
-            }
1098
-            $datetime_row++;
1099
-        }
1100
-        $main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1101
-        $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1102
-        $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1103
-        // sort $all_tickets by order
1104
-        usort(
1105
-            $all_tickets,
1106
-            function (EE_Ticket $a, EE_Ticket $b) {
1107
-                $a_order = (int) $a->get('TKT_order');
1108
-                $b_order = (int) $b->get('TKT_order');
1109
-                if ($a_order === $b_order) {
1110
-                    return 0;
1111
-                }
1112
-                return ($a_order < $b_order) ? -1 : 1;
1113
-            }
1114
-        );
1115
-        // k NOW we have all the data we need for setting up the dtt rows
1116
-        // and ticket rows so we start our dtt loop again.
1117
-        $datetime_row = 1;
1118
-        foreach ($datetimes as $datetime) {
1119
-            $main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1120
-                $datetime_row,
1121
-                $datetime,
1122
-                $datetime_tickets,
1123
-                $all_tickets,
1124
-                false,
1125
-                $datetimes
1126
-            );
1127
-            $datetime_row++;
1128
-        }
1129
-        // then loop through all tickets for the ticket rows.
1130
-        $ticket_row = 1;
1131
-        foreach ($all_tickets as $ticket) {
1132
-            $main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1133
-                $ticket_row,
1134
-                $ticket,
1135
-                $ticket_datetimes,
1136
-                $datetimes,
1137
-                false,
1138
-                $all_tickets
1139
-            );
1140
-            $ticket_row++;
1141
-        }
1142
-        $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1143
-        EEH_Template::display_template(
1144
-            PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1145
-            $main_template_args
1146
-        );
1147
-    }
977
+	/**
978
+	 * @throws ReflectionException
979
+	 * @throws InvalidArgumentException
980
+	 * @throws InvalidInterfaceException
981
+	 * @throws InvalidDataTypeException
982
+	 * @throws DomainException
983
+	 * @throws EE_Error
984
+	 */
985
+	public function pricing_metabox()
986
+	{
987
+		$existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array();
988
+		$event = $this->_adminpage_obj->get_cpt_model_obj();
989
+		// set is_creating_event property.
990
+		$EVT_ID = $event->ID();
991
+		$this->_is_creating_event = empty($this->_req_data['post']);
992
+		// default main template args
993
+		$main_template_args = array(
994
+			'event_datetime_help_link' => EEH_Template::get_help_tab_link(
995
+				'event_editor_event_datetimes_help_tab',
996
+				$this->_adminpage_obj->page_slug,
997
+				$this->_adminpage_obj->get_req_action(),
998
+				false,
999
+				false
1000
+			),
1001
+			// todo need to add a filter to the template for the help text
1002
+			// in the Events_Admin_Page core file so we can add further help
1003
+			'existing_datetime_ids'    => '',
1004
+			'total_dtt_rows'           => 1,
1005
+			'add_new_dtt_help_link'    => EEH_Template::get_help_tab_link(
1006
+				'add_new_dtt_info',
1007
+				$this->_adminpage_obj->page_slug,
1008
+				$this->_adminpage_obj->get_req_action(),
1009
+				false,
1010
+				false
1011
+			),
1012
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1013
+			'datetime_rows'            => '',
1014
+			'show_tickets_container'   => '',
1015
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '',
1016
+			'ticket_rows'              => '',
1017
+			'existing_ticket_ids'      => '',
1018
+			'total_ticket_rows'        => 1,
1019
+			'ticket_js_structure'      => '',
1020
+			'ee_collapsible_status'    => ' ee-collapsible-open'
1021
+			// $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open'
1022
+		);
1023
+		$timezone = $event instanceof EE_Event ? $event->timezone_string() : null;
1024
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1025
+		/**
1026
+		 * 1. Start with retrieving Datetimes
1027
+		 * 2. For each datetime get related tickets
1028
+		 * 3. For each ticket get related prices
1029
+		 */
1030
+		/** @var EEM_Datetime $datetime_model */
1031
+		$datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone));
1032
+		$datetimes = $datetime_model->get_all_event_dates($EVT_ID);
1033
+		$main_template_args['total_dtt_rows'] = count($datetimes);
1034
+		/**
1035
+		 * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486
1036
+		 * for why we are counting $datetime_row and then setting that on the Datetime object
1037
+		 */
1038
+		$datetime_row = 1;
1039
+		foreach ($datetimes as $datetime) {
1040
+			$DTT_ID = $datetime->get('DTT_ID');
1041
+			$datetime->set('DTT_order', $datetime_row);
1042
+			$existing_datetime_ids[] = $DTT_ID;
1043
+			// tickets attached
1044
+			$related_tickets = $datetime->ID() > 0
1045
+				? $datetime->get_many_related(
1046
+					'Ticket',
1047
+					array(
1048
+						array(
1049
+							'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0),
1050
+						),
1051
+						'default_where_conditions' => 'none',
1052
+						'order_by'                 => array('TKT_order' => 'ASC'),
1053
+					)
1054
+				)
1055
+				: array();
1056
+			// if there are no related tickets this is likely a new event OR autodraft
1057
+			// event so we need to generate the default tickets because datetimes
1058
+			// ALWAYS have at least one related ticket!!.  EXCEPT, we dont' do this if there is already more than one
1059
+			// datetime on the event.
1060
+			if (empty($related_tickets) && count($datetimes) < 2) {
1061
+				/** @var EEM_Ticket $ticket_model */
1062
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
1063
+				$related_tickets = $ticket_model->get_all_default_tickets();
1064
+				// this should be ordered by TKT_ID, so let's grab the first default ticket
1065
+				// (which will be the main default) and ensure it has any default prices added to it (but do NOT save).
1066
+				$default_prices = EEM_Price::instance()->get_all_default_prices();
1067
+				$main_default_ticket = reset($related_tickets);
1068
+				if ($main_default_ticket instanceof EE_Ticket) {
1069
+					foreach ($default_prices as $default_price) {
1070
+						if ($default_price instanceof EE_Price && $default_price->is_base_price()) {
1071
+							continue;
1072
+						}
1073
+						$main_default_ticket->cache('Price', $default_price);
1074
+					}
1075
+				}
1076
+			}
1077
+			// we can't actually setup rows in this loop yet cause we don't know all
1078
+			// the unique tickets for this event yet (tickets are linked through all datetimes).
1079
+			// So we're going to temporarily cache some of that information.
1080
+			// loop through and setup the ticket rows and make sure the order is set.
1081
+			foreach ($related_tickets as $ticket) {
1082
+				$TKT_ID = $ticket->get('TKT_ID');
1083
+				$ticket_row = $ticket->get('TKT_row');
1084
+				// we only want unique tickets in our final display!!
1085
+				if (! in_array($TKT_ID, $existing_ticket_ids, true)) {
1086
+					$existing_ticket_ids[] = $TKT_ID;
1087
+					$all_tickets[] = $ticket;
1088
+				}
1089
+				// temporary cache of this ticket info for this datetime for later processing of datetime rows.
1090
+				$datetime_tickets[ $DTT_ID ][] = $ticket_row;
1091
+				// temporary cache of this datetime info for this ticket for later processing of ticket rows.
1092
+				if (! isset($ticket_datetimes[ $TKT_ID ])
1093
+					|| ! in_array($datetime_row, $ticket_datetimes[ $TKT_ID ], true)
1094
+				) {
1095
+					$ticket_datetimes[ $TKT_ID ][] = $datetime_row;
1096
+				}
1097
+			}
1098
+			$datetime_row++;
1099
+		}
1100
+		$main_template_args['total_ticket_rows'] = count($existing_ticket_ids);
1101
+		$main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1102
+		$main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1103
+		// sort $all_tickets by order
1104
+		usort(
1105
+			$all_tickets,
1106
+			function (EE_Ticket $a, EE_Ticket $b) {
1107
+				$a_order = (int) $a->get('TKT_order');
1108
+				$b_order = (int) $b->get('TKT_order');
1109
+				if ($a_order === $b_order) {
1110
+					return 0;
1111
+				}
1112
+				return ($a_order < $b_order) ? -1 : 1;
1113
+			}
1114
+		);
1115
+		// k NOW we have all the data we need for setting up the dtt rows
1116
+		// and ticket rows so we start our dtt loop again.
1117
+		$datetime_row = 1;
1118
+		foreach ($datetimes as $datetime) {
1119
+			$main_template_args['datetime_rows'] .= $this->_get_datetime_row(
1120
+				$datetime_row,
1121
+				$datetime,
1122
+				$datetime_tickets,
1123
+				$all_tickets,
1124
+				false,
1125
+				$datetimes
1126
+			);
1127
+			$datetime_row++;
1128
+		}
1129
+		// then loop through all tickets for the ticket rows.
1130
+		$ticket_row = 1;
1131
+		foreach ($all_tickets as $ticket) {
1132
+			$main_template_args['ticket_rows'] .= $this->_get_ticket_row(
1133
+				$ticket_row,
1134
+				$ticket,
1135
+				$ticket_datetimes,
1136
+				$datetimes,
1137
+				false,
1138
+				$all_tickets
1139
+			);
1140
+			$ticket_row++;
1141
+		}
1142
+		$main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets);
1143
+		EEH_Template::display_template(
1144
+			PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php',
1145
+			$main_template_args
1146
+		);
1147
+	}
1148 1148
 
1149 1149
 
1150
-    /**
1151
-     * @param int         $datetime_row
1152
-     * @param EE_Datetime $datetime
1153
-     * @param array       $datetime_tickets
1154
-     * @param array       $all_tickets
1155
-     * @param bool        $default
1156
-     * @param array       $all_datetimes
1157
-     * @return mixed
1158
-     * @throws DomainException
1159
-     * @throws EE_Error
1160
-     */
1161
-    protected function _get_datetime_row(
1162
-        $datetime_row,
1163
-        EE_Datetime $datetime,
1164
-        $datetime_tickets = array(),
1165
-        $all_tickets = array(),
1166
-        $default = false,
1167
-        $all_datetimes = array()
1168
-    ) {
1169
-        $dtt_display_template_args = array(
1170
-            'dtt_edit_row'             => $this->_get_dtt_edit_row(
1171
-                $datetime_row,
1172
-                $datetime,
1173
-                $default,
1174
-                $all_datetimes
1175
-            ),
1176
-            'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1177
-                $datetime_row,
1178
-                $datetime,
1179
-                $datetime_tickets,
1180
-                $all_tickets,
1181
-                $default
1182
-            ),
1183
-            'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1184
-        );
1185
-        return EEH_Template::display_template(
1186
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1187
-            $dtt_display_template_args,
1188
-            true
1189
-        );
1190
-    }
1150
+	/**
1151
+	 * @param int         $datetime_row
1152
+	 * @param EE_Datetime $datetime
1153
+	 * @param array       $datetime_tickets
1154
+	 * @param array       $all_tickets
1155
+	 * @param bool        $default
1156
+	 * @param array       $all_datetimes
1157
+	 * @return mixed
1158
+	 * @throws DomainException
1159
+	 * @throws EE_Error
1160
+	 */
1161
+	protected function _get_datetime_row(
1162
+		$datetime_row,
1163
+		EE_Datetime $datetime,
1164
+		$datetime_tickets = array(),
1165
+		$all_tickets = array(),
1166
+		$default = false,
1167
+		$all_datetimes = array()
1168
+	) {
1169
+		$dtt_display_template_args = array(
1170
+			'dtt_edit_row'             => $this->_get_dtt_edit_row(
1171
+				$datetime_row,
1172
+				$datetime,
1173
+				$default,
1174
+				$all_datetimes
1175
+			),
1176
+			'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row(
1177
+				$datetime_row,
1178
+				$datetime,
1179
+				$datetime_tickets,
1180
+				$all_tickets,
1181
+				$default
1182
+			),
1183
+			'dtt_row'                  => $default ? 'DTTNUM' : $datetime_row,
1184
+		);
1185
+		return EEH_Template::display_template(
1186
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php',
1187
+			$dtt_display_template_args,
1188
+			true
1189
+		);
1190
+	}
1191 1191
 
1192 1192
 
1193
-    /**
1194
-     * This method is used to generate a dtt fields  edit row.
1195
-     * The same row is used to generate a row with valid DTT objects
1196
-     * and the default row that is used as the skeleton by the js.
1197
-     *
1198
-     * @param int           $datetime_row  The row number for the row being generated.
1199
-     * @param EE_Datetime   $datetime
1200
-     * @param bool          $default       Whether a default row is being generated or not.
1201
-     * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1202
-     * @return string
1203
-     * @throws DomainException
1204
-     * @throws EE_Error
1205
-     */
1206
-    protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1207
-    {
1208
-        // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1209
-        $default = ! $datetime instanceof EE_Datetime ? true : $default;
1210
-        $template_args = array(
1211
-            'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1212
-            'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1213
-            'edit_dtt_expanded'    => '',
1214
-            'DTT_ID'               => $default ? '' : $datetime->ID(),
1215
-            'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1216
-            'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1217
-            'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1218
-            'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1219
-            'DTT_reg_limit'        => $default
1220
-                ? ''
1221
-                : $datetime->get_pretty(
1222
-                    'DTT_reg_limit',
1223
-                    'input'
1224
-                ),
1225
-            'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1226
-            'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1227
-            'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1228
-            'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1229
-                ? ''
1230
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1231
-            'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1232
-                ? 'ee-lock-icon'
1233
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1234
-            'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1235
-                ? ''
1236
-                : EE_Admin_Page::add_query_args_and_nonce(
1237
-                    array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1238
-                    REG_ADMIN_URL
1239
-                ),
1240
-        );
1241
-        $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1242
-            ? ' style="display:none"'
1243
-            : '';
1244
-        // allow filtering of template args at this point.
1245
-        $template_args = apply_filters(
1246
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1247
-            $template_args,
1248
-            $datetime_row,
1249
-            $datetime,
1250
-            $default,
1251
-            $all_datetimes,
1252
-            $this->_is_creating_event
1253
-        );
1254
-        return EEH_Template::display_template(
1255
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1256
-            $template_args,
1257
-            true
1258
-        );
1259
-    }
1193
+	/**
1194
+	 * This method is used to generate a dtt fields  edit row.
1195
+	 * The same row is used to generate a row with valid DTT objects
1196
+	 * and the default row that is used as the skeleton by the js.
1197
+	 *
1198
+	 * @param int           $datetime_row  The row number for the row being generated.
1199
+	 * @param EE_Datetime   $datetime
1200
+	 * @param bool          $default       Whether a default row is being generated or not.
1201
+	 * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor.
1202
+	 * @return string
1203
+	 * @throws DomainException
1204
+	 * @throws EE_Error
1205
+	 */
1206
+	protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes)
1207
+	{
1208
+		// if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true.
1209
+		$default = ! $datetime instanceof EE_Datetime ? true : $default;
1210
+		$template_args = array(
1211
+			'dtt_row'              => $default ? 'DTTNUM' : $datetime_row,
1212
+			'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1213
+			'edit_dtt_expanded'    => '',
1214
+			'DTT_ID'               => $default ? '' : $datetime->ID(),
1215
+			'DTT_name'             => $default ? '' : $datetime->get_f('DTT_name'),
1216
+			'DTT_description'      => $default ? '' : $datetime->get_f('DTT_description'),
1217
+			'DTT_EVT_start'        => $default ? '' : $datetime->start_date($this->_date_time_format),
1218
+			'DTT_EVT_end'          => $default ? '' : $datetime->end_date($this->_date_time_format),
1219
+			'DTT_reg_limit'        => $default
1220
+				? ''
1221
+				: $datetime->get_pretty(
1222
+					'DTT_reg_limit',
1223
+					'input'
1224
+				),
1225
+			'DTT_order'            => $default ? 'DTTNUM' : $datetime_row,
1226
+			'dtt_sold'             => $default ? '0' : $datetime->get('DTT_sold'),
1227
+			'dtt_reserved'         => $default ? '0' : $datetime->reserved(),
1228
+			'clone_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1229
+				? ''
1230
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1231
+			'trash_icon'           => ! empty($datetime) && $datetime->get('DTT_sold') > 0
1232
+				? 'ee-lock-icon'
1233
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1234
+			'reg_list_url'         => $default || ! $datetime->event() instanceof \EE_Event
1235
+				? ''
1236
+				: EE_Admin_Page::add_query_args_and_nonce(
1237
+					array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()),
1238
+					REG_ADMIN_URL
1239
+				),
1240
+		);
1241
+		$template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1242
+			? ' style="display:none"'
1243
+			: '';
1244
+		// allow filtering of template args at this point.
1245
+		$template_args = apply_filters(
1246
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args',
1247
+			$template_args,
1248
+			$datetime_row,
1249
+			$datetime,
1250
+			$default,
1251
+			$all_datetimes,
1252
+			$this->_is_creating_event
1253
+		);
1254
+		return EEH_Template::display_template(
1255
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php',
1256
+			$template_args,
1257
+			true
1258
+		);
1259
+	}
1260 1260
 
1261 1261
 
1262
-    /**
1263
-     * @param int         $datetime_row
1264
-     * @param EE_Datetime $datetime
1265
-     * @param array       $datetime_tickets
1266
-     * @param array       $all_tickets
1267
-     * @param bool        $default
1268
-     * @return mixed
1269
-     * @throws DomainException
1270
-     * @throws EE_Error
1271
-     */
1272
-    protected function _get_dtt_attached_tickets_row(
1273
-        $datetime_row,
1274
-        $datetime,
1275
-        $datetime_tickets = array(),
1276
-        $all_tickets = array(),
1277
-        $default
1278
-    ) {
1279
-        $template_args = array(
1280
-            'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1281
-            'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1282
-            'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1283
-            'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1284
-            'show_tickets_row'                  => ' style="display:none;"',
1285
-            'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1286
-                'add_new_ticket_via_datetime',
1287
-                $this->_adminpage_obj->page_slug,
1288
-                $this->_adminpage_obj->get_req_action(),
1289
-                false,
1290
-                false
1291
-            ),
1292
-            // todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1293
-            'DTT_ID'                            => $default ? '' : $datetime->ID(),
1294
-        );
1295
-        // need to setup the list items (but only if this isn't a default skeleton setup)
1296
-        if (! $default) {
1297
-            $ticket_row = 1;
1298
-            foreach ($all_tickets as $ticket) {
1299
-                $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1300
-                    $datetime_row,
1301
-                    $ticket_row,
1302
-                    $datetime,
1303
-                    $ticket,
1304
-                    $datetime_tickets,
1305
-                    $default
1306
-                );
1307
-                $ticket_row++;
1308
-            }
1309
-        }
1310
-        // filter template args at this point
1311
-        $template_args = apply_filters(
1312
-            'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1313
-            $template_args,
1314
-            $datetime_row,
1315
-            $datetime,
1316
-            $datetime_tickets,
1317
-            $all_tickets,
1318
-            $default,
1319
-            $this->_is_creating_event
1320
-        );
1321
-        return EEH_Template::display_template(
1322
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1323
-            $template_args,
1324
-            true
1325
-        );
1326
-    }
1262
+	/**
1263
+	 * @param int         $datetime_row
1264
+	 * @param EE_Datetime $datetime
1265
+	 * @param array       $datetime_tickets
1266
+	 * @param array       $all_tickets
1267
+	 * @param bool        $default
1268
+	 * @return mixed
1269
+	 * @throws DomainException
1270
+	 * @throws EE_Error
1271
+	 */
1272
+	protected function _get_dtt_attached_tickets_row(
1273
+		$datetime_row,
1274
+		$datetime,
1275
+		$datetime_tickets = array(),
1276
+		$all_tickets = array(),
1277
+		$default
1278
+	) {
1279
+		$template_args = array(
1280
+			'dtt_row'                           => $default ? 'DTTNUM' : $datetime_row,
1281
+			'event_datetimes_name'              => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes',
1282
+			'DTT_description'                   => $default ? '' : $datetime->get_f('DTT_description'),
1283
+			'datetime_tickets_list'             => $default ? '<li class="hidden"></li>' : '',
1284
+			'show_tickets_row'                  => ' style="display:none;"',
1285
+			'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link(
1286
+				'add_new_ticket_via_datetime',
1287
+				$this->_adminpage_obj->page_slug,
1288
+				$this->_adminpage_obj->get_req_action(),
1289
+				false,
1290
+				false
1291
+			),
1292
+			// todo need to add this help info id to the Events_Admin_Page core file so we can access it here.
1293
+			'DTT_ID'                            => $default ? '' : $datetime->ID(),
1294
+		);
1295
+		// need to setup the list items (but only if this isn't a default skeleton setup)
1296
+		if (! $default) {
1297
+			$ticket_row = 1;
1298
+			foreach ($all_tickets as $ticket) {
1299
+				$template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
1300
+					$datetime_row,
1301
+					$ticket_row,
1302
+					$datetime,
1303
+					$ticket,
1304
+					$datetime_tickets,
1305
+					$default
1306
+				);
1307
+				$ticket_row++;
1308
+			}
1309
+		}
1310
+		// filter template args at this point
1311
+		$template_args = apply_filters(
1312
+			'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args',
1313
+			$template_args,
1314
+			$datetime_row,
1315
+			$datetime,
1316
+			$datetime_tickets,
1317
+			$all_tickets,
1318
+			$default,
1319
+			$this->_is_creating_event
1320
+		);
1321
+		return EEH_Template::display_template(
1322
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php',
1323
+			$template_args,
1324
+			true
1325
+		);
1326
+	}
1327 1327
 
1328 1328
 
1329
-    /**
1330
-     * @param int         $datetime_row
1331
-     * @param int         $ticket_row
1332
-     * @param EE_Datetime $datetime
1333
-     * @param EE_Ticket   $ticket
1334
-     * @param array       $datetime_tickets
1335
-     * @param bool        $default
1336
-     * @return mixed
1337
-     * @throws DomainException
1338
-     * @throws EE_Error
1339
-     */
1340
-    protected function _get_datetime_tickets_list_item(
1341
-        $datetime_row,
1342
-        $ticket_row,
1343
-        $datetime,
1344
-        $ticket,
1345
-        $datetime_tickets = array(),
1346
-        $default
1347
-    ) {
1348
-        $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1349
-            ? $datetime_tickets[ $datetime->ID() ]
1350
-            : array();
1351
-        $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1352
-        $no_ticket = $default && empty($ticket);
1353
-        $template_args = array(
1354
-            'dtt_row'                 => $default
1355
-                ? 'DTTNUM'
1356
-                : $datetime_row,
1357
-            'tkt_row'                 => $no_ticket
1358
-                ? 'TICKETNUM'
1359
-                : $ticket_row,
1360
-            'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1361
-                ? ' checked="checked"'
1362
-                : '',
1363
-            'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1364
-                ? ' ticket-selected'
1365
-                : '',
1366
-            'TKT_name'                => $no_ticket
1367
-                ? 'TKTNAME'
1368
-                : $ticket->get('TKT_name'),
1369
-            'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1370
-                ? ' tkt-status-' . EE_Ticket::onsale
1371
-                : ' tkt-status-' . $ticket->ticket_status(),
1372
-        );
1373
-        // filter template args
1374
-        $template_args = apply_filters(
1375
-            'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1376
-            $template_args,
1377
-            $datetime_row,
1378
-            $ticket_row,
1379
-            $datetime,
1380
-            $ticket,
1381
-            $datetime_tickets,
1382
-            $default,
1383
-            $this->_is_creating_event
1384
-        );
1385
-        return EEH_Template::display_template(
1386
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1387
-            $template_args,
1388
-            true
1389
-        );
1390
-    }
1329
+	/**
1330
+	 * @param int         $datetime_row
1331
+	 * @param int         $ticket_row
1332
+	 * @param EE_Datetime $datetime
1333
+	 * @param EE_Ticket   $ticket
1334
+	 * @param array       $datetime_tickets
1335
+	 * @param bool        $default
1336
+	 * @return mixed
1337
+	 * @throws DomainException
1338
+	 * @throws EE_Error
1339
+	 */
1340
+	protected function _get_datetime_tickets_list_item(
1341
+		$datetime_row,
1342
+		$ticket_row,
1343
+		$datetime,
1344
+		$ticket,
1345
+		$datetime_tickets = array(),
1346
+		$default
1347
+	) {
1348
+		$dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[ $datetime->ID() ])
1349
+			? $datetime_tickets[ $datetime->ID() ]
1350
+			: array();
1351
+		$display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0;
1352
+		$no_ticket = $default && empty($ticket);
1353
+		$template_args = array(
1354
+			'dtt_row'                 => $default
1355
+				? 'DTTNUM'
1356
+				: $datetime_row,
1357
+			'tkt_row'                 => $no_ticket
1358
+				? 'TICKETNUM'
1359
+				: $ticket_row,
1360
+			'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true)
1361
+				? ' checked="checked"'
1362
+				: '',
1363
+			'ticket_selected'         => in_array($display_row, $dtt_tkts, true)
1364
+				? ' ticket-selected'
1365
+				: '',
1366
+			'TKT_name'                => $no_ticket
1367
+				? 'TKTNAME'
1368
+				: $ticket->get('TKT_name'),
1369
+			'tkt_status_class'        => $no_ticket || $this->_is_creating_event
1370
+				? ' tkt-status-' . EE_Ticket::onsale
1371
+				: ' tkt-status-' . $ticket->ticket_status(),
1372
+		);
1373
+		// filter template args
1374
+		$template_args = apply_filters(
1375
+			'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args',
1376
+			$template_args,
1377
+			$datetime_row,
1378
+			$ticket_row,
1379
+			$datetime,
1380
+			$ticket,
1381
+			$datetime_tickets,
1382
+			$default,
1383
+			$this->_is_creating_event
1384
+		);
1385
+		return EEH_Template::display_template(
1386
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php',
1387
+			$template_args,
1388
+			true
1389
+		);
1390
+	}
1391 1391
 
1392 1392
 
1393
-    /**
1394
-     * This generates the ticket row for tickets.
1395
-     * This same method is used to generate both the actual rows and the js skeleton row
1396
-     * (when default === true)
1397
-     *
1398
-     * @param int           $ticket_row       Represents the row number being generated.
1399
-     * @param               $ticket
1400
-     * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1401
-     *                                        or empty for default
1402
-     * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1403
-     * @param bool          $default          Whether default row being generated or not.
1404
-     * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1405
-     *                                        (or empty in the case of defaults)
1406
-     * @return mixed
1407
-     * @throws InvalidArgumentException
1408
-     * @throws InvalidInterfaceException
1409
-     * @throws InvalidDataTypeException
1410
-     * @throws DomainException
1411
-     * @throws EE_Error
1412
-     * @throws ReflectionException
1413
-     */
1414
-    protected function _get_ticket_row(
1415
-        $ticket_row,
1416
-        $ticket,
1417
-        $ticket_datetimes,
1418
-        $all_datetimes,
1419
-        $default = false,
1420
-        $all_tickets = array()
1421
-    ) {
1422
-        // if $ticket is not an instance of EE_Ticket then force default to true.
1423
-        $default = ! $ticket instanceof EE_Ticket ? true : $default;
1424
-        $prices = ! empty($ticket) && ! $default
1425
-            ? $ticket->get_many_related(
1426
-                'Price',
1427
-                array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1428
-            )
1429
-            : array();
1430
-        // if there is only one price (which would be the base price)
1431
-        // or NO prices and this ticket is a default ticket,
1432
-        // let's just make sure there are no cached default prices on the object.
1433
-        // This is done by not including any query_params.
1434
-        if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1435
-            $prices = $ticket->prices();
1436
-        }
1437
-        // check if we're dealing with a default ticket in which case
1438
-        // we don't want any starting_ticket_datetime_row values set
1439
-        // (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1440
-        // This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1441
-        $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1442
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1443
-            ? $ticket_datetimes[ $ticket->ID() ]
1444
-            : array();
1445
-        $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1446
-        $base_price = $default ? null : $ticket->base_price();
1447
-        $count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1448
-        // breaking out complicated condition for ticket_status
1449
-        if ($default) {
1450
-            $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1451
-        } else {
1452
-            $ticket_status_class = $ticket->is_default()
1453
-                ? ' tkt-status-' . EE_Ticket::onsale
1454
-                : ' tkt-status-' . $ticket->ticket_status();
1455
-        }
1456
-        // breaking out complicated condition for TKT_taxable
1457
-        if ($default) {
1458
-            $TKT_taxable = '';
1459
-        } else {
1460
-            $TKT_taxable = $ticket->taxable()
1461
-                ? ' checked="checked"'
1462
-                : '';
1463
-        }
1464
-        if ($default) {
1465
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1466
-        } elseif ($ticket->is_default()) {
1467
-            $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
-        } else {
1469
-            $TKT_status = $ticket->ticket_status(true);
1470
-        }
1471
-        if ($default) {
1472
-            $TKT_min = '';
1473
-        } else {
1474
-            $TKT_min = $ticket->min();
1475
-            if ($TKT_min === -1 || $TKT_min === 0) {
1476
-                $TKT_min = '';
1477
-            }
1478
-        }
1479
-        $template_args = array(
1480
-            'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1481
-            'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1482
-            // on initial page load this will always be the correct order.
1483
-            'tkt_status_class'              => $ticket_status_class,
1484
-            'display_edit_tkt_row'          => ' style="display:none;"',
1485
-            'edit_tkt_expanded'             => '',
1486
-            'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1487
-            'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1488
-            'TKT_start_date'                => $default
1489
-                ? ''
1490
-                : $ticket->get_date('TKT_start_date', $this->_date_time_format),
1491
-            'TKT_end_date'                  => $default
1492
-                ? ''
1493
-                : $ticket->get_date('TKT_end_date', $this->_date_time_format),
1494
-            'TKT_status'                    => $TKT_status,
1495
-            'TKT_price'                     => $default
1496
-                ? ''
1497
-                : EEH_Template::format_currency(
1498
-                    $ticket->get_ticket_total_with_taxes(),
1499
-                    false,
1500
-                    false
1501
-                ),
1502
-            'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1503
-            'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1504
-            'TKT_qty'                       => $default
1505
-                ? ''
1506
-                : $ticket->get_pretty('TKT_qty', 'symbol'),
1507
-            'TKT_qty_for_input'             => $default
1508
-                ? ''
1509
-                : $ticket->get_pretty('TKT_qty', 'input'),
1510
-            'TKT_uses'                      => $default
1511
-                ? ''
1512
-                : $ticket->get_pretty('TKT_uses', 'input'),
1513
-            'TKT_min'                       => $TKT_min,
1514
-            'TKT_max'                       => $default
1515
-                ? ''
1516
-                : $ticket->get_pretty('TKT_max', 'input'),
1517
-            'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1518
-            'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1519
-            'TKT_registrations'             => $default
1520
-                ? 0
1521
-                : $ticket->count_registrations(
1522
-                    array(
1523
-                        array(
1524
-                            'STS_ID' => array(
1525
-                                '!=',
1526
-                                EEM_Registration::status_id_incomplete,
1527
-                            ),
1528
-                        ),
1529
-                    )
1530
-                ),
1531
-            'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1532
-            'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1533
-            'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1534
-            'TKT_required'                  => $default ? 0 : $ticket->required(),
1535
-            'TKT_is_default_selector'       => '',
1536
-            'ticket_price_rows'             => '',
1537
-            'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1538
-                ? ''
1539
-                : $base_price->get_pretty('PRC_amount', 'localized_float'),
1540
-            'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1541
-            'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1542
-                ? ''
1543
-                : ' style="display:none;"',
1544
-            'show_price_mod_button'         => count($prices) > 1
1545
-                                               || ($default && $count_price_mods > 0)
1546
-                                               || (! $default && $ticket->deleted())
1547
-                ? ' style="display:none;"'
1548
-                : '',
1549
-            'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1550
-            'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1551
-            'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1552
-            'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1553
-            'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1554
-            'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1555
-            'TKT_taxable'                   => $TKT_taxable,
1556
-            'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1557
-                ? ''
1558
-                : ' style="display:none"',
1559
-            'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1560
-            'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1561
-                $ticket_subtotal,
1562
-                false,
1563
-                false
1564
-            ),
1565
-            'TKT_subtotal_amount'           => $ticket_subtotal,
1566
-            'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1567
-            'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1568
-            'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1569
-                ? ' ticket-archived'
1570
-                : '',
1571
-            'trash_icon'                    => $ticket instanceof EE_Ticket
1572
-                                               && $ticket->deleted()
1573
-                                               && ! $ticket->is_permanently_deleteable()
1574
-                ? 'ee-lock-icon '
1575
-                : 'trash-icon dashicons dashicons-post-trash clickable',
1576
-            'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1577
-                ? ''
1578
-                : 'clone-icon ee-icon ee-icon-clone clickable',
1579
-        );
1580
-        $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1581
-            ? ' style="display:none"'
1582
-            : '';
1583
-        // handle rows that should NOT be empty
1584
-        if (empty($template_args['TKT_start_date'])) {
1585
-            // if empty then the start date will be now.
1586
-            $template_args['TKT_start_date'] = date(
1587
-                $this->_date_time_format,
1588
-                current_time('timestamp')
1589
-            );
1590
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1591
-        }
1592
-        if (empty($template_args['TKT_end_date'])) {
1593
-            // get the earliest datetime (if present);
1594
-            $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1595
-                ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1596
-                    'Datetime',
1597
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1598
-                )
1599
-                : null;
1600
-            if (! empty($earliest_dtt)) {
1601
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1602
-                    'DTT_EVT_start',
1603
-                    $this->_date_time_format
1604
-                );
1605
-            } else {
1606
-                // default so let's just use what's been set for the default date-time which is 30 days from now.
1607
-                $template_args['TKT_end_date'] = date(
1608
-                    $this->_date_time_format,
1609
-                    mktime(
1610
-                        24,
1611
-                        0,
1612
-                        0,
1613
-                        date('m'),
1614
-                        date('d') + 29,
1615
-                        date('Y')
1616
-                    )
1617
-                );
1618
-            }
1619
-            $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1620
-        }
1621
-        // generate ticket_datetime items
1622
-        if (! $default) {
1623
-            $datetime_row = 1;
1624
-            foreach ($all_datetimes as $datetime) {
1625
-                $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1626
-                    $datetime_row,
1627
-                    $ticket_row,
1628
-                    $datetime,
1629
-                    $ticket,
1630
-                    $ticket_datetimes,
1631
-                    $default
1632
-                );
1633
-                $datetime_row++;
1634
-            }
1635
-        }
1636
-        $price_row = 1;
1637
-        foreach ($prices as $price) {
1638
-            if (! $price instanceof EE_Price) {
1639
-                continue;
1640
-            }
1641
-            if ($price->is_base_price()) {
1642
-                $price_row++;
1643
-                continue;
1644
-            }
1645
-            $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1646
-            $show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1647
-            $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1648
-                $ticket_row,
1649
-                $price_row,
1650
-                $price,
1651
-                $default,
1652
-                $ticket,
1653
-                $show_trash,
1654
-                $show_create
1655
-            );
1656
-            $price_row++;
1657
-        }
1658
-        // filter $template_args
1659
-        $template_args = apply_filters(
1660
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1661
-            $template_args,
1662
-            $ticket_row,
1663
-            $ticket,
1664
-            $ticket_datetimes,
1665
-            $all_datetimes,
1666
-            $default,
1667
-            $all_tickets,
1668
-            $this->_is_creating_event
1669
-        );
1670
-        return EEH_Template::display_template(
1671
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1672
-            $template_args,
1673
-            true
1674
-        );
1675
-    }
1393
+	/**
1394
+	 * This generates the ticket row for tickets.
1395
+	 * This same method is used to generate both the actual rows and the js skeleton row
1396
+	 * (when default === true)
1397
+	 *
1398
+	 * @param int           $ticket_row       Represents the row number being generated.
1399
+	 * @param               $ticket
1400
+	 * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket
1401
+	 *                                        or empty for default
1402
+	 * @param EE_Datetime[] $all_datetimes    All Datetimes on the event or empty for default.
1403
+	 * @param bool          $default          Whether default row being generated or not.
1404
+	 * @param EE_Ticket[]   $all_tickets      This is an array of all tickets attached to the event
1405
+	 *                                        (or empty in the case of defaults)
1406
+	 * @return mixed
1407
+	 * @throws InvalidArgumentException
1408
+	 * @throws InvalidInterfaceException
1409
+	 * @throws InvalidDataTypeException
1410
+	 * @throws DomainException
1411
+	 * @throws EE_Error
1412
+	 * @throws ReflectionException
1413
+	 */
1414
+	protected function _get_ticket_row(
1415
+		$ticket_row,
1416
+		$ticket,
1417
+		$ticket_datetimes,
1418
+		$all_datetimes,
1419
+		$default = false,
1420
+		$all_tickets = array()
1421
+	) {
1422
+		// if $ticket is not an instance of EE_Ticket then force default to true.
1423
+		$default = ! $ticket instanceof EE_Ticket ? true : $default;
1424
+		$prices = ! empty($ticket) && ! $default
1425
+			? $ticket->get_many_related(
1426
+				'Price',
1427
+				array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))
1428
+			)
1429
+			: array();
1430
+		// if there is only one price (which would be the base price)
1431
+		// or NO prices and this ticket is a default ticket,
1432
+		// let's just make sure there are no cached default prices on the object.
1433
+		// This is done by not including any query_params.
1434
+		if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) {
1435
+			$prices = $ticket->prices();
1436
+		}
1437
+		// check if we're dealing with a default ticket in which case
1438
+		// we don't want any starting_ticket_datetime_row values set
1439
+		// (otherwise there won't be any new relationships created for tickets based off of the default ticket).
1440
+		// This will future proof in case there is ever any behaviour change between what the primary_key defaults to.
1441
+		$default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default());
1442
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
1443
+			? $ticket_datetimes[ $ticket->ID() ]
1444
+			: array();
1445
+		$ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal();
1446
+		$base_price = $default ? null : $ticket->base_price();
1447
+		$count_price_mods = EEM_Price::instance()->get_all_default_prices(true);
1448
+		// breaking out complicated condition for ticket_status
1449
+		if ($default) {
1450
+			$ticket_status_class = ' tkt-status-' . EE_Ticket::onsale;
1451
+		} else {
1452
+			$ticket_status_class = $ticket->is_default()
1453
+				? ' tkt-status-' . EE_Ticket::onsale
1454
+				: ' tkt-status-' . $ticket->ticket_status();
1455
+		}
1456
+		// breaking out complicated condition for TKT_taxable
1457
+		if ($default) {
1458
+			$TKT_taxable = '';
1459
+		} else {
1460
+			$TKT_taxable = $ticket->taxable()
1461
+				? ' checked="checked"'
1462
+				: '';
1463
+		}
1464
+		if ($default) {
1465
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1466
+		} elseif ($ticket->is_default()) {
1467
+			$TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence');
1468
+		} else {
1469
+			$TKT_status = $ticket->ticket_status(true);
1470
+		}
1471
+		if ($default) {
1472
+			$TKT_min = '';
1473
+		} else {
1474
+			$TKT_min = $ticket->min();
1475
+			if ($TKT_min === -1 || $TKT_min === 0) {
1476
+				$TKT_min = '';
1477
+			}
1478
+		}
1479
+		$template_args = array(
1480
+			'tkt_row'                       => $default ? 'TICKETNUM' : $ticket_row,
1481
+			'TKT_order'                     => $default ? 'TICKETNUM' : $ticket_row,
1482
+			// on initial page load this will always be the correct order.
1483
+			'tkt_status_class'              => $ticket_status_class,
1484
+			'display_edit_tkt_row'          => ' style="display:none;"',
1485
+			'edit_tkt_expanded'             => '',
1486
+			'edit_tickets_name'             => $default ? 'TICKETNAMEATTR' : 'edit_tickets',
1487
+			'TKT_name'                      => $default ? '' : $ticket->get_f('TKT_name'),
1488
+			'TKT_start_date'                => $default
1489
+				? ''
1490
+				: $ticket->get_date('TKT_start_date', $this->_date_time_format),
1491
+			'TKT_end_date'                  => $default
1492
+				? ''
1493
+				: $ticket->get_date('TKT_end_date', $this->_date_time_format),
1494
+			'TKT_status'                    => $TKT_status,
1495
+			'TKT_price'                     => $default
1496
+				? ''
1497
+				: EEH_Template::format_currency(
1498
+					$ticket->get_ticket_total_with_taxes(),
1499
+					false,
1500
+					false
1501
+				),
1502
+			'TKT_price_code'                => EE_Registry::instance()->CFG->currency->code,
1503
+			'TKT_price_amount'              => $default ? 0 : $ticket_subtotal,
1504
+			'TKT_qty'                       => $default
1505
+				? ''
1506
+				: $ticket->get_pretty('TKT_qty', 'symbol'),
1507
+			'TKT_qty_for_input'             => $default
1508
+				? ''
1509
+				: $ticket->get_pretty('TKT_qty', 'input'),
1510
+			'TKT_uses'                      => $default
1511
+				? ''
1512
+				: $ticket->get_pretty('TKT_uses', 'input'),
1513
+			'TKT_min'                       => $TKT_min,
1514
+			'TKT_max'                       => $default
1515
+				? ''
1516
+				: $ticket->get_pretty('TKT_max', 'input'),
1517
+			'TKT_sold'                      => $default ? 0 : $ticket->tickets_sold('ticket'),
1518
+			'TKT_reserved'                  => $default ? 0 : $ticket->reserved(),
1519
+			'TKT_registrations'             => $default
1520
+				? 0
1521
+				: $ticket->count_registrations(
1522
+					array(
1523
+						array(
1524
+							'STS_ID' => array(
1525
+								'!=',
1526
+								EEM_Registration::status_id_incomplete,
1527
+							),
1528
+						),
1529
+					)
1530
+				),
1531
+			'TKT_ID'                        => $default ? 0 : $ticket->ID(),
1532
+			'TKT_description'               => $default ? '' : $ticket->get_f('TKT_description'),
1533
+			'TKT_is_default'                => $default ? 0 : $ticket->is_default(),
1534
+			'TKT_required'                  => $default ? 0 : $ticket->required(),
1535
+			'TKT_is_default_selector'       => '',
1536
+			'ticket_price_rows'             => '',
1537
+			'TKT_base_price'                => $default || ! $base_price instanceof EE_Price
1538
+				? ''
1539
+				: $base_price->get_pretty('PRC_amount', 'localized_float'),
1540
+			'TKT_base_price_ID'             => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(),
1541
+			'show_price_modifier'           => count($prices) > 1 || ($default && $count_price_mods > 0)
1542
+				? ''
1543
+				: ' style="display:none;"',
1544
+			'show_price_mod_button'         => count($prices) > 1
1545
+											   || ($default && $count_price_mods > 0)
1546
+											   || (! $default && $ticket->deleted())
1547
+				? ' style="display:none;"'
1548
+				: '',
1549
+			'total_price_rows'              => count($prices) > 1 ? count($prices) : 1,
1550
+			'ticket_datetimes_list'         => $default ? '<li class="hidden"></li>' : '',
1551
+			'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes),
1552
+			'ticket_datetime_rows'          => $default ? '' : implode(',', $tkt_datetimes),
1553
+			'existing_ticket_price_ids'     => $default ? '' : implode(',', array_keys($prices)),
1554
+			'ticket_template_id'            => $default ? 0 : $ticket->get('TTM_ID'),
1555
+			'TKT_taxable'                   => $TKT_taxable,
1556
+			'display_subtotal'              => $ticket instanceof EE_Ticket && $ticket->taxable()
1557
+				? ''
1558
+				: ' style="display:none"',
1559
+			'price_currency_symbol'         => EE_Registry::instance()->CFG->currency->sign,
1560
+			'TKT_subtotal_amount_display'   => EEH_Template::format_currency(
1561
+				$ticket_subtotal,
1562
+				false,
1563
+				false
1564
+			),
1565
+			'TKT_subtotal_amount'           => $ticket_subtotal,
1566
+			'tax_rows'                      => $this->_get_tax_rows($ticket_row, $ticket),
1567
+			'disabled'                      => $ticket instanceof EE_Ticket && $ticket->deleted(),
1568
+			'ticket_archive_class'          => $ticket instanceof EE_Ticket && $ticket->deleted()
1569
+				? ' ticket-archived'
1570
+				: '',
1571
+			'trash_icon'                    => $ticket instanceof EE_Ticket
1572
+											   && $ticket->deleted()
1573
+											   && ! $ticket->is_permanently_deleteable()
1574
+				? 'ee-lock-icon '
1575
+				: 'trash-icon dashicons dashicons-post-trash clickable',
1576
+			'clone_icon'                    => $ticket instanceof EE_Ticket && $ticket->deleted()
1577
+				? ''
1578
+				: 'clone-icon ee-icon ee-icon-clone clickable',
1579
+		);
1580
+		$template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon'
1581
+			? ' style="display:none"'
1582
+			: '';
1583
+		// handle rows that should NOT be empty
1584
+		if (empty($template_args['TKT_start_date'])) {
1585
+			// if empty then the start date will be now.
1586
+			$template_args['TKT_start_date'] = date(
1587
+				$this->_date_time_format,
1588
+				current_time('timestamp')
1589
+			);
1590
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1591
+		}
1592
+		if (empty($template_args['TKT_end_date'])) {
1593
+			// get the earliest datetime (if present);
1594
+			$earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0
1595
+				? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related(
1596
+					'Datetime',
1597
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1598
+				)
1599
+				: null;
1600
+			if (! empty($earliest_dtt)) {
1601
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime(
1602
+					'DTT_EVT_start',
1603
+					$this->_date_time_format
1604
+				);
1605
+			} else {
1606
+				// default so let's just use what's been set for the default date-time which is 30 days from now.
1607
+				$template_args['TKT_end_date'] = date(
1608
+					$this->_date_time_format,
1609
+					mktime(
1610
+						24,
1611
+						0,
1612
+						0,
1613
+						date('m'),
1614
+						date('d') + 29,
1615
+						date('Y')
1616
+					)
1617
+				);
1618
+			}
1619
+			$template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale;
1620
+		}
1621
+		// generate ticket_datetime items
1622
+		if (! $default) {
1623
+			$datetime_row = 1;
1624
+			foreach ($all_datetimes as $datetime) {
1625
+				$template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
1626
+					$datetime_row,
1627
+					$ticket_row,
1628
+					$datetime,
1629
+					$ticket,
1630
+					$ticket_datetimes,
1631
+					$default
1632
+				);
1633
+				$datetime_row++;
1634
+			}
1635
+		}
1636
+		$price_row = 1;
1637
+		foreach ($prices as $price) {
1638
+			if (! $price instanceof EE_Price) {
1639
+				continue;
1640
+			}
1641
+			if ($price->is_base_price()) {
1642
+				$price_row++;
1643
+				continue;
1644
+			}
1645
+			$show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1);
1646
+			$show_create = ! (count($prices) > 1 && count($prices) !== $price_row);
1647
+			$template_args['ticket_price_rows'] .= $this->_get_ticket_price_row(
1648
+				$ticket_row,
1649
+				$price_row,
1650
+				$price,
1651
+				$default,
1652
+				$ticket,
1653
+				$show_trash,
1654
+				$show_create
1655
+			);
1656
+			$price_row++;
1657
+		}
1658
+		// filter $template_args
1659
+		$template_args = apply_filters(
1660
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args',
1661
+			$template_args,
1662
+			$ticket_row,
1663
+			$ticket,
1664
+			$ticket_datetimes,
1665
+			$all_datetimes,
1666
+			$default,
1667
+			$all_tickets,
1668
+			$this->_is_creating_event
1669
+		);
1670
+		return EEH_Template::display_template(
1671
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php',
1672
+			$template_args,
1673
+			true
1674
+		);
1675
+	}
1676 1676
 
1677 1677
 
1678
-    /**
1679
-     * @param int            $ticket_row
1680
-     * @param EE_Ticket|null $ticket
1681
-     * @return string
1682
-     * @throws DomainException
1683
-     * @throws EE_Error
1684
-     */
1685
-    protected function _get_tax_rows($ticket_row, $ticket)
1686
-    {
1687
-        $tax_rows = '';
1688
-        /** @var EE_Price[] $taxes */
1689
-        $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1690
-        foreach ($taxes as $tax) {
1691
-            $tax_added = $this->_get_tax_added($tax, $ticket);
1692
-            $template_args = array(
1693
-                'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1694
-                    ? ''
1695
-                    : ' style="display:none;"',
1696
-                'tax_id'            => $tax->ID(),
1697
-                'tkt_row'           => $ticket_row,
1698
-                'tax_label'         => $tax->get('PRC_name'),
1699
-                'tax_added'         => $tax_added,
1700
-                'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1701
-                'tax_amount'        => $tax->get('PRC_amount'),
1702
-            );
1703
-            $template_args = apply_filters(
1704
-                'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1705
-                $template_args,
1706
-                $ticket_row,
1707
-                $ticket,
1708
-                $this->_is_creating_event
1709
-            );
1710
-            $tax_rows .= EEH_Template::display_template(
1711
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1712
-                $template_args,
1713
-                true
1714
-            );
1715
-        }
1716
-        return $tax_rows;
1717
-    }
1678
+	/**
1679
+	 * @param int            $ticket_row
1680
+	 * @param EE_Ticket|null $ticket
1681
+	 * @return string
1682
+	 * @throws DomainException
1683
+	 * @throws EE_Error
1684
+	 */
1685
+	protected function _get_tax_rows($ticket_row, $ticket)
1686
+	{
1687
+		$tax_rows = '';
1688
+		/** @var EE_Price[] $taxes */
1689
+		$taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin();
1690
+		foreach ($taxes as $tax) {
1691
+			$tax_added = $this->_get_tax_added($tax, $ticket);
1692
+			$template_args = array(
1693
+				'display_tax'       => ! empty($ticket) && $ticket->get('TKT_taxable')
1694
+					? ''
1695
+					: ' style="display:none;"',
1696
+				'tax_id'            => $tax->ID(),
1697
+				'tkt_row'           => $ticket_row,
1698
+				'tax_label'         => $tax->get('PRC_name'),
1699
+				'tax_added'         => $tax_added,
1700
+				'tax_added_display' => EEH_Template::format_currency($tax_added, false, false),
1701
+				'tax_amount'        => $tax->get('PRC_amount'),
1702
+			);
1703
+			$template_args = apply_filters(
1704
+				'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args',
1705
+				$template_args,
1706
+				$ticket_row,
1707
+				$ticket,
1708
+				$this->_is_creating_event
1709
+			);
1710
+			$tax_rows .= EEH_Template::display_template(
1711
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php',
1712
+				$template_args,
1713
+				true
1714
+			);
1715
+		}
1716
+		return $tax_rows;
1717
+	}
1718 1718
 
1719 1719
 
1720
-    /**
1721
-     * @param EE_Price       $tax
1722
-     * @param EE_Ticket|null $ticket
1723
-     * @return float|int
1724
-     * @throws EE_Error
1725
-     */
1726
-    protected function _get_tax_added(EE_Price $tax, $ticket)
1727
-    {
1728
-        $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1729
-        return $subtotal * $tax->get('PRC_amount') / 100;
1730
-    }
1720
+	/**
1721
+	 * @param EE_Price       $tax
1722
+	 * @param EE_Ticket|null $ticket
1723
+	 * @return float|int
1724
+	 * @throws EE_Error
1725
+	 */
1726
+	protected function _get_tax_added(EE_Price $tax, $ticket)
1727
+	{
1728
+		$subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal();
1729
+		return $subtotal * $tax->get('PRC_amount') / 100;
1730
+	}
1731 1731
 
1732 1732
 
1733
-    /**
1734
-     * @param int            $ticket_row
1735
-     * @param int            $price_row
1736
-     * @param EE_Price|null  $price
1737
-     * @param bool           $default
1738
-     * @param EE_Ticket|null $ticket
1739
-     * @param bool           $show_trash
1740
-     * @param bool           $show_create
1741
-     * @return mixed
1742
-     * @throws InvalidArgumentException
1743
-     * @throws InvalidInterfaceException
1744
-     * @throws InvalidDataTypeException
1745
-     * @throws DomainException
1746
-     * @throws EE_Error
1747
-     * @throws ReflectionException
1748
-     */
1749
-    protected function _get_ticket_price_row(
1750
-        $ticket_row,
1751
-        $price_row,
1752
-        $price,
1753
-        $default,
1754
-        $ticket,
1755
-        $show_trash = true,
1756
-        $show_create = true
1757
-    ) {
1758
-        $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1759
-        $template_args = array(
1760
-            'tkt_row'               => $default && empty($ticket)
1761
-                ? 'TICKETNUM'
1762
-                : $ticket_row,
1763
-            'PRC_order'             => $default && empty($price)
1764
-                ? 'PRICENUM'
1765
-                : $price_row,
1766
-            'edit_prices_name'      => $default && empty($price)
1767
-                ? 'PRICENAMEATTR'
1768
-                : 'edit_prices',
1769
-            'price_type_selector'   => $default && empty($price)
1770
-                ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1771
-                : $this->_get_price_type_selector(
1772
-                    $ticket_row,
1773
-                    $price_row,
1774
-                    $price,
1775
-                    $default,
1776
-                    $send_disabled
1777
-                ),
1778
-            'PRC_ID'                => $default && empty($price)
1779
-                ? 0
1780
-                : $price->ID(),
1781
-            'PRC_is_default'        => $default && empty($price)
1782
-                ? 0
1783
-                : $price->get('PRC_is_default'),
1784
-            'PRC_name'              => $default && empty($price)
1785
-                ? ''
1786
-                : $price->get('PRC_name'),
1787
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1788
-            'show_plus_or_minus'    => $default && empty($price)
1789
-                ? ''
1790
-                : ' style="display:none;"',
1791
-            'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1792
-                ? ' style="display:none;"'
1793
-                : '',
1794
-            'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1795
-                ? ' style="display:none;"'
1796
-                : '',
1797
-            'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1798
-                ? ' style="display:none"'
1799
-                : '',
1800
-            'PRC_amount'            => $default && empty($price)
1801
-                ? 0
1802
-                : $price->get_pretty('PRC_amount', 'localized_float'),
1803
-            'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1804
-                ? ' style="display:none;"'
1805
-                : '',
1806
-            'show_trash_icon'       => $show_trash
1807
-                ? ''
1808
-                : ' style="display:none;"',
1809
-            'show_create_button'    => $show_create
1810
-                ? ''
1811
-                : ' style="display:none;"',
1812
-            'PRC_desc'              => $default && empty($price)
1813
-                ? ''
1814
-                : $price->get('PRC_desc'),
1815
-            'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1816
-        );
1817
-        $template_args = apply_filters(
1818
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1819
-            $template_args,
1820
-            $ticket_row,
1821
-            $price_row,
1822
-            $price,
1823
-            $default,
1824
-            $ticket,
1825
-            $show_trash,
1826
-            $show_create,
1827
-            $this->_is_creating_event
1828
-        );
1829
-        return EEH_Template::display_template(
1830
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1831
-            $template_args,
1832
-            true
1833
-        );
1834
-    }
1733
+	/**
1734
+	 * @param int            $ticket_row
1735
+	 * @param int            $price_row
1736
+	 * @param EE_Price|null  $price
1737
+	 * @param bool           $default
1738
+	 * @param EE_Ticket|null $ticket
1739
+	 * @param bool           $show_trash
1740
+	 * @param bool           $show_create
1741
+	 * @return mixed
1742
+	 * @throws InvalidArgumentException
1743
+	 * @throws InvalidInterfaceException
1744
+	 * @throws InvalidDataTypeException
1745
+	 * @throws DomainException
1746
+	 * @throws EE_Error
1747
+	 * @throws ReflectionException
1748
+	 */
1749
+	protected function _get_ticket_price_row(
1750
+		$ticket_row,
1751
+		$price_row,
1752
+		$price,
1753
+		$default,
1754
+		$ticket,
1755
+		$show_trash = true,
1756
+		$show_create = true
1757
+	) {
1758
+		$send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted');
1759
+		$template_args = array(
1760
+			'tkt_row'               => $default && empty($ticket)
1761
+				? 'TICKETNUM'
1762
+				: $ticket_row,
1763
+			'PRC_order'             => $default && empty($price)
1764
+				? 'PRICENUM'
1765
+				: $price_row,
1766
+			'edit_prices_name'      => $default && empty($price)
1767
+				? 'PRICENAMEATTR'
1768
+				: 'edit_prices',
1769
+			'price_type_selector'   => $default && empty($price)
1770
+				? $this->_get_base_price_template($ticket_row, $price_row, $price, $default)
1771
+				: $this->_get_price_type_selector(
1772
+					$ticket_row,
1773
+					$price_row,
1774
+					$price,
1775
+					$default,
1776
+					$send_disabled
1777
+				),
1778
+			'PRC_ID'                => $default && empty($price)
1779
+				? 0
1780
+				: $price->ID(),
1781
+			'PRC_is_default'        => $default && empty($price)
1782
+				? 0
1783
+				: $price->get('PRC_is_default'),
1784
+			'PRC_name'              => $default && empty($price)
1785
+				? ''
1786
+				: $price->get('PRC_name'),
1787
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1788
+			'show_plus_or_minus'    => $default && empty($price)
1789
+				? ''
1790
+				: ' style="display:none;"',
1791
+			'show_plus'             => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price())
1792
+				? ' style="display:none;"'
1793
+				: '',
1794
+			'show_minus'            => ($default && empty($price)) || ! $price->is_discount()
1795
+				? ' style="display:none;"'
1796
+				: '',
1797
+			'show_currency_symbol'  => ($default && empty($price)) || $price->is_percent()
1798
+				? ' style="display:none"'
1799
+				: '',
1800
+			'PRC_amount'            => $default && empty($price)
1801
+				? 0
1802
+				: $price->get_pretty('PRC_amount', 'localized_float'),
1803
+			'show_percentage'       => ($default && empty($price)) || ! $price->is_percent()
1804
+				? ' style="display:none;"'
1805
+				: '',
1806
+			'show_trash_icon'       => $show_trash
1807
+				? ''
1808
+				: ' style="display:none;"',
1809
+			'show_create_button'    => $show_create
1810
+				? ''
1811
+				: ' style="display:none;"',
1812
+			'PRC_desc'              => $default && empty($price)
1813
+				? ''
1814
+				: $price->get('PRC_desc'),
1815
+			'disabled'              => ! empty($ticket) && $ticket->get('TKT_deleted'),
1816
+		);
1817
+		$template_args = apply_filters(
1818
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args',
1819
+			$template_args,
1820
+			$ticket_row,
1821
+			$price_row,
1822
+			$price,
1823
+			$default,
1824
+			$ticket,
1825
+			$show_trash,
1826
+			$show_create,
1827
+			$this->_is_creating_event
1828
+		);
1829
+		return EEH_Template::display_template(
1830
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php',
1831
+			$template_args,
1832
+			true
1833
+		);
1834
+	}
1835 1835
 
1836 1836
 
1837
-    /**
1838
-     * @param int      $ticket_row
1839
-     * @param int      $price_row
1840
-     * @param EE_Price $price
1841
-     * @param bool     $default
1842
-     * @param bool     $disabled
1843
-     * @return mixed
1844
-     * @throws ReflectionException
1845
-     * @throws InvalidArgumentException
1846
-     * @throws InvalidInterfaceException
1847
-     * @throws InvalidDataTypeException
1848
-     * @throws DomainException
1849
-     * @throws EE_Error
1850
-     */
1851
-    protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1852
-    {
1853
-        if ($price->is_base_price()) {
1854
-            return $this->_get_base_price_template(
1855
-                $ticket_row,
1856
-                $price_row,
1857
-                $price,
1858
-                $default
1859
-            );
1860
-        }
1861
-        return $this->_get_price_modifier_template(
1862
-            $ticket_row,
1863
-            $price_row,
1864
-            $price,
1865
-            $default,
1866
-            $disabled
1867
-        );
1868
-    }
1837
+	/**
1838
+	 * @param int      $ticket_row
1839
+	 * @param int      $price_row
1840
+	 * @param EE_Price $price
1841
+	 * @param bool     $default
1842
+	 * @param bool     $disabled
1843
+	 * @return mixed
1844
+	 * @throws ReflectionException
1845
+	 * @throws InvalidArgumentException
1846
+	 * @throws InvalidInterfaceException
1847
+	 * @throws InvalidDataTypeException
1848
+	 * @throws DomainException
1849
+	 * @throws EE_Error
1850
+	 */
1851
+	protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false)
1852
+	{
1853
+		if ($price->is_base_price()) {
1854
+			return $this->_get_base_price_template(
1855
+				$ticket_row,
1856
+				$price_row,
1857
+				$price,
1858
+				$default
1859
+			);
1860
+		}
1861
+		return $this->_get_price_modifier_template(
1862
+			$ticket_row,
1863
+			$price_row,
1864
+			$price,
1865
+			$default,
1866
+			$disabled
1867
+		);
1868
+	}
1869 1869
 
1870 1870
 
1871
-    /**
1872
-     * @param int      $ticket_row
1873
-     * @param int      $price_row
1874
-     * @param EE_Price $price
1875
-     * @param bool     $default
1876
-     * @return mixed
1877
-     * @throws DomainException
1878
-     * @throws EE_Error
1879
-     */
1880
-    protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1881
-    {
1882
-        $template_args = array(
1883
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1884
-            'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1885
-            'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1886
-            'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1887
-            'price_selected_operator'   => '+',
1888
-            'price_selected_is_percent' => 0,
1889
-        );
1890
-        $template_args = apply_filters(
1891
-            'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1892
-            $template_args,
1893
-            $ticket_row,
1894
-            $price_row,
1895
-            $price,
1896
-            $default,
1897
-            $this->_is_creating_event
1898
-        );
1899
-        return EEH_Template::display_template(
1900
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1901
-            $template_args,
1902
-            true
1903
-        );
1904
-    }
1871
+	/**
1872
+	 * @param int      $ticket_row
1873
+	 * @param int      $price_row
1874
+	 * @param EE_Price $price
1875
+	 * @param bool     $default
1876
+	 * @return mixed
1877
+	 * @throws DomainException
1878
+	 * @throws EE_Error
1879
+	 */
1880
+	protected function _get_base_price_template($ticket_row, $price_row, $price, $default)
1881
+	{
1882
+		$template_args = array(
1883
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1884
+			'PRC_order'                 => $default && empty($price) ? 'PRICENUM' : $price_row,
1885
+			'PRT_ID'                    => $default && empty($price) ? 1 : $price->get('PRT_ID'),
1886
+			'PRT_name'                  => esc_html__('Price', 'event_espresso'),
1887
+			'price_selected_operator'   => '+',
1888
+			'price_selected_is_percent' => 0,
1889
+		);
1890
+		$template_args = apply_filters(
1891
+			'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args',
1892
+			$template_args,
1893
+			$ticket_row,
1894
+			$price_row,
1895
+			$price,
1896
+			$default,
1897
+			$this->_is_creating_event
1898
+		);
1899
+		return EEH_Template::display_template(
1900
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php',
1901
+			$template_args,
1902
+			true
1903
+		);
1904
+	}
1905 1905
 
1906 1906
 
1907
-    /**
1908
-     * @param int      $ticket_row
1909
-     * @param int      $price_row
1910
-     * @param EE_Price $price
1911
-     * @param bool     $default
1912
-     * @param bool     $disabled
1913
-     * @return mixed
1914
-     * @throws ReflectionException
1915
-     * @throws InvalidArgumentException
1916
-     * @throws InvalidInterfaceException
1917
-     * @throws InvalidDataTypeException
1918
-     * @throws DomainException
1919
-     * @throws EE_Error
1920
-     */
1921
-    protected function _get_price_modifier_template(
1922
-        $ticket_row,
1923
-        $price_row,
1924
-        $price,
1925
-        $default,
1926
-        $disabled = false
1927
-    ) {
1928
-        $select_name = $default && ! $price instanceof EE_Price
1929
-            ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1930
-            : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1931
-        /** @var EEM_Price_Type $price_type_model */
1932
-        $price_type_model = EE_Registry::instance()->load_model('Price_Type');
1933
-        $price_types = $price_type_model->get_all(array(
1934
-            array(
1935
-                'OR' => array(
1936
-                    'PBT_ID'  => '2',
1937
-                    'PBT_ID*' => '3',
1938
-                ),
1939
-            ),
1940
-        ));
1941
-        $all_price_types = $default && ! $price instanceof EE_Price
1942
-            ? array(esc_html__('Select Modifier', 'event_espresso'))
1943
-            : array();
1944
-        $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1945
-        $price_option_spans = '';
1946
-        // setup price types for selector
1947
-        foreach ($price_types as $price_type) {
1948
-            if (! $price_type instanceof EE_Price_Type) {
1949
-                continue;
1950
-            }
1951
-            $all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1952
-            // while we're in the loop let's setup the option spans used by js
1953
-            $span_args = array(
1954
-                'PRT_ID'         => $price_type->ID(),
1955
-                'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1956
-                'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1957
-            );
1958
-            $price_option_spans .= EEH_Template::display_template(
1959
-                PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1960
-                $span_args,
1961
-                true
1962
-            );
1963
-        }
1964
-        $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1965
-            : $select_name;
1966
-        $select_input = new EE_Select_Input(
1967
-            $all_price_types,
1968
-            array(
1969
-                'default'               => $selected_price_type_id,
1970
-                'html_name'             => $select_name,
1971
-                'html_class'            => 'edit-price-PRT_ID',
1972
-                'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1973
-            )
1974
-        );
1975
-        $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1976
-        $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1977
-        $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1978
-        $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1979
-        $template_args = array(
1980
-            'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1981
-            'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1982
-            'price_modifier_selector'   => $select_input->get_html_for_input(),
1983
-            'main_name'                 => $select_name,
1984
-            'selected_price_type_id'    => $selected_price_type_id,
1985
-            'price_option_spans'        => $price_option_spans,
1986
-            'price_selected_operator'   => $price_selected_operator,
1987
-            'price_selected_is_percent' => $price_selected_is_percent,
1988
-            'disabled'                  => $disabled,
1989
-        );
1990
-        $template_args = apply_filters(
1991
-            'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1992
-            $template_args,
1993
-            $ticket_row,
1994
-            $price_row,
1995
-            $price,
1996
-            $default,
1997
-            $disabled,
1998
-            $this->_is_creating_event
1999
-        );
2000
-        return EEH_Template::display_template(
2001
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2002
-            $template_args,
2003
-            true
2004
-        );
2005
-    }
1907
+	/**
1908
+	 * @param int      $ticket_row
1909
+	 * @param int      $price_row
1910
+	 * @param EE_Price $price
1911
+	 * @param bool     $default
1912
+	 * @param bool     $disabled
1913
+	 * @return mixed
1914
+	 * @throws ReflectionException
1915
+	 * @throws InvalidArgumentException
1916
+	 * @throws InvalidInterfaceException
1917
+	 * @throws InvalidDataTypeException
1918
+	 * @throws DomainException
1919
+	 * @throws EE_Error
1920
+	 */
1921
+	protected function _get_price_modifier_template(
1922
+		$ticket_row,
1923
+		$price_row,
1924
+		$price,
1925
+		$default,
1926
+		$disabled = false
1927
+	) {
1928
+		$select_name = $default && ! $price instanceof EE_Price
1929
+			? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]'
1930
+			: 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]';
1931
+		/** @var EEM_Price_Type $price_type_model */
1932
+		$price_type_model = EE_Registry::instance()->load_model('Price_Type');
1933
+		$price_types = $price_type_model->get_all(array(
1934
+			array(
1935
+				'OR' => array(
1936
+					'PBT_ID'  => '2',
1937
+					'PBT_ID*' => '3',
1938
+				),
1939
+			),
1940
+		));
1941
+		$all_price_types = $default && ! $price instanceof EE_Price
1942
+			? array(esc_html__('Select Modifier', 'event_espresso'))
1943
+			: array();
1944
+		$selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type();
1945
+		$price_option_spans = '';
1946
+		// setup price types for selector
1947
+		foreach ($price_types as $price_type) {
1948
+			if (! $price_type instanceof EE_Price_Type) {
1949
+				continue;
1950
+			}
1951
+			$all_price_types[ $price_type->ID() ] = $price_type->get('PRT_name');
1952
+			// while we're in the loop let's setup the option spans used by js
1953
+			$span_args = array(
1954
+				'PRT_ID'         => $price_type->ID(),
1955
+				'PRT_operator'   => $price_type->is_discount() ? '-' : '+',
1956
+				'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0,
1957
+			);
1958
+			$price_option_spans .= EEH_Template::display_template(
1959
+				PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php',
1960
+				$span_args,
1961
+				true
1962
+			);
1963
+		}
1964
+		$select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]'
1965
+			: $select_name;
1966
+		$select_input = new EE_Select_Input(
1967
+			$all_price_types,
1968
+			array(
1969
+				'default'               => $selected_price_type_id,
1970
+				'html_name'             => $select_name,
1971
+				'html_class'            => 'edit-price-PRT_ID',
1972
+				'other_html_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"',
1973
+			)
1974
+		);
1975
+		$price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+';
1976
+		$price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator;
1977
+		$price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0;
1978
+		$price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent;
1979
+		$template_args = array(
1980
+			'tkt_row'                   => $default ? 'TICKETNUM' : $ticket_row,
1981
+			'PRC_order'                 => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row,
1982
+			'price_modifier_selector'   => $select_input->get_html_for_input(),
1983
+			'main_name'                 => $select_name,
1984
+			'selected_price_type_id'    => $selected_price_type_id,
1985
+			'price_option_spans'        => $price_option_spans,
1986
+			'price_selected_operator'   => $price_selected_operator,
1987
+			'price_selected_is_percent' => $price_selected_is_percent,
1988
+			'disabled'                  => $disabled,
1989
+		);
1990
+		$template_args = apply_filters(
1991
+			'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args',
1992
+			$template_args,
1993
+			$ticket_row,
1994
+			$price_row,
1995
+			$price,
1996
+			$default,
1997
+			$disabled,
1998
+			$this->_is_creating_event
1999
+		);
2000
+		return EEH_Template::display_template(
2001
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php',
2002
+			$template_args,
2003
+			true
2004
+		);
2005
+	}
2006 2006
 
2007 2007
 
2008
-    /**
2009
-     * @param int              $datetime_row
2010
-     * @param int              $ticket_row
2011
-     * @param EE_Datetime|null $datetime
2012
-     * @param EE_Ticket|null   $ticket
2013
-     * @param array            $ticket_datetimes
2014
-     * @param bool             $default
2015
-     * @return mixed
2016
-     * @throws DomainException
2017
-     * @throws EE_Error
2018
-     */
2019
-    protected function _get_ticket_datetime_list_item(
2020
-        $datetime_row,
2021
-        $ticket_row,
2022
-        $datetime,
2023
-        $ticket,
2024
-        $ticket_datetimes = array(),
2025
-        $default
2026
-    ) {
2027
-        $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2028
-            ? $ticket_datetimes[ $ticket->ID() ]
2029
-            : array();
2030
-        $template_args = array(
2031
-            'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2032
-                ? 'DTTNUM'
2033
-                : $datetime_row,
2034
-            'tkt_row'                  => $default
2035
-                ? 'TICKETNUM'
2036
-                : $ticket_row,
2037
-            'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2038
-                ? ' ticket-selected'
2039
-                : '',
2040
-            'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2041
-                ? ' checked="checked"'
2042
-                : '',
2043
-            'DTT_name'                 => $default && empty($datetime)
2044
-                ? 'DTTNAME'
2045
-                : $datetime->get_dtt_display_name(true),
2046
-            'tkt_status_class'         => '',
2047
-        );
2048
-        $template_args = apply_filters(
2049
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2050
-            $template_args,
2051
-            $datetime_row,
2052
-            $ticket_row,
2053
-            $datetime,
2054
-            $ticket,
2055
-            $ticket_datetimes,
2056
-            $default,
2057
-            $this->_is_creating_event
2058
-        );
2059
-        return EEH_Template::display_template(
2060
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2061
-            $template_args,
2062
-            true
2063
-        );
2064
-    }
2008
+	/**
2009
+	 * @param int              $datetime_row
2010
+	 * @param int              $ticket_row
2011
+	 * @param EE_Datetime|null $datetime
2012
+	 * @param EE_Ticket|null   $ticket
2013
+	 * @param array            $ticket_datetimes
2014
+	 * @param bool             $default
2015
+	 * @return mixed
2016
+	 * @throws DomainException
2017
+	 * @throws EE_Error
2018
+	 */
2019
+	protected function _get_ticket_datetime_list_item(
2020
+		$datetime_row,
2021
+		$ticket_row,
2022
+		$datetime,
2023
+		$ticket,
2024
+		$ticket_datetimes = array(),
2025
+		$default
2026
+	) {
2027
+		$tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[ $ticket->ID() ])
2028
+			? $ticket_datetimes[ $ticket->ID() ]
2029
+			: array();
2030
+		$template_args = array(
2031
+			'dtt_row'                  => $default && ! $datetime instanceof EE_Datetime
2032
+				? 'DTTNUM'
2033
+				: $datetime_row,
2034
+			'tkt_row'                  => $default
2035
+				? 'TICKETNUM'
2036
+				: $ticket_row,
2037
+			'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true)
2038
+				? ' ticket-selected'
2039
+				: '',
2040
+			'ticket_datetime_checked'  => in_array($datetime_row, $tkt_datetimes, true)
2041
+				? ' checked="checked"'
2042
+				: '',
2043
+			'DTT_name'                 => $default && empty($datetime)
2044
+				? 'DTTNAME'
2045
+				: $datetime->get_dtt_display_name(true),
2046
+			'tkt_status_class'         => '',
2047
+		);
2048
+		$template_args = apply_filters(
2049
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args',
2050
+			$template_args,
2051
+			$datetime_row,
2052
+			$ticket_row,
2053
+			$datetime,
2054
+			$ticket,
2055
+			$ticket_datetimes,
2056
+			$default,
2057
+			$this->_is_creating_event
2058
+		);
2059
+		return EEH_Template::display_template(
2060
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php',
2061
+			$template_args,
2062
+			true
2063
+		);
2064
+	}
2065 2065
 
2066 2066
 
2067
-    /**
2068
-     * @param array $all_datetimes
2069
-     * @param array $all_tickets
2070
-     * @return mixed
2071
-     * @throws ReflectionException
2072
-     * @throws InvalidArgumentException
2073
-     * @throws InvalidInterfaceException
2074
-     * @throws InvalidDataTypeException
2075
-     * @throws DomainException
2076
-     * @throws EE_Error
2077
-     */
2078
-    protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2079
-    {
2080
-        $template_args = array(
2081
-            'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2082
-                'DTTNUM',
2083
-                null,
2084
-                true,
2085
-                $all_datetimes
2086
-            ),
2087
-            'default_ticket_row'                       => $this->_get_ticket_row(
2088
-                'TICKETNUM',
2089
-                null,
2090
-                array(),
2091
-                array(),
2092
-                true
2093
-            ),
2094
-            'default_price_row'                        => $this->_get_ticket_price_row(
2095
-                'TICKETNUM',
2096
-                'PRICENUM',
2097
-                null,
2098
-                true,
2099
-                null
2100
-            ),
2101
-            'default_price_rows'                       => '',
2102
-            'default_base_price_amount'                => 0,
2103
-            'default_base_price_name'                  => '',
2104
-            'default_base_price_description'           => '',
2105
-            'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2106
-                'TICKETNUM',
2107
-                'PRICENUM',
2108
-                null,
2109
-                true
2110
-            ),
2111
-            'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2112
-                'DTTNUM',
2113
-                null,
2114
-                array(),
2115
-                array(),
2116
-                true
2117
-            ),
2118
-            'existing_available_datetime_tickets_list' => '',
2119
-            'existing_available_ticket_datetimes_list' => '',
2120
-            'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2121
-                'DTTNUM',
2122
-                'TICKETNUM',
2123
-                null,
2124
-                null,
2125
-                array(),
2126
-                true
2127
-            ),
2128
-            'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2129
-                'DTTNUM',
2130
-                'TICKETNUM',
2131
-                null,
2132
-                null,
2133
-                array(),
2134
-                true
2135
-            ),
2136
-        );
2137
-        $ticket_row = 1;
2138
-        foreach ($all_tickets as $ticket) {
2139
-            $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2140
-                'DTTNUM',
2141
-                $ticket_row,
2142
-                null,
2143
-                $ticket,
2144
-                array(),
2145
-                true
2146
-            );
2147
-            $ticket_row++;
2148
-        }
2149
-        $datetime_row = 1;
2150
-        foreach ($all_datetimes as $datetime) {
2151
-            $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2152
-                $datetime_row,
2153
-                'TICKETNUM',
2154
-                $datetime,
2155
-                null,
2156
-                array(),
2157
-                true
2158
-            );
2159
-            $datetime_row++;
2160
-        }
2161
-        /** @var EEM_Price $price_model */
2162
-        $price_model = EE_Registry::instance()->load_model('Price');
2163
-        $default_prices = $price_model->get_all_default_prices();
2164
-        $price_row = 1;
2165
-        foreach ($default_prices as $price) {
2166
-            if (! $price instanceof EE_Price) {
2167
-                continue;
2168
-            }
2169
-            if ($price->is_base_price()) {
2170
-                $template_args['default_base_price_amount'] = $price->get_pretty(
2171
-                    'PRC_amount',
2172
-                    'localized_float'
2173
-                );
2174
-                $template_args['default_base_price_name'] = $price->get('PRC_name');
2175
-                $template_args['default_base_price_description'] = $price->get('PRC_desc');
2176
-                $price_row++;
2177
-                continue;
2178
-            }
2179
-            $show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2180
-                             || count($default_prices) === 1);
2181
-            $show_create = ! (count($default_prices) > 1
2182
-                              && count($default_prices)
2183
-                                 !== $price_row);
2184
-            $template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2185
-                'TICKETNUM',
2186
-                $price_row,
2187
-                $price,
2188
-                true,
2189
-                null,
2190
-                $show_trash,
2191
-                $show_create
2192
-            );
2193
-            $price_row++;
2194
-        }
2195
-        $template_args = apply_filters(
2196
-            'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2197
-            $template_args,
2198
-            $all_datetimes,
2199
-            $all_tickets,
2200
-            $this->_is_creating_event
2201
-        );
2202
-        return EEH_Template::display_template(
2203
-            PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2204
-            $template_args,
2205
-            true
2206
-        );
2207
-    }
2067
+	/**
2068
+	 * @param array $all_datetimes
2069
+	 * @param array $all_tickets
2070
+	 * @return mixed
2071
+	 * @throws ReflectionException
2072
+	 * @throws InvalidArgumentException
2073
+	 * @throws InvalidInterfaceException
2074
+	 * @throws InvalidDataTypeException
2075
+	 * @throws DomainException
2076
+	 * @throws EE_Error
2077
+	 */
2078
+	protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array())
2079
+	{
2080
+		$template_args = array(
2081
+			'default_datetime_edit_row'                => $this->_get_dtt_edit_row(
2082
+				'DTTNUM',
2083
+				null,
2084
+				true,
2085
+				$all_datetimes
2086
+			),
2087
+			'default_ticket_row'                       => $this->_get_ticket_row(
2088
+				'TICKETNUM',
2089
+				null,
2090
+				array(),
2091
+				array(),
2092
+				true
2093
+			),
2094
+			'default_price_row'                        => $this->_get_ticket_price_row(
2095
+				'TICKETNUM',
2096
+				'PRICENUM',
2097
+				null,
2098
+				true,
2099
+				null
2100
+			),
2101
+			'default_price_rows'                       => '',
2102
+			'default_base_price_amount'                => 0,
2103
+			'default_base_price_name'                  => '',
2104
+			'default_base_price_description'           => '',
2105
+			'default_price_modifier_selector_row'      => $this->_get_price_modifier_template(
2106
+				'TICKETNUM',
2107
+				'PRICENUM',
2108
+				null,
2109
+				true
2110
+			),
2111
+			'default_available_tickets_for_datetime'   => $this->_get_dtt_attached_tickets_row(
2112
+				'DTTNUM',
2113
+				null,
2114
+				array(),
2115
+				array(),
2116
+				true
2117
+			),
2118
+			'existing_available_datetime_tickets_list' => '',
2119
+			'existing_available_ticket_datetimes_list' => '',
2120
+			'new_available_datetime_ticket_list_item'  => $this->_get_datetime_tickets_list_item(
2121
+				'DTTNUM',
2122
+				'TICKETNUM',
2123
+				null,
2124
+				null,
2125
+				array(),
2126
+				true
2127
+			),
2128
+			'new_available_ticket_datetime_list_item'  => $this->_get_ticket_datetime_list_item(
2129
+				'DTTNUM',
2130
+				'TICKETNUM',
2131
+				null,
2132
+				null,
2133
+				array(),
2134
+				true
2135
+			),
2136
+		);
2137
+		$ticket_row = 1;
2138
+		foreach ($all_tickets as $ticket) {
2139
+			$template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item(
2140
+				'DTTNUM',
2141
+				$ticket_row,
2142
+				null,
2143
+				$ticket,
2144
+				array(),
2145
+				true
2146
+			);
2147
+			$ticket_row++;
2148
+		}
2149
+		$datetime_row = 1;
2150
+		foreach ($all_datetimes as $datetime) {
2151
+			$template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item(
2152
+				$datetime_row,
2153
+				'TICKETNUM',
2154
+				$datetime,
2155
+				null,
2156
+				array(),
2157
+				true
2158
+			);
2159
+			$datetime_row++;
2160
+		}
2161
+		/** @var EEM_Price $price_model */
2162
+		$price_model = EE_Registry::instance()->load_model('Price');
2163
+		$default_prices = $price_model->get_all_default_prices();
2164
+		$price_row = 1;
2165
+		foreach ($default_prices as $price) {
2166
+			if (! $price instanceof EE_Price) {
2167
+				continue;
2168
+			}
2169
+			if ($price->is_base_price()) {
2170
+				$template_args['default_base_price_amount'] = $price->get_pretty(
2171
+					'PRC_amount',
2172
+					'localized_float'
2173
+				);
2174
+				$template_args['default_base_price_name'] = $price->get('PRC_name');
2175
+				$template_args['default_base_price_description'] = $price->get('PRC_desc');
2176
+				$price_row++;
2177
+				continue;
2178
+			}
2179
+			$show_trash = ! ((count($default_prices) > 1 && $price_row === 1)
2180
+							 || count($default_prices) === 1);
2181
+			$show_create = ! (count($default_prices) > 1
2182
+							  && count($default_prices)
2183
+								 !== $price_row);
2184
+			$template_args['default_price_rows'] .= $this->_get_ticket_price_row(
2185
+				'TICKETNUM',
2186
+				$price_row,
2187
+				$price,
2188
+				true,
2189
+				null,
2190
+				$show_trash,
2191
+				$show_create
2192
+			);
2193
+			$price_row++;
2194
+		}
2195
+		$template_args = apply_filters(
2196
+			'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args',
2197
+			$template_args,
2198
+			$all_datetimes,
2199
+			$all_tickets,
2200
+			$this->_is_creating_event
2201
+		);
2202
+		return EEH_Template::display_template(
2203
+			PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php',
2204
+			$template_args,
2205
+			true
2206
+		);
2207
+	}
2208 2208
 }
Please login to merge, or discard this patch.
core/services/request/RequestInterface.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -16,155 +16,155 @@
 block discarded – undo
16 16
 interface RequestInterface extends RequestTypeContextCheckerInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @param RequestTypeContextCheckerInterface $type
21
-     */
22
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
23
-
24
-    /**
25
-     * @return array
26
-     */
27
-    public function getParams();
28
-
29
-
30
-    /**
31
-     * @return array
32
-     */
33
-    public function postParams();
34
-
35
-
36
-    /**
37
-     * @return array
38
-     */
39
-    public function cookieParams();
40
-
41
-
42
-    /**
43
-     * @return array
44
-     */
45
-    public function serverParams();
46
-
47
-
48
-    /**
49
-     * @return array
50
-     */
51
-    public function filesParams();
52
-
19
+	/**
20
+	 * @param RequestTypeContextCheckerInterface $type
21
+	 */
22
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type);
23
+
24
+	/**
25
+	 * @return array
26
+	 */
27
+	public function getParams();
28
+
29
+
30
+	/**
31
+	 * @return array
32
+	 */
33
+	public function postParams();
34
+
35
+
36
+	/**
37
+	 * @return array
38
+	 */
39
+	public function cookieParams();
40
+
41
+
42
+	/**
43
+	 * @return array
44
+	 */
45
+	public function serverParams();
46
+
47
+
48
+	/**
49
+	 * @return array
50
+	 */
51
+	public function filesParams();
52
+
53 53
 
54
-    /**
55
-     * returns contents of $_REQUEST
56
-     *
57
-     * @return array
58
-     */
59
-    public function requestParams();
54
+	/**
55
+	 * returns contents of $_REQUEST
56
+	 *
57
+	 * @return array
58
+	 */
59
+	public function requestParams();
60 60
 
61 61
 
62
-    /**
63
-     * @param string $key
64
-     * @param string $value
65
-     * @param bool   $override_ee
66
-     * @return    void
67
-     */
68
-    public function setRequestParam($key, $value, $override_ee = false);
62
+	/**
63
+	 * @param string $key
64
+	 * @param string $value
65
+	 * @param bool   $override_ee
66
+	 * @return    void
67
+	 */
68
+	public function setRequestParam($key, $value, $override_ee = false);
69 69
 
70 70
 
71
-    /**
72
-     * returns the value for a request param if the given key exists
73
-     *
74
-     * @param string $key
75
-     * @param null   $default
76
-     * @return mixed
77
-     */
78
-    public function getRequestParam($key, $default = null);
71
+	/**
72
+	 * returns the value for a request param if the given key exists
73
+	 *
74
+	 * @param string $key
75
+	 * @param null   $default
76
+	 * @return mixed
77
+	 */
78
+	public function getRequestParam($key, $default = null);
79 79
 
80 80
 
81
-    /**
82
-     * check if param exists
83
-     *
84
-     * @param string $key
85
-     * @return bool
86
-     */
87
-    public function requestParamIsSet($key);
81
+	/**
82
+	 * check if param exists
83
+	 *
84
+	 * @param string $key
85
+	 * @return bool
86
+	 */
87
+	public function requestParamIsSet($key);
88 88
 
89 89
 
90
-    /**
91
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
92
-     * and return the value for the first match found
93
-     * wildcards can be either of the following:
94
-     *      ? to represent a single character of any type
95
-     *      * to represent one or more characters of any type
96
-     *
97
-     * @param string     $pattern
98
-     * @param null|mixed $default
99
-     * @return false|int
100
-     */
101
-    public function getMatch($pattern, $default = null);
90
+	/**
91
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
92
+	 * and return the value for the first match found
93
+	 * wildcards can be either of the following:
94
+	 *      ? to represent a single character of any type
95
+	 *      * to represent one or more characters of any type
96
+	 *
97
+	 * @param string     $pattern
98
+	 * @param null|mixed $default
99
+	 * @return false|int
100
+	 */
101
+	public function getMatch($pattern, $default = null);
102 102
 
103 103
 
104
-    /**
105
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
106
-     * wildcards can be either of the following:
107
-     *      ? to represent a single character of any type
108
-     *      * to represent one or more characters of any type
109
-     * returns true if a match is found or false if not
110
-     *
111
-     * @param string $pattern
112
-     * @return false|int
113
-     */
114
-    public function matches($pattern);
104
+	/**
105
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
106
+	 * wildcards can be either of the following:
107
+	 *      ? to represent a single character of any type
108
+	 *      * to represent one or more characters of any type
109
+	 * returns true if a match is found or false if not
110
+	 *
111
+	 * @param string $pattern
112
+	 * @return false|int
113
+	 */
114
+	public function matches($pattern);
115 115
 
116 116
 
117
-    /**
118
-     * remove param
119
-     *
120
-     * @param string $key
121
-     * @param bool   $unset_from_global_too
122
-     */
123
-    public function unSetRequestParam($key, $unset_from_global_too = false);
117
+	/**
118
+	 * remove param
119
+	 *
120
+	 * @param string $key
121
+	 * @param bool   $unset_from_global_too
122
+	 */
123
+	public function unSetRequestParam($key, $unset_from_global_too = false);
124 124
 
125 125
 
126
-    /**
127
-     * remove params
128
-     *
129
-     * @param array $keys
130
-     * @param bool   $unset_from_global_too
131
-     */
132
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false);
126
+	/**
127
+	 * remove params
128
+	 *
129
+	 * @param array $keys
130
+	 * @param bool   $unset_from_global_too
131
+	 */
132
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false);
133 133
 
134 134
 
135
-    /**
136
-     * @return string
137
-     */
138
-    public function ipAddress();
135
+	/**
136
+	 * @return string
137
+	 */
138
+	public function ipAddress();
139 139
 
140 140
 
141
-    /**
142
-     * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
143
-     * @return string
144
-     */
145
-    public function requestUri($relativeToWpRoot = false);
146
-
147
-
148
-    /**
149
-     * @return string
150
-     */
151
-    public function userAgent();
152
-
153
-
154
-    /**
155
-     * @param string $user_agent
156
-     */
157
-    public function setUserAgent($user_agent = '');
158
-
159
-
160
-    /**
161
-     * @return bool
162
-     */
163
-    public function isBot();
164
-
165
-
166
-    /**
167
-     * @param bool $is_bot
168
-     */
169
-    public function setIsBot($is_bot);
141
+	/**
142
+	 * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not.
143
+	 * @return string
144
+	 */
145
+	public function requestUri($relativeToWpRoot = false);
146
+
147
+
148
+	/**
149
+	 * @return string
150
+	 */
151
+	public function userAgent();
152
+
153
+
154
+	/**
155
+	 * @param string $user_agent
156
+	 */
157
+	public function setUserAgent($user_agent = '');
158
+
159
+
160
+	/**
161
+	 * @return bool
162
+	 */
163
+	public function isBot();
164
+
165
+
166
+	/**
167
+	 * @param bool $is_bot
168
+	 */
169
+	public function setIsBot($is_bot);
170 170
 }
Please login to merge, or discard this patch.
core/services/request/Request.php 2 patches
Indentation   +652 added lines, -652 removed lines patch added patch discarded remove patch
@@ -17,656 +17,656 @@
 block discarded – undo
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19 19
 
20
-    /**
21
-     * $_GET parameters
22
-     *
23
-     * @var array $get
24
-     */
25
-    private $get;
26
-
27
-    /**
28
-     * $_POST parameters
29
-     *
30
-     * @var array $post
31
-     */
32
-    private $post;
33
-
34
-    /**
35
-     * $_COOKIE parameters
36
-     *
37
-     * @var array $cookie
38
-     */
39
-    private $cookie;
40
-
41
-    /**
42
-     * $_SERVER parameters
43
-     *
44
-     * @var array $server
45
-     */
46
-    private $server;
47
-
48
-    /**
49
-     * $_FILES parameters
50
-     *
51
-     * @var array $files
52
-     */
53
-    private $files;
54
-
55
-    /**
56
-     * $_REQUEST parameters
57
-     *
58
-     * @var array $request
59
-     */
60
-    private $request;
61
-
62
-    /**
63
-     * @var RequestTypeContextCheckerInterface
64
-     */
65
-    private $request_type;
66
-
67
-    /**
68
-     * IP address for request
69
-     *
70
-     * @var string $ip_address
71
-     */
72
-    private $ip_address;
73
-
74
-    /**
75
-     * @var string $user_agent
76
-     */
77
-    private $user_agent;
78
-
79
-    /**
80
-     * true if current user appears to be some kind of bot
81
-     *
82
-     * @var bool $is_bot
83
-     */
84
-    private $is_bot;
85
-
86
-
87
-    /**
88
-     * @param array $get
89
-     * @param array $post
90
-     * @param array $cookie
91
-     * @param array $server
92
-     * @param array $files
93
-     */
94
-    public function __construct(array $get, array $post, array $cookie, array $server, array $files = array())
95
-    {
96
-        // grab request vars
97
-        $this->get = $get;
98
-        $this->post = $post;
99
-        $this->cookie = $cookie;
100
-        $this->server = $server;
101
-        $this->files = $files;
102
-        $this->request = array_merge($this->get, $this->post);
103
-        $this->ip_address = $this->visitorIp();
104
-    }
105
-
106
-
107
-    /**
108
-     * @param RequestTypeContextCheckerInterface $type
109
-     */
110
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
-    {
112
-        $this->request_type = $type;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return array
118
-     */
119
-    public function getParams()
120
-    {
121
-        return $this->get;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return array
127
-     */
128
-    public function postParams()
129
-    {
130
-        return $this->post;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return array
136
-     */
137
-    public function cookieParams()
138
-    {
139
-        return $this->cookie;
140
-    }
141
-
142
-
143
-    /**
144
-     * @return array
145
-     */
146
-    public function serverParams()
147
-    {
148
-        return $this->server;
149
-    }
150
-
151
-
152
-    /**
153
-     * @return array
154
-     */
155
-    public function filesParams()
156
-    {
157
-        return $this->files;
158
-    }
159
-
160
-
161
-    /**
162
-     * returns contents of $_REQUEST
163
-     *
164
-     * @return array
165
-     */
166
-    public function requestParams()
167
-    {
168
-        return $this->request;
169
-    }
170
-
171
-
172
-    /**
173
-     * @param      $key
174
-     * @param      $value
175
-     * @param bool $override_ee
176
-     * @return    void
177
-     */
178
-    public function setRequestParam($key, $value, $override_ee = false)
179
-    {
180
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
181
-        if ($key !== 'ee'
182
-            || ($key === 'ee' && empty($this->request['ee']))
183
-            || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184
-        ) {
185
-            $this->request[ $key ] = $value;
186
-        }
187
-    }
188
-
189
-
190
-    /**
191
-     * returns   the value for a request param if the given key exists
192
-     *
193
-     * @param       $key
194
-     * @param null  $default
195
-     * @return mixed
196
-     */
197
-    public function getRequestParam($key, $default = null)
198
-    {
199
-        return $this->requestParameterDrillDown($key, $default, 'get');
200
-    }
201
-
202
-
203
-    /**
204
-     * check if param exists
205
-     *
206
-     * @param       $key
207
-     * @return bool
208
-     */
209
-    public function requestParamIsSet($key)
210
-    {
211
-        return $this->requestParameterDrillDown($key);
212
-    }
213
-
214
-
215
-    /**
216
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
217
-     * and return the value for the first match found
218
-     * wildcards can be either of the following:
219
-     *      ? to represent a single character of any type
220
-     *      * to represent one or more characters of any type
221
-     *
222
-     * @param string     $pattern
223
-     * @param null|mixed $default
224
-     * @return mixed
225
-     */
226
-    public function getMatch($pattern, $default = null)
227
-    {
228
-        return $this->requestParameterDrillDown($pattern, $default, 'match');
229
-    }
230
-
231
-
232
-    /**
233
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
234
-     * wildcards can be either of the following:
235
-     *      ? to represent a single character of any type
236
-     *      * to represent one or more characters of any type
237
-     * returns true if a match is found or false if not
238
-     *
239
-     * @param string $pattern
240
-     * @return bool
241
-     */
242
-    public function matches($pattern)
243
-    {
244
-        return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
245
-    }
246
-
247
-
248
-    /**
249
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
250
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
251
-     *                                      and used to search through the current request's parameter keys
252
-     * @param array  $request_params        The array of request parameters to search through
253
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
254
-     *                                      Default is null
255
-     * @param string $return                [optional] Controls what kind of value is returned.
256
-     *                                      Options are:
257
-     *                                      'bool' will return true or false if match is found or not
258
-     *                                      'key' will return the first key found that matches the supplied pattern
259
-     *                                      'value' will return the value for the first request parameter
260
-     *                                      whose key matches the supplied pattern
261
-     *                                      Default is 'value'
262
-     * @return boolean|string
263
-     */
264
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
265
-    {
266
-        $return = in_array($return, array('bool', 'key', 'value'), true)
267
-            ? $return
268
-            : 'is_set';
269
-        // replace wildcard chars with regex chars
270
-        $pattern = str_replace(
271
-            array("\*", "\?"),
272
-            array('.*', '.'),
273
-            preg_quote($pattern, '/')
274
-        );
275
-        foreach ($request_params as $key => $request_param) {
276
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
277
-                // return value for request param
278
-                if ($return === 'value') {
279
-                    return $request_params[ $key ];
280
-                }
281
-                // or actual key or true just to indicate it was found
282
-                return $return === 'key' ? $key : true;
283
-            }
284
-        }
285
-        // match not found so return default value or false
286
-        return $return === 'value' ? $default : false;
287
-    }
288
-
289
-
290
-    /**
291
-     * the supplied key can be a simple string to represent a "top-level" request parameter
292
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
293
-     * by using square brackets to surround keys for deeper array elements.
294
-     * For example :
295
-     * if the supplied $key was: "first[second][third]"
296
-     * then this will attempt to drill down into the request parameter array to find a value.
297
-     * Given the following request parameters:
298
-     *  array(
299
-     *      'first' => array(
300
-     *          'second' => array(
301
-     *              'third' => 'has a value'
302
-     *          )
303
-     *      )
304
-     *  )
305
-     * would return true if default parameters were set
306
-     *
307
-     * @param string $callback
308
-     * @param        $key
309
-     * @param null   $default
310
-     * @param array  $request_params
311
-     * @return bool|mixed|null
312
-     */
313
-    private function requestParameterDrillDown(
314
-        $key,
315
-        $default = null,
316
-        $callback = 'is_set',
317
-        array $request_params = array()
318
-    ) {
319
-        $callback = in_array($callback, array('is_set', 'get', 'match'), true)
320
-            ? $callback
321
-            : 'is_set';
322
-        $request_params = ! empty($request_params)
323
-            ? $request_params
324
-            : $this->request;
325
-        // does incoming key represent an array like 'first[second][third]'  ?
326
-        if (strpos($key, '[') !== false) {
327
-            // turn it into an actual array
328
-            $key = str_replace(']', '', $key);
329
-            $keys = explode('[', $key);
330
-            $key = array_shift($keys);
331
-            if ($callback === 'match') {
332
-                $real_key = $this->match($key, $request_params, $default, 'key');
333
-                $key = $real_key ? $real_key : $key;
334
-            }
335
-            // check if top level key exists
336
-            if (isset($request_params[ $key ])) {
337
-                // build a new key to pass along like: 'second[third]'
338
-                // or just 'second' depending on depth of keys
339
-                $key_string = array_shift($keys);
340
-                if (! empty($keys)) {
341
-                    $key_string .= '[' . implode('][', $keys) . ']';
342
-                }
343
-                return $this->requestParameterDrillDown(
344
-                    $key_string,
345
-                    $default,
346
-                    $callback,
347
-                    $request_params[ $key ]
348
-                );
349
-            }
350
-        }
351
-        if ($callback === 'is_set') {
352
-            return isset($request_params[ $key ]);
353
-        }
354
-        if ($callback === 'match') {
355
-            return $this->match($key, $request_params, $default);
356
-        }
357
-        return isset($request_params[ $key ])
358
-            ? $request_params[ $key ]
359
-            : $default;
360
-    }
361
-
362
-
363
-    /**
364
-     * remove param
365
-     *
366
-     * @param      $key
367
-     * @param bool $unset_from_global_too
368
-     */
369
-    public function unSetRequestParam($key, $unset_from_global_too = false)
370
-    {
371
-        // because unset may not actually remove var
372
-        $this->request[ $key ] = null;
373
-        unset($this->request[ $key ]);
374
-        if ($unset_from_global_too) {
375
-            unset($_REQUEST[ $key ]);
376
-        }
377
-    }
378
-
379
-
380
-    /**
381
-     * remove params
382
-     *
383
-     * @param array $keys
384
-     * @param bool  $unset_from_global_too
385
-     */
386
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
387
-    {
388
-        foreach ($keys as $key) {
389
-            $this->unSetRequestParam($key, $unset_from_global_too);
390
-        }
391
-    }
392
-
393
-
394
-    /**
395
-     * @return string
396
-     */
397
-    public function ipAddress()
398
-    {
399
-        return $this->ip_address;
400
-    }
401
-
402
-
403
-    /**
404
-     * attempt to get IP address of current visitor from server
405
-     * plz see: http://stackoverflow.com/a/2031935/1475279
406
-     *
407
-     * @access public
408
-     * @return string
409
-     */
410
-    private function visitorIp()
411
-    {
412
-        $visitor_ip = '0.0.0.0';
413
-        $server_keys = array(
414
-            'HTTP_CLIENT_IP',
415
-            'HTTP_X_FORWARDED_FOR',
416
-            'HTTP_X_FORWARDED',
417
-            'HTTP_X_CLUSTER_CLIENT_IP',
418
-            'HTTP_FORWARDED_FOR',
419
-            'HTTP_FORWARDED',
420
-            'REMOTE_ADDR',
421
-        );
422
-        foreach ($server_keys as $key) {
423
-            if (isset($this->server[ $key ])) {
424
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
425
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426
-                        $visitor_ip = $ip;
427
-                    }
428
-                }
429
-            }
430
-        }
431
-        return $visitor_ip;
432
-    }
433
-
434
-
435
-    /**
436
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
437
-     * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
438
-     *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
439
-     *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
440
-     * @return string
441
-     */
442
-    public function requestUri($relativeToWpRoot = false)
443
-    {
444
-        $request_uri = filter_input(
445
-            INPUT_SERVER,
446
-            'REQUEST_URI',
447
-            FILTER_SANITIZE_URL,
448
-            FILTER_NULL_ON_FAILURE
449
-        );
450
-        if (empty($request_uri)) {
451
-            // fallback sanitization if the above fails
452
-            $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
453
-        }
454
-        if ($relativeToWpRoot) {
455
-            $home_path = untrailingslashit(
456
-                parse_url(
457
-                    home_url(),
458
-                    PHP_URL_PATH
459
-                )
460
-            );
461
-            $request_uri = str_replace(
462
-                $home_path,
463
-                '',
464
-                $request_uri
465
-            );
466
-        }
467
-        return $request_uri;
468
-    }
469
-
470
-    /**
471
-     * @return string
472
-     */
473
-    public function userAgent()
474
-    {
475
-        return $this->user_agent;
476
-    }
477
-
478
-
479
-    /**
480
-     * @param string $user_agent
481
-     */
482
-    public function setUserAgent($user_agent = '')
483
-    {
484
-        if ($user_agent === '' || ! is_string($user_agent)) {
485
-            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
486
-        }
487
-        $this->user_agent = $user_agent;
488
-    }
489
-
490
-
491
-    /**
492
-     * @return bool
493
-     */
494
-    public function isBot()
495
-    {
496
-        return $this->is_bot;
497
-    }
498
-
499
-
500
-    /**
501
-     * @param bool $is_bot
502
-     */
503
-    public function setIsBot($is_bot)
504
-    {
505
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
506
-    }
507
-
508
-
509
-    /**
510
-     * @return bool
511
-     */
512
-    public function isActivation()
513
-    {
514
-        return $this->request_type->isActivation();
515
-    }
516
-
517
-
518
-    /**
519
-     * @param $is_activation
520
-     * @return bool
521
-     */
522
-    public function setIsActivation($is_activation)
523
-    {
524
-        return $this->request_type->setIsActivation($is_activation);
525
-    }
526
-
527
-
528
-    /**
529
-     * @return bool
530
-     */
531
-    public function isAdmin()
532
-    {
533
-        return $this->request_type->isAdmin();
534
-    }
535
-
536
-
537
-    /**
538
-     * @return bool
539
-     */
540
-    public function isAdminAjax()
541
-    {
542
-        return $this->request_type->isAdminAjax();
543
-    }
544
-
545
-
546
-    /**
547
-     * @return bool
548
-     */
549
-    public function isAjax()
550
-    {
551
-        return $this->request_type->isAjax();
552
-    }
553
-
554
-
555
-    /**
556
-     * @return bool
557
-     */
558
-    public function isEeAjax()
559
-    {
560
-        return $this->request_type->isEeAjax();
561
-    }
562
-
563
-
564
-    /**
565
-     * @return bool
566
-     */
567
-    public function isOtherAjax()
568
-    {
569
-        return $this->request_type->isOtherAjax();
570
-    }
571
-
572
-
573
-    /**
574
-     * @return bool
575
-     */
576
-    public function isApi()
577
-    {
578
-        return $this->request_type->isApi();
579
-    }
580
-
581
-
582
-    /**
583
-     * @return bool
584
-     */
585
-    public function isCli()
586
-    {
587
-        return $this->request_type->isCli();
588
-    }
589
-
590
-
591
-    /**
592
-     * @return bool
593
-     */
594
-    public function isCron()
595
-    {
596
-        return $this->request_type->isCron();
597
-    }
598
-
599
-
600
-    /**
601
-     * @return bool
602
-     */
603
-    public function isFeed()
604
-    {
605
-        return $this->request_type->isFeed();
606
-    }
607
-
608
-
609
-    /**
610
-     * @return bool
611
-     */
612
-    public function isFrontend()
613
-    {
614
-        return $this->request_type->isFrontend();
615
-    }
616
-
617
-
618
-    /**
619
-     * @return bool
620
-     */
621
-    public function isFrontAjax()
622
-    {
623
-        return $this->request_type->isFrontAjax();
624
-    }
625
-
626
-
627
-    /**
628
-     * @return bool
629
-     */
630
-    public function isIframe()
631
-    {
632
-        return $this->request_type->isIframe();
633
-    }
634
-
635
-
636
-    /**
637
-     * @return bool
638
-     */
639
-    public function isWordPressApi()
640
-    {
641
-        return $this->request_type->isWordPressApi();
642
-    }
643
-
644
-
645
-
646
-    /**
647
-     * @return bool
648
-     */
649
-    public function isWordPressHeartbeat()
650
-    {
651
-        return $this->request_type->isWordPressHeartbeat();
652
-    }
653
-
654
-
655
-
656
-    /**
657
-     * @return bool
658
-     */
659
-    public function isWordPressScrape()
660
-    {
661
-        return $this->request_type->isWordPressScrape();
662
-    }
663
-
664
-
665
-    /**
666
-     * @return string
667
-     */
668
-    public function slug()
669
-    {
670
-        return $this->request_type->slug();
671
-    }
20
+	/**
21
+	 * $_GET parameters
22
+	 *
23
+	 * @var array $get
24
+	 */
25
+	private $get;
26
+
27
+	/**
28
+	 * $_POST parameters
29
+	 *
30
+	 * @var array $post
31
+	 */
32
+	private $post;
33
+
34
+	/**
35
+	 * $_COOKIE parameters
36
+	 *
37
+	 * @var array $cookie
38
+	 */
39
+	private $cookie;
40
+
41
+	/**
42
+	 * $_SERVER parameters
43
+	 *
44
+	 * @var array $server
45
+	 */
46
+	private $server;
47
+
48
+	/**
49
+	 * $_FILES parameters
50
+	 *
51
+	 * @var array $files
52
+	 */
53
+	private $files;
54
+
55
+	/**
56
+	 * $_REQUEST parameters
57
+	 *
58
+	 * @var array $request
59
+	 */
60
+	private $request;
61
+
62
+	/**
63
+	 * @var RequestTypeContextCheckerInterface
64
+	 */
65
+	private $request_type;
66
+
67
+	/**
68
+	 * IP address for request
69
+	 *
70
+	 * @var string $ip_address
71
+	 */
72
+	private $ip_address;
73
+
74
+	/**
75
+	 * @var string $user_agent
76
+	 */
77
+	private $user_agent;
78
+
79
+	/**
80
+	 * true if current user appears to be some kind of bot
81
+	 *
82
+	 * @var bool $is_bot
83
+	 */
84
+	private $is_bot;
85
+
86
+
87
+	/**
88
+	 * @param array $get
89
+	 * @param array $post
90
+	 * @param array $cookie
91
+	 * @param array $server
92
+	 * @param array $files
93
+	 */
94
+	public function __construct(array $get, array $post, array $cookie, array $server, array $files = array())
95
+	{
96
+		// grab request vars
97
+		$this->get = $get;
98
+		$this->post = $post;
99
+		$this->cookie = $cookie;
100
+		$this->server = $server;
101
+		$this->files = $files;
102
+		$this->request = array_merge($this->get, $this->post);
103
+		$this->ip_address = $this->visitorIp();
104
+	}
105
+
106
+
107
+	/**
108
+	 * @param RequestTypeContextCheckerInterface $type
109
+	 */
110
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
111
+	{
112
+		$this->request_type = $type;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return array
118
+	 */
119
+	public function getParams()
120
+	{
121
+		return $this->get;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return array
127
+	 */
128
+	public function postParams()
129
+	{
130
+		return $this->post;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return array
136
+	 */
137
+	public function cookieParams()
138
+	{
139
+		return $this->cookie;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @return array
145
+	 */
146
+	public function serverParams()
147
+	{
148
+		return $this->server;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @return array
154
+	 */
155
+	public function filesParams()
156
+	{
157
+		return $this->files;
158
+	}
159
+
160
+
161
+	/**
162
+	 * returns contents of $_REQUEST
163
+	 *
164
+	 * @return array
165
+	 */
166
+	public function requestParams()
167
+	{
168
+		return $this->request;
169
+	}
170
+
171
+
172
+	/**
173
+	 * @param      $key
174
+	 * @param      $value
175
+	 * @param bool $override_ee
176
+	 * @return    void
177
+	 */
178
+	public function setRequestParam($key, $value, $override_ee = false)
179
+	{
180
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
181
+		if ($key !== 'ee'
182
+			|| ($key === 'ee' && empty($this->request['ee']))
183
+			|| ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184
+		) {
185
+			$this->request[ $key ] = $value;
186
+		}
187
+	}
188
+
189
+
190
+	/**
191
+	 * returns   the value for a request param if the given key exists
192
+	 *
193
+	 * @param       $key
194
+	 * @param null  $default
195
+	 * @return mixed
196
+	 */
197
+	public function getRequestParam($key, $default = null)
198
+	{
199
+		return $this->requestParameterDrillDown($key, $default, 'get');
200
+	}
201
+
202
+
203
+	/**
204
+	 * check if param exists
205
+	 *
206
+	 * @param       $key
207
+	 * @return bool
208
+	 */
209
+	public function requestParamIsSet($key)
210
+	{
211
+		return $this->requestParameterDrillDown($key);
212
+	}
213
+
214
+
215
+	/**
216
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
217
+	 * and return the value for the first match found
218
+	 * wildcards can be either of the following:
219
+	 *      ? to represent a single character of any type
220
+	 *      * to represent one or more characters of any type
221
+	 *
222
+	 * @param string     $pattern
223
+	 * @param null|mixed $default
224
+	 * @return mixed
225
+	 */
226
+	public function getMatch($pattern, $default = null)
227
+	{
228
+		return $this->requestParameterDrillDown($pattern, $default, 'match');
229
+	}
230
+
231
+
232
+	/**
233
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
234
+	 * wildcards can be either of the following:
235
+	 *      ? to represent a single character of any type
236
+	 *      * to represent one or more characters of any type
237
+	 * returns true if a match is found or false if not
238
+	 *
239
+	 * @param string $pattern
240
+	 * @return bool
241
+	 */
242
+	public function matches($pattern)
243
+	{
244
+		return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
245
+	}
246
+
247
+
248
+	/**
249
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
250
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
251
+	 *                                      and used to search through the current request's parameter keys
252
+	 * @param array  $request_params        The array of request parameters to search through
253
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
254
+	 *                                      Default is null
255
+	 * @param string $return                [optional] Controls what kind of value is returned.
256
+	 *                                      Options are:
257
+	 *                                      'bool' will return true or false if match is found or not
258
+	 *                                      'key' will return the first key found that matches the supplied pattern
259
+	 *                                      'value' will return the value for the first request parameter
260
+	 *                                      whose key matches the supplied pattern
261
+	 *                                      Default is 'value'
262
+	 * @return boolean|string
263
+	 */
264
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
265
+	{
266
+		$return = in_array($return, array('bool', 'key', 'value'), true)
267
+			? $return
268
+			: 'is_set';
269
+		// replace wildcard chars with regex chars
270
+		$pattern = str_replace(
271
+			array("\*", "\?"),
272
+			array('.*', '.'),
273
+			preg_quote($pattern, '/')
274
+		);
275
+		foreach ($request_params as $key => $request_param) {
276
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
277
+				// return value for request param
278
+				if ($return === 'value') {
279
+					return $request_params[ $key ];
280
+				}
281
+				// or actual key or true just to indicate it was found
282
+				return $return === 'key' ? $key : true;
283
+			}
284
+		}
285
+		// match not found so return default value or false
286
+		return $return === 'value' ? $default : false;
287
+	}
288
+
289
+
290
+	/**
291
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
292
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
293
+	 * by using square brackets to surround keys for deeper array elements.
294
+	 * For example :
295
+	 * if the supplied $key was: "first[second][third]"
296
+	 * then this will attempt to drill down into the request parameter array to find a value.
297
+	 * Given the following request parameters:
298
+	 *  array(
299
+	 *      'first' => array(
300
+	 *          'second' => array(
301
+	 *              'third' => 'has a value'
302
+	 *          )
303
+	 *      )
304
+	 *  )
305
+	 * would return true if default parameters were set
306
+	 *
307
+	 * @param string $callback
308
+	 * @param        $key
309
+	 * @param null   $default
310
+	 * @param array  $request_params
311
+	 * @return bool|mixed|null
312
+	 */
313
+	private function requestParameterDrillDown(
314
+		$key,
315
+		$default = null,
316
+		$callback = 'is_set',
317
+		array $request_params = array()
318
+	) {
319
+		$callback = in_array($callback, array('is_set', 'get', 'match'), true)
320
+			? $callback
321
+			: 'is_set';
322
+		$request_params = ! empty($request_params)
323
+			? $request_params
324
+			: $this->request;
325
+		// does incoming key represent an array like 'first[second][third]'  ?
326
+		if (strpos($key, '[') !== false) {
327
+			// turn it into an actual array
328
+			$key = str_replace(']', '', $key);
329
+			$keys = explode('[', $key);
330
+			$key = array_shift($keys);
331
+			if ($callback === 'match') {
332
+				$real_key = $this->match($key, $request_params, $default, 'key');
333
+				$key = $real_key ? $real_key : $key;
334
+			}
335
+			// check if top level key exists
336
+			if (isset($request_params[ $key ])) {
337
+				// build a new key to pass along like: 'second[third]'
338
+				// or just 'second' depending on depth of keys
339
+				$key_string = array_shift($keys);
340
+				if (! empty($keys)) {
341
+					$key_string .= '[' . implode('][', $keys) . ']';
342
+				}
343
+				return $this->requestParameterDrillDown(
344
+					$key_string,
345
+					$default,
346
+					$callback,
347
+					$request_params[ $key ]
348
+				);
349
+			}
350
+		}
351
+		if ($callback === 'is_set') {
352
+			return isset($request_params[ $key ]);
353
+		}
354
+		if ($callback === 'match') {
355
+			return $this->match($key, $request_params, $default);
356
+		}
357
+		return isset($request_params[ $key ])
358
+			? $request_params[ $key ]
359
+			: $default;
360
+	}
361
+
362
+
363
+	/**
364
+	 * remove param
365
+	 *
366
+	 * @param      $key
367
+	 * @param bool $unset_from_global_too
368
+	 */
369
+	public function unSetRequestParam($key, $unset_from_global_too = false)
370
+	{
371
+		// because unset may not actually remove var
372
+		$this->request[ $key ] = null;
373
+		unset($this->request[ $key ]);
374
+		if ($unset_from_global_too) {
375
+			unset($_REQUEST[ $key ]);
376
+		}
377
+	}
378
+
379
+
380
+	/**
381
+	 * remove params
382
+	 *
383
+	 * @param array $keys
384
+	 * @param bool  $unset_from_global_too
385
+	 */
386
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
387
+	{
388
+		foreach ($keys as $key) {
389
+			$this->unSetRequestParam($key, $unset_from_global_too);
390
+		}
391
+	}
392
+
393
+
394
+	/**
395
+	 * @return string
396
+	 */
397
+	public function ipAddress()
398
+	{
399
+		return $this->ip_address;
400
+	}
401
+
402
+
403
+	/**
404
+	 * attempt to get IP address of current visitor from server
405
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
406
+	 *
407
+	 * @access public
408
+	 * @return string
409
+	 */
410
+	private function visitorIp()
411
+	{
412
+		$visitor_ip = '0.0.0.0';
413
+		$server_keys = array(
414
+			'HTTP_CLIENT_IP',
415
+			'HTTP_X_FORWARDED_FOR',
416
+			'HTTP_X_FORWARDED',
417
+			'HTTP_X_CLUSTER_CLIENT_IP',
418
+			'HTTP_FORWARDED_FOR',
419
+			'HTTP_FORWARDED',
420
+			'REMOTE_ADDR',
421
+		);
422
+		foreach ($server_keys as $key) {
423
+			if (isset($this->server[ $key ])) {
424
+				foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
425
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426
+						$visitor_ip = $ip;
427
+					}
428
+				}
429
+			}
430
+		}
431
+		return $visitor_ip;
432
+	}
433
+
434
+
435
+	/**
436
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
437
+	 * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
438
+	 *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
439
+	 *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
440
+	 * @return string
441
+	 */
442
+	public function requestUri($relativeToWpRoot = false)
443
+	{
444
+		$request_uri = filter_input(
445
+			INPUT_SERVER,
446
+			'REQUEST_URI',
447
+			FILTER_SANITIZE_URL,
448
+			FILTER_NULL_ON_FAILURE
449
+		);
450
+		if (empty($request_uri)) {
451
+			// fallback sanitization if the above fails
452
+			$request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
453
+		}
454
+		if ($relativeToWpRoot) {
455
+			$home_path = untrailingslashit(
456
+				parse_url(
457
+					home_url(),
458
+					PHP_URL_PATH
459
+				)
460
+			);
461
+			$request_uri = str_replace(
462
+				$home_path,
463
+				'',
464
+				$request_uri
465
+			);
466
+		}
467
+		return $request_uri;
468
+	}
469
+
470
+	/**
471
+	 * @return string
472
+	 */
473
+	public function userAgent()
474
+	{
475
+		return $this->user_agent;
476
+	}
477
+
478
+
479
+	/**
480
+	 * @param string $user_agent
481
+	 */
482
+	public function setUserAgent($user_agent = '')
483
+	{
484
+		if ($user_agent === '' || ! is_string($user_agent)) {
485
+			$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
486
+		}
487
+		$this->user_agent = $user_agent;
488
+	}
489
+
490
+
491
+	/**
492
+	 * @return bool
493
+	 */
494
+	public function isBot()
495
+	{
496
+		return $this->is_bot;
497
+	}
498
+
499
+
500
+	/**
501
+	 * @param bool $is_bot
502
+	 */
503
+	public function setIsBot($is_bot)
504
+	{
505
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
506
+	}
507
+
508
+
509
+	/**
510
+	 * @return bool
511
+	 */
512
+	public function isActivation()
513
+	{
514
+		return $this->request_type->isActivation();
515
+	}
516
+
517
+
518
+	/**
519
+	 * @param $is_activation
520
+	 * @return bool
521
+	 */
522
+	public function setIsActivation($is_activation)
523
+	{
524
+		return $this->request_type->setIsActivation($is_activation);
525
+	}
526
+
527
+
528
+	/**
529
+	 * @return bool
530
+	 */
531
+	public function isAdmin()
532
+	{
533
+		return $this->request_type->isAdmin();
534
+	}
535
+
536
+
537
+	/**
538
+	 * @return bool
539
+	 */
540
+	public function isAdminAjax()
541
+	{
542
+		return $this->request_type->isAdminAjax();
543
+	}
544
+
545
+
546
+	/**
547
+	 * @return bool
548
+	 */
549
+	public function isAjax()
550
+	{
551
+		return $this->request_type->isAjax();
552
+	}
553
+
554
+
555
+	/**
556
+	 * @return bool
557
+	 */
558
+	public function isEeAjax()
559
+	{
560
+		return $this->request_type->isEeAjax();
561
+	}
562
+
563
+
564
+	/**
565
+	 * @return bool
566
+	 */
567
+	public function isOtherAjax()
568
+	{
569
+		return $this->request_type->isOtherAjax();
570
+	}
571
+
572
+
573
+	/**
574
+	 * @return bool
575
+	 */
576
+	public function isApi()
577
+	{
578
+		return $this->request_type->isApi();
579
+	}
580
+
581
+
582
+	/**
583
+	 * @return bool
584
+	 */
585
+	public function isCli()
586
+	{
587
+		return $this->request_type->isCli();
588
+	}
589
+
590
+
591
+	/**
592
+	 * @return bool
593
+	 */
594
+	public function isCron()
595
+	{
596
+		return $this->request_type->isCron();
597
+	}
598
+
599
+
600
+	/**
601
+	 * @return bool
602
+	 */
603
+	public function isFeed()
604
+	{
605
+		return $this->request_type->isFeed();
606
+	}
607
+
608
+
609
+	/**
610
+	 * @return bool
611
+	 */
612
+	public function isFrontend()
613
+	{
614
+		return $this->request_type->isFrontend();
615
+	}
616
+
617
+
618
+	/**
619
+	 * @return bool
620
+	 */
621
+	public function isFrontAjax()
622
+	{
623
+		return $this->request_type->isFrontAjax();
624
+	}
625
+
626
+
627
+	/**
628
+	 * @return bool
629
+	 */
630
+	public function isIframe()
631
+	{
632
+		return $this->request_type->isIframe();
633
+	}
634
+
635
+
636
+	/**
637
+	 * @return bool
638
+	 */
639
+	public function isWordPressApi()
640
+	{
641
+		return $this->request_type->isWordPressApi();
642
+	}
643
+
644
+
645
+
646
+	/**
647
+	 * @return bool
648
+	 */
649
+	public function isWordPressHeartbeat()
650
+	{
651
+		return $this->request_type->isWordPressHeartbeat();
652
+	}
653
+
654
+
655
+
656
+	/**
657
+	 * @return bool
658
+	 */
659
+	public function isWordPressScrape()
660
+	{
661
+		return $this->request_type->isWordPressScrape();
662
+	}
663
+
664
+
665
+	/**
666
+	 * @return string
667
+	 */
668
+	public function slug()
669
+	{
670
+		return $this->request_type->slug();
671
+	}
672 672
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
             || ($key === 'ee' && empty($this->request['ee']))
183 183
             || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
184 184
         ) {
185
-            $this->request[ $key ] = $value;
185
+            $this->request[$key] = $value;
186 186
         }
187 187
     }
188 188
 
@@ -273,10 +273,10 @@  discard block
 block discarded – undo
273 273
             preg_quote($pattern, '/')
274 274
         );
275 275
         foreach ($request_params as $key => $request_param) {
276
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
276
+            if (preg_match('/^'.$pattern.'$/is', $key)) {
277 277
                 // return value for request param
278 278
                 if ($return === 'value') {
279
-                    return $request_params[ $key ];
279
+                    return $request_params[$key];
280 280
                 }
281 281
                 // or actual key or true just to indicate it was found
282 282
                 return $return === 'key' ? $key : true;
@@ -333,29 +333,29 @@  discard block
 block discarded – undo
333 333
                 $key = $real_key ? $real_key : $key;
334 334
             }
335 335
             // check if top level key exists
336
-            if (isset($request_params[ $key ])) {
336
+            if (isset($request_params[$key])) {
337 337
                 // build a new key to pass along like: 'second[third]'
338 338
                 // or just 'second' depending on depth of keys
339 339
                 $key_string = array_shift($keys);
340
-                if (! empty($keys)) {
341
-                    $key_string .= '[' . implode('][', $keys) . ']';
340
+                if ( ! empty($keys)) {
341
+                    $key_string .= '['.implode('][', $keys).']';
342 342
                 }
343 343
                 return $this->requestParameterDrillDown(
344 344
                     $key_string,
345 345
                     $default,
346 346
                     $callback,
347
-                    $request_params[ $key ]
347
+                    $request_params[$key]
348 348
                 );
349 349
             }
350 350
         }
351 351
         if ($callback === 'is_set') {
352
-            return isset($request_params[ $key ]);
352
+            return isset($request_params[$key]);
353 353
         }
354 354
         if ($callback === 'match') {
355 355
             return $this->match($key, $request_params, $default);
356 356
         }
357
-        return isset($request_params[ $key ])
358
-            ? $request_params[ $key ]
357
+        return isset($request_params[$key])
358
+            ? $request_params[$key]
359 359
             : $default;
360 360
     }
361 361
 
@@ -369,10 +369,10 @@  discard block
 block discarded – undo
369 369
     public function unSetRequestParam($key, $unset_from_global_too = false)
370 370
     {
371 371
         // because unset may not actually remove var
372
-        $this->request[ $key ] = null;
373
-        unset($this->request[ $key ]);
372
+        $this->request[$key] = null;
373
+        unset($this->request[$key]);
374 374
         if ($unset_from_global_too) {
375
-            unset($_REQUEST[ $key ]);
375
+            unset($_REQUEST[$key]);
376 376
         }
377 377
     }
378 378
 
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
             'REMOTE_ADDR',
421 421
         );
422 422
         foreach ($server_keys as $key) {
423
-            if (isset($this->server[ $key ])) {
424
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
423
+            if (isset($this->server[$key])) {
424
+                foreach (array_map('trim', explode(',', $this->server[$key])) as $ip) {
425 425
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
426 426
                         $visitor_ip = $ip;
427 427
                     }
Please login to merge, or discard this patch.
core/services/admin/AdminPageHeaderDecorator.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -16,19 +16,19 @@
 block discarded – undo
16 16
 abstract class AdminPageHeaderDecorator implements AdminPageHeaderDecoratorInterface
17 17
 {
18 18
 
19
-    /**
20
-     * @var RequestInterface $request
21
-     */
22
-    protected $request;
19
+	/**
20
+	 * @var RequestInterface $request
21
+	 */
22
+	protected $request;
23 23
 
24 24
 
25
-    /**
26
-     * AdminPageHeader constructor.
27
-     *
28
-     * @param RequestInterface $request
29
-     */
30
-    public function __construct(RequestInterface $request)
31
-    {
32
-        $this->request = $request;
33
-    }
25
+	/**
26
+	 * AdminPageHeader constructor.
27
+	 *
28
+	 * @param RequestInterface $request
29
+	 */
30
+	public function __construct(RequestInterface $request)
31
+	{
32
+		$this->request = $request;
33
+	}
34 34
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Price.class.php 1 patch
Indentation   +285 added lines, -285 removed lines patch added patch discarded remove patch
@@ -10,289 +10,289 @@
 block discarded – undo
10 10
 class EE_Price extends EE_Soft_Delete_Base_Class
11 11
 {
12 12
 
13
-    /**
14
-     * @param array  $props_n_values          incoming values
15
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
16
-     *                                        used.)
17
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
18
-     *                                        date_format and the second value is the time format
19
-     * @return EE_Price
20
-     */
21
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
22
-    {
23
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
24
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
25
-    }
26
-
27
-
28
-    /**
29
-     * @param array  $props_n_values  incoming values from the database
30
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
31
-     *                                the website will be used.
32
-     * @return EE_Price
33
-     */
34
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
35
-    {
36
-        return new self($props_n_values, true, $timezone);
37
-    }
38
-
39
-
40
-    /**
41
-     *        Set Price type ID
42
-     *
43
-     * @access        public
44
-     * @param        int $PRT_ID
45
-     */
46
-    public function set_type($PRT_ID = 0)
47
-    {
48
-        $this->set('PRT_ID', $PRT_ID);
49
-    }
50
-
51
-
52
-    /**
53
-     *        Set Price Amount
54
-     *
55
-     * @access        public
56
-     * @param        float $PRC_amount
57
-     */
58
-    public function set_amount($PRC_amount = 0.00)
59
-    {
60
-        $this->set('PRC_amount', $PRC_amount);
61
-    }
62
-
63
-
64
-    /**
65
-     *        Set Price Name
66
-     *
67
-     * @access        public
68
-     * @param        string $PRC_name
69
-     */
70
-    public function set_name($PRC_name = '')
71
-    {
72
-        $this->set('PRC_name', $PRC_name);
73
-    }
74
-
75
-
76
-    /**
77
-     *        Set Price Description
78
-     *
79
-     * @access        public
80
-     * @param        string $PRC_desc
81
-     */
82
-    public function set_description($PRC_desc = '')
83
-    {
84
-        $this->Set('PRC_desc', $PRC_desc);
85
-    }
86
-
87
-
88
-    /**
89
-     *        set is_default
90
-     *
91
-     * @access        public
92
-     * @param        bool $PRC_is_default
93
-     */
94
-    public function set_is_default($PRC_is_default = false)
95
-    {
96
-        $this->set('PRC_is_default', $PRC_is_default);
97
-    }
98
-
99
-
100
-    /**
101
-     *        set deleted
102
-     *
103
-     * @access        public
104
-     * @param        bool $PRC_deleted
105
-     */
106
-    public function set_deleted($PRC_deleted = null)
107
-    {
108
-        $this->set('PRC_deleted', $PRC_deleted);
109
-    }
110
-
111
-
112
-    /**
113
-     *    get Price type
114
-     *
115
-     * @access        public
116
-     * @return        int
117
-     */
118
-    public function type()
119
-    {
120
-        return $this->get('PRT_ID');
121
-    }
122
-
123
-
124
-    /**
125
-     *    get Price Amount
126
-     *
127
-     * @access        public
128
-     * @return        float
129
-     */
130
-    public function amount()
131
-    {
132
-        return $this->get('PRC_amount');
133
-    }
134
-
135
-
136
-    /**
137
-     *    get Price Name
138
-     *
139
-     * @access        public
140
-     * @return        string
141
-     */
142
-    public function name()
143
-    {
144
-        return $this->get('PRC_name');
145
-    }
146
-
147
-
148
-    /**
149
-     *    get Price description
150
-     *
151
-     * @access        public
152
-     * @return        string
153
-     */
154
-    public function desc()
155
-    {
156
-        return $this->get('PRC_desc');
157
-    }
158
-
159
-
160
-    /**
161
-     *    get overrides
162
-     *
163
-     * @access        public
164
-     * @return        int
165
-     */
166
-    public function overrides()
167
-    {
168
-        return $this->get('PRC_overrides');
169
-    }
170
-
171
-
172
-    /**
173
-     *    get order
174
-     *
175
-     * @access        public
176
-     * @return        int
177
-     */
178
-    public function order()
179
-    {
180
-        return $this->get('PRC_order');
181
-    }
182
-
183
-
184
-    /**
185
-     * get the author of the price
186
-     *
187
-     * @since 4.5.0
188
-     *
189
-     * @return int
190
-     */
191
-    public function wp_user()
192
-    {
193
-        return $this->get('PRC_wp_user');
194
-    }
195
-
196
-
197
-    /**
198
-     *    get is_default
199
-     *
200
-     * @access        public
201
-     * @return        bool
202
-     */
203
-    public function is_default()
204
-    {
205
-        return $this->get('PRC_is_default');
206
-    }
207
-
208
-
209
-    /**
210
-     *    get deleted
211
-     *
212
-     * @access        public
213
-     * @return        bool
214
-     */
215
-    public function deleted()
216
-    {
217
-        return $this->get('PRC_deleted');
218
-    }
219
-
220
-
221
-    /**
222
-     * @return bool
223
-     */
224
-    public function parent()
225
-    {
226
-        return $this->get('PRC_parent');
227
-    }
228
-
229
-
230
-    // some helper methods for getting info on the price_type for this price
231
-
232
-    /**
233
-     * return whether the price is a base price or not
234
-     *
235
-     * @return boolean
236
-     */
237
-    public function is_base_price()
238
-    {
239
-        $price_type = $this->type_obj();
240
-        return $price_type->base_type() === 1;
241
-    }
242
-
243
-
244
-    /**
245
-     *
246
-     * @return EE_Price_Type
247
-     */
248
-    public function type_obj()
249
-    {
250
-        return $this->get_first_related('Price_Type');
251
-    }
252
-
253
-
254
-    /**
255
-     * Simply indicates whether this price increases or decreases the total
256
-     *
257
-     * @return boolean true = discount, otherwise adds to the total
258
-     */
259
-    public function is_discount()
260
-    {
261
-        $price_type = $this->type_obj();
262
-        return $price_type->is_discount();
263
-    }
264
-
265
-
266
-    /**
267
-     * whether the price is a percentage or not
268
-     *
269
-     * @return boolean
270
-     */
271
-    public function is_percent()
272
-    {
273
-        $price_type = $this->type_obj();
274
-        return $price_type->get('PRT_is_percent');
275
-    }
276
-
277
-
278
-    /**
279
-     * return pretty price dependant on whether its a dollar or percent.
280
-     *
281
-     * @since 4.4.0
282
-     *
283
-     * @return string
284
-     */
285
-    public function pretty_price()
286
-    {
287
-        return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%';
288
-    }
289
-
290
-
291
-    /**
292
-     * @return mixed
293
-     */
294
-    public function get_price_without_currency_symbol()
295
-    {
296
-        return str_replace(EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty('PRC_amount'));
297
-    }
13
+	/**
14
+	 * @param array  $props_n_values          incoming values
15
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
16
+	 *                                        used.)
17
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
18
+	 *                                        date_format and the second value is the time format
19
+	 * @return EE_Price
20
+	 */
21
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
22
+	{
23
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
24
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
25
+	}
26
+
27
+
28
+	/**
29
+	 * @param array  $props_n_values  incoming values from the database
30
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
31
+	 *                                the website will be used.
32
+	 * @return EE_Price
33
+	 */
34
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
35
+	{
36
+		return new self($props_n_values, true, $timezone);
37
+	}
38
+
39
+
40
+	/**
41
+	 *        Set Price type ID
42
+	 *
43
+	 * @access        public
44
+	 * @param        int $PRT_ID
45
+	 */
46
+	public function set_type($PRT_ID = 0)
47
+	{
48
+		$this->set('PRT_ID', $PRT_ID);
49
+	}
50
+
51
+
52
+	/**
53
+	 *        Set Price Amount
54
+	 *
55
+	 * @access        public
56
+	 * @param        float $PRC_amount
57
+	 */
58
+	public function set_amount($PRC_amount = 0.00)
59
+	{
60
+		$this->set('PRC_amount', $PRC_amount);
61
+	}
62
+
63
+
64
+	/**
65
+	 *        Set Price Name
66
+	 *
67
+	 * @access        public
68
+	 * @param        string $PRC_name
69
+	 */
70
+	public function set_name($PRC_name = '')
71
+	{
72
+		$this->set('PRC_name', $PRC_name);
73
+	}
74
+
75
+
76
+	/**
77
+	 *        Set Price Description
78
+	 *
79
+	 * @access        public
80
+	 * @param        string $PRC_desc
81
+	 */
82
+	public function set_description($PRC_desc = '')
83
+	{
84
+		$this->Set('PRC_desc', $PRC_desc);
85
+	}
86
+
87
+
88
+	/**
89
+	 *        set is_default
90
+	 *
91
+	 * @access        public
92
+	 * @param        bool $PRC_is_default
93
+	 */
94
+	public function set_is_default($PRC_is_default = false)
95
+	{
96
+		$this->set('PRC_is_default', $PRC_is_default);
97
+	}
98
+
99
+
100
+	/**
101
+	 *        set deleted
102
+	 *
103
+	 * @access        public
104
+	 * @param        bool $PRC_deleted
105
+	 */
106
+	public function set_deleted($PRC_deleted = null)
107
+	{
108
+		$this->set('PRC_deleted', $PRC_deleted);
109
+	}
110
+
111
+
112
+	/**
113
+	 *    get Price type
114
+	 *
115
+	 * @access        public
116
+	 * @return        int
117
+	 */
118
+	public function type()
119
+	{
120
+		return $this->get('PRT_ID');
121
+	}
122
+
123
+
124
+	/**
125
+	 *    get Price Amount
126
+	 *
127
+	 * @access        public
128
+	 * @return        float
129
+	 */
130
+	public function amount()
131
+	{
132
+		return $this->get('PRC_amount');
133
+	}
134
+
135
+
136
+	/**
137
+	 *    get Price Name
138
+	 *
139
+	 * @access        public
140
+	 * @return        string
141
+	 */
142
+	public function name()
143
+	{
144
+		return $this->get('PRC_name');
145
+	}
146
+
147
+
148
+	/**
149
+	 *    get Price description
150
+	 *
151
+	 * @access        public
152
+	 * @return        string
153
+	 */
154
+	public function desc()
155
+	{
156
+		return $this->get('PRC_desc');
157
+	}
158
+
159
+
160
+	/**
161
+	 *    get overrides
162
+	 *
163
+	 * @access        public
164
+	 * @return        int
165
+	 */
166
+	public function overrides()
167
+	{
168
+		return $this->get('PRC_overrides');
169
+	}
170
+
171
+
172
+	/**
173
+	 *    get order
174
+	 *
175
+	 * @access        public
176
+	 * @return        int
177
+	 */
178
+	public function order()
179
+	{
180
+		return $this->get('PRC_order');
181
+	}
182
+
183
+
184
+	/**
185
+	 * get the author of the price
186
+	 *
187
+	 * @since 4.5.0
188
+	 *
189
+	 * @return int
190
+	 */
191
+	public function wp_user()
192
+	{
193
+		return $this->get('PRC_wp_user');
194
+	}
195
+
196
+
197
+	/**
198
+	 *    get is_default
199
+	 *
200
+	 * @access        public
201
+	 * @return        bool
202
+	 */
203
+	public function is_default()
204
+	{
205
+		return $this->get('PRC_is_default');
206
+	}
207
+
208
+
209
+	/**
210
+	 *    get deleted
211
+	 *
212
+	 * @access        public
213
+	 * @return        bool
214
+	 */
215
+	public function deleted()
216
+	{
217
+		return $this->get('PRC_deleted');
218
+	}
219
+
220
+
221
+	/**
222
+	 * @return bool
223
+	 */
224
+	public function parent()
225
+	{
226
+		return $this->get('PRC_parent');
227
+	}
228
+
229
+
230
+	// some helper methods for getting info on the price_type for this price
231
+
232
+	/**
233
+	 * return whether the price is a base price or not
234
+	 *
235
+	 * @return boolean
236
+	 */
237
+	public function is_base_price()
238
+	{
239
+		$price_type = $this->type_obj();
240
+		return $price_type->base_type() === 1;
241
+	}
242
+
243
+
244
+	/**
245
+	 *
246
+	 * @return EE_Price_Type
247
+	 */
248
+	public function type_obj()
249
+	{
250
+		return $this->get_first_related('Price_Type');
251
+	}
252
+
253
+
254
+	/**
255
+	 * Simply indicates whether this price increases or decreases the total
256
+	 *
257
+	 * @return boolean true = discount, otherwise adds to the total
258
+	 */
259
+	public function is_discount()
260
+	{
261
+		$price_type = $this->type_obj();
262
+		return $price_type->is_discount();
263
+	}
264
+
265
+
266
+	/**
267
+	 * whether the price is a percentage or not
268
+	 *
269
+	 * @return boolean
270
+	 */
271
+	public function is_percent()
272
+	{
273
+		$price_type = $this->type_obj();
274
+		return $price_type->get('PRT_is_percent');
275
+	}
276
+
277
+
278
+	/**
279
+	 * return pretty price dependant on whether its a dollar or percent.
280
+	 *
281
+	 * @since 4.4.0
282
+	 *
283
+	 * @return string
284
+	 */
285
+	public function pretty_price()
286
+	{
287
+		return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%';
288
+	}
289
+
290
+
291
+	/**
292
+	 * @return mixed
293
+	 */
294
+	public function get_price_without_currency_symbol()
295
+	{
296
+		return str_replace(EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty('PRC_amount'));
297
+	}
298 298
 }
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
      */
88 88
     protected function getRegistrationModel()
89 89
     {
90
-        if (! $this->registration_model instanceof EEM_Registration) {
90
+        if ( ! $this->registration_model instanceof EEM_Registration) {
91 91
             $this->registration_model = $this->getLoader()->getShared('EEM_Registration');
92 92
         }
93 93
         return $this->registration_model;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     protected function getAttendeeModel()
104 104
     {
105
-        if (! $this->attendee_model instanceof EEM_Attendee) {
105
+        if ( ! $this->attendee_model instanceof EEM_Attendee) {
106 106
             $this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
107 107
         }
108 108
         return $this->attendee_model;
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
      */
119 119
     protected function getEventModel()
120 120
     {
121
-        if (! $this->event_model instanceof EEM_Event) {
121
+        if ( ! $this->event_model instanceof EEM_Event) {
122 122
             $this->event_model = $this->getLoader()->getShared('EEM_Event');
123 123
         }
124 124
         return $this->event_model;
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      */
134 134
     protected function getStatusModel()
135 135
     {
136
-        if (! $this->status_model instanceof EEM_Status) {
136
+        if ( ! $this->status_model instanceof EEM_Status) {
137 137
             $this->status_model = $this->getLoader()->getShared('EEM_Status');
138 138
         }
139 139
         return $this->status_model;
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
         // when adding a new registration...
146 146
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
147 147
             EE_System::do_not_cache();
148
-            if (! isset($this->_req_data['processing_registration'])
148
+            if ( ! isset($this->_req_data['processing_registration'])
149 149
                 || absint($this->_req_data['processing_registration']) !== 1
150 150
             ) {
151 151
                 // and it's NOT the attendee information reg step
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
         // style
752 752
         wp_register_style(
753 753
             'espresso_reg',
754
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
754
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
755 755
             array('ee-admin-css'),
756 756
             EVENT_ESPRESSO_VERSION
757 757
         );
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
         // script
760 760
         wp_register_script(
761 761
             'espresso_reg',
762
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
762
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
763 763
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
764 764
             EVENT_ESPRESSO_VERSION,
765 765
             true
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
             'att_publish_text' => sprintf(
784 784
                 /* translators: The date and time */
785 785
                 wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
786
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
786
+                '<b>'.$this->_cpt_model_obj->get_datetime('ATT_created').'</b>'
787 787
             ),
788 788
         );
789 789
         wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
         wp_dequeue_style('espresso_reg');
815 815
         wp_register_style(
816 816
             'espresso_att',
817
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
817
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
818 818
             array('ee-admin-css'),
819 819
             EVENT_ESPRESSO_VERSION
820 820
         );
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
     {
827 827
         wp_register_script(
828 828
             'ee-spco-for-admin',
829
-            REG_ASSETS_URL . 'spco_for_admin.js',
829
+            REG_ASSETS_URL.'spco_for_admin.js',
830 830
             array('underscore', 'jquery'),
831 831
             EVENT_ESPRESSO_VERSION,
832 832
             true
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
         }
1069 1069
         $sc_items = array(
1070 1070
             'approved_status'   => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1071
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1072 1072
                 'desc'  => EEH_Template::pretty_status(
1073 1073
                     EEM_Registration::status_id_approved,
1074 1074
                     false,
@@ -1076,7 +1076,7 @@  discard block
 block discarded – undo
1076 1076
                 ),
1077 1077
             ),
1078 1078
             'pending_status'    => array(
1079
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1079
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1080 1080
                 'desc'  => EEH_Template::pretty_status(
1081 1081
                     EEM_Registration::status_id_pending_payment,
1082 1082
                     false,
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
                 ),
1085 1085
             ),
1086 1086
             'wait_list'         => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1087
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1088 1088
                 'desc'  => EEH_Template::pretty_status(
1089 1089
                     EEM_Registration::status_id_wait_list,
1090 1090
                     false,
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
                 ),
1093 1093
             ),
1094 1094
             'incomplete_status' => array(
1095
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1095
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
1096 1096
                 'desc'  => EEH_Template::pretty_status(
1097 1097
                     EEM_Registration::status_id_incomplete,
1098 1098
                     false,
@@ -1100,7 +1100,7 @@  discard block
 block discarded – undo
1100 1100
                 ),
1101 1101
             ),
1102 1102
             'not_approved'      => array(
1103
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1103
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1104 1104
                 'desc'  => EEH_Template::pretty_status(
1105 1105
                     EEM_Registration::status_id_not_approved,
1106 1106
                     false,
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
                 ),
1109 1109
             ),
1110 1110
             'declined_status'   => array(
1111
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1111
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1112 1112
                 'desc'  => EEH_Template::pretty_status(
1113 1113
                     EEM_Registration::status_id_declined,
1114 1114
                     false,
@@ -1116,7 +1116,7 @@  discard block
 block discarded – undo
1116 1116
                 ),
1117 1117
             ),
1118 1118
             'cancelled_status'  => array(
1119
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1119
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1120 1120
                 'desc'  => EEH_Template::pretty_status(
1121 1121
                     EEM_Registration::status_id_cancelled,
1122 1122
                     false,
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
                 $EVT_ID
1180 1180
             )
1181 1181
         ) {
1182
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1182
+            $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1183 1183
                 'new_registration',
1184 1184
                 'add-registrant',
1185 1185
                 array('event_id' => $EVT_ID),
@@ -1205,7 +1205,7 @@  discard block
 block discarded – undo
1205 1205
         if ($this->_registration instanceof EE_Registration) {
1206 1206
             return true;
1207 1207
         }
1208
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1208
+        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1209 1209
         if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1210 1210
             return true;
1211 1211
         }
@@ -1286,7 +1286,7 @@  discard block
 block discarded – undo
1286 1286
         /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1287 1287
         $list_table_query_builder = $this->getLoader()->getNew(
1288 1288
             'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1289
-            [ $request ]
1289
+            [$request]
1290 1290
         );
1291 1291
         return $list_table_query_builder->getQueryParams($per_page, $count);
1292 1292
     }
@@ -1392,7 +1392,7 @@  discard block
 block discarded – undo
1392 1392
                 )
1393 1393
                 : '';
1394 1394
             // grab header
1395
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1395
+            $template_path = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1396 1396
             $this->_template_args['REG_ID'] = $this->_registration->ID();
1397 1397
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1398 1398
                 $template_path,
@@ -1544,7 +1544,7 @@  discard block
 block discarded – undo
1544 1544
                                 EEH_HTML::strong(
1545 1545
                                     $this->_registration->pretty_status(),
1546 1546
                                     '',
1547
-                                    'status-' . $this->_registration->status_ID(),
1547
+                                    'status-'.$this->_registration->status_ID(),
1548 1548
                                     'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1549 1549
                                 )
1550 1550
                             )
@@ -1600,14 +1600,14 @@  discard block
 block discarded – undo
1600 1600
     protected function _get_reg_statuses()
1601 1601
     {
1602 1602
         $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1603
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1603
+        unset($reg_status_array[EEM_Registration::status_id_incomplete]);
1604 1604
         // get current reg status
1605 1605
         $current_status = $this->_registration->status_ID();
1606 1606
         // is registration for free event? This will determine whether to display the pending payment option
1607 1607
         if ($current_status !== EEM_Registration::status_id_pending_payment
1608 1608
             && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1609 1609
         ) {
1610
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1610
+            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1611 1611
         }
1612 1612
         return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1613 1613
     }
@@ -1701,7 +1701,7 @@  discard block
 block discarded – undo
1701 1701
         $success = false;
1702 1702
         // typecast $REG_IDs
1703 1703
         $REG_IDs = (array) $REG_IDs;
1704
-        if (! empty($REG_IDs)) {
1704
+        if ( ! empty($REG_IDs)) {
1705 1705
             $success = true;
1706 1706
             // set default status if none is passed
1707 1707
             $status = $status ? $status : EEM_Registration::status_id_pending_payment;
@@ -1864,7 +1864,7 @@  discard block
 block discarded – undo
1864 1864
             $action,
1865 1865
             $notify
1866 1866
         );
1867
-        $method = $action . '_registration';
1867
+        $method = $action.'_registration';
1868 1868
         if (method_exists($this, $method)) {
1869 1869
             $this->$method($notify);
1870 1870
         }
@@ -2143,7 +2143,7 @@  discard block
 block discarded – undo
2143 2143
         $this->_template_args['REG_ID'] = $this->_registration->ID();
2144 2144
         $this->_template_args['event_id'] = $this->_registration->event_ID();
2145 2145
         $template_path =
2146
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2146
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2147 2147
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2148 2148
     }
2149 2149
 
@@ -2180,7 +2180,7 @@  discard block
 block discarded – undo
2180 2180
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2181 2181
             $this->_template_args['REG_ID'] = $this->_registration->ID();
2182 2182
             $template_path =
2183
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2183
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2184 2184
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2185 2185
         }
2186 2186
     }
@@ -2197,7 +2197,7 @@  discard block
 block discarded – undo
2197 2197
     public function form_before_question_group($output)
2198 2198
     {
2199 2199
         EE_Error::doing_it_wrong(
2200
-            __CLASS__ . '::' . __FUNCTION__,
2200
+            __CLASS__.'::'.__FUNCTION__,
2201 2201
             esc_html__(
2202 2202
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2203 2203
                 'event_espresso'
@@ -2222,7 +2222,7 @@  discard block
 block discarded – undo
2222 2222
     public function form_after_question_group($output)
2223 2223
     {
2224 2224
         EE_Error::doing_it_wrong(
2225
-            __CLASS__ . '::' . __FUNCTION__,
2225
+            __CLASS__.'::'.__FUNCTION__,
2226 2226
             esc_html__(
2227 2227
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2228 2228
                 'event_espresso'
@@ -2260,7 +2260,7 @@  discard block
 block discarded – undo
2260 2260
     public function form_form_field_label_wrap($label)
2261 2261
     {
2262 2262
         EE_Error::doing_it_wrong(
2263
-            __CLASS__ . '::' . __FUNCTION__,
2263
+            __CLASS__.'::'.__FUNCTION__,
2264 2264
             esc_html__(
2265 2265
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2266 2266
                 'event_espresso'
@@ -2270,7 +2270,7 @@  discard block
 block discarded – undo
2270 2270
         return '
2271 2271
 			<tr>
2272 2272
 				<th>
2273
-					' . $label . '
2273
+					' . $label.'
2274 2274
 				</th>';
2275 2275
     }
2276 2276
 
@@ -2286,7 +2286,7 @@  discard block
 block discarded – undo
2286 2286
     public function form_form_field_input__wrap($input)
2287 2287
     {
2288 2288
         EE_Error::doing_it_wrong(
2289
-            __CLASS__ . '::' . __FUNCTION__,
2289
+            __CLASS__.'::'.__FUNCTION__,
2290 2290
             esc_html__(
2291 2291
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2292 2292
                 'event_espresso'
@@ -2295,7 +2295,7 @@  discard block
 block discarded – undo
2295 2295
         );
2296 2296
         return '
2297 2297
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2298
-					' . $input . '
2298
+					' . $input.'
2299 2299
 				</td>
2300 2300
 			</tr>';
2301 2301
     }
@@ -2343,8 +2343,8 @@  discard block
 block discarded – undo
2343 2343
      */
2344 2344
     protected function _get_reg_custom_questions_form($REG_ID)
2345 2345
     {
2346
-        if (! $this->_reg_custom_questions_form) {
2347
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2346
+        if ( ! $this->_reg_custom_questions_form) {
2347
+            require_once(REG_ADMIN.'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2348 2348
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2349 2349
                 $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2350 2350
             );
@@ -2368,7 +2368,7 @@  discard block
 block discarded – undo
2368 2368
      */
2369 2369
     private function _save_reg_custom_questions_form($REG_ID = false)
2370 2370
     {
2371
-        if (! $REG_ID) {
2371
+        if ( ! $REG_ID) {
2372 2372
             EE_Error::add_error(
2373 2373
                 esc_html__(
2374 2374
                     'An error occurred. No registration ID was received.',
@@ -2460,30 +2460,30 @@  discard block
 block discarded – undo
2460 2460
                 $attendee = $registration->attendee()
2461 2461
                     ? $registration->attendee()
2462 2462
                     : $this->getAttendeeModel()->create_default_object();
2463
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2464
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2465
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2466
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2468
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2463
+                $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID();
2464
+                $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();
2465
+                $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();
2466
+                $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();
2467
+                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2468
+                $this->_template_args['attendees'][$att_nmbr]['address'] = implode(
2469 2469
                     ', ',
2470 2470
                     $attendee->full_address_as_array()
2471 2471
                 );
2472
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2472
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2473 2473
                     array(
2474 2474
                         'action' => 'edit_attendee',
2475 2475
                         'post'   => $attendee->ID(),
2476 2476
                     ),
2477 2477
                     REG_ADMIN_URL
2478 2478
                 );
2479
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2479
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj() instanceof EE_Event
2480 2480
                     ? $registration->event_obj()->name()
2481 2481
                     : '';
2482 2482
                 $att_nmbr++;
2483 2483
             }
2484 2484
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2485 2485
         }
2486
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2486
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2487 2487
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2488 2488
     }
2489 2489
 
@@ -2510,11 +2510,11 @@  discard block
 block discarded – undo
2510 2510
         // now let's determine if this is not the primary registration.  If it isn't then we set the
2511 2511
         // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2512 2512
         // primary registration object (that way we know if we need to show create button or not)
2513
-        if (! $this->_registration->is_primary_registrant()) {
2513
+        if ( ! $this->_registration->is_primary_registrant()) {
2514 2514
             $primary_registration = $this->_registration->get_primary_registration();
2515 2515
             $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2516 2516
                 : null;
2517
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2517
+            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2518 2518
                 // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2519 2519
                 // custom attendee object so let's not worry about the primary reg.
2520 2520
                 $primary_registration = null;
@@ -2548,7 +2548,7 @@  discard block
 block discarded – undo
2548 2548
             ) : '';
2549 2549
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2550 2550
         $this->_template_args['att_check'] = $att_check;
2551
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2551
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2552 2552
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2553 2553
     }
2554 2554
 
@@ -2586,7 +2586,7 @@  discard block
 block discarded – undo
2586 2586
         $success = 0;
2587 2587
         $overwrite_msgs = false;
2588 2588
         // Checkboxes
2589
-        if (! is_array($this->_req_data['_REG_ID'])) {
2589
+        if ( ! is_array($this->_req_data['_REG_ID'])) {
2590 2590
             $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2591 2591
         }
2592 2592
         $reg_count = count($this->_req_data['_REG_ID']);
@@ -2595,7 +2595,7 @@  discard block
 block discarded – undo
2595 2595
             /** @var EE_Registration $REG */
2596 2596
             $REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2597 2597
             $payments = $REG->registration_payments();
2598
-            if (! empty($payments)) {
2598
+            if ( ! empty($payments)) {
2599 2599
                 $name = $REG->attendee() instanceof EE_Attendee
2600 2600
                     ? $REG->attendee()->full_name()
2601 2601
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2657,17 +2657,17 @@  discard block
 block discarded – undo
2657 2657
         $REG_MDL = $this->getRegistrationModel();
2658 2658
         $success = 1;
2659 2659
         // Checkboxes
2660
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2660
+        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2661 2661
             // if array has more than one element than success message should be plural
2662 2662
             $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2663 2663
             // cycle thru checkboxes
2664 2664
             foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2665 2665
                 $REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
-                if (! $REG instanceof EE_Registration) {
2666
+                if ( ! $REG instanceof EE_Registration) {
2667 2667
                     continue;
2668 2668
                 }
2669 2669
                 $deleted = $this->_delete_registration($REG);
2670
-                if (! $deleted) {
2670
+                if ( ! $deleted) {
2671 2671
                     $success = 0;
2672 2672
                 }
2673 2673
             }
@@ -2677,7 +2677,7 @@  discard block
 block discarded – undo
2677 2677
             /** @var EE_Registration $REG */
2678 2678
             $REG = $REG_MDL->get_one_by_ID($REG_ID);
2679 2679
             $deleted = $this->_delete_registration($REG);
2680
-            if (! $deleted) {
2680
+            if ( ! $deleted) {
2681 2681
                 $success = 0;
2682 2682
             }
2683 2683
         }
@@ -2715,11 +2715,11 @@  discard block
 block discarded – undo
2715 2715
         $REGS = $TXN->get_many_related('Registration');
2716 2716
         $all_trashed = true;
2717 2717
         foreach ($REGS as $registration) {
2718
-            if (! $registration->get('REG_deleted')) {
2718
+            if ( ! $registration->get('REG_deleted')) {
2719 2719
                 $all_trashed = false;
2720 2720
             }
2721 2721
         }
2722
-        if (! $all_trashed) {
2722
+        if ( ! $all_trashed) {
2723 2723
             EE_Error::add_error(
2724 2724
                 esc_html__(
2725 2725
                     'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
@@ -2782,7 +2782,7 @@  discard block
 block discarded – undo
2782 2782
      */
2783 2783
     public function new_registration()
2784 2784
     {
2785
-        if (! $this->_set_reg_event()) {
2785
+        if ( ! $this->_set_reg_event()) {
2786 2786
             throw new EE_Error(
2787 2787
                 esc_html__(
2788 2788
                     'Unable to continue with registering because there is no Event ID in the request',
@@ -2792,8 +2792,8 @@  discard block
 block discarded – undo
2792 2792
         }
2793 2793
         EE_Registry::instance()->REQ->set_espresso_page(true);
2794 2794
         // gotta start with a clean slate if we're not coming here via ajax
2795
-        if (! defined('DOING_AJAX')
2796
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2795
+        if ( ! defined('DOING_AJAX')
2796
+            && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2797 2797
         ) {
2798 2798
             EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2799 2799
         }
@@ -2826,7 +2826,7 @@  discard block
 block discarded – undo
2826 2826
         }
2827 2827
         // grab header
2828 2828
         $template_path =
2829
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2829
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2830 2830
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2831 2831
             $template_path,
2832 2832
             $this->_template_args,
@@ -2867,7 +2867,7 @@  discard block
 block discarded – undo
2867 2867
                 '</b>'
2868 2868
             );
2869 2869
             return '
2870
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2870
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2871 2871
 	<script >
2872 2872
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2873 2873
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2936,7 +2936,7 @@  discard block
 block discarded – undo
2936 2936
         // we come back to the process_registration_step route.
2937 2937
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2938 2938
         return EEH_Template::display_template(
2939
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2939
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2940 2940
             $template_args,
2941 2941
             true
2942 2942
         );
@@ -2958,8 +2958,8 @@  discard block
 block discarded – undo
2958 2958
         if (is_object($this->_reg_event)) {
2959 2959
             return true;
2960 2960
         }
2961
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2962
-        if (! $EVT_ID) {
2961
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2962
+        if ( ! $EVT_ID) {
2963 2963
             return false;
2964 2964
         }
2965 2965
         $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
@@ -2991,8 +2991,8 @@  discard block
 block discarded – undo
2991 2991
         $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2992 2992
         // if doing ajax then we need to verify the nonce
2993 2993
         if (defined('DOING_AJAX')) {
2994
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
2995
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
2994
+            $nonce = isset($this->_req_data[$this->_req_nonce])
2995
+                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2996 2996
             $this->_verify_nonce($nonce, $this->_req_nonce);
2997 2997
         }
2998 2998
         switch ($step) {
@@ -3028,7 +3028,7 @@  discard block
 block discarded – undo
3028 3028
                 }
3029 3029
                 break;
3030 3030
             case 'questions':
3031
-                if (! isset(
3031
+                if ( ! isset(
3032 3032
                     $this->_req_data['txn_reg_status_change'],
3033 3033
                     $this->_req_data['txn_reg_status_change']['send_notifications']
3034 3034
                 )
@@ -3043,7 +3043,7 @@  discard block
 block discarded – undo
3043 3043
                         $grand_total->save_this_and_descendants_to_txn();
3044 3044
                     }
3045 3045
                 }
3046
-                if (! $transaction instanceof EE_Transaction) {
3046
+                if ( ! $transaction instanceof EE_Transaction) {
3047 3047
                     $query_args = array(
3048 3048
                         'action'                  => 'new_registration',
3049 3049
                         'processing_registration' => 2,
@@ -3065,7 +3065,7 @@  discard block
 block discarded – undo
3065 3065
                     return;
3066 3066
                 }
3067 3067
                 // maybe update status, and make sure to save transaction if not done already
3068
-                if (! $transaction->update_status_based_on_total_paid()) {
3068
+                if ( ! $transaction->update_status_based_on_total_paid()) {
3069 3069
                     $transaction->save();
3070 3070
                 }
3071 3071
                 EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
@@ -3151,7 +3151,7 @@  discard block
 block discarded – undo
3151 3151
     public function get_attendees($per_page, $count = false, $trash = false)
3152 3152
     {
3153 3153
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3154
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3154
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3155 3155
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3156 3156
         switch ($this->_req_data['orderby']) {
3157 3157
             case 'ATT_ID':
@@ -3189,8 +3189,8 @@  discard block
 block discarded – undo
3189 3189
             ? $this->_req_data['perpage']
3190 3190
             : $per_page;
3191 3191
         $_where = array();
3192
-        if (! empty($this->_req_data['s'])) {
3193
-            $sstr = '%' . $this->_req_data['s'] . '%';
3192
+        if ( ! empty($this->_req_data['s'])) {
3193
+            $sstr = '%'.$this->_req_data['s'].'%';
3194 3194
             $_where['OR'] = array(
3195 3195
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3196 3196
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3217,7 +3217,7 @@  discard block
 block discarded – undo
3217 3217
             'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3218 3218
             'limit'         => $limit,
3219 3219
         );
3220
-        if (! $count) {
3220
+        if ( ! $count) {
3221 3221
             $query_args['order_by'] = array($orderby => $sort);
3222 3222
         }
3223 3223
         if ($trash) {
@@ -3265,7 +3265,7 @@  discard block
 block discarded – undo
3265 3265
      */
3266 3266
     public function _registrations_report_base($method_name_for_getting_query_params)
3267 3267
     {
3268
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3268
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3269 3269
             wp_redirect(
3270 3270
                 EE_Admin_Page::add_query_args_and_nonce(
3271 3271
                     array(
@@ -3296,8 +3296,8 @@  discard block
 block discarded – undo
3296 3296
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3297 3297
             );
3298 3298
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3299
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3300
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3299
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3300
+                require_once(EE_CLASSES.'EE_Export.class.php');
3301 3301
                 $EE_Export = EE_Export::instance($this->_req_data);
3302 3302
                 $EE_Export->export();
3303 3303
             }
@@ -3318,8 +3318,8 @@  discard block
 block discarded – undo
3318 3318
 
3319 3319
     public function _contact_list_export()
3320 3320
     {
3321
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3322
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3321
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3322
+            require_once(EE_CLASSES.'EE_Export.class.php');
3323 3323
             $EE_Export = EE_Export::instance($this->_req_data);
3324 3324
             $EE_Export->export_attendees();
3325 3325
         }
@@ -3328,7 +3328,7 @@  discard block
 block discarded – undo
3328 3328
 
3329 3329
     public function _contact_list_report()
3330 3330
     {
3331
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3331
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3332 3332
             wp_redirect(
3333 3333
                 EE_Admin_Page::add_query_args_and_nonce(
3334 3334
                     array(
@@ -3340,8 +3340,8 @@  discard block
 block discarded – undo
3340 3340
                 )
3341 3341
             );
3342 3342
         } else {
3343
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3344
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3343
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3344
+                require_once(EE_CLASSES.'EE_Export.class.php');
3345 3345
                 $EE_Export = EE_Export::instance($this->_req_data);
3346 3346
                 $EE_Export->report_attendees();
3347 3347
             }
@@ -3429,7 +3429,7 @@  discard block
 block discarded – undo
3429 3429
             $updated_fields = array(
3430 3430
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3431 3431
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3432
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3432
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3433 3433
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3434 3434
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3435 3435
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3507,16 +3507,16 @@  discard block
 block discarded – undo
3507 3507
         $this->verify_cpt_object();
3508 3508
         remove_meta_box(
3509 3509
             'postexcerpt',
3510
-            $this->_cpt_routes[ $this->_req_action ],
3510
+            $this->_cpt_routes[$this->_req_action],
3511 3511
             'normal'
3512 3512
         );
3513
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3513
+        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3514 3514
         if (post_type_supports('espresso_attendees', 'excerpt')) {
3515 3515
             add_meta_box(
3516 3516
                 'postexcerpt',
3517 3517
                 esc_html__('Short Biography', 'event_espresso'),
3518 3518
                 'post_excerpt_meta_box',
3519
-                $this->_cpt_routes[ $this->_req_action ],
3519
+                $this->_cpt_routes[$this->_req_action],
3520 3520
                 'normal'
3521 3521
             );
3522 3522
         }
@@ -3525,7 +3525,7 @@  discard block
 block discarded – undo
3525 3525
                 'commentsdiv',
3526 3526
                 esc_html__('Notes on the Contact', 'event_espresso'),
3527 3527
                 'post_comment_meta_box',
3528
-                $this->_cpt_routes[ $this->_req_action ],
3528
+                $this->_cpt_routes[$this->_req_action],
3529 3529
                 'normal',
3530 3530
                 'core'
3531 3531
             );
@@ -3534,7 +3534,7 @@  discard block
 block discarded – undo
3534 3534
             'attendee_contact_info',
3535 3535
             esc_html__('Contact Info', 'event_espresso'),
3536 3536
             array($this, 'attendee_contact_info'),
3537
-            $this->_cpt_routes[ $this->_req_action ],
3537
+            $this->_cpt_routes[$this->_req_action],
3538 3538
             'side',
3539 3539
             'core'
3540 3540
         );
@@ -3542,7 +3542,7 @@  discard block
 block discarded – undo
3542 3542
             'attendee_details_address',
3543 3543
             esc_html__('Address Details', 'event_espresso'),
3544 3544
             array($this, 'attendee_address_details'),
3545
-            $this->_cpt_routes[ $this->_req_action ],
3545
+            $this->_cpt_routes[$this->_req_action],
3546 3546
             'normal',
3547 3547
             'core'
3548 3548
         );
@@ -3550,7 +3550,7 @@  discard block
 block discarded – undo
3550 3550
             'attendee_registrations',
3551 3551
             esc_html__('Registrations for this Contact', 'event_espresso'),
3552 3552
             array($this, 'attendee_registrations_meta_box'),
3553
-            $this->_cpt_routes[ $this->_req_action ],
3553
+            $this->_cpt_routes[$this->_req_action],
3554 3554
             'normal',
3555 3555
             'high'
3556 3556
         );
@@ -3651,7 +3651,7 @@  discard block
 block discarded – undo
3651 3651
             )
3652 3652
         );
3653 3653
         $template =
3654
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3654
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3655 3655
         EEH_Template::display_template($template, $this->_template_args);
3656 3656
     }
3657 3657
 
@@ -3674,7 +3674,7 @@  discard block
 block discarded – undo
3674 3674
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3675 3675
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3676 3676
         $template =
3677
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3677
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3678 3678
         EEH_Template::display_template($template, $this->_template_args);
3679 3679
     }
3680 3680
 
@@ -3689,7 +3689,7 @@  discard block
 block discarded – undo
3689 3689
     public function after_title_form_fields($post)
3690 3690
     {
3691 3691
         if ($post->post_type === 'espresso_attendees') {
3692
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3692
+            $template = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3693 3693
             $template_args['attendee'] = $this->_cpt_model_obj;
3694 3694
             EEH_Template::display_template($template, $template_args);
3695 3695
         }
@@ -3713,14 +3713,14 @@  discard block
 block discarded – undo
3713 3713
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3714 3714
         $success = 1;
3715 3715
         // Checkboxes
3716
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3716
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3717 3717
             // if array has more than one element than success message should be plural
3718 3718
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3719 3719
             // cycle thru checkboxes
3720 3720
             foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3721 3721
                 $updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3722 3722
                     : $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3723
-                if (! $updated) {
3723
+                if ( ! $updated) {
3724 3724
                     $success = 0;
3725 3725
                 }
3726 3726
             }
@@ -3731,7 +3731,7 @@  discard block
 block discarded – undo
3731 3731
             $att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3732 3732
             $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3733 3733
             $updated = $att->save() && $updated;
3734
-            if (! $updated) {
3734
+            if ( ! $updated) {
3735 3735
                 $success = 0;
3736 3736
             }
3737 3737
         }
Please login to merge, or discard this patch.
Indentation   +3690 added lines, -3690 removed lines patch added patch discarded remove patch
@@ -18,2227 +18,2227 @@  discard block
 block discarded – undo
18 18
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
19 19
 {
20 20
 
21
-    /**
22
-     * @var EE_Registration
23
-     */
24
-    private $_registration;
25
-
26
-    /**
27
-     * @var EE_Event
28
-     */
29
-    private $_reg_event;
30
-
31
-    /**
32
-     * @var EE_Session
33
-     */
34
-    private $_session;
35
-
36
-    private static $_reg_status;
37
-
38
-    /**
39
-     * Form for displaying the custom questions for this registration.
40
-     * This gets used a few times throughout the request so its best to cache it
41
-     *
42
-     * @var EE_Registration_Custom_Questions_Form
43
-     */
44
-    protected $_reg_custom_questions_form = null;
45
-
46
-    /**
47
-     * @var EEM_Registration $registration_model
48
-     */
49
-    private $registration_model;
50
-
51
-    /**
52
-     * @var EEM_Attendee $attendee_model
53
-     */
54
-    private $attendee_model;
55
-
56
-    /**
57
-     * @var EEM_Event $event_model
58
-     */
59
-    private $event_model;
60
-
61
-    /**
62
-     * @var EEM_Status $status_model
63
-     */
64
-    private $status_model;
65
-
66
-
67
-    /**
68
-     * @param bool $routing
69
-     * @throws EE_Error
70
-     * @throws InvalidArgumentException
71
-     * @throws InvalidDataTypeException
72
-     * @throws InvalidInterfaceException
73
-     * @throws ReflectionException
74
-     */
75
-    public function __construct($routing = true)
76
-    {
77
-        parent::__construct($routing);
78
-        add_action('wp_loaded', array($this, 'wp_loaded'));
79
-    }
80
-
81
-    /**
82
-     * @return EEM_Registration
83
-     * @throws InvalidArgumentException
84
-     * @throws InvalidDataTypeException
85
-     * @throws InvalidInterfaceException
86
-     * @since 4.10.2.p
87
-     */
88
-    protected function getRegistrationModel()
89
-    {
90
-        if (! $this->registration_model instanceof EEM_Registration) {
91
-            $this->registration_model = $this->getLoader()->getShared('EEM_Registration');
92
-        }
93
-        return $this->registration_model;
94
-    }
95
-
96
-    /**
97
-     * @return EEM_Attendee
98
-     * @throws InvalidArgumentException
99
-     * @throws InvalidDataTypeException
100
-     * @throws InvalidInterfaceException
101
-     * @since 4.10.2.p
102
-     */
103
-    protected function getAttendeeModel()
104
-    {
105
-        if (! $this->attendee_model instanceof EEM_Attendee) {
106
-            $this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
107
-        }
108
-        return $this->attendee_model;
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EEM_Event
114
-     * @throws InvalidArgumentException
115
-     * @throws InvalidDataTypeException
116
-     * @throws InvalidInterfaceException
117
-     * @since 4.10.2.p
118
-     */
119
-    protected function getEventModel()
120
-    {
121
-        if (! $this->event_model instanceof EEM_Event) {
122
-            $this->event_model = $this->getLoader()->getShared('EEM_Event');
123
-        }
124
-        return $this->event_model;
125
-    }
126
-
127
-    /**
128
-     * @return EEM_Status
129
-     * @throws InvalidArgumentException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidInterfaceException
132
-     * @since 4.10.2.p
133
-     */
134
-    protected function getStatusModel()
135
-    {
136
-        if (! $this->status_model instanceof EEM_Status) {
137
-            $this->status_model = $this->getLoader()->getShared('EEM_Status');
138
-        }
139
-        return $this->status_model;
140
-    }
141
-
142
-
143
-    public function wp_loaded()
144
-    {
145
-        // when adding a new registration...
146
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
147
-            EE_System::do_not_cache();
148
-            if (! isset($this->_req_data['processing_registration'])
149
-                || absint($this->_req_data['processing_registration']) !== 1
150
-            ) {
151
-                // and it's NOT the attendee information reg step
152
-                // force cookie expiration by setting time to last week
153
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
154
-                // and update the global
155
-                $_COOKIE['ee_registration_added'] = 0;
156
-            }
157
-        }
158
-    }
159
-
160
-
161
-    protected function _init_page_props()
162
-    {
163
-        $this->page_slug = REG_PG_SLUG;
164
-        $this->_admin_base_url = REG_ADMIN_URL;
165
-        $this->_admin_base_path = REG_ADMIN;
166
-        $this->page_label = esc_html__('Registrations', 'event_espresso');
167
-        $this->_cpt_routes = array(
168
-            'add_new_attendee' => 'espresso_attendees',
169
-            'edit_attendee'    => 'espresso_attendees',
170
-            'insert_attendee'  => 'espresso_attendees',
171
-            'update_attendee'  => 'espresso_attendees',
172
-        );
173
-        $this->_cpt_model_names = array(
174
-            'add_new_attendee' => 'EEM_Attendee',
175
-            'edit_attendee'    => 'EEM_Attendee',
176
-        );
177
-        $this->_cpt_edit_routes = array(
178
-            'espresso_attendees' => 'edit_attendee',
179
-        );
180
-        $this->_pagenow_map = array(
181
-            'add_new_attendee' => 'post-new.php',
182
-            'edit_attendee'    => 'post.php',
183
-            'trash'            => 'post.php',
184
-        );
185
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
186
-        // add filters so that the comment urls don't take users to a confusing 404 page
187
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
188
-    }
189
-
190
-
191
-    public function clear_comment_link($link, $comment, $args)
192
-    {
193
-        // gotta make sure this only happens on this route
194
-        $post_type = get_post_type($comment->comment_post_ID);
195
-        if ($post_type === 'espresso_attendees') {
196
-            return '#commentsdiv';
197
-        }
198
-        return $link;
199
-    }
200
-
201
-
202
-    protected function _ajax_hooks()
203
-    {
204
-        // todo: all hooks for registrations ajax goes in here
205
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
206
-    }
207
-
208
-
209
-    protected function _define_page_props()
210
-    {
211
-        $this->_admin_page_title = $this->page_label;
212
-        $this->_labels = array(
213
-            'buttons'                      => array(
214
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
215
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
216
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
217
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
218
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
219
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
220
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
221
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
222
-            ),
223
-            'publishbox'                   => array(
224
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
225
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
226
-            ),
227
-            'hide_add_button_on_cpt_route' => array(
228
-                'edit_attendee' => true,
229
-            ),
230
-        );
231
-    }
232
-
233
-
234
-    /**
235
-     *        grab url requests and route them
236
-     *
237
-     * @access private
238
-     * @return void
239
-     * @throws EE_Error
240
-     */
241
-    public function _set_page_routes()
242
-    {
243
-        $this->_get_registration_status_array();
244
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
245
-            ? $this->_req_data['_REG_ID'] : 0;
246
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
247
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
248
-            : $reg_id;
249
-        $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
250
-            ? $this->_req_data['ATT_ID'] : 0;
251
-        $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
252
-            ? $this->_req_data['post']
253
-            : $att_id;
254
-        $this->_page_routes = array(
255
-            'default'                             => array(
256
-                'func'       => '_registrations_overview_list_table',
257
-                'capability' => 'ee_read_registrations',
258
-            ),
259
-            'view_registration'                   => array(
260
-                'func'       => '_registration_details',
261
-                'capability' => 'ee_read_registration',
262
-                'obj_id'     => $reg_id,
263
-            ),
264
-            'edit_registration'                   => array(
265
-                'func'               => '_update_attendee_registration_form',
266
-                'noheader'           => true,
267
-                'headers_sent_route' => 'view_registration',
268
-                'capability'         => 'ee_edit_registration',
269
-                'obj_id'             => $reg_id,
270
-                '_REG_ID'            => $reg_id,
271
-            ),
272
-            'trash_registrations'                 => array(
273
-                'func'       => '_trash_or_restore_registrations',
274
-                'args'       => array('trash' => true),
275
-                'noheader'   => true,
276
-                'capability' => 'ee_delete_registrations',
277
-            ),
278
-            'restore_registrations'               => array(
279
-                'func'       => '_trash_or_restore_registrations',
280
-                'args'       => array('trash' => false),
281
-                'noheader'   => true,
282
-                'capability' => 'ee_delete_registrations',
283
-            ),
284
-            'delete_registrations'                => array(
285
-                'func'       => '_delete_registrations',
286
-                'noheader'   => true,
287
-                'capability' => 'ee_delete_registrations',
288
-            ),
289
-            'new_registration'                    => array(
290
-                'func'       => 'new_registration',
291
-                'capability' => 'ee_edit_registrations',
292
-            ),
293
-            'process_reg_step'                    => array(
294
-                'func'       => 'process_reg_step',
295
-                'noheader'   => true,
296
-                'capability' => 'ee_edit_registrations',
297
-            ),
298
-            'redirect_to_txn'                     => array(
299
-                'func'       => 'redirect_to_txn',
300
-                'noheader'   => true,
301
-                'capability' => 'ee_edit_registrations',
302
-            ),
303
-            'change_reg_status'                   => array(
304
-                'func'       => '_change_reg_status',
305
-                'noheader'   => true,
306
-                'capability' => 'ee_edit_registration',
307
-                'obj_id'     => $reg_id,
308
-            ),
309
-            'approve_registration'                => array(
310
-                'func'       => 'approve_registration',
311
-                'noheader'   => true,
312
-                'capability' => 'ee_edit_registration',
313
-                'obj_id'     => $reg_id,
314
-            ),
315
-            'approve_and_notify_registration'     => array(
316
-                'func'       => 'approve_registration',
317
-                'noheader'   => true,
318
-                'args'       => array(true),
319
-                'capability' => 'ee_edit_registration',
320
-                'obj_id'     => $reg_id,
321
-            ),
322
-            'approve_registrations'               => array(
323
-                'func'       => 'bulk_action_on_registrations',
324
-                'noheader'   => true,
325
-                'capability' => 'ee_edit_registrations',
326
-                'args'       => array('approve'),
327
-            ),
328
-            'approve_and_notify_registrations'    => array(
329
-                'func'       => 'bulk_action_on_registrations',
330
-                'noheader'   => true,
331
-                'capability' => 'ee_edit_registrations',
332
-                'args'       => array('approve', true),
333
-            ),
334
-            'decline_registration'                => array(
335
-                'func'       => 'decline_registration',
336
-                'noheader'   => true,
337
-                'capability' => 'ee_edit_registration',
338
-                'obj_id'     => $reg_id,
339
-            ),
340
-            'decline_and_notify_registration'     => array(
341
-                'func'       => 'decline_registration',
342
-                'noheader'   => true,
343
-                'args'       => array(true),
344
-                'capability' => 'ee_edit_registration',
345
-                'obj_id'     => $reg_id,
346
-            ),
347
-            'decline_registrations'               => array(
348
-                'func'       => 'bulk_action_on_registrations',
349
-                'noheader'   => true,
350
-                'capability' => 'ee_edit_registrations',
351
-                'args'       => array('decline'),
352
-            ),
353
-            'decline_and_notify_registrations'    => array(
354
-                'func'       => 'bulk_action_on_registrations',
355
-                'noheader'   => true,
356
-                'capability' => 'ee_edit_registrations',
357
-                'args'       => array('decline', true),
358
-            ),
359
-            'pending_registration'                => array(
360
-                'func'       => 'pending_registration',
361
-                'noheader'   => true,
362
-                'capability' => 'ee_edit_registration',
363
-                'obj_id'     => $reg_id,
364
-            ),
365
-            'pending_and_notify_registration'     => array(
366
-                'func'       => 'pending_registration',
367
-                'noheader'   => true,
368
-                'args'       => array(true),
369
-                'capability' => 'ee_edit_registration',
370
-                'obj_id'     => $reg_id,
371
-            ),
372
-            'pending_registrations'               => array(
373
-                'func'       => 'bulk_action_on_registrations',
374
-                'noheader'   => true,
375
-                'capability' => 'ee_edit_registrations',
376
-                'args'       => array('pending'),
377
-            ),
378
-            'pending_and_notify_registrations'    => array(
379
-                'func'       => 'bulk_action_on_registrations',
380
-                'noheader'   => true,
381
-                'capability' => 'ee_edit_registrations',
382
-                'args'       => array('pending', true),
383
-            ),
384
-            'no_approve_registration'             => array(
385
-                'func'       => 'not_approve_registration',
386
-                'noheader'   => true,
387
-                'capability' => 'ee_edit_registration',
388
-                'obj_id'     => $reg_id,
389
-            ),
390
-            'no_approve_and_notify_registration'  => array(
391
-                'func'       => 'not_approve_registration',
392
-                'noheader'   => true,
393
-                'args'       => array(true),
394
-                'capability' => 'ee_edit_registration',
395
-                'obj_id'     => $reg_id,
396
-            ),
397
-            'no_approve_registrations'            => array(
398
-                'func'       => 'bulk_action_on_registrations',
399
-                'noheader'   => true,
400
-                'capability' => 'ee_edit_registrations',
401
-                'args'       => array('not_approve'),
402
-            ),
403
-            'no_approve_and_notify_registrations' => array(
404
-                'func'       => 'bulk_action_on_registrations',
405
-                'noheader'   => true,
406
-                'capability' => 'ee_edit_registrations',
407
-                'args'       => array('not_approve', true),
408
-            ),
409
-            'cancel_registration'                 => array(
410
-                'func'       => 'cancel_registration',
411
-                'noheader'   => true,
412
-                'capability' => 'ee_edit_registration',
413
-                'obj_id'     => $reg_id,
414
-            ),
415
-            'cancel_and_notify_registration'      => array(
416
-                'func'       => 'cancel_registration',
417
-                'noheader'   => true,
418
-                'args'       => array(true),
419
-                'capability' => 'ee_edit_registration',
420
-                'obj_id'     => $reg_id,
421
-            ),
422
-            'cancel_registrations'                => array(
423
-                'func'       => 'bulk_action_on_registrations',
424
-                'noheader'   => true,
425
-                'capability' => 'ee_edit_registrations',
426
-                'args'       => array('cancel'),
427
-            ),
428
-            'cancel_and_notify_registrations'     => array(
429
-                'func'       => 'bulk_action_on_registrations',
430
-                'noheader'   => true,
431
-                'capability' => 'ee_edit_registrations',
432
-                'args'       => array('cancel', true),
433
-            ),
434
-            'wait_list_registration'              => array(
435
-                'func'       => 'wait_list_registration',
436
-                'noheader'   => true,
437
-                'capability' => 'ee_edit_registration',
438
-                'obj_id'     => $reg_id,
439
-            ),
440
-            'wait_list_and_notify_registration'   => array(
441
-                'func'       => 'wait_list_registration',
442
-                'noheader'   => true,
443
-                'args'       => array(true),
444
-                'capability' => 'ee_edit_registration',
445
-                'obj_id'     => $reg_id,
446
-            ),
447
-            'contact_list'                        => array(
448
-                'func'       => '_attendee_contact_list_table',
449
-                'capability' => 'ee_read_contacts',
450
-            ),
451
-            'add_new_attendee'                    => array(
452
-                'func' => '_create_new_cpt_item',
453
-                'args' => array(
454
-                    'new_attendee' => true,
455
-                    'capability'   => 'ee_edit_contacts',
456
-                ),
457
-            ),
458
-            'edit_attendee'                       => array(
459
-                'func'       => '_edit_cpt_item',
460
-                'capability' => 'ee_edit_contacts',
461
-                'obj_id'     => $att_id,
462
-            ),
463
-            'duplicate_attendee'                  => array(
464
-                'func'       => '_duplicate_attendee',
465
-                'noheader'   => true,
466
-                'capability' => 'ee_edit_contacts',
467
-                'obj_id'     => $att_id,
468
-            ),
469
-            'insert_attendee'                     => array(
470
-                'func'       => '_insert_or_update_attendee',
471
-                'args'       => array(
472
-                    'new_attendee' => true,
473
-                ),
474
-                'noheader'   => true,
475
-                'capability' => 'ee_edit_contacts',
476
-            ),
477
-            'update_attendee'                     => array(
478
-                'func'       => '_insert_or_update_attendee',
479
-                'args'       => array(
480
-                    'new_attendee' => false,
481
-                ),
482
-                'noheader'   => true,
483
-                'capability' => 'ee_edit_contacts',
484
-                'obj_id'     => $att_id,
485
-            ),
486
-            'trash_attendees'                     => array(
487
-                'func'       => '_trash_or_restore_attendees',
488
-                'args'       => array(
489
-                    'trash' => 'true',
490
-                ),
491
-                'noheader'   => true,
492
-                'capability' => 'ee_delete_contacts',
493
-            ),
494
-            'trash_attendee'                      => array(
495
-                'func'       => '_trash_or_restore_attendees',
496
-                'args'       => array(
497
-                    'trash' => true,
498
-                ),
499
-                'noheader'   => true,
500
-                'capability' => 'ee_delete_contacts',
501
-                'obj_id'     => $att_id,
502
-            ),
503
-            'restore_attendees'                   => array(
504
-                'func'       => '_trash_or_restore_attendees',
505
-                'args'       => array(
506
-                    'trash' => false,
507
-                ),
508
-                'noheader'   => true,
509
-                'capability' => 'ee_delete_contacts',
510
-                'obj_id'     => $att_id,
511
-            ),
512
-            'resend_registration'                 => array(
513
-                'func'       => '_resend_registration',
514
-                'noheader'   => true,
515
-                'capability' => 'ee_send_message',
516
-            ),
517
-            'registrations_report'                => array(
518
-                'func'       => '_registrations_report',
519
-                'noheader'   => true,
520
-                'capability' => 'ee_read_registrations',
521
-            ),
522
-            'contact_list_export'                 => array(
523
-                'func'       => '_contact_list_export',
524
-                'noheader'   => true,
525
-                'capability' => 'export',
526
-            ),
527
-            'contact_list_report'                 => array(
528
-                'func'       => '_contact_list_report',
529
-                'noheader'   => true,
530
-                'capability' => 'ee_read_contacts',
531
-            ),
532
-        );
533
-    }
534
-
535
-
536
-    protected function _set_page_config()
537
-    {
538
-        $this->_page_config = array(
539
-            'default'           => array(
540
-                'nav'           => array(
541
-                    'label' => esc_html__('Overview', 'event_espresso'),
542
-                    'order' => 5,
543
-                ),
544
-                'help_tabs'     => array(
545
-                    'registrations_overview_help_tab'                       => array(
546
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
547
-                        'filename' => 'registrations_overview',
548
-                    ),
549
-                    'registrations_overview_table_column_headings_help_tab' => array(
550
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
551
-                        'filename' => 'registrations_overview_table_column_headings',
552
-                    ),
553
-                    'registrations_overview_filters_help_tab'               => array(
554
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
555
-                        'filename' => 'registrations_overview_filters',
556
-                    ),
557
-                    'registrations_overview_views_help_tab'                 => array(
558
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
559
-                        'filename' => 'registrations_overview_views',
560
-                    ),
561
-                    'registrations_regoverview_other_help_tab'              => array(
562
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
563
-                        'filename' => 'registrations_overview_other',
564
-                    ),
565
-                ),
566
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
567
-                'qtips'         => array('Registration_List_Table_Tips'),
568
-                'list_table'    => 'EE_Registrations_List_Table',
569
-                'require_nonce' => false,
570
-            ),
571
-            'view_registration' => array(
572
-                'nav'           => array(
573
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
574
-                    'order'      => 15,
575
-                    'url'        => isset($this->_req_data['_REG_ID'])
576
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
577
-                        : $this->_admin_base_url,
578
-                    'persistent' => false,
579
-                ),
580
-                'help_tabs'     => array(
581
-                    'registrations_details_help_tab'                    => array(
582
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
583
-                        'filename' => 'registrations_details',
584
-                    ),
585
-                    'registrations_details_table_help_tab'              => array(
586
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
587
-                        'filename' => 'registrations_details_table',
588
-                    ),
589
-                    'registrations_details_form_answers_help_tab'       => array(
590
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
591
-                        'filename' => 'registrations_details_form_answers',
592
-                    ),
593
-                    'registrations_details_registrant_details_help_tab' => array(
594
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
595
-                        'filename' => 'registrations_details_registrant_details',
596
-                    ),
597
-                ),
598
-                'help_tour'     => array('Registration_Details_Help_Tour'),
599
-                'metaboxes'     => array_merge(
600
-                    $this->_default_espresso_metaboxes,
601
-                    array('_registration_details_metaboxes')
602
-                ),
603
-                'require_nonce' => false,
604
-            ),
605
-            'new_registration'  => array(
606
-                'nav'           => array(
607
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
608
-                    'url'        => '#',
609
-                    'order'      => 15,
610
-                    'persistent' => false,
611
-                ),
612
-                'metaboxes'     => $this->_default_espresso_metaboxes,
613
-                'labels'        => array(
614
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
615
-                ),
616
-                'require_nonce' => false,
617
-            ),
618
-            'add_new_attendee'  => array(
619
-                'nav'           => array(
620
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
621
-                    'order'      => 15,
622
-                    'persistent' => false,
623
-                ),
624
-                'metaboxes'     => array_merge(
625
-                    $this->_default_espresso_metaboxes,
626
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
627
-                ),
628
-                'require_nonce' => false,
629
-            ),
630
-            'edit_attendee'     => array(
631
-                'nav'           => array(
632
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
633
-                    'order'      => 15,
634
-                    'persistent' => false,
635
-                    'url'        => isset($this->_req_data['ATT_ID'])
636
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
637
-                        : $this->_admin_base_url,
638
-                ),
639
-                'metaboxes'     => array('attendee_editor_metaboxes'),
640
-                'require_nonce' => false,
641
-            ),
642
-            'contact_list'      => array(
643
-                'nav'           => array(
644
-                    'label' => esc_html__('Contact List', 'event_espresso'),
645
-                    'order' => 20,
646
-                ),
647
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
648
-                'help_tabs'     => array(
649
-                    'registrations_contact_list_help_tab'                       => array(
650
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
651
-                        'filename' => 'registrations_contact_list',
652
-                    ),
653
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
654
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
655
-                        'filename' => 'registrations_contact_list_table_column_headings',
656
-                    ),
657
-                    'registrations_contact_list_views_help_tab'                 => array(
658
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
659
-                        'filename' => 'registrations_contact_list_views',
660
-                    ),
661
-                    'registrations_contact_list_other_help_tab'                 => array(
662
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
663
-                        'filename' => 'registrations_contact_list_other',
664
-                    ),
665
-                ),
666
-                'help_tour'     => array('Contact_List_Help_Tour'),
667
-                'metaboxes'     => array(),
668
-                'require_nonce' => false,
669
-            ),
670
-            // override default cpt routes
671
-            'create_new'        => '',
672
-            'edit'              => '',
673
-        );
674
-    }
675
-
676
-
677
-    /**
678
-     * The below methods aren't used by this class currently
679
-     */
680
-    protected function _add_screen_options()
681
-    {
682
-    }
683
-
684
-
685
-    protected function _add_feature_pointers()
686
-    {
687
-    }
688
-
689
-
690
-    public function admin_init()
691
-    {
692
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
693
-            'click "Update Registration Questions" to save your changes',
694
-            'event_espresso'
695
-        );
696
-    }
697
-
698
-
699
-    public function admin_notices()
700
-    {
701
-    }
702
-
703
-
704
-    public function admin_footer_scripts()
705
-    {
706
-    }
707
-
708
-
709
-    /**
710
-     *        get list of registration statuses
711
-     *
712
-     * @access private
713
-     * @return void
714
-     * @throws EE_Error
715
-     */
716
-    private function _get_registration_status_array()
717
-    {
718
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
719
-    }
720
-
721
-
722
-    /**
723
-     * @throws InvalidArgumentException
724
-     * @throws InvalidDataTypeException
725
-     * @throws InvalidInterfaceException
726
-     * @since 4.10.2.p
727
-     */
728
-    protected function _add_screen_options_default()
729
-    {
730
-        $this->_per_page_screen_option();
731
-    }
732
-
733
-
734
-    /**
735
-     * @throws InvalidArgumentException
736
-     * @throws InvalidDataTypeException
737
-     * @throws InvalidInterfaceException
738
-     * @since 4.10.2.p
739
-     */
740
-    protected function _add_screen_options_contact_list()
741
-    {
742
-        $page_title = $this->_admin_page_title;
743
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
744
-        $this->_per_page_screen_option();
745
-        $this->_admin_page_title = $page_title;
746
-    }
747
-
748
-
749
-    public function load_scripts_styles()
750
-    {
751
-        // style
752
-        wp_register_style(
753
-            'espresso_reg',
754
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
755
-            array('ee-admin-css'),
756
-            EVENT_ESPRESSO_VERSION
757
-        );
758
-        wp_enqueue_style('espresso_reg');
759
-        // script
760
-        wp_register_script(
761
-            'espresso_reg',
762
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
763
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
764
-            EVENT_ESPRESSO_VERSION,
765
-            true
766
-        );
767
-        wp_enqueue_script('espresso_reg');
768
-    }
769
-
770
-
771
-    /**
772
-     * @throws EE_Error
773
-     * @throws InvalidArgumentException
774
-     * @throws InvalidDataTypeException
775
-     * @throws InvalidInterfaceException
776
-     * @throws ReflectionException
777
-     * @since 4.10.2.p
778
-     */
779
-    public function load_scripts_styles_edit_attendee()
780
-    {
781
-        // stuff to only show up on our attendee edit details page.
782
-        $attendee_details_translations = array(
783
-            'att_publish_text' => sprintf(
784
-                /* translators: The date and time */
785
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
786
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
787
-            ),
788
-        );
789
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
790
-        wp_enqueue_script('jquery-validate');
791
-    }
792
-
793
-
794
-    /**
795
-     * @throws EE_Error
796
-     * @throws InvalidArgumentException
797
-     * @throws InvalidDataTypeException
798
-     * @throws InvalidInterfaceException
799
-     * @throws ReflectionException
800
-     * @since 4.10.2.p
801
-     */
802
-    public function load_scripts_styles_view_registration()
803
-    {
804
-        // styles
805
-        wp_enqueue_style('espresso-ui-theme');
806
-        // scripts
807
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
808
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
809
-    }
810
-
811
-
812
-    public function load_scripts_styles_contact_list()
813
-    {
814
-        wp_dequeue_style('espresso_reg');
815
-        wp_register_style(
816
-            'espresso_att',
817
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
818
-            array('ee-admin-css'),
819
-            EVENT_ESPRESSO_VERSION
820
-        );
821
-        wp_enqueue_style('espresso_att');
822
-    }
823
-
824
-
825
-    public function load_scripts_styles_new_registration()
826
-    {
827
-        wp_register_script(
828
-            'ee-spco-for-admin',
829
-            REG_ASSETS_URL . 'spco_for_admin.js',
830
-            array('underscore', 'jquery'),
831
-            EVENT_ESPRESSO_VERSION,
832
-            true
833
-        );
834
-        wp_enqueue_script('ee-spco-for-admin');
835
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
836
-        EE_Form_Section_Proper::wp_enqueue_scripts();
837
-        EED_Ticket_Selector::load_tckt_slctr_assets();
838
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
839
-    }
840
-
841
-
842
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
843
-    {
844
-        add_filter('FHEE_load_EE_messages', '__return_true');
845
-    }
846
-
847
-
848
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
849
-    {
850
-        add_filter('FHEE_load_EE_messages', '__return_true');
851
-    }
852
-
853
-
854
-    /**
855
-     * @throws EE_Error
856
-     * @throws InvalidArgumentException
857
-     * @throws InvalidDataTypeException
858
-     * @throws InvalidInterfaceException
859
-     * @throws ReflectionException
860
-     * @since 4.10.2.p
861
-     */
862
-    protected function _set_list_table_views_default()
863
-    {
864
-        // for notification related bulk actions we need to make sure only active messengers have an option.
865
-        EED_Messages::set_autoloaders();
866
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
867
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
868
-        $active_mts = $message_resource_manager->list_of_active_message_types();
869
-        // key= bulk_action_slug, value= message type.
870
-        $match_array = array(
871
-            'approve_registrations'    => 'registration',
872
-            'decline_registrations'    => 'declined_registration',
873
-            'pending_registrations'    => 'pending_approval',
874
-            'no_approve_registrations' => 'not_approved_registration',
875
-            'cancel_registrations'     => 'cancelled_registration',
876
-        );
877
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
878
-            'ee_send_message',
879
-            'batch_send_messages'
880
-        );
881
-        /** setup reg status bulk actions **/
882
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
883
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
884
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
885
-                'Approve and Notify Registrations',
886
-                'event_espresso'
887
-            );
888
-        }
889
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
890
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
891
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
892
-                'Decline and Notify Registrations',
893
-                'event_espresso'
894
-            );
895
-        }
896
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
897
-            'Set Registrations to Pending Payment',
898
-            'event_espresso'
899
-        );
900
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
901
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
902
-                'Set Registrations to Pending Payment and Notify',
903
-                'event_espresso'
904
-            );
905
-        }
906
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
907
-            'Set Registrations to Not Approved',
908
-            'event_espresso'
909
-        );
910
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
911
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
912
-                'Set Registrations to Not Approved and Notify',
913
-                'event_espresso'
914
-            );
915
-        }
916
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
917
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
918
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
919
-                'Cancel Registrations and Notify',
920
-                'event_espresso'
921
-            );
922
-        }
923
-        $def_reg_status_actions = apply_filters(
924
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
925
-            $def_reg_status_actions,
926
-            $active_mts,
927
-            $can_send
928
-        );
929
-
930
-        $this->_views = array(
931
-            'all'   => array(
932
-                'slug'        => 'all',
933
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
934
-                'count'       => 0,
935
-                'bulk_action' => array_merge(
936
-                    $def_reg_status_actions,
937
-                    array(
938
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
939
-                    )
940
-                ),
941
-            ),
942
-            'month' => array(
943
-                'slug'        => 'month',
944
-                'label'       => esc_html__('This Month', 'event_espresso'),
945
-                'count'       => 0,
946
-                'bulk_action' => array_merge(
947
-                    $def_reg_status_actions,
948
-                    array(
949
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
950
-                    )
951
-                ),
952
-            ),
953
-            'today' => array(
954
-                'slug'        => 'today',
955
-                'label'       => sprintf(
956
-                    esc_html__('Today - %s', 'event_espresso'),
957
-                    date('M d, Y', current_time('timestamp'))
958
-                ),
959
-                'count'       => 0,
960
-                'bulk_action' => array_merge(
961
-                    $def_reg_status_actions,
962
-                    array(
963
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
964
-                    )
965
-                ),
966
-            ),
967
-        );
968
-        if (EE_Registry::instance()->CAP->current_user_can(
969
-            'ee_delete_registrations',
970
-            'espresso_registrations_delete_registration'
971
-        )) {
972
-            $this->_views['incomplete'] = array(
973
-                'slug'        => 'incomplete',
974
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
975
-                'count'       => 0,
976
-                'bulk_action' => array(
977
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
978
-                ),
979
-            );
980
-            $this->_views['trash'] = array(
981
-                'slug'        => 'trash',
982
-                'label'       => esc_html__('Trash', 'event_espresso'),
983
-                'count'       => 0,
984
-                'bulk_action' => array(
985
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
986
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
987
-                ),
988
-            );
989
-        }
990
-    }
991
-
992
-
993
-    protected function _set_list_table_views_contact_list()
994
-    {
995
-        $this->_views = array(
996
-            'in_use' => array(
997
-                'slug'        => 'in_use',
998
-                'label'       => esc_html__('In Use', 'event_espresso'),
999
-                'count'       => 0,
1000
-                'bulk_action' => array(
1001
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1002
-                ),
1003
-            ),
1004
-        );
1005
-        if (EE_Registry::instance()->CAP->current_user_can(
1006
-            'ee_delete_contacts',
1007
-            'espresso_registrations_trash_attendees'
1008
-        )
1009
-        ) {
1010
-            $this->_views['trash'] = array(
1011
-                'slug'        => 'trash',
1012
-                'label'       => esc_html__('Trash', 'event_espresso'),
1013
-                'count'       => 0,
1014
-                'bulk_action' => array(
1015
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1016
-                ),
1017
-            );
1018
-        }
1019
-    }
1020
-
1021
-
1022
-    protected function _registration_legend_items()
1023
-    {
1024
-        $fc_items = array(
1025
-            'star-icon'        => array(
1026
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1027
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1028
-            ),
1029
-            'view_details'     => array(
1030
-                'class' => 'dashicons dashicons-clipboard',
1031
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1032
-            ),
1033
-            'edit_attendee'    => array(
1034
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1035
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1036
-            ),
1037
-            'view_transaction' => array(
1038
-                'class' => 'dashicons dashicons-cart',
1039
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1040
-            ),
1041
-            'view_invoice'     => array(
1042
-                'class' => 'dashicons dashicons-media-spreadsheet',
1043
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1044
-            ),
1045
-        );
1046
-        if (EE_Registry::instance()->CAP->current_user_can(
1047
-            'ee_send_message',
1048
-            'espresso_registrations_resend_registration'
1049
-        )) {
1050
-            $fc_items['resend_registration'] = array(
1051
-                'class' => 'dashicons dashicons-email-alt',
1052
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1053
-            );
1054
-        } else {
1055
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
1056
-        }
1057
-        if (EE_Registry::instance()->CAP->current_user_can(
1058
-            'ee_read_global_messages',
1059
-            'view_filtered_messages'
1060
-        )) {
1061
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1062
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1063
-                $fc_items['view_related_messages'] = array(
1064
-                    'class' => $related_for_icon['css_class'],
1065
-                    'desc'  => $related_for_icon['label'],
1066
-                );
1067
-            }
1068
-        }
1069
-        $sc_items = array(
1070
-            'approved_status'   => array(
1071
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1072
-                'desc'  => EEH_Template::pretty_status(
1073
-                    EEM_Registration::status_id_approved,
1074
-                    false,
1075
-                    'sentence'
1076
-                ),
1077
-            ),
1078
-            'pending_status'    => array(
1079
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1080
-                'desc'  => EEH_Template::pretty_status(
1081
-                    EEM_Registration::status_id_pending_payment,
1082
-                    false,
1083
-                    'sentence'
1084
-                ),
1085
-            ),
1086
-            'wait_list'         => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1088
-                'desc'  => EEH_Template::pretty_status(
1089
-                    EEM_Registration::status_id_wait_list,
1090
-                    false,
1091
-                    'sentence'
1092
-                ),
1093
-            ),
1094
-            'incomplete_status' => array(
1095
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1096
-                'desc'  => EEH_Template::pretty_status(
1097
-                    EEM_Registration::status_id_incomplete,
1098
-                    false,
1099
-                    'sentence'
1100
-                ),
1101
-            ),
1102
-            'not_approved'      => array(
1103
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1104
-                'desc'  => EEH_Template::pretty_status(
1105
-                    EEM_Registration::status_id_not_approved,
1106
-                    false,
1107
-                    'sentence'
1108
-                ),
1109
-            ),
1110
-            'declined_status'   => array(
1111
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1112
-                'desc'  => EEH_Template::pretty_status(
1113
-                    EEM_Registration::status_id_declined,
1114
-                    false,
1115
-                    'sentence'
1116
-                ),
1117
-            ),
1118
-            'cancelled_status'  => array(
1119
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1120
-                'desc'  => EEH_Template::pretty_status(
1121
-                    EEM_Registration::status_id_cancelled,
1122
-                    false,
1123
-                    'sentence'
1124
-                ),
1125
-            ),
1126
-        );
1127
-        return array_merge($fc_items, $sc_items);
1128
-    }
1129
-
1130
-
1131
-
1132
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1133
-
1134
-
1135
-
1136
-    /**
1137
-     * @throws DomainException
1138
-     * @throws EE_Error
1139
-     * @throws InvalidArgumentException
1140
-     * @throws InvalidDataTypeException
1141
-     * @throws InvalidInterfaceException
1142
-     * @throws ReflectionException
1143
-     */
1144
-    protected function _registrations_overview_list_table()
1145
-    {
1146
-        $this->appendAddNewRegistrationButtonToPageTitle();
1147
-        $header_text = '';
1148
-        $admin_page_header_decorators = [
1149
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1150
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1151
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1152
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1153
-        ];
1154
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1155
-            $filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1156
-            $header_text = $filter_header_decorator->getHeaderText($header_text);
1157
-        }
1158
-        $this->_template_args['admin_page_header'] = $header_text;
1159
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1160
-        $this->display_admin_list_table_page_with_no_sidebar();
1161
-    }
1162
-
1163
-
1164
-    /**
1165
-     * @throws EE_Error
1166
-     * @throws InvalidArgumentException
1167
-     * @throws InvalidDataTypeException
1168
-     * @throws InvalidInterfaceException
1169
-     */
1170
-    private function appendAddNewRegistrationButtonToPageTitle()
1171
-    {
1172
-        $EVT_ID = ! empty($this->_req_data['event_id'])
1173
-            ? absint($this->_req_data['event_id'])
1174
-            : 0;
1175
-        if ($EVT_ID
1176
-            && EE_Registry::instance()->CAP->current_user_can(
1177
-                'ee_edit_registrations',
1178
-                'espresso_registrations_new_registration',
1179
-                $EVT_ID
1180
-            )
1181
-        ) {
1182
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1183
-                'new_registration',
1184
-                'add-registrant',
1185
-                array('event_id' => $EVT_ID),
1186
-                'add-new-h2'
1187
-            );
1188
-        }
1189
-    }
1190
-
1191
-
1192
-    /**
1193
-     * This sets the _registration property for the registration details screen
1194
-     *
1195
-     * @access private
1196
-     * @return bool
1197
-     * @throws EE_Error
1198
-     * @throws InvalidArgumentException
1199
-     * @throws InvalidDataTypeException
1200
-     * @throws InvalidInterfaceException
1201
-     */
1202
-    private function _set_registration_object()
1203
-    {
1204
-        // get out if we've already set the object
1205
-        if ($this->_registration instanceof EE_Registration) {
1206
-            return true;
1207
-        }
1208
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1209
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1210
-            return true;
1211
-        }
1212
-        $error_msg = sprintf(
1213
-            esc_html__(
1214
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1215
-                'event_espresso'
1216
-            ),
1217
-            $REG_ID
1218
-        );
1219
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1220
-        $this->_registration = null;
1221
-        return false;
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * Used to retrieve registrations for the list table.
1227
-     *
1228
-     * @param int  $per_page
1229
-     * @param bool $count
1230
-     * @param bool $this_month
1231
-     * @param bool $today
1232
-     * @return EE_Registration[]|int
1233
-     * @throws EE_Error
1234
-     * @throws InvalidArgumentException
1235
-     * @throws InvalidDataTypeException
1236
-     * @throws InvalidInterfaceException
1237
-     */
1238
-    public function get_registrations(
1239
-        $per_page = 10,
1240
-        $count = false,
1241
-        $this_month = false,
1242
-        $today = false
1243
-    ) {
1244
-        if ($this_month) {
1245
-            $this->_req_data['status'] = 'month';
1246
-        }
1247
-        if ($today) {
1248
-            $this->_req_data['status'] = 'today';
1249
-        }
1250
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1251
-        /**
1252
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1253
-         *
1254
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1255
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1256
-         *                             or if you have the development copy of EE you can view this at the path:
1257
-         *                             /docs/G--Model-System/model-query-params.md
1258
-         */
1259
-        $query_params['group_by'] = '';
1260
-
1261
-        return $count
1262
-            ? $this->getRegistrationModel()->count($query_params)
1263
-            /** @type EE_Registration[] */
1264
-            : $this->getRegistrationModel()->get_all($query_params);
1265
-    }
1266
-
1267
-
1268
-    /**
1269
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1270
-     * Note: this listens to values on the request for some of the query parameters.
1271
-     *
1272
-     * @param array $request
1273
-     * @param int   $per_page
1274
-     * @param bool  $count
1275
-     * @return array
1276
-     * @throws EE_Error
1277
-     * @throws InvalidArgumentException
1278
-     * @throws InvalidDataTypeException
1279
-     * @throws InvalidInterfaceException
1280
-     */
1281
-    protected function _get_registration_query_parameters(
1282
-        $request = array(),
1283
-        $per_page = 10,
1284
-        $count = false
1285
-    ) {
1286
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1287
-        $list_table_query_builder = $this->getLoader()->getNew(
1288
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1289
-            [ $request ]
1290
-        );
1291
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1292
-    }
1293
-
1294
-
1295
-    public function get_registration_status_array()
1296
-    {
1297
-        return self::$_reg_status;
1298
-    }
1299
-
1300
-
1301
-
1302
-
1303
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1304
-    /**
1305
-     *        generates HTML for the View Registration Details Admin page
1306
-     *
1307
-     * @access protected
1308
-     * @return void
1309
-     * @throws DomainException
1310
-     * @throws EE_Error
1311
-     * @throws InvalidArgumentException
1312
-     * @throws InvalidDataTypeException
1313
-     * @throws InvalidInterfaceException
1314
-     * @throws EntityNotFoundException
1315
-     * @throws ReflectionException
1316
-     */
1317
-    protected function _registration_details()
1318
-    {
1319
-        $this->_template_args = array();
1320
-        $this->_set_registration_object();
1321
-        if (is_object($this->_registration)) {
1322
-            $transaction = $this->_registration->transaction()
1323
-                ? $this->_registration->transaction()
1324
-                : EE_Transaction::new_instance();
1325
-            $this->_session = $transaction->session_data();
1326
-            $event_id = $this->_registration->event_ID();
1327
-            $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1328
-            $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1329
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1330
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1331
-            $this->_template_args['grand_total'] = $transaction->total();
1332
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1333
-            // link back to overview
1334
-            $this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1335
-            $this->_template_args['registration'] = $this->_registration;
1336
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1337
-                array(
1338
-                    'action'   => 'default',
1339
-                    'event_id' => $event_id,
1340
-                ),
1341
-                REG_ADMIN_URL
1342
-            );
1343
-            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
-                array(
1345
-                    'action' => 'default',
1346
-                    'EVT_ID' => $event_id,
1347
-                    'page'   => 'espresso_transactions',
1348
-                ),
1349
-                admin_url('admin.php')
1350
-            );
1351
-            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1352
-                array(
1353
-                    'page'   => 'espresso_events',
1354
-                    'action' => 'edit',
1355
-                    'post'   => $event_id,
1356
-                ),
1357
-                admin_url('admin.php')
1358
-            );
1359
-            // next and previous links
1360
-            $next_reg = $this->_registration->next(
1361
-                null,
1362
-                array(),
1363
-                'REG_ID'
1364
-            );
1365
-            $this->_template_args['next_registration'] = $next_reg
1366
-                ? $this->_next_link(
1367
-                    EE_Admin_Page::add_query_args_and_nonce(
1368
-                        array(
1369
-                            'action'  => 'view_registration',
1370
-                            '_REG_ID' => $next_reg['REG_ID'],
1371
-                        ),
1372
-                        REG_ADMIN_URL
1373
-                    ),
1374
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1375
-                )
1376
-                : '';
1377
-            $previous_reg = $this->_registration->previous(
1378
-                null,
1379
-                array(),
1380
-                'REG_ID'
1381
-            );
1382
-            $this->_template_args['previous_registration'] = $previous_reg
1383
-                ? $this->_previous_link(
1384
-                    EE_Admin_Page::add_query_args_and_nonce(
1385
-                        array(
1386
-                            'action'  => 'view_registration',
1387
-                            '_REG_ID' => $previous_reg['REG_ID'],
1388
-                        ),
1389
-                        REG_ADMIN_URL
1390
-                    ),
1391
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1392
-                )
1393
-                : '';
1394
-            // grab header
1395
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1396
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
1397
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1398
-                $template_path,
1399
-                $this->_template_args,
1400
-                true
1401
-            );
1402
-        } else {
1403
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1404
-        }
1405
-        // the details template wrapper
1406
-        $this->display_admin_page_with_sidebar();
1407
-    }
1408
-
1409
-
1410
-    /**
1411
-     * @throws EE_Error
1412
-     * @throws InvalidArgumentException
1413
-     * @throws InvalidDataTypeException
1414
-     * @throws InvalidInterfaceException
1415
-     * @throws ReflectionException
1416
-     * @since 4.10.2.p
1417
-     */
1418
-    protected function _registration_details_metaboxes()
1419
-    {
1420
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1421
-        $this->_set_registration_object();
1422
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1423
-        add_meta_box(
1424
-            'edit-reg-status-mbox',
1425
-            esc_html__('Registration Status', 'event_espresso'),
1426
-            array($this, 'set_reg_status_buttons_metabox'),
1427
-            $this->wp_page_slug,
1428
-            'normal',
1429
-            'high'
1430
-        );
1431
-        add_meta_box(
1432
-            'edit-reg-details-mbox',
1433
-            esc_html__('Registration Details', 'event_espresso'),
1434
-            array($this, '_reg_details_meta_box'),
1435
-            $this->wp_page_slug,
1436
-            'normal',
1437
-            'high'
1438
-        );
1439
-        if ($attendee instanceof EE_Attendee
1440
-            && EE_Registry::instance()->CAP->current_user_can(
1441
-                'ee_read_registration',
1442
-                'edit-reg-questions-mbox',
1443
-                $this->_registration->ID()
1444
-            )
1445
-        ) {
1446
-            add_meta_box(
1447
-                'edit-reg-questions-mbox',
1448
-                esc_html__('Registration Form Answers', 'event_espresso'),
1449
-                array($this, '_reg_questions_meta_box'),
1450
-                $this->wp_page_slug,
1451
-                'normal',
1452
-                'high'
1453
-            );
1454
-        }
1455
-        add_meta_box(
1456
-            'edit-reg-registrant-mbox',
1457
-            esc_html__('Contact Details', 'event_espresso'),
1458
-            array($this, '_reg_registrant_side_meta_box'),
1459
-            $this->wp_page_slug,
1460
-            'side',
1461
-            'high'
1462
-        );
1463
-        if ($this->_registration->group_size() > 1) {
1464
-            add_meta_box(
1465
-                'edit-reg-attendees-mbox',
1466
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1467
-                array($this, '_reg_attendees_meta_box'),
1468
-                $this->wp_page_slug,
1469
-                'normal',
1470
-                'high'
1471
-            );
1472
-        }
1473
-    }
1474
-
1475
-
1476
-    /**
1477
-     * set_reg_status_buttons_metabox
1478
-     *
1479
-     * @access protected
1480
-     * @return string
1481
-     * @throws EE_Error
1482
-     * @throws EntityNotFoundException
1483
-     * @throws InvalidArgumentException
1484
-     * @throws InvalidDataTypeException
1485
-     * @throws InvalidInterfaceException
1486
-     * @throws ReflectionException
1487
-     */
1488
-    public function set_reg_status_buttons_metabox()
1489
-    {
1490
-        $this->_set_registration_object();
1491
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1492
-        echo $change_reg_status_form->form_open(
1493
-            self::add_query_args_and_nonce(
1494
-                array(
1495
-                    'action' => 'change_reg_status',
1496
-                ),
1497
-                REG_ADMIN_URL
1498
-            )
1499
-        );
1500
-        echo $change_reg_status_form->get_html();
1501
-        echo $change_reg_status_form->form_close();
1502
-    }
1503
-
1504
-
1505
-    /**
1506
-     * @return EE_Form_Section_Proper
1507
-     * @throws EE_Error
1508
-     * @throws InvalidArgumentException
1509
-     * @throws InvalidDataTypeException
1510
-     * @throws InvalidInterfaceException
1511
-     * @throws EntityNotFoundException
1512
-     * @throws ReflectionException
1513
-     */
1514
-    protected function _generate_reg_status_change_form()
1515
-    {
1516
-        $reg_status_change_form_array = array(
1517
-            'name'            => 'reg_status_change_form',
1518
-            'html_id'         => 'reg-status-change-form',
1519
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1520
-            'subsections'     => array(
1521
-                'return'             => new EE_Hidden_Input(
1522
-                    array(
1523
-                        'name'    => 'return',
1524
-                        'default' => 'view_registration',
1525
-                    )
1526
-                ),
1527
-                'REG_ID'             => new EE_Hidden_Input(
1528
-                    array(
1529
-                        'name'    => 'REG_ID',
1530
-                        'default' => $this->_registration->ID(),
1531
-                    )
1532
-                ),
1533
-                'current_status'     => new EE_Form_Section_HTML(
1534
-                    EEH_HTML::table(
1535
-                        EEH_HTML::tr(
1536
-                            EEH_HTML::th(
1537
-                                EEH_HTML::label(
1538
-                                    EEH_HTML::strong(
1539
-                                        esc_html__('Current Registration Status', 'event_espresso')
1540
-                                    )
1541
-                                )
1542
-                            )
1543
-                            . EEH_HTML::td(
1544
-                                EEH_HTML::strong(
1545
-                                    $this->_registration->pretty_status(),
1546
-                                    '',
1547
-                                    'status-' . $this->_registration->status_ID(),
1548
-                                    'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1549
-                                )
1550
-                            )
1551
-                        )
1552
-                    )
1553
-                )
1554
-            )
1555
-        );
1556
-        if (EE_Registry::instance()->CAP->current_user_can(
1557
-            'ee_edit_registration',
1558
-            'toggle_registration_status',
1559
-            $this->_registration->ID()
1560
-        )) {
1561
-            $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1562
-                $this->_get_reg_statuses(),
1563
-                array(
1564
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1565
-                    'default'         => $this->_registration->status_ID(),
1566
-                )
1567
-            );
1568
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1569
-                array(
1570
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1571
-                    'default'         => false,
1572
-                    'html_help_text'  => esc_html__(
1573
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1574
-                        'event_espresso'
1575
-                    )
1576
-                )
1577
-            );
1578
-            $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1579
-                array(
1580
-                    'html_class'      => 'button-primary',
1581
-                    'html_label_text' => '&nbsp;',
1582
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1583
-                )
1584
-            );
1585
-        }
1586
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1587
-    }
1588
-
1589
-
1590
-    /**
1591
-     * Returns an array of all the buttons for the various statuses and switch status actions
1592
-     *
1593
-     * @return array
1594
-     * @throws EE_Error
1595
-     * @throws InvalidArgumentException
1596
-     * @throws InvalidDataTypeException
1597
-     * @throws InvalidInterfaceException
1598
-     * @throws EntityNotFoundException
1599
-     */
1600
-    protected function _get_reg_statuses()
1601
-    {
1602
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1603
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1604
-        // get current reg status
1605
-        $current_status = $this->_registration->status_ID();
1606
-        // is registration for free event? This will determine whether to display the pending payment option
1607
-        if ($current_status !== EEM_Registration::status_id_pending_payment
1608
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1609
-        ) {
1610
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1611
-        }
1612
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1613
-    }
1614
-
1615
-
1616
-    /**
1617
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1618
-     *
1619
-     * @param bool $status REG status given for changing registrations to.
1620
-     * @param bool $notify Whether to send messages notifications or not.
1621
-     * @return array (array with reg_id(s) updated and whether update was successful.
1622
-     * @throws DomainException
1623
-     * @throws EE_Error
1624
-     * @throws EntityNotFoundException
1625
-     * @throws InvalidArgumentException
1626
-     * @throws InvalidDataTypeException
1627
-     * @throws InvalidInterfaceException
1628
-     * @throws ReflectionException
1629
-     * @throws RuntimeException
1630
-     */
1631
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1632
-    {
1633
-        if (isset($this->_req_data['reg_status_change_form'])) {
1634
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1635
-                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1636
-                : array();
1637
-        } else {
1638
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1639
-                ? (array) $this->_req_data['_REG_ID']
1640
-                : array();
1641
-        }
1642
-        // sanitize $REG_IDs
1643
-        $REG_IDs = array_map('absint', $REG_IDs);
1644
-        // and remove empty entries
1645
-        $REG_IDs = array_filter($REG_IDs);
1646
-
1647
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1648
-
1649
-        /**
1650
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1651
-         * Currently this value is used downstream by the _process_resend_registration method.
1652
-         *
1653
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1654
-         * @param bool                     $status           The status registrations were changed to.
1655
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1656
-         * @param Registrations_Admin_Page $admin_page_object
1657
-         */
1658
-        $this->_req_data['_REG_ID'] = apply_filters(
1659
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1660
-            $result['REG_ID'],
1661
-            $status,
1662
-            $result['success'],
1663
-            $this
1664
-        );
1665
-
1666
-        // notify?
1667
-        if ($notify
1668
-            && $result['success']
1669
-            && ! empty($this->_req_data['_REG_ID'])
1670
-            && EE_Registry::instance()->CAP->current_user_can(
1671
-                'ee_send_message',
1672
-                'espresso_registrations_resend_registration'
1673
-            )
1674
-        ) {
1675
-            $this->_process_resend_registration();
1676
-        }
1677
-        return $result;
1678
-    }
1679
-
1680
-
1681
-    /**
1682
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1683
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1684
-     *
1685
-     * @param array  $REG_IDs
1686
-     * @param string $status
1687
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1688
-     *                        slug sent with setting the registration status.
1689
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1690
-     * @throws EE_Error
1691
-     * @throws InvalidArgumentException
1692
-     * @throws InvalidDataTypeException
1693
-     * @throws InvalidInterfaceException
1694
-     * @throws ReflectionException
1695
-     * @throws RuntimeException
1696
-     * @throws EntityNotFoundException
1697
-     * @throws DomainException
1698
-     */
1699
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1700
-    {
1701
-        $success = false;
1702
-        // typecast $REG_IDs
1703
-        $REG_IDs = (array) $REG_IDs;
1704
-        if (! empty($REG_IDs)) {
1705
-            $success = true;
1706
-            // set default status if none is passed
1707
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1708
-            $status_context = $notify
1709
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1710
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1711
-            // loop through REG_ID's and change status
1712
-            foreach ($REG_IDs as $REG_ID) {
1713
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1714
-                if ($registration instanceof EE_Registration) {
1715
-                    $registration->set_status(
1716
-                        $status,
1717
-                        false,
1718
-                        new Context(
1719
-                            $status_context,
1720
-                            esc_html__(
1721
-                                'Manually triggered status change on a Registration Admin Page route.',
1722
-                                'event_espresso'
1723
-                            )
1724
-                        )
1725
-                    );
1726
-                    $result = $registration->save();
1727
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1728
-                    $success = $result !== false ? $success : false;
1729
-                }
1730
-            }
1731
-        }
1732
-
1733
-        // return $success and processed registrations
1734
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1735
-    }
1736
-
1737
-
1738
-    /**
1739
-     * Common logic for setting up success message and redirecting to appropriate route
1740
-     *
1741
-     * @param string $STS_ID status id for the registration changed to
1742
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1743
-     * @return void
1744
-     * @throws DomainException
1745
-     * @throws EE_Error
1746
-     * @throws EntityNotFoundException
1747
-     * @throws InvalidArgumentException
1748
-     * @throws InvalidDataTypeException
1749
-     * @throws InvalidInterfaceException
1750
-     * @throws ReflectionException
1751
-     * @throws RuntimeException
1752
-     */
1753
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1754
-    {
1755
-        $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1756
-            : array('success' => false);
1757
-        $success = isset($result['success']) && $result['success'];
1758
-        // setup success message
1759
-        if ($success) {
1760
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1761
-                $msg = sprintf(
1762
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1763
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1764
-                );
1765
-            } else {
1766
-                $msg = sprintf(
1767
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1768
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1769
-                );
1770
-            }
1771
-            EE_Error::add_success($msg);
1772
-        } else {
1773
-            EE_Error::add_error(
1774
-                esc_html__(
1775
-                    'Something went wrong, and the status was not changed',
1776
-                    'event_espresso'
1777
-                ),
1778
-                __FILE__,
1779
-                __LINE__,
1780
-                __FUNCTION__
1781
-            );
1782
-        }
1783
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] === 'view_registration') {
1784
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1785
-        } else {
1786
-            $route = array('action' => 'default');
1787
-        }
1788
-        $route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1789
-        $this->_redirect_after_action($success, '', '', $route, true);
1790
-    }
1791
-
1792
-
1793
-    /**
1794
-     * incoming reg status change from reg details page.
1795
-     *
1796
-     * @return void
1797
-     * @throws EE_Error
1798
-     * @throws EntityNotFoundException
1799
-     * @throws InvalidArgumentException
1800
-     * @throws InvalidDataTypeException
1801
-     * @throws InvalidInterfaceException
1802
-     * @throws ReflectionException
1803
-     * @throws RuntimeException
1804
-     * @throws DomainException
1805
-     */
1806
-    protected function _change_reg_status()
1807
-    {
1808
-        $this->_req_data['return'] = 'view_registration';
1809
-        // set notify based on whether the send notifications toggle is set or not
1810
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1811
-        // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1812
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1813
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1814
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1815
-            case EEM_Registration::status_id_approved:
1816
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1817
-                $this->approve_registration($notify);
1818
-                break;
1819
-            case EEM_Registration::status_id_pending_payment:
1820
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1821
-                $this->pending_registration($notify);
1822
-                break;
1823
-            case EEM_Registration::status_id_not_approved:
1824
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1825
-                $this->not_approve_registration($notify);
1826
-                break;
1827
-            case EEM_Registration::status_id_declined:
1828
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1829
-                $this->decline_registration($notify);
1830
-                break;
1831
-            case EEM_Registration::status_id_cancelled:
1832
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1833
-                $this->cancel_registration($notify);
1834
-                break;
1835
-            case EEM_Registration::status_id_wait_list:
1836
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1837
-                $this->wait_list_registration($notify);
1838
-                break;
1839
-            case EEM_Registration::status_id_incomplete:
1840
-            default:
1841
-                $result['success'] = false;
1842
-                unset($this->_req_data['return']);
1843
-                $this->_reg_status_change_return('', false);
1844
-                break;
1845
-        }
1846
-    }
1847
-
1848
-
1849
-    /**
1850
-     * Callback for bulk action routes.
1851
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1852
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1853
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1854
-     * when an action is happening on just a single registration).
1855
-     *
1856
-     * @param      $action
1857
-     * @param bool $notify
1858
-     */
1859
-    protected function bulk_action_on_registrations($action, $notify = false)
1860
-    {
1861
-        do_action(
1862
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1863
-            $this,
1864
-            $action,
1865
-            $notify
1866
-        );
1867
-        $method = $action . '_registration';
1868
-        if (method_exists($this, $method)) {
1869
-            $this->$method($notify);
1870
-        }
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     * approve_registration
1876
-     *
1877
-     * @access protected
1878
-     * @param bool $notify whether or not to notify the registrant about their approval.
1879
-     * @return void
1880
-     * @throws EE_Error
1881
-     * @throws EntityNotFoundException
1882
-     * @throws InvalidArgumentException
1883
-     * @throws InvalidDataTypeException
1884
-     * @throws InvalidInterfaceException
1885
-     * @throws ReflectionException
1886
-     * @throws RuntimeException
1887
-     * @throws DomainException
1888
-     */
1889
-    protected function approve_registration($notify = false)
1890
-    {
1891
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1892
-    }
1893
-
1894
-
1895
-    /**
1896
-     *        decline_registration
1897
-     *
1898
-     * @access protected
1899
-     * @param bool $notify whether or not to notify the registrant about their status change.
1900
-     * @return void
1901
-     * @throws EE_Error
1902
-     * @throws EntityNotFoundException
1903
-     * @throws InvalidArgumentException
1904
-     * @throws InvalidDataTypeException
1905
-     * @throws InvalidInterfaceException
1906
-     * @throws ReflectionException
1907
-     * @throws RuntimeException
1908
-     * @throws DomainException
1909
-     */
1910
-    protected function decline_registration($notify = false)
1911
-    {
1912
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1913
-    }
1914
-
1915
-
1916
-    /**
1917
-     *        cancel_registration
1918
-     *
1919
-     * @access protected
1920
-     * @param bool $notify whether or not to notify the registrant about their status change.
1921
-     * @return void
1922
-     * @throws EE_Error
1923
-     * @throws EntityNotFoundException
1924
-     * @throws InvalidArgumentException
1925
-     * @throws InvalidDataTypeException
1926
-     * @throws InvalidInterfaceException
1927
-     * @throws ReflectionException
1928
-     * @throws RuntimeException
1929
-     * @throws DomainException
1930
-     */
1931
-    protected function cancel_registration($notify = false)
1932
-    {
1933
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1934
-    }
1935
-
1936
-
1937
-    /**
1938
-     *        not_approve_registration
1939
-     *
1940
-     * @access protected
1941
-     * @param bool $notify whether or not to notify the registrant about their status change.
1942
-     * @return void
1943
-     * @throws EE_Error
1944
-     * @throws EntityNotFoundException
1945
-     * @throws InvalidArgumentException
1946
-     * @throws InvalidDataTypeException
1947
-     * @throws InvalidInterfaceException
1948
-     * @throws ReflectionException
1949
-     * @throws RuntimeException
1950
-     * @throws DomainException
1951
-     */
1952
-    protected function not_approve_registration($notify = false)
1953
-    {
1954
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1955
-    }
1956
-
1957
-
1958
-    /**
1959
-     *        decline_registration
1960
-     *
1961
-     * @access protected
1962
-     * @param bool $notify whether or not to notify the registrant about their status change.
1963
-     * @return void
1964
-     * @throws EE_Error
1965
-     * @throws EntityNotFoundException
1966
-     * @throws InvalidArgumentException
1967
-     * @throws InvalidDataTypeException
1968
-     * @throws InvalidInterfaceException
1969
-     * @throws ReflectionException
1970
-     * @throws RuntimeException
1971
-     * @throws DomainException
1972
-     */
1973
-    protected function pending_registration($notify = false)
1974
-    {
1975
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1976
-    }
1977
-
1978
-
1979
-    /**
1980
-     * waitlist_registration
1981
-     *
1982
-     * @access protected
1983
-     * @param bool $notify whether or not to notify the registrant about their status change.
1984
-     * @return void
1985
-     * @throws EE_Error
1986
-     * @throws EntityNotFoundException
1987
-     * @throws InvalidArgumentException
1988
-     * @throws InvalidDataTypeException
1989
-     * @throws InvalidInterfaceException
1990
-     * @throws ReflectionException
1991
-     * @throws RuntimeException
1992
-     * @throws DomainException
1993
-     */
1994
-    protected function wait_list_registration($notify = false)
1995
-    {
1996
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
-    }
1998
-
1999
-
2000
-    /**
2001
-     *        generates HTML for the Registration main meta box
2002
-     *
2003
-     * @access public
2004
-     * @return void
2005
-     * @throws DomainException
2006
-     * @throws EE_Error
2007
-     * @throws InvalidArgumentException
2008
-     * @throws InvalidDataTypeException
2009
-     * @throws InvalidInterfaceException
2010
-     * @throws ReflectionException
2011
-     * @throws EntityNotFoundException
2012
-     */
2013
-    public function _reg_details_meta_box()
2014
-    {
2015
-        EEH_Autoloader::register_line_item_display_autoloaders();
2016
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2017
-        EE_Registry::instance()->load_helper('Line_Item');
2018
-        $transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2019
-            : EE_Transaction::new_instance();
2020
-        $this->_session = $transaction->session_data();
2021
-        $filters = new EE_Line_Item_Filter_Collection();
2022
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2023
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
2024
-        $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2025
-            $filters,
2026
-            $transaction->total_line_item()
2027
-        );
2028
-        $filtered_line_item_tree = $line_item_filter_processor->process();
2029
-        $line_item_display = new EE_Line_Item_Display(
2030
-            'reg_admin_table',
2031
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2032
-        );
2033
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2034
-            $filtered_line_item_tree,
2035
-            array('EE_Registration' => $this->_registration)
2036
-        );
2037
-        $attendee = $this->_registration->attendee();
2038
-        if (EE_Registry::instance()->CAP->current_user_can(
2039
-            'ee_read_transaction',
2040
-            'espresso_transactions_view_transaction'
2041
-        )) {
2042
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2043
-                EE_Admin_Page::add_query_args_and_nonce(
2044
-                    array(
2045
-                        'action' => 'view_transaction',
2046
-                        'TXN_ID' => $transaction->ID(),
2047
-                    ),
2048
-                    TXN_ADMIN_URL
2049
-                ),
2050
-                esc_html__(' View Transaction', 'event_espresso'),
2051
-                'button secondary-button right',
2052
-                'dashicons dashicons-cart'
2053
-            );
2054
-        } else {
2055
-            $this->_template_args['view_transaction_button'] = '';
2056
-        }
2057
-        if ($attendee instanceof EE_Attendee
2058
-            && EE_Registry::instance()->CAP->current_user_can(
2059
-                'ee_send_message',
2060
-                'espresso_registrations_resend_registration'
2061
-            )
2062
-        ) {
2063
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2064
-                EE_Admin_Page::add_query_args_and_nonce(
2065
-                    array(
2066
-                        'action'      => 'resend_registration',
2067
-                        '_REG_ID'     => $this->_registration->ID(),
2068
-                        'redirect_to' => 'view_registration',
2069
-                    ),
2070
-                    REG_ADMIN_URL
2071
-                ),
2072
-                esc_html__(' Resend Registration', 'event_espresso'),
2073
-                'button secondary-button right',
2074
-                'dashicons dashicons-email-alt'
2075
-            );
2076
-        } else {
2077
-            $this->_template_args['resend_registration_button'] = '';
2078
-        }
2079
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2080
-        $payment = $transaction->get_first_related('Payment');
2081
-        $payment = ! $payment instanceof EE_Payment
2082
-            ? EE_Payment::new_instance()
2083
-            : $payment;
2084
-        $payment_method = $payment->get_first_related('Payment_Method');
2085
-        $payment_method = ! $payment_method instanceof EE_Payment_Method
2086
-            ? EE_Payment_Method::new_instance()
2087
-            : $payment_method;
2088
-        $reg_details = array(
2089
-            'payment_method'       => $payment_method->name(),
2090
-            'response_msg'         => $payment->gateway_response(),
2091
-            'registration_id'      => $this->_registration->get('REG_code'),
2092
-            'registration_session' => $this->_registration->session_ID(),
2093
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2094
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2095
-        );
2096
-        if (isset($reg_details['registration_id'])) {
2097
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2098
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2099
-                'Registration ID',
2100
-                'event_espresso'
2101
-            );
2102
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2103
-        }
2104
-        if (isset($reg_details['payment_method'])) {
2105
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2106
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2107
-                'Most Recent Payment Method',
2108
-                'event_espresso'
2109
-            );
2110
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2111
-            $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2112
-            $this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2113
-                'Payment method response',
2114
-                'event_espresso'
2115
-            );
2116
-            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2117
-        }
2118
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2119
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2120
-            'Registration Session',
2121
-            'event_espresso'
2122
-        );
2123
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2124
-        $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2125
-        $this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2126
-            'Registration placed from IP',
2127
-            'event_espresso'
2128
-        );
2129
-        $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2130
-        $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2131
-        $this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2132
-            'Registrant User Agent',
2133
-            'event_espresso'
2134
-        );
2135
-        $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2136
-        $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2137
-            array(
2138
-                'action'   => 'default',
2139
-                'event_id' => $this->_registration->event_ID(),
2140
-            ),
2141
-            REG_ADMIN_URL
2142
-        );
2143
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2144
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2145
-        $template_path =
2146
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2147
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2148
-    }
2149
-
2150
-
2151
-    /**
2152
-     * generates HTML for the Registration Questions meta box.
2153
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2154
-     * otherwise uses new forms system
2155
-     *
2156
-     * @access public
2157
-     * @return void
2158
-     * @throws DomainException
2159
-     * @throws EE_Error
2160
-     * @throws InvalidArgumentException
2161
-     * @throws InvalidDataTypeException
2162
-     * @throws InvalidInterfaceException
2163
-     * @throws ReflectionException
2164
-     */
2165
-    public function _reg_questions_meta_box()
2166
-    {
2167
-        // allow someone to override this method entirely
2168
-        if (apply_filters(
2169
-            'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2170
-            true,
2171
-            $this,
2172
-            $this->_registration
2173
-        )) {
2174
-            $form = $this->_get_reg_custom_questions_form(
2175
-                $this->_registration->ID()
2176
-            );
2177
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2178
-                ? $form->get_html_and_js()
2179
-                : '';
2180
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2181
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2182
-            $template_path =
2183
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2184
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2185
-        }
2186
-    }
2187
-
2188
-
2189
-    /**
2190
-     * form_before_question_group
2191
-     *
2192
-     * @deprecated    as of 4.8.32.rc.000
2193
-     * @access        public
2194
-     * @param        string $output
2195
-     * @return        string
2196
-     */
2197
-    public function form_before_question_group($output)
2198
-    {
2199
-        EE_Error::doing_it_wrong(
2200
-            __CLASS__ . '::' . __FUNCTION__,
2201
-            esc_html__(
2202
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2203
-                'event_espresso'
2204
-            ),
2205
-            '4.8.32.rc.000'
2206
-        );
2207
-        return '
21
+	/**
22
+	 * @var EE_Registration
23
+	 */
24
+	private $_registration;
25
+
26
+	/**
27
+	 * @var EE_Event
28
+	 */
29
+	private $_reg_event;
30
+
31
+	/**
32
+	 * @var EE_Session
33
+	 */
34
+	private $_session;
35
+
36
+	private static $_reg_status;
37
+
38
+	/**
39
+	 * Form for displaying the custom questions for this registration.
40
+	 * This gets used a few times throughout the request so its best to cache it
41
+	 *
42
+	 * @var EE_Registration_Custom_Questions_Form
43
+	 */
44
+	protected $_reg_custom_questions_form = null;
45
+
46
+	/**
47
+	 * @var EEM_Registration $registration_model
48
+	 */
49
+	private $registration_model;
50
+
51
+	/**
52
+	 * @var EEM_Attendee $attendee_model
53
+	 */
54
+	private $attendee_model;
55
+
56
+	/**
57
+	 * @var EEM_Event $event_model
58
+	 */
59
+	private $event_model;
60
+
61
+	/**
62
+	 * @var EEM_Status $status_model
63
+	 */
64
+	private $status_model;
65
+
66
+
67
+	/**
68
+	 * @param bool $routing
69
+	 * @throws EE_Error
70
+	 * @throws InvalidArgumentException
71
+	 * @throws InvalidDataTypeException
72
+	 * @throws InvalidInterfaceException
73
+	 * @throws ReflectionException
74
+	 */
75
+	public function __construct($routing = true)
76
+	{
77
+		parent::__construct($routing);
78
+		add_action('wp_loaded', array($this, 'wp_loaded'));
79
+	}
80
+
81
+	/**
82
+	 * @return EEM_Registration
83
+	 * @throws InvalidArgumentException
84
+	 * @throws InvalidDataTypeException
85
+	 * @throws InvalidInterfaceException
86
+	 * @since 4.10.2.p
87
+	 */
88
+	protected function getRegistrationModel()
89
+	{
90
+		if (! $this->registration_model instanceof EEM_Registration) {
91
+			$this->registration_model = $this->getLoader()->getShared('EEM_Registration');
92
+		}
93
+		return $this->registration_model;
94
+	}
95
+
96
+	/**
97
+	 * @return EEM_Attendee
98
+	 * @throws InvalidArgumentException
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws InvalidInterfaceException
101
+	 * @since 4.10.2.p
102
+	 */
103
+	protected function getAttendeeModel()
104
+	{
105
+		if (! $this->attendee_model instanceof EEM_Attendee) {
106
+			$this->attendee_model = $this->getLoader()->getShared('EEM_Attendee');
107
+		}
108
+		return $this->attendee_model;
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EEM_Event
114
+	 * @throws InvalidArgumentException
115
+	 * @throws InvalidDataTypeException
116
+	 * @throws InvalidInterfaceException
117
+	 * @since 4.10.2.p
118
+	 */
119
+	protected function getEventModel()
120
+	{
121
+		if (! $this->event_model instanceof EEM_Event) {
122
+			$this->event_model = $this->getLoader()->getShared('EEM_Event');
123
+		}
124
+		return $this->event_model;
125
+	}
126
+
127
+	/**
128
+	 * @return EEM_Status
129
+	 * @throws InvalidArgumentException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidInterfaceException
132
+	 * @since 4.10.2.p
133
+	 */
134
+	protected function getStatusModel()
135
+	{
136
+		if (! $this->status_model instanceof EEM_Status) {
137
+			$this->status_model = $this->getLoader()->getShared('EEM_Status');
138
+		}
139
+		return $this->status_model;
140
+	}
141
+
142
+
143
+	public function wp_loaded()
144
+	{
145
+		// when adding a new registration...
146
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
147
+			EE_System::do_not_cache();
148
+			if (! isset($this->_req_data['processing_registration'])
149
+				|| absint($this->_req_data['processing_registration']) !== 1
150
+			) {
151
+				// and it's NOT the attendee information reg step
152
+				// force cookie expiration by setting time to last week
153
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
154
+				// and update the global
155
+				$_COOKIE['ee_registration_added'] = 0;
156
+			}
157
+		}
158
+	}
159
+
160
+
161
+	protected function _init_page_props()
162
+	{
163
+		$this->page_slug = REG_PG_SLUG;
164
+		$this->_admin_base_url = REG_ADMIN_URL;
165
+		$this->_admin_base_path = REG_ADMIN;
166
+		$this->page_label = esc_html__('Registrations', 'event_espresso');
167
+		$this->_cpt_routes = array(
168
+			'add_new_attendee' => 'espresso_attendees',
169
+			'edit_attendee'    => 'espresso_attendees',
170
+			'insert_attendee'  => 'espresso_attendees',
171
+			'update_attendee'  => 'espresso_attendees',
172
+		);
173
+		$this->_cpt_model_names = array(
174
+			'add_new_attendee' => 'EEM_Attendee',
175
+			'edit_attendee'    => 'EEM_Attendee',
176
+		);
177
+		$this->_cpt_edit_routes = array(
178
+			'espresso_attendees' => 'edit_attendee',
179
+		);
180
+		$this->_pagenow_map = array(
181
+			'add_new_attendee' => 'post-new.php',
182
+			'edit_attendee'    => 'post.php',
183
+			'trash'            => 'post.php',
184
+		);
185
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
186
+		// add filters so that the comment urls don't take users to a confusing 404 page
187
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
188
+	}
189
+
190
+
191
+	public function clear_comment_link($link, $comment, $args)
192
+	{
193
+		// gotta make sure this only happens on this route
194
+		$post_type = get_post_type($comment->comment_post_ID);
195
+		if ($post_type === 'espresso_attendees') {
196
+			return '#commentsdiv';
197
+		}
198
+		return $link;
199
+	}
200
+
201
+
202
+	protected function _ajax_hooks()
203
+	{
204
+		// todo: all hooks for registrations ajax goes in here
205
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
206
+	}
207
+
208
+
209
+	protected function _define_page_props()
210
+	{
211
+		$this->_admin_page_title = $this->page_label;
212
+		$this->_labels = array(
213
+			'buttons'                      => array(
214
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
215
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
216
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
217
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
218
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
219
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
220
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
221
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
222
+			),
223
+			'publishbox'                   => array(
224
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
225
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
226
+			),
227
+			'hide_add_button_on_cpt_route' => array(
228
+				'edit_attendee' => true,
229
+			),
230
+		);
231
+	}
232
+
233
+
234
+	/**
235
+	 *        grab url requests and route them
236
+	 *
237
+	 * @access private
238
+	 * @return void
239
+	 * @throws EE_Error
240
+	 */
241
+	public function _set_page_routes()
242
+	{
243
+		$this->_get_registration_status_array();
244
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
245
+			? $this->_req_data['_REG_ID'] : 0;
246
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
247
+			? $this->_req_data['reg_status_change_form']['REG_ID']
248
+			: $reg_id;
249
+		$att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
250
+			? $this->_req_data['ATT_ID'] : 0;
251
+		$att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
252
+			? $this->_req_data['post']
253
+			: $att_id;
254
+		$this->_page_routes = array(
255
+			'default'                             => array(
256
+				'func'       => '_registrations_overview_list_table',
257
+				'capability' => 'ee_read_registrations',
258
+			),
259
+			'view_registration'                   => array(
260
+				'func'       => '_registration_details',
261
+				'capability' => 'ee_read_registration',
262
+				'obj_id'     => $reg_id,
263
+			),
264
+			'edit_registration'                   => array(
265
+				'func'               => '_update_attendee_registration_form',
266
+				'noheader'           => true,
267
+				'headers_sent_route' => 'view_registration',
268
+				'capability'         => 'ee_edit_registration',
269
+				'obj_id'             => $reg_id,
270
+				'_REG_ID'            => $reg_id,
271
+			),
272
+			'trash_registrations'                 => array(
273
+				'func'       => '_trash_or_restore_registrations',
274
+				'args'       => array('trash' => true),
275
+				'noheader'   => true,
276
+				'capability' => 'ee_delete_registrations',
277
+			),
278
+			'restore_registrations'               => array(
279
+				'func'       => '_trash_or_restore_registrations',
280
+				'args'       => array('trash' => false),
281
+				'noheader'   => true,
282
+				'capability' => 'ee_delete_registrations',
283
+			),
284
+			'delete_registrations'                => array(
285
+				'func'       => '_delete_registrations',
286
+				'noheader'   => true,
287
+				'capability' => 'ee_delete_registrations',
288
+			),
289
+			'new_registration'                    => array(
290
+				'func'       => 'new_registration',
291
+				'capability' => 'ee_edit_registrations',
292
+			),
293
+			'process_reg_step'                    => array(
294
+				'func'       => 'process_reg_step',
295
+				'noheader'   => true,
296
+				'capability' => 'ee_edit_registrations',
297
+			),
298
+			'redirect_to_txn'                     => array(
299
+				'func'       => 'redirect_to_txn',
300
+				'noheader'   => true,
301
+				'capability' => 'ee_edit_registrations',
302
+			),
303
+			'change_reg_status'                   => array(
304
+				'func'       => '_change_reg_status',
305
+				'noheader'   => true,
306
+				'capability' => 'ee_edit_registration',
307
+				'obj_id'     => $reg_id,
308
+			),
309
+			'approve_registration'                => array(
310
+				'func'       => 'approve_registration',
311
+				'noheader'   => true,
312
+				'capability' => 'ee_edit_registration',
313
+				'obj_id'     => $reg_id,
314
+			),
315
+			'approve_and_notify_registration'     => array(
316
+				'func'       => 'approve_registration',
317
+				'noheader'   => true,
318
+				'args'       => array(true),
319
+				'capability' => 'ee_edit_registration',
320
+				'obj_id'     => $reg_id,
321
+			),
322
+			'approve_registrations'               => array(
323
+				'func'       => 'bulk_action_on_registrations',
324
+				'noheader'   => true,
325
+				'capability' => 'ee_edit_registrations',
326
+				'args'       => array('approve'),
327
+			),
328
+			'approve_and_notify_registrations'    => array(
329
+				'func'       => 'bulk_action_on_registrations',
330
+				'noheader'   => true,
331
+				'capability' => 'ee_edit_registrations',
332
+				'args'       => array('approve', true),
333
+			),
334
+			'decline_registration'                => array(
335
+				'func'       => 'decline_registration',
336
+				'noheader'   => true,
337
+				'capability' => 'ee_edit_registration',
338
+				'obj_id'     => $reg_id,
339
+			),
340
+			'decline_and_notify_registration'     => array(
341
+				'func'       => 'decline_registration',
342
+				'noheader'   => true,
343
+				'args'       => array(true),
344
+				'capability' => 'ee_edit_registration',
345
+				'obj_id'     => $reg_id,
346
+			),
347
+			'decline_registrations'               => array(
348
+				'func'       => 'bulk_action_on_registrations',
349
+				'noheader'   => true,
350
+				'capability' => 'ee_edit_registrations',
351
+				'args'       => array('decline'),
352
+			),
353
+			'decline_and_notify_registrations'    => array(
354
+				'func'       => 'bulk_action_on_registrations',
355
+				'noheader'   => true,
356
+				'capability' => 'ee_edit_registrations',
357
+				'args'       => array('decline', true),
358
+			),
359
+			'pending_registration'                => array(
360
+				'func'       => 'pending_registration',
361
+				'noheader'   => true,
362
+				'capability' => 'ee_edit_registration',
363
+				'obj_id'     => $reg_id,
364
+			),
365
+			'pending_and_notify_registration'     => array(
366
+				'func'       => 'pending_registration',
367
+				'noheader'   => true,
368
+				'args'       => array(true),
369
+				'capability' => 'ee_edit_registration',
370
+				'obj_id'     => $reg_id,
371
+			),
372
+			'pending_registrations'               => array(
373
+				'func'       => 'bulk_action_on_registrations',
374
+				'noheader'   => true,
375
+				'capability' => 'ee_edit_registrations',
376
+				'args'       => array('pending'),
377
+			),
378
+			'pending_and_notify_registrations'    => array(
379
+				'func'       => 'bulk_action_on_registrations',
380
+				'noheader'   => true,
381
+				'capability' => 'ee_edit_registrations',
382
+				'args'       => array('pending', true),
383
+			),
384
+			'no_approve_registration'             => array(
385
+				'func'       => 'not_approve_registration',
386
+				'noheader'   => true,
387
+				'capability' => 'ee_edit_registration',
388
+				'obj_id'     => $reg_id,
389
+			),
390
+			'no_approve_and_notify_registration'  => array(
391
+				'func'       => 'not_approve_registration',
392
+				'noheader'   => true,
393
+				'args'       => array(true),
394
+				'capability' => 'ee_edit_registration',
395
+				'obj_id'     => $reg_id,
396
+			),
397
+			'no_approve_registrations'            => array(
398
+				'func'       => 'bulk_action_on_registrations',
399
+				'noheader'   => true,
400
+				'capability' => 'ee_edit_registrations',
401
+				'args'       => array('not_approve'),
402
+			),
403
+			'no_approve_and_notify_registrations' => array(
404
+				'func'       => 'bulk_action_on_registrations',
405
+				'noheader'   => true,
406
+				'capability' => 'ee_edit_registrations',
407
+				'args'       => array('not_approve', true),
408
+			),
409
+			'cancel_registration'                 => array(
410
+				'func'       => 'cancel_registration',
411
+				'noheader'   => true,
412
+				'capability' => 'ee_edit_registration',
413
+				'obj_id'     => $reg_id,
414
+			),
415
+			'cancel_and_notify_registration'      => array(
416
+				'func'       => 'cancel_registration',
417
+				'noheader'   => true,
418
+				'args'       => array(true),
419
+				'capability' => 'ee_edit_registration',
420
+				'obj_id'     => $reg_id,
421
+			),
422
+			'cancel_registrations'                => array(
423
+				'func'       => 'bulk_action_on_registrations',
424
+				'noheader'   => true,
425
+				'capability' => 'ee_edit_registrations',
426
+				'args'       => array('cancel'),
427
+			),
428
+			'cancel_and_notify_registrations'     => array(
429
+				'func'       => 'bulk_action_on_registrations',
430
+				'noheader'   => true,
431
+				'capability' => 'ee_edit_registrations',
432
+				'args'       => array('cancel', true),
433
+			),
434
+			'wait_list_registration'              => array(
435
+				'func'       => 'wait_list_registration',
436
+				'noheader'   => true,
437
+				'capability' => 'ee_edit_registration',
438
+				'obj_id'     => $reg_id,
439
+			),
440
+			'wait_list_and_notify_registration'   => array(
441
+				'func'       => 'wait_list_registration',
442
+				'noheader'   => true,
443
+				'args'       => array(true),
444
+				'capability' => 'ee_edit_registration',
445
+				'obj_id'     => $reg_id,
446
+			),
447
+			'contact_list'                        => array(
448
+				'func'       => '_attendee_contact_list_table',
449
+				'capability' => 'ee_read_contacts',
450
+			),
451
+			'add_new_attendee'                    => array(
452
+				'func' => '_create_new_cpt_item',
453
+				'args' => array(
454
+					'new_attendee' => true,
455
+					'capability'   => 'ee_edit_contacts',
456
+				),
457
+			),
458
+			'edit_attendee'                       => array(
459
+				'func'       => '_edit_cpt_item',
460
+				'capability' => 'ee_edit_contacts',
461
+				'obj_id'     => $att_id,
462
+			),
463
+			'duplicate_attendee'                  => array(
464
+				'func'       => '_duplicate_attendee',
465
+				'noheader'   => true,
466
+				'capability' => 'ee_edit_contacts',
467
+				'obj_id'     => $att_id,
468
+			),
469
+			'insert_attendee'                     => array(
470
+				'func'       => '_insert_or_update_attendee',
471
+				'args'       => array(
472
+					'new_attendee' => true,
473
+				),
474
+				'noheader'   => true,
475
+				'capability' => 'ee_edit_contacts',
476
+			),
477
+			'update_attendee'                     => array(
478
+				'func'       => '_insert_or_update_attendee',
479
+				'args'       => array(
480
+					'new_attendee' => false,
481
+				),
482
+				'noheader'   => true,
483
+				'capability' => 'ee_edit_contacts',
484
+				'obj_id'     => $att_id,
485
+			),
486
+			'trash_attendees'                     => array(
487
+				'func'       => '_trash_or_restore_attendees',
488
+				'args'       => array(
489
+					'trash' => 'true',
490
+				),
491
+				'noheader'   => true,
492
+				'capability' => 'ee_delete_contacts',
493
+			),
494
+			'trash_attendee'                      => array(
495
+				'func'       => '_trash_or_restore_attendees',
496
+				'args'       => array(
497
+					'trash' => true,
498
+				),
499
+				'noheader'   => true,
500
+				'capability' => 'ee_delete_contacts',
501
+				'obj_id'     => $att_id,
502
+			),
503
+			'restore_attendees'                   => array(
504
+				'func'       => '_trash_or_restore_attendees',
505
+				'args'       => array(
506
+					'trash' => false,
507
+				),
508
+				'noheader'   => true,
509
+				'capability' => 'ee_delete_contacts',
510
+				'obj_id'     => $att_id,
511
+			),
512
+			'resend_registration'                 => array(
513
+				'func'       => '_resend_registration',
514
+				'noheader'   => true,
515
+				'capability' => 'ee_send_message',
516
+			),
517
+			'registrations_report'                => array(
518
+				'func'       => '_registrations_report',
519
+				'noheader'   => true,
520
+				'capability' => 'ee_read_registrations',
521
+			),
522
+			'contact_list_export'                 => array(
523
+				'func'       => '_contact_list_export',
524
+				'noheader'   => true,
525
+				'capability' => 'export',
526
+			),
527
+			'contact_list_report'                 => array(
528
+				'func'       => '_contact_list_report',
529
+				'noheader'   => true,
530
+				'capability' => 'ee_read_contacts',
531
+			),
532
+		);
533
+	}
534
+
535
+
536
+	protected function _set_page_config()
537
+	{
538
+		$this->_page_config = array(
539
+			'default'           => array(
540
+				'nav'           => array(
541
+					'label' => esc_html__('Overview', 'event_espresso'),
542
+					'order' => 5,
543
+				),
544
+				'help_tabs'     => array(
545
+					'registrations_overview_help_tab'                       => array(
546
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
547
+						'filename' => 'registrations_overview',
548
+					),
549
+					'registrations_overview_table_column_headings_help_tab' => array(
550
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
551
+						'filename' => 'registrations_overview_table_column_headings',
552
+					),
553
+					'registrations_overview_filters_help_tab'               => array(
554
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
555
+						'filename' => 'registrations_overview_filters',
556
+					),
557
+					'registrations_overview_views_help_tab'                 => array(
558
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
559
+						'filename' => 'registrations_overview_views',
560
+					),
561
+					'registrations_regoverview_other_help_tab'              => array(
562
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
563
+						'filename' => 'registrations_overview_other',
564
+					),
565
+				),
566
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
567
+				'qtips'         => array('Registration_List_Table_Tips'),
568
+				'list_table'    => 'EE_Registrations_List_Table',
569
+				'require_nonce' => false,
570
+			),
571
+			'view_registration' => array(
572
+				'nav'           => array(
573
+					'label'      => esc_html__('REG Details', 'event_espresso'),
574
+					'order'      => 15,
575
+					'url'        => isset($this->_req_data['_REG_ID'])
576
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
577
+						: $this->_admin_base_url,
578
+					'persistent' => false,
579
+				),
580
+				'help_tabs'     => array(
581
+					'registrations_details_help_tab'                    => array(
582
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
583
+						'filename' => 'registrations_details',
584
+					),
585
+					'registrations_details_table_help_tab'              => array(
586
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
587
+						'filename' => 'registrations_details_table',
588
+					),
589
+					'registrations_details_form_answers_help_tab'       => array(
590
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
591
+						'filename' => 'registrations_details_form_answers',
592
+					),
593
+					'registrations_details_registrant_details_help_tab' => array(
594
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
595
+						'filename' => 'registrations_details_registrant_details',
596
+					),
597
+				),
598
+				'help_tour'     => array('Registration_Details_Help_Tour'),
599
+				'metaboxes'     => array_merge(
600
+					$this->_default_espresso_metaboxes,
601
+					array('_registration_details_metaboxes')
602
+				),
603
+				'require_nonce' => false,
604
+			),
605
+			'new_registration'  => array(
606
+				'nav'           => array(
607
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
608
+					'url'        => '#',
609
+					'order'      => 15,
610
+					'persistent' => false,
611
+				),
612
+				'metaboxes'     => $this->_default_espresso_metaboxes,
613
+				'labels'        => array(
614
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
615
+				),
616
+				'require_nonce' => false,
617
+			),
618
+			'add_new_attendee'  => array(
619
+				'nav'           => array(
620
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
621
+					'order'      => 15,
622
+					'persistent' => false,
623
+				),
624
+				'metaboxes'     => array_merge(
625
+					$this->_default_espresso_metaboxes,
626
+					array('_publish_post_box', 'attendee_editor_metaboxes')
627
+				),
628
+				'require_nonce' => false,
629
+			),
630
+			'edit_attendee'     => array(
631
+				'nav'           => array(
632
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
633
+					'order'      => 15,
634
+					'persistent' => false,
635
+					'url'        => isset($this->_req_data['ATT_ID'])
636
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
637
+						: $this->_admin_base_url,
638
+				),
639
+				'metaboxes'     => array('attendee_editor_metaboxes'),
640
+				'require_nonce' => false,
641
+			),
642
+			'contact_list'      => array(
643
+				'nav'           => array(
644
+					'label' => esc_html__('Contact List', 'event_espresso'),
645
+					'order' => 20,
646
+				),
647
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
648
+				'help_tabs'     => array(
649
+					'registrations_contact_list_help_tab'                       => array(
650
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
651
+						'filename' => 'registrations_contact_list',
652
+					),
653
+					'registrations_contact-list_table_column_headings_help_tab' => array(
654
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
655
+						'filename' => 'registrations_contact_list_table_column_headings',
656
+					),
657
+					'registrations_contact_list_views_help_tab'                 => array(
658
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
659
+						'filename' => 'registrations_contact_list_views',
660
+					),
661
+					'registrations_contact_list_other_help_tab'                 => array(
662
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
663
+						'filename' => 'registrations_contact_list_other',
664
+					),
665
+				),
666
+				'help_tour'     => array('Contact_List_Help_Tour'),
667
+				'metaboxes'     => array(),
668
+				'require_nonce' => false,
669
+			),
670
+			// override default cpt routes
671
+			'create_new'        => '',
672
+			'edit'              => '',
673
+		);
674
+	}
675
+
676
+
677
+	/**
678
+	 * The below methods aren't used by this class currently
679
+	 */
680
+	protected function _add_screen_options()
681
+	{
682
+	}
683
+
684
+
685
+	protected function _add_feature_pointers()
686
+	{
687
+	}
688
+
689
+
690
+	public function admin_init()
691
+	{
692
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
693
+			'click "Update Registration Questions" to save your changes',
694
+			'event_espresso'
695
+		);
696
+	}
697
+
698
+
699
+	public function admin_notices()
700
+	{
701
+	}
702
+
703
+
704
+	public function admin_footer_scripts()
705
+	{
706
+	}
707
+
708
+
709
+	/**
710
+	 *        get list of registration statuses
711
+	 *
712
+	 * @access private
713
+	 * @return void
714
+	 * @throws EE_Error
715
+	 */
716
+	private function _get_registration_status_array()
717
+	{
718
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
719
+	}
720
+
721
+
722
+	/**
723
+	 * @throws InvalidArgumentException
724
+	 * @throws InvalidDataTypeException
725
+	 * @throws InvalidInterfaceException
726
+	 * @since 4.10.2.p
727
+	 */
728
+	protected function _add_screen_options_default()
729
+	{
730
+		$this->_per_page_screen_option();
731
+	}
732
+
733
+
734
+	/**
735
+	 * @throws InvalidArgumentException
736
+	 * @throws InvalidDataTypeException
737
+	 * @throws InvalidInterfaceException
738
+	 * @since 4.10.2.p
739
+	 */
740
+	protected function _add_screen_options_contact_list()
741
+	{
742
+		$page_title = $this->_admin_page_title;
743
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
744
+		$this->_per_page_screen_option();
745
+		$this->_admin_page_title = $page_title;
746
+	}
747
+
748
+
749
+	public function load_scripts_styles()
750
+	{
751
+		// style
752
+		wp_register_style(
753
+			'espresso_reg',
754
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
755
+			array('ee-admin-css'),
756
+			EVENT_ESPRESSO_VERSION
757
+		);
758
+		wp_enqueue_style('espresso_reg');
759
+		// script
760
+		wp_register_script(
761
+			'espresso_reg',
762
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
763
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
764
+			EVENT_ESPRESSO_VERSION,
765
+			true
766
+		);
767
+		wp_enqueue_script('espresso_reg');
768
+	}
769
+
770
+
771
+	/**
772
+	 * @throws EE_Error
773
+	 * @throws InvalidArgumentException
774
+	 * @throws InvalidDataTypeException
775
+	 * @throws InvalidInterfaceException
776
+	 * @throws ReflectionException
777
+	 * @since 4.10.2.p
778
+	 */
779
+	public function load_scripts_styles_edit_attendee()
780
+	{
781
+		// stuff to only show up on our attendee edit details page.
782
+		$attendee_details_translations = array(
783
+			'att_publish_text' => sprintf(
784
+				/* translators: The date and time */
785
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
786
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
787
+			),
788
+		);
789
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
790
+		wp_enqueue_script('jquery-validate');
791
+	}
792
+
793
+
794
+	/**
795
+	 * @throws EE_Error
796
+	 * @throws InvalidArgumentException
797
+	 * @throws InvalidDataTypeException
798
+	 * @throws InvalidInterfaceException
799
+	 * @throws ReflectionException
800
+	 * @since 4.10.2.p
801
+	 */
802
+	public function load_scripts_styles_view_registration()
803
+	{
804
+		// styles
805
+		wp_enqueue_style('espresso-ui-theme');
806
+		// scripts
807
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
808
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
809
+	}
810
+
811
+
812
+	public function load_scripts_styles_contact_list()
813
+	{
814
+		wp_dequeue_style('espresso_reg');
815
+		wp_register_style(
816
+			'espresso_att',
817
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
818
+			array('ee-admin-css'),
819
+			EVENT_ESPRESSO_VERSION
820
+		);
821
+		wp_enqueue_style('espresso_att');
822
+	}
823
+
824
+
825
+	public function load_scripts_styles_new_registration()
826
+	{
827
+		wp_register_script(
828
+			'ee-spco-for-admin',
829
+			REG_ASSETS_URL . 'spco_for_admin.js',
830
+			array('underscore', 'jquery'),
831
+			EVENT_ESPRESSO_VERSION,
832
+			true
833
+		);
834
+		wp_enqueue_script('ee-spco-for-admin');
835
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
836
+		EE_Form_Section_Proper::wp_enqueue_scripts();
837
+		EED_Ticket_Selector::load_tckt_slctr_assets();
838
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
839
+	}
840
+
841
+
842
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
843
+	{
844
+		add_filter('FHEE_load_EE_messages', '__return_true');
845
+	}
846
+
847
+
848
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
849
+	{
850
+		add_filter('FHEE_load_EE_messages', '__return_true');
851
+	}
852
+
853
+
854
+	/**
855
+	 * @throws EE_Error
856
+	 * @throws InvalidArgumentException
857
+	 * @throws InvalidDataTypeException
858
+	 * @throws InvalidInterfaceException
859
+	 * @throws ReflectionException
860
+	 * @since 4.10.2.p
861
+	 */
862
+	protected function _set_list_table_views_default()
863
+	{
864
+		// for notification related bulk actions we need to make sure only active messengers have an option.
865
+		EED_Messages::set_autoloaders();
866
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
867
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
868
+		$active_mts = $message_resource_manager->list_of_active_message_types();
869
+		// key= bulk_action_slug, value= message type.
870
+		$match_array = array(
871
+			'approve_registrations'    => 'registration',
872
+			'decline_registrations'    => 'declined_registration',
873
+			'pending_registrations'    => 'pending_approval',
874
+			'no_approve_registrations' => 'not_approved_registration',
875
+			'cancel_registrations'     => 'cancelled_registration',
876
+		);
877
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
878
+			'ee_send_message',
879
+			'batch_send_messages'
880
+		);
881
+		/** setup reg status bulk actions **/
882
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
883
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
884
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
885
+				'Approve and Notify Registrations',
886
+				'event_espresso'
887
+			);
888
+		}
889
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
890
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
891
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
892
+				'Decline and Notify Registrations',
893
+				'event_espresso'
894
+			);
895
+		}
896
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
897
+			'Set Registrations to Pending Payment',
898
+			'event_espresso'
899
+		);
900
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
901
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
902
+				'Set Registrations to Pending Payment and Notify',
903
+				'event_espresso'
904
+			);
905
+		}
906
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
907
+			'Set Registrations to Not Approved',
908
+			'event_espresso'
909
+		);
910
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
911
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
912
+				'Set Registrations to Not Approved and Notify',
913
+				'event_espresso'
914
+			);
915
+		}
916
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
917
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
918
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
919
+				'Cancel Registrations and Notify',
920
+				'event_espresso'
921
+			);
922
+		}
923
+		$def_reg_status_actions = apply_filters(
924
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
925
+			$def_reg_status_actions,
926
+			$active_mts,
927
+			$can_send
928
+		);
929
+
930
+		$this->_views = array(
931
+			'all'   => array(
932
+				'slug'        => 'all',
933
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
934
+				'count'       => 0,
935
+				'bulk_action' => array_merge(
936
+					$def_reg_status_actions,
937
+					array(
938
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
939
+					)
940
+				),
941
+			),
942
+			'month' => array(
943
+				'slug'        => 'month',
944
+				'label'       => esc_html__('This Month', 'event_espresso'),
945
+				'count'       => 0,
946
+				'bulk_action' => array_merge(
947
+					$def_reg_status_actions,
948
+					array(
949
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
950
+					)
951
+				),
952
+			),
953
+			'today' => array(
954
+				'slug'        => 'today',
955
+				'label'       => sprintf(
956
+					esc_html__('Today - %s', 'event_espresso'),
957
+					date('M d, Y', current_time('timestamp'))
958
+				),
959
+				'count'       => 0,
960
+				'bulk_action' => array_merge(
961
+					$def_reg_status_actions,
962
+					array(
963
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
964
+					)
965
+				),
966
+			),
967
+		);
968
+		if (EE_Registry::instance()->CAP->current_user_can(
969
+			'ee_delete_registrations',
970
+			'espresso_registrations_delete_registration'
971
+		)) {
972
+			$this->_views['incomplete'] = array(
973
+				'slug'        => 'incomplete',
974
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
975
+				'count'       => 0,
976
+				'bulk_action' => array(
977
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
978
+				),
979
+			);
980
+			$this->_views['trash'] = array(
981
+				'slug'        => 'trash',
982
+				'label'       => esc_html__('Trash', 'event_espresso'),
983
+				'count'       => 0,
984
+				'bulk_action' => array(
985
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
986
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
987
+				),
988
+			);
989
+		}
990
+	}
991
+
992
+
993
+	protected function _set_list_table_views_contact_list()
994
+	{
995
+		$this->_views = array(
996
+			'in_use' => array(
997
+				'slug'        => 'in_use',
998
+				'label'       => esc_html__('In Use', 'event_espresso'),
999
+				'count'       => 0,
1000
+				'bulk_action' => array(
1001
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1002
+				),
1003
+			),
1004
+		);
1005
+		if (EE_Registry::instance()->CAP->current_user_can(
1006
+			'ee_delete_contacts',
1007
+			'espresso_registrations_trash_attendees'
1008
+		)
1009
+		) {
1010
+			$this->_views['trash'] = array(
1011
+				'slug'        => 'trash',
1012
+				'label'       => esc_html__('Trash', 'event_espresso'),
1013
+				'count'       => 0,
1014
+				'bulk_action' => array(
1015
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1016
+				),
1017
+			);
1018
+		}
1019
+	}
1020
+
1021
+
1022
+	protected function _registration_legend_items()
1023
+	{
1024
+		$fc_items = array(
1025
+			'star-icon'        => array(
1026
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1027
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1028
+			),
1029
+			'view_details'     => array(
1030
+				'class' => 'dashicons dashicons-clipboard',
1031
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1032
+			),
1033
+			'edit_attendee'    => array(
1034
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
1035
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1036
+			),
1037
+			'view_transaction' => array(
1038
+				'class' => 'dashicons dashicons-cart',
1039
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1040
+			),
1041
+			'view_invoice'     => array(
1042
+				'class' => 'dashicons dashicons-media-spreadsheet',
1043
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1044
+			),
1045
+		);
1046
+		if (EE_Registry::instance()->CAP->current_user_can(
1047
+			'ee_send_message',
1048
+			'espresso_registrations_resend_registration'
1049
+		)) {
1050
+			$fc_items['resend_registration'] = array(
1051
+				'class' => 'dashicons dashicons-email-alt',
1052
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1053
+			);
1054
+		} else {
1055
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
1056
+		}
1057
+		if (EE_Registry::instance()->CAP->current_user_can(
1058
+			'ee_read_global_messages',
1059
+			'view_filtered_messages'
1060
+		)) {
1061
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1062
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1063
+				$fc_items['view_related_messages'] = array(
1064
+					'class' => $related_for_icon['css_class'],
1065
+					'desc'  => $related_for_icon['label'],
1066
+				);
1067
+			}
1068
+		}
1069
+		$sc_items = array(
1070
+			'approved_status'   => array(
1071
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1072
+				'desc'  => EEH_Template::pretty_status(
1073
+					EEM_Registration::status_id_approved,
1074
+					false,
1075
+					'sentence'
1076
+				),
1077
+			),
1078
+			'pending_status'    => array(
1079
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1080
+				'desc'  => EEH_Template::pretty_status(
1081
+					EEM_Registration::status_id_pending_payment,
1082
+					false,
1083
+					'sentence'
1084
+				),
1085
+			),
1086
+			'wait_list'         => array(
1087
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1088
+				'desc'  => EEH_Template::pretty_status(
1089
+					EEM_Registration::status_id_wait_list,
1090
+					false,
1091
+					'sentence'
1092
+				),
1093
+			),
1094
+			'incomplete_status' => array(
1095
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
1096
+				'desc'  => EEH_Template::pretty_status(
1097
+					EEM_Registration::status_id_incomplete,
1098
+					false,
1099
+					'sentence'
1100
+				),
1101
+			),
1102
+			'not_approved'      => array(
1103
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1104
+				'desc'  => EEH_Template::pretty_status(
1105
+					EEM_Registration::status_id_not_approved,
1106
+					false,
1107
+					'sentence'
1108
+				),
1109
+			),
1110
+			'declined_status'   => array(
1111
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1112
+				'desc'  => EEH_Template::pretty_status(
1113
+					EEM_Registration::status_id_declined,
1114
+					false,
1115
+					'sentence'
1116
+				),
1117
+			),
1118
+			'cancelled_status'  => array(
1119
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1120
+				'desc'  => EEH_Template::pretty_status(
1121
+					EEM_Registration::status_id_cancelled,
1122
+					false,
1123
+					'sentence'
1124
+				),
1125
+			),
1126
+		);
1127
+		return array_merge($fc_items, $sc_items);
1128
+	}
1129
+
1130
+
1131
+
1132
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1133
+
1134
+
1135
+
1136
+	/**
1137
+	 * @throws DomainException
1138
+	 * @throws EE_Error
1139
+	 * @throws InvalidArgumentException
1140
+	 * @throws InvalidDataTypeException
1141
+	 * @throws InvalidInterfaceException
1142
+	 * @throws ReflectionException
1143
+	 */
1144
+	protected function _registrations_overview_list_table()
1145
+	{
1146
+		$this->appendAddNewRegistrationButtonToPageTitle();
1147
+		$header_text = '';
1148
+		$admin_page_header_decorators = [
1149
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1150
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1151
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1152
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1153
+		];
1154
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1155
+			$filter_header_decorator = $this->getLoader()->getNew($admin_page_header_decorator);
1156
+			$header_text = $filter_header_decorator->getHeaderText($header_text);
1157
+		}
1158
+		$this->_template_args['admin_page_header'] = $header_text;
1159
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1160
+		$this->display_admin_list_table_page_with_no_sidebar();
1161
+	}
1162
+
1163
+
1164
+	/**
1165
+	 * @throws EE_Error
1166
+	 * @throws InvalidArgumentException
1167
+	 * @throws InvalidDataTypeException
1168
+	 * @throws InvalidInterfaceException
1169
+	 */
1170
+	private function appendAddNewRegistrationButtonToPageTitle()
1171
+	{
1172
+		$EVT_ID = ! empty($this->_req_data['event_id'])
1173
+			? absint($this->_req_data['event_id'])
1174
+			: 0;
1175
+		if ($EVT_ID
1176
+			&& EE_Registry::instance()->CAP->current_user_can(
1177
+				'ee_edit_registrations',
1178
+				'espresso_registrations_new_registration',
1179
+				$EVT_ID
1180
+			)
1181
+		) {
1182
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1183
+				'new_registration',
1184
+				'add-registrant',
1185
+				array('event_id' => $EVT_ID),
1186
+				'add-new-h2'
1187
+			);
1188
+		}
1189
+	}
1190
+
1191
+
1192
+	/**
1193
+	 * This sets the _registration property for the registration details screen
1194
+	 *
1195
+	 * @access private
1196
+	 * @return bool
1197
+	 * @throws EE_Error
1198
+	 * @throws InvalidArgumentException
1199
+	 * @throws InvalidDataTypeException
1200
+	 * @throws InvalidInterfaceException
1201
+	 */
1202
+	private function _set_registration_object()
1203
+	{
1204
+		// get out if we've already set the object
1205
+		if ($this->_registration instanceof EE_Registration) {
1206
+			return true;
1207
+		}
1208
+		$REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1209
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1210
+			return true;
1211
+		}
1212
+		$error_msg = sprintf(
1213
+			esc_html__(
1214
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1215
+				'event_espresso'
1216
+			),
1217
+			$REG_ID
1218
+		);
1219
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1220
+		$this->_registration = null;
1221
+		return false;
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * Used to retrieve registrations for the list table.
1227
+	 *
1228
+	 * @param int  $per_page
1229
+	 * @param bool $count
1230
+	 * @param bool $this_month
1231
+	 * @param bool $today
1232
+	 * @return EE_Registration[]|int
1233
+	 * @throws EE_Error
1234
+	 * @throws InvalidArgumentException
1235
+	 * @throws InvalidDataTypeException
1236
+	 * @throws InvalidInterfaceException
1237
+	 */
1238
+	public function get_registrations(
1239
+		$per_page = 10,
1240
+		$count = false,
1241
+		$this_month = false,
1242
+		$today = false
1243
+	) {
1244
+		if ($this_month) {
1245
+			$this->_req_data['status'] = 'month';
1246
+		}
1247
+		if ($today) {
1248
+			$this->_req_data['status'] = 'today';
1249
+		}
1250
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1251
+		/**
1252
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1253
+		 *
1254
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1255
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1256
+		 *                             or if you have the development copy of EE you can view this at the path:
1257
+		 *                             /docs/G--Model-System/model-query-params.md
1258
+		 */
1259
+		$query_params['group_by'] = '';
1260
+
1261
+		return $count
1262
+			? $this->getRegistrationModel()->count($query_params)
1263
+			/** @type EE_Registration[] */
1264
+			: $this->getRegistrationModel()->get_all($query_params);
1265
+	}
1266
+
1267
+
1268
+	/**
1269
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1270
+	 * Note: this listens to values on the request for some of the query parameters.
1271
+	 *
1272
+	 * @param array $request
1273
+	 * @param int   $per_page
1274
+	 * @param bool  $count
1275
+	 * @return array
1276
+	 * @throws EE_Error
1277
+	 * @throws InvalidArgumentException
1278
+	 * @throws InvalidDataTypeException
1279
+	 * @throws InvalidInterfaceException
1280
+	 */
1281
+	protected function _get_registration_query_parameters(
1282
+		$request = array(),
1283
+		$per_page = 10,
1284
+		$count = false
1285
+	) {
1286
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1287
+		$list_table_query_builder = $this->getLoader()->getNew(
1288
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1289
+			[ $request ]
1290
+		);
1291
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1292
+	}
1293
+
1294
+
1295
+	public function get_registration_status_array()
1296
+	{
1297
+		return self::$_reg_status;
1298
+	}
1299
+
1300
+
1301
+
1302
+
1303
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1304
+	/**
1305
+	 *        generates HTML for the View Registration Details Admin page
1306
+	 *
1307
+	 * @access protected
1308
+	 * @return void
1309
+	 * @throws DomainException
1310
+	 * @throws EE_Error
1311
+	 * @throws InvalidArgumentException
1312
+	 * @throws InvalidDataTypeException
1313
+	 * @throws InvalidInterfaceException
1314
+	 * @throws EntityNotFoundException
1315
+	 * @throws ReflectionException
1316
+	 */
1317
+	protected function _registration_details()
1318
+	{
1319
+		$this->_template_args = array();
1320
+		$this->_set_registration_object();
1321
+		if (is_object($this->_registration)) {
1322
+			$transaction = $this->_registration->transaction()
1323
+				? $this->_registration->transaction()
1324
+				: EE_Transaction::new_instance();
1325
+			$this->_session = $transaction->session_data();
1326
+			$event_id = $this->_registration->event_ID();
1327
+			$this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1328
+			$this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1329
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1330
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1331
+			$this->_template_args['grand_total'] = $transaction->total();
1332
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1333
+			// link back to overview
1334
+			$this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1335
+			$this->_template_args['registration'] = $this->_registration;
1336
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1337
+				array(
1338
+					'action'   => 'default',
1339
+					'event_id' => $event_id,
1340
+				),
1341
+				REG_ADMIN_URL
1342
+			);
1343
+			$this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1344
+				array(
1345
+					'action' => 'default',
1346
+					'EVT_ID' => $event_id,
1347
+					'page'   => 'espresso_transactions',
1348
+				),
1349
+				admin_url('admin.php')
1350
+			);
1351
+			$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1352
+				array(
1353
+					'page'   => 'espresso_events',
1354
+					'action' => 'edit',
1355
+					'post'   => $event_id,
1356
+				),
1357
+				admin_url('admin.php')
1358
+			);
1359
+			// next and previous links
1360
+			$next_reg = $this->_registration->next(
1361
+				null,
1362
+				array(),
1363
+				'REG_ID'
1364
+			);
1365
+			$this->_template_args['next_registration'] = $next_reg
1366
+				? $this->_next_link(
1367
+					EE_Admin_Page::add_query_args_and_nonce(
1368
+						array(
1369
+							'action'  => 'view_registration',
1370
+							'_REG_ID' => $next_reg['REG_ID'],
1371
+						),
1372
+						REG_ADMIN_URL
1373
+					),
1374
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1375
+				)
1376
+				: '';
1377
+			$previous_reg = $this->_registration->previous(
1378
+				null,
1379
+				array(),
1380
+				'REG_ID'
1381
+			);
1382
+			$this->_template_args['previous_registration'] = $previous_reg
1383
+				? $this->_previous_link(
1384
+					EE_Admin_Page::add_query_args_and_nonce(
1385
+						array(
1386
+							'action'  => 'view_registration',
1387
+							'_REG_ID' => $previous_reg['REG_ID'],
1388
+						),
1389
+						REG_ADMIN_URL
1390
+					),
1391
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1392
+				)
1393
+				: '';
1394
+			// grab header
1395
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1396
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
1397
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1398
+				$template_path,
1399
+				$this->_template_args,
1400
+				true
1401
+			);
1402
+		} else {
1403
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1404
+		}
1405
+		// the details template wrapper
1406
+		$this->display_admin_page_with_sidebar();
1407
+	}
1408
+
1409
+
1410
+	/**
1411
+	 * @throws EE_Error
1412
+	 * @throws InvalidArgumentException
1413
+	 * @throws InvalidDataTypeException
1414
+	 * @throws InvalidInterfaceException
1415
+	 * @throws ReflectionException
1416
+	 * @since 4.10.2.p
1417
+	 */
1418
+	protected function _registration_details_metaboxes()
1419
+	{
1420
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1421
+		$this->_set_registration_object();
1422
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1423
+		add_meta_box(
1424
+			'edit-reg-status-mbox',
1425
+			esc_html__('Registration Status', 'event_espresso'),
1426
+			array($this, 'set_reg_status_buttons_metabox'),
1427
+			$this->wp_page_slug,
1428
+			'normal',
1429
+			'high'
1430
+		);
1431
+		add_meta_box(
1432
+			'edit-reg-details-mbox',
1433
+			esc_html__('Registration Details', 'event_espresso'),
1434
+			array($this, '_reg_details_meta_box'),
1435
+			$this->wp_page_slug,
1436
+			'normal',
1437
+			'high'
1438
+		);
1439
+		if ($attendee instanceof EE_Attendee
1440
+			&& EE_Registry::instance()->CAP->current_user_can(
1441
+				'ee_read_registration',
1442
+				'edit-reg-questions-mbox',
1443
+				$this->_registration->ID()
1444
+			)
1445
+		) {
1446
+			add_meta_box(
1447
+				'edit-reg-questions-mbox',
1448
+				esc_html__('Registration Form Answers', 'event_espresso'),
1449
+				array($this, '_reg_questions_meta_box'),
1450
+				$this->wp_page_slug,
1451
+				'normal',
1452
+				'high'
1453
+			);
1454
+		}
1455
+		add_meta_box(
1456
+			'edit-reg-registrant-mbox',
1457
+			esc_html__('Contact Details', 'event_espresso'),
1458
+			array($this, '_reg_registrant_side_meta_box'),
1459
+			$this->wp_page_slug,
1460
+			'side',
1461
+			'high'
1462
+		);
1463
+		if ($this->_registration->group_size() > 1) {
1464
+			add_meta_box(
1465
+				'edit-reg-attendees-mbox',
1466
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1467
+				array($this, '_reg_attendees_meta_box'),
1468
+				$this->wp_page_slug,
1469
+				'normal',
1470
+				'high'
1471
+			);
1472
+		}
1473
+	}
1474
+
1475
+
1476
+	/**
1477
+	 * set_reg_status_buttons_metabox
1478
+	 *
1479
+	 * @access protected
1480
+	 * @return string
1481
+	 * @throws EE_Error
1482
+	 * @throws EntityNotFoundException
1483
+	 * @throws InvalidArgumentException
1484
+	 * @throws InvalidDataTypeException
1485
+	 * @throws InvalidInterfaceException
1486
+	 * @throws ReflectionException
1487
+	 */
1488
+	public function set_reg_status_buttons_metabox()
1489
+	{
1490
+		$this->_set_registration_object();
1491
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1492
+		echo $change_reg_status_form->form_open(
1493
+			self::add_query_args_and_nonce(
1494
+				array(
1495
+					'action' => 'change_reg_status',
1496
+				),
1497
+				REG_ADMIN_URL
1498
+			)
1499
+		);
1500
+		echo $change_reg_status_form->get_html();
1501
+		echo $change_reg_status_form->form_close();
1502
+	}
1503
+
1504
+
1505
+	/**
1506
+	 * @return EE_Form_Section_Proper
1507
+	 * @throws EE_Error
1508
+	 * @throws InvalidArgumentException
1509
+	 * @throws InvalidDataTypeException
1510
+	 * @throws InvalidInterfaceException
1511
+	 * @throws EntityNotFoundException
1512
+	 * @throws ReflectionException
1513
+	 */
1514
+	protected function _generate_reg_status_change_form()
1515
+	{
1516
+		$reg_status_change_form_array = array(
1517
+			'name'            => 'reg_status_change_form',
1518
+			'html_id'         => 'reg-status-change-form',
1519
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1520
+			'subsections'     => array(
1521
+				'return'             => new EE_Hidden_Input(
1522
+					array(
1523
+						'name'    => 'return',
1524
+						'default' => 'view_registration',
1525
+					)
1526
+				),
1527
+				'REG_ID'             => new EE_Hidden_Input(
1528
+					array(
1529
+						'name'    => 'REG_ID',
1530
+						'default' => $this->_registration->ID(),
1531
+					)
1532
+				),
1533
+				'current_status'     => new EE_Form_Section_HTML(
1534
+					EEH_HTML::table(
1535
+						EEH_HTML::tr(
1536
+							EEH_HTML::th(
1537
+								EEH_HTML::label(
1538
+									EEH_HTML::strong(
1539
+										esc_html__('Current Registration Status', 'event_espresso')
1540
+									)
1541
+								)
1542
+							)
1543
+							. EEH_HTML::td(
1544
+								EEH_HTML::strong(
1545
+									$this->_registration->pretty_status(),
1546
+									'',
1547
+									'status-' . $this->_registration->status_ID(),
1548
+									'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1549
+								)
1550
+							)
1551
+						)
1552
+					)
1553
+				)
1554
+			)
1555
+		);
1556
+		if (EE_Registry::instance()->CAP->current_user_can(
1557
+			'ee_edit_registration',
1558
+			'toggle_registration_status',
1559
+			$this->_registration->ID()
1560
+		)) {
1561
+			$reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1562
+				$this->_get_reg_statuses(),
1563
+				array(
1564
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1565
+					'default'         => $this->_registration->status_ID(),
1566
+				)
1567
+			);
1568
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1569
+				array(
1570
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1571
+					'default'         => false,
1572
+					'html_help_text'  => esc_html__(
1573
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1574
+						'event_espresso'
1575
+					)
1576
+				)
1577
+			);
1578
+			$reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1579
+				array(
1580
+					'html_class'      => 'button-primary',
1581
+					'html_label_text' => '&nbsp;',
1582
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1583
+				)
1584
+			);
1585
+		}
1586
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1587
+	}
1588
+
1589
+
1590
+	/**
1591
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1592
+	 *
1593
+	 * @return array
1594
+	 * @throws EE_Error
1595
+	 * @throws InvalidArgumentException
1596
+	 * @throws InvalidDataTypeException
1597
+	 * @throws InvalidInterfaceException
1598
+	 * @throws EntityNotFoundException
1599
+	 */
1600
+	protected function _get_reg_statuses()
1601
+	{
1602
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1603
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1604
+		// get current reg status
1605
+		$current_status = $this->_registration->status_ID();
1606
+		// is registration for free event? This will determine whether to display the pending payment option
1607
+		if ($current_status !== EEM_Registration::status_id_pending_payment
1608
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1609
+		) {
1610
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1611
+		}
1612
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1613
+	}
1614
+
1615
+
1616
+	/**
1617
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1618
+	 *
1619
+	 * @param bool $status REG status given for changing registrations to.
1620
+	 * @param bool $notify Whether to send messages notifications or not.
1621
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1622
+	 * @throws DomainException
1623
+	 * @throws EE_Error
1624
+	 * @throws EntityNotFoundException
1625
+	 * @throws InvalidArgumentException
1626
+	 * @throws InvalidDataTypeException
1627
+	 * @throws InvalidInterfaceException
1628
+	 * @throws ReflectionException
1629
+	 * @throws RuntimeException
1630
+	 */
1631
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1632
+	{
1633
+		if (isset($this->_req_data['reg_status_change_form'])) {
1634
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1635
+				? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1636
+				: array();
1637
+		} else {
1638
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1639
+				? (array) $this->_req_data['_REG_ID']
1640
+				: array();
1641
+		}
1642
+		// sanitize $REG_IDs
1643
+		$REG_IDs = array_map('absint', $REG_IDs);
1644
+		// and remove empty entries
1645
+		$REG_IDs = array_filter($REG_IDs);
1646
+
1647
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1648
+
1649
+		/**
1650
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1651
+		 * Currently this value is used downstream by the _process_resend_registration method.
1652
+		 *
1653
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1654
+		 * @param bool                     $status           The status registrations were changed to.
1655
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1656
+		 * @param Registrations_Admin_Page $admin_page_object
1657
+		 */
1658
+		$this->_req_data['_REG_ID'] = apply_filters(
1659
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1660
+			$result['REG_ID'],
1661
+			$status,
1662
+			$result['success'],
1663
+			$this
1664
+		);
1665
+
1666
+		// notify?
1667
+		if ($notify
1668
+			&& $result['success']
1669
+			&& ! empty($this->_req_data['_REG_ID'])
1670
+			&& EE_Registry::instance()->CAP->current_user_can(
1671
+				'ee_send_message',
1672
+				'espresso_registrations_resend_registration'
1673
+			)
1674
+		) {
1675
+			$this->_process_resend_registration();
1676
+		}
1677
+		return $result;
1678
+	}
1679
+
1680
+
1681
+	/**
1682
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1683
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1684
+	 *
1685
+	 * @param array  $REG_IDs
1686
+	 * @param string $status
1687
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1688
+	 *                        slug sent with setting the registration status.
1689
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1690
+	 * @throws EE_Error
1691
+	 * @throws InvalidArgumentException
1692
+	 * @throws InvalidDataTypeException
1693
+	 * @throws InvalidInterfaceException
1694
+	 * @throws ReflectionException
1695
+	 * @throws RuntimeException
1696
+	 * @throws EntityNotFoundException
1697
+	 * @throws DomainException
1698
+	 */
1699
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1700
+	{
1701
+		$success = false;
1702
+		// typecast $REG_IDs
1703
+		$REG_IDs = (array) $REG_IDs;
1704
+		if (! empty($REG_IDs)) {
1705
+			$success = true;
1706
+			// set default status if none is passed
1707
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1708
+			$status_context = $notify
1709
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1710
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1711
+			// loop through REG_ID's and change status
1712
+			foreach ($REG_IDs as $REG_ID) {
1713
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1714
+				if ($registration instanceof EE_Registration) {
1715
+					$registration->set_status(
1716
+						$status,
1717
+						false,
1718
+						new Context(
1719
+							$status_context,
1720
+							esc_html__(
1721
+								'Manually triggered status change on a Registration Admin Page route.',
1722
+								'event_espresso'
1723
+							)
1724
+						)
1725
+					);
1726
+					$result = $registration->save();
1727
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1728
+					$success = $result !== false ? $success : false;
1729
+				}
1730
+			}
1731
+		}
1732
+
1733
+		// return $success and processed registrations
1734
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1735
+	}
1736
+
1737
+
1738
+	/**
1739
+	 * Common logic for setting up success message and redirecting to appropriate route
1740
+	 *
1741
+	 * @param string $STS_ID status id for the registration changed to
1742
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1743
+	 * @return void
1744
+	 * @throws DomainException
1745
+	 * @throws EE_Error
1746
+	 * @throws EntityNotFoundException
1747
+	 * @throws InvalidArgumentException
1748
+	 * @throws InvalidDataTypeException
1749
+	 * @throws InvalidInterfaceException
1750
+	 * @throws ReflectionException
1751
+	 * @throws RuntimeException
1752
+	 */
1753
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1754
+	{
1755
+		$result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1756
+			: array('success' => false);
1757
+		$success = isset($result['success']) && $result['success'];
1758
+		// setup success message
1759
+		if ($success) {
1760
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1761
+				$msg = sprintf(
1762
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1763
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1764
+				);
1765
+			} else {
1766
+				$msg = sprintf(
1767
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1768
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1769
+				);
1770
+			}
1771
+			EE_Error::add_success($msg);
1772
+		} else {
1773
+			EE_Error::add_error(
1774
+				esc_html__(
1775
+					'Something went wrong, and the status was not changed',
1776
+					'event_espresso'
1777
+				),
1778
+				__FILE__,
1779
+				__LINE__,
1780
+				__FUNCTION__
1781
+			);
1782
+		}
1783
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] === 'view_registration') {
1784
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1785
+		} else {
1786
+			$route = array('action' => 'default');
1787
+		}
1788
+		$route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1789
+		$this->_redirect_after_action($success, '', '', $route, true);
1790
+	}
1791
+
1792
+
1793
+	/**
1794
+	 * incoming reg status change from reg details page.
1795
+	 *
1796
+	 * @return void
1797
+	 * @throws EE_Error
1798
+	 * @throws EntityNotFoundException
1799
+	 * @throws InvalidArgumentException
1800
+	 * @throws InvalidDataTypeException
1801
+	 * @throws InvalidInterfaceException
1802
+	 * @throws ReflectionException
1803
+	 * @throws RuntimeException
1804
+	 * @throws DomainException
1805
+	 */
1806
+	protected function _change_reg_status()
1807
+	{
1808
+		$this->_req_data['return'] = 'view_registration';
1809
+		// set notify based on whether the send notifications toggle is set or not
1810
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1811
+		// $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1812
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1813
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1814
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1815
+			case EEM_Registration::status_id_approved:
1816
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1817
+				$this->approve_registration($notify);
1818
+				break;
1819
+			case EEM_Registration::status_id_pending_payment:
1820
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1821
+				$this->pending_registration($notify);
1822
+				break;
1823
+			case EEM_Registration::status_id_not_approved:
1824
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1825
+				$this->not_approve_registration($notify);
1826
+				break;
1827
+			case EEM_Registration::status_id_declined:
1828
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1829
+				$this->decline_registration($notify);
1830
+				break;
1831
+			case EEM_Registration::status_id_cancelled:
1832
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1833
+				$this->cancel_registration($notify);
1834
+				break;
1835
+			case EEM_Registration::status_id_wait_list:
1836
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1837
+				$this->wait_list_registration($notify);
1838
+				break;
1839
+			case EEM_Registration::status_id_incomplete:
1840
+			default:
1841
+				$result['success'] = false;
1842
+				unset($this->_req_data['return']);
1843
+				$this->_reg_status_change_return('', false);
1844
+				break;
1845
+		}
1846
+	}
1847
+
1848
+
1849
+	/**
1850
+	 * Callback for bulk action routes.
1851
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1852
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1853
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1854
+	 * when an action is happening on just a single registration).
1855
+	 *
1856
+	 * @param      $action
1857
+	 * @param bool $notify
1858
+	 */
1859
+	protected function bulk_action_on_registrations($action, $notify = false)
1860
+	{
1861
+		do_action(
1862
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1863
+			$this,
1864
+			$action,
1865
+			$notify
1866
+		);
1867
+		$method = $action . '_registration';
1868
+		if (method_exists($this, $method)) {
1869
+			$this->$method($notify);
1870
+		}
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 * approve_registration
1876
+	 *
1877
+	 * @access protected
1878
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1879
+	 * @return void
1880
+	 * @throws EE_Error
1881
+	 * @throws EntityNotFoundException
1882
+	 * @throws InvalidArgumentException
1883
+	 * @throws InvalidDataTypeException
1884
+	 * @throws InvalidInterfaceException
1885
+	 * @throws ReflectionException
1886
+	 * @throws RuntimeException
1887
+	 * @throws DomainException
1888
+	 */
1889
+	protected function approve_registration($notify = false)
1890
+	{
1891
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1892
+	}
1893
+
1894
+
1895
+	/**
1896
+	 *        decline_registration
1897
+	 *
1898
+	 * @access protected
1899
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1900
+	 * @return void
1901
+	 * @throws EE_Error
1902
+	 * @throws EntityNotFoundException
1903
+	 * @throws InvalidArgumentException
1904
+	 * @throws InvalidDataTypeException
1905
+	 * @throws InvalidInterfaceException
1906
+	 * @throws ReflectionException
1907
+	 * @throws RuntimeException
1908
+	 * @throws DomainException
1909
+	 */
1910
+	protected function decline_registration($notify = false)
1911
+	{
1912
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1913
+	}
1914
+
1915
+
1916
+	/**
1917
+	 *        cancel_registration
1918
+	 *
1919
+	 * @access protected
1920
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1921
+	 * @return void
1922
+	 * @throws EE_Error
1923
+	 * @throws EntityNotFoundException
1924
+	 * @throws InvalidArgumentException
1925
+	 * @throws InvalidDataTypeException
1926
+	 * @throws InvalidInterfaceException
1927
+	 * @throws ReflectionException
1928
+	 * @throws RuntimeException
1929
+	 * @throws DomainException
1930
+	 */
1931
+	protected function cancel_registration($notify = false)
1932
+	{
1933
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1934
+	}
1935
+
1936
+
1937
+	/**
1938
+	 *        not_approve_registration
1939
+	 *
1940
+	 * @access protected
1941
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1942
+	 * @return void
1943
+	 * @throws EE_Error
1944
+	 * @throws EntityNotFoundException
1945
+	 * @throws InvalidArgumentException
1946
+	 * @throws InvalidDataTypeException
1947
+	 * @throws InvalidInterfaceException
1948
+	 * @throws ReflectionException
1949
+	 * @throws RuntimeException
1950
+	 * @throws DomainException
1951
+	 */
1952
+	protected function not_approve_registration($notify = false)
1953
+	{
1954
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1955
+	}
1956
+
1957
+
1958
+	/**
1959
+	 *        decline_registration
1960
+	 *
1961
+	 * @access protected
1962
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1963
+	 * @return void
1964
+	 * @throws EE_Error
1965
+	 * @throws EntityNotFoundException
1966
+	 * @throws InvalidArgumentException
1967
+	 * @throws InvalidDataTypeException
1968
+	 * @throws InvalidInterfaceException
1969
+	 * @throws ReflectionException
1970
+	 * @throws RuntimeException
1971
+	 * @throws DomainException
1972
+	 */
1973
+	protected function pending_registration($notify = false)
1974
+	{
1975
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1976
+	}
1977
+
1978
+
1979
+	/**
1980
+	 * waitlist_registration
1981
+	 *
1982
+	 * @access protected
1983
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1984
+	 * @return void
1985
+	 * @throws EE_Error
1986
+	 * @throws EntityNotFoundException
1987
+	 * @throws InvalidArgumentException
1988
+	 * @throws InvalidDataTypeException
1989
+	 * @throws InvalidInterfaceException
1990
+	 * @throws ReflectionException
1991
+	 * @throws RuntimeException
1992
+	 * @throws DomainException
1993
+	 */
1994
+	protected function wait_list_registration($notify = false)
1995
+	{
1996
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1997
+	}
1998
+
1999
+
2000
+	/**
2001
+	 *        generates HTML for the Registration main meta box
2002
+	 *
2003
+	 * @access public
2004
+	 * @return void
2005
+	 * @throws DomainException
2006
+	 * @throws EE_Error
2007
+	 * @throws InvalidArgumentException
2008
+	 * @throws InvalidDataTypeException
2009
+	 * @throws InvalidInterfaceException
2010
+	 * @throws ReflectionException
2011
+	 * @throws EntityNotFoundException
2012
+	 */
2013
+	public function _reg_details_meta_box()
2014
+	{
2015
+		EEH_Autoloader::register_line_item_display_autoloaders();
2016
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2017
+		EE_Registry::instance()->load_helper('Line_Item');
2018
+		$transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2019
+			: EE_Transaction::new_instance();
2020
+		$this->_session = $transaction->session_data();
2021
+		$filters = new EE_Line_Item_Filter_Collection();
2022
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2023
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
2024
+		$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2025
+			$filters,
2026
+			$transaction->total_line_item()
2027
+		);
2028
+		$filtered_line_item_tree = $line_item_filter_processor->process();
2029
+		$line_item_display = new EE_Line_Item_Display(
2030
+			'reg_admin_table',
2031
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2032
+		);
2033
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2034
+			$filtered_line_item_tree,
2035
+			array('EE_Registration' => $this->_registration)
2036
+		);
2037
+		$attendee = $this->_registration->attendee();
2038
+		if (EE_Registry::instance()->CAP->current_user_can(
2039
+			'ee_read_transaction',
2040
+			'espresso_transactions_view_transaction'
2041
+		)) {
2042
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2043
+				EE_Admin_Page::add_query_args_and_nonce(
2044
+					array(
2045
+						'action' => 'view_transaction',
2046
+						'TXN_ID' => $transaction->ID(),
2047
+					),
2048
+					TXN_ADMIN_URL
2049
+				),
2050
+				esc_html__(' View Transaction', 'event_espresso'),
2051
+				'button secondary-button right',
2052
+				'dashicons dashicons-cart'
2053
+			);
2054
+		} else {
2055
+			$this->_template_args['view_transaction_button'] = '';
2056
+		}
2057
+		if ($attendee instanceof EE_Attendee
2058
+			&& EE_Registry::instance()->CAP->current_user_can(
2059
+				'ee_send_message',
2060
+				'espresso_registrations_resend_registration'
2061
+			)
2062
+		) {
2063
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2064
+				EE_Admin_Page::add_query_args_and_nonce(
2065
+					array(
2066
+						'action'      => 'resend_registration',
2067
+						'_REG_ID'     => $this->_registration->ID(),
2068
+						'redirect_to' => 'view_registration',
2069
+					),
2070
+					REG_ADMIN_URL
2071
+				),
2072
+				esc_html__(' Resend Registration', 'event_espresso'),
2073
+				'button secondary-button right',
2074
+				'dashicons dashicons-email-alt'
2075
+			);
2076
+		} else {
2077
+			$this->_template_args['resend_registration_button'] = '';
2078
+		}
2079
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2080
+		$payment = $transaction->get_first_related('Payment');
2081
+		$payment = ! $payment instanceof EE_Payment
2082
+			? EE_Payment::new_instance()
2083
+			: $payment;
2084
+		$payment_method = $payment->get_first_related('Payment_Method');
2085
+		$payment_method = ! $payment_method instanceof EE_Payment_Method
2086
+			? EE_Payment_Method::new_instance()
2087
+			: $payment_method;
2088
+		$reg_details = array(
2089
+			'payment_method'       => $payment_method->name(),
2090
+			'response_msg'         => $payment->gateway_response(),
2091
+			'registration_id'      => $this->_registration->get('REG_code'),
2092
+			'registration_session' => $this->_registration->session_ID(),
2093
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2094
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2095
+		);
2096
+		if (isset($reg_details['registration_id'])) {
2097
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2098
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2099
+				'Registration ID',
2100
+				'event_espresso'
2101
+			);
2102
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2103
+		}
2104
+		if (isset($reg_details['payment_method'])) {
2105
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2106
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2107
+				'Most Recent Payment Method',
2108
+				'event_espresso'
2109
+			);
2110
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2111
+			$this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2112
+			$this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2113
+				'Payment method response',
2114
+				'event_espresso'
2115
+			);
2116
+			$this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2117
+		}
2118
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2119
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2120
+			'Registration Session',
2121
+			'event_espresso'
2122
+		);
2123
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2124
+		$this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2125
+		$this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2126
+			'Registration placed from IP',
2127
+			'event_espresso'
2128
+		);
2129
+		$this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2130
+		$this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2131
+		$this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2132
+			'Registrant User Agent',
2133
+			'event_espresso'
2134
+		);
2135
+		$this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2136
+		$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2137
+			array(
2138
+				'action'   => 'default',
2139
+				'event_id' => $this->_registration->event_ID(),
2140
+			),
2141
+			REG_ADMIN_URL
2142
+		);
2143
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2144
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2145
+		$template_path =
2146
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2147
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2148
+	}
2149
+
2150
+
2151
+	/**
2152
+	 * generates HTML for the Registration Questions meta box.
2153
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2154
+	 * otherwise uses new forms system
2155
+	 *
2156
+	 * @access public
2157
+	 * @return void
2158
+	 * @throws DomainException
2159
+	 * @throws EE_Error
2160
+	 * @throws InvalidArgumentException
2161
+	 * @throws InvalidDataTypeException
2162
+	 * @throws InvalidInterfaceException
2163
+	 * @throws ReflectionException
2164
+	 */
2165
+	public function _reg_questions_meta_box()
2166
+	{
2167
+		// allow someone to override this method entirely
2168
+		if (apply_filters(
2169
+			'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2170
+			true,
2171
+			$this,
2172
+			$this->_registration
2173
+		)) {
2174
+			$form = $this->_get_reg_custom_questions_form(
2175
+				$this->_registration->ID()
2176
+			);
2177
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2178
+				? $form->get_html_and_js()
2179
+				: '';
2180
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2181
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2182
+			$template_path =
2183
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2184
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2185
+		}
2186
+	}
2187
+
2188
+
2189
+	/**
2190
+	 * form_before_question_group
2191
+	 *
2192
+	 * @deprecated    as of 4.8.32.rc.000
2193
+	 * @access        public
2194
+	 * @param        string $output
2195
+	 * @return        string
2196
+	 */
2197
+	public function form_before_question_group($output)
2198
+	{
2199
+		EE_Error::doing_it_wrong(
2200
+			__CLASS__ . '::' . __FUNCTION__,
2201
+			esc_html__(
2202
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2203
+				'event_espresso'
2204
+			),
2205
+			'4.8.32.rc.000'
2206
+		);
2207
+		return '
2208 2208
 	<table class="form-table ee-width-100">
2209 2209
 		<tbody>
2210 2210
 			';
2211
-    }
2212
-
2213
-
2214
-    /**
2215
-     * form_after_question_group
2216
-     *
2217
-     * @deprecated    as of 4.8.32.rc.000
2218
-     * @access        public
2219
-     * @param        string $output
2220
-     * @return        string
2221
-     */
2222
-    public function form_after_question_group($output)
2223
-    {
2224
-        EE_Error::doing_it_wrong(
2225
-            __CLASS__ . '::' . __FUNCTION__,
2226
-            esc_html__(
2227
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2228
-                'event_espresso'
2229
-            ),
2230
-            '4.8.32.rc.000'
2231
-        );
2232
-        return '
2211
+	}
2212
+
2213
+
2214
+	/**
2215
+	 * form_after_question_group
2216
+	 *
2217
+	 * @deprecated    as of 4.8.32.rc.000
2218
+	 * @access        public
2219
+	 * @param        string $output
2220
+	 * @return        string
2221
+	 */
2222
+	public function form_after_question_group($output)
2223
+	{
2224
+		EE_Error::doing_it_wrong(
2225
+			__CLASS__ . '::' . __FUNCTION__,
2226
+			esc_html__(
2227
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2228
+				'event_espresso'
2229
+			),
2230
+			'4.8.32.rc.000'
2231
+		);
2232
+		return '
2233 2233
 			<tr class="hide-if-no-js">
2234 2234
 				<th> </th>
2235 2235
 				<td class="reg-admin-edit-attendee-question-td">
2236 2236
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2237
-               . esc_attr__('click to edit question', 'event_espresso')
2238
-               . '">
2237
+			   . esc_attr__('click to edit question', 'event_espresso')
2238
+			   . '">
2239 2239
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2240
-               . esc_html__('edit the above question group', 'event_espresso')
2241
-               . '</span>
2240
+			   . esc_html__('edit the above question group', 'event_espresso')
2241
+			   . '</span>
2242 2242
 						<div class="dashicons dashicons-edit"></div>
2243 2243
 					</a>
2244 2244
 				</td>
@@ -2246,627 +2246,627 @@  discard block
 block discarded – undo
2246 2246
 		</tbody>
2247 2247
 	</table>
2248 2248
 ';
2249
-    }
2250
-
2251
-
2252
-    /**
2253
-     * form_form_field_label_wrap
2254
-     *
2255
-     * @deprecated    as of 4.8.32.rc.000
2256
-     * @access        public
2257
-     * @param        string $label
2258
-     * @return        string
2259
-     */
2260
-    public function form_form_field_label_wrap($label)
2261
-    {
2262
-        EE_Error::doing_it_wrong(
2263
-            __CLASS__ . '::' . __FUNCTION__,
2264
-            esc_html__(
2265
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2266
-                'event_espresso'
2267
-            ),
2268
-            '4.8.32.rc.000'
2269
-        );
2270
-        return '
2249
+	}
2250
+
2251
+
2252
+	/**
2253
+	 * form_form_field_label_wrap
2254
+	 *
2255
+	 * @deprecated    as of 4.8.32.rc.000
2256
+	 * @access        public
2257
+	 * @param        string $label
2258
+	 * @return        string
2259
+	 */
2260
+	public function form_form_field_label_wrap($label)
2261
+	{
2262
+		EE_Error::doing_it_wrong(
2263
+			__CLASS__ . '::' . __FUNCTION__,
2264
+			esc_html__(
2265
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2266
+				'event_espresso'
2267
+			),
2268
+			'4.8.32.rc.000'
2269
+		);
2270
+		return '
2271 2271
 			<tr>
2272 2272
 				<th>
2273 2273
 					' . $label . '
2274 2274
 				</th>';
2275
-    }
2276
-
2277
-
2278
-    /**
2279
-     * form_form_field_input__wrap
2280
-     *
2281
-     * @deprecated    as of 4.8.32.rc.000
2282
-     * @access        public
2283
-     * @param        string $input
2284
-     * @return        string
2285
-     */
2286
-    public function form_form_field_input__wrap($input)
2287
-    {
2288
-        EE_Error::doing_it_wrong(
2289
-            __CLASS__ . '::' . __FUNCTION__,
2290
-            esc_html__(
2291
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2292
-                'event_espresso'
2293
-            ),
2294
-            '4.8.32.rc.000'
2295
-        );
2296
-        return '
2275
+	}
2276
+
2277
+
2278
+	/**
2279
+	 * form_form_field_input__wrap
2280
+	 *
2281
+	 * @deprecated    as of 4.8.32.rc.000
2282
+	 * @access        public
2283
+	 * @param        string $input
2284
+	 * @return        string
2285
+	 */
2286
+	public function form_form_field_input__wrap($input)
2287
+	{
2288
+		EE_Error::doing_it_wrong(
2289
+			__CLASS__ . '::' . __FUNCTION__,
2290
+			esc_html__(
2291
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2292
+				'event_espresso'
2293
+			),
2294
+			'4.8.32.rc.000'
2295
+		);
2296
+		return '
2297 2297
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2298 2298
 					' . $input . '
2299 2299
 				</td>
2300 2300
 			</tr>';
2301
-    }
2302
-
2303
-
2304
-    /**
2305
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2306
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2307
-     * to display the page
2308
-     *
2309
-     * @access protected
2310
-     * @return void
2311
-     * @throws EE_Error
2312
-     * @throws InvalidArgumentException
2313
-     * @throws InvalidDataTypeException
2314
-     * @throws InvalidInterfaceException
2315
-     * @throws ReflectionException
2316
-     */
2317
-    protected function _update_attendee_registration_form()
2318
-    {
2319
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2320
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2321
-            $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2322
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2323
-            if ($success) {
2324
-                $what = esc_html__('Registration Form', 'event_espresso');
2325
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2326
-                    : array('action' => 'default');
2327
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2328
-            }
2329
-        }
2330
-    }
2331
-
2332
-
2333
-    /**
2334
-     * Gets the form for saving registrations custom questions (if done
2335
-     * previously retrieves the cached form object, which may have validation errors in it)
2336
-     *
2337
-     * @param int $REG_ID
2338
-     * @return EE_Registration_Custom_Questions_Form
2339
-     * @throws EE_Error
2340
-     * @throws InvalidArgumentException
2341
-     * @throws InvalidDataTypeException
2342
-     * @throws InvalidInterfaceException
2343
-     */
2344
-    protected function _get_reg_custom_questions_form($REG_ID)
2345
-    {
2346
-        if (! $this->_reg_custom_questions_form) {
2347
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2348
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2349
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2350
-            );
2351
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2352
-        }
2353
-        return $this->_reg_custom_questions_form;
2354
-    }
2355
-
2356
-
2357
-    /**
2358
-     * Saves
2359
-     *
2360
-     * @access private
2361
-     * @param bool $REG_ID
2362
-     * @return bool
2363
-     * @throws EE_Error
2364
-     * @throws InvalidArgumentException
2365
-     * @throws InvalidDataTypeException
2366
-     * @throws InvalidInterfaceException
2367
-     * @throws ReflectionException
2368
-     */
2369
-    private function _save_reg_custom_questions_form($REG_ID = false)
2370
-    {
2371
-        if (! $REG_ID) {
2372
-            EE_Error::add_error(
2373
-                esc_html__(
2374
-                    'An error occurred. No registration ID was received.',
2375
-                    'event_espresso'
2376
-                ),
2377
-                __FILE__,
2378
-                __FUNCTION__,
2379
-                __LINE__
2380
-            );
2381
-        }
2382
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2383
-        $form->receive_form_submission($this->_req_data);
2384
-        $success = false;
2385
-        if ($form->is_valid()) {
2386
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2387
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2388
-                    $where_conditions = array(
2389
-                        'QST_ID' => $question_id,
2390
-                        'REG_ID' => $REG_ID,
2391
-                    );
2392
-                    $possibly_new_values = array(
2393
-                        'ANS_value' => $input->normalized_value(),
2394
-                    );
2395
-                    $answer = EEM_Answer::instance()->get_one(array($where_conditions));
2396
-                    if ($answer instanceof EE_Answer) {
2397
-                        $success = $answer->save($possibly_new_values);
2398
-                    } else {
2399
-                        // insert it then
2400
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2401
-                        $answer = EE_Answer::new_instance($cols_n_vals);
2402
-                        $success = $answer->save();
2403
-                    }
2404
-                }
2405
-            }
2406
-        } else {
2407
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2408
-        }
2409
-        return $success;
2410
-    }
2411
-
2412
-
2413
-    /**
2414
-     *        generates HTML for the Registration main meta box
2415
-     *
2416
-     * @access public
2417
-     * @return void
2418
-     * @throws DomainException
2419
-     * @throws EE_Error
2420
-     * @throws InvalidArgumentException
2421
-     * @throws InvalidDataTypeException
2422
-     * @throws InvalidInterfaceException
2423
-     * @throws ReflectionException
2424
-     */
2425
-    public function _reg_attendees_meta_box()
2426
-    {
2427
-        $REG = $this->getRegistrationModel();
2428
-        // get all other registrations on this transaction, and cache
2429
-        // the attendees for them so we don't have to run another query using force_join
2430
-        $registrations = $REG->get_all(
2431
-            array(
2432
-                array(
2433
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2434
-                    'REG_ID' => array('!=', $this->_registration->ID()),
2435
-                ),
2436
-                'force_join' => array('Attendee'),
2437
-                'default_where_conditions' => 'other_models_only',
2438
-            )
2439
-        );
2440
-        $this->_template_args['attendees'] = array();
2441
-        $this->_template_args['attendee_notice'] = '';
2442
-        if (empty($registrations)
2443
-            || (is_array($registrations)
2444
-                && ! EEH_Array::get_one_item_from_array($registrations))
2445
-        ) {
2446
-            EE_Error::add_error(
2447
-                esc_html__(
2448
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2449
-                    'event_espresso'
2450
-                ),
2451
-                __FILE__,
2452
-                __FUNCTION__,
2453
-                __LINE__
2454
-            );
2455
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2456
-        } else {
2457
-            $att_nmbr = 1;
2458
-            foreach ($registrations as $registration) {
2459
-                /* @var $registration EE_Registration */
2460
-                $attendee = $registration->attendee()
2461
-                    ? $registration->attendee()
2462
-                    : $this->getAttendeeModel()->create_default_object();
2463
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2464
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2465
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2466
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2467
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2468
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2469
-                    ', ',
2470
-                    $attendee->full_address_as_array()
2471
-                );
2472
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2473
-                    array(
2474
-                        'action' => 'edit_attendee',
2475
-                        'post'   => $attendee->ID(),
2476
-                    ),
2477
-                    REG_ADMIN_URL
2478
-                );
2479
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2480
-                    ? $registration->event_obj()->name()
2481
-                    : '';
2482
-                $att_nmbr++;
2483
-            }
2484
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2485
-        }
2486
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2487
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2488
-    }
2489
-
2490
-
2491
-    /**
2492
-     *        generates HTML for the Edit Registration side meta box
2493
-     *
2494
-     * @access public
2495
-     * @return void
2496
-     * @throws DomainException
2497
-     * @throws EE_Error
2498
-     * @throws InvalidArgumentException
2499
-     * @throws InvalidDataTypeException
2500
-     * @throws InvalidInterfaceException
2501
-     * @throws ReflectionException
2502
-     */
2503
-    public function _reg_registrant_side_meta_box()
2504
-    {
2505
-        /*@var $attendee EE_Attendee */
2506
-        $att_check = $this->_registration->attendee();
2507
-        $attendee = $att_check instanceof EE_Attendee
2508
-            ? $att_check
2509
-            : $this->getAttendeeModel()->create_default_object();
2510
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2511
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2512
-        // primary registration object (that way we know if we need to show create button or not)
2513
-        if (! $this->_registration->is_primary_registrant()) {
2514
-            $primary_registration = $this->_registration->get_primary_registration();
2515
-            $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2516
-                : null;
2517
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2518
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2519
-                // custom attendee object so let's not worry about the primary reg.
2520
-                $primary_registration = null;
2521
-            }
2522
-        } else {
2523
-            $primary_registration = null;
2524
-        }
2525
-        $this->_template_args['ATT_ID'] = $attendee->ID();
2526
-        $this->_template_args['fname'] = $attendee->fname();
2527
-        $this->_template_args['lname'] = $attendee->lname();
2528
-        $this->_template_args['email'] = $attendee->email();
2529
-        $this->_template_args['phone'] = $attendee->phone();
2530
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2531
-        // edit link
2532
-        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2533
-            array(
2534
-                'action' => 'edit_attendee',
2535
-                'post'   => $attendee->ID(),
2536
-            ),
2537
-            REG_ADMIN_URL
2538
-        );
2539
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2540
-        // create link
2541
-        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2542
-            ? EE_Admin_Page::add_query_args_and_nonce(
2543
-                array(
2544
-                    'action'  => 'duplicate_attendee',
2545
-                    '_REG_ID' => $this->_registration->ID(),
2546
-                ),
2547
-                REG_ADMIN_URL
2548
-            ) : '';
2549
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2550
-        $this->_template_args['att_check'] = $att_check;
2551
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2552
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2553
-    }
2554
-
2555
-
2556
-    /**
2557
-     * trash or restore registrations
2558
-     *
2559
-     * @param  boolean $trash whether to archive or restore
2560
-     * @return void
2561
-     * @throws EE_Error
2562
-     * @throws InvalidArgumentException
2563
-     * @throws InvalidDataTypeException
2564
-     * @throws InvalidInterfaceException
2565
-     * @throws RuntimeException
2566
-     * @access protected
2567
-     */
2568
-    protected function _trash_or_restore_registrations($trash = true)
2569
-    {
2570
-        // if empty _REG_ID then get out because there's nothing to do
2571
-        if (empty($this->_req_data['_REG_ID'])) {
2572
-            EE_Error::add_error(
2573
-                sprintf(
2574
-                    esc_html__(
2575
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2576
-                        'event_espresso'
2577
-                    ),
2578
-                    $trash ? 'trash' : 'restore'
2579
-                ),
2580
-                __FILE__,
2581
-                __LINE__,
2582
-                __FUNCTION__
2583
-            );
2584
-            $this->_redirect_after_action(false, '', '', array(), true);
2585
-        }
2586
-        $success = 0;
2587
-        $overwrite_msgs = false;
2588
-        // Checkboxes
2589
-        if (! is_array($this->_req_data['_REG_ID'])) {
2590
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2591
-        }
2592
-        $reg_count = count($this->_req_data['_REG_ID']);
2593
-        // cycle thru checkboxes
2594
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2595
-            /** @var EE_Registration $REG */
2596
-            $REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2597
-            $payments = $REG->registration_payments();
2598
-            if (! empty($payments)) {
2599
-                $name = $REG->attendee() instanceof EE_Attendee
2600
-                    ? $REG->attendee()->full_name()
2601
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2602
-                $overwrite_msgs = true;
2603
-                EE_Error::add_error(
2604
-                    sprintf(
2605
-                        esc_html__(
2606
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2607
-                            'event_espresso'
2608
-                        ),
2609
-                        $name
2610
-                    ),
2611
-                    __FILE__,
2612
-                    __FUNCTION__,
2613
-                    __LINE__
2614
-                );
2615
-                // can't trash this registration because it has payments.
2616
-                continue;
2617
-            }
2618
-            $updated = $trash ? $REG->delete() : $REG->restore();
2619
-            if ($updated) {
2620
-                $success++;
2621
-            }
2622
-        }
2623
-        $this->_redirect_after_action(
2624
-            $success === $reg_count, // were ALL registrations affected?
2625
-            $success > 1
2626
-                ? esc_html__('Registrations', 'event_espresso')
2627
-                : esc_html__('Registration', 'event_espresso'),
2628
-            $trash
2629
-                ? esc_html__('moved to the trash', 'event_espresso')
2630
-                : esc_html__('restored', 'event_espresso'),
2631
-            $this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2632
-            $overwrite_msgs
2633
-        );
2634
-    }
2635
-
2636
-
2637
-    /**
2638
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2639
-     * registration but also.
2640
-     * 1. Removing relations to EE_Attendee
2641
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2642
-     * ALSO trashed.
2643
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2644
-     * 4. Removing relationships between all tickets and the related registrations
2645
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2646
-     * 6. Deleting permanently any related Checkins.
2647
-     *
2648
-     * @return void
2649
-     * @throws EE_Error
2650
-     * @throws InvalidArgumentException
2651
-     * @throws InvalidDataTypeException
2652
-     * @throws InvalidInterfaceException
2653
-     * @throws ReflectionException
2654
-     */
2655
-    protected function _delete_registrations()
2656
-    {
2657
-        $REG_MDL = $this->getRegistrationModel();
2658
-        $success = 1;
2659
-        // Checkboxes
2660
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2661
-            // if array has more than one element than success message should be plural
2662
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2663
-            // cycle thru checkboxes
2664
-            foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2665
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
-                if (! $REG instanceof EE_Registration) {
2667
-                    continue;
2668
-                }
2669
-                $deleted = $this->_delete_registration($REG);
2670
-                if (! $deleted) {
2671
-                    $success = 0;
2672
-                }
2673
-            }
2674
-        } else {
2675
-            // grab single id and delete
2676
-            $REG_ID = $this->_req_data['_REG_ID'];
2677
-            /** @var EE_Registration $REG */
2678
-            $REG = $REG_MDL->get_one_by_ID($REG_ID);
2679
-            $deleted = $this->_delete_registration($REG);
2680
-            if (! $deleted) {
2681
-                $success = 0;
2682
-            }
2683
-        }
2684
-        $what = $success > 1
2685
-            ? esc_html__('Registrations', 'event_espresso')
2686
-            : esc_html__('Registration', 'event_espresso');
2687
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2688
-        $this->_redirect_after_action(
2689
-            $success,
2690
-            $what,
2691
-            $action_desc,
2692
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2693
-            true
2694
-        );
2695
-    }
2696
-
2697
-
2698
-    /**
2699
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2700
-     * models get affected.
2701
-     *
2702
-     * @param EE_Registration $REG registration to be deleted permanently
2703
-     * @return bool true = successful deletion, false = fail.
2704
-     * @throws EE_Error
2705
-     * @throws InvalidArgumentException
2706
-     * @throws InvalidDataTypeException
2707
-     * @throws InvalidInterfaceException
2708
-     * @throws ReflectionException
2709
-     */
2710
-    protected function _delete_registration(EE_Registration $REG)
2711
-    {
2712
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2713
-        // registrations on the transaction that are NOT trashed.
2714
-        $TXN = $REG->get_first_related('Transaction');
2715
-        $REGS = $TXN->get_many_related('Registration');
2716
-        $all_trashed = true;
2717
-        foreach ($REGS as $registration) {
2718
-            if (! $registration->get('REG_deleted')) {
2719
-                $all_trashed = false;
2720
-            }
2721
-        }
2722
-        if (! $all_trashed) {
2723
-            EE_Error::add_error(
2724
-                esc_html__(
2725
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2726
-                    'event_espresso'
2727
-                ),
2728
-                __FILE__,
2729
-                __FUNCTION__,
2730
-                __LINE__
2731
-            );
2732
-            return false;
2733
-        }
2734
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2735
-        // separately from THIS one).
2736
-        foreach ($REGS as $registration) {
2737
-            // delete related answers
2738
-            $registration->delete_related_permanently('Answer');
2739
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2740
-            $attendee = $registration->get_first_related('Attendee');
2741
-            if ($attendee instanceof EE_Attendee) {
2742
-                $registration->_remove_relation_to($attendee, 'Attendee');
2743
-            }
2744
-            // now remove relationships to tickets on this registration.
2745
-            $registration->_remove_relations('Ticket');
2746
-            // now delete permanently the checkins related to this registration.
2747
-            $registration->delete_related_permanently('Checkin');
2748
-            if ($registration->ID() === $REG->ID()) {
2749
-                continue;
2750
-            } //we don't want to delete permanently the existing registration just yet.
2751
-            // remove relation to transaction for these registrations if NOT the existing registrations
2752
-            $registration->_remove_relations('Transaction');
2753
-            // delete permanently any related messages.
2754
-            $registration->delete_related_permanently('Message');
2755
-            // now delete this registration permanently
2756
-            $registration->delete_permanently();
2757
-        }
2758
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2759
-        // (the transaction and line items should be all that's left).
2760
-        // delete the line items related to the transaction for this registration.
2761
-        $TXN->delete_related_permanently('Line_Item');
2762
-        // we need to remove all the relationships on the transaction
2763
-        $TXN->delete_related_permanently('Payment');
2764
-        $TXN->delete_related_permanently('Extra_Meta');
2765
-        $TXN->delete_related_permanently('Message');
2766
-        // now we can delete this REG permanently (and the transaction of course)
2767
-        $REG->delete_related_permanently('Transaction');
2768
-        return $REG->delete_permanently();
2769
-    }
2770
-
2771
-
2772
-    /**
2773
-     *    generates HTML for the Register New Attendee Admin page
2774
-     *
2775
-     * @access private
2776
-     * @throws DomainException
2777
-     * @throws EE_Error
2778
-     * @throws InvalidArgumentException
2779
-     * @throws InvalidDataTypeException
2780
-     * @throws InvalidInterfaceException
2781
-     * @throws ReflectionException
2782
-     */
2783
-    public function new_registration()
2784
-    {
2785
-        if (! $this->_set_reg_event()) {
2786
-            throw new EE_Error(
2787
-                esc_html__(
2788
-                    'Unable to continue with registering because there is no Event ID in the request',
2789
-                    'event_espresso'
2790
-                )
2791
-            );
2792
-        }
2793
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2794
-        // gotta start with a clean slate if we're not coming here via ajax
2795
-        if (! defined('DOING_AJAX')
2796
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2797
-        ) {
2798
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2799
-        }
2800
-        $this->_template_args['event_name'] = '';
2801
-        // event name
2802
-        if ($this->_reg_event) {
2803
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2804
-            $edit_event_url = self::add_query_args_and_nonce(
2805
-                array(
2806
-                    'action' => 'edit',
2807
-                    'post'   => $this->_reg_event->ID(),
2808
-                ),
2809
-                EVENTS_ADMIN_URL
2810
-            );
2811
-            $edit_event_lnk = '<a href="'
2812
-                              . $edit_event_url
2813
-                              . '" title="'
2814
-                              . esc_attr__('Edit ', 'event_espresso')
2815
-                              . $this->_reg_event->name()
2816
-                              . '">'
2817
-                              . esc_html__('Edit Event', 'event_espresso')
2818
-                              . '</a>';
2819
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2820
-                                                   . $edit_event_lnk
2821
-                                                   . '</span>';
2822
-        }
2823
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2824
-        if (defined('DOING_AJAX')) {
2825
-            $this->_return_json();
2826
-        }
2827
-        // grab header
2828
-        $template_path =
2829
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2830
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2831
-            $template_path,
2832
-            $this->_template_args,
2833
-            true
2834
-        );
2835
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2836
-        // the details template wrapper
2837
-        $this->display_admin_page_with_sidebar();
2838
-    }
2839
-
2840
-
2841
-    /**
2842
-     * This returns the content for a registration step
2843
-     *
2844
-     * @access protected
2845
-     * @return string html
2846
-     * @throws DomainException
2847
-     * @throws EE_Error
2848
-     * @throws InvalidArgumentException
2849
-     * @throws InvalidDataTypeException
2850
-     * @throws InvalidInterfaceException
2851
-     */
2852
-    protected function _get_registration_step_content()
2853
-    {
2854
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2855
-            $warning_msg = sprintf(
2856
-                esc_html__(
2857
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2858
-                    'event_espresso'
2859
-                ),
2860
-                '<br />',
2861
-                '<h3 class="important-notice">',
2862
-                '</h3>',
2863
-                '<div class="float-right">',
2864
-                '<span id="redirect_timer" class="important-notice">30</span>',
2865
-                '</div>',
2866
-                '<b>',
2867
-                '</b>'
2868
-            );
2869
-            return '
2301
+	}
2302
+
2303
+
2304
+	/**
2305
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2306
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2307
+	 * to display the page
2308
+	 *
2309
+	 * @access protected
2310
+	 * @return void
2311
+	 * @throws EE_Error
2312
+	 * @throws InvalidArgumentException
2313
+	 * @throws InvalidDataTypeException
2314
+	 * @throws InvalidInterfaceException
2315
+	 * @throws ReflectionException
2316
+	 */
2317
+	protected function _update_attendee_registration_form()
2318
+	{
2319
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2320
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2321
+			$REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2322
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2323
+			if ($success) {
2324
+				$what = esc_html__('Registration Form', 'event_espresso');
2325
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2326
+					: array('action' => 'default');
2327
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2328
+			}
2329
+		}
2330
+	}
2331
+
2332
+
2333
+	/**
2334
+	 * Gets the form for saving registrations custom questions (if done
2335
+	 * previously retrieves the cached form object, which may have validation errors in it)
2336
+	 *
2337
+	 * @param int $REG_ID
2338
+	 * @return EE_Registration_Custom_Questions_Form
2339
+	 * @throws EE_Error
2340
+	 * @throws InvalidArgumentException
2341
+	 * @throws InvalidDataTypeException
2342
+	 * @throws InvalidInterfaceException
2343
+	 */
2344
+	protected function _get_reg_custom_questions_form($REG_ID)
2345
+	{
2346
+		if (! $this->_reg_custom_questions_form) {
2347
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2348
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2349
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2350
+			);
2351
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2352
+		}
2353
+		return $this->_reg_custom_questions_form;
2354
+	}
2355
+
2356
+
2357
+	/**
2358
+	 * Saves
2359
+	 *
2360
+	 * @access private
2361
+	 * @param bool $REG_ID
2362
+	 * @return bool
2363
+	 * @throws EE_Error
2364
+	 * @throws InvalidArgumentException
2365
+	 * @throws InvalidDataTypeException
2366
+	 * @throws InvalidInterfaceException
2367
+	 * @throws ReflectionException
2368
+	 */
2369
+	private function _save_reg_custom_questions_form($REG_ID = false)
2370
+	{
2371
+		if (! $REG_ID) {
2372
+			EE_Error::add_error(
2373
+				esc_html__(
2374
+					'An error occurred. No registration ID was received.',
2375
+					'event_espresso'
2376
+				),
2377
+				__FILE__,
2378
+				__FUNCTION__,
2379
+				__LINE__
2380
+			);
2381
+		}
2382
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2383
+		$form->receive_form_submission($this->_req_data);
2384
+		$success = false;
2385
+		if ($form->is_valid()) {
2386
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2387
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2388
+					$where_conditions = array(
2389
+						'QST_ID' => $question_id,
2390
+						'REG_ID' => $REG_ID,
2391
+					);
2392
+					$possibly_new_values = array(
2393
+						'ANS_value' => $input->normalized_value(),
2394
+					);
2395
+					$answer = EEM_Answer::instance()->get_one(array($where_conditions));
2396
+					if ($answer instanceof EE_Answer) {
2397
+						$success = $answer->save($possibly_new_values);
2398
+					} else {
2399
+						// insert it then
2400
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2401
+						$answer = EE_Answer::new_instance($cols_n_vals);
2402
+						$success = $answer->save();
2403
+					}
2404
+				}
2405
+			}
2406
+		} else {
2407
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2408
+		}
2409
+		return $success;
2410
+	}
2411
+
2412
+
2413
+	/**
2414
+	 *        generates HTML for the Registration main meta box
2415
+	 *
2416
+	 * @access public
2417
+	 * @return void
2418
+	 * @throws DomainException
2419
+	 * @throws EE_Error
2420
+	 * @throws InvalidArgumentException
2421
+	 * @throws InvalidDataTypeException
2422
+	 * @throws InvalidInterfaceException
2423
+	 * @throws ReflectionException
2424
+	 */
2425
+	public function _reg_attendees_meta_box()
2426
+	{
2427
+		$REG = $this->getRegistrationModel();
2428
+		// get all other registrations on this transaction, and cache
2429
+		// the attendees for them so we don't have to run another query using force_join
2430
+		$registrations = $REG->get_all(
2431
+			array(
2432
+				array(
2433
+					'TXN_ID' => $this->_registration->transaction_ID(),
2434
+					'REG_ID' => array('!=', $this->_registration->ID()),
2435
+				),
2436
+				'force_join' => array('Attendee'),
2437
+				'default_where_conditions' => 'other_models_only',
2438
+			)
2439
+		);
2440
+		$this->_template_args['attendees'] = array();
2441
+		$this->_template_args['attendee_notice'] = '';
2442
+		if (empty($registrations)
2443
+			|| (is_array($registrations)
2444
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2445
+		) {
2446
+			EE_Error::add_error(
2447
+				esc_html__(
2448
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2449
+					'event_espresso'
2450
+				),
2451
+				__FILE__,
2452
+				__FUNCTION__,
2453
+				__LINE__
2454
+			);
2455
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2456
+		} else {
2457
+			$att_nmbr = 1;
2458
+			foreach ($registrations as $registration) {
2459
+				/* @var $registration EE_Registration */
2460
+				$attendee = $registration->attendee()
2461
+					? $registration->attendee()
2462
+					: $this->getAttendeeModel()->create_default_object();
2463
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2464
+				$this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2465
+				$this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2466
+				$this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2467
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2468
+				$this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2469
+					', ',
2470
+					$attendee->full_address_as_array()
2471
+				);
2472
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2473
+					array(
2474
+						'action' => 'edit_attendee',
2475
+						'post'   => $attendee->ID(),
2476
+					),
2477
+					REG_ADMIN_URL
2478
+				);
2479
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2480
+					? $registration->event_obj()->name()
2481
+					: '';
2482
+				$att_nmbr++;
2483
+			}
2484
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2485
+		}
2486
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2487
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2488
+	}
2489
+
2490
+
2491
+	/**
2492
+	 *        generates HTML for the Edit Registration side meta box
2493
+	 *
2494
+	 * @access public
2495
+	 * @return void
2496
+	 * @throws DomainException
2497
+	 * @throws EE_Error
2498
+	 * @throws InvalidArgumentException
2499
+	 * @throws InvalidDataTypeException
2500
+	 * @throws InvalidInterfaceException
2501
+	 * @throws ReflectionException
2502
+	 */
2503
+	public function _reg_registrant_side_meta_box()
2504
+	{
2505
+		/*@var $attendee EE_Attendee */
2506
+		$att_check = $this->_registration->attendee();
2507
+		$attendee = $att_check instanceof EE_Attendee
2508
+			? $att_check
2509
+			: $this->getAttendeeModel()->create_default_object();
2510
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2511
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2512
+		// primary registration object (that way we know if we need to show create button or not)
2513
+		if (! $this->_registration->is_primary_registrant()) {
2514
+			$primary_registration = $this->_registration->get_primary_registration();
2515
+			$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2516
+				: null;
2517
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2518
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2519
+				// custom attendee object so let's not worry about the primary reg.
2520
+				$primary_registration = null;
2521
+			}
2522
+		} else {
2523
+			$primary_registration = null;
2524
+		}
2525
+		$this->_template_args['ATT_ID'] = $attendee->ID();
2526
+		$this->_template_args['fname'] = $attendee->fname();
2527
+		$this->_template_args['lname'] = $attendee->lname();
2528
+		$this->_template_args['email'] = $attendee->email();
2529
+		$this->_template_args['phone'] = $attendee->phone();
2530
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2531
+		// edit link
2532
+		$this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2533
+			array(
2534
+				'action' => 'edit_attendee',
2535
+				'post'   => $attendee->ID(),
2536
+			),
2537
+			REG_ADMIN_URL
2538
+		);
2539
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2540
+		// create link
2541
+		$this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2542
+			? EE_Admin_Page::add_query_args_and_nonce(
2543
+				array(
2544
+					'action'  => 'duplicate_attendee',
2545
+					'_REG_ID' => $this->_registration->ID(),
2546
+				),
2547
+				REG_ADMIN_URL
2548
+			) : '';
2549
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2550
+		$this->_template_args['att_check'] = $att_check;
2551
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2552
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2553
+	}
2554
+
2555
+
2556
+	/**
2557
+	 * trash or restore registrations
2558
+	 *
2559
+	 * @param  boolean $trash whether to archive or restore
2560
+	 * @return void
2561
+	 * @throws EE_Error
2562
+	 * @throws InvalidArgumentException
2563
+	 * @throws InvalidDataTypeException
2564
+	 * @throws InvalidInterfaceException
2565
+	 * @throws RuntimeException
2566
+	 * @access protected
2567
+	 */
2568
+	protected function _trash_or_restore_registrations($trash = true)
2569
+	{
2570
+		// if empty _REG_ID then get out because there's nothing to do
2571
+		if (empty($this->_req_data['_REG_ID'])) {
2572
+			EE_Error::add_error(
2573
+				sprintf(
2574
+					esc_html__(
2575
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2576
+						'event_espresso'
2577
+					),
2578
+					$trash ? 'trash' : 'restore'
2579
+				),
2580
+				__FILE__,
2581
+				__LINE__,
2582
+				__FUNCTION__
2583
+			);
2584
+			$this->_redirect_after_action(false, '', '', array(), true);
2585
+		}
2586
+		$success = 0;
2587
+		$overwrite_msgs = false;
2588
+		// Checkboxes
2589
+		if (! is_array($this->_req_data['_REG_ID'])) {
2590
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2591
+		}
2592
+		$reg_count = count($this->_req_data['_REG_ID']);
2593
+		// cycle thru checkboxes
2594
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2595
+			/** @var EE_Registration $REG */
2596
+			$REG = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2597
+			$payments = $REG->registration_payments();
2598
+			if (! empty($payments)) {
2599
+				$name = $REG->attendee() instanceof EE_Attendee
2600
+					? $REG->attendee()->full_name()
2601
+					: esc_html__('Unknown Attendee', 'event_espresso');
2602
+				$overwrite_msgs = true;
2603
+				EE_Error::add_error(
2604
+					sprintf(
2605
+						esc_html__(
2606
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2607
+							'event_espresso'
2608
+						),
2609
+						$name
2610
+					),
2611
+					__FILE__,
2612
+					__FUNCTION__,
2613
+					__LINE__
2614
+				);
2615
+				// can't trash this registration because it has payments.
2616
+				continue;
2617
+			}
2618
+			$updated = $trash ? $REG->delete() : $REG->restore();
2619
+			if ($updated) {
2620
+				$success++;
2621
+			}
2622
+		}
2623
+		$this->_redirect_after_action(
2624
+			$success === $reg_count, // were ALL registrations affected?
2625
+			$success > 1
2626
+				? esc_html__('Registrations', 'event_espresso')
2627
+				: esc_html__('Registration', 'event_espresso'),
2628
+			$trash
2629
+				? esc_html__('moved to the trash', 'event_espresso')
2630
+				: esc_html__('restored', 'event_espresso'),
2631
+			$this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2632
+			$overwrite_msgs
2633
+		);
2634
+	}
2635
+
2636
+
2637
+	/**
2638
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2639
+	 * registration but also.
2640
+	 * 1. Removing relations to EE_Attendee
2641
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2642
+	 * ALSO trashed.
2643
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2644
+	 * 4. Removing relationships between all tickets and the related registrations
2645
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2646
+	 * 6. Deleting permanently any related Checkins.
2647
+	 *
2648
+	 * @return void
2649
+	 * @throws EE_Error
2650
+	 * @throws InvalidArgumentException
2651
+	 * @throws InvalidDataTypeException
2652
+	 * @throws InvalidInterfaceException
2653
+	 * @throws ReflectionException
2654
+	 */
2655
+	protected function _delete_registrations()
2656
+	{
2657
+		$REG_MDL = $this->getRegistrationModel();
2658
+		$success = 1;
2659
+		// Checkboxes
2660
+		if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2661
+			// if array has more than one element than success message should be plural
2662
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2663
+			// cycle thru checkboxes
2664
+			foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2665
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2666
+				if (! $REG instanceof EE_Registration) {
2667
+					continue;
2668
+				}
2669
+				$deleted = $this->_delete_registration($REG);
2670
+				if (! $deleted) {
2671
+					$success = 0;
2672
+				}
2673
+			}
2674
+		} else {
2675
+			// grab single id and delete
2676
+			$REG_ID = $this->_req_data['_REG_ID'];
2677
+			/** @var EE_Registration $REG */
2678
+			$REG = $REG_MDL->get_one_by_ID($REG_ID);
2679
+			$deleted = $this->_delete_registration($REG);
2680
+			if (! $deleted) {
2681
+				$success = 0;
2682
+			}
2683
+		}
2684
+		$what = $success > 1
2685
+			? esc_html__('Registrations', 'event_espresso')
2686
+			: esc_html__('Registration', 'event_espresso');
2687
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2688
+		$this->_redirect_after_action(
2689
+			$success,
2690
+			$what,
2691
+			$action_desc,
2692
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2693
+			true
2694
+		);
2695
+	}
2696
+
2697
+
2698
+	/**
2699
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2700
+	 * models get affected.
2701
+	 *
2702
+	 * @param EE_Registration $REG registration to be deleted permanently
2703
+	 * @return bool true = successful deletion, false = fail.
2704
+	 * @throws EE_Error
2705
+	 * @throws InvalidArgumentException
2706
+	 * @throws InvalidDataTypeException
2707
+	 * @throws InvalidInterfaceException
2708
+	 * @throws ReflectionException
2709
+	 */
2710
+	protected function _delete_registration(EE_Registration $REG)
2711
+	{
2712
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2713
+		// registrations on the transaction that are NOT trashed.
2714
+		$TXN = $REG->get_first_related('Transaction');
2715
+		$REGS = $TXN->get_many_related('Registration');
2716
+		$all_trashed = true;
2717
+		foreach ($REGS as $registration) {
2718
+			if (! $registration->get('REG_deleted')) {
2719
+				$all_trashed = false;
2720
+			}
2721
+		}
2722
+		if (! $all_trashed) {
2723
+			EE_Error::add_error(
2724
+				esc_html__(
2725
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2726
+					'event_espresso'
2727
+				),
2728
+				__FILE__,
2729
+				__FUNCTION__,
2730
+				__LINE__
2731
+			);
2732
+			return false;
2733
+		}
2734
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2735
+		// separately from THIS one).
2736
+		foreach ($REGS as $registration) {
2737
+			// delete related answers
2738
+			$registration->delete_related_permanently('Answer');
2739
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2740
+			$attendee = $registration->get_first_related('Attendee');
2741
+			if ($attendee instanceof EE_Attendee) {
2742
+				$registration->_remove_relation_to($attendee, 'Attendee');
2743
+			}
2744
+			// now remove relationships to tickets on this registration.
2745
+			$registration->_remove_relations('Ticket');
2746
+			// now delete permanently the checkins related to this registration.
2747
+			$registration->delete_related_permanently('Checkin');
2748
+			if ($registration->ID() === $REG->ID()) {
2749
+				continue;
2750
+			} //we don't want to delete permanently the existing registration just yet.
2751
+			// remove relation to transaction for these registrations if NOT the existing registrations
2752
+			$registration->_remove_relations('Transaction');
2753
+			// delete permanently any related messages.
2754
+			$registration->delete_related_permanently('Message');
2755
+			// now delete this registration permanently
2756
+			$registration->delete_permanently();
2757
+		}
2758
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2759
+		// (the transaction and line items should be all that's left).
2760
+		// delete the line items related to the transaction for this registration.
2761
+		$TXN->delete_related_permanently('Line_Item');
2762
+		// we need to remove all the relationships on the transaction
2763
+		$TXN->delete_related_permanently('Payment');
2764
+		$TXN->delete_related_permanently('Extra_Meta');
2765
+		$TXN->delete_related_permanently('Message');
2766
+		// now we can delete this REG permanently (and the transaction of course)
2767
+		$REG->delete_related_permanently('Transaction');
2768
+		return $REG->delete_permanently();
2769
+	}
2770
+
2771
+
2772
+	/**
2773
+	 *    generates HTML for the Register New Attendee Admin page
2774
+	 *
2775
+	 * @access private
2776
+	 * @throws DomainException
2777
+	 * @throws EE_Error
2778
+	 * @throws InvalidArgumentException
2779
+	 * @throws InvalidDataTypeException
2780
+	 * @throws InvalidInterfaceException
2781
+	 * @throws ReflectionException
2782
+	 */
2783
+	public function new_registration()
2784
+	{
2785
+		if (! $this->_set_reg_event()) {
2786
+			throw new EE_Error(
2787
+				esc_html__(
2788
+					'Unable to continue with registering because there is no Event ID in the request',
2789
+					'event_espresso'
2790
+				)
2791
+			);
2792
+		}
2793
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2794
+		// gotta start with a clean slate if we're not coming here via ajax
2795
+		if (! defined('DOING_AJAX')
2796
+			&& (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2797
+		) {
2798
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2799
+		}
2800
+		$this->_template_args['event_name'] = '';
2801
+		// event name
2802
+		if ($this->_reg_event) {
2803
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2804
+			$edit_event_url = self::add_query_args_and_nonce(
2805
+				array(
2806
+					'action' => 'edit',
2807
+					'post'   => $this->_reg_event->ID(),
2808
+				),
2809
+				EVENTS_ADMIN_URL
2810
+			);
2811
+			$edit_event_lnk = '<a href="'
2812
+							  . $edit_event_url
2813
+							  . '" title="'
2814
+							  . esc_attr__('Edit ', 'event_espresso')
2815
+							  . $this->_reg_event->name()
2816
+							  . '">'
2817
+							  . esc_html__('Edit Event', 'event_espresso')
2818
+							  . '</a>';
2819
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2820
+												   . $edit_event_lnk
2821
+												   . '</span>';
2822
+		}
2823
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2824
+		if (defined('DOING_AJAX')) {
2825
+			$this->_return_json();
2826
+		}
2827
+		// grab header
2828
+		$template_path =
2829
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2830
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2831
+			$template_path,
2832
+			$this->_template_args,
2833
+			true
2834
+		);
2835
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2836
+		// the details template wrapper
2837
+		$this->display_admin_page_with_sidebar();
2838
+	}
2839
+
2840
+
2841
+	/**
2842
+	 * This returns the content for a registration step
2843
+	 *
2844
+	 * @access protected
2845
+	 * @return string html
2846
+	 * @throws DomainException
2847
+	 * @throws EE_Error
2848
+	 * @throws InvalidArgumentException
2849
+	 * @throws InvalidDataTypeException
2850
+	 * @throws InvalidInterfaceException
2851
+	 */
2852
+	protected function _get_registration_step_content()
2853
+	{
2854
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2855
+			$warning_msg = sprintf(
2856
+				esc_html__(
2857
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2858
+					'event_espresso'
2859
+				),
2860
+				'<br />',
2861
+				'<h3 class="important-notice">',
2862
+				'</h3>',
2863
+				'<div class="float-right">',
2864
+				'<span id="redirect_timer" class="important-notice">30</span>',
2865
+				'</div>',
2866
+				'<b>',
2867
+				'</b>'
2868
+			);
2869
+			return '
2870 2870
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2871 2871
 	<script >
2872 2872
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2879,868 +2879,868 @@  discard block
 block discarded – undo
2879 2879
 	        }
2880 2880
 	    }, 800 );
2881 2881
 	</script >';
2882
-        }
2883
-        $template_args = array(
2884
-            'title'                    => '',
2885
-            'content'                  => '',
2886
-            'step_button_text'         => '',
2887
-            'show_notification_toggle' => false,
2888
-        );
2889
-        // to indicate we're processing a new registration
2890
-        $hidden_fields = array(
2891
-            'processing_registration' => array(
2892
-                'type'  => 'hidden',
2893
-                'value' => 0,
2894
-            ),
2895
-            'event_id'                => array(
2896
-                'type'  => 'hidden',
2897
-                'value' => $this->_reg_event->ID(),
2898
-            ),
2899
-        );
2900
-        // if the cart is empty then we know we're at step one so we'll display ticket selector
2901
-        $cart = EE_Registry::instance()->SSN->cart();
2902
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2903
-        switch ($step) {
2904
-            case 'ticket':
2905
-                $hidden_fields['processing_registration']['value'] = 1;
2906
-                $template_args['title'] = esc_html__(
2907
-                    'Step One: Select the Ticket for this registration',
2908
-                    'event_espresso'
2909
-                );
2910
-                $template_args['content'] =
2911
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2912
-                $template_args['content'] .= '</div>';
2913
-                $template_args['step_button_text'] = esc_html__(
2914
-                    'Add Tickets and Continue to Registrant Details',
2915
-                    'event_espresso'
2916
-                );
2917
-                $template_args['show_notification_toggle'] = false;
2918
-                break;
2919
-            case 'questions':
2920
-                $hidden_fields['processing_registration']['value'] = 2;
2921
-                $template_args['title'] = esc_html__(
2922
-                    'Step Two: Add Registrant Details for this Registration',
2923
-                    'event_espresso'
2924
-                );
2925
-                // in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2926
-                // properly by the first process_reg_step run.
2927
-                $template_args['content'] =
2928
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
2929
-                $template_args['step_button_text'] = esc_html__(
2930
-                    'Save Registration and Continue to Details',
2931
-                    'event_espresso'
2932
-                );
2933
-                $template_args['show_notification_toggle'] = true;
2934
-                break;
2935
-        }
2936
-        // we come back to the process_registration_step route.
2937
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2938
-        return EEH_Template::display_template(
2939
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2940
-            $template_args,
2941
-            true
2942
-        );
2943
-    }
2944
-
2945
-
2946
-    /**
2947
-     *        set_reg_event
2948
-     *
2949
-     * @access private
2950
-     * @return bool
2951
-     * @throws EE_Error
2952
-     * @throws InvalidArgumentException
2953
-     * @throws InvalidDataTypeException
2954
-     * @throws InvalidInterfaceException
2955
-     */
2956
-    private function _set_reg_event()
2957
-    {
2958
-        if (is_object($this->_reg_event)) {
2959
-            return true;
2960
-        }
2961
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2962
-        if (! $EVT_ID) {
2963
-            return false;
2964
-        }
2965
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2966
-        return true;
2967
-    }
2968
-
2969
-
2970
-    /**
2971
-     * process_reg_step
2972
-     *
2973
-     * @access        public
2974
-     * @return string
2975
-     * @throws DomainException
2976
-     * @throws EE_Error
2977
-     * @throws InvalidArgumentException
2978
-     * @throws InvalidDataTypeException
2979
-     * @throws InvalidInterfaceException
2980
-     * @throws ReflectionException
2981
-     * @throws RuntimeException
2982
-     */
2983
-    public function process_reg_step()
2984
-    {
2985
-        EE_System::do_not_cache();
2986
-        $this->_set_reg_event();
2987
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2988
-        EE_Registry::instance()->REQ->set('uts', time());
2989
-        // what step are we on?
2990
-        $cart = EE_Registry::instance()->SSN->cart();
2991
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2992
-        // if doing ajax then we need to verify the nonce
2993
-        if (defined('DOING_AJAX')) {
2994
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
2995
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
2996
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2997
-        }
2998
-        switch ($step) {
2999
-            case 'ticket':
3000
-                // process ticket selection
3001
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3002
-                if ($success) {
3003
-                    EE_Error::add_success(
3004
-                        esc_html__(
3005
-                            'Tickets Selected. Now complete the registration.',
3006
-                            'event_espresso'
3007
-                        )
3008
-                    );
3009
-                } else {
3010
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3011
-                }
3012
-                if (defined('DOING_AJAX')) {
3013
-                    $this->new_registration(); // display next step
3014
-                } else {
3015
-                    $query_args = array(
3016
-                        'action'                  => 'new_registration',
3017
-                        'processing_registration' => 1,
3018
-                        'event_id'                => $this->_reg_event->ID(),
3019
-                        'uts'                     => time(),
3020
-                    );
3021
-                    $this->_redirect_after_action(
3022
-                        false,
3023
-                        '',
3024
-                        '',
3025
-                        $query_args,
3026
-                        true
3027
-                    );
3028
-                }
3029
-                break;
3030
-            case 'questions':
3031
-                if (! isset(
3032
-                    $this->_req_data['txn_reg_status_change'],
3033
-                    $this->_req_data['txn_reg_status_change']['send_notifications']
3034
-                )
3035
-                ) {
3036
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3037
-                }
3038
-                // process registration
3039
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3040
-                if ($cart instanceof EE_Cart) {
3041
-                    $grand_total = $cart->get_cart_grand_total();
3042
-                    if ($grand_total instanceof EE_Line_Item) {
3043
-                        $grand_total->save_this_and_descendants_to_txn();
3044
-                    }
3045
-                }
3046
-                if (! $transaction instanceof EE_Transaction) {
3047
-                    $query_args = array(
3048
-                        'action'                  => 'new_registration',
3049
-                        'processing_registration' => 2,
3050
-                        'event_id'                => $this->_reg_event->ID(),
3051
-                        'uts'                     => time(),
3052
-                    );
3053
-                    if (defined('DOING_AJAX')) {
3054
-                        // display registration form again because there are errors (maybe validation?)
3055
-                        $this->new_registration();
3056
-                        return;
3057
-                    }
3058
-                    $this->_redirect_after_action(
3059
-                        false,
3060
-                        '',
3061
-                        '',
3062
-                        $query_args,
3063
-                        true
3064
-                    );
3065
-                    return;
3066
-                }
3067
-                // maybe update status, and make sure to save transaction if not done already
3068
-                if (! $transaction->update_status_based_on_total_paid()) {
3069
-                    $transaction->save();
3070
-                }
3071
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3072
-                $this->_req_data = array();
3073
-                $query_args = array(
3074
-                    'action'        => 'redirect_to_txn',
3075
-                    'TXN_ID'        => $transaction->ID(),
3076
-                    'EVT_ID'        => $this->_reg_event->ID(),
3077
-                    'event_name'    => urlencode($this->_reg_event->name()),
3078
-                    'redirect_from' => 'new_registration',
3079
-                );
3080
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3081
-                break;
3082
-        }
3083
-        // what are you looking here for?  Should be nothing to do at this point.
3084
-    }
3085
-
3086
-
3087
-    /**
3088
-     * redirect_to_txn
3089
-     *
3090
-     * @access public
3091
-     * @return void
3092
-     * @throws EE_Error
3093
-     * @throws InvalidArgumentException
3094
-     * @throws InvalidDataTypeException
3095
-     * @throws InvalidInterfaceException
3096
-     * @throws ReflectionException
3097
-     */
3098
-    public function redirect_to_txn()
3099
-    {
3100
-        EE_System::do_not_cache();
3101
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3102
-        $query_args = array(
3103
-            'action' => 'view_transaction',
3104
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3105
-            'page'   => 'espresso_transactions',
3106
-        );
3107
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3108
-            $query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3109
-            $query_args['event_name'] = urlencode($this->_req_data['event_name']);
3110
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3111
-        }
3112
-        EE_Error::add_success(
3113
-            esc_html__(
3114
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3115
-                'event_espresso'
3116
-            )
3117
-        );
3118
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3119
-    }
3120
-
3121
-
3122
-    /**
3123
-     *        generates HTML for the Attendee Contact List
3124
-     *
3125
-     * @access protected
3126
-     * @return void
3127
-     * @throws DomainException
3128
-     * @throws EE_Error
3129
-     */
3130
-    protected function _attendee_contact_list_table()
3131
-    {
3132
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3133
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3134
-        $this->display_admin_list_table_page_with_no_sidebar();
3135
-    }
3136
-
3137
-
3138
-    /**
3139
-     *        get_attendees
3140
-     *
3141
-     * @param      $per_page
3142
-     * @param bool $count whether to return count or data.
3143
-     * @param bool $trash
3144
-     * @return array
3145
-     * @throws EE_Error
3146
-     * @throws InvalidArgumentException
3147
-     * @throws InvalidDataTypeException
3148
-     * @throws InvalidInterfaceException
3149
-     * @access public
3150
-     */
3151
-    public function get_attendees($per_page, $count = false, $trash = false)
3152
-    {
3153
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3154
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3155
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3156
-        switch ($this->_req_data['orderby']) {
3157
-            case 'ATT_ID':
3158
-                $orderby = 'ATT_ID';
3159
-                break;
3160
-            case 'ATT_fname':
3161
-                $orderby = 'ATT_fname';
3162
-                break;
3163
-            case 'ATT_email':
3164
-                $orderby = 'ATT_email';
3165
-                break;
3166
-            case 'ATT_city':
3167
-                $orderby = 'ATT_city';
3168
-                break;
3169
-            case 'STA_ID':
3170
-                $orderby = 'STA_ID';
3171
-                break;
3172
-            case 'CNT_ID':
3173
-                $orderby = 'CNT_ID';
3174
-                break;
3175
-            case 'Registration_Count':
3176
-                $orderby = 'Registration_Count';
3177
-                break;
3178
-            default:
3179
-                $orderby = 'ATT_lname';
3180
-        }
3181
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3182
-            ? $this->_req_data['order']
3183
-            : 'ASC';
3184
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3185
-            ? $this->_req_data['paged']
3186
-            : 1;
3187
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3188
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3189
-            ? $this->_req_data['perpage']
3190
-            : $per_page;
3191
-        $_where = array();
3192
-        if (! empty($this->_req_data['s'])) {
3193
-            $sstr = '%' . $this->_req_data['s'] . '%';
3194
-            $_where['OR'] = array(
3195
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3196
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3197
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3198
-                'ATT_fname'                         => array('LIKE', $sstr),
3199
-                'ATT_lname'                         => array('LIKE', $sstr),
3200
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3201
-                'ATT_email'                         => array('LIKE', $sstr),
3202
-                'ATT_address'                       => array('LIKE', $sstr),
3203
-                'ATT_address2'                      => array('LIKE', $sstr),
3204
-                'ATT_city'                          => array('LIKE', $sstr),
3205
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3206
-                'State.STA_name'                    => array('LIKE', $sstr),
3207
-                'ATT_phone'                         => array('LIKE', $sstr),
3208
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3209
-                'Registration.REG_code'             => array('LIKE', $sstr),
3210
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3211
-            );
3212
-        }
3213
-        $offset = ($current_page - 1) * $per_page;
3214
-        $limit = $count ? null : array($offset, $per_page);
3215
-        $query_args = array(
3216
-            $_where,
3217
-            'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3218
-            'limit'         => $limit,
3219
-        );
3220
-        if (! $count) {
3221
-            $query_args['order_by'] = array($orderby => $sort);
3222
-        }
3223
-        if ($trash) {
3224
-            $query_args[0]['status'] = array('!=', 'publish');
3225
-            $all_attendees = $count
3226
-                ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3227
-                : $this->getAttendeeModel()->get_all($query_args);
3228
-        } else {
3229
-            $query_args[0]['status'] = array('IN', array('publish'));
3230
-            $all_attendees = $count
3231
-                ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3232
-                : $this->getAttendeeModel()->get_all($query_args);
3233
-        }
3234
-        return $all_attendees;
3235
-    }
3236
-
3237
-
3238
-    /**
3239
-     * This is just taking care of resending the registration confirmation
3240
-     *
3241
-     * @access protected
3242
-     * @return void
3243
-     * @throws EE_Error
3244
-     * @throws InvalidArgumentException
3245
-     * @throws InvalidDataTypeException
3246
-     * @throws InvalidInterfaceException
3247
-     * @throws ReflectionException
3248
-     */
3249
-    protected function _resend_registration()
3250
-    {
3251
-        $this->_process_resend_registration();
3252
-        $query_args = isset($this->_req_data['redirect_to'])
3253
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3254
-            : array('action' => 'default');
3255
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3256
-    }
3257
-
3258
-    /**
3259
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3260
-     * to use when selecting registrations
3261
-     *
3262
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3263
-     *                                                     the query parameters from the request
3264
-     * @return void ends the request with a redirect or download
3265
-     */
3266
-    public function _registrations_report_base($method_name_for_getting_query_params)
3267
-    {
3268
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3269
-            wp_redirect(
3270
-                EE_Admin_Page::add_query_args_and_nonce(
3271
-                    array(
3272
-                        'page'        => 'espresso_batch',
3273
-                        'batch'       => 'file',
3274
-                        'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3275
-                        'filters'     => urlencode(
3276
-                            serialize(
3277
-                                $this->$method_name_for_getting_query_params(
3278
-                                    EEH_Array::is_set(
3279
-                                        $this->_req_data,
3280
-                                        'filters',
3281
-                                        array()
3282
-                                    )
3283
-                                )
3284
-                            )
3285
-                        ),
3286
-                        'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3287
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3288
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3289
-                    )
3290
-                )
3291
-            );
3292
-        } else {
3293
-            $new_request_args = array(
3294
-                'export' => 'report',
3295
-                'action' => 'registrations_report_for_event',
3296
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3297
-            );
3298
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3299
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3300
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3301
-                $EE_Export = EE_Export::instance($this->_req_data);
3302
-                $EE_Export->export();
3303
-            }
3304
-        }
3305
-    }
3306
-
3307
-
3308
-    /**
3309
-     * Creates a registration report using only query parameters in the request
3310
-     *
3311
-     * @return void
3312
-     */
3313
-    public function _registrations_report()
3314
-    {
3315
-        $this->_registrations_report_base('_get_registration_query_parameters');
3316
-    }
3317
-
3318
-
3319
-    public function _contact_list_export()
3320
-    {
3321
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3322
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3323
-            $EE_Export = EE_Export::instance($this->_req_data);
3324
-            $EE_Export->export_attendees();
3325
-        }
3326
-    }
3327
-
3328
-
3329
-    public function _contact_list_report()
3330
-    {
3331
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3332
-            wp_redirect(
3333
-                EE_Admin_Page::add_query_args_and_nonce(
3334
-                    array(
3335
-                        'page'        => 'espresso_batch',
3336
-                        'batch'       => 'file',
3337
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3338
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3339
-                    )
3340
-                )
3341
-            );
3342
-        } else {
3343
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3344
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3345
-                $EE_Export = EE_Export::instance($this->_req_data);
3346
-                $EE_Export->report_attendees();
3347
-            }
3348
-        }
3349
-    }
3350
-
3351
-
3352
-
3353
-
3354
-
3355
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3356
-    /**
3357
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3358
-     *
3359
-     * @return void
3360
-     * @throws EE_Error
3361
-     * @throws InvalidArgumentException
3362
-     * @throws InvalidDataTypeException
3363
-     * @throws InvalidInterfaceException
3364
-     * @throws ReflectionException
3365
-     */
3366
-    protected function _duplicate_attendee()
3367
-    {
3368
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3369
-        // verify we have necessary info
3370
-        if (empty($this->_req_data['_REG_ID'])) {
3371
-            EE_Error::add_error(
3372
-                esc_html__(
3373
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3374
-                    'event_espresso'
3375
-                ),
3376
-                __FILE__,
3377
-                __LINE__,
3378
-                __FUNCTION__
3379
-            );
3380
-            $query_args = array('action' => $action);
3381
-            $this->_redirect_after_action('', '', '', $query_args, true);
3382
-        }
3383
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3384
-        $registration = $this->getRegistrationModel()->get_one_by_ID($this->_req_data['_REG_ID']);
3385
-        $attendee = $registration->attendee();
3386
-        // remove relation of existing attendee on registration
3387
-        $registration->_remove_relation_to($attendee, 'Attendee');
3388
-        // new attendee
3389
-        $new_attendee = clone $attendee;
3390
-        $new_attendee->set('ATT_ID', 0);
3391
-        $new_attendee->save();
3392
-        // add new attendee to reg
3393
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3394
-        EE_Error::add_success(
3395
-            esc_html__(
3396
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3397
-                'event_espresso'
3398
-            )
3399
-        );
3400
-        // redirect to edit page for attendee
3401
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3402
-        $this->_redirect_after_action('', '', '', $query_args, true);
3403
-    }
3404
-
3405
-
3406
-    /**
3407
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3408
-     *
3409
-     * @param int     $post_id
3410
-     * @param WP_POST $post
3411
-     * @throws DomainException
3412
-     * @throws EE_Error
3413
-     * @throws InvalidArgumentException
3414
-     * @throws InvalidDataTypeException
3415
-     * @throws InvalidInterfaceException
3416
-     * @throws LogicException
3417
-     * @throws InvalidFormSubmissionException
3418
-     * @throws ReflectionException
3419
-     */
3420
-    protected function _insert_update_cpt_item($post_id, $post)
3421
-    {
3422
-        $success = true;
3423
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3424
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3425
-            : null;
3426
-        // for attendee updates
3427
-        if ($attendee instanceof EE_Attendee) {
3428
-            // note we should only be UPDATING attendees at this point.
3429
-            $updated_fields = array(
3430
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3431
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3432
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3433
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3434
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3435
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3436
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3437
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3438
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3439
-            );
3440
-            foreach ($updated_fields as $field => $value) {
3441
-                $attendee->set($field, $value);
3442
-            }
3443
-
3444
-            // process contact details metabox form handler (which will also save the attendee)
3445
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3446
-            $success = $contact_details_form->process($this->_req_data);
3447
-
3448
-            $attendee_update_callbacks = apply_filters(
3449
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3450
-                array()
3451
-            );
3452
-            foreach ($attendee_update_callbacks as $a_callback) {
3453
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3454
-                    throw new EE_Error(
3455
-                        sprintf(
3456
-                            esc_html__(
3457
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3458
-                                'event_espresso'
3459
-                            ),
3460
-                            $a_callback
3461
-                        )
3462
-                    );
3463
-                }
3464
-            }
3465
-        }
3466
-
3467
-        if ($success === false) {
3468
-            EE_Error::add_error(
3469
-                esc_html__(
3470
-                    'Something went wrong with updating the meta table data for the registration.',
3471
-                    'event_espresso'
3472
-                ),
3473
-                __FILE__,
3474
-                __FUNCTION__,
3475
-                __LINE__
3476
-            );
3477
-        }
3478
-    }
3479
-
3480
-
3481
-    public function trash_cpt_item($post_id)
3482
-    {
3483
-    }
3484
-
3485
-
3486
-    public function delete_cpt_item($post_id)
3487
-    {
3488
-    }
3489
-
3490
-
3491
-    public function restore_cpt_item($post_id)
3492
-    {
3493
-    }
3494
-
3495
-
3496
-    protected function _restore_cpt_item($post_id, $revision_id)
3497
-    {
3498
-    }
3499
-
3500
-
3501
-    /**
3502
-     * @throws EE_Error
3503
-     * @since 4.10.2.p
3504
-     */
3505
-    public function attendee_editor_metaboxes()
3506
-    {
3507
-        $this->verify_cpt_object();
3508
-        remove_meta_box(
3509
-            'postexcerpt',
3510
-            $this->_cpt_routes[ $this->_req_action ],
3511
-            'normal'
3512
-        );
3513
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3514
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3515
-            add_meta_box(
3516
-                'postexcerpt',
3517
-                esc_html__('Short Biography', 'event_espresso'),
3518
-                'post_excerpt_meta_box',
3519
-                $this->_cpt_routes[ $this->_req_action ],
3520
-                'normal'
3521
-            );
3522
-        }
3523
-        if (post_type_supports('espresso_attendees', 'comments')) {
3524
-            add_meta_box(
3525
-                'commentsdiv',
3526
-                esc_html__('Notes on the Contact', 'event_espresso'),
3527
-                'post_comment_meta_box',
3528
-                $this->_cpt_routes[ $this->_req_action ],
3529
-                'normal',
3530
-                'core'
3531
-            );
3532
-        }
3533
-        add_meta_box(
3534
-            'attendee_contact_info',
3535
-            esc_html__('Contact Info', 'event_espresso'),
3536
-            array($this, 'attendee_contact_info'),
3537
-            $this->_cpt_routes[ $this->_req_action ],
3538
-            'side',
3539
-            'core'
3540
-        );
3541
-        add_meta_box(
3542
-            'attendee_details_address',
3543
-            esc_html__('Address Details', 'event_espresso'),
3544
-            array($this, 'attendee_address_details'),
3545
-            $this->_cpt_routes[ $this->_req_action ],
3546
-            'normal',
3547
-            'core'
3548
-        );
3549
-        add_meta_box(
3550
-            'attendee_registrations',
3551
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3552
-            array($this, 'attendee_registrations_meta_box'),
3553
-            $this->_cpt_routes[ $this->_req_action ],
3554
-            'normal',
3555
-            'high'
3556
-        );
3557
-    }
3558
-
3559
-
3560
-    /**
3561
-     * Metabox for attendee contact info
3562
-     *
3563
-     * @param  WP_Post $post wp post object
3564
-     * @return string attendee contact info ( and form )
3565
-     * @throws EE_Error
3566
-     * @throws InvalidArgumentException
3567
-     * @throws InvalidDataTypeException
3568
-     * @throws InvalidInterfaceException
3569
-     * @throws LogicException
3570
-     * @throws DomainException
3571
-     */
3572
-    public function attendee_contact_info($post)
3573
-    {
3574
-        // get attendee object ( should already have it )
3575
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3576
-        $form->enqueueStylesAndScripts();
3577
-        echo $form->display();
3578
-    }
3579
-
3580
-
3581
-    /**
3582
-     * Return form handler for the contact details metabox
3583
-     *
3584
-     * @param EE_Attendee $attendee
3585
-     * @return AttendeeContactDetailsMetaboxFormHandler
3586
-     * @throws DomainException
3587
-     * @throws InvalidArgumentException
3588
-     * @throws InvalidDataTypeException
3589
-     * @throws InvalidInterfaceException
3590
-     */
3591
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3592
-    {
3593
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3594
-    }
3595
-
3596
-
3597
-    /**
3598
-     * Metabox for attendee details
3599
-     *
3600
-     * @param  WP_Post $post wp post object
3601
-     * @throws DomainException
3602
-     */
3603
-    public function attendee_address_details($post)
3604
-    {
3605
-        // get attendee object (should already have it)
3606
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3607
-        $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3608
-            new EE_Question_Form_Input(
3609
-                EE_Question::new_instance(
3610
-                    array(
3611
-                        'QST_ID'           => 0,
3612
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3613
-                        'QST_system'       => 'admin-state',
3614
-                    )
3615
-                ),
3616
-                EE_Answer::new_instance(
3617
-                    array(
3618
-                        'ANS_ID'    => 0,
3619
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3620
-                    )
3621
-                ),
3622
-                array(
3623
-                    'input_id'       => 'STA_ID',
3624
-                    'input_name'     => 'STA_ID',
3625
-                    'input_prefix'   => '',
3626
-                    'append_qstn_id' => false,
3627
-                )
3628
-            )
3629
-        );
3630
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3631
-            new EE_Question_Form_Input(
3632
-                EE_Question::new_instance(
3633
-                    array(
3634
-                        'QST_ID'           => 0,
3635
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3636
-                        'QST_system'       => 'admin-country',
3637
-                    )
3638
-                ),
3639
-                EE_Answer::new_instance(
3640
-                    array(
3641
-                        'ANS_ID'    => 0,
3642
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3643
-                    )
3644
-                ),
3645
-                array(
3646
-                    'input_id'       => 'CNT_ISO',
3647
-                    'input_name'     => 'CNT_ISO',
3648
-                    'input_prefix'   => '',
3649
-                    'append_qstn_id' => false,
3650
-                )
3651
-            )
3652
-        );
3653
-        $template =
3654
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3655
-        EEH_Template::display_template($template, $this->_template_args);
3656
-    }
3657
-
3658
-
3659
-    /**
3660
-     *        _attendee_details
3661
-     *
3662
-     * @access protected
3663
-     * @param $post
3664
-     * @return void
3665
-     * @throws DomainException
3666
-     * @throws EE_Error
3667
-     * @throws InvalidArgumentException
3668
-     * @throws InvalidDataTypeException
3669
-     * @throws InvalidInterfaceException
3670
-     * @throws ReflectionException
3671
-     */
3672
-    public function attendee_registrations_meta_box($post)
3673
-    {
3674
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3675
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3676
-        $template =
3677
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3678
-        EEH_Template::display_template($template, $this->_template_args);
3679
-    }
3680
-
3681
-
3682
-    /**
3683
-     * add in the form fields for the attendee edit
3684
-     *
3685
-     * @param  WP_Post $post wp post object
3686
-     * @return string html for new form.
3687
-     * @throws DomainException
3688
-     */
3689
-    public function after_title_form_fields($post)
3690
-    {
3691
-        if ($post->post_type === 'espresso_attendees') {
3692
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3693
-            $template_args['attendee'] = $this->_cpt_model_obj;
3694
-            EEH_Template::display_template($template, $template_args);
3695
-        }
3696
-    }
3697
-
3698
-
3699
-    /**
3700
-     *        _trash_or_restore_attendee
3701
-     *
3702
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3703
-     * @return void
3704
-     * @throws EE_Error
3705
-     * @throws InvalidArgumentException
3706
-     * @throws InvalidDataTypeException
3707
-     * @throws InvalidInterfaceException
3708
-     * @throws ReflectionException
3709
-     * @access protected
3710
-     */
3711
-    protected function _trash_or_restore_attendees($trash = true)
3712
-    {
3713
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3714
-        $success = 1;
3715
-        // Checkboxes
3716
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3717
-            // if array has more than one element than success message should be plural
3718
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3719
-            // cycle thru checkboxes
3720
-            foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3721
-                $updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3722
-                    : $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3723
-                if (! $updated) {
3724
-                    $success = 0;
3725
-                }
3726
-            }
3727
-        } else {
3728
-            // grab single id and delete
3729
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3730
-            // get attendee
3731
-            $att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3732
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3733
-            $updated = $att->save() && $updated;
3734
-            if (! $updated) {
3735
-                $success = 0;
3736
-            }
3737
-        }
3738
-        $what = $success > 1
3739
-            ? esc_html__('Contacts', 'event_espresso')
3740
-            : esc_html__('Contact', 'event_espresso');
3741
-        $action_desc = $trash
3742
-            ? esc_html__('moved to the trash', 'event_espresso')
3743
-            : esc_html__('restored', 'event_espresso');
3744
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3745
-    }
2882
+		}
2883
+		$template_args = array(
2884
+			'title'                    => '',
2885
+			'content'                  => '',
2886
+			'step_button_text'         => '',
2887
+			'show_notification_toggle' => false,
2888
+		);
2889
+		// to indicate we're processing a new registration
2890
+		$hidden_fields = array(
2891
+			'processing_registration' => array(
2892
+				'type'  => 'hidden',
2893
+				'value' => 0,
2894
+			),
2895
+			'event_id'                => array(
2896
+				'type'  => 'hidden',
2897
+				'value' => $this->_reg_event->ID(),
2898
+			),
2899
+		);
2900
+		// if the cart is empty then we know we're at step one so we'll display ticket selector
2901
+		$cart = EE_Registry::instance()->SSN->cart();
2902
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2903
+		switch ($step) {
2904
+			case 'ticket':
2905
+				$hidden_fields['processing_registration']['value'] = 1;
2906
+				$template_args['title'] = esc_html__(
2907
+					'Step One: Select the Ticket for this registration',
2908
+					'event_espresso'
2909
+				);
2910
+				$template_args['content'] =
2911
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2912
+				$template_args['content'] .= '</div>';
2913
+				$template_args['step_button_text'] = esc_html__(
2914
+					'Add Tickets and Continue to Registrant Details',
2915
+					'event_espresso'
2916
+				);
2917
+				$template_args['show_notification_toggle'] = false;
2918
+				break;
2919
+			case 'questions':
2920
+				$hidden_fields['processing_registration']['value'] = 2;
2921
+				$template_args['title'] = esc_html__(
2922
+					'Step Two: Add Registrant Details for this Registration',
2923
+					'event_espresso'
2924
+				);
2925
+				// in theory we should be able to run EED_SPCO at this point because the cart should have been setup
2926
+				// properly by the first process_reg_step run.
2927
+				$template_args['content'] =
2928
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
2929
+				$template_args['step_button_text'] = esc_html__(
2930
+					'Save Registration and Continue to Details',
2931
+					'event_espresso'
2932
+				);
2933
+				$template_args['show_notification_toggle'] = true;
2934
+				break;
2935
+		}
2936
+		// we come back to the process_registration_step route.
2937
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2938
+		return EEH_Template::display_template(
2939
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2940
+			$template_args,
2941
+			true
2942
+		);
2943
+	}
2944
+
2945
+
2946
+	/**
2947
+	 *        set_reg_event
2948
+	 *
2949
+	 * @access private
2950
+	 * @return bool
2951
+	 * @throws EE_Error
2952
+	 * @throws InvalidArgumentException
2953
+	 * @throws InvalidDataTypeException
2954
+	 * @throws InvalidInterfaceException
2955
+	 */
2956
+	private function _set_reg_event()
2957
+	{
2958
+		if (is_object($this->_reg_event)) {
2959
+			return true;
2960
+		}
2961
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2962
+		if (! $EVT_ID) {
2963
+			return false;
2964
+		}
2965
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2966
+		return true;
2967
+	}
2968
+
2969
+
2970
+	/**
2971
+	 * process_reg_step
2972
+	 *
2973
+	 * @access        public
2974
+	 * @return string
2975
+	 * @throws DomainException
2976
+	 * @throws EE_Error
2977
+	 * @throws InvalidArgumentException
2978
+	 * @throws InvalidDataTypeException
2979
+	 * @throws InvalidInterfaceException
2980
+	 * @throws ReflectionException
2981
+	 * @throws RuntimeException
2982
+	 */
2983
+	public function process_reg_step()
2984
+	{
2985
+		EE_System::do_not_cache();
2986
+		$this->_set_reg_event();
2987
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2988
+		EE_Registry::instance()->REQ->set('uts', time());
2989
+		// what step are we on?
2990
+		$cart = EE_Registry::instance()->SSN->cart();
2991
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2992
+		// if doing ajax then we need to verify the nonce
2993
+		if (defined('DOING_AJAX')) {
2994
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
2995
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
2996
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2997
+		}
2998
+		switch ($step) {
2999
+			case 'ticket':
3000
+				// process ticket selection
3001
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3002
+				if ($success) {
3003
+					EE_Error::add_success(
3004
+						esc_html__(
3005
+							'Tickets Selected. Now complete the registration.',
3006
+							'event_espresso'
3007
+						)
3008
+					);
3009
+				} else {
3010
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3011
+				}
3012
+				if (defined('DOING_AJAX')) {
3013
+					$this->new_registration(); // display next step
3014
+				} else {
3015
+					$query_args = array(
3016
+						'action'                  => 'new_registration',
3017
+						'processing_registration' => 1,
3018
+						'event_id'                => $this->_reg_event->ID(),
3019
+						'uts'                     => time(),
3020
+					);
3021
+					$this->_redirect_after_action(
3022
+						false,
3023
+						'',
3024
+						'',
3025
+						$query_args,
3026
+						true
3027
+					);
3028
+				}
3029
+				break;
3030
+			case 'questions':
3031
+				if (! isset(
3032
+					$this->_req_data['txn_reg_status_change'],
3033
+					$this->_req_data['txn_reg_status_change']['send_notifications']
3034
+				)
3035
+				) {
3036
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3037
+				}
3038
+				// process registration
3039
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3040
+				if ($cart instanceof EE_Cart) {
3041
+					$grand_total = $cart->get_cart_grand_total();
3042
+					if ($grand_total instanceof EE_Line_Item) {
3043
+						$grand_total->save_this_and_descendants_to_txn();
3044
+					}
3045
+				}
3046
+				if (! $transaction instanceof EE_Transaction) {
3047
+					$query_args = array(
3048
+						'action'                  => 'new_registration',
3049
+						'processing_registration' => 2,
3050
+						'event_id'                => $this->_reg_event->ID(),
3051
+						'uts'                     => time(),
3052
+					);
3053
+					if (defined('DOING_AJAX')) {
3054
+						// display registration form again because there are errors (maybe validation?)
3055
+						$this->new_registration();
3056
+						return;
3057
+					}
3058
+					$this->_redirect_after_action(
3059
+						false,
3060
+						'',
3061
+						'',
3062
+						$query_args,
3063
+						true
3064
+					);
3065
+					return;
3066
+				}
3067
+				// maybe update status, and make sure to save transaction if not done already
3068
+				if (! $transaction->update_status_based_on_total_paid()) {
3069
+					$transaction->save();
3070
+				}
3071
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3072
+				$this->_req_data = array();
3073
+				$query_args = array(
3074
+					'action'        => 'redirect_to_txn',
3075
+					'TXN_ID'        => $transaction->ID(),
3076
+					'EVT_ID'        => $this->_reg_event->ID(),
3077
+					'event_name'    => urlencode($this->_reg_event->name()),
3078
+					'redirect_from' => 'new_registration',
3079
+				);
3080
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3081
+				break;
3082
+		}
3083
+		// what are you looking here for?  Should be nothing to do at this point.
3084
+	}
3085
+
3086
+
3087
+	/**
3088
+	 * redirect_to_txn
3089
+	 *
3090
+	 * @access public
3091
+	 * @return void
3092
+	 * @throws EE_Error
3093
+	 * @throws InvalidArgumentException
3094
+	 * @throws InvalidDataTypeException
3095
+	 * @throws InvalidInterfaceException
3096
+	 * @throws ReflectionException
3097
+	 */
3098
+	public function redirect_to_txn()
3099
+	{
3100
+		EE_System::do_not_cache();
3101
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3102
+		$query_args = array(
3103
+			'action' => 'view_transaction',
3104
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3105
+			'page'   => 'espresso_transactions',
3106
+		);
3107
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3108
+			$query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3109
+			$query_args['event_name'] = urlencode($this->_req_data['event_name']);
3110
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3111
+		}
3112
+		EE_Error::add_success(
3113
+			esc_html__(
3114
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3115
+				'event_espresso'
3116
+			)
3117
+		);
3118
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3119
+	}
3120
+
3121
+
3122
+	/**
3123
+	 *        generates HTML for the Attendee Contact List
3124
+	 *
3125
+	 * @access protected
3126
+	 * @return void
3127
+	 * @throws DomainException
3128
+	 * @throws EE_Error
3129
+	 */
3130
+	protected function _attendee_contact_list_table()
3131
+	{
3132
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3133
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3134
+		$this->display_admin_list_table_page_with_no_sidebar();
3135
+	}
3136
+
3137
+
3138
+	/**
3139
+	 *        get_attendees
3140
+	 *
3141
+	 * @param      $per_page
3142
+	 * @param bool $count whether to return count or data.
3143
+	 * @param bool $trash
3144
+	 * @return array
3145
+	 * @throws EE_Error
3146
+	 * @throws InvalidArgumentException
3147
+	 * @throws InvalidDataTypeException
3148
+	 * @throws InvalidInterfaceException
3149
+	 * @access public
3150
+	 */
3151
+	public function get_attendees($per_page, $count = false, $trash = false)
3152
+	{
3153
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3154
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3155
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3156
+		switch ($this->_req_data['orderby']) {
3157
+			case 'ATT_ID':
3158
+				$orderby = 'ATT_ID';
3159
+				break;
3160
+			case 'ATT_fname':
3161
+				$orderby = 'ATT_fname';
3162
+				break;
3163
+			case 'ATT_email':
3164
+				$orderby = 'ATT_email';
3165
+				break;
3166
+			case 'ATT_city':
3167
+				$orderby = 'ATT_city';
3168
+				break;
3169
+			case 'STA_ID':
3170
+				$orderby = 'STA_ID';
3171
+				break;
3172
+			case 'CNT_ID':
3173
+				$orderby = 'CNT_ID';
3174
+				break;
3175
+			case 'Registration_Count':
3176
+				$orderby = 'Registration_Count';
3177
+				break;
3178
+			default:
3179
+				$orderby = 'ATT_lname';
3180
+		}
3181
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3182
+			? $this->_req_data['order']
3183
+			: 'ASC';
3184
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3185
+			? $this->_req_data['paged']
3186
+			: 1;
3187
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3188
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3189
+			? $this->_req_data['perpage']
3190
+			: $per_page;
3191
+		$_where = array();
3192
+		if (! empty($this->_req_data['s'])) {
3193
+			$sstr = '%' . $this->_req_data['s'] . '%';
3194
+			$_where['OR'] = array(
3195
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3196
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3197
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3198
+				'ATT_fname'                         => array('LIKE', $sstr),
3199
+				'ATT_lname'                         => array('LIKE', $sstr),
3200
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3201
+				'ATT_email'                         => array('LIKE', $sstr),
3202
+				'ATT_address'                       => array('LIKE', $sstr),
3203
+				'ATT_address2'                      => array('LIKE', $sstr),
3204
+				'ATT_city'                          => array('LIKE', $sstr),
3205
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3206
+				'State.STA_name'                    => array('LIKE', $sstr),
3207
+				'ATT_phone'                         => array('LIKE', $sstr),
3208
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3209
+				'Registration.REG_code'             => array('LIKE', $sstr),
3210
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3211
+			);
3212
+		}
3213
+		$offset = ($current_page - 1) * $per_page;
3214
+		$limit = $count ? null : array($offset, $per_page);
3215
+		$query_args = array(
3216
+			$_where,
3217
+			'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3218
+			'limit'         => $limit,
3219
+		);
3220
+		if (! $count) {
3221
+			$query_args['order_by'] = array($orderby => $sort);
3222
+		}
3223
+		if ($trash) {
3224
+			$query_args[0]['status'] = array('!=', 'publish');
3225
+			$all_attendees = $count
3226
+				? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3227
+				: $this->getAttendeeModel()->get_all($query_args);
3228
+		} else {
3229
+			$query_args[0]['status'] = array('IN', array('publish'));
3230
+			$all_attendees = $count
3231
+				? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3232
+				: $this->getAttendeeModel()->get_all($query_args);
3233
+		}
3234
+		return $all_attendees;
3235
+	}
3236
+
3237
+
3238
+	/**
3239
+	 * This is just taking care of resending the registration confirmation
3240
+	 *
3241
+	 * @access protected
3242
+	 * @return void
3243
+	 * @throws EE_Error
3244
+	 * @throws InvalidArgumentException
3245
+	 * @throws InvalidDataTypeException
3246
+	 * @throws InvalidInterfaceException
3247
+	 * @throws ReflectionException
3248
+	 */
3249
+	protected function _resend_registration()
3250
+	{
3251
+		$this->_process_resend_registration();
3252
+		$query_args = isset($this->_req_data['redirect_to'])
3253
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3254
+			: array('action' => 'default');
3255
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3256
+	}
3257
+
3258
+	/**
3259
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3260
+	 * to use when selecting registrations
3261
+	 *
3262
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3263
+	 *                                                     the query parameters from the request
3264
+	 * @return void ends the request with a redirect or download
3265
+	 */
3266
+	public function _registrations_report_base($method_name_for_getting_query_params)
3267
+	{
3268
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3269
+			wp_redirect(
3270
+				EE_Admin_Page::add_query_args_and_nonce(
3271
+					array(
3272
+						'page'        => 'espresso_batch',
3273
+						'batch'       => 'file',
3274
+						'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3275
+						'filters'     => urlencode(
3276
+							serialize(
3277
+								$this->$method_name_for_getting_query_params(
3278
+									EEH_Array::is_set(
3279
+										$this->_req_data,
3280
+										'filters',
3281
+										array()
3282
+									)
3283
+								)
3284
+							)
3285
+						),
3286
+						'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3287
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3288
+						'return_url'  => urlencode($this->_req_data['return_url']),
3289
+					)
3290
+				)
3291
+			);
3292
+		} else {
3293
+			$new_request_args = array(
3294
+				'export' => 'report',
3295
+				'action' => 'registrations_report_for_event',
3296
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3297
+			);
3298
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3299
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3300
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3301
+				$EE_Export = EE_Export::instance($this->_req_data);
3302
+				$EE_Export->export();
3303
+			}
3304
+		}
3305
+	}
3306
+
3307
+
3308
+	/**
3309
+	 * Creates a registration report using only query parameters in the request
3310
+	 *
3311
+	 * @return void
3312
+	 */
3313
+	public function _registrations_report()
3314
+	{
3315
+		$this->_registrations_report_base('_get_registration_query_parameters');
3316
+	}
3317
+
3318
+
3319
+	public function _contact_list_export()
3320
+	{
3321
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3322
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3323
+			$EE_Export = EE_Export::instance($this->_req_data);
3324
+			$EE_Export->export_attendees();
3325
+		}
3326
+	}
3327
+
3328
+
3329
+	public function _contact_list_report()
3330
+	{
3331
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3332
+			wp_redirect(
3333
+				EE_Admin_Page::add_query_args_and_nonce(
3334
+					array(
3335
+						'page'        => 'espresso_batch',
3336
+						'batch'       => 'file',
3337
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3338
+						'return_url'  => urlencode($this->_req_data['return_url']),
3339
+					)
3340
+				)
3341
+			);
3342
+		} else {
3343
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3344
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3345
+				$EE_Export = EE_Export::instance($this->_req_data);
3346
+				$EE_Export->report_attendees();
3347
+			}
3348
+		}
3349
+	}
3350
+
3351
+
3352
+
3353
+
3354
+
3355
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3356
+	/**
3357
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3358
+	 *
3359
+	 * @return void
3360
+	 * @throws EE_Error
3361
+	 * @throws InvalidArgumentException
3362
+	 * @throws InvalidDataTypeException
3363
+	 * @throws InvalidInterfaceException
3364
+	 * @throws ReflectionException
3365
+	 */
3366
+	protected function _duplicate_attendee()
3367
+	{
3368
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3369
+		// verify we have necessary info
3370
+		if (empty($this->_req_data['_REG_ID'])) {
3371
+			EE_Error::add_error(
3372
+				esc_html__(
3373
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3374
+					'event_espresso'
3375
+				),
3376
+				__FILE__,
3377
+				__LINE__,
3378
+				__FUNCTION__
3379
+			);
3380
+			$query_args = array('action' => $action);
3381
+			$this->_redirect_after_action('', '', '', $query_args, true);
3382
+		}
3383
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3384
+		$registration = $this->getRegistrationModel()->get_one_by_ID($this->_req_data['_REG_ID']);
3385
+		$attendee = $registration->attendee();
3386
+		// remove relation of existing attendee on registration
3387
+		$registration->_remove_relation_to($attendee, 'Attendee');
3388
+		// new attendee
3389
+		$new_attendee = clone $attendee;
3390
+		$new_attendee->set('ATT_ID', 0);
3391
+		$new_attendee->save();
3392
+		// add new attendee to reg
3393
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3394
+		EE_Error::add_success(
3395
+			esc_html__(
3396
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3397
+				'event_espresso'
3398
+			)
3399
+		);
3400
+		// redirect to edit page for attendee
3401
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3402
+		$this->_redirect_after_action('', '', '', $query_args, true);
3403
+	}
3404
+
3405
+
3406
+	/**
3407
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3408
+	 *
3409
+	 * @param int     $post_id
3410
+	 * @param WP_POST $post
3411
+	 * @throws DomainException
3412
+	 * @throws EE_Error
3413
+	 * @throws InvalidArgumentException
3414
+	 * @throws InvalidDataTypeException
3415
+	 * @throws InvalidInterfaceException
3416
+	 * @throws LogicException
3417
+	 * @throws InvalidFormSubmissionException
3418
+	 * @throws ReflectionException
3419
+	 */
3420
+	protected function _insert_update_cpt_item($post_id, $post)
3421
+	{
3422
+		$success = true;
3423
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3424
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3425
+			: null;
3426
+		// for attendee updates
3427
+		if ($attendee instanceof EE_Attendee) {
3428
+			// note we should only be UPDATING attendees at this point.
3429
+			$updated_fields = array(
3430
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3431
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3432
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3433
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3434
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3435
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3436
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3437
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3438
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3439
+			);
3440
+			foreach ($updated_fields as $field => $value) {
3441
+				$attendee->set($field, $value);
3442
+			}
3443
+
3444
+			// process contact details metabox form handler (which will also save the attendee)
3445
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3446
+			$success = $contact_details_form->process($this->_req_data);
3447
+
3448
+			$attendee_update_callbacks = apply_filters(
3449
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3450
+				array()
3451
+			);
3452
+			foreach ($attendee_update_callbacks as $a_callback) {
3453
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3454
+					throw new EE_Error(
3455
+						sprintf(
3456
+							esc_html__(
3457
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3458
+								'event_espresso'
3459
+							),
3460
+							$a_callback
3461
+						)
3462
+					);
3463
+				}
3464
+			}
3465
+		}
3466
+
3467
+		if ($success === false) {
3468
+			EE_Error::add_error(
3469
+				esc_html__(
3470
+					'Something went wrong with updating the meta table data for the registration.',
3471
+					'event_espresso'
3472
+				),
3473
+				__FILE__,
3474
+				__FUNCTION__,
3475
+				__LINE__
3476
+			);
3477
+		}
3478
+	}
3479
+
3480
+
3481
+	public function trash_cpt_item($post_id)
3482
+	{
3483
+	}
3484
+
3485
+
3486
+	public function delete_cpt_item($post_id)
3487
+	{
3488
+	}
3489
+
3490
+
3491
+	public function restore_cpt_item($post_id)
3492
+	{
3493
+	}
3494
+
3495
+
3496
+	protected function _restore_cpt_item($post_id, $revision_id)
3497
+	{
3498
+	}
3499
+
3500
+
3501
+	/**
3502
+	 * @throws EE_Error
3503
+	 * @since 4.10.2.p
3504
+	 */
3505
+	public function attendee_editor_metaboxes()
3506
+	{
3507
+		$this->verify_cpt_object();
3508
+		remove_meta_box(
3509
+			'postexcerpt',
3510
+			$this->_cpt_routes[ $this->_req_action ],
3511
+			'normal'
3512
+		);
3513
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3514
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3515
+			add_meta_box(
3516
+				'postexcerpt',
3517
+				esc_html__('Short Biography', 'event_espresso'),
3518
+				'post_excerpt_meta_box',
3519
+				$this->_cpt_routes[ $this->_req_action ],
3520
+				'normal'
3521
+			);
3522
+		}
3523
+		if (post_type_supports('espresso_attendees', 'comments')) {
3524
+			add_meta_box(
3525
+				'commentsdiv',
3526
+				esc_html__('Notes on the Contact', 'event_espresso'),
3527
+				'post_comment_meta_box',
3528
+				$this->_cpt_routes[ $this->_req_action ],
3529
+				'normal',
3530
+				'core'
3531
+			);
3532
+		}
3533
+		add_meta_box(
3534
+			'attendee_contact_info',
3535
+			esc_html__('Contact Info', 'event_espresso'),
3536
+			array($this, 'attendee_contact_info'),
3537
+			$this->_cpt_routes[ $this->_req_action ],
3538
+			'side',
3539
+			'core'
3540
+		);
3541
+		add_meta_box(
3542
+			'attendee_details_address',
3543
+			esc_html__('Address Details', 'event_espresso'),
3544
+			array($this, 'attendee_address_details'),
3545
+			$this->_cpt_routes[ $this->_req_action ],
3546
+			'normal',
3547
+			'core'
3548
+		);
3549
+		add_meta_box(
3550
+			'attendee_registrations',
3551
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3552
+			array($this, 'attendee_registrations_meta_box'),
3553
+			$this->_cpt_routes[ $this->_req_action ],
3554
+			'normal',
3555
+			'high'
3556
+		);
3557
+	}
3558
+
3559
+
3560
+	/**
3561
+	 * Metabox for attendee contact info
3562
+	 *
3563
+	 * @param  WP_Post $post wp post object
3564
+	 * @return string attendee contact info ( and form )
3565
+	 * @throws EE_Error
3566
+	 * @throws InvalidArgumentException
3567
+	 * @throws InvalidDataTypeException
3568
+	 * @throws InvalidInterfaceException
3569
+	 * @throws LogicException
3570
+	 * @throws DomainException
3571
+	 */
3572
+	public function attendee_contact_info($post)
3573
+	{
3574
+		// get attendee object ( should already have it )
3575
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3576
+		$form->enqueueStylesAndScripts();
3577
+		echo $form->display();
3578
+	}
3579
+
3580
+
3581
+	/**
3582
+	 * Return form handler for the contact details metabox
3583
+	 *
3584
+	 * @param EE_Attendee $attendee
3585
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3586
+	 * @throws DomainException
3587
+	 * @throws InvalidArgumentException
3588
+	 * @throws InvalidDataTypeException
3589
+	 * @throws InvalidInterfaceException
3590
+	 */
3591
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3592
+	{
3593
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3594
+	}
3595
+
3596
+
3597
+	/**
3598
+	 * Metabox for attendee details
3599
+	 *
3600
+	 * @param  WP_Post $post wp post object
3601
+	 * @throws DomainException
3602
+	 */
3603
+	public function attendee_address_details($post)
3604
+	{
3605
+		// get attendee object (should already have it)
3606
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3607
+		$this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3608
+			new EE_Question_Form_Input(
3609
+				EE_Question::new_instance(
3610
+					array(
3611
+						'QST_ID'           => 0,
3612
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3613
+						'QST_system'       => 'admin-state',
3614
+					)
3615
+				),
3616
+				EE_Answer::new_instance(
3617
+					array(
3618
+						'ANS_ID'    => 0,
3619
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3620
+					)
3621
+				),
3622
+				array(
3623
+					'input_id'       => 'STA_ID',
3624
+					'input_name'     => 'STA_ID',
3625
+					'input_prefix'   => '',
3626
+					'append_qstn_id' => false,
3627
+				)
3628
+			)
3629
+		);
3630
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3631
+			new EE_Question_Form_Input(
3632
+				EE_Question::new_instance(
3633
+					array(
3634
+						'QST_ID'           => 0,
3635
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3636
+						'QST_system'       => 'admin-country',
3637
+					)
3638
+				),
3639
+				EE_Answer::new_instance(
3640
+					array(
3641
+						'ANS_ID'    => 0,
3642
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3643
+					)
3644
+				),
3645
+				array(
3646
+					'input_id'       => 'CNT_ISO',
3647
+					'input_name'     => 'CNT_ISO',
3648
+					'input_prefix'   => '',
3649
+					'append_qstn_id' => false,
3650
+				)
3651
+			)
3652
+		);
3653
+		$template =
3654
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3655
+		EEH_Template::display_template($template, $this->_template_args);
3656
+	}
3657
+
3658
+
3659
+	/**
3660
+	 *        _attendee_details
3661
+	 *
3662
+	 * @access protected
3663
+	 * @param $post
3664
+	 * @return void
3665
+	 * @throws DomainException
3666
+	 * @throws EE_Error
3667
+	 * @throws InvalidArgumentException
3668
+	 * @throws InvalidDataTypeException
3669
+	 * @throws InvalidInterfaceException
3670
+	 * @throws ReflectionException
3671
+	 */
3672
+	public function attendee_registrations_meta_box($post)
3673
+	{
3674
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3675
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3676
+		$template =
3677
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3678
+		EEH_Template::display_template($template, $this->_template_args);
3679
+	}
3680
+
3681
+
3682
+	/**
3683
+	 * add in the form fields for the attendee edit
3684
+	 *
3685
+	 * @param  WP_Post $post wp post object
3686
+	 * @return string html for new form.
3687
+	 * @throws DomainException
3688
+	 */
3689
+	public function after_title_form_fields($post)
3690
+	{
3691
+		if ($post->post_type === 'espresso_attendees') {
3692
+			$template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3693
+			$template_args['attendee'] = $this->_cpt_model_obj;
3694
+			EEH_Template::display_template($template, $template_args);
3695
+		}
3696
+	}
3697
+
3698
+
3699
+	/**
3700
+	 *        _trash_or_restore_attendee
3701
+	 *
3702
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3703
+	 * @return void
3704
+	 * @throws EE_Error
3705
+	 * @throws InvalidArgumentException
3706
+	 * @throws InvalidDataTypeException
3707
+	 * @throws InvalidInterfaceException
3708
+	 * @throws ReflectionException
3709
+	 * @access protected
3710
+	 */
3711
+	protected function _trash_or_restore_attendees($trash = true)
3712
+	{
3713
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3714
+		$success = 1;
3715
+		// Checkboxes
3716
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3717
+			// if array has more than one element than success message should be plural
3718
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3719
+			// cycle thru checkboxes
3720
+			foreach ($this->_req_data['checkbox'] as $ATT_ID) {
3721
+				$updated = $trash ? $this->getAttendeeModel()->update_by_ID(array('status' => 'trash'), $ATT_ID)
3722
+					: $this->getAttendeeModel()->update_by_ID(array('status' => 'publish'), $ATT_ID);
3723
+				if (! $updated) {
3724
+					$success = 0;
3725
+				}
3726
+			}
3727
+		} else {
3728
+			// grab single id and delete
3729
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3730
+			// get attendee
3731
+			$att = $this->getAttendeeModel()->get_one_by_ID($ATT_ID);
3732
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3733
+			$updated = $att->save() && $updated;
3734
+			if (! $updated) {
3735
+				$success = 0;
3736
+			}
3737
+		}
3738
+		$what = $success > 1
3739
+			? esc_html__('Contacts', 'event_espresso')
3740
+			: esc_html__('Contact', 'event_espresso');
3741
+		$action_desc = $trash
3742
+			? esc_html__('moved to the trash', 'event_espresso')
3743
+			: esc_html__('restored', 'event_espresso');
3744
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3745
+	}
3746 3746
 }
Please login to merge, or discard this patch.
caffeinated/payment_methods/Paypal_Pro/EEG_Paypal_Pro.gateway.php 1 patch
Indentation   +602 added lines, -602 removed lines patch added patch discarded remove patch
@@ -11,606 +11,606 @@
 block discarded – undo
11 11
 class EEG_Paypal_Pro extends EE_Onsite_Gateway
12 12
 {
13 13
 
14
-    /**
15
-     * @var $_paypal_api_username string
16
-     */
17
-    protected $_api_username = null;
18
-
19
-    /**
20
-     * @var $_api_password string
21
-     */
22
-    protected $_api_password = null;
23
-
24
-    /**
25
-     * @var $_api_signature string
26
-     */
27
-    protected $_api_signature = null;
28
-
29
-    /**
30
-     * @var $_credit_card_types array with the keys for credit card types accepted on this account
31
-     */
32
-    protected $_credit_card_types    = null;
33
-
34
-    protected $_currencies_supported = array(
35
-        'USD',
36
-        'GBP',
37
-        'CAD',
38
-        'AUD',
39
-        'BRL',
40
-        'CHF',
41
-        'CZK',
42
-        'DKK',
43
-        'EUR',
44
-        'HKD',
45
-        'HUF',
46
-        'ILS',
47
-        'JPY',
48
-        'MXN',
49
-        'MYR',
50
-        'NOK',
51
-        'NZD',
52
-        'PHP',
53
-        'PLN',
54
-        'SEK',
55
-        'SGD',
56
-        'THB',
57
-        'TRY',
58
-        'TWD',
59
-        'RUB',
60
-        'INR',
61
-    );
62
-
63
-
64
-
65
-    /**
66
-     * @param EEI_Payment $payment
67
-     * @param array       $billing_info {
68
-     * @type string $credit_card
69
-     * @type string $credit_card_type
70
-     * @type string $exp_month always 2 characters
71
-     * @type string $exp_year always 4 characters
72
-     * @type string $cvv
73
-     * }
74
-     * @see      parent::do_direct_payment for more info
75
-     * @return EE_Payment|EEI_Payment
76
-     * @throws EE_Error
77
-     */
78
-    public function do_direct_payment($payment, $billing_info = null)
79
-    {
80
-        $transaction = $payment->transaction();
81
-        if (! $transaction instanceof EEI_Transaction) {
82
-            throw new EE_Error(
83
-                esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
84
-            );
85
-        }
86
-        $primary_registrant = $transaction->primary_registration();
87
-        if (! $primary_registrant instanceof EEI_Registration) {
88
-            throw new EE_Error(
89
-                esc_html__(
90
-                    'No primary registration on transaction while paying with PayPal Pro.',
91
-                    'event_espresso'
92
-                )
93
-            );
94
-        }
95
-        $attendee = $primary_registrant->attendee();
96
-        if (! $attendee instanceof EEI_Attendee) {
97
-            throw new EE_Error(
98
-                esc_html__(
99
-                    'No attendee on primary registration while paying with PayPal Pro.',
100
-                    'event_espresso'
101
-                )
102
-            );
103
-        }
104
-        $gateway_formatter = $this->_get_gateway_formatter();
105
-        $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127);
106
-        // charge for the full amount. Show itemized list
107
-        if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
108
-            $item_num = 1;
109
-            $total_line_item = $transaction->total_line_item();
110
-            $order_items = array();
111
-            foreach ($total_line_item->get_items() as $line_item) {
112
-                // ignore line items with a quantity of 0
113
-                if ($line_item->quantity() == 0) {
114
-                    continue;
115
-                }
116
-                // For percent items, whose unit_price is 0, use the total instead.
117
-                if ($line_item->is_percent()) {
118
-                    $unit_price = $line_item->total();
119
-                    $line_item_quantity = 1;
120
-                } else {
121
-                    $unit_price = $line_item->unit_price();
122
-                    $line_item_quantity = $line_item->quantity();
123
-                }
124
-                $item = array(
125
-                    // Item Name.  127 char max.
126
-                    'l_name'                 => substr(
127
-                        $gateway_formatter->formatLineItemName($line_item, $payment),
128
-                        0,
129
-                        127
130
-                    ),
131
-                    // Item description.  127 char max.
132
-                    'l_desc'                 => substr(
133
-                        $gateway_formatter->formatLineItemDesc($line_item, $payment),
134
-                        0,
135
-                        127
136
-                    ),
137
-                    // Cost of individual item.
138
-                    'l_amt'                  => $unit_price,
139
-                    // Item Number.  127 char max.
140
-                    'l_number'               => $item_num++,
141
-                    // Item quantity.  Must be any positive integer.
142
-                    'l_qty'                  => $line_item_quantity,
143
-                    // Item's sales tax amount.
144
-                    'l_taxamt'               => '',
145
-                    // eBay auction number of item.
146
-                    'l_ebayitemnumber'       => '',
147
-                    // eBay transaction ID of purchased item.
148
-                    'l_ebayitemauctiontxnid' => '',
149
-                    // eBay order ID for the item.
150
-                    'l_ebayitemorderid'      => '',
151
-                );
152
-                // add to array of all items
153
-                array_push($order_items, $item);
154
-            }
155
-            $item_amount = $total_line_item->get_items_total();
156
-            $tax_amount = $total_line_item->get_total_tax();
157
-        } else {
158
-            $order_items = array();
159
-            $item_amount = $payment->amount();
160
-            $tax_amount = 0;
161
-            array_push($order_items, array(
162
-                // Item Name.  127 char max.
163
-                'l_name'   => substr(
164
-                    $gateway_formatter->formatPartialPaymentLineItemName($payment),
165
-                    0,
166
-                    127
167
-                ),
168
-                // Item description.  127 char max.
169
-                'l_desc'   => substr(
170
-                    $gateway_formatter->formatPartialPaymentLineItemDesc($payment),
171
-                    0,
172
-                    127
173
-                ),
174
-                // Cost of individual item.
175
-                'l_amt'    => $payment->amount(),
176
-                // Item Number.  127 char max.
177
-                'l_number' => 1,
178
-                // Item quantity.  Must be any positive integer.
179
-                'l_qty'    => 1,
180
-            ));
181
-        }
182
-        // Populate data arrays with order data.
183
-        $DPFields = array(
184
-            // How you want to obtain payment ?
185
-            // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture.
186
-            // Sale indicates that this is a final sale for which you are requesting payment.  Default is Sale.
187
-            'paymentaction'    => 'Sale',
188
-            // Required.  IP address of the payer's browser.
189
-            'ipaddress'        => $_SERVER['REMOTE_ADDR'],
190
-            // Flag to determine whether you want the results returned by FMF.  1 or 0.  Default is 0.
191
-            'returnfmfdetails' => '1',
192
-        );
193
-        $CCDetails = array(
194
-            // Required. Type of credit card.  Visa, MasterCard, Discover, Amex, Maestro, Solo.
195
-            // If Maestro or Solo, the currency code must be GBP.
196
-            //  In addition, either start date or issue number must be specified.
197
-            'creditcardtype' => $billing_info['credit_card_type'],
198
-            // Required.  Credit card number.  No spaces or punctuation.
199
-            'acct'           => $billing_info['credit_card'],
200
-            // Required.  Credit card expiration date.  Format is MMYYYY
201
-            'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
202
-            // Requirements determined by your PayPal account settings.  Security digits for credit card.
203
-            'cvv2'           => $billing_info['cvv'],
204
-        );
205
-        $PayerInfo = array(
206
-            // Email address of payer.
207
-            'email'       => $billing_info['email'],
208
-            // Unique PayPal customer ID for payer.
209
-            'payerid'     => '',
210
-            // Status of payer.  Values are verified or unverified
211
-            'payerstatus' => '',
212
-            // Payer's business name.
213
-            'business'    => '',
214
-        );
215
-        $PayerName = array(
216
-            // Payer's salutation.  20 char max.
217
-            'salutation' => '',
218
-            // Payer's first name.  25 char max.
219
-            'firstname'  => substr($billing_info['first_name'], 0, 25),
220
-            // Payer's middle name.  25 char max.
221
-            'middlename' => '',
222
-            // Payer's last name.  25 char max.
223
-            'lastname'   => substr($billing_info['last_name'], 0, 25),
224
-            // Payer's suffix.  12 char max.
225
-            'suffix'     => '',
226
-        );
227
-        $BillingAddress = array(
228
-            // Required.  First street address.
229
-            'street'      => $billing_info['address'],
230
-            // Second street address.
231
-            'street2'     => $billing_info['address2'],
232
-            // Required.  Name of City.
233
-            'city'        => $billing_info['city'],
234
-            // Required. Name of State or Province.
235
-            'state'       => substr($billing_info['state'], 0, 40),
236
-            // Required.  Country code.
237
-            'countrycode' => $billing_info['country'],
238
-            // Required.  Postal code of payer.
239
-            'zip'         => $billing_info['zip'],
240
-        );
241
-        // check if the registration info contains the needed fields for paypal pro
242
-        // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
243
-        if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
244
-            $use_registration_address_info = true;
245
-        } else {
246
-            $use_registration_address_info = false;
247
-        }
248
-        // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it.
249
-        // If not, use the billing info again
250
-        $ShippingAddress = array(
251
-            'shiptoname'     => substr($use_registration_address_info
252
-                ? $attendee->full_name()
253
-                : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
254
-            'shiptostreet'   => substr($use_registration_address_info
255
-                ? $attendee->address()
256
-                : $billing_info['address'], 0, 100),
257
-            'shiptostreet2'  => substr($use_registration_address_info
258
-                ? $attendee->address2() : $billing_info['address2'], 0, 100),
259
-            'shiptocity'     => substr($use_registration_address_info
260
-                ? $attendee->city()
261
-                : $billing_info['city'], 0, 40),
262
-            'shiptostate'          => substr($use_registration_address_info
263
-                ? $attendee->state_name()
264
-                : $billing_info['state'], 0, 40),
265
-            'shiptocountry'  => $use_registration_address_info
266
-                ? $attendee->country_ID()
267
-                : $billing_info['country'],
268
-            'shiptozip'      => substr($use_registration_address_info
269
-                ? $attendee->zip()
270
-                : $billing_info['zip'], 0, 20),
271
-            'shiptophonenum' => substr($use_registration_address_info
272
-                ? $attendee->phone()
273
-                : $billing_info['phone'], 0, 20),
274
-        );
275
-        $PaymentDetails = array(
276
-            // Required.  Total amount of order, including shipping, handling, and tax.
277
-            'amt'          => $gateway_formatter->formatCurrency($payment->amount()),
278
-            // Required.  Three-letter currency code.  Default is USD.
279
-            'currencycode' => $payment->currency_code(),
280
-            // Required if you include itemized cart details. (L_AMTn, etc.)
281
-            // Subtotal of items not including S&H, or tax.
282
-            'itemamt'      => $gateway_formatter->formatCurrency($item_amount),//
283
-            // Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
284
-            'shippingamt'  => '',
285
-            // Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
286
-            'handlingamt'  => '',
287
-            // Required if you specify itemized cart tax details.
288
-            // Sum of tax for all items on the order.  Total sales tax.
289
-            'taxamt'       => $gateway_formatter->formatCurrency($tax_amount),
290
-            // Description of the order the customer is purchasing.  127 char max.
291
-            'desc'         => $order_description,
292
-            // Free-form field for your own use.  256 char max.
293
-            'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
294
-            // Your own invoice or tracking number
295
-            'invnum'       => wp_generate_password(12, false),// $transaction->ID(),
296
-            // URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
297
-            'notifyurl'    => '',
298
-            'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this
299
-        );
300
-        // Wrap all data arrays into a single, "master" array which will be passed into the class function.
301
-        $PayPalRequestData = array(
302
-            'DPFields'        => $DPFields,
303
-            'CCDetails'       => $CCDetails,
304
-            'PayerInfo'       => $PayerInfo,
305
-            'PayerName'       => $PayerName,
306
-            'BillingAddress'  => $BillingAddress,
307
-            'ShippingAddress' => $ShippingAddress,
308
-            'PaymentDetails'  => $PaymentDetails,
309
-            'OrderItems'      => $order_items,
310
-        );
311
-        $this->_log_clean_request($PayPalRequestData, $payment);
312
-        try {
313
-            $PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
314
-            // remove PCI-sensitive data so it doesn't get stored
315
-            $PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
316
-            if (isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') {
317
-                $message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso');
318
-            } elseif (isset($PayPalResult['L_LONGMESSAGE0'])) {
319
-                $message = $PayPalResult['L_LONGMESSAGE0'];
320
-            } else {
321
-                $message = $PayPalResult['ACK'];
322
-            }
323
-            if (empty($PayPalResult['RAWRESPONSE'])) {
324
-                $payment->set_status($this->_pay_model->failed_status());
325
-                $payment->set_gateway_response(esc_html__('No response received from Paypal Pro', 'event_espresso'));
326
-                $payment->set_details($PayPalResult);
327
-            } else {
328
-                if ($this->_APICallSuccessful($PayPalResult)) {
329
-                    $payment->set_status($this->_pay_model->approved_status());
330
-                } else {
331
-                    $payment->set_status($this->_pay_model->declined_status());
332
-                }
333
-                // make sure we interpret the AMT as a float, not an international string
334
-                // (where periods are thousand separators)
335
-                $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
336
-                $payment->set_gateway_response($message);
337
-                $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID'])
338
-                    ? $PayPalResult['TRANSACTIONID']
339
-                    : null);
340
-                $primary_registration_code = $primary_registrant instanceof EE_Registration
341
-                    ? $primary_registrant->reg_code()
342
-                    : '';
343
-                $payment->set_extra_accntng($primary_registration_code);
344
-                $payment->set_details($PayPalResult);
345
-            }
346
-        } catch (Exception $e) {
347
-            $payment->set_status($this->_pay_model->failed_status());
348
-            $payment->set_gateway_response($e->getMessage());
349
-        }
350
-        // $payment->set_status( $this->_pay_model->declined_status() );
351
-        // $payment->set_gateway_response( '' );
352
-        return $payment;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * CLeans out sensitive CC data and then logs it, and returns the cleaned request
359
-     *
360
-     * @param array       $request
361
-     * @param EEI_Payment $payment
362
-     * @return void
363
-     */
364
-    private function _log_clean_request($request, $payment)
365
-    {
366
-        $cleaned_request_data = $request;
367
-        unset($cleaned_request_data['CCDetails']['acct']);
368
-        unset($cleaned_request_data['CCDetails']['cvv2']);
369
-        unset($cleaned_request_data['CCDetails']['expdate']);
370
-        $this->log(array('Paypal Request' => $cleaned_request_data), $payment);
371
-    }
372
-
373
-
374
-
375
-    /**
376
-     * Cleans the response, logs it, and returns it
377
-     *
378
-     * @param array       $response
379
-     * @param EEI_Payment $payment
380
-     * @return array cleaned
381
-     */
382
-    private function _log_clean_response($response, $payment)
383
-    {
384
-        unset($response['REQUESTDATA']['CREDITCARDTYPE']);
385
-        unset($response['REQUESTDATA']['ACCT']);
386
-        unset($response['REQUESTDATA']['EXPDATE']);
387
-        unset($response['REQUESTDATA']['CVV2']);
388
-        unset($response['RAWREQUEST']);
389
-        $this->log(array('Paypal Response' => $response), $payment);
390
-        return $response;
391
-    }
392
-
393
-
394
-
395
-    /**
396
-     * @param $DataArray
397
-     * @return array
398
-     */
399
-    private function prep_and_curl_request($DataArray)
400
-    {
401
-        // Create empty holders for each portion of the NVP string
402
-        $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
403
-        $CCDetailsNVP = '';
404
-        $PayerInfoNVP = '';
405
-        $PayerNameNVP = '';
406
-        $BillingAddressNVP = '';
407
-        $ShippingAddressNVP = '';
408
-        $PaymentDetailsNVP = '';
409
-        $OrderItemsNVP = '';
410
-        $Secure3DNVP = '';
411
-        // DP Fields
412
-        $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
413
-        foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
414
-            $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
415
-        }
416
-        // CC Details Fields
417
-        $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
418
-        foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
419
-            $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
420
-        }
421
-        // PayerInfo Type Fields
422
-        $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
423
-        foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
424
-            $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
425
-        }
426
-        // Payer Name Fields
427
-        $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
428
-        foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
429
-            $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
430
-        }
431
-        // Address Fields (Billing)
432
-        $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
433
-        foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
434
-            $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
435
-        }
436
-        // Payment Details Type Fields
437
-        $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
438
-        foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
439
-            $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
440
-        }
441
-        // Payment Details Item Type Fields
442
-        $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
443
-        $n = 0;
444
-        foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
445
-            $CurrentItem = $OrderItems[ $OrderItemsVar ];
446
-            foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
447
-                $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
448
-            }
449
-            $n++;
450
-        }
451
-        // Ship To Address Fields
452
-        $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
453
-        foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
454
-            $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
455
-        }
456
-        // 3D Secure Fields
457
-        $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
458
-        foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
459
-            $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
460
-        }
461
-        // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
462
-        $NVPRequest = 'USER='
463
-                      . $this->_api_username
464
-                      . '&PWD='
465
-                      . $this->_api_password
466
-                      . '&VERSION=64.0'
467
-                      . '&SIGNATURE='
468
-                      . $this->_api_signature
469
-                      . $DPFieldsNVP
470
-                      . $CCDetailsNVP
471
-                      . $PayerInfoNVP
472
-                      . $PayerNameNVP
473
-                      . $BillingAddressNVP
474
-                      . $PaymentDetailsNVP
475
-                      . $OrderItemsNVP
476
-                      . $ShippingAddressNVP
477
-                      . $Secure3DNVP;
478
-        $NVPResponse = $this->_CURLRequest($NVPRequest);
479
-        $NVPRequestArray = $this->_NVPToArray($NVPRequest);
480
-        $NVPResponseArray = $this->_NVPToArray($NVPResponse);
481
-        $Errors = $this->_GetErrors($NVPResponseArray);
482
-        $NVPResponseArray['ERRORS'] = $Errors;
483
-        $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
484
-        $NVPResponseArray['RAWREQUEST'] = $NVPRequest;
485
-        $NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
486
-        return $NVPResponseArray;
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * @param $Request
493
-     * @return mixed
494
-     */
495
-    private function _CURLRequest($Request)
496
-    {
497
-        $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
498
-        $curl = curl_init();
499
-        curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
500
-        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
501
-        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
502
-        curl_setopt($curl, CURLOPT_URL, $EndPointURL);
503
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
504
-        curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
505
-        curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
506
-        // execute the curl POST
507
-        $Response = curl_exec($curl);
508
-        curl_close($curl);
509
-        return $Response;
510
-    }
511
-
512
-
513
-
514
-    /**
515
-     * @param $NVPString
516
-     * @return array
517
-     */
518
-    private function _NVPToArray($NVPString)
519
-    {
520
-        // prepare responses into array
521
-        $proArray = array();
522
-        while (strlen($NVPString)) {
523
-            // name
524
-            $keypos = strpos($NVPString, '=');
525
-            $keyval = substr($NVPString, 0, $keypos);
526
-            // value
527
-            $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
528
-            $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
529
-            // decoding the response
530
-            $proArray[ $keyval ] = urldecode($valval);
531
-            $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
532
-        }
533
-        return $proArray;
534
-    }
535
-
536
-
537
-
538
-    /**
539
-     * @param array $PayPalResult
540
-     * @return bool
541
-     */
542
-    private function _APICallSuccessful($PayPalResult)
543
-    {
544
-        $approved = false;
545
-        // check main response message from PayPal
546
-        if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
547
-            $ack = strtoupper($PayPalResult['ACK']);
548
-            $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
549
-        }
550
-        return $approved;
551
-    }
552
-
553
-
554
-
555
-    /**
556
-     * @param $DataArray
557
-     * @return array
558
-     */
559
-    private function _GetErrors($DataArray)
560
-    {
561
-        $Errors = array();
562
-        $n = 0;
563
-        while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) {
564
-            $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : '';
565
-            $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ])
566
-                ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ]
567
-                : '';
568
-            $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ])
569
-                ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ]
570
-                : '';
571
-            $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ])
572
-                ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ]
573
-                : '';
574
-            $CurrentItem = array(
575
-                'L_ERRORCODE'    => $LErrorCode,
576
-                'L_SHORTMESSAGE' => $LShortMessage,
577
-                'L_LONGMESSAGE'  => $LLongMessage,
578
-                'L_SEVERITYCODE' => $LSeverityCode,
579
-            );
580
-            array_push($Errors, $CurrentItem);
581
-            $n++;
582
-        }
583
-        return $Errors;
584
-    }
585
-
586
-
587
-
588
-    /**
589
-     *        nothing to see here...  move along....
590
-     *
591
-     * @access protected
592
-     * @param $Errors
593
-     * @return string
594
-     */
595
-    private function _DisplayErrors($Errors)
596
-    {
597
-        $error = '';
598
-        foreach ($Errors as $ErrorVar => $ErrorVal) {
599
-            $CurrentError = $Errors[ $ErrorVar ];
600
-            foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
601
-                $CurrentVarName = '';
602
-                if ($CurrentErrorVar == 'L_ERRORCODE') {
603
-                    $CurrentVarName = 'Error Code';
604
-                } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
605
-                    $CurrentVarName = 'Short Message';
606
-                } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
607
-                    $CurrentVarName = 'Long Message';
608
-                } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
609
-                    $CurrentVarName = 'Severity Code';
610
-                }
611
-                $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
612
-            }
613
-        }
614
-        return $error;
615
-    }
14
+	/**
15
+	 * @var $_paypal_api_username string
16
+	 */
17
+	protected $_api_username = null;
18
+
19
+	/**
20
+	 * @var $_api_password string
21
+	 */
22
+	protected $_api_password = null;
23
+
24
+	/**
25
+	 * @var $_api_signature string
26
+	 */
27
+	protected $_api_signature = null;
28
+
29
+	/**
30
+	 * @var $_credit_card_types array with the keys for credit card types accepted on this account
31
+	 */
32
+	protected $_credit_card_types    = null;
33
+
34
+	protected $_currencies_supported = array(
35
+		'USD',
36
+		'GBP',
37
+		'CAD',
38
+		'AUD',
39
+		'BRL',
40
+		'CHF',
41
+		'CZK',
42
+		'DKK',
43
+		'EUR',
44
+		'HKD',
45
+		'HUF',
46
+		'ILS',
47
+		'JPY',
48
+		'MXN',
49
+		'MYR',
50
+		'NOK',
51
+		'NZD',
52
+		'PHP',
53
+		'PLN',
54
+		'SEK',
55
+		'SGD',
56
+		'THB',
57
+		'TRY',
58
+		'TWD',
59
+		'RUB',
60
+		'INR',
61
+	);
62
+
63
+
64
+
65
+	/**
66
+	 * @param EEI_Payment $payment
67
+	 * @param array       $billing_info {
68
+	 * @type string $credit_card
69
+	 * @type string $credit_card_type
70
+	 * @type string $exp_month always 2 characters
71
+	 * @type string $exp_year always 4 characters
72
+	 * @type string $cvv
73
+	 * }
74
+	 * @see      parent::do_direct_payment for more info
75
+	 * @return EE_Payment|EEI_Payment
76
+	 * @throws EE_Error
77
+	 */
78
+	public function do_direct_payment($payment, $billing_info = null)
79
+	{
80
+		$transaction = $payment->transaction();
81
+		if (! $transaction instanceof EEI_Transaction) {
82
+			throw new EE_Error(
83
+				esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
84
+			);
85
+		}
86
+		$primary_registrant = $transaction->primary_registration();
87
+		if (! $primary_registrant instanceof EEI_Registration) {
88
+			throw new EE_Error(
89
+				esc_html__(
90
+					'No primary registration on transaction while paying with PayPal Pro.',
91
+					'event_espresso'
92
+				)
93
+			);
94
+		}
95
+		$attendee = $primary_registrant->attendee();
96
+		if (! $attendee instanceof EEI_Attendee) {
97
+			throw new EE_Error(
98
+				esc_html__(
99
+					'No attendee on primary registration while paying with PayPal Pro.',
100
+					'event_espresso'
101
+				)
102
+			);
103
+		}
104
+		$gateway_formatter = $this->_get_gateway_formatter();
105
+		$order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127);
106
+		// charge for the full amount. Show itemized list
107
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
108
+			$item_num = 1;
109
+			$total_line_item = $transaction->total_line_item();
110
+			$order_items = array();
111
+			foreach ($total_line_item->get_items() as $line_item) {
112
+				// ignore line items with a quantity of 0
113
+				if ($line_item->quantity() == 0) {
114
+					continue;
115
+				}
116
+				// For percent items, whose unit_price is 0, use the total instead.
117
+				if ($line_item->is_percent()) {
118
+					$unit_price = $line_item->total();
119
+					$line_item_quantity = 1;
120
+				} else {
121
+					$unit_price = $line_item->unit_price();
122
+					$line_item_quantity = $line_item->quantity();
123
+				}
124
+				$item = array(
125
+					// Item Name.  127 char max.
126
+					'l_name'                 => substr(
127
+						$gateway_formatter->formatLineItemName($line_item, $payment),
128
+						0,
129
+						127
130
+					),
131
+					// Item description.  127 char max.
132
+					'l_desc'                 => substr(
133
+						$gateway_formatter->formatLineItemDesc($line_item, $payment),
134
+						0,
135
+						127
136
+					),
137
+					// Cost of individual item.
138
+					'l_amt'                  => $unit_price,
139
+					// Item Number.  127 char max.
140
+					'l_number'               => $item_num++,
141
+					// Item quantity.  Must be any positive integer.
142
+					'l_qty'                  => $line_item_quantity,
143
+					// Item's sales tax amount.
144
+					'l_taxamt'               => '',
145
+					// eBay auction number of item.
146
+					'l_ebayitemnumber'       => '',
147
+					// eBay transaction ID of purchased item.
148
+					'l_ebayitemauctiontxnid' => '',
149
+					// eBay order ID for the item.
150
+					'l_ebayitemorderid'      => '',
151
+				);
152
+				// add to array of all items
153
+				array_push($order_items, $item);
154
+			}
155
+			$item_amount = $total_line_item->get_items_total();
156
+			$tax_amount = $total_line_item->get_total_tax();
157
+		} else {
158
+			$order_items = array();
159
+			$item_amount = $payment->amount();
160
+			$tax_amount = 0;
161
+			array_push($order_items, array(
162
+				// Item Name.  127 char max.
163
+				'l_name'   => substr(
164
+					$gateway_formatter->formatPartialPaymentLineItemName($payment),
165
+					0,
166
+					127
167
+				),
168
+				// Item description.  127 char max.
169
+				'l_desc'   => substr(
170
+					$gateway_formatter->formatPartialPaymentLineItemDesc($payment),
171
+					0,
172
+					127
173
+				),
174
+				// Cost of individual item.
175
+				'l_amt'    => $payment->amount(),
176
+				// Item Number.  127 char max.
177
+				'l_number' => 1,
178
+				// Item quantity.  Must be any positive integer.
179
+				'l_qty'    => 1,
180
+			));
181
+		}
182
+		// Populate data arrays with order data.
183
+		$DPFields = array(
184
+			// How you want to obtain payment ?
185
+			// Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture.
186
+			// Sale indicates that this is a final sale for which you are requesting payment.  Default is Sale.
187
+			'paymentaction'    => 'Sale',
188
+			// Required.  IP address of the payer's browser.
189
+			'ipaddress'        => $_SERVER['REMOTE_ADDR'],
190
+			// Flag to determine whether you want the results returned by FMF.  1 or 0.  Default is 0.
191
+			'returnfmfdetails' => '1',
192
+		);
193
+		$CCDetails = array(
194
+			// Required. Type of credit card.  Visa, MasterCard, Discover, Amex, Maestro, Solo.
195
+			// If Maestro or Solo, the currency code must be GBP.
196
+			//  In addition, either start date or issue number must be specified.
197
+			'creditcardtype' => $billing_info['credit_card_type'],
198
+			// Required.  Credit card number.  No spaces or punctuation.
199
+			'acct'           => $billing_info['credit_card'],
200
+			// Required.  Credit card expiration date.  Format is MMYYYY
201
+			'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
202
+			// Requirements determined by your PayPal account settings.  Security digits for credit card.
203
+			'cvv2'           => $billing_info['cvv'],
204
+		);
205
+		$PayerInfo = array(
206
+			// Email address of payer.
207
+			'email'       => $billing_info['email'],
208
+			// Unique PayPal customer ID for payer.
209
+			'payerid'     => '',
210
+			// Status of payer.  Values are verified or unverified
211
+			'payerstatus' => '',
212
+			// Payer's business name.
213
+			'business'    => '',
214
+		);
215
+		$PayerName = array(
216
+			// Payer's salutation.  20 char max.
217
+			'salutation' => '',
218
+			// Payer's first name.  25 char max.
219
+			'firstname'  => substr($billing_info['first_name'], 0, 25),
220
+			// Payer's middle name.  25 char max.
221
+			'middlename' => '',
222
+			// Payer's last name.  25 char max.
223
+			'lastname'   => substr($billing_info['last_name'], 0, 25),
224
+			// Payer's suffix.  12 char max.
225
+			'suffix'     => '',
226
+		);
227
+		$BillingAddress = array(
228
+			// Required.  First street address.
229
+			'street'      => $billing_info['address'],
230
+			// Second street address.
231
+			'street2'     => $billing_info['address2'],
232
+			// Required.  Name of City.
233
+			'city'        => $billing_info['city'],
234
+			// Required. Name of State or Province.
235
+			'state'       => substr($billing_info['state'], 0, 40),
236
+			// Required.  Country code.
237
+			'countrycode' => $billing_info['country'],
238
+			// Required.  Postal code of payer.
239
+			'zip'         => $billing_info['zip'],
240
+		);
241
+		// check if the registration info contains the needed fields for paypal pro
242
+		// (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
243
+		if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
244
+			$use_registration_address_info = true;
245
+		} else {
246
+			$use_registration_address_info = false;
247
+		}
248
+		// so if the attendee has enough data to fill out PayPal Pro's shipping info, use it.
249
+		// If not, use the billing info again
250
+		$ShippingAddress = array(
251
+			'shiptoname'     => substr($use_registration_address_info
252
+				? $attendee->full_name()
253
+				: $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
254
+			'shiptostreet'   => substr($use_registration_address_info
255
+				? $attendee->address()
256
+				: $billing_info['address'], 0, 100),
257
+			'shiptostreet2'  => substr($use_registration_address_info
258
+				? $attendee->address2() : $billing_info['address2'], 0, 100),
259
+			'shiptocity'     => substr($use_registration_address_info
260
+				? $attendee->city()
261
+				: $billing_info['city'], 0, 40),
262
+			'shiptostate'          => substr($use_registration_address_info
263
+				? $attendee->state_name()
264
+				: $billing_info['state'], 0, 40),
265
+			'shiptocountry'  => $use_registration_address_info
266
+				? $attendee->country_ID()
267
+				: $billing_info['country'],
268
+			'shiptozip'      => substr($use_registration_address_info
269
+				? $attendee->zip()
270
+				: $billing_info['zip'], 0, 20),
271
+			'shiptophonenum' => substr($use_registration_address_info
272
+				? $attendee->phone()
273
+				: $billing_info['phone'], 0, 20),
274
+		);
275
+		$PaymentDetails = array(
276
+			// Required.  Total amount of order, including shipping, handling, and tax.
277
+			'amt'          => $gateway_formatter->formatCurrency($payment->amount()),
278
+			// Required.  Three-letter currency code.  Default is USD.
279
+			'currencycode' => $payment->currency_code(),
280
+			// Required if you include itemized cart details. (L_AMTn, etc.)
281
+			// Subtotal of items not including S&H, or tax.
282
+			'itemamt'      => $gateway_formatter->formatCurrency($item_amount),//
283
+			// Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
284
+			'shippingamt'  => '',
285
+			// Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
286
+			'handlingamt'  => '',
287
+			// Required if you specify itemized cart tax details.
288
+			// Sum of tax for all items on the order.  Total sales tax.
289
+			'taxamt'       => $gateway_formatter->formatCurrency($tax_amount),
290
+			// Description of the order the customer is purchasing.  127 char max.
291
+			'desc'         => $order_description,
292
+			// Free-form field for your own use.  256 char max.
293
+			'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
294
+			// Your own invoice or tracking number
295
+			'invnum'       => wp_generate_password(12, false),// $transaction->ID(),
296
+			// URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
297
+			'notifyurl'    => '',
298
+			'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this
299
+		);
300
+		// Wrap all data arrays into a single, "master" array which will be passed into the class function.
301
+		$PayPalRequestData = array(
302
+			'DPFields'        => $DPFields,
303
+			'CCDetails'       => $CCDetails,
304
+			'PayerInfo'       => $PayerInfo,
305
+			'PayerName'       => $PayerName,
306
+			'BillingAddress'  => $BillingAddress,
307
+			'ShippingAddress' => $ShippingAddress,
308
+			'PaymentDetails'  => $PaymentDetails,
309
+			'OrderItems'      => $order_items,
310
+		);
311
+		$this->_log_clean_request($PayPalRequestData, $payment);
312
+		try {
313
+			$PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
314
+			// remove PCI-sensitive data so it doesn't get stored
315
+			$PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
316
+			if (isset($PayPalResult['L_ERRORCODE0']) && $PayPalResult['L_ERRORCODE0'] === '10002') {
317
+				$message = esc_html__('PayPal did not accept your API username, password, or signature. Please double-check these credentials and if debug mode is on.', 'event_espresso');
318
+			} elseif (isset($PayPalResult['L_LONGMESSAGE0'])) {
319
+				$message = $PayPalResult['L_LONGMESSAGE0'];
320
+			} else {
321
+				$message = $PayPalResult['ACK'];
322
+			}
323
+			if (empty($PayPalResult['RAWRESPONSE'])) {
324
+				$payment->set_status($this->_pay_model->failed_status());
325
+				$payment->set_gateway_response(esc_html__('No response received from Paypal Pro', 'event_espresso'));
326
+				$payment->set_details($PayPalResult);
327
+			} else {
328
+				if ($this->_APICallSuccessful($PayPalResult)) {
329
+					$payment->set_status($this->_pay_model->approved_status());
330
+				} else {
331
+					$payment->set_status($this->_pay_model->declined_status());
332
+				}
333
+				// make sure we interpret the AMT as a float, not an international string
334
+				// (where periods are thousand separators)
335
+				$payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
336
+				$payment->set_gateway_response($message);
337
+				$payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID'])
338
+					? $PayPalResult['TRANSACTIONID']
339
+					: null);
340
+				$primary_registration_code = $primary_registrant instanceof EE_Registration
341
+					? $primary_registrant->reg_code()
342
+					: '';
343
+				$payment->set_extra_accntng($primary_registration_code);
344
+				$payment->set_details($PayPalResult);
345
+			}
346
+		} catch (Exception $e) {
347
+			$payment->set_status($this->_pay_model->failed_status());
348
+			$payment->set_gateway_response($e->getMessage());
349
+		}
350
+		// $payment->set_status( $this->_pay_model->declined_status() );
351
+		// $payment->set_gateway_response( '' );
352
+		return $payment;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * CLeans out sensitive CC data and then logs it, and returns the cleaned request
359
+	 *
360
+	 * @param array       $request
361
+	 * @param EEI_Payment $payment
362
+	 * @return void
363
+	 */
364
+	private function _log_clean_request($request, $payment)
365
+	{
366
+		$cleaned_request_data = $request;
367
+		unset($cleaned_request_data['CCDetails']['acct']);
368
+		unset($cleaned_request_data['CCDetails']['cvv2']);
369
+		unset($cleaned_request_data['CCDetails']['expdate']);
370
+		$this->log(array('Paypal Request' => $cleaned_request_data), $payment);
371
+	}
372
+
373
+
374
+
375
+	/**
376
+	 * Cleans the response, logs it, and returns it
377
+	 *
378
+	 * @param array       $response
379
+	 * @param EEI_Payment $payment
380
+	 * @return array cleaned
381
+	 */
382
+	private function _log_clean_response($response, $payment)
383
+	{
384
+		unset($response['REQUESTDATA']['CREDITCARDTYPE']);
385
+		unset($response['REQUESTDATA']['ACCT']);
386
+		unset($response['REQUESTDATA']['EXPDATE']);
387
+		unset($response['REQUESTDATA']['CVV2']);
388
+		unset($response['RAWREQUEST']);
389
+		$this->log(array('Paypal Response' => $response), $payment);
390
+		return $response;
391
+	}
392
+
393
+
394
+
395
+	/**
396
+	 * @param $DataArray
397
+	 * @return array
398
+	 */
399
+	private function prep_and_curl_request($DataArray)
400
+	{
401
+		// Create empty holders for each portion of the NVP string
402
+		$DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
403
+		$CCDetailsNVP = '';
404
+		$PayerInfoNVP = '';
405
+		$PayerNameNVP = '';
406
+		$BillingAddressNVP = '';
407
+		$ShippingAddressNVP = '';
408
+		$PaymentDetailsNVP = '';
409
+		$OrderItemsNVP = '';
410
+		$Secure3DNVP = '';
411
+		// DP Fields
412
+		$DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
413
+		foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
414
+			$DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
415
+		}
416
+		// CC Details Fields
417
+		$CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
418
+		foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
419
+			$CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
420
+		}
421
+		// PayerInfo Type Fields
422
+		$PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
423
+		foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
424
+			$PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
425
+		}
426
+		// Payer Name Fields
427
+		$PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
428
+		foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
429
+			$PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
430
+		}
431
+		// Address Fields (Billing)
432
+		$BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
433
+		foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
434
+			$BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
435
+		}
436
+		// Payment Details Type Fields
437
+		$PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
438
+		foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
439
+			$PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
440
+		}
441
+		// Payment Details Item Type Fields
442
+		$OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
443
+		$n = 0;
444
+		foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
445
+			$CurrentItem = $OrderItems[ $OrderItemsVar ];
446
+			foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
447
+				$OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
448
+			}
449
+			$n++;
450
+		}
451
+		// Ship To Address Fields
452
+		$ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
453
+		foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
454
+			$ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
455
+		}
456
+		// 3D Secure Fields
457
+		$Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
458
+		foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
459
+			$Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
460
+		}
461
+		// Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
462
+		$NVPRequest = 'USER='
463
+					  . $this->_api_username
464
+					  . '&PWD='
465
+					  . $this->_api_password
466
+					  . '&VERSION=64.0'
467
+					  . '&SIGNATURE='
468
+					  . $this->_api_signature
469
+					  . $DPFieldsNVP
470
+					  . $CCDetailsNVP
471
+					  . $PayerInfoNVP
472
+					  . $PayerNameNVP
473
+					  . $BillingAddressNVP
474
+					  . $PaymentDetailsNVP
475
+					  . $OrderItemsNVP
476
+					  . $ShippingAddressNVP
477
+					  . $Secure3DNVP;
478
+		$NVPResponse = $this->_CURLRequest($NVPRequest);
479
+		$NVPRequestArray = $this->_NVPToArray($NVPRequest);
480
+		$NVPResponseArray = $this->_NVPToArray($NVPResponse);
481
+		$Errors = $this->_GetErrors($NVPResponseArray);
482
+		$NVPResponseArray['ERRORS'] = $Errors;
483
+		$NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
484
+		$NVPResponseArray['RAWREQUEST'] = $NVPRequest;
485
+		$NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
486
+		return $NVPResponseArray;
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * @param $Request
493
+	 * @return mixed
494
+	 */
495
+	private function _CURLRequest($Request)
496
+	{
497
+		$EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
498
+		$curl = curl_init();
499
+		curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
500
+		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
501
+		curl_setopt($curl, CURLOPT_TIMEOUT, 60);
502
+		curl_setopt($curl, CURLOPT_URL, $EndPointURL);
503
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
504
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
505
+		curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
506
+		// execute the curl POST
507
+		$Response = curl_exec($curl);
508
+		curl_close($curl);
509
+		return $Response;
510
+	}
511
+
512
+
513
+
514
+	/**
515
+	 * @param $NVPString
516
+	 * @return array
517
+	 */
518
+	private function _NVPToArray($NVPString)
519
+	{
520
+		// prepare responses into array
521
+		$proArray = array();
522
+		while (strlen($NVPString)) {
523
+			// name
524
+			$keypos = strpos($NVPString, '=');
525
+			$keyval = substr($NVPString, 0, $keypos);
526
+			// value
527
+			$valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
528
+			$valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
529
+			// decoding the response
530
+			$proArray[ $keyval ] = urldecode($valval);
531
+			$NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
532
+		}
533
+		return $proArray;
534
+	}
535
+
536
+
537
+
538
+	/**
539
+	 * @param array $PayPalResult
540
+	 * @return bool
541
+	 */
542
+	private function _APICallSuccessful($PayPalResult)
543
+	{
544
+		$approved = false;
545
+		// check main response message from PayPal
546
+		if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
547
+			$ack = strtoupper($PayPalResult['ACK']);
548
+			$approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
549
+		}
550
+		return $approved;
551
+	}
552
+
553
+
554
+
555
+	/**
556
+	 * @param $DataArray
557
+	 * @return array
558
+	 */
559
+	private function _GetErrors($DataArray)
560
+	{
561
+		$Errors = array();
562
+		$n = 0;
563
+		while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) {
564
+			$LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : '';
565
+			$LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ])
566
+				? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ]
567
+				: '';
568
+			$LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ])
569
+				? $DataArray[ 'L_LONGMESSAGE' . $n . '' ]
570
+				: '';
571
+			$LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ])
572
+				? $DataArray[ 'L_SEVERITYCODE' . $n . '' ]
573
+				: '';
574
+			$CurrentItem = array(
575
+				'L_ERRORCODE'    => $LErrorCode,
576
+				'L_SHORTMESSAGE' => $LShortMessage,
577
+				'L_LONGMESSAGE'  => $LLongMessage,
578
+				'L_SEVERITYCODE' => $LSeverityCode,
579
+			);
580
+			array_push($Errors, $CurrentItem);
581
+			$n++;
582
+		}
583
+		return $Errors;
584
+	}
585
+
586
+
587
+
588
+	/**
589
+	 *        nothing to see here...  move along....
590
+	 *
591
+	 * @access protected
592
+	 * @param $Errors
593
+	 * @return string
594
+	 */
595
+	private function _DisplayErrors($Errors)
596
+	{
597
+		$error = '';
598
+		foreach ($Errors as $ErrorVar => $ErrorVal) {
599
+			$CurrentError = $Errors[ $ErrorVar ];
600
+			foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
601
+				$CurrentVarName = '';
602
+				if ($CurrentErrorVar == 'L_ERRORCODE') {
603
+					$CurrentVarName = 'Error Code';
604
+				} elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
605
+					$CurrentVarName = 'Short Message';
606
+				} elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
607
+					$CurrentVarName = 'Long Message';
608
+				} elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
609
+					$CurrentVarName = 'Severity Code';
610
+				}
611
+				$error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
612
+			}
613
+		}
614
+		return $error;
615
+	}
616 616
 }
Please login to merge, or discard this patch.