Completed
Branch db-repair-tool (5be9a7)
by
unknown
13:43 queued 07:31
created
core/helpers/EEH_Form_Fields.helper.php 2 patches
Indentation   +2064 added lines, -2064 removed lines patch added patch discarded remove patch
@@ -27,1057 +27,1057 @@  discard block
 block discarded – undo
27 27
  */
28 28
 class EEH_Form_Fields
29 29
 {
30
-    /**
31
-     *  Generates HTML for the forms used on admin pages
32
-     *
33
-     *
34
-     * @static
35
-     * @access public
36
-     * @param array $input_vars - array of input field details
37
-     *                          format:
38
-     *                          $template_form_fields['field-id'] = array(
39
-     *                          'name' => 'name_attribute',
40
-     *                          'label' => esc_html__('Field Label', 'event_espresso'), //or false
41
-     *                          'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden',
42
-     *                          'checkbox', 'wp_editor'
43
-     *                          'type' => 'int', //what "type" the value is (i.e. string, int etc)
44
-     *                          'required' => false, //boolean for whether the field is required
45
-     *                          'validation' => true, //boolean, whether to validate the field (todo)
46
-     *                          'value' => 'some_value_for_field', //what value is used for field
47
-     *                          'format' => '%d', //what format the value is (%d, %f, or %s)
48
-     *                          'db-col' => 'column_in_db' //used to indicate which column the field corresponds with
49
-     *                          in the db
50
-     *                          'options' => optiona, optionb || array('value' => 'label', '') //if the input type is
51
-     *                          "select", this allows you to set the args for the different <option> tags.
52
-     *                          'tabindex' => 1 //this allows you to set the tabindex for the field.
53
-     *                          'append_content' => '' //this allows you to send in html content to append to the
54
-     *                          field.
55
-     *                          )
56
-     * @param array $form_id    - used for defining unique identifiers for the form.
57
-     * @return string
58
-     * @todo   : at some point we can break this down into other static methods to abstract it a bit better.
59
-     */
60
-    public static function get_form_fields($input_vars = [], $form_id = false)
61
-    {
62
-
63
-        if (empty($input_vars)) {
64
-            EE_Error::add_error(
65
-                esc_html__('missing required variables for the form field generator', 'event_espresso'),
66
-                __FILE__,
67
-                __FUNCTION__,
68
-                __LINE__
69
-            );
70
-            return false;
71
-        }
72
-
73
-        $output        = "";
74
-        $inputs        = [];
75
-        $hidden_inputs = [];
76
-
77
-        // cycle thru inputs
78
-        foreach ($input_vars as $input_key => $input_value) {
79
-            $defaults = [
80
-                'append_content' => '',
81
-                'css_class'      => '',
82
-                'cols'           => 80,
83
-                'db-col'         => 'column_in_db',
84
-                'format'         => '%d',
85
-                'input'          => 'hidden',
86
-                'label'          => esc_html__('No label', 'event_espresso'),
87
-                'name'           => $input_key,
88
-                'options'        => [],
89
-                'required'       => false,
90
-                'tabindex'       => 0,
91
-                'rows'           => 10,
92
-                'type'           => 'int',
93
-                'validation'     => true,
94
-                'value'          => 'some_value_for_field',
95
-            ];
96
-
97
-            $input_value = wp_parse_args($input_value, $defaults);
98
-
99
-            $append_content = $input_value['append_content'];
100
-            $css_class      = $input_value['css_class'];
101
-            $cols           = $input_value['cols'];
102
-            $label          = $input_value['label'];
103
-            $name           = $input_value['name'];
104
-            $options        = $input_value['options'];
105
-            $required       = $input_value['required'];
106
-            $tab_index      = $input_value['tabindex'];
107
-            $rows           = $input_value['rows'];
108
-            $type           = $input_value['input'];
109
-            $value          = $input_value['value'];
110
-
111
-            $id    = $form_id ? $form_id . '-' . $input_key : $input_key;
112
-            $class = $required ? 'required ' . $css_class : $css_class;
113
-
114
-            // what type of input are we dealing with ?
115
-            switch ($type) {
116
-                case 'checkbox':
117
-                case 'radio':
118
-                    $field = self::adminMulti($value, $class, $id, $name, $required, $tab_index, $type, 1, $label);
119
-                    $field .= $append_content ?: '';
120
-                    break;
121
-
122
-                case 'hidden':
123
-                    $field           = null;
124
-                    $hidden_inputs[] = self::adminHidden($css_class, $id, $name, $value);
125
-                    break;
126
-
127
-                case 'select':
128
-                    $options = is_array($options) ? $options : explode(',', $options);
129
-                    $field   = self::adminLabel($id, $label, $required);
130
-                    $field   .= self::adminSelect($value, $class, $id, $name, $required, $tab_index, $options);
131
-                    $field   .= $append_content ?: '';
132
-                    break;
133
-
134
-                case 'textarea':
135
-                    $field = self::adminLabel($id, $label, $required);
136
-                    $field .= self::adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value);
137
-                    $field .= $append_content ?: '';
138
-                    break;
139
-
140
-                case 'wp_editor':
141
-                    $label = esc_html($label);
142
-                    $field = "<h4>{$label}</h4>";
143
-                    $field .= $append_content ?: '';
144
-                    $field .= self::adminWpEditor(
145
-                        $class,
146
-                        $id,
147
-                        $name,
148
-                        $rows,
149
-                        $tab_index,
150
-                        $value
151
-                    );
152
-                    break;
153
-
154
-                default:
155
-                    $field = self::adminLabel($id, $label, $required);
156
-                    $field .= self::adminText($class, $id, $name, $required, $tab_index, $value);
157
-                    $field .= $append_content ?: '';
158
-            }
159
-            if ($field) {
160
-                $inputs[] = $field;
161
-            }
162
-        } // end foreach( $input_vars as $input_key => $input_value )
163
-
164
-        if (! empty($inputs)) {
165
-            $glue   = "
30
+	/**
31
+	 *  Generates HTML for the forms used on admin pages
32
+	 *
33
+	 *
34
+	 * @static
35
+	 * @access public
36
+	 * @param array $input_vars - array of input field details
37
+	 *                          format:
38
+	 *                          $template_form_fields['field-id'] = array(
39
+	 *                          'name' => 'name_attribute',
40
+	 *                          'label' => esc_html__('Field Label', 'event_espresso'), //or false
41
+	 *                          'input' => 'hidden', //field input type can be 'text', 'select', 'textarea', 'hidden',
42
+	 *                          'checkbox', 'wp_editor'
43
+	 *                          'type' => 'int', //what "type" the value is (i.e. string, int etc)
44
+	 *                          'required' => false, //boolean for whether the field is required
45
+	 *                          'validation' => true, //boolean, whether to validate the field (todo)
46
+	 *                          'value' => 'some_value_for_field', //what value is used for field
47
+	 *                          'format' => '%d', //what format the value is (%d, %f, or %s)
48
+	 *                          'db-col' => 'column_in_db' //used to indicate which column the field corresponds with
49
+	 *                          in the db
50
+	 *                          'options' => optiona, optionb || array('value' => 'label', '') //if the input type is
51
+	 *                          "select", this allows you to set the args for the different <option> tags.
52
+	 *                          'tabindex' => 1 //this allows you to set the tabindex for the field.
53
+	 *                          'append_content' => '' //this allows you to send in html content to append to the
54
+	 *                          field.
55
+	 *                          )
56
+	 * @param array $form_id    - used for defining unique identifiers for the form.
57
+	 * @return string
58
+	 * @todo   : at some point we can break this down into other static methods to abstract it a bit better.
59
+	 */
60
+	public static function get_form_fields($input_vars = [], $form_id = false)
61
+	{
62
+
63
+		if (empty($input_vars)) {
64
+			EE_Error::add_error(
65
+				esc_html__('missing required variables for the form field generator', 'event_espresso'),
66
+				__FILE__,
67
+				__FUNCTION__,
68
+				__LINE__
69
+			);
70
+			return false;
71
+		}
72
+
73
+		$output        = "";
74
+		$inputs        = [];
75
+		$hidden_inputs = [];
76
+
77
+		// cycle thru inputs
78
+		foreach ($input_vars as $input_key => $input_value) {
79
+			$defaults = [
80
+				'append_content' => '',
81
+				'css_class'      => '',
82
+				'cols'           => 80,
83
+				'db-col'         => 'column_in_db',
84
+				'format'         => '%d',
85
+				'input'          => 'hidden',
86
+				'label'          => esc_html__('No label', 'event_espresso'),
87
+				'name'           => $input_key,
88
+				'options'        => [],
89
+				'required'       => false,
90
+				'tabindex'       => 0,
91
+				'rows'           => 10,
92
+				'type'           => 'int',
93
+				'validation'     => true,
94
+				'value'          => 'some_value_for_field',
95
+			];
96
+
97
+			$input_value = wp_parse_args($input_value, $defaults);
98
+
99
+			$append_content = $input_value['append_content'];
100
+			$css_class      = $input_value['css_class'];
101
+			$cols           = $input_value['cols'];
102
+			$label          = $input_value['label'];
103
+			$name           = $input_value['name'];
104
+			$options        = $input_value['options'];
105
+			$required       = $input_value['required'];
106
+			$tab_index      = $input_value['tabindex'];
107
+			$rows           = $input_value['rows'];
108
+			$type           = $input_value['input'];
109
+			$value          = $input_value['value'];
110
+
111
+			$id    = $form_id ? $form_id . '-' . $input_key : $input_key;
112
+			$class = $required ? 'required ' . $css_class : $css_class;
113
+
114
+			// what type of input are we dealing with ?
115
+			switch ($type) {
116
+				case 'checkbox':
117
+				case 'radio':
118
+					$field = self::adminMulti($value, $class, $id, $name, $required, $tab_index, $type, 1, $label);
119
+					$field .= $append_content ?: '';
120
+					break;
121
+
122
+				case 'hidden':
123
+					$field           = null;
124
+					$hidden_inputs[] = self::adminHidden($css_class, $id, $name, $value);
125
+					break;
126
+
127
+				case 'select':
128
+					$options = is_array($options) ? $options : explode(',', $options);
129
+					$field   = self::adminLabel($id, $label, $required);
130
+					$field   .= self::adminSelect($value, $class, $id, $name, $required, $tab_index, $options);
131
+					$field   .= $append_content ?: '';
132
+					break;
133
+
134
+				case 'textarea':
135
+					$field = self::adminLabel($id, $label, $required);
136
+					$field .= self::adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value);
137
+					$field .= $append_content ?: '';
138
+					break;
139
+
140
+				case 'wp_editor':
141
+					$label = esc_html($label);
142
+					$field = "<h4>{$label}</h4>";
143
+					$field .= $append_content ?: '';
144
+					$field .= self::adminWpEditor(
145
+						$class,
146
+						$id,
147
+						$name,
148
+						$rows,
149
+						$tab_index,
150
+						$value
151
+					);
152
+					break;
153
+
154
+				default:
155
+					$field = self::adminLabel($id, $label, $required);
156
+					$field .= self::adminText($class, $id, $name, $required, $tab_index, $value);
157
+					$field .= $append_content ?: '';
158
+			}
159
+			if ($field) {
160
+				$inputs[] = $field;
161
+			}
162
+		} // end foreach( $input_vars as $input_key => $input_value )
163
+
164
+		if (! empty($inputs)) {
165
+			$glue   = "
166 166
                 </li>
167 167
                 <li>
168 168
                     ";
169
-            $inputs = implode($glue, $inputs);
170
-            $output = "
169
+			$inputs = implode($glue, $inputs);
170
+			$output = "
171 171
             <ul>
172 172
                 <li>
173 173
                 {$inputs}
174 174
                 </li>
175 175
             </ul>
176 176
             ";
177
-        }
178
-        return $output . implode("\n", $hidden_inputs);
179
-    }
180
-
181
-
182
-    /**
183
-     * form_fields_array
184
-     * This utility function assembles form fields from a given structured array with field information.
185
-     * //TODO: This is an alternate generator that we may want to use instead.
186
-     *
187
-     * @param array $fields structured array of fields to assemble in the following format:
188
-     *                      [field_name] => array(
189
-     *                      ['label'] => 'label for field',
190
-     *                      ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select
191
-     *                      type of field you can indicated the labels for each option via this index
192
-     *                      ['extra_desc'] => 'extra description for the field', //optional
193
-     *                      ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults
194
-     *                      to text
195
-     *                      ['value'] => 'value that goes in the field', //(if multi then this is an array of values
196
-     *                      and the 'default' paramater will be used for what is selected)
197
-     *                      ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)',
198
-     *                      ['class'] => 'name-of-class(es)-for-input',
199
-     *                      ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi
200
-     *                      select type of field you can indicate the css class for each option via this index.
201
-     *                      ['id'] => 'css-id-for-input') //defaults to 'field_name'
202
-     *                      ['unique_id'] => 1 //defaults to empty string.  This is useful for when the fields
203
-     *                      generated are going to be used in a loop and you want to make sure that the field
204
-     *                      identifiers are unique from each other.
205
-     *                      ['dimensions'] => array(100,300), //defaults to empty array.  This is used by field types
206
-     *                      such as textarea to indicate cols/rows.
207
-     *                      ['tabindex'] => '' //this allows you to set the tabindex for the field.
208
-     *                      ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally
209
-     *                      contain an array of arguments for the editor setup.
210
-     *
211
-     * @return array         an array of inputs for form indexed by field name, and in the following structure:
212
-     *     [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}'
213
-     */
214
-    public static function get_form_fields_array($fields)
215
-    {
216
-
217
-        $form_fields = [];
218
-        $fields      = (array) $fields;
219
-
220
-        foreach ($fields as $field_name => $field_atts) {
221
-            // defaults:
222
-            $defaults = [
223
-                'class'         => '',
224
-                'classes'       => '',
225
-                'default'       => '',
226
-                'dimensions'    => ['10', '5'],
227
-                'extra_desc'    => '',
228
-                'id'            => $field_name,
229
-                'label'         => '',
230
-                'labels'        => '',
231
-                'required'      => false,
232
-                'tabindex'      => 0,
233
-                'type'          => 'text',
234
-                'unique_id'     => '',
235
-                'value'         => '',
236
-                'wpeditor_args' => [],
237
-            ];
238
-            // merge defaults with passed arguments
239
-            $_fields = wp_parse_args($field_atts, $defaults);
240
-
241
-            $class          = $_fields['class'];
242
-            $classes        = $_fields['classes'];
243
-            $default        = $_fields['default'];
244
-            $dims           = $_fields['dimensions'];
245
-            $extra_desc     = $_fields['extra_desc'];
246
-            $id             = $_fields['id'];
247
-            $label          = $_fields['label'];
248
-            $labels         = $_fields['labels'];
249
-            $required       = $_fields['required'];
250
-            $tab_index      = $_fields['tabindex'];
251
-            $type           = $_fields['type'];
252
-            $unique_id      = $_fields['unique_id'];
253
-            $value          = $_fields['value'];
254
-            $wp_editor_args = $_fields['wpeditor_args'];
255
-
256
-            // generate label
257
-            $label = ! empty($label) ? self::adminLabel($id, $label, $required) : '';
258
-            // generate field name
259
-            $name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
260
-
261
-            // we determine what we're building based on the type
262
-            switch ($type) {
263
-                case 'checkbox':
264
-                case 'radio':
265
-                    if (is_array($value)) {
266
-                        $c_input = '';
267
-                        foreach ($value as $key => $val) {
268
-                            $c_input .= self::adminMulti(
269
-                                $default,
270
-                                isset($classes[ $key ]) ? $classes[ $key ] : '',
271
-                                $field_name . '_' . $value,
272
-                                $name,
273
-                                $required,
274
-                                $tab_index,
275
-                                $type,
276
-                                $val,
277
-                                isset($labels[ $key ]) ? $labels[ $key ] : ''
278
-                            );
279
-                        }
280
-                        $field = $c_input;
281
-                    } else {
282
-                        $field = self::adminMulti(
283
-                            $default,
284
-                            $class,
285
-                            $id,
286
-                            $name,
287
-                            $required,
288
-                            $tab_index,
289
-                            $type,
290
-                            $value,
291
-                            $_fields['label']
292
-                        );
293
-                    }
294
-                    break;
295
-
296
-                case 'hidden':
297
-                    $field = self::adminHidden($class, $id, $name, $value);
298
-                    break;
299
-
300
-                case 'select':
301
-                    $options = [];
302
-                    foreach ($value as $key => $val) {
303
-                        $options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : '';
304
-                    }
305
-                    $field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options);
306
-                    break;
307
-
308
-                case 'textarea':
309
-                    $field =
310
-                        self::adminTextarea($class, $dims[0], $id, $name, $required, $dims[1], $tab_index, $value);
311
-                    break;
312
-
313
-                case 'wp_editor':
314
-                    $field = self::adminWpEditor(
315
-                        $class,
316
-                        $_fields['id'],
317
-                        $name,
318
-                        $dims[1],
319
-                        $tab_index,
320
-                        $value,
321
-                        $wp_editor_args
322
-                    );
323
-                    break;
324
-
325
-                default:
326
-                    $field = self::adminText($class, $id, $name, $required, $tab_index, $value);
327
-            }
328
-
329
-            $form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc];
330
-        }
331
-
332
-        return $form_fields;
333
-    }
334
-
335
-
336
-    /**
337
-     * @param string $class
338
-     * @param string $id
339
-     * @param string $name
340
-     * @param string $value
341
-     * @return string
342
-     * @since   4.10.14.p
343
-     */
344
-    private static function adminHidden($class, $id, $name, $value)
345
-    {
346
-        $id    = esc_attr($id);
347
-        $name  = esc_attr($name);
348
-        $class = esc_attr($class);
349
-        return "
177
+		}
178
+		return $output . implode("\n", $hidden_inputs);
179
+	}
180
+
181
+
182
+	/**
183
+	 * form_fields_array
184
+	 * This utility function assembles form fields from a given structured array with field information.
185
+	 * //TODO: This is an alternate generator that we may want to use instead.
186
+	 *
187
+	 * @param array $fields structured array of fields to assemble in the following format:
188
+	 *                      [field_name] => array(
189
+	 *                      ['label'] => 'label for field',
190
+	 *                      ['labels'] => array('label_1', 'label_2'); //optional - if the field type is a multi select
191
+	 *                      type of field you can indicated the labels for each option via this index
192
+	 *                      ['extra_desc'] => 'extra description for the field', //optional
193
+	 *                      ['type'] => 'textarea'|'text'|'wp_editor'|'checkbox'|'radio'|'hidden'|'select', //defaults
194
+	 *                      to text
195
+	 *                      ['value'] => 'value that goes in the field', //(if multi then this is an array of values
196
+	 *                      and the 'default' paramater will be used for what is selected)
197
+	 *                      ['default'] => 'default if the field type is multi (i.e. select or radios or checkboxes)',
198
+	 *                      ['class'] => 'name-of-class(es)-for-input',
199
+	 *                      ['classes'] => array('class_1', 'class_2'); //optional - if the field type is a multi
200
+	 *                      select type of field you can indicate the css class for each option via this index.
201
+	 *                      ['id'] => 'css-id-for-input') //defaults to 'field_name'
202
+	 *                      ['unique_id'] => 1 //defaults to empty string.  This is useful for when the fields
203
+	 *                      generated are going to be used in a loop and you want to make sure that the field
204
+	 *                      identifiers are unique from each other.
205
+	 *                      ['dimensions'] => array(100,300), //defaults to empty array.  This is used by field types
206
+	 *                      such as textarea to indicate cols/rows.
207
+	 *                      ['tabindex'] => '' //this allows you to set the tabindex for the field.
208
+	 *                      ['wpeditor_args'] => array() //if the type of field is wpeditor then this can optionally
209
+	 *                      contain an array of arguments for the editor setup.
210
+	 *
211
+	 * @return array         an array of inputs for form indexed by field name, and in the following structure:
212
+	 *     [field_name] => array( 'label' => '{label_html}', 'field' => '{input_html}'
213
+	 */
214
+	public static function get_form_fields_array($fields)
215
+	{
216
+
217
+		$form_fields = [];
218
+		$fields      = (array) $fields;
219
+
220
+		foreach ($fields as $field_name => $field_atts) {
221
+			// defaults:
222
+			$defaults = [
223
+				'class'         => '',
224
+				'classes'       => '',
225
+				'default'       => '',
226
+				'dimensions'    => ['10', '5'],
227
+				'extra_desc'    => '',
228
+				'id'            => $field_name,
229
+				'label'         => '',
230
+				'labels'        => '',
231
+				'required'      => false,
232
+				'tabindex'      => 0,
233
+				'type'          => 'text',
234
+				'unique_id'     => '',
235
+				'value'         => '',
236
+				'wpeditor_args' => [],
237
+			];
238
+			// merge defaults with passed arguments
239
+			$_fields = wp_parse_args($field_atts, $defaults);
240
+
241
+			$class          = $_fields['class'];
242
+			$classes        = $_fields['classes'];
243
+			$default        = $_fields['default'];
244
+			$dims           = $_fields['dimensions'];
245
+			$extra_desc     = $_fields['extra_desc'];
246
+			$id             = $_fields['id'];
247
+			$label          = $_fields['label'];
248
+			$labels         = $_fields['labels'];
249
+			$required       = $_fields['required'];
250
+			$tab_index      = $_fields['tabindex'];
251
+			$type           = $_fields['type'];
252
+			$unique_id      = $_fields['unique_id'];
253
+			$value          = $_fields['value'];
254
+			$wp_editor_args = $_fields['wpeditor_args'];
255
+
256
+			// generate label
257
+			$label = ! empty($label) ? self::adminLabel($id, $label, $required) : '';
258
+			// generate field name
259
+			$name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
260
+
261
+			// we determine what we're building based on the type
262
+			switch ($type) {
263
+				case 'checkbox':
264
+				case 'radio':
265
+					if (is_array($value)) {
266
+						$c_input = '';
267
+						foreach ($value as $key => $val) {
268
+							$c_input .= self::adminMulti(
269
+								$default,
270
+								isset($classes[ $key ]) ? $classes[ $key ] : '',
271
+								$field_name . '_' . $value,
272
+								$name,
273
+								$required,
274
+								$tab_index,
275
+								$type,
276
+								$val,
277
+								isset($labels[ $key ]) ? $labels[ $key ] : ''
278
+							);
279
+						}
280
+						$field = $c_input;
281
+					} else {
282
+						$field = self::adminMulti(
283
+							$default,
284
+							$class,
285
+							$id,
286
+							$name,
287
+							$required,
288
+							$tab_index,
289
+							$type,
290
+							$value,
291
+							$_fields['label']
292
+						);
293
+					}
294
+					break;
295
+
296
+				case 'hidden':
297
+					$field = self::adminHidden($class, $id, $name, $value);
298
+					break;
299
+
300
+				case 'select':
301
+					$options = [];
302
+					foreach ($value as $key => $val) {
303
+						$options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : '';
304
+					}
305
+					$field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options);
306
+					break;
307
+
308
+				case 'textarea':
309
+					$field =
310
+						self::adminTextarea($class, $dims[0], $id, $name, $required, $dims[1], $tab_index, $value);
311
+					break;
312
+
313
+				case 'wp_editor':
314
+					$field = self::adminWpEditor(
315
+						$class,
316
+						$_fields['id'],
317
+						$name,
318
+						$dims[1],
319
+						$tab_index,
320
+						$value,
321
+						$wp_editor_args
322
+					);
323
+					break;
324
+
325
+				default:
326
+					$field = self::adminText($class, $id, $name, $required, $tab_index, $value);
327
+			}
328
+
329
+			$form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc];
330
+		}
331
+
332
+		return $form_fields;
333
+	}
334
+
335
+
336
+	/**
337
+	 * @param string $class
338
+	 * @param string $id
339
+	 * @param string $name
340
+	 * @param string $value
341
+	 * @return string
342
+	 * @since   4.10.14.p
343
+	 */
344
+	private static function adminHidden($class, $id, $name, $value)
345
+	{
346
+		$id    = esc_attr($id);
347
+		$name  = esc_attr($name);
348
+		$class = esc_attr($class);
349
+		return "
350 350
         <input name='{$name}' type='hidden' id='{$id}' class='{$class}' value='{$value}' />";
351
-    }
352
-
353
-
354
-    /**
355
-     * @param string $id
356
-     * @param string $label
357
-     * @param string $required
358
-     * @return string
359
-     * @since   4.10.14.p
360
-     */
361
-    private static function adminLabel($id, $label, $required)
362
-    {
363
-        $id       = esc_attr($id);
364
-        $label    = esc_html($label);
365
-        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? " <span>*</span>" : '';
366
-        return "<label for='{$id}'>{$label}{$required}</label>";
367
-    }
368
-
369
-
370
-    /**
371
-     * @param string $default
372
-     * @param string $class
373
-     * @param string $id
374
-     * @param string $name
375
-     * @param string $required
376
-     * @param int    $tab_index
377
-     * @param string $type
378
-     * @param string $value
379
-     * @param string $label
380
-     * @return string
381
-     * @since   4.10.14.p
382
-     */
383
-    private static function adminMulti($default, $class, $id, $name, $required, $tab_index, $type, $value, $label = '')
384
-    {
385
-        $id        = esc_attr($id);
386
-        $name      = esc_attr($name);
387
-        $class     = esc_attr($class);
388
-        $tab_index = absint($tab_index);
389
-        $checked   = ! empty($default) && $default == $value ? 'checked ' : '';
390
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
391
-        $input     = "
351
+	}
352
+
353
+
354
+	/**
355
+	 * @param string $id
356
+	 * @param string $label
357
+	 * @param string $required
358
+	 * @return string
359
+	 * @since   4.10.14.p
360
+	 */
361
+	private static function adminLabel($id, $label, $required)
362
+	{
363
+		$id       = esc_attr($id);
364
+		$label    = esc_html($label);
365
+		$required = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? " <span>*</span>" : '';
366
+		return "<label for='{$id}'>{$label}{$required}</label>";
367
+	}
368
+
369
+
370
+	/**
371
+	 * @param string $default
372
+	 * @param string $class
373
+	 * @param string $id
374
+	 * @param string $name
375
+	 * @param string $required
376
+	 * @param int    $tab_index
377
+	 * @param string $type
378
+	 * @param string $value
379
+	 * @param string $label
380
+	 * @return string
381
+	 * @since   4.10.14.p
382
+	 */
383
+	private static function adminMulti($default, $class, $id, $name, $required, $tab_index, $type, $value, $label = '')
384
+	{
385
+		$id        = esc_attr($id);
386
+		$name      = esc_attr($name);
387
+		$class     = esc_attr($class);
388
+		$tab_index = absint($tab_index);
389
+		$checked   = ! empty($default) && $default == $value ? 'checked ' : '';
390
+		$required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
391
+		$input     = "
392 392
         <input name='{$name}[]' type='{$type}' id='{$id}' class='{$class}' value='{$value}' {$checked} {$required} tabindex='{$tab_index}'/>";
393
-        if ($label === '') {
394
-            return $input;
395
-        }
396
-        $label = esc_html($label);
397
-        $label_class = self::appendInputSizeClass('', $label);
398
-        $label_class = $label_class ? ' class="' . $label_class . '"' : '';
399
-        return "
393
+		if ($label === '') {
394
+			return $input;
395
+		}
396
+		$label = esc_html($label);
397
+		$label_class = self::appendInputSizeClass('', $label);
398
+		$label_class = $label_class ? ' class="' . $label_class . '"' : '';
399
+		return "
400 400
         <label for='$id'{$label_class}>
401 401
             {$input}
402 402
             {$label}
403 403
         </label>";
404
-    }
405
-
406
-
407
-    /**
408
-     * @param string $default
409
-     * @param string $class
410
-     * @param string $id
411
-     * @param string $name
412
-     * @param string $required
413
-     * @param int    $tab_index
414
-     * @param array  $options
415
-     * @return string
416
-     * @since   4.10.14.p
417
-     */
418
-    private static function adminSelect($default, $class, $id, $name, $required, $tab_index, $options = [])
419
-    {
420
-        $options_array = [];
421
-        foreach ($options as $value => $label) {
422
-            $selected        = ! empty($default) && $default == $value ? 'selected' : '';
423
-            $value           = esc_attr($value);
424
-            $label           = wp_strip_all_tags($label);
425
-            $options_array[] = "<option value='{$value}' {$selected}>{$label}</option>";
426
-        }
427
-        $options_html = implode($options_array, "\n");
428
-        $id           = esc_attr($id);
429
-        $name         = esc_attr($name);
430
-        $class        = esc_attr($class);
431
-        $tab_index    = absint($tab_index);
432
-        $required     = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
433
-
434
-        $class = self::appendInputSizeClass($class, $options);
435
-
436
-        return "
404
+	}
405
+
406
+
407
+	/**
408
+	 * @param string $default
409
+	 * @param string $class
410
+	 * @param string $id
411
+	 * @param string $name
412
+	 * @param string $required
413
+	 * @param int    $tab_index
414
+	 * @param array  $options
415
+	 * @return string
416
+	 * @since   4.10.14.p
417
+	 */
418
+	private static function adminSelect($default, $class, $id, $name, $required, $tab_index, $options = [])
419
+	{
420
+		$options_array = [];
421
+		foreach ($options as $value => $label) {
422
+			$selected        = ! empty($default) && $default == $value ? 'selected' : '';
423
+			$value           = esc_attr($value);
424
+			$label           = wp_strip_all_tags($label);
425
+			$options_array[] = "<option value='{$value}' {$selected}>{$label}</option>";
426
+		}
427
+		$options_html = implode($options_array, "\n");
428
+		$id           = esc_attr($id);
429
+		$name         = esc_attr($name);
430
+		$class        = esc_attr($class);
431
+		$tab_index    = absint($tab_index);
432
+		$required     = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
433
+
434
+		$class = self::appendInputSizeClass($class, $options);
435
+
436
+		return "
437 437
         <select name='{$name}' id='{$id}' class='{$class}' {$required} tabindex='{$tab_index}'>
438 438
             {$options_html}
439 439
         </select>";
440
-    }
441
-
442
-
443
-    /**
444
-     * @param string $class
445
-     * @param string $id
446
-     * @param string $name
447
-     * @param string $required
448
-     * @param int    $tab_index
449
-     * @param string $value
450
-     * @return string
451
-     * @since   4.10.14.p
452
-     */
453
-    private static function adminText($class, $id, $name, $required, $tab_index, $value)
454
-    {
455
-        $id        = esc_attr($id);
456
-        $name      = esc_attr($name);
457
-        $class     = esc_attr($class);
458
-        $tab_index = absint($tab_index);
459
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
460
-        $class     = self::appendInputSizeClass($class, $value);
461
-        return "
440
+	}
441
+
442
+
443
+	/**
444
+	 * @param string $class
445
+	 * @param string $id
446
+	 * @param string $name
447
+	 * @param string $required
448
+	 * @param int    $tab_index
449
+	 * @param string $value
450
+	 * @return string
451
+	 * @since   4.10.14.p
452
+	 */
453
+	private static function adminText($class, $id, $name, $required, $tab_index, $value)
454
+	{
455
+		$id        = esc_attr($id);
456
+		$name      = esc_attr($name);
457
+		$class     = esc_attr($class);
458
+		$tab_index = absint($tab_index);
459
+		$required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
460
+		$class     = self::appendInputSizeClass($class, $value);
461
+		return "
462 462
         <input name='{$name}' type='text' id='{$id}' class='{$class}' value='{$value}' {$required} tabindex='{$tab_index}'/>";
463
-    }
464
-
465
-
466
-    /**
467
-     * @param string $class
468
-     * @param int    $cols
469
-     * @param string $id
470
-     * @param string $name
471
-     * @param string $required
472
-     * @param int    $rows
473
-     * @param int    $tab_index
474
-     * @param string $value
475
-     * @return string
476
-     * @since   4.10.14.p
477
-     */
478
-    private static function adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value)
479
-    {
480
-        $id        = esc_attr($id);
481
-        $name      = esc_attr($name);
482
-        $class     = esc_attr($class);
483
-        $cols      = absint($cols);
484
-        $rows      = absint($rows);
485
-        $value     = esc_textarea($value);
486
-        $tab_index = absint($tab_index);
487
-        $required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
488
-        return "
463
+	}
464
+
465
+
466
+	/**
467
+	 * @param string $class
468
+	 * @param int    $cols
469
+	 * @param string $id
470
+	 * @param string $name
471
+	 * @param string $required
472
+	 * @param int    $rows
473
+	 * @param int    $tab_index
474
+	 * @param string $value
475
+	 * @return string
476
+	 * @since   4.10.14.p
477
+	 */
478
+	private static function adminTextarea($class, $cols, $id, $name, $required, $rows, $tab_index, $value)
479
+	{
480
+		$id        = esc_attr($id);
481
+		$name      = esc_attr($name);
482
+		$class     = esc_attr($class);
483
+		$cols      = absint($cols);
484
+		$rows      = absint($rows);
485
+		$value     = esc_textarea($value);
486
+		$tab_index = absint($tab_index);
487
+		$required  = filter_var($required, FILTER_VALIDATE_BOOLEAN) ? 'required' : '';
488
+		return "
489 489
         <textarea name='{$name}' id='{$id}' class='{$class}' rows='{$rows}' cols='{$cols}' {$required} tabindex='{$tab_index}'>{$value}</textarea>";
490
-    }
491
-
492
-
493
-    /**
494
-     * @param string $class
495
-     * @param string $id
496
-     * @param string $name
497
-     * @param int    $rows
498
-     * @param int    $tab_index
499
-     * @param string $value
500
-     * @param array  $wp_editor_args
501
-     * @return false|string
502
-     * @since   4.10.14.p
503
-     */
504
-    private static function adminWpEditor($class, $id, $name, $rows, $tab_index, $value, $wp_editor_args = [])
505
-    {
506
-        $editor_settings = $wp_editor_args + [
507
-                'textarea_name' => esc_attr($name),
508
-                'textarea_rows' => absint($rows),
509
-                'editor_class'  => esc_attr($class),
510
-                'tabindex'      => absint($tab_index),
511
-            ];
512
-        ob_start();
513
-        wp_editor($value, esc_attr($id), $editor_settings);
514
-        return ob_get_clean();
515
-    }
516
-
517
-
518
-    /**
519
-     * espresso admin page select_input
520
-     * Turns an array into a select fields
521
-     *
522
-     * @static
523
-     * @access public
524
-     * @param string  $name       field name
525
-     * @param array   $values     option values, numbered array starting at 0, where each value is an array with a key
526
-     *                            'text' (meaning text to display' and 'id' (meaning the internal value) eg:
527
-     *                            array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or
528
-     *                            as an array of key-value pairs, where the key is to be used for the select input's
529
-     *                            name, and the value will be the text shown to the user.  Optionally you can also
530
-     *                            include an additional key of "class" which will add a specific class to the option
531
-     *                            for that value.
532
-     * @param string  $default    default value
533
-     * @param string  $parameters extra parameters
534
-     * @param string  $class      css class
535
-     * @param boolean $autosize   whether to autosize the select or not
536
-     * @return string              html string for the select input
537
-     */
538
-    public static function select_input(
539
-        $name,
540
-        $values,
541
-        $default = '',
542
-        $parameters = '',
543
-        $class = '',
544
-        $autosize = true
545
-    ) {
546
-        // if $values was submitted in the wrong format, convert it over
547
-        if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) {
548
-            $converted_values = [];
549
-            foreach ($values as $id => $text) {
550
-                $converted_values[] = ['id' => $id, 'text' => $text];
551
-            }
552
-            $values = $converted_values;
553
-        }
554
-
555
-        $field =
556
-            '<select id="' . EEH_Formatter::ee_tep_output_string($name)
557
-            . '" name="' . EEH_Formatter::ee_tep_output_string($name)
558
-            . '"';
559
-
560
-        if (EEH_Formatter::ee_tep_not_null($parameters)) {
561
-            $field .= ' ' . $parameters;
562
-        }
563
-        $class = $autosize ? self::appendInputSizeClass($class, $values) : '';
564
-
565
-        $field .= ' class="' . $class . '">';
566
-
567
-        if (empty($default) && isset($GLOBALS[ $name ])) {
568
-            $default = stripslashes($GLOBALS[ $name ]);
569
-        }
570
-
571
-        $field .= self::selectInputOption($values, $default);
572
-        $field .= '</select>';
573
-
574
-        return $field;
575
-    }
576
-
577
-
578
-    private static function selectInputOption(array $values, $default): string
579
-    {
580
-        if (isset($values['id'], $values['text'])) {
581
-            $id = is_scalar($values['id']) ? $values['id'] : '';
582
-            $text = is_scalar($values['text']) ? $values['text'] : '';
583
-            $selected = $default == $values['id'] ? ' selected = "selected"' : '';
584
-            $html_class = isset($values['class']) ? ' class="' . $values['class'] . '"' : '';
585
-            return "<option value='{$id}'{$selected}{$html_class}>{$text}</option>";
586
-        }
587
-        $options = '';
588
-        foreach ($values as $value) {
589
-            $options .= self::selectInputOption($value, $default);
590
-        }
591
-        return $options;
592
-    }
593
-
594
-
595
-    /**
596
-     * @param mixed $value
597
-     * @return int
598
-     * @since   $VID:$
599
-     */
600
-    private static function getInputValueLength($value): int
601
-    {
602
-        if ($value instanceof EE_Question_Option) {
603
-            return self::getInputValueLength($value->desc());
604
-        }
605
-        if (is_array($value)) {
606
-            $chars = 0;
607
-            foreach ($value as $val) {
608
-                $length = self::getInputValueLength($val);
609
-                $chars = max($length, $chars);
610
-            }
611
-            return $chars;
612
-        }
613
-        // not a primitive? return something big
614
-        if (! is_scalar($value)) {
615
-            return 500;
616
-        }
617
-        return strlen((string) $value);
618
-    }
619
-
620
-
621
-    /**
622
-     * @param string $class
623
-     * @param mixed $value
624
-     * @return string
625
-     * @since   $VID:$
626
-     */
627
-    private static function appendInputSizeClass(string $class, $value): string
628
-    {
629
-        if (strpos($class, 'ee-input-width--') !== false) {
630
-            return $class;
631
-        }
632
-        $chars = self::getInputValueLength($value);
633
-        if ($chars && $chars < 5) {
634
-            return "{$class} ee-input-width--tiny";
635
-        }
636
-        if ($chars && $chars < 25) {
637
-            return "{$class} ee-input-width--small";
638
-        }
639
-        if ($chars && $chars > 100) {
640
-            return "{$class} ee-input-width--big";
641
-        }
642
-        return "{$class} ee-input-width--reg";
643
-    }
644
-
645
-
646
-    /**
647
-     * generate_question_groups_html
648
-     *
649
-     * @param array  $question_groups
650
-     * @param string $group_wrapper
651
-     * @return string HTML
652
-     * @throws EE_Error
653
-     * @throws ReflectionException
654
-     */
655
-    public static function generate_question_groups_html($question_groups = [], $group_wrapper = 'fieldset')
656
-    {
657
-
658
-        $html                            = '';
659
-        $before_question_group_questions =
660
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
661
-        $after_question_group_questions  =
662
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
663
-
664
-        if (! empty($question_groups)) {
665
-            // loop thru question groups
666
-            foreach ($question_groups as $QSG) {
667
-                // check that questions exist
668
-                if (! empty($QSG['QSG_questions'])) {
669
-                    // use fieldsets
670
-                    $html .= "\n\t"
671
-                             . '<'
672
-                             . $group_wrapper
673
-                             . ' class="espresso-question-group-wrap" id="'
674
-                             . $QSG['QSG_identifier']
675
-                             . '">';
676
-                    // group_name
677
-                    $html .= $QSG['QSG_show_group_name']
678
-                        ? "\n\t\t"
679
-                          . '<h5 class="espresso-question-group-title-h5 section-title">'
680
-                          . self::prep_answer($QSG['QSG_name'])
681
-                          . '</h5>'
682
-                        : '';
683
-                    // group_desc
684
-                    $html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc'])
685
-                        ? '<div class="espresso-question-group-desc-pg">'
686
-                          . self::prep_answer($QSG['QSG_desc'])
687
-                          . '</div>'
688
-                        : '';
689
-
690
-                    $html .= $before_question_group_questions;
691
-                    // loop thru questions
692
-                    foreach ($QSG['QSG_questions'] as $question) {
693
-                        $QFI  = new EE_Question_Form_Input(
694
-                            $question['qst_obj'],
695
-                            $question['ans_obj'],
696
-                            $question
697
-                        );
698
-                        $html .= self::generate_form_input($QFI);
699
-                    }
700
-                    $html .= $after_question_group_questions;
701
-                    $html .= "\n\t" . '</' . $group_wrapper . '>';
702
-                }
703
-            }
704
-        }
705
-
706
-        return $html;
707
-    }
708
-
709
-
710
-    /**
711
-     * generate_question_groups_html
712
-     *
713
-     * @param array  $question_groups
714
-     * @param array  $q_meta
715
-     * @param bool   $from_admin
716
-     * @param string $group_wrapper
717
-     * @return string HTML
718
-     * @throws EE_Error
719
-     * @throws ReflectionException
720
-     */
721
-    public static function generate_question_groups_html2(
722
-        $question_groups = [],
723
-        $q_meta = [],
724
-        $from_admin = false,
725
-        $group_wrapper = 'fieldset'
726
-    ) {
727
-
728
-        $html                            = '';
729
-        $before_question_group_questions =
730
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
731
-        $after_question_group_questions  =
732
-            apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
733
-
734
-        $default_q_meta = [
735
-            'att_nmbr'    => 1,
736
-            'ticket_id'   => '',
737
-            'input_name'  => '',
738
-            'input_id'    => '',
739
-            'input_class' => '',
740
-        ];
741
-        $q_meta         = array_merge($default_q_meta, $q_meta);
742
-
743
-        if (! empty($question_groups)) {
744
-            // loop thru question groups
745
-            foreach ($question_groups as $QSG) {
746
-                if ($QSG instanceof EE_Question_Group) {
747
-                    // check that questions exist
748
-
749
-                    $where = ['QST_deleted' => 0];
750
-                    if (! $from_admin) {
751
-                        $where['QST_admin_only'] = 0;
752
-                    }
753
-                    $questions =
754
-                        $QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]);
755
-                    if (! empty($questions)) {
756
-                        // use fieldsets
757
-                        $html .= "\n\t"
758
-                                 . '<' . $group_wrapper . ' class="espresso-question-group-wrap" '
759
-                                 . 'id="' . $QSG->get('QSG_identifier') . '">';
760
-                        // group_name
761
-                        if ($QSG->show_group_name()) {
762
-                            $html .= "\n\t\t"
763
-                                     . '<h5 class="espresso-question-group-title-h5 section-title">'
764
-                                     . $QSG->get_pretty('QSG_name')
765
-                                     . '</h5>';
766
-                        }
767
-                        // group_desc
768
-                        if ($QSG->show_group_desc()) {
769
-                            $html .= '<div class="espresso-question-group-desc-pg">'
770
-                                     . $QSG->get_pretty('QSG_desc')
771
-                                     . '</div>';
772
-                        }
773
-
774
-                        $html .= $before_question_group_questions;
775
-                        // loop thru questions
776
-                        foreach ($questions as $QST) {
777
-                            $qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID();
778
-
779
-                            $answer = null;
780
-
781
-                            /** @var RequestInterface $request */
782
-                            $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
783
-                            $request_qstn = $request->getRequestParam('qstn', [], 'string', true);
784
-                            if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
785
-                                // check for answer in $request_qstn in case we are reprocessing a form after an error
786
-                                if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) {
787
-                                    $answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])
788
-                                        ? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ]
789
-                                        : sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]);
790
-                                }
791
-                            } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
792
-                                // attendee data from the session
793
-                                $answer =
794
-                                    isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
795
-                            }
796
-
797
-
798
-                            $QFI  = new EE_Question_Form_Input(
799
-                                $QST,
800
-                                EE_Answer::new_instance(
801
-                                    [
802
-                                        'ANS_ID'    => 0,
803
-                                        'QST_ID'    => 0,
804
-                                        'REG_ID'    => 0,
805
-                                        'ANS_value' => $answer,
806
-                                    ]
807
-                                ),
808
-                                $q_meta
809
-                            );
810
-                            $html .= self::generate_form_input($QFI);
811
-                        }
812
-                        $html .= $after_question_group_questions;
813
-                        $html .= "\n\t" . '</' . $group_wrapper . '>';
814
-                    }
815
-                }
816
-            }
817
-        }
818
-        return $html;
819
-    }
820
-
821
-
822
-    /**
823
-     * generate_form_input
824
-     *
825
-     * @param EE_Question_Form_Input $QFI
826
-     * @return string HTML
827
-     * @throws EE_Error
828
-     * @throws ReflectionException
829
-     */
830
-    public static function generate_form_input(EE_Question_Form_Input $QFI)
831
-    {
832
-        if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) {
833
-            return '';
834
-        }
835
-        /** @var RequestInterface $request */
836
-        $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
837
-
838
-        $QFI = self::_load_system_dropdowns($QFI);
839
-        $QFI = self::_load_specialized_dropdowns($QFI);
840
-
841
-        // we also need to verify
842
-
843
-        $display_text = $QFI->get('QST_display_text');
844
-        $input_name   = $QFI->get('QST_input_name');
845
-        $answer       = $request->getRequestParam($input_name, $QFI->get('ANS_value'));
846
-        $input_id     = $QFI->get('QST_input_id');
847
-        $input_class  = $QFI->get('QST_input_class');
848
-        //      $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : '';
849
-        $disabled          = $QFI->get('QST_disabled');
850
-        $required_label    = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>');
851
-        $QST_required      = $QFI->get('QST_required');
852
-        $required          =
853
-            $QST_required
854
-                ? ['label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required]
855
-                : [];
856
-        $use_html_entities = $QFI->get_meta('htmlentities');
857
-        $required_text     =
858
-            $QFI->get('QST_required_text') != ''
859
-                ? $QFI->get('QST_required_text')
860
-                : esc_html__('This field is required', 'event_espresso');
861
-        $required_text     = $QST_required
862
-            ? "\n\t\t\t"
863
-              . '<div class="required-text hidden">'
864
-              . self::prep_answer($required_text, $use_html_entities)
865
-              . '</div>'
866
-            : '';
867
-        $label_class       = $QFI->get('label_class');
868
-        $label_class       = $label_class ? "{$label_class} espresso-form-input-lbl" : 'espresso-form-input-lbl';
869
-        $QST_options       = $QFI->options(true, $answer);
870
-        $options           = is_array($QST_options) ? self::prep_answer_options($QST_options) : [];
871
-        $system_ID         = $QFI->get('QST_system');
872
-        $label_b4          = $QFI->get_meta('label_b4');
873
-        $use_desc_4_label  = $QFI->get_meta('use_desc_4_label');
874
-        $add_mobile_label  = $QFI->get_meta('add_mobile_label');
875
-
876
-
877
-        switch ($QFI->get('QST_type')) {
878
-            case 'TEXTAREA':
879
-                return EEH_Form_Fields::textarea(
880
-                    $display_text,
881
-                    $answer,
882
-                    $input_name,
883
-                    $input_id,
884
-                    $input_class,
885
-                    [],
886
-                    $required,
887
-                    $required_text,
888
-                    $label_class,
889
-                    $disabled,
890
-                    $system_ID,
891
-                    $use_html_entities,
892
-                    $add_mobile_label
893
-                );
894
-
895
-            case 'DROPDOWN':
896
-                return EEH_Form_Fields::select(
897
-                    $display_text,
898
-                    $answer,
899
-                    $options,
900
-                    $input_name,
901
-                    $input_id,
902
-                    $input_class,
903
-                    $required,
904
-                    $required_text,
905
-                    $label_class,
906
-                    $disabled,
907
-                    $system_ID,
908
-                    $use_html_entities,
909
-                    true,
910
-                    $add_mobile_label
911
-                );
912
-
913
-
914
-            case 'RADIO_BTN':
915
-                return EEH_Form_Fields::radio(
916
-                    $display_text,
917
-                    $answer,
918
-                    $options,
919
-                    $input_name,
920
-                    $input_id,
921
-                    $input_class,
922
-                    $required,
923
-                    $required_text,
924
-                    $label_class,
925
-                    $disabled,
926
-                    $system_ID,
927
-                    $use_html_entities,
928
-                    $label_b4,
929
-                    $use_desc_4_label,
930
-                    $add_mobile_label
931
-                );
932
-
933
-            case 'CHECKBOX':
934
-                return EEH_Form_Fields::checkbox(
935
-                    $display_text,
936
-                    $answer,
937
-                    $options,
938
-                    $input_name,
939
-                    $input_id,
940
-                    $input_class,
941
-                    $required,
942
-                    $required_text,
943
-                    $label_class,
944
-                    $disabled,
945
-                    $label_b4,
946
-                    $system_ID,
947
-                    $use_html_entities,
948
-                    $add_mobile_label
949
-                );
950
-
951
-            case 'DATE':
952
-                return EEH_Form_Fields::datepicker(
953
-                    $display_text,
954
-                    $answer,
955
-                    $input_name,
956
-                    $input_id,
957
-                    $input_class,
958
-                    $required,
959
-                    $required_text,
960
-                    $label_class,
961
-                    $disabled,
962
-                    $system_ID,
963
-                    $use_html_entities,
964
-                    $add_mobile_label
965
-                );
966
-
967
-            case 'TEXT':
968
-            default:
969
-                return EEH_Form_Fields::text(
970
-                    $display_text,
971
-                    $answer,
972
-                    $input_name,
973
-                    $input_id,
974
-                    $input_class,
975
-                    $required,
976
-                    $required_text,
977
-                    $label_class,
978
-                    $disabled,
979
-                    $system_ID,
980
-                    $use_html_entities,
981
-                    $add_mobile_label
982
-                );
983
-        }
984
-    }
985
-
986
-
987
-    public static function label(
988
-        string $question,
989
-        string $required_text = '',
990
-        string $required_label = '',
991
-        string $name = '',
992
-        string $label_class = '',
993
-        bool $filter = true
994
-    ): string {
995
-        $for   = ! empty($name) ? " for='{$name}'" : '';
996
-        $class = ! empty($label_class) ? " class='{$label_class}'" : '';
997
-        $label = self::prep_question($question) . $required_label;
998
-        $label_html = "
490
+	}
491
+
492
+
493
+	/**
494
+	 * @param string $class
495
+	 * @param string $id
496
+	 * @param string $name
497
+	 * @param int    $rows
498
+	 * @param int    $tab_index
499
+	 * @param string $value
500
+	 * @param array  $wp_editor_args
501
+	 * @return false|string
502
+	 * @since   4.10.14.p
503
+	 */
504
+	private static function adminWpEditor($class, $id, $name, $rows, $tab_index, $value, $wp_editor_args = [])
505
+	{
506
+		$editor_settings = $wp_editor_args + [
507
+				'textarea_name' => esc_attr($name),
508
+				'textarea_rows' => absint($rows),
509
+				'editor_class'  => esc_attr($class),
510
+				'tabindex'      => absint($tab_index),
511
+			];
512
+		ob_start();
513
+		wp_editor($value, esc_attr($id), $editor_settings);
514
+		return ob_get_clean();
515
+	}
516
+
517
+
518
+	/**
519
+	 * espresso admin page select_input
520
+	 * Turns an array into a select fields
521
+	 *
522
+	 * @static
523
+	 * @access public
524
+	 * @param string  $name       field name
525
+	 * @param array   $values     option values, numbered array starting at 0, where each value is an array with a key
526
+	 *                            'text' (meaning text to display' and 'id' (meaning the internal value) eg:
527
+	 *                            array(1=>array('text'=>'Monday','id'=>1),2=>array('text'=>'Tuesday','id'=>2)...). or
528
+	 *                            as an array of key-value pairs, where the key is to be used for the select input's
529
+	 *                            name, and the value will be the text shown to the user.  Optionally you can also
530
+	 *                            include an additional key of "class" which will add a specific class to the option
531
+	 *                            for that value.
532
+	 * @param string  $default    default value
533
+	 * @param string  $parameters extra parameters
534
+	 * @param string  $class      css class
535
+	 * @param boolean $autosize   whether to autosize the select or not
536
+	 * @return string              html string for the select input
537
+	 */
538
+	public static function select_input(
539
+		$name,
540
+		$values,
541
+		$default = '',
542
+		$parameters = '',
543
+		$class = '',
544
+		$autosize = true
545
+	) {
546
+		// if $values was submitted in the wrong format, convert it over
547
+		if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) {
548
+			$converted_values = [];
549
+			foreach ($values as $id => $text) {
550
+				$converted_values[] = ['id' => $id, 'text' => $text];
551
+			}
552
+			$values = $converted_values;
553
+		}
554
+
555
+		$field =
556
+			'<select id="' . EEH_Formatter::ee_tep_output_string($name)
557
+			. '" name="' . EEH_Formatter::ee_tep_output_string($name)
558
+			. '"';
559
+
560
+		if (EEH_Formatter::ee_tep_not_null($parameters)) {
561
+			$field .= ' ' . $parameters;
562
+		}
563
+		$class = $autosize ? self::appendInputSizeClass($class, $values) : '';
564
+
565
+		$field .= ' class="' . $class . '">';
566
+
567
+		if (empty($default) && isset($GLOBALS[ $name ])) {
568
+			$default = stripslashes($GLOBALS[ $name ]);
569
+		}
570
+
571
+		$field .= self::selectInputOption($values, $default);
572
+		$field .= '</select>';
573
+
574
+		return $field;
575
+	}
576
+
577
+
578
+	private static function selectInputOption(array $values, $default): string
579
+	{
580
+		if (isset($values['id'], $values['text'])) {
581
+			$id = is_scalar($values['id']) ? $values['id'] : '';
582
+			$text = is_scalar($values['text']) ? $values['text'] : '';
583
+			$selected = $default == $values['id'] ? ' selected = "selected"' : '';
584
+			$html_class = isset($values['class']) ? ' class="' . $values['class'] . '"' : '';
585
+			return "<option value='{$id}'{$selected}{$html_class}>{$text}</option>";
586
+		}
587
+		$options = '';
588
+		foreach ($values as $value) {
589
+			$options .= self::selectInputOption($value, $default);
590
+		}
591
+		return $options;
592
+	}
593
+
594
+
595
+	/**
596
+	 * @param mixed $value
597
+	 * @return int
598
+	 * @since   $VID:$
599
+	 */
600
+	private static function getInputValueLength($value): int
601
+	{
602
+		if ($value instanceof EE_Question_Option) {
603
+			return self::getInputValueLength($value->desc());
604
+		}
605
+		if (is_array($value)) {
606
+			$chars = 0;
607
+			foreach ($value as $val) {
608
+				$length = self::getInputValueLength($val);
609
+				$chars = max($length, $chars);
610
+			}
611
+			return $chars;
612
+		}
613
+		// not a primitive? return something big
614
+		if (! is_scalar($value)) {
615
+			return 500;
616
+		}
617
+		return strlen((string) $value);
618
+	}
619
+
620
+
621
+	/**
622
+	 * @param string $class
623
+	 * @param mixed $value
624
+	 * @return string
625
+	 * @since   $VID:$
626
+	 */
627
+	private static function appendInputSizeClass(string $class, $value): string
628
+	{
629
+		if (strpos($class, 'ee-input-width--') !== false) {
630
+			return $class;
631
+		}
632
+		$chars = self::getInputValueLength($value);
633
+		if ($chars && $chars < 5) {
634
+			return "{$class} ee-input-width--tiny";
635
+		}
636
+		if ($chars && $chars < 25) {
637
+			return "{$class} ee-input-width--small";
638
+		}
639
+		if ($chars && $chars > 100) {
640
+			return "{$class} ee-input-width--big";
641
+		}
642
+		return "{$class} ee-input-width--reg";
643
+	}
644
+
645
+
646
+	/**
647
+	 * generate_question_groups_html
648
+	 *
649
+	 * @param array  $question_groups
650
+	 * @param string $group_wrapper
651
+	 * @return string HTML
652
+	 * @throws EE_Error
653
+	 * @throws ReflectionException
654
+	 */
655
+	public static function generate_question_groups_html($question_groups = [], $group_wrapper = 'fieldset')
656
+	{
657
+
658
+		$html                            = '';
659
+		$before_question_group_questions =
660
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
661
+		$after_question_group_questions  =
662
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
663
+
664
+		if (! empty($question_groups)) {
665
+			// loop thru question groups
666
+			foreach ($question_groups as $QSG) {
667
+				// check that questions exist
668
+				if (! empty($QSG['QSG_questions'])) {
669
+					// use fieldsets
670
+					$html .= "\n\t"
671
+							 . '<'
672
+							 . $group_wrapper
673
+							 . ' class="espresso-question-group-wrap" id="'
674
+							 . $QSG['QSG_identifier']
675
+							 . '">';
676
+					// group_name
677
+					$html .= $QSG['QSG_show_group_name']
678
+						? "\n\t\t"
679
+						  . '<h5 class="espresso-question-group-title-h5 section-title">'
680
+						  . self::prep_answer($QSG['QSG_name'])
681
+						  . '</h5>'
682
+						: '';
683
+					// group_desc
684
+					$html .= $QSG['QSG_show_group_desc'] && ! empty($QSG['QSG_desc'])
685
+						? '<div class="espresso-question-group-desc-pg">'
686
+						  . self::prep_answer($QSG['QSG_desc'])
687
+						  . '</div>'
688
+						: '';
689
+
690
+					$html .= $before_question_group_questions;
691
+					// loop thru questions
692
+					foreach ($QSG['QSG_questions'] as $question) {
693
+						$QFI  = new EE_Question_Form_Input(
694
+							$question['qst_obj'],
695
+							$question['ans_obj'],
696
+							$question
697
+						);
698
+						$html .= self::generate_form_input($QFI);
699
+					}
700
+					$html .= $after_question_group_questions;
701
+					$html .= "\n\t" . '</' . $group_wrapper . '>';
702
+				}
703
+			}
704
+		}
705
+
706
+		return $html;
707
+	}
708
+
709
+
710
+	/**
711
+	 * generate_question_groups_html
712
+	 *
713
+	 * @param array  $question_groups
714
+	 * @param array  $q_meta
715
+	 * @param bool   $from_admin
716
+	 * @param string $group_wrapper
717
+	 * @return string HTML
718
+	 * @throws EE_Error
719
+	 * @throws ReflectionException
720
+	 */
721
+	public static function generate_question_groups_html2(
722
+		$question_groups = [],
723
+		$q_meta = [],
724
+		$from_admin = false,
725
+		$group_wrapper = 'fieldset'
726
+	) {
727
+
728
+		$html                            = '';
729
+		$before_question_group_questions =
730
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', '');
731
+		$after_question_group_questions  =
732
+			apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
733
+
734
+		$default_q_meta = [
735
+			'att_nmbr'    => 1,
736
+			'ticket_id'   => '',
737
+			'input_name'  => '',
738
+			'input_id'    => '',
739
+			'input_class' => '',
740
+		];
741
+		$q_meta         = array_merge($default_q_meta, $q_meta);
742
+
743
+		if (! empty($question_groups)) {
744
+			// loop thru question groups
745
+			foreach ($question_groups as $QSG) {
746
+				if ($QSG instanceof EE_Question_Group) {
747
+					// check that questions exist
748
+
749
+					$where = ['QST_deleted' => 0];
750
+					if (! $from_admin) {
751
+						$where['QST_admin_only'] = 0;
752
+					}
753
+					$questions =
754
+						$QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]);
755
+					if (! empty($questions)) {
756
+						// use fieldsets
757
+						$html .= "\n\t"
758
+								 . '<' . $group_wrapper . ' class="espresso-question-group-wrap" '
759
+								 . 'id="' . $QSG->get('QSG_identifier') . '">';
760
+						// group_name
761
+						if ($QSG->show_group_name()) {
762
+							$html .= "\n\t\t"
763
+									 . '<h5 class="espresso-question-group-title-h5 section-title">'
764
+									 . $QSG->get_pretty('QSG_name')
765
+									 . '</h5>';
766
+						}
767
+						// group_desc
768
+						if ($QSG->show_group_desc()) {
769
+							$html .= '<div class="espresso-question-group-desc-pg">'
770
+									 . $QSG->get_pretty('QSG_desc')
771
+									 . '</div>';
772
+						}
773
+
774
+						$html .= $before_question_group_questions;
775
+						// loop thru questions
776
+						foreach ($questions as $QST) {
777
+							$qstn_id = $QST->is_system_question() ? $QST->system_ID() : $QST->ID();
778
+
779
+							$answer = null;
780
+
781
+							/** @var RequestInterface $request */
782
+							$request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
783
+							$request_qstn = $request->getRequestParam('qstn', [], 'string', true);
784
+							if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
785
+								// check for answer in $request_qstn in case we are reprocessing a form after an error
786
+								if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) {
787
+									$answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])
788
+										? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ]
789
+										: sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]);
790
+								}
791
+							} elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
792
+								// attendee data from the session
793
+								$answer =
794
+									isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
795
+							}
796
+
797
+
798
+							$QFI  = new EE_Question_Form_Input(
799
+								$QST,
800
+								EE_Answer::new_instance(
801
+									[
802
+										'ANS_ID'    => 0,
803
+										'QST_ID'    => 0,
804
+										'REG_ID'    => 0,
805
+										'ANS_value' => $answer,
806
+									]
807
+								),
808
+								$q_meta
809
+							);
810
+							$html .= self::generate_form_input($QFI);
811
+						}
812
+						$html .= $after_question_group_questions;
813
+						$html .= "\n\t" . '</' . $group_wrapper . '>';
814
+					}
815
+				}
816
+			}
817
+		}
818
+		return $html;
819
+	}
820
+
821
+
822
+	/**
823
+	 * generate_form_input
824
+	 *
825
+	 * @param EE_Question_Form_Input $QFI
826
+	 * @return string HTML
827
+	 * @throws EE_Error
828
+	 * @throws ReflectionException
829
+	 */
830
+	public static function generate_form_input(EE_Question_Form_Input $QFI)
831
+	{
832
+		if (isset($QFI->QST_admin_only) && $QFI->QST_admin_only && ! is_admin()) {
833
+			return '';
834
+		}
835
+		/** @var RequestInterface $request */
836
+		$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
837
+
838
+		$QFI = self::_load_system_dropdowns($QFI);
839
+		$QFI = self::_load_specialized_dropdowns($QFI);
840
+
841
+		// we also need to verify
842
+
843
+		$display_text = $QFI->get('QST_display_text');
844
+		$input_name   = $QFI->get('QST_input_name');
845
+		$answer       = $request->getRequestParam($input_name, $QFI->get('ANS_value'));
846
+		$input_id     = $QFI->get('QST_input_id');
847
+		$input_class  = $QFI->get('QST_input_class');
848
+		//      $disabled = $QFI->get('QST_disabled') ? ' disabled="disabled"' : '';
849
+		$disabled          = $QFI->get('QST_disabled');
850
+		$required_label    = apply_filters(' FHEE__EEH_Form_Fields__generate_form_input__required_label', '<em>*</em>');
851
+		$QST_required      = $QFI->get('QST_required');
852
+		$required          =
853
+			$QST_required
854
+				? ['label' => $required_label, 'class' => 'required needs-value', 'title' => $QST_required]
855
+				: [];
856
+		$use_html_entities = $QFI->get_meta('htmlentities');
857
+		$required_text     =
858
+			$QFI->get('QST_required_text') != ''
859
+				? $QFI->get('QST_required_text')
860
+				: esc_html__('This field is required', 'event_espresso');
861
+		$required_text     = $QST_required
862
+			? "\n\t\t\t"
863
+			  . '<div class="required-text hidden">'
864
+			  . self::prep_answer($required_text, $use_html_entities)
865
+			  . '</div>'
866
+			: '';
867
+		$label_class       = $QFI->get('label_class');
868
+		$label_class       = $label_class ? "{$label_class} espresso-form-input-lbl" : 'espresso-form-input-lbl';
869
+		$QST_options       = $QFI->options(true, $answer);
870
+		$options           = is_array($QST_options) ? self::prep_answer_options($QST_options) : [];
871
+		$system_ID         = $QFI->get('QST_system');
872
+		$label_b4          = $QFI->get_meta('label_b4');
873
+		$use_desc_4_label  = $QFI->get_meta('use_desc_4_label');
874
+		$add_mobile_label  = $QFI->get_meta('add_mobile_label');
875
+
876
+
877
+		switch ($QFI->get('QST_type')) {
878
+			case 'TEXTAREA':
879
+				return EEH_Form_Fields::textarea(
880
+					$display_text,
881
+					$answer,
882
+					$input_name,
883
+					$input_id,
884
+					$input_class,
885
+					[],
886
+					$required,
887
+					$required_text,
888
+					$label_class,
889
+					$disabled,
890
+					$system_ID,
891
+					$use_html_entities,
892
+					$add_mobile_label
893
+				);
894
+
895
+			case 'DROPDOWN':
896
+				return EEH_Form_Fields::select(
897
+					$display_text,
898
+					$answer,
899
+					$options,
900
+					$input_name,
901
+					$input_id,
902
+					$input_class,
903
+					$required,
904
+					$required_text,
905
+					$label_class,
906
+					$disabled,
907
+					$system_ID,
908
+					$use_html_entities,
909
+					true,
910
+					$add_mobile_label
911
+				);
912
+
913
+
914
+			case 'RADIO_BTN':
915
+				return EEH_Form_Fields::radio(
916
+					$display_text,
917
+					$answer,
918
+					$options,
919
+					$input_name,
920
+					$input_id,
921
+					$input_class,
922
+					$required,
923
+					$required_text,
924
+					$label_class,
925
+					$disabled,
926
+					$system_ID,
927
+					$use_html_entities,
928
+					$label_b4,
929
+					$use_desc_4_label,
930
+					$add_mobile_label
931
+				);
932
+
933
+			case 'CHECKBOX':
934
+				return EEH_Form_Fields::checkbox(
935
+					$display_text,
936
+					$answer,
937
+					$options,
938
+					$input_name,
939
+					$input_id,
940
+					$input_class,
941
+					$required,
942
+					$required_text,
943
+					$label_class,
944
+					$disabled,
945
+					$label_b4,
946
+					$system_ID,
947
+					$use_html_entities,
948
+					$add_mobile_label
949
+				);
950
+
951
+			case 'DATE':
952
+				return EEH_Form_Fields::datepicker(
953
+					$display_text,
954
+					$answer,
955
+					$input_name,
956
+					$input_id,
957
+					$input_class,
958
+					$required,
959
+					$required_text,
960
+					$label_class,
961
+					$disabled,
962
+					$system_ID,
963
+					$use_html_entities,
964
+					$add_mobile_label
965
+				);
966
+
967
+			case 'TEXT':
968
+			default:
969
+				return EEH_Form_Fields::text(
970
+					$display_text,
971
+					$answer,
972
+					$input_name,
973
+					$input_id,
974
+					$input_class,
975
+					$required,
976
+					$required_text,
977
+					$label_class,
978
+					$disabled,
979
+					$system_ID,
980
+					$use_html_entities,
981
+					$add_mobile_label
982
+				);
983
+		}
984
+	}
985
+
986
+
987
+	public static function label(
988
+		string $question,
989
+		string $required_text = '',
990
+		string $required_label = '',
991
+		string $name = '',
992
+		string $label_class = '',
993
+		bool $filter = true
994
+	): string {
995
+		$for   = ! empty($name) ? " for='{$name}'" : '';
996
+		$class = ! empty($label_class) ? " class='{$label_class}'" : '';
997
+		$label = self::prep_question($question) . $required_label;
998
+		$label_html = "
999 999
             {$required_text}
1000 1000
             <label{$for}{$class}>{$label}</label>";
1001
-        // filter label but ensure required text comes before it
1002
-        return $filter
1003
-            ? apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text)
1004
-            : $label_html;
1005
-    }
1006
-
1007
-
1008
-
1009
-    public static function mobileLabel(
1010
-        bool $add_mobile_label,
1011
-        string $question,
1012
-        string $required_text = '',
1013
-        string $required_label = '',
1014
-        string $label_class = '',
1015
-        string $name = ''
1016
-    ): string {
1017
-        return $add_mobile_label
1018
-            ? self::label($question, $required_text, $required_label, $name, $label_class, false)
1019
-            : '';
1020
-    }
1021
-
1022
-
1023
-    /**
1024
-     * generates HTML for a form text input
1025
-     *
1026
-     * @param string $question    label content
1027
-     * @param string $answer      form input value attribute
1028
-     * @param string $name        form input name attribute
1029
-     * @param string $id          form input css id attribute
1030
-     * @param string $class       form input css class attribute
1031
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1032
-     *                            required 'class', and required 'msg' attribute
1033
-     * @param string $label_class css class attribute for the label
1034
-     * @param string $disabled    disabled="disabled" or null
1035
-     * @return string HTML
1036
-     */
1037
-    public static function text(
1038
-        $question = false,
1039
-        $answer = null,
1040
-        $name = false,
1041
-        $id = '',
1042
-        $class = '',
1043
-        $required = false,
1044
-        $required_text = '',
1045
-        $label_class = '',
1046
-        $disabled = false,
1047
-        $system_ID = false,
1048
-        $use_html_entities = true,
1049
-        $add_mobile_label = false,
1050
-        $extra_attributes = ''
1051
-    ) {
1052
-        // need these
1053
-        if (! $question || ! $name) {
1054
-            return null;
1055
-        }
1056
-        // prep the answer
1057
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1058
-        // prep the required array
1059
-        $required = self::prep_required($required);
1060
-        // set disabled tag
1061
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1062
-        // ya gots ta have style man!!!
1063
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
1064
-        $class     = empty($class) ? $txt_class : $class;
1065
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1066
-        $class = self::appendInputSizeClass($class, $answer);
1067
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1068
-        $extra_attributes = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', $extra_attributes);
1069
-
1070
-        $label_html = self::label($question, $required_text, $required['label'], $name, $label_class);
1071
-        $mobile_label = self::mobileLabel(
1072
-            $add_mobile_label,
1073
-            $question,
1074
-            $required_text,
1075
-            $required['label'],
1076
-            $label_class,
1077
-            $name
1078
-        );
1079
-
1080
-        $input_html = $mobile_label . '
1001
+		// filter label but ensure required text comes before it
1002
+		return $filter
1003
+			? apply_filters('FHEE__EEH_Form_Fields__label_html', $label_html, $required_text)
1004
+			: $label_html;
1005
+	}
1006
+
1007
+
1008
+
1009
+	public static function mobileLabel(
1010
+		bool $add_mobile_label,
1011
+		string $question,
1012
+		string $required_text = '',
1013
+		string $required_label = '',
1014
+		string $label_class = '',
1015
+		string $name = ''
1016
+	): string {
1017
+		return $add_mobile_label
1018
+			? self::label($question, $required_text, $required_label, $name, $label_class, false)
1019
+			: '';
1020
+	}
1021
+
1022
+
1023
+	/**
1024
+	 * generates HTML for a form text input
1025
+	 *
1026
+	 * @param string $question    label content
1027
+	 * @param string $answer      form input value attribute
1028
+	 * @param string $name        form input name attribute
1029
+	 * @param string $id          form input css id attribute
1030
+	 * @param string $class       form input css class attribute
1031
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1032
+	 *                            required 'class', and required 'msg' attribute
1033
+	 * @param string $label_class css class attribute for the label
1034
+	 * @param string $disabled    disabled="disabled" or null
1035
+	 * @return string HTML
1036
+	 */
1037
+	public static function text(
1038
+		$question = false,
1039
+		$answer = null,
1040
+		$name = false,
1041
+		$id = '',
1042
+		$class = '',
1043
+		$required = false,
1044
+		$required_text = '',
1045
+		$label_class = '',
1046
+		$disabled = false,
1047
+		$system_ID = false,
1048
+		$use_html_entities = true,
1049
+		$add_mobile_label = false,
1050
+		$extra_attributes = ''
1051
+	) {
1052
+		// need these
1053
+		if (! $question || ! $name) {
1054
+			return null;
1055
+		}
1056
+		// prep the answer
1057
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1058
+		// prep the required array
1059
+		$required = self::prep_required($required);
1060
+		// set disabled tag
1061
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1062
+		// ya gots ta have style man!!!
1063
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
1064
+		$class     = empty($class) ? $txt_class : $class;
1065
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1066
+		$class = self::appendInputSizeClass($class, $answer);
1067
+		$class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1068
+		$extra_attributes = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', $extra_attributes);
1069
+
1070
+		$label_html = self::label($question, $required_text, $required['label'], $name, $label_class);
1071
+		$mobile_label = self::mobileLabel(
1072
+			$add_mobile_label,
1073
+			$question,
1074
+			$required_text,
1075
+			$required['label'],
1076
+			$label_class,
1077
+			$name
1078
+		);
1079
+
1080
+		$input_html = $mobile_label . '
1081 1081
             <input  type="text"
1082 1082
                     name="' . $name . '"
1083 1083
                     id="' . $id . '"
@@ -1087,1039 +1087,1039 @@  discard block
 block discarded – undo
1087 1087
                     ' . $disabled . ' ' . $extra_attributes . '
1088 1088
             />';
1089 1089
 
1090
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1091
-        return $label_html . $input_html;
1092
-    }
1093
-
1094
-
1095
-    /**
1096
-     * generates HTML for a form textarea
1097
-     *
1098
-     * @param string $question    label content
1099
-     * @param string $answer      form input value attribute
1100
-     * @param string $name        form input name attribute
1101
-     * @param string $id          form input css id attribute
1102
-     * @param string $class       form input css class attribute
1103
-     * @param array  $dimensions  array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 )
1104
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1105
-     *                            required 'class', and required 'msg' attribute
1106
-     * @param string $label_class css class attribute for the label
1107
-     * @param string $disabled    disabled="disabled" or null
1108
-     * @return string HTML
1109
-     */
1110
-    public static function textarea(
1111
-        $question = false,
1112
-        $answer = null,
1113
-        $name = false,
1114
-        $id = '',
1115
-        $class = '',
1116
-        $dimensions = false,
1117
-        $required = false,
1118
-        $required_text = '',
1119
-        $label_class = '',
1120
-        $disabled = false,
1121
-        $system_ID = false,
1122
-        $use_html_entities = true,
1123
-        $add_mobile_label = false
1124
-    ) {
1125
-        // need these
1126
-        if (! $question || ! $name) {
1127
-            return null;
1128
-        }
1129
-        // prep the answer
1130
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1131
-        // prep the required array
1132
-        $required = self::prep_required($required);
1133
-        // make sure $dimensions is an array
1134
-        $dimensions = is_array($dimensions) ? $dimensions : [];
1135
-        // and set some defaults
1136
-        $dimensions = array_merge(['rows' => 3, 'cols' => 40], $dimensions);
1137
-        // set disabled tag
1138
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1139
-        // ya gots ta have style man!!!
1140
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1141
-        $class     .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1142
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1143
-
1144
-        $label_html   = self::label($question, $required_text, $required['label'], $name, $label_class);
1145
-        $mobile_label = self::mobileLabel(
1146
-            $add_mobile_label,
1147
-            $question,
1148
-            $required_text,
1149
-            $required['label'],
1150
-            $label_class,
1151
-            $name
1152
-        );
1153
-
1154
-        $input_html = $mobile_label
1155
-            . '<textarea name="' . $name . '" id="' . $id . '" class="' . trim($class) . '" '
1156
-            . 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  '
1157
-            . 'aria-label="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>'
1158
-             . esc_textarea($answer)
1159
-              . '</textarea>';
1160
-
1161
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1162
-        return $label_html . $input_html;
1163
-    }
1164
-
1165
-
1166
-    /**
1167
-     * generates HTML for a form select input
1168
-     *
1169
-     * @param string $question    label content
1170
-     * @param string $answer      form input value attribute
1171
-     * @param array  $options     array of answer options where array key = option value and array value = option
1172
-     *                            display text
1173
-     * @param string $name        form input name attribute
1174
-     * @param string $id          form input css id attribute
1175
-     * @param string $class       form input css class attribute
1176
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1177
-     *                            required 'class', and required 'msg' attribute
1178
-     * @param string $label_class css class attribute for the label
1179
-     * @param string $disabled    disabled="disabled" or null
1180
-     * @return string HTML
1181
-     */
1182
-    public static function select(
1183
-        $question = false,
1184
-        $answer = null,
1185
-        $options = false,
1186
-        $name = false,
1187
-        $id = '',
1188
-        $class = '',
1189
-        $required = false,
1190
-        $required_text = '',
1191
-        $label_class = '',
1192
-        $disabled = false,
1193
-        $system_ID = false,
1194
-        $use_html_entities = true,
1195
-        $add_please_select_option = false,
1196
-        $add_mobile_label = false
1197
-    ) {
1198
-
1199
-        // need these
1200
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1201
-            return null;
1202
-        }
1203
-        // prep the answer
1204
-        $answer = is_array($answer)
1205
-            ? self::prep_answer(array_shift($answer), $use_html_entities)
1206
-            : self::prep_answer($answer, $use_html_entities);
1207
-        // prep the required array
1208
-        $required = self::prep_required($required);
1209
-        // set disabled tag
1210
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1211
-        // ya gots ta have style man!!!
1212
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1213
-        $class = self::appendInputSizeClass($class, $options);
1214
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1215
-
1216
-        $label_html   = self::label($question, $required_text, $required['label'], $name, $label_class);
1217
-        $mobile_label = self::mobileLabel(
1218
-            $add_mobile_label,
1219
-            $question,
1220
-            $required_text,
1221
-            $required['label'],
1222
-            $label_class,
1223
-            $name
1224
-        );
1225
-
1226
-        $input_html = $mobile_label
1227
-            . '<select name="' . $name . '" id="' . $id . '" class="' . trim($class) . ' ' . $required['class'] . '" '
1228
-            . 'aria-label="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
1229
-        // recursively count array elements, to determine total number of options
1230
-        $only_option = count($options, 1) == 1;
1231
-        if (! $only_option) {
1232
-            // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
1233
-            $selected   = $answer === null ? ' selected' : '';
1234
-            $input_html .= $add_please_select_option
1235
-                ? "\n\t\t\t\t"
1236
-                  . '<option value=""' . $selected . '>'
1237
-                  . esc_html__(' - please select - ', 'event_espresso')
1238
-                  . '</option>'
1239
-                : '';
1240
-        }
1241
-        foreach ($options as $key => $value) {
1242
-            // if value is an array, then create option groups, else create regular ol' options
1243
-            $input_html .= is_array($value)
1244
-                ? self::_generate_select_option_group(
1245
-                    $key,
1246
-                    $value,
1247
-                    $answer,
1248
-                    $use_html_entities
1249
-                )
1250
-                : self::_generate_select_option(
1251
-                    $value->value(),
1252
-                    $value->desc(),
1253
-                    $answer,
1254
-                    $only_option,
1255
-                    $use_html_entities
1256
-                );
1257
-        }
1258
-
1259
-        $input_html .= "\n\t\t\t" . '</select>';
1260
-
1261
-        $input_html =
1262
-            apply_filters(
1263
-                'FHEE__EEH_Form_Fields__select__before_end_wrapper',
1264
-                $input_html,
1265
-                $question,
1266
-                $answer,
1267
-                $name,
1268
-                $id,
1269
-                $class,
1270
-                $system_ID
1271
-            );
1272
-
1273
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1274
-        return $label_html . $input_html;
1275
-    }
1276
-
1277
-
1278
-    /**
1279
-     *  _generate_select_option_group
1280
-     *
1281
-     *  if  $value for a select box is an array, then the key will be used as the optgroup label
1282
-     *  and the value array will be looped thru and the elements sent to _generate_select_option
1283
-     *
1284
-     * @param mixed   $opt_group
1285
-     * @param mixed   $QSOs
1286
-     * @param mixed   $answer
1287
-     * @param boolean $use_html_entities
1288
-     * @return string
1289
-     */
1290
-    private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
1291
-    {
1292
-        $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
1293
-        foreach ($QSOs as $QSO) {
1294
-            $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
1295
-        }
1296
-        $html .= "\n\t\t\t\t" . '</optgroup>';
1297
-        return $html;
1298
-    }
1299
-
1300
-
1301
-    /**
1302
-     *  _generate_select_option
1303
-     *
1304
-     * @param mixed   $key
1305
-     * @param mixed   $value
1306
-     * @param mixed   $answer
1307
-     * @param int     $only_option
1308
-     * @param boolean $use_html_entities
1309
-     * @return string
1310
-     */
1311
-    private static function _generate_select_option(
1312
-        $key,
1313
-        $value,
1314
-        $answer,
1315
-        $only_option = false,
1316
-        $use_html_entities = true
1317
-    ) {
1318
-        $key      = self::prep_answer($key, $use_html_entities);
1319
-        $value    = self::prep_answer($value, $use_html_entities);
1320
-        $value    = ! empty($value) ? $value : $key;
1321
-        $selected = ($answer == $key || $only_option) ? 'selected' : '';
1322
-        return "\n\t\t\t\t"
1323
-               . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> '
1324
-               . $value
1325
-               . '&nbsp;&nbsp;&nbsp;</option>';
1326
-    }
1327
-
1328
-
1329
-    /**
1330
-     * generates HTML for form radio button inputs
1331
-     *
1332
-     * @param bool|string $question    label content
1333
-     * @param string      $answer      form input value attribute
1334
-     * @param array|bool  $options     array of answer options where array key = option value and array value = option
1335
-     *                                 display text
1336
-     * @param bool|string $name        form input name attribute
1337
-     * @param string      $id          form input css id attribute
1338
-     * @param string      $class       form input css class attribute
1339
-     * @param array|bool  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1340
-     *                                 required 'class', and required 'msg' attribute
1341
-     * @param string      $required_text
1342
-     * @param string      $label_class css class attribute for the label
1343
-     * @param bool|string $disabled    disabled="disabled" or null
1344
-     * @param bool        $system_ID
1345
-     * @param bool        $use_html_entities
1346
-     * @param bool        $label_b4
1347
-     * @param bool        $use_desc_4_label
1348
-     * @return string HTML
1349
-     */
1350
-    public static function radio(
1351
-        $question = false,
1352
-        $answer = null,
1353
-        $options = false,
1354
-        $name = false,
1355
-        $id = '',
1356
-        $class = '',
1357
-        $required = false,
1358
-        $required_text = '',
1359
-        $label_class = '',
1360
-        $disabled = false,
1361
-        $system_ID = false,
1362
-        $use_html_entities = true,
1363
-        $label_b4 = false,
1364
-        $use_desc_4_label = false,
1365
-        $add_mobile_label = false
1366
-    ) {
1367
-        // need these
1368
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1369
-            return null;
1370
-        }
1371
-        // prep the answer
1372
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1373
-        // prep the required array
1374
-        $required = self::prep_required($required);
1375
-        // set disabled tag
1376
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1377
-        // ya gots ta have style man!!!
1378
-        $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1379
-        $class       = ! empty($class) ? $class : 'espresso-radio-btn-inp';
1380
-        $extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1381
-
1382
-        $label_html = self::label($question, $required_text, $required['label'], '', $label_class);
1383
-        $mobile_label = self::mobileLabel(
1384
-            $add_mobile_label,
1385
-            $question,
1386
-            $required_text,
1387
-            $required['label'],
1388
-            $label_class
1389
-        );
1390
-
1391
-        $input_html = $mobile_label
1392
-            . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $class . '-ul">';
1393
-
1394
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1395
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1396
-
1397
-        foreach ($options as $OPT) {
1398
-            if ($OPT instanceof EE_Question_Option) {
1399
-                $value   = self::prep_option_value($OPT->value());
1400
-                $label   = $use_desc_4_label ? $OPT->desc() : $OPT->value();
1401
-                $size    = $use_desc_4_label
1402
-                    ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc())
1403
-                    : self::get_label_size_class($OPT->value());
1404
-                $desc    = $OPT->desc();// no self::prep_answer
1405
-                $answer  = is_numeric($value) && empty($answer) ? 0 : $answer;
1406
-                $checked = (string) $value == (string) $answer ? ' checked' : '';
1407
-                $opt     = '-' . sanitize_key($value);
1408
-
1409
-                $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1410
-                $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
1411
-                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>&nbsp;&nbsp;' : '';
1412
-                $input_html .= "\n\t\t\t\t\t\t"
1413
-                               . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" '
1414
-                               . 'class="' . $class . '" value="' . $value . '" '
1415
-                               . 'aria-label="' . esc_attr($required['msg']) . '" ' . $disabled
1416
-                               . $checked . ' ' . $extra . '/>';
1417
-                $input_html .= ! $label_b4
1418
-                    ? "\n\t\t\t\t\t\t"
1419
-                      . '&nbsp;&nbsp;<span class="espresso-radio-btn-desc">'
1420
-                      . $label
1421
-                      . '</span>'
1422
-                    : '';
1423
-                $input_html .= "\n\t\t\t\t\t" . '</label>';
1424
-                $input_html .= $use_desc_4_label
1425
-                    ? ''
1426
-                    : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
1427
-                $input_html .= "\n\t\t\t\t" . '</li>';
1428
-            }
1429
-        }
1430
-
1431
-        $input_html .= "\n\t\t\t" . '</ul>';
1432
-
1433
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1434
-        return $label_html . $input_html;
1435
-    }
1436
-
1437
-
1438
-    /**
1439
-     * generates HTML for form checkbox inputs
1440
-     *
1441
-     * @param string $question    label content
1442
-     * @param string $answer      form input value attribute
1443
-     * @param array  $options     array of options where array key = option value and array value = option display text
1444
-     * @param string $name        form input name attribute
1445
-     * @param string $id          form input css id attribute
1446
-     * @param string $class       form input css class attribute
1447
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1448
-     *                            required 'class', and required 'msg' attribute
1449
-     * @param string $label_class css class attribute for the label
1450
-     * @param string $disabled    disabled="disabled" or null
1451
-     * @return string HTML
1452
-     */
1453
-    public static function checkbox(
1454
-        $question = false,
1455
-        $answer = null,
1456
-        $options = false,
1457
-        $name = false,
1458
-        $id = '',
1459
-        $class = '',
1460
-        $required = false,
1461
-        $required_text = '',
1462
-        $label_class = '',
1463
-        $disabled = false,
1464
-        $label_b4 = false,
1465
-        $system_ID = false,
1466
-        $use_html_entities = true,
1467
-        $add_mobile_label = false
1468
-    ) {
1469
-        // need these
1470
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1471
-            return null;
1472
-        }
1473
-        $answer = maybe_unserialize($answer);
1474
-
1475
-        // prep the answer(s)
1476
-        $answer = is_array($answer) ? $answer : [sanitize_key($answer) => $answer];
1477
-
1478
-        foreach ($answer as $key => $value) {
1479
-            $key            = self::prep_option_value($key);
1480
-            $answer[ $key ] = self::prep_answer($value, $use_html_entities);
1481
-        }
1482
-
1483
-        // prep the required array
1484
-        $required = self::prep_required($required);
1485
-        // set disabled tag
1486
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1487
-        // ya gots ta have style man!!!
1488
-        $radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1489
-        $class       = empty($class) ? 'espresso-radio-btn-inp' : $class;
1490
-        $extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1491
-
1492
-        $label_html   = self::label($question, $required_text, $required['label'], '', $label_class);
1493
-        $mobile_label = self::mobileLabel(
1494
-            $add_mobile_label,
1495
-            $question,
1496
-            $required_text,
1497
-            $required['label'],
1498
-            $label_class
1499
-        );
1500
-
1501
-        $input_html = $mobile_label
1502
-            . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $class . '-ul">';
1503
-
1504
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1505
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1506
-
1507
-        foreach ($options as $OPT) {
1508
-            $value = $OPT->value();// self::prep_option_value( $OPT->value() );
1509
-            $size  = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
1510
-            $text  = self::prep_answer($OPT->value());
1511
-            $desc  = $OPT->desc();
1512
-            $opt   = '-' . sanitize_key($value);
1513
-
1514
-            $checked = is_array($answer) && in_array($text, $answer) ? ' checked' : '';
1515
-
1516
-            $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1517
-            $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
1518
-            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>&nbsp;&nbsp;' : '';
1519
-            $input_html .= "\n\t\t\t\t\t\t"
1520
-                           . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" '
1521
-                           . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" '
1522
-                           . 'aria-label="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
1523
-            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '&nbsp;&nbsp;<span>' . $text . '</span>' : '';
1524
-            $input_html .= "\n\t\t\t\t\t" . '</label>';
1525
-            if (! empty($desc) && $desc != $text) {
1526
-                $input_html .= "\n\t\t\t\t\t"
1527
-                               . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'
1528
-                               . $desc
1529
-                               . '</div>';
1530
-            }
1531
-            $input_html .= "\n\t\t\t\t" . '</li>';
1532
-        }
1533
-
1534
-        $input_html .= "\n\t\t\t" . '</ul>';
1535
-
1536
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1537
-        return $label_html . $input_html;
1538
-    }
1539
-
1540
-
1541
-    /**
1542
-     * generates HTML for a form datepicker input
1543
-     *
1544
-     * @param string $question    label content
1545
-     * @param string $answer      form input value attribute
1546
-     * @param string $name        form input name attribute
1547
-     * @param string $id          form input css id attribute
1548
-     * @param string $class       form input css class attribute
1549
-     * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1550
-     *                            required 'class', and required 'msg' attribute
1551
-     * @param string $label_class css class attribute for the label
1552
-     * @param string $disabled    disabled="disabled" or null
1553
-     * @return string HTML
1554
-     */
1555
-    public static function datepicker(
1556
-        $question = false,
1557
-        $answer = null,
1558
-        $name = false,
1559
-        $id = '',
1560
-        $class = '',
1561
-        $required = false,
1562
-        $required_text = '',
1563
-        $label_class = '',
1564
-        $disabled = false,
1565
-        $system_ID = false,
1566
-        $use_html_entities = true,
1567
-        $add_mobile_label = false
1568
-    ) {
1569
-        // need these
1570
-        if (! $question || ! $name) {
1571
-            return null;
1572
-        }
1573
-        // prep the answer
1574
-        $answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1575
-        // prep the required array
1576
-        $required = self::prep_required($required);
1577
-        // set disabled tag
1578
-        $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1579
-        // ya gots ta have style man!!!
1580
-        $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1581
-        $class     = empty($class) ? $txt_class : $class;
1582
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1583
-        $class = self::appendInputSizeClass($class, $answer);
1584
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1585
-
1586
-        $label_html   = self::label($question, $required_text, $required['label'], '', $label_class);
1587
-        $mobile_label = self::mobileLabel(
1588
-            $add_mobile_label,
1589
-            $question,
1590
-            $required_text,
1591
-            $required['label'],
1592
-            $label_class,
1593
-            $name
1594
-        );
1595
-
1596
-        $input_html = $mobile_label
1597
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
1598
-            . 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  '
1599
-            . 'aria-label="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1600
-
1601
-        // enqueue scripts
1602
-        wp_register_style(
1603
-            'espresso-ui-theme',
1604
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1605
-            [],
1606
-            EVENT_ESPRESSO_VERSION
1607
-        );
1608
-        wp_enqueue_style('espresso-ui-theme');
1609
-        wp_enqueue_script('jquery-ui-datepicker');
1610
-
1611
-        $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1612
-        return $label_html . $input_html;
1613
-    }
1614
-
1615
-
1616
-    /**
1617
-     *  remove_label_keep_required_msg
1618
-     *  this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label
1619
-     *
1620
-     * @access public
1621
-     * @return     string
1622
-     */
1623
-    public static function remove_label_keep_required_msg($label_html, $required_text)
1624
-    {
1625
-        return $required_text;
1626
-    }
1627
-
1628
-
1629
-    /**
1630
-     * Simply returns the HTML for a hidden input of the given name and value.
1631
-     *
1632
-     * @param string $name
1633
-     * @param string $value
1634
-     * @return string HTML
1635
-     */
1636
-    public static function hidden_input($name, $value, $id = '')
1637
-    {
1638
-        $id = ! empty($id) ? $id : $name;
1639
-        return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>';
1640
-    }
1641
-
1642
-
1643
-    /**
1644
-     * prep_question
1645
-     *
1646
-     * @param string $question
1647
-     * @return string
1648
-     */
1649
-    public static function prep_question($question)
1650
-    {
1651
-        return $question;
1652
-    }
1653
-
1654
-
1655
-    /**
1656
-     *  prep_answer
1657
-     *
1658
-     * @param mixed $answer
1659
-     * @return string
1660
-     */
1661
-    public static function prep_answer($answer, $use_html_entities = true)
1662
-    {
1663
-        // make sure we convert bools first.  Otherwise (bool) false becomes an empty string which is NOT desired,
1664
-        // we want "0".
1665
-        if (is_bool($answer)) {
1666
-            $answer = $answer ? 1 : 0;
1667
-        }
1668
-        $answer = trim(stripslashes(str_replace('&#039;', "'", $answer)));
1669
-        return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer;
1670
-    }
1671
-
1672
-
1673
-    /**
1674
-     *  prep_answer_options
1675
-     *
1676
-     * @param array $QSOs array of EE_Question_Option objects
1677
-     * @return array
1678
-     */
1679
-    public static function prep_answer_options($QSOs = [])
1680
-    {
1681
-        $prepped_answer_options = [];
1682
-        if (is_array($QSOs) && ! empty($QSOs)) {
1683
-            foreach ($QSOs as $key => $QSO) {
1684
-                if (! $QSO instanceof EE_Question_Option) {
1685
-                    $QSO = EE_Question_Option::new_instance(
1686
-                        [
1687
-                            'QSO_value' => is_array($QSO) && isset($QSO['id'])
1688
-                                ? (string) $QSO['id']
1689
-                                : (string) $key,
1690
-                            'QSO_desc'  => is_array($QSO) && isset($QSO['text'])
1691
-                                ? (string) $QSO['text']
1692
-                                : (string) $QSO,
1693
-                        ]
1694
-                    );
1695
-                }
1696
-                if ($QSO->opt_group()) {
1697
-                    $prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1698
-                } else {
1699
-                    $prepped_answer_options[] = $QSO;
1700
-                }
1701
-            }
1702
-        }
1703
-        //      d( $prepped_answer_options );
1704
-        return $prepped_answer_options;
1705
-    }
1706
-
1707
-
1708
-    /**
1709
-     *  prep_option_value
1710
-     *
1711
-     * @param string $option_value
1712
-     * @return string
1713
-     */
1714
-    public static function prep_option_value($option_value)
1715
-    {
1716
-        return esc_attr(trim(stripslashes($option_value)));
1717
-    }
1718
-
1719
-
1720
-    /**
1721
-     *  prep_required
1722
-     *
1723
-     * @param string|array $required
1724
-     * @return array
1725
-     */
1726
-    public static function prep_required($required = [])
1727
-    {
1728
-        // make sure required is an array
1729
-        $required = is_array($required) ? $required : [];
1730
-        // and set some defaults
1731
-        return array_merge(['label' => '', 'class' => '', 'msg' => ''], $required);
1732
-    }
1733
-
1734
-
1735
-    /**
1736
-     *  get_label_size_class
1737
-     *
1738
-     * @param string $value
1739
-     * @return string
1740
-     */
1741
-    public static function get_label_size_class($value = false)
1742
-    {
1743
-        if ($value === false || $value === '') {
1744
-            return ' class="medium-lbl"';
1745
-        }
1746
-        // determine length of option value
1747
-        $val_size = strlen($value);
1748
-        switch ($val_size) {
1749
-            case $val_size < 3:
1750
-                $size = ' class="nano-lbl"';
1751
-                break;
1752
-            case $val_size < 6:
1753
-                $size = ' class="micro-lbl"';
1754
-                break;
1755
-            case $val_size < 12:
1756
-                $size = ' class="tiny-lbl"';
1757
-                break;
1758
-            case $val_size < 25:
1759
-                $size = ' class="small-lbl"';
1760
-                break;
1761
-            case $val_size > 100:
1762
-                $size = ' class="big-lbl"';
1763
-                break;
1764
-            default:
1765
-                $size = ' class="medium-lbl"';
1766
-                break;
1767
-        }
1768
-        return $size;
1769
-    }
1770
-
1771
-
1772
-    /**
1773
-     *  _load_system_dropdowns
1774
-     *
1775
-     * @param EE_Question_Form_Input $QFI
1776
-     * @return array
1777
-     * @throws EE_Error
1778
-     * @throws ReflectionException
1779
-     */
1780
-    private static function _load_system_dropdowns($QFI)
1781
-    {
1782
-        $QST_system = $QFI->get('QST_system');
1783
-        switch ($QST_system) {
1784
-            case 'state':
1785
-                $QFI = self::generate_state_dropdown($QFI);
1786
-                break;
1787
-            case 'country':
1788
-                $QFI = self::generate_country_dropdown($QFI);
1789
-                break;
1790
-            case 'admin-state':
1791
-                $QFI = self::generate_state_dropdown($QFI, true);
1792
-                break;
1793
-            case 'admin-country':
1794
-                $QFI = self::generate_country_dropdown($QFI, true);
1795
-                break;
1796
-        }
1797
-        return $QFI;
1798
-    }
1799
-
1800
-
1801
-    /**
1802
-     * This preps dropdowns that are specialized.
1803
-     *
1804
-     * @param EE_Question_Form_Input $QFI
1805
-     *
1806
-     * @return EE_Question_Form_Input
1807
-     * @throws EE_Error
1808
-     * @throws ReflectionException
1809
-     * @since  4.6.0
1810
-     */
1811
-    protected static function _load_specialized_dropdowns($QFI)
1812
-    {
1813
-        switch ($QFI->get('QST_type')) {
1814
-            case 'STATE':
1815
-                $QFI = self::generate_state_dropdown($QFI);
1816
-                break;
1817
-            case 'COUNTRY':
1818
-                $QFI = self::generate_country_dropdown($QFI);
1819
-                break;
1820
-        }
1821
-        return $QFI;
1822
-    }
1823
-
1824
-
1825
-    /**
1826
-     *    generate_state_dropdown
1827
-     *
1828
-     * @param EE_Question_Form_Input $QST
1829
-     * @param bool                   $get_all
1830
-     * @return EE_Question_Form_Input
1831
-     * @throws EE_Error
1832
-     * @throws ReflectionException
1833
-     */
1834
-    public static function generate_state_dropdown($QST, $get_all = false)
1835
-    {
1836
-        $states = $get_all
1837
-            ? EEM_State::instance()->get_all_states()
1838
-            : EEM_State::instance()->get_all_states_of_active_countries();
1839
-        if ($states && count($states) != count($QST->options())) {
1840
-            $QST->set('QST_type', 'DROPDOWN');
1841
-            // if multiple countries, we'll create option groups within the dropdown
1842
-            foreach ($states as $state) {
1843
-                if ($state instanceof EE_State) {
1844
-                    $QSO = EE_Question_Option::new_instance(
1845
-                        [
1846
-                            'QSO_value'   => $state->ID(),
1847
-                            'QSO_desc'    => $state->name(),
1848
-                            'QST_ID'      => $QST->get('QST_ID'),
1849
-                            'QSO_deleted' => false,
1850
-                        ]
1851
-                    );
1852
-                    // set option group
1853
-                    $QSO->set_opt_group($state->country()->name());
1854
-                    // add option to question
1855
-                    $QST->add_temp_option($QSO);
1856
-                }
1857
-            }
1858
-        }
1859
-        return $QST;
1860
-    }
1861
-
1862
-
1863
-    /**
1864
-     *    generate_country_dropdown
1865
-     *
1866
-     * @param      $QST
1867
-     * @param bool $get_all
1868
-     * @return array
1869
-     * @throws EE_Error
1870
-     * @throws ReflectionException
1871
-     * @internal param array $question
1872
-     */
1873
-    public static function generate_country_dropdown($QST, $get_all = false)
1874
-    {
1875
-        $countries = $get_all
1876
-            ? EEM_Country::instance()->get_all_countries()
1877
-            : EEM_Country::instance()->get_all_active_countries();
1878
-        if ($countries && count($countries) != count($QST->options())) {
1879
-            $QST->set('QST_type', 'DROPDOWN');
1880
-            // now add countries
1881
-            foreach ($countries as $country) {
1882
-                if ($country instanceof EE_Country) {
1883
-                    $QSO = EE_Question_Option::new_instance(
1884
-                        [
1885
-                            'QSO_value'   => $country->ID(),
1886
-                            'QSO_desc'    => $country->name(),
1887
-                            'QST_ID'      => $QST->get('QST_ID'),
1888
-                            'QSO_deleted' => false,
1889
-                        ]
1890
-                    );
1891
-                    $QST->add_temp_option($QSO);
1892
-                }
1893
-            }
1894
-        }
1895
-        return $QST;
1896
-    }
1897
-
1898
-
1899
-    /**
1900
-     *  generates options for a month dropdown selector with numbers from 01 to 12
1901
-     *
1902
-     * @return array()
1903
-     */
1904
-    public static function two_digit_months_dropdown_options()
1905
-    {
1906
-        $options = [];
1907
-        for ($x = 1; $x <= 12; $x++) {
1908
-            $mm             = str_pad($x, 2, '0', STR_PAD_LEFT);
1909
-            $options[ $mm ] = $mm;
1910
-        }
1911
-        return EEH_Form_Fields::prep_answer_options($options);
1912
-    }
1913
-
1914
-
1915
-    /**
1916
-     *  generates a year dropdown selector with numbers for the next ten years
1917
-     *
1918
-     * @return array
1919
-     */
1920
-    public static function next_decade_two_digit_year_dropdown_options()
1921
-    {
1922
-        $options      = [];
1923
-        $current_year = date('y');
1924
-        $next_decade  = $current_year + 10;
1925
-        for ($x = $current_year; $x <= $next_decade; $x++) {
1926
-            $yy             = str_pad($x, 2, '0', STR_PAD_LEFT);
1927
-            $options[ $yy ] = $yy;
1928
-        }
1929
-        return EEH_Form_Fields::prep_answer_options($options);
1930
-    }
1931
-
1932
-
1933
-    /**
1934
-     * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for
1935
-     * list table filter.
1936
-     *
1937
-     * @param string  $cur_date     any currently selected date can be entered here.
1938
-     * @param string  $status       Registration status
1939
-     * @param integer $evt_category Event Category ID if the Event Category filter is selected
1940
-     * @return string                html
1941
-     * @throws EE_Error
1942
-     */
1943
-    public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1944
-    {
1945
-        $_where = [];
1946
-        if (! empty($status)) {
1947
-            $_where['STS_ID'] = $status;
1948
-        }
1949
-
1950
-        if ($evt_category > 0) {
1951
-            $_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1952
-        }
1953
-
1954
-        $regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1955
-
1956
-        // setup vals for select input helper
1957
-        $options = [
1958
-            0 => [
1959
-                'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1960
-                'id'   => '',
1961
-            ],
1962
-        ];
1963
-
1964
-        foreach ($regdtts as $regdtt) {
1965
-            $date      = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1966
-            $options[] = [
1967
-                'text' => $date,
1968
-                'id'   => $date,
1969
-            ];
1970
-        }
1971
-
1972
-        return self::select_input('month_range', $options, $cur_date);
1973
-    }
1974
-
1975
-
1976
-    /**
1977
-     * generates a month/year dropdown selector for all events matching the given criteria
1978
-     * Typically used for list table filter
1979
-     *
1980
-     * @param string $cur_date          any currently selected date can be entered here.
1981
-     * @param string $status            "view" (i.e. all, today, month, draft)
1982
-     * @param int    $evt_category      category event belongs to
1983
-     * @param string $evt_active_status "upcoming", "expired", "active", or "inactive"
1984
-     * @return string                    html
1985
-     * @throws EE_Error
1986
-     */
1987
-    public static function generate_event_months_dropdown(
1988
-        $cur_date = '',
1989
-        $status = null,
1990
-        $evt_category = null,
1991
-        $evt_active_status = null
1992
-    ) {
1993
-        // determine what post_status our condition will have for the query.
1994
-        // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1995
-        switch ($status) {
1996
-            case 'month':
1997
-            case 'today':
1998
-            case null:
1999
-            case 'all':
2000
-                $where['Event.status'] = ['NOT IN', ['trash']];
2001
-                break;
2002
-            case 'draft':
2003
-                $where['Event.status'] = ['IN', ['draft', 'auto-draft']];
2004
-                break;
2005
-            default:
2006
-                $where['Event.status'] = $status;
2007
-        }
2008
-
2009
-        // phpcs:enable
2010
-
2011
-        // categories?
2012
-
2013
-
2014
-        if (! empty($evt_category)) {
2015
-            $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
2016
-            $where['Event.Term_Taxonomy.term_id']  = $evt_category;
2017
-        }
2018
-
2019
-
2020
-        //      $where['DTT_is_primary'] = 1;
2021
-
2022
-        $DTTS = EEM_Datetime::instance()->get_dtt_months_and_years($where, $evt_active_status);
2023
-
2024
-        // let's setup vals for select input helper
2025
-        $options = [
2026
-            0 => [
2027
-                'text' => esc_html__('Select a Month/Year', 'event_espresso'),
2028
-                'id'   => "",
2029
-            ],
2030
-        ];
2031
-
2032
-
2033
-        // translate month and date
2034
-        global $wp_locale;
2035
-
2036
-        foreach ($DTTS as $DTT) {
2037
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
2038
-            $id             = $DTT->dtt_month . ' ' . $DTT->dtt_year;
2039
-            $options[]      = [
2040
-                'text' => $localized_date,
2041
-                'id'   => $id,
2042
-            ];
2043
-        }
2044
-
2045
-
2046
-        return self::select_input('month_range', $options, $cur_date);
2047
-    }
2048
-
2049
-
2050
-    /**
2051
-     * generates the dropdown selector for event categories
2052
-     * typically used as a filter on list tables.
2053
-     *
2054
-     * @param integer $current_cat currently selected category
2055
-     * @return string               html for dropdown
2056
-     * @throws EE_Error
2057
-     * @throws ReflectionException
2058
-     */
2059
-    public static function generate_event_category_dropdown($current_cat = -1)
2060
-    {
2061
-        $categories = EEM_Term::instance()->get_all_ee_categories(true);
2062
-        $options    = [
2063
-            '0' => [
2064
-                'text' => esc_html__('All Categories', 'event_espresso'),
2065
-                'id'   => -1,
2066
-            ],
2067
-        ];
2068
-
2069
-        // setup categories for dropdown
2070
-        foreach ($categories as $category) {
2071
-            $options[] = [
2072
-                'text' => $category->get('name'),
2073
-                'id'   => $category->ID(),
2074
-            ];
2075
-        }
2076
-
2077
-        return self::select_input('EVT_CAT', $options, $current_cat);
2078
-    }
2079
-
2080
-
2081
-    /**
2082
-     *    generate a submit button with or without it's own microform
2083
-     *    this is the only way to create buttons that are compatible across all themes
2084
-     *
2085
-     * @access    public
2086
-     * @param string      $url              - the form action
2087
-     * @param string      $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm"
2088
-     *                                      for the form
2089
-     * @param string      $class            - css classes (separated by spaces if more than one)
2090
-     * @param string      $text             - what appears on the button
2091
-     * @param string      $nonce_action     - if using nonces
2092
-     * @param bool|string $input_only       - whether to print form header and footer. TRUE returns the input without
2093
-     *                                      the form
2094
-     * @param string      $extra_attributes - any extra attributes that need to be attached to the form input
2095
-     * @return    string
2096
-     */
2097
-    public static function submit_button(
2098
-        $url = '',
2099
-        $ID = '',
2100
-        $class = '',
2101
-        $text = '',
2102
-        $nonce_action = '',
2103
-        $input_only = false,
2104
-        $extra_attributes = ''
2105
-    ) {
2106
-        $btn = '';
2107
-        if (empty($url) || empty($ID)) {
2108
-            return $btn;
2109
-        }
2110
-        $text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso');
2111
-        $btn  .= '<input id="' . $ID . '-btn" class="' . $class . '" '
2112
-                 . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
2113
-        if (! $input_only) {
2114
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
2115
-            $btn_frm .= ! empty($nonce_action)
2116
-                ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false)
2117
-                : '';
2118
-            $btn_frm .= $btn;
2119
-            $btn_frm .= '</form>';
2120
-            $btn     = $btn_frm;
2121
-            unset($btn_frm);
2122
-        }
2123
-        return $btn;
2124
-    }
1090
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1091
+		return $label_html . $input_html;
1092
+	}
1093
+
1094
+
1095
+	/**
1096
+	 * generates HTML for a form textarea
1097
+	 *
1098
+	 * @param string $question    label content
1099
+	 * @param string $answer      form input value attribute
1100
+	 * @param string $name        form input name attribute
1101
+	 * @param string $id          form input css id attribute
1102
+	 * @param string $class       form input css class attribute
1103
+	 * @param array  $dimensions  array of form input rows and cols attributes : array( 'rows' => 3, 'cols' => 40 )
1104
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1105
+	 *                            required 'class', and required 'msg' attribute
1106
+	 * @param string $label_class css class attribute for the label
1107
+	 * @param string $disabled    disabled="disabled" or null
1108
+	 * @return string HTML
1109
+	 */
1110
+	public static function textarea(
1111
+		$question = false,
1112
+		$answer = null,
1113
+		$name = false,
1114
+		$id = '',
1115
+		$class = '',
1116
+		$dimensions = false,
1117
+		$required = false,
1118
+		$required_text = '',
1119
+		$label_class = '',
1120
+		$disabled = false,
1121
+		$system_ID = false,
1122
+		$use_html_entities = true,
1123
+		$add_mobile_label = false
1124
+	) {
1125
+		// need these
1126
+		if (! $question || ! $name) {
1127
+			return null;
1128
+		}
1129
+		// prep the answer
1130
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1131
+		// prep the required array
1132
+		$required = self::prep_required($required);
1133
+		// make sure $dimensions is an array
1134
+		$dimensions = is_array($dimensions) ? $dimensions : [];
1135
+		// and set some defaults
1136
+		$dimensions = array_merge(['rows' => 3, 'cols' => 40], $dimensions);
1137
+		// set disabled tag
1138
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1139
+		// ya gots ta have style man!!!
1140
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1141
+		$class     .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1142
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1143
+
1144
+		$label_html   = self::label($question, $required_text, $required['label'], $name, $label_class);
1145
+		$mobile_label = self::mobileLabel(
1146
+			$add_mobile_label,
1147
+			$question,
1148
+			$required_text,
1149
+			$required['label'],
1150
+			$label_class,
1151
+			$name
1152
+		);
1153
+
1154
+		$input_html = $mobile_label
1155
+			. '<textarea name="' . $name . '" id="' . $id . '" class="' . trim($class) . '" '
1156
+			. 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  '
1157
+			. 'aria-label="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>'
1158
+			 . esc_textarea($answer)
1159
+			  . '</textarea>';
1160
+
1161
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1162
+		return $label_html . $input_html;
1163
+	}
1164
+
1165
+
1166
+	/**
1167
+	 * generates HTML for a form select input
1168
+	 *
1169
+	 * @param string $question    label content
1170
+	 * @param string $answer      form input value attribute
1171
+	 * @param array  $options     array of answer options where array key = option value and array value = option
1172
+	 *                            display text
1173
+	 * @param string $name        form input name attribute
1174
+	 * @param string $id          form input css id attribute
1175
+	 * @param string $class       form input css class attribute
1176
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1177
+	 *                            required 'class', and required 'msg' attribute
1178
+	 * @param string $label_class css class attribute for the label
1179
+	 * @param string $disabled    disabled="disabled" or null
1180
+	 * @return string HTML
1181
+	 */
1182
+	public static function select(
1183
+		$question = false,
1184
+		$answer = null,
1185
+		$options = false,
1186
+		$name = false,
1187
+		$id = '',
1188
+		$class = '',
1189
+		$required = false,
1190
+		$required_text = '',
1191
+		$label_class = '',
1192
+		$disabled = false,
1193
+		$system_ID = false,
1194
+		$use_html_entities = true,
1195
+		$add_please_select_option = false,
1196
+		$add_mobile_label = false
1197
+	) {
1198
+
1199
+		// need these
1200
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1201
+			return null;
1202
+		}
1203
+		// prep the answer
1204
+		$answer = is_array($answer)
1205
+			? self::prep_answer(array_shift($answer), $use_html_entities)
1206
+			: self::prep_answer($answer, $use_html_entities);
1207
+		// prep the required array
1208
+		$required = self::prep_required($required);
1209
+		// set disabled tag
1210
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1211
+		// ya gots ta have style man!!!
1212
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1213
+		$class = self::appendInputSizeClass($class, $options);
1214
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1215
+
1216
+		$label_html   = self::label($question, $required_text, $required['label'], $name, $label_class);
1217
+		$mobile_label = self::mobileLabel(
1218
+			$add_mobile_label,
1219
+			$question,
1220
+			$required_text,
1221
+			$required['label'],
1222
+			$label_class,
1223
+			$name
1224
+		);
1225
+
1226
+		$input_html = $mobile_label
1227
+			. '<select name="' . $name . '" id="' . $id . '" class="' . trim($class) . ' ' . $required['class'] . '" '
1228
+			. 'aria-label="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
1229
+		// recursively count array elements, to determine total number of options
1230
+		$only_option = count($options, 1) == 1;
1231
+		if (! $only_option) {
1232
+			// if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
1233
+			$selected   = $answer === null ? ' selected' : '';
1234
+			$input_html .= $add_please_select_option
1235
+				? "\n\t\t\t\t"
1236
+				  . '<option value=""' . $selected . '>'
1237
+				  . esc_html__(' - please select - ', 'event_espresso')
1238
+				  . '</option>'
1239
+				: '';
1240
+		}
1241
+		foreach ($options as $key => $value) {
1242
+			// if value is an array, then create option groups, else create regular ol' options
1243
+			$input_html .= is_array($value)
1244
+				? self::_generate_select_option_group(
1245
+					$key,
1246
+					$value,
1247
+					$answer,
1248
+					$use_html_entities
1249
+				)
1250
+				: self::_generate_select_option(
1251
+					$value->value(),
1252
+					$value->desc(),
1253
+					$answer,
1254
+					$only_option,
1255
+					$use_html_entities
1256
+				);
1257
+		}
1258
+
1259
+		$input_html .= "\n\t\t\t" . '</select>';
1260
+
1261
+		$input_html =
1262
+			apply_filters(
1263
+				'FHEE__EEH_Form_Fields__select__before_end_wrapper',
1264
+				$input_html,
1265
+				$question,
1266
+				$answer,
1267
+				$name,
1268
+				$id,
1269
+				$class,
1270
+				$system_ID
1271
+			);
1272
+
1273
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1274
+		return $label_html . $input_html;
1275
+	}
1276
+
1277
+
1278
+	/**
1279
+	 *  _generate_select_option_group
1280
+	 *
1281
+	 *  if  $value for a select box is an array, then the key will be used as the optgroup label
1282
+	 *  and the value array will be looped thru and the elements sent to _generate_select_option
1283
+	 *
1284
+	 * @param mixed   $opt_group
1285
+	 * @param mixed   $QSOs
1286
+	 * @param mixed   $answer
1287
+	 * @param boolean $use_html_entities
1288
+	 * @return string
1289
+	 */
1290
+	private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
1291
+	{
1292
+		$html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
1293
+		foreach ($QSOs as $QSO) {
1294
+			$html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
1295
+		}
1296
+		$html .= "\n\t\t\t\t" . '</optgroup>';
1297
+		return $html;
1298
+	}
1299
+
1300
+
1301
+	/**
1302
+	 *  _generate_select_option
1303
+	 *
1304
+	 * @param mixed   $key
1305
+	 * @param mixed   $value
1306
+	 * @param mixed   $answer
1307
+	 * @param int     $only_option
1308
+	 * @param boolean $use_html_entities
1309
+	 * @return string
1310
+	 */
1311
+	private static function _generate_select_option(
1312
+		$key,
1313
+		$value,
1314
+		$answer,
1315
+		$only_option = false,
1316
+		$use_html_entities = true
1317
+	) {
1318
+		$key      = self::prep_answer($key, $use_html_entities);
1319
+		$value    = self::prep_answer($value, $use_html_entities);
1320
+		$value    = ! empty($value) ? $value : $key;
1321
+		$selected = ($answer == $key || $only_option) ? 'selected' : '';
1322
+		return "\n\t\t\t\t"
1323
+			   . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> '
1324
+			   . $value
1325
+			   . '&nbsp;&nbsp;&nbsp;</option>';
1326
+	}
1327
+
1328
+
1329
+	/**
1330
+	 * generates HTML for form radio button inputs
1331
+	 *
1332
+	 * @param bool|string $question    label content
1333
+	 * @param string      $answer      form input value attribute
1334
+	 * @param array|bool  $options     array of answer options where array key = option value and array value = option
1335
+	 *                                 display text
1336
+	 * @param bool|string $name        form input name attribute
1337
+	 * @param string      $id          form input css id attribute
1338
+	 * @param string      $class       form input css class attribute
1339
+	 * @param array|bool  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1340
+	 *                                 required 'class', and required 'msg' attribute
1341
+	 * @param string      $required_text
1342
+	 * @param string      $label_class css class attribute for the label
1343
+	 * @param bool|string $disabled    disabled="disabled" or null
1344
+	 * @param bool        $system_ID
1345
+	 * @param bool        $use_html_entities
1346
+	 * @param bool        $label_b4
1347
+	 * @param bool        $use_desc_4_label
1348
+	 * @return string HTML
1349
+	 */
1350
+	public static function radio(
1351
+		$question = false,
1352
+		$answer = null,
1353
+		$options = false,
1354
+		$name = false,
1355
+		$id = '',
1356
+		$class = '',
1357
+		$required = false,
1358
+		$required_text = '',
1359
+		$label_class = '',
1360
+		$disabled = false,
1361
+		$system_ID = false,
1362
+		$use_html_entities = true,
1363
+		$label_b4 = false,
1364
+		$use_desc_4_label = false,
1365
+		$add_mobile_label = false
1366
+	) {
1367
+		// need these
1368
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1369
+			return null;
1370
+		}
1371
+		// prep the answer
1372
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1373
+		// prep the required array
1374
+		$required = self::prep_required($required);
1375
+		// set disabled tag
1376
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1377
+		// ya gots ta have style man!!!
1378
+		$radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1379
+		$class       = ! empty($class) ? $class : 'espresso-radio-btn-inp';
1380
+		$extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1381
+
1382
+		$label_html = self::label($question, $required_text, $required['label'], '', $label_class);
1383
+		$mobile_label = self::mobileLabel(
1384
+			$add_mobile_label,
1385
+			$question,
1386
+			$required_text,
1387
+			$required['label'],
1388
+			$label_class
1389
+		);
1390
+
1391
+		$input_html = $mobile_label
1392
+			. '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $class . '-ul">';
1393
+
1394
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1395
+		$class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1396
+
1397
+		foreach ($options as $OPT) {
1398
+			if ($OPT instanceof EE_Question_Option) {
1399
+				$value   = self::prep_option_value($OPT->value());
1400
+				$label   = $use_desc_4_label ? $OPT->desc() : $OPT->value();
1401
+				$size    = $use_desc_4_label
1402
+					? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc())
1403
+					: self::get_label_size_class($OPT->value());
1404
+				$desc    = $OPT->desc();// no self::prep_answer
1405
+				$answer  = is_numeric($value) && empty($answer) ? 0 : $answer;
1406
+				$checked = (string) $value == (string) $answer ? ' checked' : '';
1407
+				$opt     = '-' . sanitize_key($value);
1408
+
1409
+				$input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1410
+				$input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
1411
+				$input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>&nbsp;&nbsp;' : '';
1412
+				$input_html .= "\n\t\t\t\t\t\t"
1413
+							   . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" '
1414
+							   . 'class="' . $class . '" value="' . $value . '" '
1415
+							   . 'aria-label="' . esc_attr($required['msg']) . '" ' . $disabled
1416
+							   . $checked . ' ' . $extra . '/>';
1417
+				$input_html .= ! $label_b4
1418
+					? "\n\t\t\t\t\t\t"
1419
+					  . '&nbsp;&nbsp;<span class="espresso-radio-btn-desc">'
1420
+					  . $label
1421
+					  . '</span>'
1422
+					: '';
1423
+				$input_html .= "\n\t\t\t\t\t" . '</label>';
1424
+				$input_html .= $use_desc_4_label
1425
+					? ''
1426
+					: '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
1427
+				$input_html .= "\n\t\t\t\t" . '</li>';
1428
+			}
1429
+		}
1430
+
1431
+		$input_html .= "\n\t\t\t" . '</ul>';
1432
+
1433
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1434
+		return $label_html . $input_html;
1435
+	}
1436
+
1437
+
1438
+	/**
1439
+	 * generates HTML for form checkbox inputs
1440
+	 *
1441
+	 * @param string $question    label content
1442
+	 * @param string $answer      form input value attribute
1443
+	 * @param array  $options     array of options where array key = option value and array value = option display text
1444
+	 * @param string $name        form input name attribute
1445
+	 * @param string $id          form input css id attribute
1446
+	 * @param string $class       form input css class attribute
1447
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1448
+	 *                            required 'class', and required 'msg' attribute
1449
+	 * @param string $label_class css class attribute for the label
1450
+	 * @param string $disabled    disabled="disabled" or null
1451
+	 * @return string HTML
1452
+	 */
1453
+	public static function checkbox(
1454
+		$question = false,
1455
+		$answer = null,
1456
+		$options = false,
1457
+		$name = false,
1458
+		$id = '',
1459
+		$class = '',
1460
+		$required = false,
1461
+		$required_text = '',
1462
+		$label_class = '',
1463
+		$disabled = false,
1464
+		$label_b4 = false,
1465
+		$system_ID = false,
1466
+		$use_html_entities = true,
1467
+		$add_mobile_label = false
1468
+	) {
1469
+		// need these
1470
+		if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1471
+			return null;
1472
+		}
1473
+		$answer = maybe_unserialize($answer);
1474
+
1475
+		// prep the answer(s)
1476
+		$answer = is_array($answer) ? $answer : [sanitize_key($answer) => $answer];
1477
+
1478
+		foreach ($answer as $key => $value) {
1479
+			$key            = self::prep_option_value($key);
1480
+			$answer[ $key ] = self::prep_answer($value, $use_html_entities);
1481
+		}
1482
+
1483
+		// prep the required array
1484
+		$required = self::prep_required($required);
1485
+		// set disabled tag
1486
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1487
+		// ya gots ta have style man!!!
1488
+		$radio_class = is_admin() ? 'ee-admin-radio-lbl' : $label_class;
1489
+		$class       = empty($class) ? 'espresso-radio-btn-inp' : $class;
1490
+		$extra       = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1491
+
1492
+		$label_html   = self::label($question, $required_text, $required['label'], '', $label_class);
1493
+		$mobile_label = self::mobileLabel(
1494
+			$add_mobile_label,
1495
+			$question,
1496
+			$required_text,
1497
+			$required['label'],
1498
+			$label_class
1499
+		);
1500
+
1501
+		$input_html = $mobile_label
1502
+			. '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $class . '-ul">';
1503
+
1504
+		$class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1505
+		$class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1506
+
1507
+		foreach ($options as $OPT) {
1508
+			$value = $OPT->value();// self::prep_option_value( $OPT->value() );
1509
+			$size  = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
1510
+			$text  = self::prep_answer($OPT->value());
1511
+			$desc  = $OPT->desc();
1512
+			$opt   = '-' . sanitize_key($value);
1513
+
1514
+			$checked = is_array($answer) && in_array($text, $answer) ? ' checked' : '';
1515
+
1516
+			$input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1517
+			$input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
1518
+			$input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>&nbsp;&nbsp;' : '';
1519
+			$input_html .= "\n\t\t\t\t\t\t"
1520
+						   . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" '
1521
+						   . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" '
1522
+						   . 'aria-label="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
1523
+			$input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '&nbsp;&nbsp;<span>' . $text . '</span>' : '';
1524
+			$input_html .= "\n\t\t\t\t\t" . '</label>';
1525
+			if (! empty($desc) && $desc != $text) {
1526
+				$input_html .= "\n\t\t\t\t\t"
1527
+							   . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'
1528
+							   . $desc
1529
+							   . '</div>';
1530
+			}
1531
+			$input_html .= "\n\t\t\t\t" . '</li>';
1532
+		}
1533
+
1534
+		$input_html .= "\n\t\t\t" . '</ul>';
1535
+
1536
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1537
+		return $label_html . $input_html;
1538
+	}
1539
+
1540
+
1541
+	/**
1542
+	 * generates HTML for a form datepicker input
1543
+	 *
1544
+	 * @param string $question    label content
1545
+	 * @param string $answer      form input value attribute
1546
+	 * @param string $name        form input name attribute
1547
+	 * @param string $id          form input css id attribute
1548
+	 * @param string $class       form input css class attribute
1549
+	 * @param array  $required    'label', 'class', and 'msg' - array of values for required "label" content, css
1550
+	 *                            required 'class', and required 'msg' attribute
1551
+	 * @param string $label_class css class attribute for the label
1552
+	 * @param string $disabled    disabled="disabled" or null
1553
+	 * @return string HTML
1554
+	 */
1555
+	public static function datepicker(
1556
+		$question = false,
1557
+		$answer = null,
1558
+		$name = false,
1559
+		$id = '',
1560
+		$class = '',
1561
+		$required = false,
1562
+		$required_text = '',
1563
+		$label_class = '',
1564
+		$disabled = false,
1565
+		$system_ID = false,
1566
+		$use_html_entities = true,
1567
+		$add_mobile_label = false
1568
+	) {
1569
+		// need these
1570
+		if (! $question || ! $name) {
1571
+			return null;
1572
+		}
1573
+		// prep the answer
1574
+		$answer = is_array($answer) ? '' : self::prep_answer($answer, $use_html_entities);
1575
+		// prep the required array
1576
+		$required = self::prep_required($required);
1577
+		// set disabled tag
1578
+		$disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1579
+		// ya gots ta have style man!!!
1580
+		$txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1581
+		$class     = empty($class) ? $txt_class : $class;
1582
+		$class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1583
+		$class = self::appendInputSizeClass($class, $answer);
1584
+		$extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1585
+
1586
+		$label_html   = self::label($question, $required_text, $required['label'], '', $label_class);
1587
+		$mobile_label = self::mobileLabel(
1588
+			$add_mobile_label,
1589
+			$question,
1590
+			$required_text,
1591
+			$required['label'],
1592
+			$label_class,
1593
+			$name
1594
+		);
1595
+
1596
+		$input_html = $mobile_label
1597
+			. '<input type="text" name="' . $name . '" id="' . $id . '" '
1598
+			. 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  '
1599
+			. 'aria-label="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1600
+
1601
+		// enqueue scripts
1602
+		wp_register_style(
1603
+			'espresso-ui-theme',
1604
+			EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1605
+			[],
1606
+			EVENT_ESPRESSO_VERSION
1607
+		);
1608
+		wp_enqueue_style('espresso-ui-theme');
1609
+		wp_enqueue_script('jquery-ui-datepicker');
1610
+
1611
+		$input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1612
+		return $label_html . $input_html;
1613
+	}
1614
+
1615
+
1616
+	/**
1617
+	 *  remove_label_keep_required_msg
1618
+	 *  this will strip out a form input's label HTML while keeping the required text HTML that MUST be before the label
1619
+	 *
1620
+	 * @access public
1621
+	 * @return     string
1622
+	 */
1623
+	public static function remove_label_keep_required_msg($label_html, $required_text)
1624
+	{
1625
+		return $required_text;
1626
+	}
1627
+
1628
+
1629
+	/**
1630
+	 * Simply returns the HTML for a hidden input of the given name and value.
1631
+	 *
1632
+	 * @param string $name
1633
+	 * @param string $value
1634
+	 * @return string HTML
1635
+	 */
1636
+	public static function hidden_input($name, $value, $id = '')
1637
+	{
1638
+		$id = ! empty($id) ? $id : $name;
1639
+		return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>';
1640
+	}
1641
+
1642
+
1643
+	/**
1644
+	 * prep_question
1645
+	 *
1646
+	 * @param string $question
1647
+	 * @return string
1648
+	 */
1649
+	public static function prep_question($question)
1650
+	{
1651
+		return $question;
1652
+	}
1653
+
1654
+
1655
+	/**
1656
+	 *  prep_answer
1657
+	 *
1658
+	 * @param mixed $answer
1659
+	 * @return string
1660
+	 */
1661
+	public static function prep_answer($answer, $use_html_entities = true)
1662
+	{
1663
+		// make sure we convert bools first.  Otherwise (bool) false becomes an empty string which is NOT desired,
1664
+		// we want "0".
1665
+		if (is_bool($answer)) {
1666
+			$answer = $answer ? 1 : 0;
1667
+		}
1668
+		$answer = trim(stripslashes(str_replace('&#039;', "'", $answer)));
1669
+		return $use_html_entities ? htmlentities($answer, ENT_QUOTES, 'UTF-8') : $answer;
1670
+	}
1671
+
1672
+
1673
+	/**
1674
+	 *  prep_answer_options
1675
+	 *
1676
+	 * @param array $QSOs array of EE_Question_Option objects
1677
+	 * @return array
1678
+	 */
1679
+	public static function prep_answer_options($QSOs = [])
1680
+	{
1681
+		$prepped_answer_options = [];
1682
+		if (is_array($QSOs) && ! empty($QSOs)) {
1683
+			foreach ($QSOs as $key => $QSO) {
1684
+				if (! $QSO instanceof EE_Question_Option) {
1685
+					$QSO = EE_Question_Option::new_instance(
1686
+						[
1687
+							'QSO_value' => is_array($QSO) && isset($QSO['id'])
1688
+								? (string) $QSO['id']
1689
+								: (string) $key,
1690
+							'QSO_desc'  => is_array($QSO) && isset($QSO['text'])
1691
+								? (string) $QSO['text']
1692
+								: (string) $QSO,
1693
+						]
1694
+					);
1695
+				}
1696
+				if ($QSO->opt_group()) {
1697
+					$prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1698
+				} else {
1699
+					$prepped_answer_options[] = $QSO;
1700
+				}
1701
+			}
1702
+		}
1703
+		//      d( $prepped_answer_options );
1704
+		return $prepped_answer_options;
1705
+	}
1706
+
1707
+
1708
+	/**
1709
+	 *  prep_option_value
1710
+	 *
1711
+	 * @param string $option_value
1712
+	 * @return string
1713
+	 */
1714
+	public static function prep_option_value($option_value)
1715
+	{
1716
+		return esc_attr(trim(stripslashes($option_value)));
1717
+	}
1718
+
1719
+
1720
+	/**
1721
+	 *  prep_required
1722
+	 *
1723
+	 * @param string|array $required
1724
+	 * @return array
1725
+	 */
1726
+	public static function prep_required($required = [])
1727
+	{
1728
+		// make sure required is an array
1729
+		$required = is_array($required) ? $required : [];
1730
+		// and set some defaults
1731
+		return array_merge(['label' => '', 'class' => '', 'msg' => ''], $required);
1732
+	}
1733
+
1734
+
1735
+	/**
1736
+	 *  get_label_size_class
1737
+	 *
1738
+	 * @param string $value
1739
+	 * @return string
1740
+	 */
1741
+	public static function get_label_size_class($value = false)
1742
+	{
1743
+		if ($value === false || $value === '') {
1744
+			return ' class="medium-lbl"';
1745
+		}
1746
+		// determine length of option value
1747
+		$val_size = strlen($value);
1748
+		switch ($val_size) {
1749
+			case $val_size < 3:
1750
+				$size = ' class="nano-lbl"';
1751
+				break;
1752
+			case $val_size < 6:
1753
+				$size = ' class="micro-lbl"';
1754
+				break;
1755
+			case $val_size < 12:
1756
+				$size = ' class="tiny-lbl"';
1757
+				break;
1758
+			case $val_size < 25:
1759
+				$size = ' class="small-lbl"';
1760
+				break;
1761
+			case $val_size > 100:
1762
+				$size = ' class="big-lbl"';
1763
+				break;
1764
+			default:
1765
+				$size = ' class="medium-lbl"';
1766
+				break;
1767
+		}
1768
+		return $size;
1769
+	}
1770
+
1771
+
1772
+	/**
1773
+	 *  _load_system_dropdowns
1774
+	 *
1775
+	 * @param EE_Question_Form_Input $QFI
1776
+	 * @return array
1777
+	 * @throws EE_Error
1778
+	 * @throws ReflectionException
1779
+	 */
1780
+	private static function _load_system_dropdowns($QFI)
1781
+	{
1782
+		$QST_system = $QFI->get('QST_system');
1783
+		switch ($QST_system) {
1784
+			case 'state':
1785
+				$QFI = self::generate_state_dropdown($QFI);
1786
+				break;
1787
+			case 'country':
1788
+				$QFI = self::generate_country_dropdown($QFI);
1789
+				break;
1790
+			case 'admin-state':
1791
+				$QFI = self::generate_state_dropdown($QFI, true);
1792
+				break;
1793
+			case 'admin-country':
1794
+				$QFI = self::generate_country_dropdown($QFI, true);
1795
+				break;
1796
+		}
1797
+		return $QFI;
1798
+	}
1799
+
1800
+
1801
+	/**
1802
+	 * This preps dropdowns that are specialized.
1803
+	 *
1804
+	 * @param EE_Question_Form_Input $QFI
1805
+	 *
1806
+	 * @return EE_Question_Form_Input
1807
+	 * @throws EE_Error
1808
+	 * @throws ReflectionException
1809
+	 * @since  4.6.0
1810
+	 */
1811
+	protected static function _load_specialized_dropdowns($QFI)
1812
+	{
1813
+		switch ($QFI->get('QST_type')) {
1814
+			case 'STATE':
1815
+				$QFI = self::generate_state_dropdown($QFI);
1816
+				break;
1817
+			case 'COUNTRY':
1818
+				$QFI = self::generate_country_dropdown($QFI);
1819
+				break;
1820
+		}
1821
+		return $QFI;
1822
+	}
1823
+
1824
+
1825
+	/**
1826
+	 *    generate_state_dropdown
1827
+	 *
1828
+	 * @param EE_Question_Form_Input $QST
1829
+	 * @param bool                   $get_all
1830
+	 * @return EE_Question_Form_Input
1831
+	 * @throws EE_Error
1832
+	 * @throws ReflectionException
1833
+	 */
1834
+	public static function generate_state_dropdown($QST, $get_all = false)
1835
+	{
1836
+		$states = $get_all
1837
+			? EEM_State::instance()->get_all_states()
1838
+			: EEM_State::instance()->get_all_states_of_active_countries();
1839
+		if ($states && count($states) != count($QST->options())) {
1840
+			$QST->set('QST_type', 'DROPDOWN');
1841
+			// if multiple countries, we'll create option groups within the dropdown
1842
+			foreach ($states as $state) {
1843
+				if ($state instanceof EE_State) {
1844
+					$QSO = EE_Question_Option::new_instance(
1845
+						[
1846
+							'QSO_value'   => $state->ID(),
1847
+							'QSO_desc'    => $state->name(),
1848
+							'QST_ID'      => $QST->get('QST_ID'),
1849
+							'QSO_deleted' => false,
1850
+						]
1851
+					);
1852
+					// set option group
1853
+					$QSO->set_opt_group($state->country()->name());
1854
+					// add option to question
1855
+					$QST->add_temp_option($QSO);
1856
+				}
1857
+			}
1858
+		}
1859
+		return $QST;
1860
+	}
1861
+
1862
+
1863
+	/**
1864
+	 *    generate_country_dropdown
1865
+	 *
1866
+	 * @param      $QST
1867
+	 * @param bool $get_all
1868
+	 * @return array
1869
+	 * @throws EE_Error
1870
+	 * @throws ReflectionException
1871
+	 * @internal param array $question
1872
+	 */
1873
+	public static function generate_country_dropdown($QST, $get_all = false)
1874
+	{
1875
+		$countries = $get_all
1876
+			? EEM_Country::instance()->get_all_countries()
1877
+			: EEM_Country::instance()->get_all_active_countries();
1878
+		if ($countries && count($countries) != count($QST->options())) {
1879
+			$QST->set('QST_type', 'DROPDOWN');
1880
+			// now add countries
1881
+			foreach ($countries as $country) {
1882
+				if ($country instanceof EE_Country) {
1883
+					$QSO = EE_Question_Option::new_instance(
1884
+						[
1885
+							'QSO_value'   => $country->ID(),
1886
+							'QSO_desc'    => $country->name(),
1887
+							'QST_ID'      => $QST->get('QST_ID'),
1888
+							'QSO_deleted' => false,
1889
+						]
1890
+					);
1891
+					$QST->add_temp_option($QSO);
1892
+				}
1893
+			}
1894
+		}
1895
+		return $QST;
1896
+	}
1897
+
1898
+
1899
+	/**
1900
+	 *  generates options for a month dropdown selector with numbers from 01 to 12
1901
+	 *
1902
+	 * @return array()
1903
+	 */
1904
+	public static function two_digit_months_dropdown_options()
1905
+	{
1906
+		$options = [];
1907
+		for ($x = 1; $x <= 12; $x++) {
1908
+			$mm             = str_pad($x, 2, '0', STR_PAD_LEFT);
1909
+			$options[ $mm ] = $mm;
1910
+		}
1911
+		return EEH_Form_Fields::prep_answer_options($options);
1912
+	}
1913
+
1914
+
1915
+	/**
1916
+	 *  generates a year dropdown selector with numbers for the next ten years
1917
+	 *
1918
+	 * @return array
1919
+	 */
1920
+	public static function next_decade_two_digit_year_dropdown_options()
1921
+	{
1922
+		$options      = [];
1923
+		$current_year = date('y');
1924
+		$next_decade  = $current_year + 10;
1925
+		for ($x = $current_year; $x <= $next_decade; $x++) {
1926
+			$yy             = str_pad($x, 2, '0', STR_PAD_LEFT);
1927
+			$options[ $yy ] = $yy;
1928
+		}
1929
+		return EEH_Form_Fields::prep_answer_options($options);
1930
+	}
1931
+
1932
+
1933
+	/**
1934
+	 * generates a month/year dropdown selector for all registrations matching the given criteria.  Typically used for
1935
+	 * list table filter.
1936
+	 *
1937
+	 * @param string  $cur_date     any currently selected date can be entered here.
1938
+	 * @param string  $status       Registration status
1939
+	 * @param integer $evt_category Event Category ID if the Event Category filter is selected
1940
+	 * @return string                html
1941
+	 * @throws EE_Error
1942
+	 */
1943
+	public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1944
+	{
1945
+		$_where = [];
1946
+		if (! empty($status)) {
1947
+			$_where['STS_ID'] = $status;
1948
+		}
1949
+
1950
+		if ($evt_category > 0) {
1951
+			$_where['Event.Term_Taxonomy.term_id'] = $evt_category;
1952
+		}
1953
+
1954
+		$regdtts = EEM_Registration::instance()->get_reg_months_and_years($_where);
1955
+
1956
+		// setup vals for select input helper
1957
+		$options = [
1958
+			0 => [
1959
+				'text' => esc_html__('Select a Month/Year', 'event_espresso'),
1960
+				'id'   => '',
1961
+			],
1962
+		];
1963
+
1964
+		foreach ($regdtts as $regdtt) {
1965
+			$date      = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1966
+			$options[] = [
1967
+				'text' => $date,
1968
+				'id'   => $date,
1969
+			];
1970
+		}
1971
+
1972
+		return self::select_input('month_range', $options, $cur_date);
1973
+	}
1974
+
1975
+
1976
+	/**
1977
+	 * generates a month/year dropdown selector for all events matching the given criteria
1978
+	 * Typically used for list table filter
1979
+	 *
1980
+	 * @param string $cur_date          any currently selected date can be entered here.
1981
+	 * @param string $status            "view" (i.e. all, today, month, draft)
1982
+	 * @param int    $evt_category      category event belongs to
1983
+	 * @param string $evt_active_status "upcoming", "expired", "active", or "inactive"
1984
+	 * @return string                    html
1985
+	 * @throws EE_Error
1986
+	 */
1987
+	public static function generate_event_months_dropdown(
1988
+		$cur_date = '',
1989
+		$status = null,
1990
+		$evt_category = null,
1991
+		$evt_active_status = null
1992
+	) {
1993
+		// determine what post_status our condition will have for the query.
1994
+		// phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment
1995
+		switch ($status) {
1996
+			case 'month':
1997
+			case 'today':
1998
+			case null:
1999
+			case 'all':
2000
+				$where['Event.status'] = ['NOT IN', ['trash']];
2001
+				break;
2002
+			case 'draft':
2003
+				$where['Event.status'] = ['IN', ['draft', 'auto-draft']];
2004
+				break;
2005
+			default:
2006
+				$where['Event.status'] = $status;
2007
+		}
2008
+
2009
+		// phpcs:enable
2010
+
2011
+		// categories?
2012
+
2013
+
2014
+		if (! empty($evt_category)) {
2015
+			$where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
2016
+			$where['Event.Term_Taxonomy.term_id']  = $evt_category;
2017
+		}
2018
+
2019
+
2020
+		//      $where['DTT_is_primary'] = 1;
2021
+
2022
+		$DTTS = EEM_Datetime::instance()->get_dtt_months_and_years($where, $evt_active_status);
2023
+
2024
+		// let's setup vals for select input helper
2025
+		$options = [
2026
+			0 => [
2027
+				'text' => esc_html__('Select a Month/Year', 'event_espresso'),
2028
+				'id'   => "",
2029
+			],
2030
+		];
2031
+
2032
+
2033
+		// translate month and date
2034
+		global $wp_locale;
2035
+
2036
+		foreach ($DTTS as $DTT) {
2037
+			$localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
2038
+			$id             = $DTT->dtt_month . ' ' . $DTT->dtt_year;
2039
+			$options[]      = [
2040
+				'text' => $localized_date,
2041
+				'id'   => $id,
2042
+			];
2043
+		}
2044
+
2045
+
2046
+		return self::select_input('month_range', $options, $cur_date);
2047
+	}
2048
+
2049
+
2050
+	/**
2051
+	 * generates the dropdown selector for event categories
2052
+	 * typically used as a filter on list tables.
2053
+	 *
2054
+	 * @param integer $current_cat currently selected category
2055
+	 * @return string               html for dropdown
2056
+	 * @throws EE_Error
2057
+	 * @throws ReflectionException
2058
+	 */
2059
+	public static function generate_event_category_dropdown($current_cat = -1)
2060
+	{
2061
+		$categories = EEM_Term::instance()->get_all_ee_categories(true);
2062
+		$options    = [
2063
+			'0' => [
2064
+				'text' => esc_html__('All Categories', 'event_espresso'),
2065
+				'id'   => -1,
2066
+			],
2067
+		];
2068
+
2069
+		// setup categories for dropdown
2070
+		foreach ($categories as $category) {
2071
+			$options[] = [
2072
+				'text' => $category->get('name'),
2073
+				'id'   => $category->ID(),
2074
+			];
2075
+		}
2076
+
2077
+		return self::select_input('EVT_CAT', $options, $current_cat);
2078
+	}
2079
+
2080
+
2081
+	/**
2082
+	 *    generate a submit button with or without it's own microform
2083
+	 *    this is the only way to create buttons that are compatible across all themes
2084
+	 *
2085
+	 * @access    public
2086
+	 * @param string      $url              - the form action
2087
+	 * @param string      $ID               - some kind of unique ID, appended with "-sbmt" for the input and "-frm"
2088
+	 *                                      for the form
2089
+	 * @param string      $class            - css classes (separated by spaces if more than one)
2090
+	 * @param string      $text             - what appears on the button
2091
+	 * @param string      $nonce_action     - if using nonces
2092
+	 * @param bool|string $input_only       - whether to print form header and footer. TRUE returns the input without
2093
+	 *                                      the form
2094
+	 * @param string      $extra_attributes - any extra attributes that need to be attached to the form input
2095
+	 * @return    string
2096
+	 */
2097
+	public static function submit_button(
2098
+		$url = '',
2099
+		$ID = '',
2100
+		$class = '',
2101
+		$text = '',
2102
+		$nonce_action = '',
2103
+		$input_only = false,
2104
+		$extra_attributes = ''
2105
+	) {
2106
+		$btn = '';
2107
+		if (empty($url) || empty($ID)) {
2108
+			return $btn;
2109
+		}
2110
+		$text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso');
2111
+		$btn  .= '<input id="' . $ID . '-btn" class="' . $class . '" '
2112
+				 . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
2113
+		if (! $input_only) {
2114
+			$btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
2115
+			$btn_frm .= ! empty($nonce_action)
2116
+				? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false)
2117
+				: '';
2118
+			$btn_frm .= $btn;
2119
+			$btn_frm .= '</form>';
2120
+			$btn     = $btn_frm;
2121
+			unset($btn_frm);
2122
+		}
2123
+		return $btn;
2124
+	}
2125 2125
 }
Please login to merge, or discard this patch.
Spacing   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
             $type           = $input_value['input'];
109 109
             $value          = $input_value['value'];
110 110
 
111
-            $id    = $form_id ? $form_id . '-' . $input_key : $input_key;
112
-            $class = $required ? 'required ' . $css_class : $css_class;
111
+            $id    = $form_id ? $form_id.'-'.$input_key : $input_key;
112
+            $class = $required ? 'required '.$css_class : $css_class;
113 113
 
114 114
             // what type of input are we dealing with ?
115 115
             switch ($type) {
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
             }
162 162
         } // end foreach( $input_vars as $input_key => $input_value )
163 163
 
164
-        if (! empty($inputs)) {
165
-            $glue   = "
164
+        if ( ! empty($inputs)) {
165
+            $glue = "
166 166
                 </li>
167 167
                 <li>
168 168
                     ";
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             </ul>
176 176
             ";
177 177
         }
178
-        return $output . implode("\n", $hidden_inputs);
178
+        return $output.implode("\n", $hidden_inputs);
179 179
     }
180 180
 
181 181
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
             // generate label
257 257
             $label = ! empty($label) ? self::adminLabel($id, $label, $required) : '';
258 258
             // generate field name
259
-            $name = ! empty($unique_id) ? $field_name . '[' . $unique_id . ']' : $field_name;
259
+            $name = ! empty($unique_id) ? $field_name.'['.$unique_id.']' : $field_name;
260 260
 
261 261
             // we determine what we're building based on the type
262 262
             switch ($type) {
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
                         foreach ($value as $key => $val) {
268 268
                             $c_input .= self::adminMulti(
269 269
                                 $default,
270
-                                isset($classes[ $key ]) ? $classes[ $key ] : '',
271
-                                $field_name . '_' . $value,
270
+                                isset($classes[$key]) ? $classes[$key] : '',
271
+                                $field_name.'_'.$value,
272 272
                                 $name,
273 273
                                 $required,
274 274
                                 $tab_index,
275 275
                                 $type,
276 276
                                 $val,
277
-                                isset($labels[ $key ]) ? $labels[ $key ] : ''
277
+                                isset($labels[$key]) ? $labels[$key] : ''
278 278
                             );
279 279
                         }
280 280
                         $field = $c_input;
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
                 case 'select':
301 301
                     $options = [];
302 302
                     foreach ($value as $key => $val) {
303
-                        $options[ $val ] = isset($labels[ $key ]) ? $labels[ $key ] : '';
303
+                        $options[$val] = isset($labels[$key]) ? $labels[$key] : '';
304 304
                     }
305 305
                     $field = self::adminSelect($default, $class, $id, $name, $required, $tab_index, $options);
306 306
                     break;
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
                     $field = self::adminText($class, $id, $name, $required, $tab_index, $value);
327 327
             }
328 328
 
329
-            $form_fields[ $field_name ] = ['label' => $label, 'field' => $field . $extra_desc];
329
+            $form_fields[$field_name] = ['label' => $label, 'field' => $field.$extra_desc];
330 330
         }
331 331
 
332 332
         return $form_fields;
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
         }
396 396
         $label = esc_html($label);
397 397
         $label_class = self::appendInputSizeClass('', $label);
398
-        $label_class = $label_class ? ' class="' . $label_class . '"' : '';
398
+        $label_class = $label_class ? ' class="'.$label_class.'"' : '';
399 399
         return "
400 400
         <label for='$id'{$label_class}>
401 401
             {$input}
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
         $autosize = true
545 545
     ) {
546 546
         // if $values was submitted in the wrong format, convert it over
547
-        if (! empty($values) && (! array_key_exists(0, $values) || ! is_array($values[0]))) {
547
+        if ( ! empty($values) && ( ! array_key_exists(0, $values) || ! is_array($values[0]))) {
548 548
             $converted_values = [];
549 549
             foreach ($values as $id => $text) {
550 550
                 $converted_values[] = ['id' => $id, 'text' => $text];
@@ -553,19 +553,19 @@  discard block
 block discarded – undo
553 553
         }
554 554
 
555 555
         $field =
556
-            '<select id="' . EEH_Formatter::ee_tep_output_string($name)
557
-            . '" name="' . EEH_Formatter::ee_tep_output_string($name)
556
+            '<select id="'.EEH_Formatter::ee_tep_output_string($name)
557
+            . '" name="'.EEH_Formatter::ee_tep_output_string($name)
558 558
             . '"';
559 559
 
560 560
         if (EEH_Formatter::ee_tep_not_null($parameters)) {
561
-            $field .= ' ' . $parameters;
561
+            $field .= ' '.$parameters;
562 562
         }
563 563
         $class = $autosize ? self::appendInputSizeClass($class, $values) : '';
564 564
 
565
-        $field .= ' class="' . $class . '">';
565
+        $field .= ' class="'.$class.'">';
566 566
 
567
-        if (empty($default) && isset($GLOBALS[ $name ])) {
568
-            $default = stripslashes($GLOBALS[ $name ]);
567
+        if (empty($default) && isset($GLOBALS[$name])) {
568
+            $default = stripslashes($GLOBALS[$name]);
569 569
         }
570 570
 
571 571
         $field .= self::selectInputOption($values, $default);
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
             $id = is_scalar($values['id']) ? $values['id'] : '';
582 582
             $text = is_scalar($values['text']) ? $values['text'] : '';
583 583
             $selected = $default == $values['id'] ? ' selected = "selected"' : '';
584
-            $html_class = isset($values['class']) ? ' class="' . $values['class'] . '"' : '';
584
+            $html_class = isset($values['class']) ? ' class="'.$values['class'].'"' : '';
585 585
             return "<option value='{$id}'{$selected}{$html_class}>{$text}</option>";
586 586
         }
587 587
         $options = '';
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
             return $chars;
612 612
         }
613 613
         // not a primitive? return something big
614
-        if (! is_scalar($value)) {
614
+        if ( ! is_scalar($value)) {
615 615
             return 500;
616 616
         }
617 617
         return strlen((string) $value);
@@ -661,11 +661,11 @@  discard block
 block discarded – undo
661 661
         $after_question_group_questions  =
662 662
             apply_filters('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', '');
663 663
 
664
-        if (! empty($question_groups)) {
664
+        if ( ! empty($question_groups)) {
665 665
             // loop thru question groups
666 666
             foreach ($question_groups as $QSG) {
667 667
                 // check that questions exist
668
-                if (! empty($QSG['QSG_questions'])) {
668
+                if ( ! empty($QSG['QSG_questions'])) {
669 669
                     // use fieldsets
670 670
                     $html .= "\n\t"
671 671
                              . '<'
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
                     $html .= $before_question_group_questions;
691 691
                     // loop thru questions
692 692
                     foreach ($QSG['QSG_questions'] as $question) {
693
-                        $QFI  = new EE_Question_Form_Input(
693
+                        $QFI = new EE_Question_Form_Input(
694 694
                             $question['qst_obj'],
695 695
                             $question['ans_obj'],
696 696
                             $question
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
                         $html .= self::generate_form_input($QFI);
699 699
                     }
700 700
                     $html .= $after_question_group_questions;
701
-                    $html .= "\n\t" . '</' . $group_wrapper . '>';
701
+                    $html .= "\n\t".'</'.$group_wrapper.'>';
702 702
                 }
703 703
             }
704 704
         }
@@ -738,25 +738,25 @@  discard block
 block discarded – undo
738 738
             'input_id'    => '',
739 739
             'input_class' => '',
740 740
         ];
741
-        $q_meta         = array_merge($default_q_meta, $q_meta);
741
+        $q_meta = array_merge($default_q_meta, $q_meta);
742 742
 
743
-        if (! empty($question_groups)) {
743
+        if ( ! empty($question_groups)) {
744 744
             // loop thru question groups
745 745
             foreach ($question_groups as $QSG) {
746 746
                 if ($QSG instanceof EE_Question_Group) {
747 747
                     // check that questions exist
748 748
 
749 749
                     $where = ['QST_deleted' => 0];
750
-                    if (! $from_admin) {
750
+                    if ( ! $from_admin) {
751 751
                         $where['QST_admin_only'] = 0;
752 752
                     }
753 753
                     $questions =
754 754
                         $QSG->questions([$where, 'order_by' => ['Question_Group_Question.QGQ_order' => 'ASC']]);
755
-                    if (! empty($questions)) {
755
+                    if ( ! empty($questions)) {
756 756
                         // use fieldsets
757 757
                         $html .= "\n\t"
758
-                                 . '<' . $group_wrapper . ' class="espresso-question-group-wrap" '
759
-                                 . 'id="' . $QSG->get('QSG_identifier') . '">';
758
+                                 . '<'.$group_wrapper.' class="espresso-question-group-wrap" '
759
+                                 . 'id="'.$QSG->get('QSG_identifier').'">';
760 760
                         // group_name
761 761
                         if ($QSG->show_group_name()) {
762 762
                             $html .= "\n\t\t"
@@ -781,21 +781,21 @@  discard block
 block discarded – undo
781 781
                             /** @var RequestInterface $request */
782 782
                             $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
783 783
                             $request_qstn = $request->getRequestParam('qstn', [], 'string', true);
784
-                            if (! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
784
+                            if ( ! empty($request_qstn) && isset($q_meta['input_id']) && isset($q_meta['att_nmbr'])) {
785 785
                                 // check for answer in $request_qstn in case we are reprocessing a form after an error
786
-                                if (isset($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])) {
787
-                                    $answer = is_array($request_qstn[ $q_meta['input_id'] ][ $qstn_id ])
788
-                                        ? $request_qstn[ $q_meta['input_id'] ][ $qstn_id ]
789
-                                        : sanitize_text_field($request_qstn[ $q_meta['input_id'] ][ $qstn_id ]);
786
+                                if (isset($request_qstn[$q_meta['input_id']][$qstn_id])) {
787
+                                    $answer = is_array($request_qstn[$q_meta['input_id']][$qstn_id])
788
+                                        ? $request_qstn[$q_meta['input_id']][$qstn_id]
789
+                                        : sanitize_text_field($request_qstn[$q_meta['input_id']][$qstn_id]);
790 790
                                 }
791 791
                             } elseif (isset($q_meta['attendee']) && $q_meta['attendee']) {
792 792
                                 // attendee data from the session
793 793
                                 $answer =
794
-                                    isset($q_meta['attendee'][ $qstn_id ]) ? $q_meta['attendee'][ $qstn_id ] : null;
794
+                                    isset($q_meta['attendee'][$qstn_id]) ? $q_meta['attendee'][$qstn_id] : null;
795 795
                             }
796 796
 
797 797
 
798
-                            $QFI  = new EE_Question_Form_Input(
798
+                            $QFI = new EE_Question_Form_Input(
799 799
                                 $QST,
800 800
                                 EE_Answer::new_instance(
801 801
                                     [
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
                             $html .= self::generate_form_input($QFI);
811 811
                         }
812 812
                         $html .= $after_question_group_questions;
813
-                        $html .= "\n\t" . '</' . $group_wrapper . '>';
813
+                        $html .= "\n\t".'</'.$group_wrapper.'>';
814 814
                     }
815 815
                 }
816 816
             }
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
             $QFI->get('QST_required_text') != ''
859 859
                 ? $QFI->get('QST_required_text')
860 860
                 : esc_html__('This field is required', 'event_espresso');
861
-        $required_text     = $QST_required
861
+        $required_text = $QST_required
862 862
             ? "\n\t\t\t"
863 863
               . '<div class="required-text hidden">'
864 864
               . self::prep_answer($required_text, $use_html_entities)
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
     ): string {
995 995
         $for   = ! empty($name) ? " for='{$name}'" : '';
996 996
         $class = ! empty($label_class) ? " class='{$label_class}'" : '';
997
-        $label = self::prep_question($question) . $required_label;
997
+        $label = self::prep_question($question).$required_label;
998 998
         $label_html = "
999 999
             {$required_text}
1000 1000
             <label{$for}{$class}>{$label}</label>";
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
         $extra_attributes = ''
1051 1051
     ) {
1052 1052
         // need these
1053
-        if (! $question || ! $name) {
1053
+        if ( ! $question || ! $name) {
1054 1054
             return null;
1055 1055
         }
1056 1056
         // prep the answer
@@ -1062,9 +1062,9 @@  discard block
 block discarded – undo
1062 1062
         // ya gots ta have style man!!!
1063 1063
         $txt_class = is_admin() ? 'regular-text' : 'espresso-text-inp';
1064 1064
         $class     = empty($class) ? $txt_class : $class;
1065
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1065
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1066 1066
         $class = self::appendInputSizeClass($class, $answer);
1067
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1067
+        $class .= ! empty($required['class']) ? ' '.$required['class'] : '';
1068 1068
         $extra_attributes = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', $extra_attributes);
1069 1069
 
1070 1070
         $label_html = self::label($question, $required_text, $required['label'], $name, $label_class);
@@ -1077,18 +1077,18 @@  discard block
 block discarded – undo
1077 1077
             $name
1078 1078
         );
1079 1079
 
1080
-        $input_html = $mobile_label . '
1080
+        $input_html = $mobile_label.'
1081 1081
             <input  type="text"
1082
-                    name="' . $name . '"
1083
-                    id="' . $id . '"
1084
-                    class="' . trim($class) . '"
1085
-                    value="' . esc_attr($answer) . '"
1086
-                    aria-label="' . esc_attr($required['msg']) . '"
1087
-                    ' . $disabled . ' ' . $extra_attributes . '
1082
+                    name="' . $name.'"
1083
+                    id="' . $id.'"
1084
+                    class="' . trim($class).'"
1085
+                    value="' . esc_attr($answer).'"
1086
+                    aria-label="' . esc_attr($required['msg']).'"
1087
+                    ' . $disabled.' '.$extra_attributes.'
1088 1088
             />';
1089 1089
 
1090 1090
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1091
-        return $label_html . $input_html;
1091
+        return $label_html.$input_html;
1092 1092
     }
1093 1093
 
1094 1094
 
@@ -1123,7 +1123,7 @@  discard block
 block discarded – undo
1123 1123
         $add_mobile_label = false
1124 1124
     ) {
1125 1125
         // need these
1126
-        if (! $question || ! $name) {
1126
+        if ( ! $question || ! $name) {
1127 1127
             return null;
1128 1128
         }
1129 1129
         // prep the answer
@@ -1137,9 +1137,9 @@  discard block
 block discarded – undo
1137 1137
         // set disabled tag
1138 1138
         $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1139 1139
         // ya gots ta have style man!!!
1140
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1141
-        $class     .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1142
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1140
+        $class     .= ! empty($system_ID) ? ' '.$system_ID : '';
1141
+        $class     .= ! empty($required['class']) ? ' '.$required['class'] : '';
1142
+        $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1143 1143
 
1144 1144
         $label_html   = self::label($question, $required_text, $required['label'], $name, $label_class);
1145 1145
         $mobile_label = self::mobileLabel(
@@ -1152,14 +1152,14 @@  discard block
 block discarded – undo
1152 1152
         );
1153 1153
 
1154 1154
         $input_html = $mobile_label
1155
-            . '<textarea name="' . $name . '" id="' . $id . '" class="' . trim($class) . '" '
1156
-            . 'rows="' . $dimensions['rows'] . '" cols="' . $dimensions['cols'] . '"  '
1157
-            . 'aria-label="' . $required['msg'] . '" ' . $disabled . ' ' . $extra . '>'
1155
+            . '<textarea name="'.$name.'" id="'.$id.'" class="'.trim($class).'" '
1156
+            . 'rows="'.$dimensions['rows'].'" cols="'.$dimensions['cols'].'"  '
1157
+            . 'aria-label="'.$required['msg'].'" '.$disabled.' '.$extra.'>'
1158 1158
              . esc_textarea($answer)
1159 1159
               . '</textarea>';
1160 1160
 
1161 1161
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1162
-        return $label_html . $input_html;
1162
+        return $label_html.$input_html;
1163 1163
     }
1164 1164
 
1165 1165
 
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
     ) {
1198 1198
 
1199 1199
         // need these
1200
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1200
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1201 1201
             return null;
1202 1202
         }
1203 1203
         // prep the answer
@@ -1209,9 +1209,9 @@  discard block
 block discarded – undo
1209 1209
         // set disabled tag
1210 1210
         $disabled = $answer === null || ! $disabled ? '' : ' disabled="disabled"';
1211 1211
         // ya gots ta have style man!!!
1212
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1212
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1213 1213
         $class = self::appendInputSizeClass($class, $options);
1214
-        $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1214
+        $extra = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1215 1215
 
1216 1216
         $label_html   = self::label($question, $required_text, $required['label'], $name, $label_class);
1217 1217
         $mobile_label = self::mobileLabel(
@@ -1224,16 +1224,16 @@  discard block
 block discarded – undo
1224 1224
         );
1225 1225
 
1226 1226
         $input_html = $mobile_label
1227
-            . '<select name="' . $name . '" id="' . $id . '" class="' . trim($class) . ' ' . $required['class'] . '" '
1228
-            . 'aria-label="' . esc_attr($required['msg']) . '"' . $disabled . ' ' . $extra . '>';
1227
+            . '<select name="'.$name.'" id="'.$id.'" class="'.trim($class).' '.$required['class'].'" '
1228
+            . 'aria-label="'.esc_attr($required['msg']).'"'.$disabled.' '.$extra.'>';
1229 1229
         // recursively count array elements, to determine total number of options
1230 1230
         $only_option = count($options, 1) == 1;
1231
-        if (! $only_option) {
1231
+        if ( ! $only_option) {
1232 1232
             // if there is NO answer set and there are multiple options to choose from, then set the "please select" message as selected
1233
-            $selected   = $answer === null ? ' selected' : '';
1233
+            $selected = $answer === null ? ' selected' : '';
1234 1234
             $input_html .= $add_please_select_option
1235 1235
                 ? "\n\t\t\t\t"
1236
-                  . '<option value=""' . $selected . '>'
1236
+                  . '<option value=""'.$selected.'>'
1237 1237
                   . esc_html__(' - please select - ', 'event_espresso')
1238 1238
                   . '</option>'
1239 1239
                 : '';
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
                 );
1257 1257
         }
1258 1258
 
1259
-        $input_html .= "\n\t\t\t" . '</select>';
1259
+        $input_html .= "\n\t\t\t".'</select>';
1260 1260
 
1261 1261
         $input_html =
1262 1262
             apply_filters(
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
             );
1272 1272
 
1273 1273
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1274
-        return $label_html . $input_html;
1274
+        return $label_html.$input_html;
1275 1275
     }
1276 1276
 
1277 1277
 
@@ -1289,11 +1289,11 @@  discard block
 block discarded – undo
1289 1289
      */
1290 1290
     private static function _generate_select_option_group($opt_group, $QSOs, $answer, $use_html_entities = true)
1291 1291
     {
1292
-        $html = "\n\t\t\t\t" . '<optgroup label="' . self::prep_option_value($opt_group) . '">';
1292
+        $html = "\n\t\t\t\t".'<optgroup label="'.self::prep_option_value($opt_group).'">';
1293 1293
         foreach ($QSOs as $QSO) {
1294 1294
             $html .= self::_generate_select_option($QSO->value(), $QSO->desc(), $answer, false, $use_html_entities);
1295 1295
         }
1296
-        $html .= "\n\t\t\t\t" . '</optgroup>';
1296
+        $html .= "\n\t\t\t\t".'</optgroup>';
1297 1297
         return $html;
1298 1298
     }
1299 1299
 
@@ -1320,7 +1320,7 @@  discard block
 block discarded – undo
1320 1320
         $value    = ! empty($value) ? $value : $key;
1321 1321
         $selected = ($answer == $key || $only_option) ? 'selected' : '';
1322 1322
         return "\n\t\t\t\t"
1323
-               . '<option value="' . self::prep_option_value($key) . '" ' . $selected . '> '
1323
+               . '<option value="'.self::prep_option_value($key).'" '.$selected.'> '
1324 1324
                . $value
1325 1325
                . '&nbsp;&nbsp;&nbsp;</option>';
1326 1326
     }
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
         $add_mobile_label = false
1366 1366
     ) {
1367 1367
         // need these
1368
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1368
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1369 1369
             return null;
1370 1370
         }
1371 1371
         // prep the answer
@@ -1389,49 +1389,49 @@  discard block
 block discarded – undo
1389 1389
         );
1390 1390
 
1391 1391
         $input_html = $mobile_label
1392
-            . '<ul id="' . $id . '-ul" class="espresso-radio-btn-options-ul ' . $class . '-ul">';
1392
+            . '<ul id="'.$id.'-ul" class="espresso-radio-btn-options-ul '.$class.'-ul">';
1393 1393
 
1394
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1395
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1394
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1395
+        $class .= ! empty($required['class']) ? ' '.$required['class'] : '';
1396 1396
 
1397 1397
         foreach ($options as $OPT) {
1398 1398
             if ($OPT instanceof EE_Question_Option) {
1399 1399
                 $value   = self::prep_option_value($OPT->value());
1400 1400
                 $label   = $use_desc_4_label ? $OPT->desc() : $OPT->value();
1401 1401
                 $size    = $use_desc_4_label
1402
-                    ? self::get_label_size_class($OPT->value() . ' ' . $OPT->desc())
1402
+                    ? self::get_label_size_class($OPT->value().' '.$OPT->desc())
1403 1403
                     : self::get_label_size_class($OPT->value());
1404
-                $desc    = $OPT->desc();// no self::prep_answer
1404
+                $desc    = $OPT->desc(); // no self::prep_answer
1405 1405
                 $answer  = is_numeric($value) && empty($answer) ? 0 : $answer;
1406 1406
                 $checked = (string) $value == (string) $answer ? ' checked' : '';
1407
-                $opt     = '-' . sanitize_key($value);
1407
+                $opt     = '-'.sanitize_key($value);
1408 1408
 
1409
-                $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1410
-                $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-radio-btn-lbl">';
1411
-                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $label . '</span>&nbsp;&nbsp;' : '';
1409
+                $input_html .= "\n\t\t\t\t".'<li'.$size.'>';
1410
+                $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-radio-btn-lbl">';
1411
+                $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$label.'</span>&nbsp;&nbsp;' : '';
1412 1412
                 $input_html .= "\n\t\t\t\t\t\t"
1413
-                               . '<input type="radio" name="' . $name . '" id="' . $id . $opt . '" '
1414
-                               . 'class="' . $class . '" value="' . $value . '" '
1415
-                               . 'aria-label="' . esc_attr($required['msg']) . '" ' . $disabled
1416
-                               . $checked . ' ' . $extra . '/>';
1413
+                               . '<input type="radio" name="'.$name.'" id="'.$id.$opt.'" '
1414
+                               . 'class="'.$class.'" value="'.$value.'" '
1415
+                               . 'aria-label="'.esc_attr($required['msg']).'" '.$disabled
1416
+                               . $checked.' '.$extra.'/>';
1417 1417
                 $input_html .= ! $label_b4
1418 1418
                     ? "\n\t\t\t\t\t\t"
1419 1419
                       . '&nbsp;&nbsp;<span class="espresso-radio-btn-desc">'
1420 1420
                       . $label
1421 1421
                       . '</span>'
1422 1422
                     : '';
1423
-                $input_html .= "\n\t\t\t\t\t" . '</label>';
1423
+                $input_html .= "\n\t\t\t\t\t".'</label>';
1424 1424
                 $input_html .= $use_desc_4_label
1425 1425
                     ? ''
1426
-                    : '<span class="espresso-radio-btn-option-desc small-text grey-text">' . $desc . '</span>';
1427
-                $input_html .= "\n\t\t\t\t" . '</li>';
1426
+                    : '<span class="espresso-radio-btn-option-desc small-text grey-text">'.$desc.'</span>';
1427
+                $input_html .= "\n\t\t\t\t".'</li>';
1428 1428
             }
1429 1429
         }
1430 1430
 
1431
-        $input_html .= "\n\t\t\t" . '</ul>';
1431
+        $input_html .= "\n\t\t\t".'</ul>';
1432 1432
 
1433 1433
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1434
-        return $label_html . $input_html;
1434
+        return $label_html.$input_html;
1435 1435
     }
1436 1436
 
1437 1437
 
@@ -1467,7 +1467,7 @@  discard block
 block discarded – undo
1467 1467
         $add_mobile_label = false
1468 1468
     ) {
1469 1469
         // need these
1470
-        if (! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1470
+        if ( ! $question || ! $name || ! $options || empty($options) || ! is_array($options)) {
1471 1471
             return null;
1472 1472
         }
1473 1473
         $answer = maybe_unserialize($answer);
@@ -1477,7 +1477,7 @@  discard block
 block discarded – undo
1477 1477
 
1478 1478
         foreach ($answer as $key => $value) {
1479 1479
             $key            = self::prep_option_value($key);
1480
-            $answer[ $key ] = self::prep_answer($value, $use_html_entities);
1480
+            $answer[$key] = self::prep_answer($value, $use_html_entities);
1481 1481
         }
1482 1482
 
1483 1483
         // prep the required array
@@ -1499,42 +1499,42 @@  discard block
 block discarded – undo
1499 1499
         );
1500 1500
 
1501 1501
         $input_html = $mobile_label
1502
-            . '<ul id="' . $id . '-ul" class="espresso-checkbox-options-ul ' . $class . '-ul">';
1502
+            . '<ul id="'.$id.'-ul" class="espresso-checkbox-options-ul '.$class.'-ul">';
1503 1503
 
1504
-        $class .= ! empty($system_ID) ? ' ' . $system_ID : '';
1505
-        $class .= ! empty($required['class']) ? ' ' . $required['class'] : '';
1504
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1505
+        $class .= ! empty($required['class']) ? ' '.$required['class'] : '';
1506 1506
 
1507 1507
         foreach ($options as $OPT) {
1508
-            $value = $OPT->value();// self::prep_option_value( $OPT->value() );
1509
-            $size  = self::get_label_size_class($OPT->value() . ' ' . $OPT->desc());
1508
+            $value = $OPT->value(); // self::prep_option_value( $OPT->value() );
1509
+            $size  = self::get_label_size_class($OPT->value().' '.$OPT->desc());
1510 1510
             $text  = self::prep_answer($OPT->value());
1511 1511
             $desc  = $OPT->desc();
1512
-            $opt   = '-' . sanitize_key($value);
1512
+            $opt   = '-'.sanitize_key($value);
1513 1513
 
1514 1514
             $checked = is_array($answer) && in_array($text, $answer) ? ' checked' : '';
1515 1515
 
1516
-            $input_html .= "\n\t\t\t\t" . '<li' . $size . '>';
1517
-            $input_html .= "\n\t\t\t\t\t" . '<label class="' . $radio_class . ' espresso-checkbox-lbl">';
1518
-            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t" . '<span>' . $text . '</span>&nbsp;&nbsp;' : '';
1516
+            $input_html .= "\n\t\t\t\t".'<li'.$size.'>';
1517
+            $input_html .= "\n\t\t\t\t\t".'<label class="'.$radio_class.' espresso-checkbox-lbl">';
1518
+            $input_html .= $label_b4 ? "\n\t\t\t\t\t\t".'<span>'.$text.'</span>&nbsp;&nbsp;' : '';
1519 1519
             $input_html .= "\n\t\t\t\t\t\t"
1520
-                           . '<input type="checkbox" name="' . $name . '[' . $OPT->ID() . ']" '
1521
-                           . 'id="' . $id . $opt . '" class="' . $class . '" value="' . $value . '" '
1522
-                           . 'aria-label="' . esc_attr($required['msg']) . '" ' . $disabled . $checked . ' ' . $extra . '/>';
1523
-            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t" . '&nbsp;&nbsp;<span>' . $text . '</span>' : '';
1524
-            $input_html .= "\n\t\t\t\t\t" . '</label>';
1525
-            if (! empty($desc) && $desc != $text) {
1520
+                           . '<input type="checkbox" name="'.$name.'['.$OPT->ID().']" '
1521
+                           . 'id="'.$id.$opt.'" class="'.$class.'" value="'.$value.'" '
1522
+                           . 'aria-label="'.esc_attr($required['msg']).'" '.$disabled.$checked.' '.$extra.'/>';
1523
+            $input_html .= ! $label_b4 ? "\n\t\t\t\t\t\t".'&nbsp;&nbsp;<span>'.$text.'</span>' : '';
1524
+            $input_html .= "\n\t\t\t\t\t".'</label>';
1525
+            if ( ! empty($desc) && $desc != $text) {
1526 1526
                 $input_html .= "\n\t\t\t\t\t"
1527 1527
                                . ' &nbsp; <br/><div class="espresso-checkbox-option-desc small-text grey-text">'
1528 1528
                                . $desc
1529 1529
                                . '</div>';
1530 1530
             }
1531
-            $input_html .= "\n\t\t\t\t" . '</li>';
1531
+            $input_html .= "\n\t\t\t\t".'</li>';
1532 1532
         }
1533 1533
 
1534
-        $input_html .= "\n\t\t\t" . '</ul>';
1534
+        $input_html .= "\n\t\t\t".'</ul>';
1535 1535
 
1536 1536
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1537
-        return $label_html . $input_html;
1537
+        return $label_html.$input_html;
1538 1538
     }
1539 1539
 
1540 1540
 
@@ -1567,7 +1567,7 @@  discard block
 block discarded – undo
1567 1567
         $add_mobile_label = false
1568 1568
     ) {
1569 1569
         // need these
1570
-        if (! $question || ! $name) {
1570
+        if ( ! $question || ! $name) {
1571 1571
             return null;
1572 1572
         }
1573 1573
         // prep the answer
@@ -1579,7 +1579,7 @@  discard block
 block discarded – undo
1579 1579
         // ya gots ta have style man!!!
1580 1580
         $txt_class = is_admin() ? 'regular-text' : 'espresso-datepicker-inp';
1581 1581
         $class     = empty($class) ? $txt_class : $class;
1582
-        $class     .= ! empty($system_ID) ? ' ' . $system_ID : '';
1582
+        $class .= ! empty($system_ID) ? ' '.$system_ID : '';
1583 1583
         $class = self::appendInputSizeClass($class, $answer);
1584 1584
         $extra     = apply_filters('FHEE__EEH_Form_Fields__additional_form_field_attributes', '');
1585 1585
 
@@ -1594,14 +1594,14 @@  discard block
 block discarded – undo
1594 1594
         );
1595 1595
 
1596 1596
         $input_html = $mobile_label
1597
-            . '<input type="text" name="' . $name . '" id="' . $id . '" '
1598
-            . 'class="' . $class . ' ' . $required['class'] . ' datepicker" value="' . $answer . '"  '
1599
-            . 'aria-label="' . esc_attr($required['msg']) . '" ' . $disabled . ' ' . $extra . '/>';
1597
+            . '<input type="text" name="'.$name.'" id="'.$id.'" '
1598
+            . 'class="'.$class.' '.$required['class'].' datepicker" value="'.$answer.'"  '
1599
+            . 'aria-label="'.esc_attr($required['msg']).'" '.$disabled.' '.$extra.'/>';
1600 1600
 
1601 1601
         // enqueue scripts
1602 1602
         wp_register_style(
1603 1603
             'espresso-ui-theme',
1604
-            EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1604
+            EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css',
1605 1605
             [],
1606 1606
             EVENT_ESPRESSO_VERSION
1607 1607
         );
@@ -1609,7 +1609,7 @@  discard block
 block discarded – undo
1609 1609
         wp_enqueue_script('jquery-ui-datepicker');
1610 1610
 
1611 1611
         $input_html = apply_filters('FHEE__EEH_Form_Fields__input_html', $input_html, $label_html, $id);
1612
-        return $label_html . $input_html;
1612
+        return $label_html.$input_html;
1613 1613
     }
1614 1614
 
1615 1615
 
@@ -1636,7 +1636,7 @@  discard block
 block discarded – undo
1636 1636
     public static function hidden_input($name, $value, $id = '')
1637 1637
     {
1638 1638
         $id = ! empty($id) ? $id : $name;
1639
-        return '<input id="' . $id . '" type="hidden" name="' . $name . '" value="' . $value . '"/>';
1639
+        return '<input id="'.$id.'" type="hidden" name="'.$name.'" value="'.$value.'"/>';
1640 1640
     }
1641 1641
 
1642 1642
 
@@ -1681,7 +1681,7 @@  discard block
 block discarded – undo
1681 1681
         $prepped_answer_options = [];
1682 1682
         if (is_array($QSOs) && ! empty($QSOs)) {
1683 1683
             foreach ($QSOs as $key => $QSO) {
1684
-                if (! $QSO instanceof EE_Question_Option) {
1684
+                if ( ! $QSO instanceof EE_Question_Option) {
1685 1685
                     $QSO = EE_Question_Option::new_instance(
1686 1686
                         [
1687 1687
                             'QSO_value' => is_array($QSO) && isset($QSO['id'])
@@ -1694,7 +1694,7 @@  discard block
 block discarded – undo
1694 1694
                     );
1695 1695
                 }
1696 1696
                 if ($QSO->opt_group()) {
1697
-                    $prepped_answer_options[ $QSO->opt_group() ][] = $QSO;
1697
+                    $prepped_answer_options[$QSO->opt_group()][] = $QSO;
1698 1698
                 } else {
1699 1699
                     $prepped_answer_options[] = $QSO;
1700 1700
                 }
@@ -1906,7 +1906,7 @@  discard block
 block discarded – undo
1906 1906
         $options = [];
1907 1907
         for ($x = 1; $x <= 12; $x++) {
1908 1908
             $mm             = str_pad($x, 2, '0', STR_PAD_LEFT);
1909
-            $options[ $mm ] = $mm;
1909
+            $options[$mm] = $mm;
1910 1910
         }
1911 1911
         return EEH_Form_Fields::prep_answer_options($options);
1912 1912
     }
@@ -1924,7 +1924,7 @@  discard block
 block discarded – undo
1924 1924
         $next_decade  = $current_year + 10;
1925 1925
         for ($x = $current_year; $x <= $next_decade; $x++) {
1926 1926
             $yy             = str_pad($x, 2, '0', STR_PAD_LEFT);
1927
-            $options[ $yy ] = $yy;
1927
+            $options[$yy] = $yy;
1928 1928
         }
1929 1929
         return EEH_Form_Fields::prep_answer_options($options);
1930 1930
     }
@@ -1943,7 +1943,7 @@  discard block
 block discarded – undo
1943 1943
     public static function generate_registration_months_dropdown($cur_date = '', $status = '', $evt_category = 0)
1944 1944
     {
1945 1945
         $_where = [];
1946
-        if (! empty($status)) {
1946
+        if ( ! empty($status)) {
1947 1947
             $_where['STS_ID'] = $status;
1948 1948
         }
1949 1949
 
@@ -1962,7 +1962,7 @@  discard block
 block discarded – undo
1962 1962
         ];
1963 1963
 
1964 1964
         foreach ($regdtts as $regdtt) {
1965
-            $date      = $regdtt->reg_month . ' ' . $regdtt->reg_year;
1965
+            $date      = $regdtt->reg_month.' '.$regdtt->reg_year;
1966 1966
             $options[] = [
1967 1967
                 'text' => $date,
1968 1968
                 'id'   => $date,
@@ -2011,7 +2011,7 @@  discard block
 block discarded – undo
2011 2011
         // categories?
2012 2012
 
2013 2013
 
2014
-        if (! empty($evt_category)) {
2014
+        if ( ! empty($evt_category)) {
2015 2015
             $where['Event.Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
2016 2016
             $where['Event.Term_Taxonomy.term_id']  = $evt_category;
2017 2017
         }
@@ -2034,8 +2034,8 @@  discard block
 block discarded – undo
2034 2034
         global $wp_locale;
2035 2035
 
2036 2036
         foreach ($DTTS as $DTT) {
2037
-            $localized_date = $wp_locale->get_month($DTT->dtt_month_num) . ' ' . $DTT->dtt_year;
2038
-            $id             = $DTT->dtt_month . ' ' . $DTT->dtt_year;
2037
+            $localized_date = $wp_locale->get_month($DTT->dtt_month_num).' '.$DTT->dtt_year;
2038
+            $id             = $DTT->dtt_month.' '.$DTT->dtt_year;
2039 2039
             $options[]      = [
2040 2040
                 'text' => $localized_date,
2041 2041
                 'id'   => $id,
@@ -2108,16 +2108,16 @@  discard block
 block discarded – undo
2108 2108
             return $btn;
2109 2109
         }
2110 2110
         $text = ! empty($text) ? $text : esc_html__('Submit', 'event_espresso');
2111
-        $btn  .= '<input id="' . $ID . '-btn" class="' . $class . '" '
2112
-                 . 'type="submit" value="' . $text . '" ' . $extra_attributes . '/>';
2113
-        if (! $input_only) {
2114
-            $btn_frm = '<form id="' . $ID . '-frm" method="POST" action="' . $url . '">';
2111
+        $btn .= '<input id="'.$ID.'-btn" class="'.$class.'" '
2112
+                 . 'type="submit" value="'.$text.'" '.$extra_attributes.'/>';
2113
+        if ( ! $input_only) {
2114
+            $btn_frm = '<form id="'.$ID.'-frm" method="POST" action="'.$url.'">';
2115 2115
             $btn_frm .= ! empty($nonce_action)
2116
-                ? wp_nonce_field($nonce_action, $nonce_action . '_nonce', true, false)
2116
+                ? wp_nonce_field($nonce_action, $nonce_action.'_nonce', true, false)
2117 2117
                 : '';
2118 2118
             $btn_frm .= $btn;
2119 2119
             $btn_frm .= '</form>';
2120
-            $btn     = $btn_frm;
2120
+            $btn = $btn_frm;
2121 2121
             unset($btn_frm);
2122 2122
         }
2123 2123
         return $btn;
Please login to merge, or discard this patch.
core/helpers/EEH_Export.helper.php 2 patches
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -13,171 +13,171 @@
 block discarded – undo
13 13
  */
14 14
 class EEH_Export
15 15
 {
16
-    /**
17
-     * Gets the 'normal' column named for fields
18
-     * @param EE_Model_Field_Base $field
19
-     * @return string
20
-     * @throws EE_Error
21
-     */
22
-    public static function get_column_name_for_field(EE_Model_Field_Base $field)
23
-    {
24
-        $column_name = wp_specialchars_decode($field->get_nicename(), ENT_QUOTES);
25
-        if (
26
-            apply_filters(
27
-                'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
28
-                false,
29
-                $column_name,
30
-                $field
31
-            )
32
-        ) {
33
-            $column_name .= "["
34
-                . wp_specialchars_decode($field->get_name(), ENT_QUOTES)
35
-                . "]";
36
-        }
37
-        return $column_name;
38
-    }
39
-
40
-
41
-    /**
42
-     * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers
43
-     *
44
-     * @param string $filepath
45
-     * @param array  $data                  2D array,first numerically-indexed,
46
-     *                                      and next-level-down preferably indexed by string
47
-     * @param bool   $write_column_headers  whether or not we should add the keys in the bottom-most array
48
-     *                                      as a row for headers in the CSV.
49
-     *                                      Eg, if $data looked like:
50
-     *                                          array(
51
-     *                                              0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...),
52
-     *                                              1=>array(...,...)
53
-     *                                          )
54
-     * @param bool   $headers_only          if true then we won't print any data, just headers. defaults to false
55
-     * @return boolean                      if we successfully wrote to the CSV or not. If there's no $data,
56
-     *                                      we consider that a success (because we wrote everything there was...nothing)
57
-     * @throws EE_Error
58
-     */
59
-    public static function write_data_array_to_csv(
60
-        string $filepath,
61
-        array $data,
62
-        bool $write_column_headers = true,
63
-        bool $headers_only = false
64
-    ) {
65
-        // determine if $data is actually a 2d array
66
-        if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) {
67
-            // make sure top level is numerically indexed,
68
-            if (EEH_Array::is_associative_array($data)) {
69
-                throw new EE_Error(sprintf(esc_html__("top-level array must be numerically indexed. Does these look like numbers to you? %s", "event_espresso"), implode(",", array_keys($data))));
70
-            }
71
-            $new_file_contents = '';
72
-            $item_in_top_level_array = EEH_Array::get_one_item_from_array($data);
73
-            // now, is the last item in the top-level array of $data an associative or numeric array?
74
-            if ($write_column_headers && EEH_Array::is_associative_array($item_in_top_level_array)) {
75
-                // its associative, so we want to output its keys as column headers
76
-                $keys = array_keys($item_in_top_level_array);
77
-                $new_file_contents .=  EEH_Export::get_csv_row($keys);
78
-                if ($headers_only) {
79
-                    return EEH_File::write_to_file(
80
-                        $filepath,
81
-                        EEH_File::get_file_contents($filepath) . $new_file_contents
82
-                    );
83
-                }
84
-            }
85
-            // start writing data
86
-            foreach ($data as $data_row) {
87
-                $new_row = EEH_Export::get_csv_row($data_row);
88
-                $new_file_contents .= $new_row ?: '';
89
-            }
90
-            return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents);
91
-        }
92
-        // no data TO write... so we can assume that's a success
93
-        return true;
94
-    }
95
-
96
-
97
-
98
-     /**
99
-      *
100
-     *  Writes a row to the csv file
101
-     *  @param array $row - individual row of csv data
102
-     *  @param string $delimiter - csv delimiter
103
-     *  @param string $enclosure - csv enclosure
104
-     *  @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value
105
-     *  @return string of text for teh csv file
106
-     */
107
-    public static function get_csv_row(array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false)
108
-    {
109
-        // Allow user to filter the csv delimiter and enclosure for other countries csv standards
110
-        $delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter);
111
-        $enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure);
112
-
113
-        $delimiter_esc = preg_quote($delimiter, '/');
114
-        $enclosure_esc = preg_quote($enclosure, '/');
115
-
116
-        $output = array();
117
-        foreach ($row as $field_value) {
118
-            if (is_object($field_value) || is_array($field_value)) {
119
-                $field_value = serialize($field_value);
120
-            }
121
-            if ($field_value === null && $mysql_null) {
122
-                $output[] = 'NULL';
123
-                continue;
124
-            }
125
-
126
-            $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ?
127
-                ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value;
128
-        }
129
-
130
-        return  implode($delimiter, $output) . PHP_EOL;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * Shortcut for preparing a database result for display
137
-     * @param EEM_Base $model
138
-     * @param string $field_name
139
-     * @param string $raw_db_value
140
-     * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty
141
-     * @return string
142
-     */
143
-    public static function prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true)
144
-    {
145
-        $field_obj = $model->field_settings_for($field_name);
146
-        $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value);
147
-        if ($field_obj instanceof EE_Datetime_Field) {
148
-            $field_obj->set_date_format(EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), $pretty_schema);
149
-            $field_obj->set_time_format(EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), $pretty_schema);
150
-        }
151
-        if ($pretty_schema === true) {
152
-            return $field_obj->prepare_for_pretty_echoing($value_on_model_obj);
153
-        } elseif (is_string($pretty_schema)) {
154
-            return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema);
155
-        } else {
156
-            return $field_obj->prepare_for_get($value_on_model_obj);
157
-        }
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Gets the date format to use in exports. filterable
164
-     * @param string $current_format
165
-     * @return string
166
-     */
167
-    public static function get_date_format_for_export($current_format = null)
168
-    {
169
-        return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format);
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Gets the time format we want to use in exports. Filterable
176
-     * @param string $current_format
177
-     * @return string
178
-     */
179
-    public static function get_time_format_for_export($current_format = null)
180
-    {
181
-        return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format);
182
-    }
16
+	/**
17
+	 * Gets the 'normal' column named for fields
18
+	 * @param EE_Model_Field_Base $field
19
+	 * @return string
20
+	 * @throws EE_Error
21
+	 */
22
+	public static function get_column_name_for_field(EE_Model_Field_Base $field)
23
+	{
24
+		$column_name = wp_specialchars_decode($field->get_nicename(), ENT_QUOTES);
25
+		if (
26
+			apply_filters(
27
+				'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
28
+				false,
29
+				$column_name,
30
+				$field
31
+			)
32
+		) {
33
+			$column_name .= "["
34
+				. wp_specialchars_decode($field->get_name(), ENT_QUOTES)
35
+				. "]";
36
+		}
37
+		return $column_name;
38
+	}
39
+
40
+
41
+	/**
42
+	 * Writes $data to the csv file open in $filehandle. uses the array indices of $data for column headers
43
+	 *
44
+	 * @param string $filepath
45
+	 * @param array  $data                  2D array,first numerically-indexed,
46
+	 *                                      and next-level-down preferably indexed by string
47
+	 * @param bool   $write_column_headers  whether or not we should add the keys in the bottom-most array
48
+	 *                                      as a row for headers in the CSV.
49
+	 *                                      Eg, if $data looked like:
50
+	 *                                          array(
51
+	 *                                              0=>array('EVT_ID'=>1,'EVT_name'=>'monkey'...),
52
+	 *                                              1=>array(...,...)
53
+	 *                                          )
54
+	 * @param bool   $headers_only          if true then we won't print any data, just headers. defaults to false
55
+	 * @return boolean                      if we successfully wrote to the CSV or not. If there's no $data,
56
+	 *                                      we consider that a success (because we wrote everything there was...nothing)
57
+	 * @throws EE_Error
58
+	 */
59
+	public static function write_data_array_to_csv(
60
+		string $filepath,
61
+		array $data,
62
+		bool $write_column_headers = true,
63
+		bool $headers_only = false
64
+	) {
65
+		// determine if $data is actually a 2d array
66
+		if ($data && is_array($data) && is_array(EEH_Array::get_one_item_from_array($data))) {
67
+			// make sure top level is numerically indexed,
68
+			if (EEH_Array::is_associative_array($data)) {
69
+				throw new EE_Error(sprintf(esc_html__("top-level array must be numerically indexed. Does these look like numbers to you? %s", "event_espresso"), implode(",", array_keys($data))));
70
+			}
71
+			$new_file_contents = '';
72
+			$item_in_top_level_array = EEH_Array::get_one_item_from_array($data);
73
+			// now, is the last item in the top-level array of $data an associative or numeric array?
74
+			if ($write_column_headers && EEH_Array::is_associative_array($item_in_top_level_array)) {
75
+				// its associative, so we want to output its keys as column headers
76
+				$keys = array_keys($item_in_top_level_array);
77
+				$new_file_contents .=  EEH_Export::get_csv_row($keys);
78
+				if ($headers_only) {
79
+					return EEH_File::write_to_file(
80
+						$filepath,
81
+						EEH_File::get_file_contents($filepath) . $new_file_contents
82
+					);
83
+				}
84
+			}
85
+			// start writing data
86
+			foreach ($data as $data_row) {
87
+				$new_row = EEH_Export::get_csv_row($data_row);
88
+				$new_file_contents .= $new_row ?: '';
89
+			}
90
+			return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents);
91
+		}
92
+		// no data TO write... so we can assume that's a success
93
+		return true;
94
+	}
95
+
96
+
97
+
98
+	 /**
99
+	  *
100
+	  *  Writes a row to the csv file
101
+	  *  @param array $row - individual row of csv data
102
+	  *  @param string $delimiter - csv delimiter
103
+	  *  @param string $enclosure - csv enclosure
104
+	  *  @param bool $mysql_null - allows php NULL to be overridden with MySQl's insertable NULL value
105
+	  *  @return string of text for teh csv file
106
+	  */
107
+	public static function get_csv_row(array $row, $delimiter = ',', $enclosure = '"', $mysql_null = false)
108
+	{
109
+		// Allow user to filter the csv delimiter and enclosure for other countries csv standards
110
+		$delimiter = apply_filters('FHEE__EE_CSV__fputcsv2__delimiter', $delimiter);
111
+		$enclosure = apply_filters('FHEE__EE_CSV__fputcsv2__enclosure', $enclosure);
112
+
113
+		$delimiter_esc = preg_quote($delimiter, '/');
114
+		$enclosure_esc = preg_quote($enclosure, '/');
115
+
116
+		$output = array();
117
+		foreach ($row as $field_value) {
118
+			if (is_object($field_value) || is_array($field_value)) {
119
+				$field_value = serialize($field_value);
120
+			}
121
+			if ($field_value === null && $mysql_null) {
122
+				$output[] = 'NULL';
123
+				continue;
124
+			}
125
+
126
+			$output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ?
127
+				( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value;
128
+		}
129
+
130
+		return  implode($delimiter, $output) . PHP_EOL;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * Shortcut for preparing a database result for display
137
+	 * @param EEM_Base $model
138
+	 * @param string $field_name
139
+	 * @param string $raw_db_value
140
+	 * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty
141
+	 * @return string
142
+	 */
143
+	public static function prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true)
144
+	{
145
+		$field_obj = $model->field_settings_for($field_name);
146
+		$value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value);
147
+		if ($field_obj instanceof EE_Datetime_Field) {
148
+			$field_obj->set_date_format(EEH_Export::get_date_format_for_export($field_obj->get_date_format($pretty_schema)), $pretty_schema);
149
+			$field_obj->set_time_format(EEH_Export::get_time_format_for_export($field_obj->get_time_format($pretty_schema)), $pretty_schema);
150
+		}
151
+		if ($pretty_schema === true) {
152
+			return $field_obj->prepare_for_pretty_echoing($value_on_model_obj);
153
+		} elseif (is_string($pretty_schema)) {
154
+			return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema);
155
+		} else {
156
+			return $field_obj->prepare_for_get($value_on_model_obj);
157
+		}
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Gets the date format to use in exports. filterable
164
+	 * @param string $current_format
165
+	 * @return string
166
+	 */
167
+	public static function get_date_format_for_export($current_format = null)
168
+	{
169
+		return apply_filters('FHEE__EE_CSV__get_date_format_for_csv__format', 'Y-m-d', $current_format);
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Gets the time format we want to use in exports. Filterable
176
+	 * @param string $current_format
177
+	 * @return string
178
+	 */
179
+	public static function get_time_format_for_export($current_format = null)
180
+	{
181
+		return apply_filters('FHEE__EE_CSV__get_time_format_for_csv__format', 'H:i:s', $current_format);
182
+	}
183 183
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -74,11 +74,11 @@  discard block
 block discarded – undo
74 74
             if ($write_column_headers && EEH_Array::is_associative_array($item_in_top_level_array)) {
75 75
                 // its associative, so we want to output its keys as column headers
76 76
                 $keys = array_keys($item_in_top_level_array);
77
-                $new_file_contents .=  EEH_Export::get_csv_row($keys);
77
+                $new_file_contents .= EEH_Export::get_csv_row($keys);
78 78
                 if ($headers_only) {
79 79
                     return EEH_File::write_to_file(
80 80
                         $filepath,
81
-                        EEH_File::get_file_contents($filepath) . $new_file_contents
81
+                        EEH_File::get_file_contents($filepath).$new_file_contents
82 82
                     );
83 83
                 }
84 84
             }
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
                 $new_row = EEH_Export::get_csv_row($data_row);
88 88
                 $new_file_contents .= $new_row ?: '';
89 89
             }
90
-            return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath) . $new_file_contents);
90
+            return EEH_File::write_to_file($filepath, EEH_File::get_file_contents($filepath).$new_file_contents);
91 91
         }
92 92
         // no data TO write... so we can assume that's a success
93 93
         return true;
@@ -124,10 +124,10 @@  discard block
 block discarded – undo
124 124
             }
125 125
 
126 126
             $output[] = preg_match("/(?:${delimiter_esc}|${enclosure_esc}|\s)/", $field_value) ?
127
-                ( $enclosure . str_replace($enclosure, $enclosure . $enclosure, $field_value) . $enclosure ) : $field_value;
127
+                ($enclosure.str_replace($enclosure, $enclosure.$enclosure, $field_value).$enclosure) : $field_value;
128 128
         }
129 129
 
130
-        return  implode($delimiter, $output) . PHP_EOL;
130
+        return  implode($delimiter, $output).PHP_EOL;
131 131
     }
132 132
 
133 133
 
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlers/RegistrationsReport.php 2 patches
Indentation   +619 added lines, -619 removed lines patch added patch discarded remove patch
@@ -39,623 +39,623 @@
 block discarded – undo
39 39
  */
40 40
 class RegistrationsReport extends JobHandlerFile
41 41
 {
42
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
43
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
44
-    /**
45
-     * Performs any necessary setup for starting the job. This is also a good
46
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
47
-     * when continue_job will be called
48
-     *
49
-     * @param JobParameters $job_parameters
50
-     * @return JobStepResponse
51
-     * @throws BatchRequestException
52
-     * @throws EE_Error
53
-     * @throws ReflectionException
54
-     */
55
-    public function create_job(JobParameters $job_parameters)
56
-    {
57
-        $event_id = absint($job_parameters->request_datum('EVT_ID', '0'));
58
-        if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
59
-            throw new BatchRequestException(
60
-                esc_html__('You do not have permission to view registrations', 'event_espresso')
61
-            );
62
-        }
63
-        $filepath = $this->create_file_from_job_with_name(
64
-            $job_parameters->job_id(),
65
-            $this->get_filename()
66
-        );
67
-        $job_parameters->add_extra_data('filepath', $filepath);
68
-        if ($job_parameters->request_datum('use_filters', false)) {
69
-            $query_params = maybe_unserialize($job_parameters->request_datum('filters', []));
70
-        } else {
71
-            $query_params = apply_filters(
72
-                'FHEE__EE_Export__report_registration_for_event',
73
-                [
74
-                    [
75
-                        'OR'                 => [
76
-                            // don't include registrations from failed or abandoned transactions...
77
-                            'Transaction.STS_ID' => [
78
-                                'NOT IN',
79
-                                [
80
-                                    EEM_Transaction::failed_status_code,
81
-                                    EEM_Transaction::abandoned_status_code,
82
-                                ],
83
-                            ],
84
-                            // unless the registration is approved,
85
-                            // in which case include it regardless of transaction status
86
-                            'STS_ID'             => EEM_Registration::status_id_approved,
87
-                        ],
88
-                        'Ticket.TKT_deleted' => ['IN', [true, false]],
89
-                    ],
90
-                    'order_by'   => ['Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'],
91
-                    'force_join' => ['Transaction', 'Ticket', 'Attendee'],
92
-                    'caps'       => EEM_Base::caps_read_admin,
93
-                ],
94
-                $event_id
95
-            );
96
-            if ($event_id) {
97
-                $query_params[0]['EVT_ID'] = $event_id;
98
-            } else {
99
-                $query_params['force_join'][] = 'Event';
100
-            }
101
-        }
102
-
103
-        if (! isset($query_params['force_join'])) {
104
-            $query_params['force_join'] = ['Event', 'Transaction', 'Ticket', 'Attendee'];
105
-        }
106
-        $job_parameters->add_extra_data('query_params', $query_params);
107
-        $question_labels = $this->_get_question_labels($query_params);
108
-        $job_parameters->add_extra_data('question_labels', $question_labels);
109
-        $job_parameters->set_job_size(
110
-            EEM_Registration::instance()->count(
111
-                array_diff_key(
112
-                    $query_params,
113
-                    array_flip(['limit'])
114
-                )
115
-            )
116
-        );
117
-        // we need to set the header columns
118
-        // but to do that we need to process one row so that we can extract ALL of the column headers
119
-        $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $question_labels, $query_params);
120
-        // but we don't want to write any actual data yet...
121
-        // so let's blank out all of the values for that first row
122
-        array_walk(
123
-            $csv_data_for_row[0],
124
-            function (&$value) {
125
-                $value = null;
126
-            }
127
-        );
128
-        EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true, true);
129
-        $this->updateTextHeader(
130
-            esc_html__('Registrations report started successfully...', 'event_espresso')
131
-        );
132
-        return new JobStepResponse($job_parameters, $this->feedback);
133
-    }
134
-
135
-
136
-    /**
137
-     * Gets the filename
138
-     *
139
-     * @return string
140
-     */
141
-    protected function get_filename(): string
142
-    {
143
-        return apply_filters(
144
-            'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
145
-            sprintf(
146
-                'event-espresso-registrations-%s.csv',
147
-                str_replace([':', ' '], '-', current_time('mysql'))
148
-            )
149
-        );
150
-    }
151
-
152
-
153
-    /**
154
-     * Gets the questions which are to be used for this report, so they
155
-     * can be remembered for later
156
-     *
157
-     * @param array $registration_query_params
158
-     * @return array question admin labels to be used for this report
159
-     * @throws EE_Error
160
-     * @throws ReflectionException
161
-     */
162
-    protected function _get_question_labels(array $registration_query_params): array
163
-    {
164
-        $where                 = $registration_query_params[0] ?? null;
165
-        $question_query_params = [];
166
-        if ($where !== null) {
167
-            $question_query_params = [
168
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
169
-            ];
170
-        }
171
-        // Make sure it's not a system question
172
-        $question_query_params[0]['OR*not-system-questions'] = [
173
-            'QST_system'      => '',
174
-            'QST_system*null' => ['IS_NULL'],
175
-        ];
176
-        if (
177
-            apply_filters(
178
-                'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
179
-                false,
180
-                $registration_query_params
181
-            )
182
-        ) {
183
-            $question_query_params[0]['Answer.ANS_ID'] = ['IS_NOT_NULL'];
184
-        }
185
-        $question_query_params['group_by'] = ['QST_ID'];
186
-        return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
187
-    }
188
-
189
-
190
-    /**
191
-     * Takes where params meant for registrations and changes them to work for questions
192
-     *
193
-     * @param array $reg_where_params
194
-     * @return array
195
-     * @throws EE_Error
196
-     * @throws ReflectionException
197
-     */
198
-    protected function _change_registration_where_params_to_question_where_params(array $reg_where_params): array
199
-    {
200
-        $question_where_params = [];
201
-        foreach ($reg_where_params as $key => $val) {
202
-            if (EEM_Registration::instance()->is_logic_query_param_key($key)) {
203
-                $question_where_params[ $key ] =
204
-                    $this->_change_registration_where_params_to_question_where_params($val);
205
-            } else {
206
-                // it's a normal where condition
207
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
208
-            }
209
-        }
210
-        return $question_where_params;
211
-    }
212
-
213
-
214
-    /**
215
-     * Performs another step of the job
216
-     *
217
-     * @param JobParameters $job_parameters
218
-     * @param int           $batch_size
219
-     * @return JobStepResponse
220
-     * @throws EE_Error
221
-     * @throws ReflectionException
222
-     */
223
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
224
-    {
225
-        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
226
-            $csv_data = $this->get_csv_data_for(
227
-                $job_parameters->request_datum('EVT_ID', '0'),
228
-                $job_parameters->units_processed(),
229
-                $batch_size,
230
-                $job_parameters->extra_datum('question_labels'),
231
-                $job_parameters->extra_datum('query_params')
232
-            );
233
-            EEH_Export::write_data_array_to_csv(
234
-                $job_parameters->extra_datum('filepath'),
235
-                $csv_data,
236
-                false
237
-            );
238
-            $units_processed = count($csv_data);
239
-            if ($units_processed) {
240
-                $job_parameters->mark_processed($units_processed);
241
-                $this->updateText(
242
-                    sprintf(
243
-                        esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'),
244
-                        $units_processed
245
-                    )
246
-                );
247
-            }
248
-        }
249
-        $extra_response_data = ['file_url' => ''];
250
-        if ($job_parameters->units_processed() >= $job_parameters->job_size()) {
251
-            $job_parameters->set_status(JobParameters::status_complete);
252
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
253
-            $this->displayJobFinalResults($job_parameters);
254
-        } else {
255
-            $job_parameters->set_status(JobParameters::status_continue);
256
-        }
257
-        return new JobStepResponse($job_parameters, $this->feedback, $extra_response_data);
258
-    }
259
-
260
-
261
-    /**
262
-     * Gets the csv data for a batch of registrations
263
-     *
264
-     * @param int|null $event_id
265
-     * @param int      $offset
266
-     * @param int      $limit
267
-     * @param array    $question_labels the IDs for all the questions which were answered by someone in this selection
268
-     * @param array    $query_params    for using where querying the model
269
-     * @return array top-level keys are numeric, next-level keys are column headers
270
-     * @throws EE_Error
271
-     * @throws ReflectionException
272
-     */
273
-    public function get_csv_data_for(
274
-        ?int  $event_id,
275
-        int   $offset,
276
-        int   $limit,
277
-        array $question_labels,
278
-        array $query_params
279
-    ): array {
280
-        $reg_fields_to_include = [
281
-            'TXN_ID',
282
-            'ATT_ID',
283
-            'REG_ID',
284
-            'REG_date',
285
-            'REG_code',
286
-            'REG_count',
287
-            'REG_final_price',
288
-        ];
289
-        $att_fields_to_include = [
290
-            'ATT_fname',
291
-            'ATT_lname',
292
-            'ATT_email',
293
-            'ATT_address',
294
-            'ATT_address2',
295
-            'ATT_city',
296
-            'STA_ID',
297
-            'CNT_ISO',
298
-            'ATT_zip',
299
-            'ATT_phone',
300
-        ];
301
-
302
-        // get models
303
-        $event_model   = EEM_Event::instance();
304
-        $date_model    = EEM_Datetime::instance();
305
-        $ticket_model  = EEM_Ticket::instance();
306
-        $txn_model     = EEM_Transaction::instance();
307
-        $reg_model     = EEM_Registration::instance();
308
-        $att_model     = EEM_Attendee::instance();
309
-        $pay_model     = EEM_Payment::instance();
310
-        $status_model  = EEM_Status::instance();
311
-        $qst_model     = EEM_Question::instance();
312
-        $answer_model  = EEM_Answer::instance();
313
-        $state_model   = EEM_State::instance();
314
-        $country_model = EEM_Country::instance();
315
-
316
-        $registrations_csv_ready_array = [];
317
-        $query_params['limit']         = [$offset, $limit];
318
-        $registration_rows             = $reg_model->get_all_wpdb_results($query_params);
319
-
320
-        foreach ($registration_rows as $reg_row) {
321
-            if (is_array($reg_row)) {
322
-                $reg_csv_array = [];
323
-                // ALL registrations, or is list filtered to just one?
324
-                if (! $event_id) {
325
-                    // ALL registrations, so get each event's name and ID
326
-                    $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf(
327
-                        /* translators: 1: event name, 2: event ID */
328
-                        esc_html__('%1$s (%2$s)', 'event_espresso'),
329
-                        EEH_Export::prepare_value_from_db_for_display(
330
-                            $event_model,
331
-                            'EVT_name',
332
-                            $reg_row['Event_CPT.post_title']
333
-                        ),
334
-                        $reg_row['Event_CPT.ID']
335
-                    );
336
-                }
337
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1';
338
-
339
-                foreach ($reg_fields_to_include as $field_name) {
340
-                    $field = $reg_model->field_settings_for($field_name);
341
-                    switch ($field_name) {
342
-                        case 'REG_final_price':
343
-                            $value = EEH_Export::prepare_value_from_db_for_display(
344
-                                $reg_model,
345
-                                $field_name,
346
-                                $reg_row['Registration.REG_final_price'],
347
-                                'localized_float'
348
-                            );
349
-                            break;
350
-                        case 'REG_count':
351
-                            $value = sprintf(
352
-                                /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
353
-                                esc_html__('%1$s of %2$s', 'event_espresso'),
354
-                                EEH_Export::prepare_value_from_db_for_display(
355
-                                    $reg_model,
356
-                                    'REG_count',
357
-                                    $reg_row['Registration.REG_count']
358
-                                ),
359
-                                EEH_Export::prepare_value_from_db_for_display(
360
-                                    $reg_model,
361
-                                    'REG_group_size',
362
-                                    $reg_row['Registration.REG_group_size']
363
-                                )
364
-                            );
365
-                            break;
366
-                        case 'REG_date':
367
-                            $value = EEH_Export::prepare_value_from_db_for_display(
368
-                                $reg_model,
369
-                                $field_name,
370
-                                $reg_row['Registration.REG_date'],
371
-                                'no_html'
372
-                            );
373
-                            break;
374
-                        default:
375
-                            $value = EEH_Export::prepare_value_from_db_for_display(
376
-                                $reg_model,
377
-                                $field_name,
378
-                                $reg_row[ $field->get_qualified_column() ]
379
-                            );
380
-                    }
381
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
382
-                    if ($field_name == 'REG_final_price') {
383
-                        // add a column named Currency after the final price
384
-                        $reg_csv_array[ esc_html__('Currency', 'event_espresso') ] =
385
-                            EE_Config::instance()->currency->code;
386
-                    }
387
-                }
388
-
389
-                // get pretty status
390
-                $stati = $status_model->localized_status(
391
-                    [
392
-                        $reg_row['Registration.STS_ID']     => esc_html__('unknown', 'event_espresso'),
393
-                        $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'),
394
-                    ],
395
-                    false,
396
-                    'sentence'
397
-                );
398
-
399
-                $reg_csv_array[ esc_html__('Registration Status', 'event_espresso') ] =
400
-                    $stati[ $reg_row['Registration.STS_ID'] ];
401
-                // get pretty transaction status
402
-                $reg_csv_array[ esc_html__('Transaction Status', 'event_espresso') ]     =
403
-                    $stati[ $reg_row['TransactionTable.STS_ID'] ];
404
-                $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
405
-                    ? EEH_Export::prepare_value_from_db_for_display(
406
-                        $txn_model,
407
-                        'TXN_total',
408
-                        $reg_row['TransactionTable.TXN_total'],
409
-                        'localized_float'
410
-                    )
411
-                    : '0.00';
412
-
413
-                $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg
414
-                    ? EEH_Export::prepare_value_from_db_for_display(
415
-                        $txn_model,
416
-                        'TXN_paid',
417
-                        $reg_row['TransactionTable.TXN_paid'],
418
-                        'localized_float'
419
-                    )
420
-                    : '0.00';
421
-
422
-                $payment_methods     = [];
423
-                $gateway_txn_ids_etc = [];
424
-                $payment_times       = [];
425
-
426
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
427
-                    $payments_info = $pay_model->get_all_wpdb_results(
428
-                        [
429
-                            [
430
-                                'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
431
-                                'STS_ID' => EEM_Payment::status_id_approved,
432
-                            ],
433
-                            'force_join' => ['Payment_Method'],
434
-                        ],
435
-                        ARRAY_A,
436
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
437
-                    );
438
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
439
-                        $payment_methods[]     = $payment_method_and_gateway_txn_id['name']
440
-                                                 ?? esc_html__('Unknown', 'event_espresso');
441
-                        $gateway_txn_ids_etc[] = $payment_method_and_gateway_txn_id['gateway_txn_id'] ?? '';
442
-                        $payment_times[]       = $payment_method_and_gateway_txn_id['payment_time'] ?? '';
443
-                    }
444
-                }
445
-                $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode(
446
-                    ',',
447
-                    $payment_times
448
-                );
449
-
450
-                $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode(
451
-                    ',',
452
-                    $payment_methods
453
-                );
454
-
455
-                $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
456
-                    ',',
457
-                    $gateway_txn_ids_etc
458
-                );
459
-
460
-                // get whether or not the user has checked in
461
-                $reg_csv_array[ esc_html__('Check-Ins', 'event_espresso') ] = $reg_model->count_related(
462
-                    $reg_row['Registration.REG_ID'],
463
-                    'Checkin'
464
-                );
465
-
466
-                $ticket_name      = esc_html__('Unknown', 'event_espresso');
467
-                $datetime_strings = [esc_html__('Unknown', 'event_espresso')];
468
-
469
-                // get ticket of registration and its price
470
-                if ($reg_row['Ticket.TKT_ID']) {
471
-                    $ticket_name      = EEH_Export::prepare_value_from_db_for_display(
472
-                        $ticket_model,
473
-                        'TKT_name',
474
-                        $reg_row['Ticket.TKT_name']
475
-                    );
476
-                    $datetime_strings = [];
477
-                    $datetimes        = $date_model->get_all_wpdb_results(
478
-                        [
479
-                            ['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']],
480
-                            'order_by'                 => ['DTT_EVT_start' => 'ASC'],
481
-                            'default_where_conditions' => 'none',
482
-                        ]
483
-                    );
484
-                    foreach ($datetimes as $datetime) {
485
-                        $datetime_strings[] = EEH_Export::prepare_value_from_db_for_display(
486
-                            $date_model,
487
-                            'DTT_EVT_start',
488
-                            $datetime['Datetime.DTT_EVT_start']
489
-                        );
490
-                    }
491
-                }
492
-
493
-                $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
494
-
495
-                $reg_csv_array[ esc_html__('Ticket Datetimes', 'event_espresso') ] = implode(
496
-                    ', ',
497
-                    $datetime_strings
498
-                );
499
-
500
-                // get datetime(s) of registration
501
-                // add attendee columns
502
-                foreach ($att_fields_to_include as $att_field_name) {
503
-                    $field_obj = $att_model->field_settings_for($att_field_name);
504
-                    $value     = '';
505
-                    if ($reg_row['Attendee_CPT.ID']) {
506
-                        switch ($att_field_name) {
507
-                            case 'STA_ID':
508
-                                $value = $state_model->get_var(
509
-                                    [['STA_ID' => $reg_row['Attendee_Meta.STA_ID']]],
510
-                                    'STA_name'
511
-                                );
512
-                                break;
513
-                            case 'CNT_ISO':
514
-                                $value = $country_model->get_var(
515
-                                    [['CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO']]],
516
-                                    'CNT_name'
517
-                                );
518
-                                break;
519
-                            default:
520
-                                $value = EEH_Export::prepare_value_from_db_for_display(
521
-                                    $att_model,
522
-                                    $att_field_name,
523
-                                    $reg_row[ $field_obj->get_qualified_column() ]
524
-                                );
525
-                        }
526
-                    }
527
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
528
-                }
529
-                // make sure each registration has the same questions in the same order
530
-                foreach ($question_labels as $question_label) {
531
-                    if (! isset($reg_csv_array[ $question_label ])) {
532
-                        $reg_csv_array[ $question_label ] = null;
533
-                    }
534
-                }
535
-                $answers = $answer_model->get_all_wpdb_results(
536
-                    [
537
-                        ['REG_ID' => $reg_row['Registration.REG_ID']],
538
-                        'force_join' => ['Question'],
539
-                    ]
540
-                );
541
-                // now fill out the questions THEY answered
542
-                foreach ($answers as $answer_row) {
543
-                    if ($answer_row['Question.QST_system']) {
544
-                        // it's an answer to a system question. That was already displayed as part of the attendee
545
-                        // fields, so don't write it out again thanks.
546
-                        continue;
547
-                    }
548
-
549
-                    $question_label = $answer_row['Question.QST_ID']
550
-                        ? EEH_Export::prepare_value_from_db_for_display(
551
-                            $qst_model,
552
-                            'QST_admin_label',
553
-                            $answer_row['Question.QST_admin_label']
554
-                        )
555
-                        : sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
556
-
557
-                    $reg_csv_array[ $question_label ] = isset($answer_row['Question.QST_type'])
558
-                                                        && $answer_row['Question.QST_type']
559
-                                                           === EEM_Question::QST_type_state
560
-                        ? $state_model->get_state_name_by_ID($answer_row['Answer.ANS_value'])
561
-                        // this isn't for html, so don't show html entities
562
-                        : html_entity_decode(
563
-                            EEH_Export::prepare_value_from_db_for_display(
564
-                                $answer_model,
565
-                                'ANS_value',
566
-                                $answer_row['Answer.ANS_value']
567
-                            )
568
-                        );
569
-                }
570
-
571
-                /**
572
-                 * Filter to change the contents of each row of the registrations report CSV file.
573
-                 * This can be used to add or remote columns from the CSV file, or change their values.
574
-                 * Note when using: all rows in the CSV should have the same columns.
575
-                 *
576
-                 * @param array $reg_csv_array keys are the column names, values are their cell values
577
-                 * @param array $reg_row       one entry from EEM_Registration::get_all_wpdb_results()
578
-                 */
579
-                $registrations_csv_ready_array[] = apply_filters(
580
-                    'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
581
-                    $reg_csv_array,
582
-                    $reg_row
583
-                );
584
-            }
585
-        }
586
-
587
-        // if we couldn't export anything, we want to at least show the column headers
588
-        if (empty($registrations_csv_ready_array)) {
589
-            $reg_csv_array               = [];
590
-            $model_and_fields_to_include = [
591
-                'Registration' => $reg_fields_to_include,
592
-                'Attendee'     => $att_fields_to_include,
593
-            ];
594
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
595
-                $model = EE_Registry::instance()->load_model($model_name);
596
-                foreach ($field_list as $field_name) {
597
-                    $field                                                          =
598
-                        $model->field_settings_for($field_name);
599
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
600
-                }
601
-            }
602
-            $registrations_csv_ready_array[] = $reg_csv_array;
603
-        }
604
-        return $registrations_csv_ready_array;
605
-    }
606
-
607
-
608
-    /**
609
-     * Counts total unit to process
610
-     *
611
-     * @param int|array $event_id
612
-     * @return int
613
-     * @throws EE_Error
614
-     * @throws ReflectionException
615
-     * @deprecated since 4.9.19
616
-     */
617
-    public function count_units_to_process($event_id): int
618
-    {
619
-        // use the legacy filter
620
-        if ($event_id) {
621
-            $query_params[0]['EVT_ID'] = $event_id;
622
-        } else {
623
-            $query_params['force_join'][] = 'Event';
624
-        }
625
-        return EEM_Registration::instance()->count($query_params);
626
-    }
627
-
628
-
629
-    /**
630
-     * Performs any clean-up logic when we know the job is completed.
631
-     * In this case, we delete the temporary file
632
-     *
633
-     * @param JobParameters $job_parameters
634
-     * @return JobStepResponse
635
-     */
636
-    public function cleanup_job(JobParameters $job_parameters)
637
-    {
638
-        $this->updateText(esc_html__('File Generation complete and downloaded', 'event_espresso'));
639
-        $this->_file_helper->delete(
640
-            EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
641
-            true,
642
-            'd'
643
-        );
644
-        $this->updateText(esc_html__('Cleaned up temporary file', 'event_espresso'));
645
-        $this->updateText(
646
-            $this->infoWrapper(
647
-                sprintf(
648
-                    esc_html__(
649
-                        'If not automatically redirected in %1$s seconds, click here to return to the %2$sRegistrations List Table%3$s',
650
-                        'event_espresso'
651
-                    ),
652
-                    '<span id="ee-redirect-timer">10</span>',
653
-                    '<a href="' . $job_parameters->request_datum('return_url') . '">',
654
-                    '</a>'
655
-                )
656
-            )
657
-        );
658
-
659
-        return new JobStepResponse($job_parameters, $this->feedback);
660
-    }
42
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
43
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
44
+	/**
45
+	 * Performs any necessary setup for starting the job. This is also a good
46
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
47
+	 * when continue_job will be called
48
+	 *
49
+	 * @param JobParameters $job_parameters
50
+	 * @return JobStepResponse
51
+	 * @throws BatchRequestException
52
+	 * @throws EE_Error
53
+	 * @throws ReflectionException
54
+	 */
55
+	public function create_job(JobParameters $job_parameters)
56
+	{
57
+		$event_id = absint($job_parameters->request_datum('EVT_ID', '0'));
58
+		if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
59
+			throw new BatchRequestException(
60
+				esc_html__('You do not have permission to view registrations', 'event_espresso')
61
+			);
62
+		}
63
+		$filepath = $this->create_file_from_job_with_name(
64
+			$job_parameters->job_id(),
65
+			$this->get_filename()
66
+		);
67
+		$job_parameters->add_extra_data('filepath', $filepath);
68
+		if ($job_parameters->request_datum('use_filters', false)) {
69
+			$query_params = maybe_unserialize($job_parameters->request_datum('filters', []));
70
+		} else {
71
+			$query_params = apply_filters(
72
+				'FHEE__EE_Export__report_registration_for_event',
73
+				[
74
+					[
75
+						'OR'                 => [
76
+							// don't include registrations from failed or abandoned transactions...
77
+							'Transaction.STS_ID' => [
78
+								'NOT IN',
79
+								[
80
+									EEM_Transaction::failed_status_code,
81
+									EEM_Transaction::abandoned_status_code,
82
+								],
83
+							],
84
+							// unless the registration is approved,
85
+							// in which case include it regardless of transaction status
86
+							'STS_ID'             => EEM_Registration::status_id_approved,
87
+						],
88
+						'Ticket.TKT_deleted' => ['IN', [true, false]],
89
+					],
90
+					'order_by'   => ['Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'],
91
+					'force_join' => ['Transaction', 'Ticket', 'Attendee'],
92
+					'caps'       => EEM_Base::caps_read_admin,
93
+				],
94
+				$event_id
95
+			);
96
+			if ($event_id) {
97
+				$query_params[0]['EVT_ID'] = $event_id;
98
+			} else {
99
+				$query_params['force_join'][] = 'Event';
100
+			}
101
+		}
102
+
103
+		if (! isset($query_params['force_join'])) {
104
+			$query_params['force_join'] = ['Event', 'Transaction', 'Ticket', 'Attendee'];
105
+		}
106
+		$job_parameters->add_extra_data('query_params', $query_params);
107
+		$question_labels = $this->_get_question_labels($query_params);
108
+		$job_parameters->add_extra_data('question_labels', $question_labels);
109
+		$job_parameters->set_job_size(
110
+			EEM_Registration::instance()->count(
111
+				array_diff_key(
112
+					$query_params,
113
+					array_flip(['limit'])
114
+				)
115
+			)
116
+		);
117
+		// we need to set the header columns
118
+		// but to do that we need to process one row so that we can extract ALL of the column headers
119
+		$csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $question_labels, $query_params);
120
+		// but we don't want to write any actual data yet...
121
+		// so let's blank out all of the values for that first row
122
+		array_walk(
123
+			$csv_data_for_row[0],
124
+			function (&$value) {
125
+				$value = null;
126
+			}
127
+		);
128
+		EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true, true);
129
+		$this->updateTextHeader(
130
+			esc_html__('Registrations report started successfully...', 'event_espresso')
131
+		);
132
+		return new JobStepResponse($job_parameters, $this->feedback);
133
+	}
134
+
135
+
136
+	/**
137
+	 * Gets the filename
138
+	 *
139
+	 * @return string
140
+	 */
141
+	protected function get_filename(): string
142
+	{
143
+		return apply_filters(
144
+			'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
145
+			sprintf(
146
+				'event-espresso-registrations-%s.csv',
147
+				str_replace([':', ' '], '-', current_time('mysql'))
148
+			)
149
+		);
150
+	}
151
+
152
+
153
+	/**
154
+	 * Gets the questions which are to be used for this report, so they
155
+	 * can be remembered for later
156
+	 *
157
+	 * @param array $registration_query_params
158
+	 * @return array question admin labels to be used for this report
159
+	 * @throws EE_Error
160
+	 * @throws ReflectionException
161
+	 */
162
+	protected function _get_question_labels(array $registration_query_params): array
163
+	{
164
+		$where                 = $registration_query_params[0] ?? null;
165
+		$question_query_params = [];
166
+		if ($where !== null) {
167
+			$question_query_params = [
168
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
169
+			];
170
+		}
171
+		// Make sure it's not a system question
172
+		$question_query_params[0]['OR*not-system-questions'] = [
173
+			'QST_system'      => '',
174
+			'QST_system*null' => ['IS_NULL'],
175
+		];
176
+		if (
177
+			apply_filters(
178
+				'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
179
+				false,
180
+				$registration_query_params
181
+			)
182
+		) {
183
+			$question_query_params[0]['Answer.ANS_ID'] = ['IS_NOT_NULL'];
184
+		}
185
+		$question_query_params['group_by'] = ['QST_ID'];
186
+		return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
187
+	}
188
+
189
+
190
+	/**
191
+	 * Takes where params meant for registrations and changes them to work for questions
192
+	 *
193
+	 * @param array $reg_where_params
194
+	 * @return array
195
+	 * @throws EE_Error
196
+	 * @throws ReflectionException
197
+	 */
198
+	protected function _change_registration_where_params_to_question_where_params(array $reg_where_params): array
199
+	{
200
+		$question_where_params = [];
201
+		foreach ($reg_where_params as $key => $val) {
202
+			if (EEM_Registration::instance()->is_logic_query_param_key($key)) {
203
+				$question_where_params[ $key ] =
204
+					$this->_change_registration_where_params_to_question_where_params($val);
205
+			} else {
206
+				// it's a normal where condition
207
+				$question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
208
+			}
209
+		}
210
+		return $question_where_params;
211
+	}
212
+
213
+
214
+	/**
215
+	 * Performs another step of the job
216
+	 *
217
+	 * @param JobParameters $job_parameters
218
+	 * @param int           $batch_size
219
+	 * @return JobStepResponse
220
+	 * @throws EE_Error
221
+	 * @throws ReflectionException
222
+	 */
223
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
224
+	{
225
+		if ($job_parameters->units_processed() < $job_parameters->job_size()) {
226
+			$csv_data = $this->get_csv_data_for(
227
+				$job_parameters->request_datum('EVT_ID', '0'),
228
+				$job_parameters->units_processed(),
229
+				$batch_size,
230
+				$job_parameters->extra_datum('question_labels'),
231
+				$job_parameters->extra_datum('query_params')
232
+			);
233
+			EEH_Export::write_data_array_to_csv(
234
+				$job_parameters->extra_datum('filepath'),
235
+				$csv_data,
236
+				false
237
+			);
238
+			$units_processed = count($csv_data);
239
+			if ($units_processed) {
240
+				$job_parameters->mark_processed($units_processed);
241
+				$this->updateText(
242
+					sprintf(
243
+						esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'),
244
+						$units_processed
245
+					)
246
+				);
247
+			}
248
+		}
249
+		$extra_response_data = ['file_url' => ''];
250
+		if ($job_parameters->units_processed() >= $job_parameters->job_size()) {
251
+			$job_parameters->set_status(JobParameters::status_complete);
252
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
253
+			$this->displayJobFinalResults($job_parameters);
254
+		} else {
255
+			$job_parameters->set_status(JobParameters::status_continue);
256
+		}
257
+		return new JobStepResponse($job_parameters, $this->feedback, $extra_response_data);
258
+	}
259
+
260
+
261
+	/**
262
+	 * Gets the csv data for a batch of registrations
263
+	 *
264
+	 * @param int|null $event_id
265
+	 * @param int      $offset
266
+	 * @param int      $limit
267
+	 * @param array    $question_labels the IDs for all the questions which were answered by someone in this selection
268
+	 * @param array    $query_params    for using where querying the model
269
+	 * @return array top-level keys are numeric, next-level keys are column headers
270
+	 * @throws EE_Error
271
+	 * @throws ReflectionException
272
+	 */
273
+	public function get_csv_data_for(
274
+		?int  $event_id,
275
+		int   $offset,
276
+		int   $limit,
277
+		array $question_labels,
278
+		array $query_params
279
+	): array {
280
+		$reg_fields_to_include = [
281
+			'TXN_ID',
282
+			'ATT_ID',
283
+			'REG_ID',
284
+			'REG_date',
285
+			'REG_code',
286
+			'REG_count',
287
+			'REG_final_price',
288
+		];
289
+		$att_fields_to_include = [
290
+			'ATT_fname',
291
+			'ATT_lname',
292
+			'ATT_email',
293
+			'ATT_address',
294
+			'ATT_address2',
295
+			'ATT_city',
296
+			'STA_ID',
297
+			'CNT_ISO',
298
+			'ATT_zip',
299
+			'ATT_phone',
300
+		];
301
+
302
+		// get models
303
+		$event_model   = EEM_Event::instance();
304
+		$date_model    = EEM_Datetime::instance();
305
+		$ticket_model  = EEM_Ticket::instance();
306
+		$txn_model     = EEM_Transaction::instance();
307
+		$reg_model     = EEM_Registration::instance();
308
+		$att_model     = EEM_Attendee::instance();
309
+		$pay_model     = EEM_Payment::instance();
310
+		$status_model  = EEM_Status::instance();
311
+		$qst_model     = EEM_Question::instance();
312
+		$answer_model  = EEM_Answer::instance();
313
+		$state_model   = EEM_State::instance();
314
+		$country_model = EEM_Country::instance();
315
+
316
+		$registrations_csv_ready_array = [];
317
+		$query_params['limit']         = [$offset, $limit];
318
+		$registration_rows             = $reg_model->get_all_wpdb_results($query_params);
319
+
320
+		foreach ($registration_rows as $reg_row) {
321
+			if (is_array($reg_row)) {
322
+				$reg_csv_array = [];
323
+				// ALL registrations, or is list filtered to just one?
324
+				if (! $event_id) {
325
+					// ALL registrations, so get each event's name and ID
326
+					$reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf(
327
+						/* translators: 1: event name, 2: event ID */
328
+						esc_html__('%1$s (%2$s)', 'event_espresso'),
329
+						EEH_Export::prepare_value_from_db_for_display(
330
+							$event_model,
331
+							'EVT_name',
332
+							$reg_row['Event_CPT.post_title']
333
+						),
334
+						$reg_row['Event_CPT.ID']
335
+					);
336
+				}
337
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1';
338
+
339
+				foreach ($reg_fields_to_include as $field_name) {
340
+					$field = $reg_model->field_settings_for($field_name);
341
+					switch ($field_name) {
342
+						case 'REG_final_price':
343
+							$value = EEH_Export::prepare_value_from_db_for_display(
344
+								$reg_model,
345
+								$field_name,
346
+								$reg_row['Registration.REG_final_price'],
347
+								'localized_float'
348
+							);
349
+							break;
350
+						case 'REG_count':
351
+							$value = sprintf(
352
+								/* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
353
+								esc_html__('%1$s of %2$s', 'event_espresso'),
354
+								EEH_Export::prepare_value_from_db_for_display(
355
+									$reg_model,
356
+									'REG_count',
357
+									$reg_row['Registration.REG_count']
358
+								),
359
+								EEH_Export::prepare_value_from_db_for_display(
360
+									$reg_model,
361
+									'REG_group_size',
362
+									$reg_row['Registration.REG_group_size']
363
+								)
364
+							);
365
+							break;
366
+						case 'REG_date':
367
+							$value = EEH_Export::prepare_value_from_db_for_display(
368
+								$reg_model,
369
+								$field_name,
370
+								$reg_row['Registration.REG_date'],
371
+								'no_html'
372
+							);
373
+							break;
374
+						default:
375
+							$value = EEH_Export::prepare_value_from_db_for_display(
376
+								$reg_model,
377
+								$field_name,
378
+								$reg_row[ $field->get_qualified_column() ]
379
+							);
380
+					}
381
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
382
+					if ($field_name == 'REG_final_price') {
383
+						// add a column named Currency after the final price
384
+						$reg_csv_array[ esc_html__('Currency', 'event_espresso') ] =
385
+							EE_Config::instance()->currency->code;
386
+					}
387
+				}
388
+
389
+				// get pretty status
390
+				$stati = $status_model->localized_status(
391
+					[
392
+						$reg_row['Registration.STS_ID']     => esc_html__('unknown', 'event_espresso'),
393
+						$reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'),
394
+					],
395
+					false,
396
+					'sentence'
397
+				);
398
+
399
+				$reg_csv_array[ esc_html__('Registration Status', 'event_espresso') ] =
400
+					$stati[ $reg_row['Registration.STS_ID'] ];
401
+				// get pretty transaction status
402
+				$reg_csv_array[ esc_html__('Transaction Status', 'event_espresso') ]     =
403
+					$stati[ $reg_row['TransactionTable.STS_ID'] ];
404
+				$reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
405
+					? EEH_Export::prepare_value_from_db_for_display(
406
+						$txn_model,
407
+						'TXN_total',
408
+						$reg_row['TransactionTable.TXN_total'],
409
+						'localized_float'
410
+					)
411
+					: '0.00';
412
+
413
+				$reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg
414
+					? EEH_Export::prepare_value_from_db_for_display(
415
+						$txn_model,
416
+						'TXN_paid',
417
+						$reg_row['TransactionTable.TXN_paid'],
418
+						'localized_float'
419
+					)
420
+					: '0.00';
421
+
422
+				$payment_methods     = [];
423
+				$gateway_txn_ids_etc = [];
424
+				$payment_times       = [];
425
+
426
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
427
+					$payments_info = $pay_model->get_all_wpdb_results(
428
+						[
429
+							[
430
+								'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
431
+								'STS_ID' => EEM_Payment::status_id_approved,
432
+							],
433
+							'force_join' => ['Payment_Method'],
434
+						],
435
+						ARRAY_A,
436
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
437
+					);
438
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
439
+						$payment_methods[]     = $payment_method_and_gateway_txn_id['name']
440
+												 ?? esc_html__('Unknown', 'event_espresso');
441
+						$gateway_txn_ids_etc[] = $payment_method_and_gateway_txn_id['gateway_txn_id'] ?? '';
442
+						$payment_times[]       = $payment_method_and_gateway_txn_id['payment_time'] ?? '';
443
+					}
444
+				}
445
+				$reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode(
446
+					',',
447
+					$payment_times
448
+				);
449
+
450
+				$reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode(
451
+					',',
452
+					$payment_methods
453
+				);
454
+
455
+				$reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
456
+					',',
457
+					$gateway_txn_ids_etc
458
+				);
459
+
460
+				// get whether or not the user has checked in
461
+				$reg_csv_array[ esc_html__('Check-Ins', 'event_espresso') ] = $reg_model->count_related(
462
+					$reg_row['Registration.REG_ID'],
463
+					'Checkin'
464
+				);
465
+
466
+				$ticket_name      = esc_html__('Unknown', 'event_espresso');
467
+				$datetime_strings = [esc_html__('Unknown', 'event_espresso')];
468
+
469
+				// get ticket of registration and its price
470
+				if ($reg_row['Ticket.TKT_ID']) {
471
+					$ticket_name      = EEH_Export::prepare_value_from_db_for_display(
472
+						$ticket_model,
473
+						'TKT_name',
474
+						$reg_row['Ticket.TKT_name']
475
+					);
476
+					$datetime_strings = [];
477
+					$datetimes        = $date_model->get_all_wpdb_results(
478
+						[
479
+							['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']],
480
+							'order_by'                 => ['DTT_EVT_start' => 'ASC'],
481
+							'default_where_conditions' => 'none',
482
+						]
483
+					);
484
+					foreach ($datetimes as $datetime) {
485
+						$datetime_strings[] = EEH_Export::prepare_value_from_db_for_display(
486
+							$date_model,
487
+							'DTT_EVT_start',
488
+							$datetime['Datetime.DTT_EVT_start']
489
+						);
490
+					}
491
+				}
492
+
493
+				$reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
494
+
495
+				$reg_csv_array[ esc_html__('Ticket Datetimes', 'event_espresso') ] = implode(
496
+					', ',
497
+					$datetime_strings
498
+				);
499
+
500
+				// get datetime(s) of registration
501
+				// add attendee columns
502
+				foreach ($att_fields_to_include as $att_field_name) {
503
+					$field_obj = $att_model->field_settings_for($att_field_name);
504
+					$value     = '';
505
+					if ($reg_row['Attendee_CPT.ID']) {
506
+						switch ($att_field_name) {
507
+							case 'STA_ID':
508
+								$value = $state_model->get_var(
509
+									[['STA_ID' => $reg_row['Attendee_Meta.STA_ID']]],
510
+									'STA_name'
511
+								);
512
+								break;
513
+							case 'CNT_ISO':
514
+								$value = $country_model->get_var(
515
+									[['CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO']]],
516
+									'CNT_name'
517
+								);
518
+								break;
519
+							default:
520
+								$value = EEH_Export::prepare_value_from_db_for_display(
521
+									$att_model,
522
+									$att_field_name,
523
+									$reg_row[ $field_obj->get_qualified_column() ]
524
+								);
525
+						}
526
+					}
527
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
528
+				}
529
+				// make sure each registration has the same questions in the same order
530
+				foreach ($question_labels as $question_label) {
531
+					if (! isset($reg_csv_array[ $question_label ])) {
532
+						$reg_csv_array[ $question_label ] = null;
533
+					}
534
+				}
535
+				$answers = $answer_model->get_all_wpdb_results(
536
+					[
537
+						['REG_ID' => $reg_row['Registration.REG_ID']],
538
+						'force_join' => ['Question'],
539
+					]
540
+				);
541
+				// now fill out the questions THEY answered
542
+				foreach ($answers as $answer_row) {
543
+					if ($answer_row['Question.QST_system']) {
544
+						// it's an answer to a system question. That was already displayed as part of the attendee
545
+						// fields, so don't write it out again thanks.
546
+						continue;
547
+					}
548
+
549
+					$question_label = $answer_row['Question.QST_ID']
550
+						? EEH_Export::prepare_value_from_db_for_display(
551
+							$qst_model,
552
+							'QST_admin_label',
553
+							$answer_row['Question.QST_admin_label']
554
+						)
555
+						: sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
556
+
557
+					$reg_csv_array[ $question_label ] = isset($answer_row['Question.QST_type'])
558
+														&& $answer_row['Question.QST_type']
559
+														   === EEM_Question::QST_type_state
560
+						? $state_model->get_state_name_by_ID($answer_row['Answer.ANS_value'])
561
+						// this isn't for html, so don't show html entities
562
+						: html_entity_decode(
563
+							EEH_Export::prepare_value_from_db_for_display(
564
+								$answer_model,
565
+								'ANS_value',
566
+								$answer_row['Answer.ANS_value']
567
+							)
568
+						);
569
+				}
570
+
571
+				/**
572
+				 * Filter to change the contents of each row of the registrations report CSV file.
573
+				 * This can be used to add or remote columns from the CSV file, or change their values.
574
+				 * Note when using: all rows in the CSV should have the same columns.
575
+				 *
576
+				 * @param array $reg_csv_array keys are the column names, values are their cell values
577
+				 * @param array $reg_row       one entry from EEM_Registration::get_all_wpdb_results()
578
+				 */
579
+				$registrations_csv_ready_array[] = apply_filters(
580
+					'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
581
+					$reg_csv_array,
582
+					$reg_row
583
+				);
584
+			}
585
+		}
586
+
587
+		// if we couldn't export anything, we want to at least show the column headers
588
+		if (empty($registrations_csv_ready_array)) {
589
+			$reg_csv_array               = [];
590
+			$model_and_fields_to_include = [
591
+				'Registration' => $reg_fields_to_include,
592
+				'Attendee'     => $att_fields_to_include,
593
+			];
594
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
595
+				$model = EE_Registry::instance()->load_model($model_name);
596
+				foreach ($field_list as $field_name) {
597
+					$field                                                          =
598
+						$model->field_settings_for($field_name);
599
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
600
+				}
601
+			}
602
+			$registrations_csv_ready_array[] = $reg_csv_array;
603
+		}
604
+		return $registrations_csv_ready_array;
605
+	}
606
+
607
+
608
+	/**
609
+	 * Counts total unit to process
610
+	 *
611
+	 * @param int|array $event_id
612
+	 * @return int
613
+	 * @throws EE_Error
614
+	 * @throws ReflectionException
615
+	 * @deprecated since 4.9.19
616
+	 */
617
+	public function count_units_to_process($event_id): int
618
+	{
619
+		// use the legacy filter
620
+		if ($event_id) {
621
+			$query_params[0]['EVT_ID'] = $event_id;
622
+		} else {
623
+			$query_params['force_join'][] = 'Event';
624
+		}
625
+		return EEM_Registration::instance()->count($query_params);
626
+	}
627
+
628
+
629
+	/**
630
+	 * Performs any clean-up logic when we know the job is completed.
631
+	 * In this case, we delete the temporary file
632
+	 *
633
+	 * @param JobParameters $job_parameters
634
+	 * @return JobStepResponse
635
+	 */
636
+	public function cleanup_job(JobParameters $job_parameters)
637
+	{
638
+		$this->updateText(esc_html__('File Generation complete and downloaded', 'event_espresso'));
639
+		$this->_file_helper->delete(
640
+			EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
641
+			true,
642
+			'd'
643
+		);
644
+		$this->updateText(esc_html__('Cleaned up temporary file', 'event_espresso'));
645
+		$this->updateText(
646
+			$this->infoWrapper(
647
+				sprintf(
648
+					esc_html__(
649
+						'If not automatically redirected in %1$s seconds, click here to return to the %2$sRegistrations List Table%3$s',
650
+						'event_espresso'
651
+					),
652
+					'<span id="ee-redirect-timer">10</span>',
653
+					'<a href="' . $job_parameters->request_datum('return_url') . '">',
654
+					'</a>'
655
+				)
656
+			)
657
+		);
658
+
659
+		return new JobStepResponse($job_parameters, $this->feedback);
660
+	}
661 661
 }
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
     public function create_job(JobParameters $job_parameters)
56 56
     {
57 57
         $event_id = absint($job_parameters->request_datum('EVT_ID', '0'));
58
-        if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
58
+        if ( ! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
59 59
             throw new BatchRequestException(
60 60
                 esc_html__('You do not have permission to view registrations', 'event_espresso')
61 61
             );
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
             }
101 101
         }
102 102
 
103
-        if (! isset($query_params['force_join'])) {
103
+        if ( ! isset($query_params['force_join'])) {
104 104
             $query_params['force_join'] = ['Event', 'Transaction', 'Ticket', 'Attendee'];
105 105
         }
106 106
         $job_parameters->add_extra_data('query_params', $query_params);
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
         // so let's blank out all of the values for that first row
122 122
         array_walk(
123 123
             $csv_data_for_row[0],
124
-            function (&$value) {
124
+            function(&$value) {
125 125
                 $value = null;
126 126
             }
127 127
         );
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
         $question_where_params = [];
201 201
         foreach ($reg_where_params as $key => $val) {
202 202
             if (EEM_Registration::instance()->is_logic_query_param_key($key)) {
203
-                $question_where_params[ $key ] =
203
+                $question_where_params[$key] =
204 204
                     $this->_change_registration_where_params_to_question_where_params($val);
205 205
             } else {
206 206
                 // it's a normal where condition
207
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
207
+                $question_where_params['Question_Group.Event.Registration.'.$key] = $val;
208 208
             }
209 209
         }
210 210
         return $question_where_params;
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
             if (is_array($reg_row)) {
322 322
                 $reg_csv_array = [];
323 323
                 // ALL registrations, or is list filtered to just one?
324
-                if (! $event_id) {
324
+                if ( ! $event_id) {
325 325
                     // ALL registrations, so get each event's name and ID
326
-                    $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf(
326
+                    $reg_csv_array[esc_html__('Event', 'event_espresso')] = sprintf(
327 327
                         /* translators: 1: event name, 2: event ID */
328 328
                         esc_html__('%1$s (%2$s)', 'event_espresso'),
329 329
                         EEH_Export::prepare_value_from_db_for_display(
@@ -375,13 +375,13 @@  discard block
 block discarded – undo
375 375
                             $value = EEH_Export::prepare_value_from_db_for_display(
376 376
                                 $reg_model,
377 377
                                 $field_name,
378
-                                $reg_row[ $field->get_qualified_column() ]
378
+                                $reg_row[$field->get_qualified_column()]
379 379
                             );
380 380
                     }
381
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
381
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = $value;
382 382
                     if ($field_name == 'REG_final_price') {
383 383
                         // add a column named Currency after the final price
384
-                        $reg_csv_array[ esc_html__('Currency', 'event_espresso') ] =
384
+                        $reg_csv_array[esc_html__('Currency', 'event_espresso')] =
385 385
                             EE_Config::instance()->currency->code;
386 386
                     }
387 387
                 }
@@ -396,12 +396,12 @@  discard block
 block discarded – undo
396 396
                     'sentence'
397 397
                 );
398 398
 
399
-                $reg_csv_array[ esc_html__('Registration Status', 'event_espresso') ] =
400
-                    $stati[ $reg_row['Registration.STS_ID'] ];
399
+                $reg_csv_array[esc_html__('Registration Status', 'event_espresso')] =
400
+                    $stati[$reg_row['Registration.STS_ID']];
401 401
                 // get pretty transaction status
402
-                $reg_csv_array[ esc_html__('Transaction Status', 'event_espresso') ]     =
403
-                    $stati[ $reg_row['TransactionTable.STS_ID'] ];
404
-                $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
402
+                $reg_csv_array[esc_html__('Transaction Status', 'event_espresso')]     =
403
+                    $stati[$reg_row['TransactionTable.STS_ID']];
404
+                $reg_csv_array[esc_html__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
405 405
                     ? EEH_Export::prepare_value_from_db_for_display(
406 406
                         $txn_model,
407 407
                         'TXN_total',
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
                     )
411 411
                     : '0.00';
412 412
 
413
-                $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg
413
+                $reg_csv_array[esc_html__('Amount Paid', 'event_espresso')] = $is_primary_reg
414 414
                     ? EEH_Export::prepare_value_from_db_for_display(
415 415
                         $txn_model,
416 416
                         'TXN_paid',
@@ -442,23 +442,23 @@  discard block
 block discarded – undo
442 442
                         $payment_times[]       = $payment_method_and_gateway_txn_id['payment_time'] ?? '';
443 443
                     }
444 444
                 }
445
-                $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode(
445
+                $reg_csv_array[esc_html__('Payment Date(s)', 'event_espresso')] = implode(
446 446
                     ',',
447 447
                     $payment_times
448 448
                 );
449 449
 
450
-                $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode(
450
+                $reg_csv_array[esc_html__('Payment Method(s)', 'event_espresso')] = implode(
451 451
                     ',',
452 452
                     $payment_methods
453 453
                 );
454 454
 
455
-                $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
455
+                $reg_csv_array[esc_html__('Gateway Transaction ID(s)', 'event_espresso')] = implode(
456 456
                     ',',
457 457
                     $gateway_txn_ids_etc
458 458
                 );
459 459
 
460 460
                 // get whether or not the user has checked in
461
-                $reg_csv_array[ esc_html__('Check-Ins', 'event_espresso') ] = $reg_model->count_related(
461
+                $reg_csv_array[esc_html__('Check-Ins', 'event_espresso')] = $reg_model->count_related(
462 462
                     $reg_row['Registration.REG_ID'],
463 463
                     'Checkin'
464 464
                 );
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 
469 469
                 // get ticket of registration and its price
470 470
                 if ($reg_row['Ticket.TKT_ID']) {
471
-                    $ticket_name      = EEH_Export::prepare_value_from_db_for_display(
471
+                    $ticket_name = EEH_Export::prepare_value_from_db_for_display(
472 472
                         $ticket_model,
473 473
                         'TKT_name',
474 474
                         $reg_row['Ticket.TKT_name']
@@ -490,9 +490,9 @@  discard block
 block discarded – undo
490 490
                     }
491 491
                 }
492 492
 
493
-                $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
493
+                $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
494 494
 
495
-                $reg_csv_array[ esc_html__('Ticket Datetimes', 'event_espresso') ] = implode(
495
+                $reg_csv_array[esc_html__('Ticket Datetimes', 'event_espresso')] = implode(
496 496
                     ', ',
497 497
                     $datetime_strings
498 498
                 );
@@ -520,16 +520,16 @@  discard block
 block discarded – undo
520 520
                                 $value = EEH_Export::prepare_value_from_db_for_display(
521 521
                                     $att_model,
522 522
                                     $att_field_name,
523
-                                    $reg_row[ $field_obj->get_qualified_column() ]
523
+                                    $reg_row[$field_obj->get_qualified_column()]
524 524
                                 );
525 525
                         }
526 526
                     }
527
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
527
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field_obj)] = $value;
528 528
                 }
529 529
                 // make sure each registration has the same questions in the same order
530 530
                 foreach ($question_labels as $question_label) {
531
-                    if (! isset($reg_csv_array[ $question_label ])) {
532
-                        $reg_csv_array[ $question_label ] = null;
531
+                    if ( ! isset($reg_csv_array[$question_label])) {
532
+                        $reg_csv_array[$question_label] = null;
533 533
                     }
534 534
                 }
535 535
                 $answers = $answer_model->get_all_wpdb_results(
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
                         )
555 555
                         : sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
556 556
 
557
-                    $reg_csv_array[ $question_label ] = isset($answer_row['Question.QST_type'])
557
+                    $reg_csv_array[$question_label] = isset($answer_row['Question.QST_type'])
558 558
                                                         && $answer_row['Question.QST_type']
559 559
                                                            === EEM_Question::QST_type_state
560 560
                         ? $state_model->get_state_name_by_ID($answer_row['Answer.ANS_value'])
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
                 foreach ($field_list as $field_name) {
597 597
                     $field                                                          =
598 598
                         $model->field_settings_for($field_name);
599
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
599
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null;
600 600
                 }
601 601
             }
602 602
             $registrations_csv_ready_array[] = $reg_csv_array;
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
                         'event_espresso'
651 651
                     ),
652 652
                     '<span id="ee-redirect-timer">10</span>',
653
-                    '<a href="' . $job_parameters->request_datum('return_url') . '">',
653
+                    '<a href="'.$job_parameters->request_datum('return_url').'">',
654 654
                     '</a>'
655 655
                 )
656 656
             )
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlerBaseClasses/JobHandlerFile.php 2 patches
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -19,144 +19,144 @@
 block discarded – undo
19 19
  */
20 20
 abstract class JobHandlerFile extends JobHandler
21 21
 {
22
-    // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
23
-    const temp_folder_name = 'batch_temp_folder';
24
-
25
-    // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
26
-
27
-    /**
28
-     * @var EEHI_File
29
-     */
30
-    protected $_file_helper = null;
31
-
32
-
33
-    /**
34
-     * JobHandlerFile constructor.
35
-     *
36
-     * @param EEHI_File|null $file_helper
37
-     */
38
-    public function __construct(EEHI_File $file_helper = null)
39
-    {
40
-        if (! $file_helper) {
41
-            $this->_file_helper = new EEH_File();
42
-        }
43
-    }
44
-
45
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
-
47
-
48
-    /**
49
-     * Creates a file
50
-     *
51
-     * @param string $job_id
52
-     * @param string $filename
53
-     * @param string $filetype
54
-     * @param string $bom initial content to place in the file.
55
-     * @return string
56
-     * @throws BatchRequestException
57
-     */
58
-    public function create_file_from_job_with_name(
59
-        string $job_id,
60
-        string $filename,
61
-        string $filetype = 'application/ms-excel',
62
-        string $bom = "\xEF\xBB\xBF"
63
-    ): string {
64
-        $filepath = '';
65
-        try {
66
-            $base_folder = $this->get_base_folder();
67
-            $success     = $this->_file_helper->ensure_folder_exists_and_is_writable(
68
-                $base_folder . JobHandlerFile::temp_folder_name
69
-            );
70
-            if ($success) {
71
-                $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
72
-                    $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id
73
-                );
74
-            }
75
-            if ($success) {
76
-                $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename;
77
-                $success  = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
78
-            }
79
-            // let's add the .htaccess file so safari will open the file properly
80
-            if ($success) {
81
-                $extension = EEH_File::get_file_extension($filepath);
82
-                EEH_File::write_to_file(
83
-                    $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess',
84
-                    'AddType ' . $filetype . ' ' . $extension,
85
-                    '.htaccess'
86
-                );
87
-            }
88
-            /**
89
-             * Filters what initial content will be added to the file.
90
-             *
91
-             * @param string $return_value  By default it's whatever was passed into
92
-             *                              JobHandlerFile::create_file_from_job_with_name()
93
-             * @param string $filename
94
-             * @param string $filetype default 'application/ms-excel'
95
-             * @param string $filepath
96
-             */
97
-            EEH_File::write_to_file(
98
-                $filepath,
99
-                apply_filters(
100
-                    'FHEE__EE_CSV__begin_sending_csv__start_writing',
101
-                    $bom,
102
-                    $filename,
103
-                    $filetype,
104
-                    $filepath
105
-                )
106
-            );
107
-            // those methods normally fail with an exception, but if not, let's do it
108
-            if (! $success) {
109
-                throw new EE_Error(
110
-                    esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso')
111
-                );
112
-            }
113
-        } catch (EE_Error $e) {
114
-            throw new BatchRequestException(
115
-                sprintf(
116
-                // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
117
-                    esc_html__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'),
118
-                    $job_id,
119
-                    $e->getMessage()
120
-                ),
121
-                500,
122
-                $e
123
-            );
124
-        }
125
-        return $filepath;
126
-    }
127
-
128
-
129
-    /**
130
-     * Gets the URL to download the file
131
-     *
132
-     * @param string $filepath
133
-     * @return string url to file
134
-     */
135
-    public function get_url_to_file(string $filepath): string
136
-    {
137
-        return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath);
138
-    }
139
-
140
-
141
-    /**
142
-     * Gets the folder which will contain the "batch_temp_folder"
143
-     *
144
-     * @return string
145
-     */
146
-    public function get_base_folder(): string
147
-    {
148
-        return apply_filters(
149
-            'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder',
150
-            EVENT_ESPRESSO_UPLOAD_DIR
151
-        );
152
-    }
153
-
154
-
155
-    public function get_base_url(): string
156
-    {
157
-        return apply_filters(
158
-            'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url',
159
-            EVENT_ESPRESSO_UPLOAD_URL
160
-        );
161
-    }
22
+	// phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase
23
+	const temp_folder_name = 'batch_temp_folder';
24
+
25
+	// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore
26
+
27
+	/**
28
+	 * @var EEHI_File
29
+	 */
30
+	protected $_file_helper = null;
31
+
32
+
33
+	/**
34
+	 * JobHandlerFile constructor.
35
+	 *
36
+	 * @param EEHI_File|null $file_helper
37
+	 */
38
+	public function __construct(EEHI_File $file_helper = null)
39
+	{
40
+		if (! $file_helper) {
41
+			$this->_file_helper = new EEH_File();
42
+		}
43
+	}
44
+
45
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
+
47
+
48
+	/**
49
+	 * Creates a file
50
+	 *
51
+	 * @param string $job_id
52
+	 * @param string $filename
53
+	 * @param string $filetype
54
+	 * @param string $bom initial content to place in the file.
55
+	 * @return string
56
+	 * @throws BatchRequestException
57
+	 */
58
+	public function create_file_from_job_with_name(
59
+		string $job_id,
60
+		string $filename,
61
+		string $filetype = 'application/ms-excel',
62
+		string $bom = "\xEF\xBB\xBF"
63
+	): string {
64
+		$filepath = '';
65
+		try {
66
+			$base_folder = $this->get_base_folder();
67
+			$success     = $this->_file_helper->ensure_folder_exists_and_is_writable(
68
+				$base_folder . JobHandlerFile::temp_folder_name
69
+			);
70
+			if ($success) {
71
+				$success = $this->_file_helper->ensure_folder_exists_and_is_writable(
72
+					$base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id
73
+				);
74
+			}
75
+			if ($success) {
76
+				$filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename;
77
+				$success  = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
78
+			}
79
+			// let's add the .htaccess file so safari will open the file properly
80
+			if ($success) {
81
+				$extension = EEH_File::get_file_extension($filepath);
82
+				EEH_File::write_to_file(
83
+					$base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess',
84
+					'AddType ' . $filetype . ' ' . $extension,
85
+					'.htaccess'
86
+				);
87
+			}
88
+			/**
89
+			 * Filters what initial content will be added to the file.
90
+			 *
91
+			 * @param string $return_value  By default it's whatever was passed into
92
+			 *                              JobHandlerFile::create_file_from_job_with_name()
93
+			 * @param string $filename
94
+			 * @param string $filetype default 'application/ms-excel'
95
+			 * @param string $filepath
96
+			 */
97
+			EEH_File::write_to_file(
98
+				$filepath,
99
+				apply_filters(
100
+					'FHEE__EE_CSV__begin_sending_csv__start_writing',
101
+					$bom,
102
+					$filename,
103
+					$filetype,
104
+					$filepath
105
+				)
106
+			);
107
+			// those methods normally fail with an exception, but if not, let's do it
108
+			if (! $success) {
109
+				throw new EE_Error(
110
+					esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso')
111
+				);
112
+			}
113
+		} catch (EE_Error $e) {
114
+			throw new BatchRequestException(
115
+				sprintf(
116
+				// phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment
117
+					esc_html__('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'),
118
+					$job_id,
119
+					$e->getMessage()
120
+				),
121
+				500,
122
+				$e
123
+			);
124
+		}
125
+		return $filepath;
126
+	}
127
+
128
+
129
+	/**
130
+	 * Gets the URL to download the file
131
+	 *
132
+	 * @param string $filepath
133
+	 * @return string url to file
134
+	 */
135
+	public function get_url_to_file(string $filepath): string
136
+	{
137
+		return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath);
138
+	}
139
+
140
+
141
+	/**
142
+	 * Gets the folder which will contain the "batch_temp_folder"
143
+	 *
144
+	 * @return string
145
+	 */
146
+	public function get_base_folder(): string
147
+	{
148
+		return apply_filters(
149
+			'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder',
150
+			EVENT_ESPRESSO_UPLOAD_DIR
151
+		);
152
+	}
153
+
154
+
155
+	public function get_base_url(): string
156
+	{
157
+		return apply_filters(
158
+			'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url',
159
+			EVENT_ESPRESSO_UPLOAD_URL
160
+		);
161
+	}
162 162
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function __construct(EEHI_File $file_helper = null)
39 39
     {
40
-        if (! $file_helper) {
40
+        if ( ! $file_helper) {
41 41
             $this->_file_helper = new EEH_File();
42 42
         }
43 43
     }
@@ -65,23 +65,23 @@  discard block
 block discarded – undo
65 65
         try {
66 66
             $base_folder = $this->get_base_folder();
67 67
             $success     = $this->_file_helper->ensure_folder_exists_and_is_writable(
68
-                $base_folder . JobHandlerFile::temp_folder_name
68
+                $base_folder.JobHandlerFile::temp_folder_name
69 69
             );
70 70
             if ($success) {
71 71
                 $success = $this->_file_helper->ensure_folder_exists_and_is_writable(
72
-                    $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id
72
+                    $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id
73 73
                 );
74 74
             }
75 75
             if ($success) {
76
-                $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename;
76
+                $filepath = $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/'.$filename;
77 77
                 $success  = $this->_file_helper->ensure_file_exists_and_is_writable($filepath);
78 78
             }
79 79
             // let's add the .htaccess file so safari will open the file properly
80 80
             if ($success) {
81 81
                 $extension = EEH_File::get_file_extension($filepath);
82 82
                 EEH_File::write_to_file(
83
-                    $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess',
84
-                    'AddType ' . $filetype . ' ' . $extension,
83
+                    $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/.htaccess',
84
+                    'AddType '.$filetype.' '.$extension,
85 85
                     '.htaccess'
86 86
                 );
87 87
             }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
                 )
106 106
             );
107 107
             // those methods normally fail with an exception, but if not, let's do it
108
-            if (! $success) {
108
+            if ( ! $success) {
109 109
                 throw new EE_Error(
110 110
                     esc_html__('Could not create temporary file, an unknown error occurred', 'event_espresso')
111 111
                 );
Please login to merge, or discard this patch.
core/libraries/batch/JobHandlerBaseClasses/JobHandler.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	public function getRequestData($key)
134 134
 	{
135
-		return $this->request_data[ $key] ?? null;
135
+		return $this->request_data[$key] ?? null;
136 136
 	}
137 137
 
138 138
 
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	{
180 180
 		$this->feedback[] = '
181 181
 			<div class="ee-batch-job-step-results">
182
-				' . $this->infoWrapper("processed this batch: $processed") . '
182
+				' . $this->infoWrapper("processed this batch: $processed").'
183 183
 			</div>';
184 184
 	}
185 185
 
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 		if ($job_parameters->status() === JobParameters::status_complete) {
190 190
 			$this->feedback[] = '
191 191
 			<div class="ee-batch-job-final-results">
192
-				' . $this->okWrapper("total units processed: {$job_parameters->units_processed()}") . '
193
-				' . $this->jobStatusNotice($job_parameters) . '
192
+				' . $this->okWrapper("total units processed: {$job_parameters->units_processed()}").'
193
+				' . $this->jobStatusNotice($job_parameters).'
194 194
 			</div>';
195 195
 		}
196 196
 	}
Please login to merge, or discard this patch.
modules/batch/EED_Batch.module.php 2 patches
Indentation   +443 added lines, -443 removed lines patch added patch discarded remove patch
@@ -28,447 +28,447 @@
 block discarded – undo
28 28
  */
29 29
 class EED_Batch extends EED_Module
30 30
 {
31
-    public const PAGE_SLUG = 'espresso_batch';
32
-
33
-    /**
34
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
35
-     * processes data only
36
-     */
37
-    const batch_job = 'job';
38
-
39
-    /**
40
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
41
-     * produces a file for download
42
-     */
43
-    const batch_file_job = 'file';
44
-
45
-    /**
46
-     * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
47
-     * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
48
-     * at all
49
-     */
50
-    const batch_not_job = 'none';
51
-
52
-    /**
53
-     *
54
-     * @var string 'file', or 'job', or false to indicate its not a batch request at all
55
-     */
56
-    protected $_batch_request_type = '';
57
-
58
-    /**
59
-     * Because we want to use the response in both the localized JS and in the body
60
-     * we need to make this response available between method calls
61
-     *
62
-     * @var JobStepResponse|null
63
-     */
64
-    protected $_job_step_response = null;
65
-
66
-    /**
67
-     * @var LoaderInterface|null
68
-     */
69
-    protected $loader = null;
70
-
71
-
72
-    /**
73
-     * Gets the batch instance
74
-     *
75
-     * @return  EED_Module|EED_Batch
76
-     * @throws EE_Error
77
-     * @throws ReflectionException
78
-     */
79
-    public static function instance(): EED_Batch
80
-    {
81
-        return parent::get_instance(__CLASS__);
82
-    }
83
-
84
-
85
-    /**
86
-     * Sets hooks to enable batch jobs on the frontend. Disabled by default
87
-     * because it's an attack vector and there are currently no implementations
88
-     *
89
-     * @throws EE_Error
90
-     * @throws ReflectionException
91
-     */
92
-    public static function set_hooks()
93
-    {
94
-        // because this is a possible attack vector, let's have this disabled until
95
-        // we at least have a real use for it on the frontend
96
-        if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
97
-            add_action('wp_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
98
-            add_filter('template_include', [self::instance(), 'override_template'], 99);
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * Initializes some hooks for the admin in order to run batch jobs
105
-     *
106
-     * @throws EE_Error
107
-     * @throws ReflectionException
108
-     */
109
-    public static function set_hooks_admin()
110
-    {
111
-        add_action('admin_menu', [self::instance(), 'register_admin_pages']);
112
-        add_action('admin_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
113
-
114
-        // ajax
115
-        add_action('wp_ajax_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
116
-        add_action('wp_ajax_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
117
-        add_action('wp_ajax_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
118
-        add_action('wp_ajax_nopriv_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
119
-        add_action('wp_ajax_nopriv_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
120
-        add_action('wp_ajax_nopriv_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
121
-        add_filter(
122
-            'admin_body_class',
123
-            function ($classes) {
124
-                if (strpos($classes, 'espresso-admin') === false) {
125
-                    $classes .= ' espresso-admin';
126
-                }
127
-                return $classes;
128
-            }
129
-        );
130
-    }
131
-
132
-
133
-    /**
134
-     * @return LoaderInterface
135
-     * @throws InvalidArgumentException
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidInterfaceException
138
-     * @since 4.9.80.p
139
-     */
140
-    protected function getLoader(): LoaderInterface
141
-    {
142
-        if (! $this->loader instanceof LoaderInterface) {
143
-            $this->loader = LoaderFactory::getLoader();
144
-        }
145
-        return $this->loader;
146
-    }
147
-
148
-
149
-    /**
150
-     * Enqueues batch scripts on the frontend or admin, and creates a job
151
-     */
152
-    public function enqueue_scripts()
153
-    {
154
-        $request = EED_Batch::getRequest();
155
-        if (
156
-            $request->getRequestParam(EED_Batch::PAGE_SLUG)
157
-            || $request->getRequestParam('page') === EED_Batch::PAGE_SLUG
158
-        ) {
159
-            if (
160
-                ! $request->requestParamIsSet('default_nonce')
161
-                || ! wp_verify_nonce($request->getRequestParam('default_nonce'), 'default_nonce')
162
-            ) {
163
-                wp_die(
164
-                    esc_html__(
165
-                        'The link you clicked to start the batch job has expired. Please go back and refresh the previous page.',
166
-                        'event_espresso'
167
-                    )
168
-                );
169
-            }
170
-            switch ($this->batch_request_type()) {
171
-                case self::batch_job:
172
-                    $this->enqueue_scripts_styles_batch_create();
173
-                    break;
174
-                case self::batch_file_job:
175
-                    $this->enqueue_scripts_styles_batch_file_create();
176
-                    break;
177
-            }
178
-        }
179
-    }
180
-
181
-
182
-    /**
183
-     * Create a batch job, enqueues a script to run it, and localizes some data for it
184
-     */
185
-    public function enqueue_scripts_styles_batch_create()
186
-    {
187
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
188
-        wp_enqueue_script(
189
-            'batch_runner_init',
190
-            BATCH_URL . 'assets/batch_runner_init.js',
191
-            ['batch_runner'],
192
-            date('Y-m-d-H:i', time()),
193
-            true
194
-        );
195
-        wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
196
-        wp_localize_script('batch_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
197
-
198
-        $return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', 'url');
199
-        if ($return_url) {
200
-            wp_localize_script(
201
-                'batch_runner_init',
202
-                'ee_job_i18n',
203
-                [
204
-                    'return_url'                => $return_url,
205
-                    'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam(
206
-                        'auto_redirect_on_complete'
207
-                    ),
208
-                    'user_message'              => EED_Batch::getRequest()->getRequestParam('assessment_notice')
209
-                        ?: EED_Batch::getRequest()->getRequestParam('job_start_notice'),
210
-                ]
211
-            );
212
-        }
213
-    }
214
-
215
-
216
-    /**
217
-     * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
218
-     */
219
-    public function enqueue_scripts_styles_batch_file_create()
220
-    {
221
-        // creates a job based on the request variable
222
-        $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
223
-        wp_enqueue_script(
224
-            'batch_file_runner_init',
225
-            BATCH_URL . 'assets/batch_file_runner_init.js',
226
-            ['batch_runner'],
227
-            date('Y-m-d-H:i', time()),
228
-            true
229
-        );
230
-        wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
231
-        wp_localize_script('batch_file_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
232
-
233
-        $return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', 'url');
234
-        if ($return_url) {
235
-            wp_localize_script(
236
-                'batch_file_runner_init',
237
-                'ee_job_i18n',
238
-                ['return_url' => $return_url]
239
-            );
240
-        }
241
-    }
242
-
243
-
244
-    /**
245
-     * Enqueues scripts and styles common to any batch job, and creates
246
-     * a job from the request data, and stores the response in the
247
-     * $this->_job_step_response property
248
-     *
249
-     * @return JobStepResponse
250
-     */
251
-    protected function _enqueue_batch_job_scripts_and_styles_and_start_job(): JobStepResponse
252
-    {
253
-        // just copy the bits of EE admin's eei18n that we need in the JS
254
-        EE_Registry::$i18n_js_strings['batchJobError'] = __(
255
-            'An error occurred and the job has been stopped. Please refresh the page to try again.',
256
-            'event_espresso'
257
-        );
258
-        EE_Registry::$i18n_js_strings['is_admin']      = is_admin();
259
-        wp_enqueue_style(
260
-            EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN,
261
-            EE_ADMIN_URL . 'assets/ee-admin-page.css',
262
-            [],
263
-            EVENT_ESPRESSO_VERSION
264
-        );
265
-        wp_enqueue_style(
266
-            'batch_runner',
267
-            BATCH_URL . 'assets/batch_runner.css',
268
-            [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
269
-            date('Y-m-d-H:i', time())
270
-        );
271
-        wp_register_script(
272
-            'progress_bar',
273
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
274
-            ['jquery'],
275
-            date('Y-m-d-H:i', time()),
276
-            true
277
-        );
278
-        wp_enqueue_style(
279
-            'progress_bar',
280
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
281
-            [],
282
-            date('Y-m-d-H:i', time())
283
-        );
284
-        wp_enqueue_script(
285
-            'batch_runner',
286
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
287
-            ['progress_bar', CoreAssetManager::JS_HANDLE_CORE],
288
-            date('Y-m-d-H:i', time()),
289
-            true
290
-        );
291
-        /** @var BatchRequestProcessor $batch_runner */
292
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
293
-        // eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
294
-        // remember the response for later. We need it to display the page body
295
-        $this->_job_step_response = $batch_runner->createJob();
296
-        return $this->_job_step_response;
297
-    }
298
-
299
-
300
-    /**
301
-     * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
302
-     *
303
-     * @param string $template
304
-     * @return string
305
-     */
306
-    public function override_template(string $template): string
307
-    {
308
-        $request = EED_Batch::getRequest();
309
-        if ($request->requestParamIsSet('batch') && $request->requestParamIsSet(EED_Batch::PAGE_SLUG)) {
310
-            return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.php';
311
-        }
312
-        return $template;
313
-    }
314
-
315
-
316
-    /**
317
-     * Adds an admin page which doesn't appear in the admin menu
318
-     *
319
-     * @throws EE_Error
320
-     * @throws ReflectionException
321
-     */
322
-    public function register_admin_pages()
323
-    {
324
-        add_submenu_page(
325
-            '',
326
-            // parent slug. we don't want this to actually appear in the menu
327
-            esc_html__('Batch Job', 'event_espresso'),
328
-            // page title
329
-            'n/a',
330
-            // menu title
331
-            'read',
332
-            // we want this page to actually be accessible to anyone,
333
-            EED_Batch::PAGE_SLUG,
334
-            // menu slug
335
-            [self::instance(), 'show_admin_page']
336
-        );
337
-    }
338
-
339
-
340
-    /**
341
-     * Renders the admin page, after most of the work was already done during enqueuing scripts
342
-     * of creating the job and localizing some data
343
-     */
344
-    public function show_admin_page()
345
-    {
346
-        echo EEH_Template::locate_template(
347
-            EE_MODULES . 'batch/templates/batch_wrapper.template.php',
348
-            [
349
-                'batch_request_type'        => $this->batch_request_type(),
350
-                'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam('auto_redirect_on_complete'),
351
-                'user_message'              => EED_Batch::getRequest()->getRequestParam('assessment_notice')
352
-                    ?: EED_Batch::getRequest()->getRequestParam('job_start_notice'),
353
-            ]
354
-        );
355
-    }
356
-
357
-
358
-    private function runBatchRunnerJob(string $job)
359
-    {
360
-        $job_id = EED_Batch::getRequest()->getRequestParam('job_id');
361
-        /** @var BatchRequestProcessor $batch_runner */
362
-        $batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
363
-        $job_response = $batch_runner->{$job}($job_id);
364
-        $this->_return_json($job_response->to_array());
365
-    }
366
-
367
-
368
-    /**
369
-     * Receives ajax calls for continuing a job
370
-     */
371
-    public function continueBatchJob()
372
-    {
373
-        $this->runBatchRunnerJob('continueJob');
374
-    }
375
-
376
-
377
-    /**
378
-     * Receives ajax calls for continuing a job
379
-     */
380
-    public function advanceBatchJob()
381
-    {
382
-        $this->runBatchRunnerJob('advanceJob');
383
-    }
384
-
385
-
386
-    /**
387
-     * Receives the ajax call to cleanup a job
388
-     *
389
-     * @return void
390
-     */
391
-    public function cleanupBatchJob()
392
-    {
393
-        $this->runBatchRunnerJob('cleanupJob');
394
-    }
395
-
396
-
397
-    /**
398
-     * Returns a json response
399
-     *
400
-     * @param array $data The data we want to send echo via in the JSON response's "data" element
401
-     *
402
-     * The returned json object is created from an array in the following format:
403
-     * array(
404
-     *    'notices' => '', // - contains any EE_Error formatted notices
405
-     *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
406
-     *    We're also going to include the template args with every package (so js can pick out any specific template
407
-     *    args that might be included in here)
408
-     *    'isEEajax' => true,//indicates this is a response from EE
409
-     * )
410
-     */
411
-    protected function _return_json(array $data)
412
-    {
413
-        $json = [
414
-            'notices'  => EE_Error::get_notices(),
415
-            'data'     => $data,
416
-            'isEEajax' => true
417
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
418
-        ];
419
-
420
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
421
-        if (error_get_last() === null || ! headers_sent()) {
422
-            header('Content-Type: application/json; charset=UTF-8');
423
-            echo wp_json_encode($json);
424
-            exit();
425
-        }
426
-    }
427
-
428
-
429
-    /**
430
-     * Gets the job step response which was done during the enqueuing of scripts
431
-     *
432
-     * @return JobStepResponse
433
-     */
434
-    public function job_step_response(): JobStepResponse
435
-    {
436
-        return $this->_job_step_response;
437
-    }
438
-
439
-
440
-    /**
441
-     * Gets the batch request type indicated in the current request
442
-     *
443
-     * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
444
-     */
445
-    public function batch_request_type(): string
446
-    {
447
-        if (! $this->_batch_request_type) {
448
-            $request = EED_Batch::getRequest();
449
-            $batch   = $request->getRequestParam('batch');
450
-            switch ($batch) {
451
-                case self::batch_job:
452
-                    $this->_batch_request_type = self::batch_job;
453
-                    break;
454
-                case self::batch_file_job:
455
-                    $this->_batch_request_type = self::batch_file_job;
456
-                    break;
457
-                default:
458
-                    // if we didn't find that it was a batch request, indicate it wasn't
459
-                    $this->_batch_request_type = self::batch_not_job;
460
-            }
461
-        }
462
-        return $this->_batch_request_type;
463
-    }
464
-
465
-
466
-    /**
467
-     * Unnecessary
468
-     *
469
-     * @param WP $WP
470
-     */
471
-    public function run($WP)
472
-    {
473
-    }
31
+	public const PAGE_SLUG = 'espresso_batch';
32
+
33
+	/**
34
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
35
+	 * processes data only
36
+	 */
37
+	const batch_job = 'job';
38
+
39
+	/**
40
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates to run a job that
41
+	 * produces a file for download
42
+	 */
43
+	const batch_file_job = 'file';
44
+
45
+	/**
46
+	 * Possibly value for $_REQUEST[ 'batch' ]. Indicates this request is NOT
47
+	 * for a batch job. It's the same as not providing the $_REQUEST[ 'batch' ]
48
+	 * at all
49
+	 */
50
+	const batch_not_job = 'none';
51
+
52
+	/**
53
+	 *
54
+	 * @var string 'file', or 'job', or false to indicate its not a batch request at all
55
+	 */
56
+	protected $_batch_request_type = '';
57
+
58
+	/**
59
+	 * Because we want to use the response in both the localized JS and in the body
60
+	 * we need to make this response available between method calls
61
+	 *
62
+	 * @var JobStepResponse|null
63
+	 */
64
+	protected $_job_step_response = null;
65
+
66
+	/**
67
+	 * @var LoaderInterface|null
68
+	 */
69
+	protected $loader = null;
70
+
71
+
72
+	/**
73
+	 * Gets the batch instance
74
+	 *
75
+	 * @return  EED_Module|EED_Batch
76
+	 * @throws EE_Error
77
+	 * @throws ReflectionException
78
+	 */
79
+	public static function instance(): EED_Batch
80
+	{
81
+		return parent::get_instance(__CLASS__);
82
+	}
83
+
84
+
85
+	/**
86
+	 * Sets hooks to enable batch jobs on the frontend. Disabled by default
87
+	 * because it's an attack vector and there are currently no implementations
88
+	 *
89
+	 * @throws EE_Error
90
+	 * @throws ReflectionException
91
+	 */
92
+	public static function set_hooks()
93
+	{
94
+		// because this is a possible attack vector, let's have this disabled until
95
+		// we at least have a real use for it on the frontend
96
+		if (apply_filters('FHEE__EED_Batch__set_hooks__enable_frontend_batch', false)) {
97
+			add_action('wp_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
98
+			add_filter('template_include', [self::instance(), 'override_template'], 99);
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * Initializes some hooks for the admin in order to run batch jobs
105
+	 *
106
+	 * @throws EE_Error
107
+	 * @throws ReflectionException
108
+	 */
109
+	public static function set_hooks_admin()
110
+	{
111
+		add_action('admin_menu', [self::instance(), 'register_admin_pages']);
112
+		add_action('admin_enqueue_scripts', [self::instance(), 'enqueue_scripts']);
113
+
114
+		// ajax
115
+		add_action('wp_ajax_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
116
+		add_action('wp_ajax_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
117
+		add_action('wp_ajax_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
118
+		add_action('wp_ajax_nopriv_espresso_batch_continue', [self::instance(), 'continueBatchJob']);
119
+		add_action('wp_ajax_nopriv_espresso_batch_advance', [self::instance(), 'advanceBatchJob']);
120
+		add_action('wp_ajax_nopriv_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
121
+		add_filter(
122
+			'admin_body_class',
123
+			function ($classes) {
124
+				if (strpos($classes, 'espresso-admin') === false) {
125
+					$classes .= ' espresso-admin';
126
+				}
127
+				return $classes;
128
+			}
129
+		);
130
+	}
131
+
132
+
133
+	/**
134
+	 * @return LoaderInterface
135
+	 * @throws InvalidArgumentException
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidInterfaceException
138
+	 * @since 4.9.80.p
139
+	 */
140
+	protected function getLoader(): LoaderInterface
141
+	{
142
+		if (! $this->loader instanceof LoaderInterface) {
143
+			$this->loader = LoaderFactory::getLoader();
144
+		}
145
+		return $this->loader;
146
+	}
147
+
148
+
149
+	/**
150
+	 * Enqueues batch scripts on the frontend or admin, and creates a job
151
+	 */
152
+	public function enqueue_scripts()
153
+	{
154
+		$request = EED_Batch::getRequest();
155
+		if (
156
+			$request->getRequestParam(EED_Batch::PAGE_SLUG)
157
+			|| $request->getRequestParam('page') === EED_Batch::PAGE_SLUG
158
+		) {
159
+			if (
160
+				! $request->requestParamIsSet('default_nonce')
161
+				|| ! wp_verify_nonce($request->getRequestParam('default_nonce'), 'default_nonce')
162
+			) {
163
+				wp_die(
164
+					esc_html__(
165
+						'The link you clicked to start the batch job has expired. Please go back and refresh the previous page.',
166
+						'event_espresso'
167
+					)
168
+				);
169
+			}
170
+			switch ($this->batch_request_type()) {
171
+				case self::batch_job:
172
+					$this->enqueue_scripts_styles_batch_create();
173
+					break;
174
+				case self::batch_file_job:
175
+					$this->enqueue_scripts_styles_batch_file_create();
176
+					break;
177
+			}
178
+		}
179
+	}
180
+
181
+
182
+	/**
183
+	 * Create a batch job, enqueues a script to run it, and localizes some data for it
184
+	 */
185
+	public function enqueue_scripts_styles_batch_create()
186
+	{
187
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
188
+		wp_enqueue_script(
189
+			'batch_runner_init',
190
+			BATCH_URL . 'assets/batch_runner_init.js',
191
+			['batch_runner'],
192
+			date('Y-m-d-H:i', time()),
193
+			true
194
+		);
195
+		wp_localize_script('batch_runner_init', 'ee_job_response', $job_response->to_array());
196
+		wp_localize_script('batch_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
197
+
198
+		$return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', 'url');
199
+		if ($return_url) {
200
+			wp_localize_script(
201
+				'batch_runner_init',
202
+				'ee_job_i18n',
203
+				[
204
+					'return_url'                => $return_url,
205
+					'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam(
206
+						'auto_redirect_on_complete'
207
+					),
208
+					'user_message'              => EED_Batch::getRequest()->getRequestParam('assessment_notice')
209
+						?: EED_Batch::getRequest()->getRequestParam('job_start_notice'),
210
+				]
211
+			);
212
+		}
213
+	}
214
+
215
+
216
+	/**
217
+	 * Creates a batch job which will download a file, enqueues a script to run the job, and localizes some data for it
218
+	 */
219
+	public function enqueue_scripts_styles_batch_file_create()
220
+	{
221
+		// creates a job based on the request variable
222
+		$job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
223
+		wp_enqueue_script(
224
+			'batch_file_runner_init',
225
+			BATCH_URL . 'assets/batch_file_runner_init.js',
226
+			['batch_runner'],
227
+			date('Y-m-d-H:i', time()),
228
+			true
229
+		);
230
+		wp_localize_script('batch_file_runner_init', 'ee_job_response', $job_response->to_array());
231
+		wp_localize_script('batch_file_runner_init', 'eei18n', EE_Registry::$i18n_js_strings);
232
+
233
+		$return_url = EED_Batch::getRequest()->getRequestParam('return_url', '', 'url');
234
+		if ($return_url) {
235
+			wp_localize_script(
236
+				'batch_file_runner_init',
237
+				'ee_job_i18n',
238
+				['return_url' => $return_url]
239
+			);
240
+		}
241
+	}
242
+
243
+
244
+	/**
245
+	 * Enqueues scripts and styles common to any batch job, and creates
246
+	 * a job from the request data, and stores the response in the
247
+	 * $this->_job_step_response property
248
+	 *
249
+	 * @return JobStepResponse
250
+	 */
251
+	protected function _enqueue_batch_job_scripts_and_styles_and_start_job(): JobStepResponse
252
+	{
253
+		// just copy the bits of EE admin's eei18n that we need in the JS
254
+		EE_Registry::$i18n_js_strings['batchJobError'] = __(
255
+			'An error occurred and the job has been stopped. Please refresh the page to try again.',
256
+			'event_espresso'
257
+		);
258
+		EE_Registry::$i18n_js_strings['is_admin']      = is_admin();
259
+		wp_enqueue_style(
260
+			EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN,
261
+			EE_ADMIN_URL . 'assets/ee-admin-page.css',
262
+			[],
263
+			EVENT_ESPRESSO_VERSION
264
+		);
265
+		wp_enqueue_style(
266
+			'batch_runner',
267
+			BATCH_URL . 'assets/batch_runner.css',
268
+			[EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
269
+			date('Y-m-d-H:i', time())
270
+		);
271
+		wp_register_script(
272
+			'progress_bar',
273
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
274
+			['jquery'],
275
+			date('Y-m-d-H:i', time()),
276
+			true
277
+		);
278
+		wp_enqueue_style(
279
+			'progress_bar',
280
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
281
+			[],
282
+			date('Y-m-d-H:i', time())
283
+		);
284
+		wp_enqueue_script(
285
+			'batch_runner',
286
+			EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
287
+			['progress_bar', CoreAssetManager::JS_HANDLE_CORE],
288
+			date('Y-m-d-H:i', time()),
289
+			true
290
+		);
291
+		/** @var BatchRequestProcessor $batch_runner */
292
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
293
+		// eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
294
+		// remember the response for later. We need it to display the page body
295
+		$this->_job_step_response = $batch_runner->createJob();
296
+		return $this->_job_step_response;
297
+	}
298
+
299
+
300
+	/**
301
+	 * If we are doing a frontend batch job, this makes it so WP shows our template's HTML
302
+	 *
303
+	 * @param string $template
304
+	 * @return string
305
+	 */
306
+	public function override_template(string $template): string
307
+	{
308
+		$request = EED_Batch::getRequest();
309
+		if ($request->requestParamIsSet('batch') && $request->requestParamIsSet(EED_Batch::PAGE_SLUG)) {
310
+			return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.php';
311
+		}
312
+		return $template;
313
+	}
314
+
315
+
316
+	/**
317
+	 * Adds an admin page which doesn't appear in the admin menu
318
+	 *
319
+	 * @throws EE_Error
320
+	 * @throws ReflectionException
321
+	 */
322
+	public function register_admin_pages()
323
+	{
324
+		add_submenu_page(
325
+			'',
326
+			// parent slug. we don't want this to actually appear in the menu
327
+			esc_html__('Batch Job', 'event_espresso'),
328
+			// page title
329
+			'n/a',
330
+			// menu title
331
+			'read',
332
+			// we want this page to actually be accessible to anyone,
333
+			EED_Batch::PAGE_SLUG,
334
+			// menu slug
335
+			[self::instance(), 'show_admin_page']
336
+		);
337
+	}
338
+
339
+
340
+	/**
341
+	 * Renders the admin page, after most of the work was already done during enqueuing scripts
342
+	 * of creating the job and localizing some data
343
+	 */
344
+	public function show_admin_page()
345
+	{
346
+		echo EEH_Template::locate_template(
347
+			EE_MODULES . 'batch/templates/batch_wrapper.template.php',
348
+			[
349
+				'batch_request_type'        => $this->batch_request_type(),
350
+				'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam('auto_redirect_on_complete'),
351
+				'user_message'              => EED_Batch::getRequest()->getRequestParam('assessment_notice')
352
+					?: EED_Batch::getRequest()->getRequestParam('job_start_notice'),
353
+			]
354
+		);
355
+	}
356
+
357
+
358
+	private function runBatchRunnerJob(string $job)
359
+	{
360
+		$job_id = EED_Batch::getRequest()->getRequestParam('job_id');
361
+		/** @var BatchRequestProcessor $batch_runner */
362
+		$batch_runner = $this->getLoader()->getShared('EventEspressoBatchRequest\BatchRequestProcessor');
363
+		$job_response = $batch_runner->{$job}($job_id);
364
+		$this->_return_json($job_response->to_array());
365
+	}
366
+
367
+
368
+	/**
369
+	 * Receives ajax calls for continuing a job
370
+	 */
371
+	public function continueBatchJob()
372
+	{
373
+		$this->runBatchRunnerJob('continueJob');
374
+	}
375
+
376
+
377
+	/**
378
+	 * Receives ajax calls for continuing a job
379
+	 */
380
+	public function advanceBatchJob()
381
+	{
382
+		$this->runBatchRunnerJob('advanceJob');
383
+	}
384
+
385
+
386
+	/**
387
+	 * Receives the ajax call to cleanup a job
388
+	 *
389
+	 * @return void
390
+	 */
391
+	public function cleanupBatchJob()
392
+	{
393
+		$this->runBatchRunnerJob('cleanupJob');
394
+	}
395
+
396
+
397
+	/**
398
+	 * Returns a json response
399
+	 *
400
+	 * @param array $data The data we want to send echo via in the JSON response's "data" element
401
+	 *
402
+	 * The returned json object is created from an array in the following format:
403
+	 * array(
404
+	 *    'notices' => '', // - contains any EE_Error formatted notices
405
+	 *    'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
406
+	 *    We're also going to include the template args with every package (so js can pick out any specific template
407
+	 *    args that might be included in here)
408
+	 *    'isEEajax' => true,//indicates this is a response from EE
409
+	 * )
410
+	 */
411
+	protected function _return_json(array $data)
412
+	{
413
+		$json = [
414
+			'notices'  => EE_Error::get_notices(),
415
+			'data'     => $data,
416
+			'isEEajax' => true
417
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
418
+		];
419
+
420
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
421
+		if (error_get_last() === null || ! headers_sent()) {
422
+			header('Content-Type: application/json; charset=UTF-8');
423
+			echo wp_json_encode($json);
424
+			exit();
425
+		}
426
+	}
427
+
428
+
429
+	/**
430
+	 * Gets the job step response which was done during the enqueuing of scripts
431
+	 *
432
+	 * @return JobStepResponse
433
+	 */
434
+	public function job_step_response(): JobStepResponse
435
+	{
436
+		return $this->_job_step_response;
437
+	}
438
+
439
+
440
+	/**
441
+	 * Gets the batch request type indicated in the current request
442
+	 *
443
+	 * @return string: EED_Batch::batch_job, EED_Batch::batch_file_job, EED_Batch::batch_not_job
444
+	 */
445
+	public function batch_request_type(): string
446
+	{
447
+		if (! $this->_batch_request_type) {
448
+			$request = EED_Batch::getRequest();
449
+			$batch   = $request->getRequestParam('batch');
450
+			switch ($batch) {
451
+				case self::batch_job:
452
+					$this->_batch_request_type = self::batch_job;
453
+					break;
454
+				case self::batch_file_job:
455
+					$this->_batch_request_type = self::batch_file_job;
456
+					break;
457
+				default:
458
+					// if we didn't find that it was a batch request, indicate it wasn't
459
+					$this->_batch_request_type = self::batch_not_job;
460
+			}
461
+		}
462
+		return $this->_batch_request_type;
463
+	}
464
+
465
+
466
+	/**
467
+	 * Unnecessary
468
+	 *
469
+	 * @param WP $WP
470
+	 */
471
+	public function run($WP)
472
+	{
473
+	}
474 474
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         add_action('wp_ajax_nopriv_espresso_batch_cleanup', [self::instance(), 'cleanupBatchJob']);
121 121
         add_filter(
122 122
             'admin_body_class',
123
-            function ($classes) {
123
+            function($classes) {
124 124
                 if (strpos($classes, 'espresso-admin') === false) {
125 125
                     $classes .= ' espresso-admin';
126 126
                 }
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     protected function getLoader(): LoaderInterface
141 141
     {
142
-        if (! $this->loader instanceof LoaderInterface) {
142
+        if ( ! $this->loader instanceof LoaderInterface) {
143 143
             $this->loader = LoaderFactory::getLoader();
144 144
         }
145 145
         return $this->loader;
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
188 188
         wp_enqueue_script(
189 189
             'batch_runner_init',
190
-            BATCH_URL . 'assets/batch_runner_init.js',
190
+            BATCH_URL.'assets/batch_runner_init.js',
191 191
             ['batch_runner'],
192 192
             date('Y-m-d-H:i', time()),
193 193
             true
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
         $job_response = $this->_enqueue_batch_job_scripts_and_styles_and_start_job();
223 223
         wp_enqueue_script(
224 224
             'batch_file_runner_init',
225
-            BATCH_URL . 'assets/batch_file_runner_init.js',
225
+            BATCH_URL.'assets/batch_file_runner_init.js',
226 226
             ['batch_runner'],
227 227
             date('Y-m-d-H:i', time()),
228 228
             true
@@ -255,35 +255,35 @@  discard block
 block discarded – undo
255 255
             'An error occurred and the job has been stopped. Please refresh the page to try again.',
256 256
             'event_espresso'
257 257
         );
258
-        EE_Registry::$i18n_js_strings['is_admin']      = is_admin();
258
+        EE_Registry::$i18n_js_strings['is_admin'] = is_admin();
259 259
         wp_enqueue_style(
260 260
             EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN,
261
-            EE_ADMIN_URL . 'assets/ee-admin-page.css',
261
+            EE_ADMIN_URL.'assets/ee-admin-page.css',
262 262
             [],
263 263
             EVENT_ESPRESSO_VERSION
264 264
         );
265 265
         wp_enqueue_style(
266 266
             'batch_runner',
267
-            BATCH_URL . 'assets/batch_runner.css',
267
+            BATCH_URL.'assets/batch_runner.css',
268 268
             [EspressoLegacyAdminAssetManager::CSS_HANDLE_EE_ADMIN],
269 269
             date('Y-m-d-H:i', time())
270 270
         );
271 271
         wp_register_script(
272 272
             'progress_bar',
273
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.js',
273
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.js',
274 274
             ['jquery'],
275 275
             date('Y-m-d-H:i', time()),
276 276
             true
277 277
         );
278 278
         wp_enqueue_style(
279 279
             'progress_bar',
280
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/progress_bar.css',
280
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/progress_bar.css',
281 281
             [],
282 282
             date('Y-m-d-H:i', time())
283 283
         );
284 284
         wp_enqueue_script(
285 285
             'batch_runner',
286
-            EE_PLUGIN_DIR_URL . 'core/libraries/batch/Assets/batch_runner.js',
286
+            EE_PLUGIN_DIR_URL.'core/libraries/batch/Assets/batch_runner.js',
287 287
             ['progress_bar', CoreAssetManager::JS_HANDLE_CORE],
288 288
             date('Y-m-d-H:i', time()),
289 289
             true
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
     {
308 308
         $request = EED_Batch::getRequest();
309 309
         if ($request->requestParamIsSet('batch') && $request->requestParamIsSet(EED_Batch::PAGE_SLUG)) {
310
-            return EE_MODULES . 'batch/templates/batch_frontend_wrapper.template.php';
310
+            return EE_MODULES.'batch/templates/batch_frontend_wrapper.template.php';
311 311
         }
312 312
         return $template;
313 313
     }
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
     public function show_admin_page()
345 345
     {
346 346
         echo EEH_Template::locate_template(
347
-            EE_MODULES . 'batch/templates/batch_wrapper.template.php',
347
+            EE_MODULES.'batch/templates/batch_wrapper.template.php',
348 348
             [
349 349
                 'batch_request_type'        => $this->batch_request_type(),
350 350
                 'auto_redirect_on_complete' => EED_Batch::getRequest()->getRequestParam('auto_redirect_on_complete'),
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
      */
445 445
     public function batch_request_type(): string
446 446
     {
447
-        if (! $this->_batch_request_type) {
447
+        if ( ! $this->_batch_request_type) {
448 448
             $request = EED_Batch::getRequest();
449 449
             $batch   = $request->getRequestParam('batch');
450 450
             switch ($batch) {
Please login to merge, or discard this patch.
admin_pages/transactions/EE_Admin_Transactions_List_Table.class.php 2 patches
Indentation   +658 added lines, -658 removed lines patch added patch discarded remove patch
@@ -13,161 +13,161 @@  discard block
 block discarded – undo
13 13
  */
14 14
 class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table
15 15
 {
16
-    /**
17
-     * @var SessionLifespan $session_lifespan
18
-     */
19
-    private $session_lifespan;
20
-
21
-    private $_status;
22
-
23
-
24
-    /**
25
-     * @param Transactions_Admin_Page $admin_page
26
-     * @param SessionLifespan         $lifespan
27
-     */
28
-    public function __construct(Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
29
-    {
30
-        parent::__construct($admin_page);
31
-        $this->session_lifespan = $lifespan;
32
-        $this->_status = $this->_admin_page->get_transaction_status_array();
33
-    }
34
-
35
-
36
-    /**
37
-     *_setup_data
38
-     */
39
-    protected function _setup_data()
40
-    {
41
-        $this->_data = $this->_admin_page->get_transactions($this->_per_page);
42
-        $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
43
-        $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
44
-    }
45
-
46
-
47
-    /**
48
-     *_set_properties
49
-     */
50
-    protected function _set_properties()
51
-    {
52
-        $this->_wp_list_args = array(
53
-            'singular' => esc_html__('transaction', 'event_espresso'),
54
-            'plural'   => esc_html__('transactions', 'event_espresso'),
55
-            'ajax'     => true,
56
-            'screen'   => $this->_admin_page->get_current_screen()->id,
57
-        );
58
-        $ID_column_name = esc_html__('ID', 'event_espresso');
59
-        $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">';
60
-        $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso');
61
-        $ID_column_name .= '</span> ';
62
-        $this->_columns = array(
63
-            'id'        => $ID_column_name,
64
-            'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'),
65
-            'event_name'    => esc_html__('Event', 'event_espresso'),
66
-            'ATT_fname'     => esc_html__('Primary Registrant', 'event_espresso'),
67
-            'TXN_paid'      => esc_html__('Paid', 'event_espresso'),
68
-            'TXN_total'     => esc_html__('Total', 'event_espresso'),
69
-            'actions' => $this->actionsColumnHeader(),
70
-        );
71
-
72
-        $this->_sortable_columns = array(
73
-            'id'        => array('TXN_ID' => false),
74
-            'event_name'    => array('event_name' => false),
75
-            'ATT_fname'     => array('ATT_fname' => false),
76
-            'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
77
-        );
78
-
79
-        $this->_primary_column = 'TXN_ID';
80
-
81
-        $this->_hidden_columns = array();
82
-    }
83
-
84
-
85
-    /**
86
-     * This simply sets up the row class for the table rows.
87
-     * Allows for easier overriding of child methods for setting up sorting.
88
-     *
89
-     * @param EE_Transaction $transaction the current item
90
-     * @return string
91
-     * @throws EE_Error
92
-     * @throws ReflectionException
93
-     */
94
-    protected function _get_row_class($transaction)
95
-    {
96
-        $class = parent::_get_row_class($transaction);
97
-        // add status class
98
-        $class .= ' txn-status-' . $transaction->status_ID();
99
-        if ($this->_has_checkbox_column) {
100
-            $class .= ' has-checkbox-column';
101
-        }
102
-        return $class;
103
-    }
104
-
105
-
106
-    /**
107
-     * _get_table_filters
108
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
109
-     * get's shown in the table.
110
-     *
111
-     * @abstract
112
-     * @access protected
113
-     * @return array
114
-     */
115
-    protected function _get_table_filters()
116
-    {
117
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
118
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
119
-            : date('Y-m-d', strtotime('-10 year'));
120
-        $end_date = isset($this->_req_data['txn-filter-end-date'])
121
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
122
-            : date('Y-m-d', current_time('timestamp'));
123
-
124
-        return [
125
-            EEH_Form_Fields::text(
126
-                esc_html__('Display Transactions from', 'event_espresso'),
127
-                esc_html($start_date),
128
-                'txn-filter-start-date',
129
-                'txn-filter-start-date',
130
-                'ee-datepicker'
131
-            ),
132
-            EEH_Form_Fields::text(
133
-                esc_html__(' until ', 'event_espresso'),
134
-                esc_html($end_date),
135
-                'txn-filter-end-date',
136
-                'txn-filter-end-date',
137
-                'ee-datepicker'
138
-            )
139
-        ];
140
-    }
141
-
142
-
143
-    /**
144
-     *_add_view_counts
145
-     */
146
-    protected function _add_view_counts()
147
-    {
148
-        foreach ($this->_views as $view) {
149
-            $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
150
-        }
151
-    }
152
-
153
-
154
-    /**
155
-     *    column TXN_ID
156
-     *
157
-     * @param EE_Transaction $transaction
158
-     * @return string
159
-     * @throws EE_Error
160
-     */
161
-    public function column_id(EE_Transaction $transaction)
162
-    {
163
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
164
-            array(
165
-                'action' => 'view_transaction',
166
-                'TXN_ID' => $transaction->ID(),
167
-            ),
168
-            TXN_ADMIN_URL
169
-        );
170
-        $content = '
16
+	/**
17
+	 * @var SessionLifespan $session_lifespan
18
+	 */
19
+	private $session_lifespan;
20
+
21
+	private $_status;
22
+
23
+
24
+	/**
25
+	 * @param Transactions_Admin_Page $admin_page
26
+	 * @param SessionLifespan         $lifespan
27
+	 */
28
+	public function __construct(Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
29
+	{
30
+		parent::__construct($admin_page);
31
+		$this->session_lifespan = $lifespan;
32
+		$this->_status = $this->_admin_page->get_transaction_status_array();
33
+	}
34
+
35
+
36
+	/**
37
+	 *_setup_data
38
+	 */
39
+	protected function _setup_data()
40
+	{
41
+		$this->_data = $this->_admin_page->get_transactions($this->_per_page);
42
+		$status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
43
+		$this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
44
+	}
45
+
46
+
47
+	/**
48
+	 *_set_properties
49
+	 */
50
+	protected function _set_properties()
51
+	{
52
+		$this->_wp_list_args = array(
53
+			'singular' => esc_html__('transaction', 'event_espresso'),
54
+			'plural'   => esc_html__('transactions', 'event_espresso'),
55
+			'ajax'     => true,
56
+			'screen'   => $this->_admin_page->get_current_screen()->id,
57
+		);
58
+		$ID_column_name = esc_html__('ID', 'event_espresso');
59
+		$ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">';
60
+		$ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso');
61
+		$ID_column_name .= '</span> ';
62
+		$this->_columns = array(
63
+			'id'        => $ID_column_name,
64
+			'TXN_timestamp' => esc_html__('Transaction Date', 'event_espresso'),
65
+			'event_name'    => esc_html__('Event', 'event_espresso'),
66
+			'ATT_fname'     => esc_html__('Primary Registrant', 'event_espresso'),
67
+			'TXN_paid'      => esc_html__('Paid', 'event_espresso'),
68
+			'TXN_total'     => esc_html__('Total', 'event_espresso'),
69
+			'actions' => $this->actionsColumnHeader(),
70
+		);
71
+
72
+		$this->_sortable_columns = array(
73
+			'id'        => array('TXN_ID' => false),
74
+			'event_name'    => array('event_name' => false),
75
+			'ATT_fname'     => array('ATT_fname' => false),
76
+			'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
77
+		);
78
+
79
+		$this->_primary_column = 'TXN_ID';
80
+
81
+		$this->_hidden_columns = array();
82
+	}
83
+
84
+
85
+	/**
86
+	 * This simply sets up the row class for the table rows.
87
+	 * Allows for easier overriding of child methods for setting up sorting.
88
+	 *
89
+	 * @param EE_Transaction $transaction the current item
90
+	 * @return string
91
+	 * @throws EE_Error
92
+	 * @throws ReflectionException
93
+	 */
94
+	protected function _get_row_class($transaction)
95
+	{
96
+		$class = parent::_get_row_class($transaction);
97
+		// add status class
98
+		$class .= ' txn-status-' . $transaction->status_ID();
99
+		if ($this->_has_checkbox_column) {
100
+			$class .= ' has-checkbox-column';
101
+		}
102
+		return $class;
103
+	}
104
+
105
+
106
+	/**
107
+	 * _get_table_filters
108
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
109
+	 * get's shown in the table.
110
+	 *
111
+	 * @abstract
112
+	 * @access protected
113
+	 * @return array
114
+	 */
115
+	protected function _get_table_filters()
116
+	{
117
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
118
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
119
+			: date('Y-m-d', strtotime('-10 year'));
120
+		$end_date = isset($this->_req_data['txn-filter-end-date'])
121
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
122
+			: date('Y-m-d', current_time('timestamp'));
123
+
124
+		return [
125
+			EEH_Form_Fields::text(
126
+				esc_html__('Display Transactions from', 'event_espresso'),
127
+				esc_html($start_date),
128
+				'txn-filter-start-date',
129
+				'txn-filter-start-date',
130
+				'ee-datepicker'
131
+			),
132
+			EEH_Form_Fields::text(
133
+				esc_html__(' until ', 'event_espresso'),
134
+				esc_html($end_date),
135
+				'txn-filter-end-date',
136
+				'txn-filter-end-date',
137
+				'ee-datepicker'
138
+			)
139
+		];
140
+	}
141
+
142
+
143
+	/**
144
+	 *_add_view_counts
145
+	 */
146
+	protected function _add_view_counts()
147
+	{
148
+		foreach ($this->_views as $view) {
149
+			$this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
150
+		}
151
+	}
152
+
153
+
154
+	/**
155
+	 *    column TXN_ID
156
+	 *
157
+	 * @param EE_Transaction $transaction
158
+	 * @return string
159
+	 * @throws EE_Error
160
+	 */
161
+	public function column_id(EE_Transaction $transaction)
162
+	{
163
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
164
+			array(
165
+				'action' => 'view_transaction',
166
+				'TXN_ID' => $transaction->ID(),
167
+			),
168
+			TXN_ADMIN_URL
169
+		);
170
+		$content = '
171 171
         <span class="ee-entity-id">
172 172
             <a  class="ee-aria-tooltip"
173 173
                 href="' . $view_lnk_url . '"
@@ -176,539 +176,539 @@  discard block
 block discarded – undo
176 176
                ' . $transaction->ID() . '
177 177
            </a>
178 178
         </span>';
179
-        // txn timestamp
180
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
181
-        return $this->columnContent('id', $content, 'end');
182
-    }
183
-
184
-
185
-    /**
186
-     * @param EE_Transaction $transaction
187
-     * @return string
188
-     * @throws EE_Error
189
-     * @throws InvalidArgumentException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     */
193
-    protected function _get_txn_timestamp(EE_Transaction $transaction)
194
-    {
195
-        // is TXN less than 2 hours old ?
196
-        if (
197
-            ($transaction->failed() || $transaction->is_abandoned())
198
-            && $this->session_lifespan->expiration() < $transaction->datetime(false, true)
199
-        ) {
200
-            $timestamp = esc_html__('TXN in progress...', 'event_espresso');
201
-        } else {
202
-            $timestamp = $transaction->get_i18n_datetime('TXN_timestamp', 'M jS Y g:i a');
203
-        }
204
-        return $timestamp;
205
-    }
206
-
207
-
208
-    /**
209
-     *    column_cb
210
-     *
211
-     * @param EE_Transaction $transaction
212
-     * @return string
213
-     * @throws EE_Error
214
-     */
215
-    public function column_cb($transaction)
216
-    {
217
-        return sprintf(
218
-            '<input type="checkbox" name="%1$s[]" value="%2$s" />',
219
-            $this->_wp_list_args['singular'],
220
-            $transaction->ID()
221
-        );
222
-    }
223
-
224
-
225
-    /**
226
-     *    column_TXN_timestamp
227
-     *
228
-     * @param EE_Transaction $transaction
229
-     * @return string
230
-     * @throws EE_Error
231
-     * @throws ReflectionException
232
-     */
233
-    public function column_TXN_timestamp(EE_Transaction $transaction)
234
-    {
235
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
236
-            array(
237
-                'action' => 'view_transaction',
238
-                'TXN_ID' => $transaction->ID(),
239
-            ),
240
-            TXN_ADMIN_URL
241
-        );
242
-        $status        = esc_attr($transaction->status_ID());
243
-        $pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
244
-        return '
179
+		// txn timestamp
180
+		$content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
181
+		return $this->columnContent('id', $content, 'end');
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param EE_Transaction $transaction
187
+	 * @return string
188
+	 * @throws EE_Error
189
+	 * @throws InvalidArgumentException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 */
193
+	protected function _get_txn_timestamp(EE_Transaction $transaction)
194
+	{
195
+		// is TXN less than 2 hours old ?
196
+		if (
197
+			($transaction->failed() || $transaction->is_abandoned())
198
+			&& $this->session_lifespan->expiration() < $transaction->datetime(false, true)
199
+		) {
200
+			$timestamp = esc_html__('TXN in progress...', 'event_espresso');
201
+		} else {
202
+			$timestamp = $transaction->get_i18n_datetime('TXN_timestamp', 'M jS Y g:i a');
203
+		}
204
+		return $timestamp;
205
+	}
206
+
207
+
208
+	/**
209
+	 *    column_cb
210
+	 *
211
+	 * @param EE_Transaction $transaction
212
+	 * @return string
213
+	 * @throws EE_Error
214
+	 */
215
+	public function column_cb($transaction)
216
+	{
217
+		return sprintf(
218
+			'<input type="checkbox" name="%1$s[]" value="%2$s" />',
219
+			$this->_wp_list_args['singular'],
220
+			$transaction->ID()
221
+		);
222
+	}
223
+
224
+
225
+	/**
226
+	 *    column_TXN_timestamp
227
+	 *
228
+	 * @param EE_Transaction $transaction
229
+	 * @return string
230
+	 * @throws EE_Error
231
+	 * @throws ReflectionException
232
+	 */
233
+	public function column_TXN_timestamp(EE_Transaction $transaction)
234
+	{
235
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
236
+			array(
237
+				'action' => 'view_transaction',
238
+				'TXN_ID' => $transaction->ID(),
239
+			),
240
+			TXN_ADMIN_URL
241
+		);
242
+		$status        = esc_attr($transaction->status_ID());
243
+		$pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
244
+		return '
245 245
             <div class="ee-layout-row">
246 246
                 <span aria-label="' . $pretty_status . '"  class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"></span>
247 247
                 <a  href="' . $view_lnk_url . '"
248 248
                     class="row-title ee-status-color--' . $status . ' ee-aria-tooltip"
249 249
                     aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID(
250
-                    ) . '">
250
+					) . '">
251 251
                 ' . $this->_get_txn_timestamp($transaction) . '
252 252
                 </a>
253 253
             </div>';
254
-    }
255
-
256
-
257
-    /**
258
-     *    column_TXN_total
259
-     *
260
-     * @param EE_Transaction $transaction
261
-     * @return string
262
-     * @throws EE_Error
263
-     */
264
-    public function column_TXN_total(EE_Transaction $transaction)
265
-    {
266
-        if ($transaction->get('TXN_total') > 0) {
267
-            return '<span class="txn-pad-rght">'
268
-                   . apply_filters(
269
-                       'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
270
-                       $transaction->get_pretty('TXN_total'),
271
-                       $transaction
272
-                   )
273
-                   . '</span>';
274
-        } else {
275
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
276
-        }
277
-    }
278
-
279
-
280
-    /**
281
-     *    column_TXN_paid
282
-     *
283
-     * @param EE_Transaction $transaction
284
-     * @return mixed|string
285
-     * @throws EE_Error
286
-     */
287
-    public function column_TXN_paid(EE_Transaction $transaction)
288
-    {
289
-        $transaction_total = $transaction->get('TXN_total');
290
-        $transaction_paid = $transaction->get('TXN_paid');
291
-
292
-        if (EEH_Money::compare_floats($transaction_total, 0, '>')) {
293
-            // monies owing
294
-            $span_class = 'txn-overview-part-payment-spn';
295
-            if (EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
296
-                // paid in full
297
-                $span_class = 'txn-overview-full-payment-spn';
298
-            } elseif (EEH_Money::compare_floats($transaction_paid, 0, '==')) {
299
-                // no payments made
300
-                $span_class = 'txn-overview-no-payment-spn';
301
-            }
302
-        } else {
303
-            // transaction_total == 0 so this is a free event
304
-            $span_class = 'txn-overview-free-event-spn';
305
-        }
306
-
307
-        $payment_method = $transaction->payment_method();
308
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
309
-            ? $payment_method->admin_name()
310
-            : esc_html__('Unknown', 'event_espresso');
311
-
312
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
313
-                   . $transaction->get_pretty('TXN_paid')
314
-                   . '</span>';
315
-        if ($transaction_paid > 0) {
316
-            $content .= ' <span class="ee-status-text-small">'
317
-                        . sprintf(
318
-                            esc_html__('...via %s', 'event_espresso'),
319
-                            $payment_method_name
320
-                        )
321
-                        . '</span>';
322
-        }
323
-        return "<div>{$content}</div>";
324
-    }
325
-
326
-
327
-    /**
328
-     *    column_ATT_fname
329
-     *
330
-     * @param EE_Transaction $transaction
331
-     * @return string
332
-     * @throws EE_Error
333
-     * @throws InvalidArgumentException
334
-     * @throws InvalidDataTypeException
335
-     * @throws InvalidInterfaceException
336
-     */
337
-    public function column_ATT_fname(EE_Transaction $transaction)
338
-    {
339
-        $primary_reg = $transaction->primary_registration();
340
-        $attendee = $primary_reg->get_first_related('Attendee');
341
-        if ($attendee instanceof EE_Attendee) {
342
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
343
-                array(
344
-                    'action'  => 'view_registration',
345
-                    '_REG_ID' => $primary_reg->ID(),
346
-                ),
347
-                REG_ADMIN_URL
348
-            );
349
-            $content = EE_Registry::instance()->CAP->current_user_can(
350
-                'ee_read_registration',
351
-                'espresso_registrations_view_registration',
352
-                $primary_reg->ID()
353
-            )
354
-                ? '<a href="' . $edit_lnk_url . '"'
355
-                  . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
356
-                  . $attendee->full_name()
357
-                  . '</a>'
358
-                : $attendee->full_name();
359
-            $content .= '<br>' . $attendee->email();
360
-            return $content;
361
-        }
362
-        return $transaction->failed() || $transaction->is_abandoned()
363
-            ? esc_html__('no contact record.', 'event_espresso')
364
-            : esc_html__(
365
-                'No contact record, because the transaction was abandoned or the registration process failed.',
366
-                'event_espresso'
367
-            );
368
-    }
369
-
370
-
371
-    /**
372
-     *    column_ATT_email
373
-     *
374
-     * @param EE_Transaction $transaction
375
-     * @return string
376
-     * @throws EE_Error
377
-     */
378
-    public function column_ATT_email(EE_Transaction $transaction)
379
-    {
380
-        $attendee = $transaction->primary_registration()->get_first_related('Attendee');
381
-        if (! empty($attendee)) {
382
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
383
-                   . $attendee->get('ATT_email')
384
-                   . '</a>';
385
-        } else {
386
-            return $transaction->failed() || $transaction->is_abandoned()
387
-                ? esc_html__('no contact record.', 'event_espresso')
388
-                : esc_html__(
389
-                    'No contact record, because the transaction was abandoned or the registration process failed.',
390
-                    'event_espresso'
391
-                );
392
-        }
393
-    }
394
-
395
-
396
-    /**
397
-     *    column_event_name
398
-     *
399
-     * @param EE_Transaction $transaction
400
-     * @return string
401
-     * @throws EE_Error
402
-     * @throws InvalidArgumentException
403
-     * @throws InvalidDataTypeException
404
-     * @throws InvalidInterfaceException
405
-     */
406
-    public function column_event_name(EE_Transaction $transaction)
407
-    {
408
-        $actions = array();
409
-        $event = $transaction->primary_registration()->get_first_related('Event');
410
-        if (! empty($event)) {
411
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
412
-                array('action' => 'edit', 'post' => $event->ID()),
413
-                EVENTS_ADMIN_URL
414
-            );
415
-            $event_name = $event->get('EVT_name');
416
-
417
-            // filter this view by transactions for this event
418
-            $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
419
-                array(
420
-                    'action' => 'default',
421
-                    'EVT_ID' => $event->ID(),
422
-                ),
423
-                TXN_ADMIN_URL
424
-            );
425
-            if (
426
-                empty($this->_req_data['EVT_ID'])
427
-                && EE_Registry::instance()->CAP->current_user_can(
428
-                    'ee_edit_event',
429
-                    'espresso_events_edit',
430
-                    $event->ID()
431
-                )
432
-            ) {
433
-                $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"'
434
-                                              . ' aria-label="' . esc_attr__(
435
-                                                  'Filter transactions by this event',
436
-                                                  'event_espresso'
437
-                                              ) . '">'
438
-                                              . esc_html__('View Transactions for this event', 'event_espresso')
439
-                                              . '</a>';
440
-            }
441
-
442
-            return sprintf(
443
-                '%1$s %2$s',
444
-                EE_Registry::instance()->CAP->current_user_can(
445
-                    'ee_edit_event',
446
-                    'espresso_events_edit',
447
-                    $event->ID()
448
-                )
449
-                    ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"'
450
-                      . ' aria-label="'
451
-                      . sprintf(
452
-                          esc_attr__('Edit Event: %s', 'event_espresso'),
453
-                          $event->get('EVT_name')
454
-                      )
455
-                      . '">'
456
-                      . wp_trim_words(
457
-                          $event_name,
458
-                          30,
459
-                          '...'
460
-                      )
461
-                      . '</a>'
462
-                    : wp_trim_words($event_name, 30, '...'),
463
-                $this->row_actions($actions)
464
-            );
465
-        } else {
466
-            return esc_html__(
467
-                'The event associated with this transaction via the primary registration cannot be retrieved.',
468
-                'event_espresso'
469
-            );
470
-        }
471
-    }
472
-
473
-
474
-    /**
475
-     *    column_actions
476
-     *
477
-     * @param EE_Transaction $transaction
478
-     * @return string
479
-     * @throws EE_Error
480
-     */
481
-    public function column_actions(EE_Transaction $transaction)
482
-    {
483
-        return $this->actionsModalMenu(
484
-            $this->_action_string(
485
-                $this->get_transaction_details_link($transaction)
486
-                . $this->get_invoice_link($transaction)
487
-                . $this->get_receipt_link($transaction)
488
-                . $this->get_primary_registration_details_link($transaction)
489
-                . $this->get_send_payment_reminder_trigger_link($transaction)
490
-                . $this->get_payment_overview_link($transaction)
491
-                . $this->get_related_messages_link($transaction),
492
-                $transaction,
493
-                'div',
494
-                'txn-overview-actions ee-list-table-actions'
495
-            )
496
-        );
497
-    }
498
-
499
-
500
-    /**
501
-     * Get the transaction details link.
502
-     *
503
-     * @param EE_Transaction $transaction
504
-     * @return string
505
-     * @throws EE_Error
506
-     */
507
-    protected function get_transaction_details_link(EE_Transaction $transaction)
508
-    {
509
-        $url = EE_Admin_Page::add_query_args_and_nonce(
510
-            array(
511
-                'action' => 'view_transaction',
512
-                'TXN_ID' => $transaction->ID(),
513
-            ),
514
-            TXN_ADMIN_URL
515
-        );
516
-        return '
254
+	}
255
+
256
+
257
+	/**
258
+	 *    column_TXN_total
259
+	 *
260
+	 * @param EE_Transaction $transaction
261
+	 * @return string
262
+	 * @throws EE_Error
263
+	 */
264
+	public function column_TXN_total(EE_Transaction $transaction)
265
+	{
266
+		if ($transaction->get('TXN_total') > 0) {
267
+			return '<span class="txn-pad-rght">'
268
+				   . apply_filters(
269
+					   'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
270
+					   $transaction->get_pretty('TXN_total'),
271
+					   $transaction
272
+				   )
273
+				   . '</span>';
274
+		} else {
275
+			return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
276
+		}
277
+	}
278
+
279
+
280
+	/**
281
+	 *    column_TXN_paid
282
+	 *
283
+	 * @param EE_Transaction $transaction
284
+	 * @return mixed|string
285
+	 * @throws EE_Error
286
+	 */
287
+	public function column_TXN_paid(EE_Transaction $transaction)
288
+	{
289
+		$transaction_total = $transaction->get('TXN_total');
290
+		$transaction_paid = $transaction->get('TXN_paid');
291
+
292
+		if (EEH_Money::compare_floats($transaction_total, 0, '>')) {
293
+			// monies owing
294
+			$span_class = 'txn-overview-part-payment-spn';
295
+			if (EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
296
+				// paid in full
297
+				$span_class = 'txn-overview-full-payment-spn';
298
+			} elseif (EEH_Money::compare_floats($transaction_paid, 0, '==')) {
299
+				// no payments made
300
+				$span_class = 'txn-overview-no-payment-spn';
301
+			}
302
+		} else {
303
+			// transaction_total == 0 so this is a free event
304
+			$span_class = 'txn-overview-free-event-spn';
305
+		}
306
+
307
+		$payment_method = $transaction->payment_method();
308
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
309
+			? $payment_method->admin_name()
310
+			: esc_html__('Unknown', 'event_espresso');
311
+
312
+		$content = '<span class="' . $span_class . ' txn-pad-rght">'
313
+				   . $transaction->get_pretty('TXN_paid')
314
+				   . '</span>';
315
+		if ($transaction_paid > 0) {
316
+			$content .= ' <span class="ee-status-text-small">'
317
+						. sprintf(
318
+							esc_html__('...via %s', 'event_espresso'),
319
+							$payment_method_name
320
+						)
321
+						. '</span>';
322
+		}
323
+		return "<div>{$content}</div>";
324
+	}
325
+
326
+
327
+	/**
328
+	 *    column_ATT_fname
329
+	 *
330
+	 * @param EE_Transaction $transaction
331
+	 * @return string
332
+	 * @throws EE_Error
333
+	 * @throws InvalidArgumentException
334
+	 * @throws InvalidDataTypeException
335
+	 * @throws InvalidInterfaceException
336
+	 */
337
+	public function column_ATT_fname(EE_Transaction $transaction)
338
+	{
339
+		$primary_reg = $transaction->primary_registration();
340
+		$attendee = $primary_reg->get_first_related('Attendee');
341
+		if ($attendee instanceof EE_Attendee) {
342
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
343
+				array(
344
+					'action'  => 'view_registration',
345
+					'_REG_ID' => $primary_reg->ID(),
346
+				),
347
+				REG_ADMIN_URL
348
+			);
349
+			$content = EE_Registry::instance()->CAP->current_user_can(
350
+				'ee_read_registration',
351
+				'espresso_registrations_view_registration',
352
+				$primary_reg->ID()
353
+			)
354
+				? '<a href="' . $edit_lnk_url . '"'
355
+				  . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
356
+				  . $attendee->full_name()
357
+				  . '</a>'
358
+				: $attendee->full_name();
359
+			$content .= '<br>' . $attendee->email();
360
+			return $content;
361
+		}
362
+		return $transaction->failed() || $transaction->is_abandoned()
363
+			? esc_html__('no contact record.', 'event_espresso')
364
+			: esc_html__(
365
+				'No contact record, because the transaction was abandoned or the registration process failed.',
366
+				'event_espresso'
367
+			);
368
+	}
369
+
370
+
371
+	/**
372
+	 *    column_ATT_email
373
+	 *
374
+	 * @param EE_Transaction $transaction
375
+	 * @return string
376
+	 * @throws EE_Error
377
+	 */
378
+	public function column_ATT_email(EE_Transaction $transaction)
379
+	{
380
+		$attendee = $transaction->primary_registration()->get_first_related('Attendee');
381
+		if (! empty($attendee)) {
382
+			return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
383
+				   . $attendee->get('ATT_email')
384
+				   . '</a>';
385
+		} else {
386
+			return $transaction->failed() || $transaction->is_abandoned()
387
+				? esc_html__('no contact record.', 'event_espresso')
388
+				: esc_html__(
389
+					'No contact record, because the transaction was abandoned or the registration process failed.',
390
+					'event_espresso'
391
+				);
392
+		}
393
+	}
394
+
395
+
396
+	/**
397
+	 *    column_event_name
398
+	 *
399
+	 * @param EE_Transaction $transaction
400
+	 * @return string
401
+	 * @throws EE_Error
402
+	 * @throws InvalidArgumentException
403
+	 * @throws InvalidDataTypeException
404
+	 * @throws InvalidInterfaceException
405
+	 */
406
+	public function column_event_name(EE_Transaction $transaction)
407
+	{
408
+		$actions = array();
409
+		$event = $transaction->primary_registration()->get_first_related('Event');
410
+		if (! empty($event)) {
411
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
412
+				array('action' => 'edit', 'post' => $event->ID()),
413
+				EVENTS_ADMIN_URL
414
+			);
415
+			$event_name = $event->get('EVT_name');
416
+
417
+			// filter this view by transactions for this event
418
+			$txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
419
+				array(
420
+					'action' => 'default',
421
+					'EVT_ID' => $event->ID(),
422
+				),
423
+				TXN_ADMIN_URL
424
+			);
425
+			if (
426
+				empty($this->_req_data['EVT_ID'])
427
+				&& EE_Registry::instance()->CAP->current_user_can(
428
+					'ee_edit_event',
429
+					'espresso_events_edit',
430
+					$event->ID()
431
+				)
432
+			) {
433
+				$actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"'
434
+											  . ' aria-label="' . esc_attr__(
435
+												  'Filter transactions by this event',
436
+												  'event_espresso'
437
+											  ) . '">'
438
+											  . esc_html__('View Transactions for this event', 'event_espresso')
439
+											  . '</a>';
440
+			}
441
+
442
+			return sprintf(
443
+				'%1$s %2$s',
444
+				EE_Registry::instance()->CAP->current_user_can(
445
+					'ee_edit_event',
446
+					'espresso_events_edit',
447
+					$event->ID()
448
+				)
449
+					? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"'
450
+					  . ' aria-label="'
451
+					  . sprintf(
452
+						  esc_attr__('Edit Event: %s', 'event_espresso'),
453
+						  $event->get('EVT_name')
454
+					  )
455
+					  . '">'
456
+					  . wp_trim_words(
457
+						  $event_name,
458
+						  30,
459
+						  '...'
460
+					  )
461
+					  . '</a>'
462
+					: wp_trim_words($event_name, 30, '...'),
463
+				$this->row_actions($actions)
464
+			);
465
+		} else {
466
+			return esc_html__(
467
+				'The event associated with this transaction via the primary registration cannot be retrieved.',
468
+				'event_espresso'
469
+			);
470
+		}
471
+	}
472
+
473
+
474
+	/**
475
+	 *    column_actions
476
+	 *
477
+	 * @param EE_Transaction $transaction
478
+	 * @return string
479
+	 * @throws EE_Error
480
+	 */
481
+	public function column_actions(EE_Transaction $transaction)
482
+	{
483
+		return $this->actionsModalMenu(
484
+			$this->_action_string(
485
+				$this->get_transaction_details_link($transaction)
486
+				. $this->get_invoice_link($transaction)
487
+				. $this->get_receipt_link($transaction)
488
+				. $this->get_primary_registration_details_link($transaction)
489
+				. $this->get_send_payment_reminder_trigger_link($transaction)
490
+				. $this->get_payment_overview_link($transaction)
491
+				. $this->get_related_messages_link($transaction),
492
+				$transaction,
493
+				'div',
494
+				'txn-overview-actions ee-list-table-actions'
495
+			)
496
+		);
497
+	}
498
+
499
+
500
+	/**
501
+	 * Get the transaction details link.
502
+	 *
503
+	 * @param EE_Transaction $transaction
504
+	 * @return string
505
+	 * @throws EE_Error
506
+	 */
507
+	protected function get_transaction_details_link(EE_Transaction $transaction)
508
+	{
509
+		$url = EE_Admin_Page::add_query_args_and_nonce(
510
+			array(
511
+				'action' => 'view_transaction',
512
+				'TXN_ID' => $transaction->ID(),
513
+			),
514
+			TXN_ADMIN_URL
515
+		);
516
+		return '
517 517
 				<a class="ee-aria-tooltip button button--icon-only" href="' . $url . '"'
518
-               . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--icon-only">
518
+			   . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--icon-only">
519 519
 					<span class="dashicons dashicons-cart"></span>
520 520
 				</a>';
521
-    }
522
-
523
-
524
-    /**
525
-     * Get the invoice link for the given registration.
526
-     *
527
-     * @param EE_Transaction $transaction
528
-     * @return string
529
-     * @throws EE_Error
530
-     */
531
-    protected function get_invoice_link(EE_Transaction $transaction)
532
-    {
533
-        $registration = $transaction->primary_registration();
534
-        if ($registration instanceof EE_Registration) {
535
-            $url = $registration->invoice_url();
536
-            // only show invoice link if message type is active.
537
-            if (
538
-                $registration->attendee() instanceof EE_Attendee
539
-                && EEH_MSG_Template::is_mt_active('invoice')
540
-            ) {
541
-                return '
521
+	}
522
+
523
+
524
+	/**
525
+	 * Get the invoice link for the given registration.
526
+	 *
527
+	 * @param EE_Transaction $transaction
528
+	 * @return string
529
+	 * @throws EE_Error
530
+	 */
531
+	protected function get_invoice_link(EE_Transaction $transaction)
532
+	{
533
+		$registration = $transaction->primary_registration();
534
+		if ($registration instanceof EE_Registration) {
535
+			$url = $registration->invoice_url();
536
+			// only show invoice link if message type is active.
537
+			if (
538
+				$registration->attendee() instanceof EE_Attendee
539
+				&& EEH_MSG_Template::is_mt_active('invoice')
540
+			) {
541
+				return '
542 542
                     <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
543
-                       . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
543
+					   . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
544 544
                         <span class="dashicons dashicons-media-spreadsheet"></span>
545 545
                     </a>';
546
-            }
547
-        }
548
-        return '';
549
-    }
550
-
551
-
552
-    /**
553
-     * Get the receipt link for the transaction.
554
-     *
555
-     * @param EE_Transaction $transaction
556
-     * @return string
557
-     * @throws EE_Error
558
-     */
559
-    protected function get_receipt_link(EE_Transaction $transaction)
560
-    {
561
-        $registration = $transaction->primary_registration();
562
-        if ($registration instanceof EE_Registration) {
563
-            $url = $registration->receipt_url();
564
-            // only show receipt link if message type is active.
565
-            if (
566
-                $registration->attendee() instanceof EE_Attendee
567
-                && EEH_MSG_Template::is_mt_active('receipt')
568
-            ) {
569
-                return '
546
+			}
547
+		}
548
+		return '';
549
+	}
550
+
551
+
552
+	/**
553
+	 * Get the receipt link for the transaction.
554
+	 *
555
+	 * @param EE_Transaction $transaction
556
+	 * @return string
557
+	 * @throws EE_Error
558
+	 */
559
+	protected function get_receipt_link(EE_Transaction $transaction)
560
+	{
561
+		$registration = $transaction->primary_registration();
562
+		if ($registration instanceof EE_Registration) {
563
+			$url = $registration->receipt_url();
564
+			// only show receipt link if message type is active.
565
+			if (
566
+				$registration->attendee() instanceof EE_Attendee
567
+				&& EEH_MSG_Template::is_mt_active('receipt')
568
+			) {
569
+				return '
570 570
 				<a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
571
-                       . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
571
+					   . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
572 572
 					<span class="dashicons dashicons-text-page"></span>
573 573
 				</a>';
574
-            }
575
-        }
576
-        return '';
577
-    }
578
-
579
-
580
-    /**
581
-     * Get the link to view the details for the primary registration.
582
-     *
583
-     * @param EE_Transaction $transaction
584
-     * @return string
585
-     * @throws EE_Error
586
-     * @throws InvalidArgumentException
587
-     * @throws InvalidDataTypeException
588
-     * @throws InvalidInterfaceException
589
-     */
590
-    protected function get_primary_registration_details_link(EE_Transaction $transaction)
591
-    {
592
-        $registration = $transaction->primary_registration();
593
-        if ($registration instanceof EE_Registration) {
594
-            $url = EE_Admin_Page::add_query_args_and_nonce(
595
-                array(
596
-                    'action'  => 'view_registration',
597
-                    '_REG_ID' => $registration->ID(),
598
-                ),
599
-                REG_ADMIN_URL
600
-            );
601
-            return EE_Registry::instance()->CAP->current_user_can(
602
-                'ee_read_registration',
603
-                'espresso_registrations_view_registration',
604
-                $registration->ID()
605
-            )
606
-                ? '
574
+			}
575
+		}
576
+		return '';
577
+	}
578
+
579
+
580
+	/**
581
+	 * Get the link to view the details for the primary registration.
582
+	 *
583
+	 * @param EE_Transaction $transaction
584
+	 * @return string
585
+	 * @throws EE_Error
586
+	 * @throws InvalidArgumentException
587
+	 * @throws InvalidDataTypeException
588
+	 * @throws InvalidInterfaceException
589
+	 */
590
+	protected function get_primary_registration_details_link(EE_Transaction $transaction)
591
+	{
592
+		$registration = $transaction->primary_registration();
593
+		if ($registration instanceof EE_Registration) {
594
+			$url = EE_Admin_Page::add_query_args_and_nonce(
595
+				array(
596
+					'action'  => 'view_registration',
597
+					'_REG_ID' => $registration->ID(),
598
+				),
599
+				REG_ADMIN_URL
600
+			);
601
+			return EE_Registry::instance()->CAP->current_user_can(
602
+				'ee_read_registration',
603
+				'espresso_registrations_view_registration',
604
+				$registration->ID()
605
+			)
606
+				? '
607 607
 					<a href="' . $url . '"
608 608
 					    aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '"
609 609
 					    class="ee-aria-tooltip button button--icon-only"
610 610
                     >
611 611
 						<span class="dashicons dashicons-clipboard"></span>
612 612
 					</a>'
613
-                : '';
614
-        }
615
-        return '';
616
-    }
617
-
618
-
619
-    /**
620
-     * Get send payment reminder trigger link
621
-     *
622
-     * @param EE_Transaction $transaction
623
-     * @return string
624
-     * @throws EE_Error
625
-     * @throws InvalidArgumentException
626
-     * @throws InvalidDataTypeException
627
-     * @throws InvalidInterfaceException
628
-     */
629
-    protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
630
-    {
631
-        $registration = $transaction->primary_registration();
632
-        if (
633
-            $registration instanceof EE_Registration
634
-            && $registration->attendee() instanceof EE_Attendee
635
-            && EEH_MSG_Template::is_mt_active('payment_reminder')
636
-            && ! in_array(
637
-                $transaction->status_ID(),
638
-                array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
639
-                true
640
-            )
641
-            && EE_Registry::instance()->CAP->current_user_can(
642
-                'ee_send_message',
643
-                'espresso_transactions_send_payment_reminder'
644
-            )
645
-        ) {
646
-            $url = EE_Admin_Page::add_query_args_and_nonce(
647
-                array(
648
-                    'action' => 'send_payment_reminder',
649
-                    'TXN_ID' => $transaction->ID(),
650
-                ),
651
-                TXN_ADMIN_URL
652
-            );
653
-            return '
613
+				: '';
614
+		}
615
+		return '';
616
+	}
617
+
618
+
619
+	/**
620
+	 * Get send payment reminder trigger link
621
+	 *
622
+	 * @param EE_Transaction $transaction
623
+	 * @return string
624
+	 * @throws EE_Error
625
+	 * @throws InvalidArgumentException
626
+	 * @throws InvalidDataTypeException
627
+	 * @throws InvalidInterfaceException
628
+	 */
629
+	protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
630
+	{
631
+		$registration = $transaction->primary_registration();
632
+		if (
633
+			$registration instanceof EE_Registration
634
+			&& $registration->attendee() instanceof EE_Attendee
635
+			&& EEH_MSG_Template::is_mt_active('payment_reminder')
636
+			&& ! in_array(
637
+				$transaction->status_ID(),
638
+				array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
639
+				true
640
+			)
641
+			&& EE_Registry::instance()->CAP->current_user_can(
642
+				'ee_send_message',
643
+				'espresso_transactions_send_payment_reminder'
644
+			)
645
+		) {
646
+			$url = EE_Admin_Page::add_query_args_and_nonce(
647
+				array(
648
+					'action' => 'send_payment_reminder',
649
+					'TXN_ID' => $transaction->ID(),
650
+				),
651
+				TXN_ADMIN_URL
652
+			);
653
+			return '
654 654
                 <a href="' . $url . '"
655 655
                     aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '"
656 656
                     class="ee-aria-tooltip button button--icon-only"
657 657
                 >
658 658
                     <span class="dashicons dashicons-email-alt"></span>
659 659
                 </a>';
660
-        }
661
-        return '';
662
-    }
663
-
664
-
665
-    /**
666
-     * Get link to filtered view in the message activity list table of messages for this transaction.
667
-     *
668
-     * @param EE_Transaction $transaction
669
-     * @return string
670
-     * @throws EE_Error
671
-     * @throws InvalidArgumentException
672
-     * @throws InvalidDataTypeException
673
-     * @throws InvalidInterfaceException
674
-     */
675
-    protected function get_related_messages_link(EE_Transaction $transaction)
676
-    {
677
-        return EE_Registry::instance()->CAP->current_user_can(
678
-            'ee_read_global_messages',
679
-            'view_filtered_messages'
680
-        )
681
-            ? EEH_MSG_Template::get_message_action_link(
682
-                'see_notifications_for',
683
-                null,
684
-                array('TXN_ID' => $transaction->ID())
685
-            )
686
-            : '';
687
-    }
688
-
689
-
690
-    /**
691
-     * Return the link to make a payment on the frontend
692
-     *
693
-     * @param EE_Transaction $transaction
694
-     * @return string
695
-     * @throws EE_Error
696
-     */
697
-    protected function get_payment_overview_link(EE_Transaction $transaction)
698
-    {
699
-        $registration = $transaction->primary_registration();
700
-        if (
701
-            $registration instanceof EE_Registration
702
-            && $transaction->status_ID() !== EEM_Transaction::complete_status_code
703
-            && $registration->owes_monies_and_can_pay()
704
-        ) {
705
-            return '
660
+		}
661
+		return '';
662
+	}
663
+
664
+
665
+	/**
666
+	 * Get link to filtered view in the message activity list table of messages for this transaction.
667
+	 *
668
+	 * @param EE_Transaction $transaction
669
+	 * @return string
670
+	 * @throws EE_Error
671
+	 * @throws InvalidArgumentException
672
+	 * @throws InvalidDataTypeException
673
+	 * @throws InvalidInterfaceException
674
+	 */
675
+	protected function get_related_messages_link(EE_Transaction $transaction)
676
+	{
677
+		return EE_Registry::instance()->CAP->current_user_can(
678
+			'ee_read_global_messages',
679
+			'view_filtered_messages'
680
+		)
681
+			? EEH_MSG_Template::get_message_action_link(
682
+				'see_notifications_for',
683
+				null,
684
+				array('TXN_ID' => $transaction->ID())
685
+			)
686
+			: '';
687
+	}
688
+
689
+
690
+	/**
691
+	 * Return the link to make a payment on the frontend
692
+	 *
693
+	 * @param EE_Transaction $transaction
694
+	 * @return string
695
+	 * @throws EE_Error
696
+	 */
697
+	protected function get_payment_overview_link(EE_Transaction $transaction)
698
+	{
699
+		$registration = $transaction->primary_registration();
700
+		if (
701
+			$registration instanceof EE_Registration
702
+			&& $transaction->status_ID() !== EEM_Transaction::complete_status_code
703
+			&& $registration->owes_monies_and_can_pay()
704
+		) {
705
+			return '
706 706
                 <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
707
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
708
-                   . ' class="ee-aria-tooltip button button--icon-only">
707
+				   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
708
+				   . ' class="ee-aria-tooltip button button--icon-only">
709 709
                     <span class="dashicons dashicons-money"></span>
710 710
                 </a>';
711
-        }
712
-        return '';
713
-    }
711
+		}
712
+		return '';
713
+	}
714 714
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         );
58 58
         $ID_column_name = esc_html__('ID', 'event_espresso');
59 59
         $ID_column_name .= '<span class="show-on-mobile-view-only" style="float:none">';
60
-        $ID_column_name .= ' : ' . esc_html__('Transaction Date', 'event_espresso');
60
+        $ID_column_name .= ' : '.esc_html__('Transaction Date', 'event_espresso');
61 61
         $ID_column_name .= '</span> ';
62 62
         $this->_columns = array(
63 63
             'id'        => $ID_column_name,
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     {
96 96
         $class = parent::_get_row_class($transaction);
97 97
         // add status class
98
-        $class .= ' txn-status-' . $transaction->status_ID();
98
+        $class .= ' txn-status-'.$transaction->status_ID();
99 99
         if ($this->_has_checkbox_column) {
100 100
             $class .= ' has-checkbox-column';
101 101
         }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     protected function _add_view_counts()
147 147
     {
148 148
         foreach ($this->_views as $view) {
149
-            $this->_views[ $view['slug'] ]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
149
+            $this->_views[$view['slug']]['count'] = $this->_admin_page->get_transactions($this->_per_page, true, $view['slug']);
150 150
         }
151 151
     }
152 152
 
@@ -170,14 +170,14 @@  discard block
 block discarded – undo
170 170
         $content = '
171 171
         <span class="ee-entity-id">
172 172
             <a  class="ee-aria-tooltip"
173
-                href="' . $view_lnk_url . '"
174
-                aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '"
173
+                href="' . $view_lnk_url.'"
174
+                aria-label="' . esc_attr__('Go to Transaction Details', 'event_espresso').'"
175 175
             >
176
-               ' . $transaction->ID() . '
176
+               ' . $transaction->ID().'
177 177
            </a>
178 178
         </span>';
179 179
         // txn timestamp
180
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
180
+        $content .= '  <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>';
181 181
         return $this->columnContent('id', $content, 'end');
182 182
     }
183 183
 
@@ -243,12 +243,12 @@  discard block
 block discarded – undo
243 243
         $pretty_status = EEH_Template::pretty_status($status, false, 'sentence');
244 244
         return '
245 245
             <div class="ee-layout-row">
246
-                <span aria-label="' . $pretty_status . '"  class="ee-status-dot ee-status-bg--' . $status . ' ee-aria-tooltip"></span>
247
-                <a  href="' . $view_lnk_url . '"
248
-                    class="row-title ee-status-color--' . $status . ' ee-aria-tooltip"
249
-                    aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID(
250
-                    ) . '">
251
-                ' . $this->_get_txn_timestamp($transaction) . '
246
+                <span aria-label="' . $pretty_status.'"  class="ee-status-dot ee-status-bg--'.$status.' ee-aria-tooltip"></span>
247
+                <a  href="' . $view_lnk_url.'"
248
+                    class="row-title ee-status-color--' . $status.' ee-aria-tooltip"
249
+                    aria-label="' . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID(
250
+                    ).'">
251
+                ' . $this->_get_txn_timestamp($transaction).'
252 252
                 </a>
253 253
             </div>';
254 254
     }
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                    )
273 273
                    . '</span>';
274 274
         } else {
275
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
275
+            return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>';
276 276
         }
277 277
     }
278 278
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
             ? $payment_method->admin_name()
310 310
             : esc_html__('Unknown', 'event_espresso');
311 311
 
312
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
312
+        $content = '<span class="'.$span_class.' txn-pad-rght">'
313 313
                    . $transaction->get_pretty('TXN_paid')
314 314
                    . '</span>';
315 315
         if ($transaction_paid > 0) {
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
                 'espresso_registrations_view_registration',
352 352
                 $primary_reg->ID()
353 353
             )
354
-                ? '<a href="' . $edit_lnk_url . '"'
355
-                  . ' aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
354
+                ? '<a href="'.$edit_lnk_url.'"'
355
+                  . ' aria-label="'.esc_attr__('View Registration Details', 'event_espresso').'">'
356 356
                   . $attendee->full_name()
357 357
                   . '</a>'
358 358
                 : $attendee->full_name();
359
-            $content .= '<br>' . $attendee->email();
359
+            $content .= '<br>'.$attendee->email();
360 360
             return $content;
361 361
         }
362 362
         return $transaction->failed() || $transaction->is_abandoned()
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
     public function column_ATT_email(EE_Transaction $transaction)
379 379
     {
380 380
         $attendee = $transaction->primary_registration()->get_first_related('Attendee');
381
-        if (! empty($attendee)) {
382
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
381
+        if ( ! empty($attendee)) {
382
+            return '<a href="mailto:'.$attendee->get('ATT_email').'">'
383 383
                    . $attendee->get('ATT_email')
384 384
                    . '</a>';
385 385
         } else {
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
     {
408 408
         $actions = array();
409 409
         $event = $transaction->primary_registration()->get_first_related('Event');
410
-        if (! empty($event)) {
410
+        if ( ! empty($event)) {
411 411
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
412 412
                 array('action' => 'edit', 'post' => $event->ID()),
413 413
                 EVENTS_ADMIN_URL
@@ -430,11 +430,11 @@  discard block
 block discarded – undo
430 430
                     $event->ID()
431 431
                 )
432 432
             ) {
433
-                $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="' . $txn_by_event_lnk . '"'
434
-                                              . ' aria-label="' . esc_attr__(
433
+                $actions['filter_by_event'] = '<a class="ee-aria-tooltip" href="'.$txn_by_event_lnk.'"'
434
+                                              . ' aria-label="'.esc_attr__(
435 435
                                                   'Filter transactions by this event',
436 436
                                                   'event_espresso'
437
-                                              ) . '">'
437
+                                              ).'">'
438 438
                                               . esc_html__('View Transactions for this event', 'event_espresso')
439 439
                                               . '</a>';
440 440
             }
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
                     'espresso_events_edit',
447 447
                     $event->ID()
448 448
                 )
449
-                    ? '<a class="ee-aria-tooltip" href="' . $edit_event_url . '"'
449
+                    ? '<a class="ee-aria-tooltip" href="'.$edit_event_url.'"'
450 450
                       . ' aria-label="'
451 451
                       . sprintf(
452 452
                           esc_attr__('Edit Event: %s', 'event_espresso'),
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
             TXN_ADMIN_URL
515 515
         );
516 516
         return '
517
-				<a class="ee-aria-tooltip button button--icon-only" href="' . $url . '"'
518
-               . ' aria-label="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="button button--icon-only">
517
+				<a class="ee-aria-tooltip button button--icon-only" href="' . $url.'"'
518
+               . ' aria-label="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="button button--icon-only">
519 519
 					<span class="dashicons dashicons-cart"></span>
520 520
 				</a>';
521 521
     }
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
                 && EEH_MSG_Template::is_mt_active('invoice')
540 540
             ) {
541 541
                 return '
542
-                    <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
543
-                       . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
542
+                    <a aria-label="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"'
543
+                       . ' target="_blank" href="'.$url.'" class="ee-aria-tooltip button button--icon-only">
544 544
                         <span class="dashicons dashicons-media-spreadsheet"></span>
545 545
                     </a>';
546 546
             }
@@ -567,8 +567,8 @@  discard block
 block discarded – undo
567 567
                 && EEH_MSG_Template::is_mt_active('receipt')
568 568
             ) {
569 569
                 return '
570
-				<a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
571
-                       . ' target="_blank" href="' . $url . '" class="ee-aria-tooltip button button--icon-only">
570
+				<a aria-label="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"'
571
+                       . ' target="_blank" href="'.$url.'" class="ee-aria-tooltip button button--icon-only">
572 572
 					<span class="dashicons dashicons-text-page"></span>
573 573
 				</a>';
574 574
             }
@@ -604,8 +604,8 @@  discard block
 block discarded – undo
604 604
                 $registration->ID()
605 605
             )
606 606
                 ? '
607
-					<a href="' . $url . '"
608
-					    aria-label="' . esc_attr__('View Registration Details', 'event_espresso') . '"
607
+					<a href="' . $url.'"
608
+					    aria-label="' . esc_attr__('View Registration Details', 'event_espresso').'"
609 609
 					    class="ee-aria-tooltip button button--icon-only"
610 610
                     >
611 611
 						<span class="dashicons dashicons-clipboard"></span>
@@ -651,8 +651,8 @@  discard block
 block discarded – undo
651 651
                 TXN_ADMIN_URL
652 652
             );
653 653
             return '
654
-                <a href="' . $url . '"
655
-                    aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '"
654
+                <a href="' . $url.'"
655
+                    aria-label="' . esc_attr__('Send Payment Reminder', 'event_espresso').'"
656 656
                     class="ee-aria-tooltip button button--icon-only"
657 657
                 >
658 658
                     <span class="dashicons dashicons-email-alt"></span>
@@ -703,8 +703,8 @@  discard block
 block discarded – undo
703 703
             && $registration->owes_monies_and_can_pay()
704 704
         ) {
705 705
             return '
706
-                <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
707
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
706
+                <a aria-label="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"'
707
+                   . ' target="_blank" href="'.$registration->payment_overview_url(true).'"'
708 708
                    . ' class="ee-aria-tooltip button button--icon-only">
709 709
                     <span class="dashicons dashicons-money"></span>
710 710
                 </a>';
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Indentation   +3645 added lines, -3645 removed lines patch added patch discarded remove patch
@@ -20,2202 +20,2202 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
22 22
 {
23
-    /**
24
-     * @var EE_Registration
25
-     */
26
-    private $_registration;
27
-
28
-    /**
29
-     * @var EE_Event
30
-     */
31
-    private $_reg_event;
32
-
33
-    /**
34
-     * @var EE_Session
35
-     */
36
-    private $_session;
37
-
38
-    /**
39
-     * @var array
40
-     */
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form;
50
-
51
-    /**
52
-     * @var EEM_Registration $registration_model
53
-     */
54
-    private $registration_model;
55
-
56
-    /**
57
-     * @var EEM_Attendee $attendee_model
58
-     */
59
-    private $attendee_model;
60
-
61
-    /**
62
-     * @var EEM_Event $event_model
63
-     */
64
-    private $event_model;
65
-
66
-    /**
67
-     * @var EEM_Status $status_model
68
-     */
69
-    private $status_model;
70
-
71
-
72
-    /**
73
-     * @param bool $routing
74
-     * @throws EE_Error
75
-     * @throws InvalidArgumentException
76
-     * @throws InvalidDataTypeException
77
-     * @throws InvalidInterfaceException
78
-     * @throws ReflectionException
79
-     */
80
-    public function __construct($routing = true)
81
-    {
82
-        parent::__construct($routing);
83
-        add_action('wp_loaded', [$this, 'wp_loaded']);
84
-    }
85
-
86
-
87
-    /**
88
-     * @return EEM_Registration
89
-     * @throws InvalidArgumentException
90
-     * @throws InvalidDataTypeException
91
-     * @throws InvalidInterfaceException
92
-     * @since 4.10.2.p
93
-     */
94
-    protected function getRegistrationModel()
95
-    {
96
-        if (! $this->registration_model instanceof EEM_Registration) {
97
-            $this->registration_model = $this->loader->getShared('EEM_Registration');
98
-        }
99
-        return $this->registration_model;
100
-    }
101
-
102
-
103
-    /**
104
-     * @return EEM_Attendee
105
-     * @throws InvalidArgumentException
106
-     * @throws InvalidDataTypeException
107
-     * @throws InvalidInterfaceException
108
-     * @since 4.10.2.p
109
-     */
110
-    protected function getAttendeeModel()
111
-    {
112
-        if (! $this->attendee_model instanceof EEM_Attendee) {
113
-            $this->attendee_model = $this->loader->getShared('EEM_Attendee');
114
-        }
115
-        return $this->attendee_model;
116
-    }
117
-
118
-
119
-    /**
120
-     * @return EEM_Event
121
-     * @throws InvalidArgumentException
122
-     * @throws InvalidDataTypeException
123
-     * @throws InvalidInterfaceException
124
-     * @since 4.10.2.p
125
-     */
126
-    protected function getEventModel()
127
-    {
128
-        if (! $this->event_model instanceof EEM_Event) {
129
-            $this->event_model = $this->loader->getShared('EEM_Event');
130
-        }
131
-        return $this->event_model;
132
-    }
133
-
134
-
135
-    /**
136
-     * @return EEM_Status
137
-     * @throws InvalidArgumentException
138
-     * @throws InvalidDataTypeException
139
-     * @throws InvalidInterfaceException
140
-     * @since 4.10.2.p
141
-     */
142
-    protected function getStatusModel()
143
-    {
144
-        if (! $this->status_model instanceof EEM_Status) {
145
-            $this->status_model = $this->loader->getShared('EEM_Status');
146
-        }
147
-        return $this->status_model;
148
-    }
149
-
150
-
151
-    public function wp_loaded()
152
-    {
153
-        // when adding a new registration...
154
-        $action = $this->request->getRequestParam('action');
155
-        if ($action === 'new_registration') {
156
-            EE_System::do_not_cache();
157
-            if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
158
-                // and it's NOT the attendee information reg step
159
-                // force cookie expiration by setting time to last week
160
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
161
-                // and update the global
162
-                $_COOKIE['ee_registration_added'] = 0;
163
-            }
164
-        }
165
-    }
166
-
167
-
168
-    protected function _init_page_props()
169
-    {
170
-        $this->page_slug        = REG_PG_SLUG;
171
-        $this->_admin_base_url  = REG_ADMIN_URL;
172
-        $this->_admin_base_path = REG_ADMIN;
173
-        $this->page_label       = esc_html__('Registrations', 'event_espresso');
174
-        $this->_cpt_routes      = [
175
-            'add_new_attendee' => 'espresso_attendees',
176
-            'edit_attendee'    => 'espresso_attendees',
177
-            'insert_attendee'  => 'espresso_attendees',
178
-            'update_attendee'  => 'espresso_attendees',
179
-        ];
180
-        $this->_cpt_model_names = [
181
-            'add_new_attendee' => 'EEM_Attendee',
182
-            'edit_attendee'    => 'EEM_Attendee',
183
-        ];
184
-        $this->_cpt_edit_routes = [
185
-            'espresso_attendees' => 'edit_attendee',
186
-        ];
187
-        $this->_pagenow_map     = [
188
-            'add_new_attendee' => 'post-new.php',
189
-            'edit_attendee'    => 'post.php',
190
-            'trash'            => 'post.php',
191
-        ];
192
-        add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
193
-        // add filters so that the comment urls don't take users to a confusing 404 page
194
-        add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
195
-    }
196
-
197
-
198
-    /**
199
-     * @param string     $link    The comment permalink with '#comment-$id' appended.
200
-     * @param WP_Comment $comment The current comment object.
201
-     * @return string
202
-     */
203
-    public function clear_comment_link($link, WP_Comment $comment)
204
-    {
205
-        // gotta make sure this only happens on this route
206
-        $post_type = get_post_type($comment->comment_post_ID);
207
-        if ($post_type === 'espresso_attendees') {
208
-            return '#commentsdiv';
209
-        }
210
-        return $link;
211
-    }
212
-
213
-
214
-    protected function _ajax_hooks()
215
-    {
216
-        // todo: all hooks for registrations ajax goes in here
217
-        add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
218
-    }
219
-
220
-
221
-    protected function _define_page_props()
222
-    {
223
-        $this->_admin_page_title = $this->page_label;
224
-        $this->_labels           = [
225
-            'buttons'                      => [
226
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
227
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
228
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
229
-                'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
230
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
231
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
232
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
233
-                'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
234
-            ],
235
-            'publishbox'                   => [
236
-                'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
237
-                'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
238
-            ],
239
-            'hide_add_button_on_cpt_route' => [
240
-                'edit_attendee' => true,
241
-            ],
242
-        ];
243
-    }
244
-
245
-
246
-    /**
247
-     * grab url requests and route them
248
-     *
249
-     * @return void
250
-     * @throws EE_Error
251
-     */
252
-    public function _set_page_routes()
253
-    {
254
-        $this->_get_registration_status_array();
255
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
256
-        $REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
257
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
258
-        $ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
259
-        $this->_page_routes = [
260
-            'default'                             => [
261
-                'func'       => '_registrations_overview_list_table',
262
-                'capability' => 'ee_read_registrations',
263
-            ],
264
-            'view_registration'                   => [
265
-                'func'       => '_registration_details',
266
-                'capability' => 'ee_read_registration',
267
-                'obj_id'     => $REG_ID,
268
-            ],
269
-            'edit_registration'                   => [
270
-                'func'               => '_update_attendee_registration_form',
271
-                'noheader'           => true,
272
-                'headers_sent_route' => 'view_registration',
273
-                'capability'         => 'ee_edit_registration',
274
-                'obj_id'             => $REG_ID,
275
-                '_REG_ID'            => $REG_ID,
276
-            ],
277
-            'trash_registrations'                 => [
278
-                'func'       => '_trash_or_restore_registrations',
279
-                'args'       => ['trash' => true],
280
-                'noheader'   => true,
281
-                'capability' => 'ee_delete_registrations',
282
-            ],
283
-            'restore_registrations'               => [
284
-                'func'       => '_trash_or_restore_registrations',
285
-                'args'       => ['trash' => false],
286
-                'noheader'   => true,
287
-                'capability' => 'ee_delete_registrations',
288
-            ],
289
-            'delete_registrations'                => [
290
-                'func'       => '_delete_registrations',
291
-                'noheader'   => true,
292
-                'capability' => 'ee_delete_registrations',
293
-            ],
294
-            'new_registration'                    => [
295
-                'func'       => 'new_registration',
296
-                'capability' => 'ee_edit_registrations',
297
-            ],
298
-            'process_reg_step'                    => [
299
-                'func'       => 'process_reg_step',
300
-                'noheader'   => true,
301
-                'capability' => 'ee_edit_registrations',
302
-            ],
303
-            'redirect_to_txn'                     => [
304
-                'func'       => 'redirect_to_txn',
305
-                'noheader'   => true,
306
-                'capability' => 'ee_edit_registrations',
307
-            ],
308
-            'change_reg_status'                   => [
309
-                'func'       => '_change_reg_status',
310
-                'noheader'   => true,
311
-                'capability' => 'ee_edit_registration',
312
-                'obj_id'     => $REG_ID,
313
-            ],
314
-            'approve_registration'                => [
315
-                'func'       => 'approve_registration',
316
-                'noheader'   => true,
317
-                'capability' => 'ee_edit_registration',
318
-                'obj_id'     => $REG_ID,
319
-            ],
320
-            'approve_and_notify_registration'     => [
321
-                'func'       => 'approve_registration',
322
-                'noheader'   => true,
323
-                'args'       => [true],
324
-                'capability' => 'ee_edit_registration',
325
-                'obj_id'     => $REG_ID,
326
-            ],
327
-            'approve_registrations'               => [
328
-                'func'       => 'bulk_action_on_registrations',
329
-                'noheader'   => true,
330
-                'capability' => 'ee_edit_registrations',
331
-                'args'       => ['approve'],
332
-            ],
333
-            'approve_and_notify_registrations'    => [
334
-                'func'       => 'bulk_action_on_registrations',
335
-                'noheader'   => true,
336
-                'capability' => 'ee_edit_registrations',
337
-                'args'       => ['approve', true],
338
-            ],
339
-            'decline_registration'                => [
340
-                'func'       => 'decline_registration',
341
-                'noheader'   => true,
342
-                'capability' => 'ee_edit_registration',
343
-                'obj_id'     => $REG_ID,
344
-            ],
345
-            'decline_and_notify_registration'     => [
346
-                'func'       => 'decline_registration',
347
-                'noheader'   => true,
348
-                'args'       => [true],
349
-                'capability' => 'ee_edit_registration',
350
-                'obj_id'     => $REG_ID,
351
-            ],
352
-            'decline_registrations'               => [
353
-                'func'       => 'bulk_action_on_registrations',
354
-                'noheader'   => true,
355
-                'capability' => 'ee_edit_registrations',
356
-                'args'       => ['decline'],
357
-            ],
358
-            'decline_and_notify_registrations'    => [
359
-                'func'       => 'bulk_action_on_registrations',
360
-                'noheader'   => true,
361
-                'capability' => 'ee_edit_registrations',
362
-                'args'       => ['decline', true],
363
-            ],
364
-            'pending_registration'                => [
365
-                'func'       => 'pending_registration',
366
-                'noheader'   => true,
367
-                'capability' => 'ee_edit_registration',
368
-                'obj_id'     => $REG_ID,
369
-            ],
370
-            'pending_and_notify_registration'     => [
371
-                'func'       => 'pending_registration',
372
-                'noheader'   => true,
373
-                'args'       => [true],
374
-                'capability' => 'ee_edit_registration',
375
-                'obj_id'     => $REG_ID,
376
-            ],
377
-            'pending_registrations'               => [
378
-                'func'       => 'bulk_action_on_registrations',
379
-                'noheader'   => true,
380
-                'capability' => 'ee_edit_registrations',
381
-                'args'       => ['pending'],
382
-            ],
383
-            'pending_and_notify_registrations'    => [
384
-                'func'       => 'bulk_action_on_registrations',
385
-                'noheader'   => true,
386
-                'capability' => 'ee_edit_registrations',
387
-                'args'       => ['pending', true],
388
-            ],
389
-            'no_approve_registration'             => [
390
-                'func'       => 'not_approve_registration',
391
-                'noheader'   => true,
392
-                'capability' => 'ee_edit_registration',
393
-                'obj_id'     => $REG_ID,
394
-            ],
395
-            'no_approve_and_notify_registration'  => [
396
-                'func'       => 'not_approve_registration',
397
-                'noheader'   => true,
398
-                'args'       => [true],
399
-                'capability' => 'ee_edit_registration',
400
-                'obj_id'     => $REG_ID,
401
-            ],
402
-            'no_approve_registrations'            => [
403
-                'func'       => 'bulk_action_on_registrations',
404
-                'noheader'   => true,
405
-                'capability' => 'ee_edit_registrations',
406
-                'args'       => ['not_approve'],
407
-            ],
408
-            'no_approve_and_notify_registrations' => [
409
-                'func'       => 'bulk_action_on_registrations',
410
-                'noheader'   => true,
411
-                'capability' => 'ee_edit_registrations',
412
-                'args'       => ['not_approve', true],
413
-            ],
414
-            'cancel_registration'                 => [
415
-                'func'       => 'cancel_registration',
416
-                'noheader'   => true,
417
-                'capability' => 'ee_edit_registration',
418
-                'obj_id'     => $REG_ID,
419
-            ],
420
-            'cancel_and_notify_registration'      => [
421
-                'func'       => 'cancel_registration',
422
-                'noheader'   => true,
423
-                'args'       => [true],
424
-                'capability' => 'ee_edit_registration',
425
-                'obj_id'     => $REG_ID,
426
-            ],
427
-            'cancel_registrations'                => [
428
-                'func'       => 'bulk_action_on_registrations',
429
-                'noheader'   => true,
430
-                'capability' => 'ee_edit_registrations',
431
-                'args'       => ['cancel'],
432
-            ],
433
-            'cancel_and_notify_registrations'     => [
434
-                'func'       => 'bulk_action_on_registrations',
435
-                'noheader'   => true,
436
-                'capability' => 'ee_edit_registrations',
437
-                'args'       => ['cancel', true],
438
-            ],
439
-            'wait_list_registration'              => [
440
-                'func'       => 'wait_list_registration',
441
-                'noheader'   => true,
442
-                'capability' => 'ee_edit_registration',
443
-                'obj_id'     => $REG_ID,
444
-            ],
445
-            'wait_list_and_notify_registration'   => [
446
-                'func'       => 'wait_list_registration',
447
-                'noheader'   => true,
448
-                'args'       => [true],
449
-                'capability' => 'ee_edit_registration',
450
-                'obj_id'     => $REG_ID,
451
-            ],
452
-            'contact_list'                        => [
453
-                'func'       => '_attendee_contact_list_table',
454
-                'capability' => 'ee_read_contacts',
455
-            ],
456
-            'add_new_attendee'                    => [
457
-                'func' => '_create_new_cpt_item',
458
-                'args' => [
459
-                    'new_attendee' => true,
460
-                    'capability'   => 'ee_edit_contacts',
461
-                ],
462
-            ],
463
-            'edit_attendee'                       => [
464
-                'func'       => '_edit_cpt_item',
465
-                'capability' => 'ee_edit_contacts',
466
-                'obj_id'     => $ATT_ID,
467
-            ],
468
-            'duplicate_attendee'                  => [
469
-                'func'       => '_duplicate_attendee',
470
-                'noheader'   => true,
471
-                'capability' => 'ee_edit_contacts',
472
-                'obj_id'     => $ATT_ID,
473
-            ],
474
-            'insert_attendee'                     => [
475
-                'func'       => '_insert_or_update_attendee',
476
-                'args'       => [
477
-                    'new_attendee' => true,
478
-                ],
479
-                'noheader'   => true,
480
-                'capability' => 'ee_edit_contacts',
481
-            ],
482
-            'update_attendee'                     => [
483
-                'func'       => '_insert_or_update_attendee',
484
-                'args'       => [
485
-                    'new_attendee' => false,
486
-                ],
487
-                'noheader'   => true,
488
-                'capability' => 'ee_edit_contacts',
489
-                'obj_id'     => $ATT_ID,
490
-            ],
491
-            'trash_attendees'                     => [
492
-                'func'       => '_trash_or_restore_attendees',
493
-                'args'       => [
494
-                    'trash' => 'true',
495
-                ],
496
-                'noheader'   => true,
497
-                'capability' => 'ee_delete_contacts',
498
-            ],
499
-            'trash_attendee'                      => [
500
-                'func'       => '_trash_or_restore_attendees',
501
-                'args'       => [
502
-                    'trash' => true,
503
-                ],
504
-                'noheader'   => true,
505
-                'capability' => 'ee_delete_contacts',
506
-                'obj_id'     => $ATT_ID,
507
-            ],
508
-            'restore_attendees'                   => [
509
-                'func'       => '_trash_or_restore_attendees',
510
-                'args'       => [
511
-                    'trash' => false,
512
-                ],
513
-                'noheader'   => true,
514
-                'capability' => 'ee_delete_contacts',
515
-                'obj_id'     => $ATT_ID,
516
-            ],
517
-            'resend_registration'                 => [
518
-                'func'       => '_resend_registration',
519
-                'noheader'   => true,
520
-                'capability' => 'ee_send_message',
521
-            ],
522
-            'registrations_report'                => [
523
-                'func'       => '_registrations_report',
524
-                'noheader'   => true,
525
-                'capability' => 'ee_read_registrations',
526
-            ],
527
-            'contact_list_export'                 => [
528
-                'func'       => '_contact_list_export',
529
-                'noheader'   => true,
530
-                'capability' => 'export',
531
-            ],
532
-            'contact_list_report'                 => [
533
-                'func'       => '_contact_list_report',
534
-                'noheader'   => true,
535
-                'capability' => 'ee_read_contacts',
536
-            ],
537
-        ];
538
-    }
539
-
540
-
541
-    protected function _set_page_config()
542
-    {
543
-        $REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
544
-        $ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
545
-        $this->_page_config = [
546
-            'default'           => [
547
-                'nav'           => [
548
-                    'label' => esc_html__('Overview', 'event_espresso'),
549
-                    'order' => 5,
550
-                ],
551
-                'help_tabs'     => [
552
-                    'registrations_overview_help_tab'                       => [
553
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
554
-                        'filename' => 'registrations_overview',
555
-                    ],
556
-                    'registrations_overview_table_column_headings_help_tab' => [
557
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
558
-                        'filename' => 'registrations_overview_table_column_headings',
559
-                    ],
560
-                    'registrations_overview_filters_help_tab'               => [
561
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
562
-                        'filename' => 'registrations_overview_filters',
563
-                    ],
564
-                    'registrations_overview_views_help_tab'                 => [
565
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
566
-                        'filename' => 'registrations_overview_views',
567
-                    ],
568
-                    'registrations_regoverview_other_help_tab'              => [
569
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
570
-                        'filename' => 'registrations_overview_other',
571
-                    ],
572
-                ],
573
-                'list_table'    => 'EE_Registrations_List_Table',
574
-                'require_nonce' => false,
575
-            ],
576
-            'view_registration' => [
577
-                'nav'           => [
578
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
579
-                    'order'      => 15,
580
-                    'url'        => $REG_ID
581
-                        ? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
582
-                        : $this->_admin_base_url,
583
-                    'persistent' => false,
584
-                ],
585
-                'help_tabs'     => [
586
-                    'registrations_details_help_tab'                    => [
587
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
588
-                        'filename' => 'registrations_details',
589
-                    ],
590
-                    'registrations_details_table_help_tab'              => [
591
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
592
-                        'filename' => 'registrations_details_table',
593
-                    ],
594
-                    'registrations_details_form_answers_help_tab'       => [
595
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
596
-                        'filename' => 'registrations_details_form_answers',
597
-                    ],
598
-                    'registrations_details_registrant_details_help_tab' => [
599
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
600
-                        'filename' => 'registrations_details_registrant_details',
601
-                    ],
602
-                ],
603
-                'metaboxes'     => array_merge(
604
-                    $this->_default_espresso_metaboxes,
605
-                    ['_registration_details_metaboxes']
606
-                ),
607
-                'require_nonce' => false,
608
-            ],
609
-            'new_registration'  => [
610
-                'nav'           => [
611
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
612
-                    'url'        => '#',
613
-                    'order'      => 15,
614
-                    'persistent' => false,
615
-                ],
616
-                'metaboxes'     => $this->_default_espresso_metaboxes,
617
-                'labels'        => [
618
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
619
-                ],
620
-                'require_nonce' => false,
621
-            ],
622
-            'add_new_attendee'  => [
623
-                'nav'           => [
624
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
625
-                    'order'      => 15,
626
-                    'persistent' => false,
627
-                ],
628
-                'metaboxes'     => array_merge(
629
-                    $this->_default_espresso_metaboxes,
630
-                    ['_publish_post_box', 'attendee_editor_metaboxes']
631
-                ),
632
-                'require_nonce' => false,
633
-            ],
634
-            'edit_attendee'     => [
635
-                'nav'           => [
636
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
637
-                    'order'      => 15,
638
-                    'persistent' => false,
639
-                    'url'        => $ATT_ID
640
-                        ? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
641
-                        : $this->_admin_base_url,
642
-                ],
643
-                'metaboxes'     => array_merge(
644
-                    $this->_default_espresso_metaboxes,
645
-                    ['attendee_editor_metaboxes']
646
-                ),
647
-                'require_nonce' => false,
648
-            ],
649
-            'contact_list'      => [
650
-                'nav'           => [
651
-                    'label' => esc_html__('Contact List', 'event_espresso'),
652
-                    'order' => 20,
653
-                ],
654
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
655
-                'help_tabs'     => [
656
-                    'registrations_contact_list_help_tab'                       => [
657
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
658
-                        'filename' => 'registrations_contact_list',
659
-                    ],
660
-                    'registrations_contact-list_table_column_headings_help_tab' => [
661
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
662
-                        'filename' => 'registrations_contact_list_table_column_headings',
663
-                    ],
664
-                    'registrations_contact_list_views_help_tab'                 => [
665
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
666
-                        'filename' => 'registrations_contact_list_views',
667
-                    ],
668
-                    'registrations_contact_list_other_help_tab'                 => [
669
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
670
-                        'filename' => 'registrations_contact_list_other',
671
-                    ],
672
-                ],
673
-                'metaboxes'     => [],
674
-                'require_nonce' => false,
675
-            ],
676
-            // override default cpt routes
677
-            'create_new'        => '',
678
-            'edit'              => '',
679
-        ];
680
-    }
681
-
682
-
683
-    /**
684
-     * The below methods aren't used by this class currently
685
-     */
686
-    protected function _add_screen_options()
687
-    {
688
-    }
689
-
690
-
691
-    protected function _add_feature_pointers()
692
-    {
693
-    }
694
-
695
-
696
-    public function admin_init()
697
-    {
698
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
699
-            'click "Update Registration Questions" to save your changes',
700
-            'event_espresso'
701
-        );
702
-    }
703
-
704
-
705
-    public function admin_notices()
706
-    {
707
-    }
708
-
709
-
710
-    public function admin_footer_scripts()
711
-    {
712
-    }
713
-
714
-
715
-    /**
716
-     * get list of registration statuses
717
-     *
718
-     * @return void
719
-     * @throws EE_Error
720
-     */
721
-    private function _get_registration_status_array()
722
-    {
723
-        self::$_reg_status = EEM_Registration::reg_status_array([], true);
724
-    }
725
-
726
-
727
-    /**
728
-     * @throws InvalidArgumentException
729
-     * @throws InvalidDataTypeException
730
-     * @throws InvalidInterfaceException
731
-     * @since 4.10.2.p
732
-     */
733
-    protected function _add_screen_options_default()
734
-    {
735
-        $this->_per_page_screen_option();
736
-    }
737
-
738
-
739
-    /**
740
-     * @throws InvalidArgumentException
741
-     * @throws InvalidDataTypeException
742
-     * @throws InvalidInterfaceException
743
-     * @since 4.10.2.p
744
-     */
745
-    protected function _add_screen_options_contact_list()
746
-    {
747
-        $page_title              = $this->_admin_page_title;
748
-        $this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
749
-        $this->_per_page_screen_option();
750
-        $this->_admin_page_title = $page_title;
751
-    }
752
-
753
-
754
-    public function load_scripts_styles()
755
-    {
756
-        // style
757
-        wp_register_style(
758
-            'espresso_reg',
759
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
760
-            ['ee-admin-css'],
761
-            EVENT_ESPRESSO_VERSION
762
-        );
763
-        wp_enqueue_style('espresso_reg');
764
-        // script
765
-        wp_register_script(
766
-            'espresso_reg',
767
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
768
-            ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
769
-            EVENT_ESPRESSO_VERSION,
770
-            true
771
-        );
772
-        wp_enqueue_script('espresso_reg');
773
-    }
774
-
775
-
776
-    /**
777
-     * @throws EE_Error
778
-     * @throws InvalidArgumentException
779
-     * @throws InvalidDataTypeException
780
-     * @throws InvalidInterfaceException
781
-     * @throws ReflectionException
782
-     * @since 4.10.2.p
783
-     */
784
-    public function load_scripts_styles_edit_attendee()
785
-    {
786
-        // stuff to only show up on our attendee edit details page.
787
-        $attendee_details_translations = [
788
-            'att_publish_text' => sprintf(
789
-            /* translators: The date and time */
790
-                wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
791
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
792
-            ),
793
-        ];
794
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
795
-        wp_enqueue_script('jquery-validate');
796
-    }
797
-
798
-
799
-    /**
800
-     * @throws EE_Error
801
-     * @throws InvalidArgumentException
802
-     * @throws InvalidDataTypeException
803
-     * @throws InvalidInterfaceException
804
-     * @throws ReflectionException
805
-     * @since 4.10.2.p
806
-     */
807
-    public function load_scripts_styles_view_registration()
808
-    {
809
-        // styles
810
-        wp_enqueue_style('espresso-ui-theme');
811
-        // scripts
812
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
813
-        $this->_reg_custom_questions_form->wp_enqueue_scripts();
814
-    }
815
-
816
-
817
-    public function load_scripts_styles_contact_list()
818
-    {
819
-        wp_dequeue_style('espresso_reg');
820
-        wp_register_style(
821
-            'espresso_att',
822
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
823
-            ['ee-admin-css'],
824
-            EVENT_ESPRESSO_VERSION
825
-        );
826
-        wp_enqueue_style('espresso_att');
827
-    }
828
-
829
-
830
-    public function load_scripts_styles_new_registration()
831
-    {
832
-        wp_register_script(
833
-            'ee-spco-for-admin',
834
-            REG_ASSETS_URL . 'spco_for_admin.js',
835
-            ['underscore', 'jquery'],
836
-            EVENT_ESPRESSO_VERSION,
837
-            true
838
-        );
839
-        wp_enqueue_script('ee-spco-for-admin');
840
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
841
-        EE_Form_Section_Proper::wp_enqueue_scripts();
842
-        EED_Ticket_Selector::load_tckt_slctr_assets();
843
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
844
-    }
845
-
846
-
847
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
848
-    {
849
-        add_filter('FHEE_load_EE_messages', '__return_true');
850
-    }
851
-
852
-
853
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
854
-    {
855
-        add_filter('FHEE_load_EE_messages', '__return_true');
856
-    }
857
-
858
-
859
-    /**
860
-     * @throws EE_Error
861
-     * @throws InvalidArgumentException
862
-     * @throws InvalidDataTypeException
863
-     * @throws InvalidInterfaceException
864
-     * @throws ReflectionException
865
-     * @since 4.10.2.p
866
-     */
867
-    protected function _set_list_table_views_default()
868
-    {
869
-        // for notification related bulk actions we need to make sure only active messengers have an option.
870
-        EED_Messages::set_autoloaders();
871
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
872
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
873
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
874
-        // key= bulk_action_slug, value= message type.
875
-        $match_array = [
876
-            'approve_registrations'    => 'registration',
877
-            'decline_registrations'    => 'declined_registration',
878
-            'pending_registrations'    => 'pending_approval',
879
-            'no_approve_registrations' => 'not_approved_registration',
880
-            'cancel_registrations'     => 'cancelled_registration',
881
-        ];
882
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
883
-            'ee_send_message',
884
-            'batch_send_messages'
885
-        );
886
-        /** setup reg status bulk actions **/
887
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
888
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
889
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
890
-                'Approve and Notify Registrations',
891
-                'event_espresso'
892
-            );
893
-        }
894
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
895
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
896
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
897
-                'Decline and Notify Registrations',
898
-                'event_espresso'
899
-            );
900
-        }
901
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
902
-            'Set Registrations to Pending Payment',
903
-            'event_espresso'
904
-        );
905
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
906
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
907
-                'Set Registrations to Pending Payment and Notify',
908
-                'event_espresso'
909
-            );
910
-        }
911
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
912
-            'Set Registrations to Not Approved',
913
-            'event_espresso'
914
-        );
915
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
916
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
917
-                'Set Registrations to Not Approved and Notify',
918
-                'event_espresso'
919
-            );
920
-        }
921
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
922
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
923
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
924
-                'Cancel Registrations and Notify',
925
-                'event_espresso'
926
-            );
927
-        }
928
-        $def_reg_status_actions = apply_filters(
929
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
930
-            $def_reg_status_actions,
931
-            $active_mts,
932
-            $can_send
933
-        );
934
-
935
-        $this->_views = [
936
-            'all'   => [
937
-                'slug'        => 'all',
938
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
939
-                'count'       => 0,
940
-                'bulk_action' => array_merge(
941
-                    $def_reg_status_actions,
942
-                    [
943
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
944
-                    ]
945
-                ),
946
-            ],
947
-            'month' => [
948
-                'slug'        => 'month',
949
-                'label'       => esc_html__('This Month', 'event_espresso'),
950
-                'count'       => 0,
951
-                'bulk_action' => array_merge(
952
-                    $def_reg_status_actions,
953
-                    [
954
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
955
-                    ]
956
-                ),
957
-            ],
958
-            'today' => [
959
-                'slug'        => 'today',
960
-                'label'       => sprintf(
961
-                    esc_html__('Today - %s', 'event_espresso'),
962
-                    date('M d, Y', current_time('timestamp'))
963
-                ),
964
-                'count'       => 0,
965
-                'bulk_action' => array_merge(
966
-                    $def_reg_status_actions,
967
-                    [
968
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
969
-                    ]
970
-                ),
971
-            ],
972
-        ];
973
-        if (
974
-            EE_Registry::instance()->CAP->current_user_can(
975
-                'ee_delete_registrations',
976
-                'espresso_registrations_delete_registration'
977
-            )
978
-        ) {
979
-            $this->_views['incomplete'] = [
980
-                'slug'        => 'incomplete',
981
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
982
-                'count'       => 0,
983
-                'bulk_action' => [
984
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
985
-                ],
986
-            ];
987
-            $this->_views['trash']      = [
988
-                'slug'        => 'trash',
989
-                'label'       => esc_html__('Trash', 'event_espresso'),
990
-                'count'       => 0,
991
-                'bulk_action' => [
992
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
993
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
994
-                ],
995
-            ];
996
-        }
997
-    }
998
-
999
-
1000
-    protected function _set_list_table_views_contact_list()
1001
-    {
1002
-        $this->_views = [
1003
-            'in_use' => [
1004
-                'slug'        => 'in_use',
1005
-                'label'       => esc_html__('In Use', 'event_espresso'),
1006
-                'count'       => 0,
1007
-                'bulk_action' => [
1008
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1009
-                ],
1010
-            ],
1011
-        ];
1012
-        if (
1013
-            EE_Registry::instance()->CAP->current_user_can(
1014
-                'ee_delete_contacts',
1015
-                'espresso_registrations_trash_attendees'
1016
-            )
1017
-        ) {
1018
-            $this->_views['trash'] = [
1019
-                'slug'        => 'trash',
1020
-                'label'       => esc_html__('Trash', 'event_espresso'),
1021
-                'count'       => 0,
1022
-                'bulk_action' => [
1023
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1024
-                ],
1025
-            ];
1026
-        }
1027
-    }
1028
-
1029
-
1030
-    /**
1031
-     * @return array
1032
-     * @throws EE_Error
1033
-     */
1034
-    protected function _registration_legend_items()
1035
-    {
1036
-        $fc_items = [
1037
-            'star-icon'        => [
1038
-                'class' => 'dashicons dashicons-star-filled gold-icon',
1039
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1040
-            ],
1041
-            'view_details'     => [
1042
-                'class' => 'dashicons dashicons-clipboard',
1043
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1044
-            ],
1045
-            'edit_attendee'    => [
1046
-                'class' => 'dashicons dashicons-admin-users',
1047
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1048
-            ],
1049
-            'view_transaction' => [
1050
-                'class' => 'dashicons dashicons-cart',
1051
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1052
-            ],
1053
-            'view_invoice'     => [
1054
-                'class' => 'dashicons dashicons-media-spreadsheet',
1055
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1056
-            ],
1057
-        ];
1058
-        if (
1059
-            EE_Registry::instance()->CAP->current_user_can(
1060
-                'ee_send_message',
1061
-                'espresso_registrations_resend_registration'
1062
-            )
1063
-        ) {
1064
-            $fc_items['resend_registration'] = [
1065
-                'class' => 'dashicons dashicons-email-alt',
1066
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1067
-            ];
1068
-        } else {
1069
-            $fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1070
-        }
1071
-        if (
1072
-            EE_Registry::instance()->CAP->current_user_can(
1073
-                'ee_read_global_messages',
1074
-                'view_filtered_messages'
1075
-            )
1076
-        ) {
1077
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1078
-            if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1079
-                $fc_items['view_related_messages'] = [
1080
-                    'class' => $related_for_icon['css_class'],
1081
-                    'desc'  => $related_for_icon['label'],
1082
-                ];
1083
-            }
1084
-        }
1085
-        $sc_items = [
1086
-            'approved_status'   => [
1087
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1088
-                'desc'  => EEH_Template::pretty_status(
1089
-                    EEM_Registration::status_id_approved,
1090
-                    false,
1091
-                    'sentence'
1092
-                ),
1093
-            ],
1094
-            'pending_status'    => [
1095
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1096
-                'desc'  => EEH_Template::pretty_status(
1097
-                    EEM_Registration::status_id_pending_payment,
1098
-                    false,
1099
-                    'sentence'
1100
-                ),
1101
-            ],
1102
-            'wait_list'         => [
1103
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1104
-                'desc'  => EEH_Template::pretty_status(
1105
-                    EEM_Registration::status_id_wait_list,
1106
-                    false,
1107
-                    'sentence'
1108
-                ),
1109
-            ],
1110
-            'incomplete_status' => [
1111
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1112
-                'desc'  => EEH_Template::pretty_status(
1113
-                    EEM_Registration::status_id_incomplete,
1114
-                    false,
1115
-                    'sentence'
1116
-                ),
1117
-            ],
1118
-            'not_approved'      => [
1119
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1120
-                'desc'  => EEH_Template::pretty_status(
1121
-                    EEM_Registration::status_id_not_approved,
1122
-                    false,
1123
-                    'sentence'
1124
-                ),
1125
-            ],
1126
-            'declined_status'   => [
1127
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1128
-                'desc'  => EEH_Template::pretty_status(
1129
-                    EEM_Registration::status_id_declined,
1130
-                    false,
1131
-                    'sentence'
1132
-                ),
1133
-            ],
1134
-            'cancelled_status'  => [
1135
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1136
-                'desc'  => EEH_Template::pretty_status(
1137
-                    EEM_Registration::status_id_cancelled,
1138
-                    false,
1139
-                    'sentence'
1140
-                ),
1141
-            ],
1142
-        ];
1143
-        return array_merge($fc_items, $sc_items);
1144
-    }
1145
-
1146
-
1147
-
1148
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1149
-
1150
-
1151
-    /**
1152
-     * @throws DomainException
1153
-     * @throws EE_Error
1154
-     * @throws InvalidArgumentException
1155
-     * @throws InvalidDataTypeException
1156
-     * @throws InvalidInterfaceException
1157
-     */
1158
-    protected function _registrations_overview_list_table()
1159
-    {
1160
-        $this->appendAddNewRegistrationButtonToPageTitle();
1161
-        $header_text                  = '';
1162
-        $admin_page_header_decorators = [
1163
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1164
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1165
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1166
-            'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1167
-        ];
1168
-        foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1169
-            $filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1170
-            $header_text = $filter_header_decorator->getHeaderText($header_text);
1171
-        }
1172
-        $this->_template_args['admin_page_header'] = $header_text;
1173
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1174
-        $this->display_admin_list_table_page_with_no_sidebar();
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * @throws EE_Error
1180
-     * @throws InvalidArgumentException
1181
-     * @throws InvalidDataTypeException
1182
-     * @throws InvalidInterfaceException
1183
-     */
1184
-    private function appendAddNewRegistrationButtonToPageTitle()
1185
-    {
1186
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1187
-        if (
1188
-            $EVT_ID
1189
-            && EE_Registry::instance()->CAP->current_user_can(
1190
-                'ee_edit_registrations',
1191
-                'espresso_registrations_new_registration',
1192
-                $EVT_ID
1193
-            )
1194
-        ) {
1195
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1196
-                'new_registration',
1197
-                'add-registrant',
1198
-                ['event_id' => $EVT_ID],
1199
-                'add-new-h2'
1200
-            );
1201
-        }
1202
-    }
1203
-
1204
-
1205
-    /**
1206
-     * This sets the _registration property for the registration details screen
1207
-     *
1208
-     * @return void
1209
-     * @throws EE_Error
1210
-     * @throws InvalidArgumentException
1211
-     * @throws InvalidDataTypeException
1212
-     * @throws InvalidInterfaceException
1213
-     */
1214
-    private function _set_registration_object()
1215
-    {
1216
-        // get out if we've already set the object
1217
-        if ($this->_registration instanceof EE_Registration) {
1218
-            return;
1219
-        }
1220
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1221
-        if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1222
-            return;
1223
-        }
1224
-        $error_msg = sprintf(
1225
-            esc_html__(
1226
-                'An error occurred and the details for Registration ID #%s could not be retrieved.',
1227
-                'event_espresso'
1228
-            ),
1229
-            $REG_ID
1230
-        );
1231
-        EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1232
-        $this->_registration = null;
1233
-    }
1234
-
1235
-
1236
-    /**
1237
-     * Used to retrieve registrations for the list table.
1238
-     *
1239
-     * @param int  $per_page
1240
-     * @param bool $count
1241
-     * @param bool $this_month
1242
-     * @param bool $today
1243
-     * @return EE_Registration[]|int
1244
-     * @throws EE_Error
1245
-     * @throws InvalidArgumentException
1246
-     * @throws InvalidDataTypeException
1247
-     * @throws InvalidInterfaceException
1248
-     */
1249
-    public function get_registrations(
1250
-        $per_page = 10,
1251
-        $count = false,
1252
-        $this_month = false,
1253
-        $today = false
1254
-    ) {
1255
-        if ($this_month) {
1256
-            $this->request->setRequestParam('status', 'month');
1257
-        }
1258
-        if ($today) {
1259
-            $this->request->setRequestParam('status', 'today');
1260
-        }
1261
-        $query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1262
-        /**
1263
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1264
-         *
1265
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1266
-         * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1267
-         *                      or if you have the development copy of EE you can view this at the path:
1268
-         *                      /docs/G--Model-System/model-query-params.md
1269
-         */
1270
-        $query_params['group_by'] = '';
1271
-
1272
-        return $count
1273
-            ? $this->getRegistrationModel()->count($query_params)
1274
-            /** @type EE_Registration[] */
1275
-            : $this->getRegistrationModel()->get_all($query_params);
1276
-    }
1277
-
1278
-
1279
-    /**
1280
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1281
-     * Note: this listens to values on the request for some of the query parameters.
1282
-     *
1283
-     * @param array $request
1284
-     * @param int   $per_page
1285
-     * @param bool  $count
1286
-     * @return array
1287
-     * @throws EE_Error
1288
-     * @throws InvalidArgumentException
1289
-     * @throws InvalidDataTypeException
1290
-     * @throws InvalidInterfaceException
1291
-     */
1292
-    protected function _get_registration_query_parameters(
1293
-        $request = [],
1294
-        $per_page = 10,
1295
-        $count = false
1296
-    ) {
1297
-        /** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1298
-        $list_table_query_builder = $this->loader->getNew(
1299
-            'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1300
-            [null, null, $request]
1301
-        );
1302
-        return $list_table_query_builder->getQueryParams($per_page, $count);
1303
-    }
1304
-
1305
-
1306
-    public function get_registration_status_array()
1307
-    {
1308
-        return self::$_reg_status;
1309
-    }
1310
-
1311
-
1312
-
1313
-
1314
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1315
-    /**
1316
-     * generates HTML for the View Registration Details Admin page
1317
-     *
1318
-     * @return void
1319
-     * @throws DomainException
1320
-     * @throws EE_Error
1321
-     * @throws InvalidArgumentException
1322
-     * @throws InvalidDataTypeException
1323
-     * @throws InvalidInterfaceException
1324
-     * @throws EntityNotFoundException
1325
-     * @throws ReflectionException
1326
-     */
1327
-    protected function _registration_details()
1328
-    {
1329
-        $this->_template_args = [];
1330
-        $this->_set_registration_object();
1331
-        if (is_object($this->_registration)) {
1332
-            $transaction                                   = $this->_registration->transaction()
1333
-                ? $this->_registration->transaction()
1334
-                : EE_Transaction::new_instance();
1335
-            $this->_session                                = $transaction->session_data();
1336
-            $event_id                                      = $this->_registration->event_ID();
1337
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1338
-            $this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1339
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1340
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1341
-            $this->_template_args['grand_total']           = $transaction->total();
1342
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1343
-            // link back to overview
1344
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1345
-            $this->_template_args['registration']                = $this->_registration;
1346
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1347
-                [
1348
-                    'action'   => 'default',
1349
-                    'event_id' => $event_id,
1350
-                ],
1351
-                REG_ADMIN_URL
1352
-            );
1353
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1354
-                [
1355
-                    'action' => 'default',
1356
-                    'EVT_ID' => $event_id,
1357
-                    'page'   => 'espresso_transactions',
1358
-                ],
1359
-                admin_url('admin.php')
1360
-            );
1361
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1362
-                [
1363
-                    'page'   => 'espresso_events',
1364
-                    'action' => 'edit',
1365
-                    'post'   => $event_id,
1366
-                ],
1367
-                admin_url('admin.php')
1368
-            );
1369
-            // next and previous links
1370
-            $next_reg                                      = $this->_registration->next(
1371
-                null,
1372
-                [],
1373
-                'REG_ID'
1374
-            );
1375
-            $this->_template_args['next_registration']     = $next_reg
1376
-                ? $this->_next_link(
1377
-                    EE_Admin_Page::add_query_args_and_nonce(
1378
-                        [
1379
-                            'action'  => 'view_registration',
1380
-                            '_REG_ID' => $next_reg['REG_ID'],
1381
-                        ],
1382
-                        REG_ADMIN_URL
1383
-                    ),
1384
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1385
-                )
1386
-                : '';
1387
-            $previous_reg                                  = $this->_registration->previous(
1388
-                null,
1389
-                [],
1390
-                'REG_ID'
1391
-            );
1392
-            $this->_template_args['previous_registration'] = $previous_reg
1393
-                ? $this->_previous_link(
1394
-                    EE_Admin_Page::add_query_args_and_nonce(
1395
-                        [
1396
-                            'action'  => 'view_registration',
1397
-                            '_REG_ID' => $previous_reg['REG_ID'],
1398
-                        ],
1399
-                        REG_ADMIN_URL
1400
-                    ),
1401
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1402
-                )
1403
-                : '';
1404
-            // grab header
1405
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1406
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1407
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1408
-                $template_path,
1409
-                $this->_template_args,
1410
-                true
1411
-            );
1412
-        } else {
1413
-            $this->_template_args['admin_page_header'] = '';
1414
-            $this->_display_espresso_notices();
1415
-        }
1416
-        // the details template wrapper
1417
-        $this->display_admin_page_with_sidebar();
1418
-    }
1419
-
1420
-
1421
-    /**
1422
-     * @throws EE_Error
1423
-     * @throws InvalidArgumentException
1424
-     * @throws InvalidDataTypeException
1425
-     * @throws InvalidInterfaceException
1426
-     * @throws ReflectionException
1427
-     * @since 4.10.2.p
1428
-     */
1429
-    protected function _registration_details_metaboxes()
1430
-    {
1431
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1432
-        $this->_set_registration_object();
1433
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1434
-        $this->addMetaBox(
1435
-            'edit-reg-status-mbox',
1436
-            esc_html__('Registration Status', 'event_espresso'),
1437
-            [$this, 'set_reg_status_buttons_metabox'],
1438
-            $this->_wp_page_slug
1439
-        );
1440
-        $this->addMetaBox(
1441
-            'edit-reg-details-mbox',
1442
-            '<span>' . esc_html__('Registration Details', 'event_espresso')
1443
-            . '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1444
-            [$this, '_reg_details_meta_box'],
1445
-            $this->_wp_page_slug
1446
-        );
1447
-        if (
1448
-            $attendee instanceof EE_Attendee
1449
-            && EE_Registry::instance()->CAP->current_user_can(
1450
-                'ee_read_registration',
1451
-                'edit-reg-questions-mbox',
1452
-                $this->_registration->ID()
1453
-            )
1454
-        ) {
1455
-            $this->addMetaBox(
1456
-                'edit-reg-questions-mbox',
1457
-                esc_html__('Registration Form Answers', 'event_espresso'),
1458
-                [$this, '_reg_questions_meta_box'],
1459
-                $this->_wp_page_slug
1460
-            );
1461
-        }
1462
-        $this->addMetaBox(
1463
-            'edit-reg-registrant-mbox',
1464
-            esc_html__('Contact Details', 'event_espresso'),
1465
-            [$this, '_reg_registrant_side_meta_box'],
1466
-            $this->_wp_page_slug,
1467
-            'side'
1468
-        );
1469
-        if ($this->_registration->group_size() > 1) {
1470
-            $this->addMetaBox(
1471
-                'edit-reg-attendees-mbox',
1472
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1473
-                [$this, '_reg_attendees_meta_box'],
1474
-                $this->_wp_page_slug
1475
-            );
1476
-        }
1477
-    }
1478
-
1479
-
1480
-    /**
1481
-     * set_reg_status_buttons_metabox
1482
-     *
1483
-     * @return void
1484
-     * @throws EE_Error
1485
-     * @throws EntityNotFoundException
1486
-     * @throws InvalidArgumentException
1487
-     * @throws InvalidDataTypeException
1488
-     * @throws InvalidInterfaceException
1489
-     * @throws ReflectionException
1490
-     */
1491
-    public function set_reg_status_buttons_metabox()
1492
-    {
1493
-        $this->_set_registration_object();
1494
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1495
-        $output                 = $change_reg_status_form->form_open(
1496
-            self::add_query_args_and_nonce(
1497
-                [
1498
-                    'action' => 'change_reg_status',
1499
-                ],
1500
-                REG_ADMIN_URL
1501
-            )
1502
-        );
1503
-        $output                 .= $change_reg_status_form->get_html();
1504
-        $output                 .= $change_reg_status_form->form_close();
1505
-        echo wp_kses($output, AllowedTags::getWithFormTags());
1506
-    }
1507
-
1508
-
1509
-    /**
1510
-     * @return EE_Form_Section_Proper
1511
-     * @throws EE_Error
1512
-     * @throws InvalidArgumentException
1513
-     * @throws InvalidDataTypeException
1514
-     * @throws InvalidInterfaceException
1515
-     * @throws EntityNotFoundException
1516
-     * @throws ReflectionException
1517
-     */
1518
-    protected function _generate_reg_status_change_form()
1519
-    {
1520
-        $reg_status_change_form_array = [
1521
-            'name'            => 'reg_status_change_form',
1522
-            'html_id'         => 'reg-status-change-form',
1523
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1524
-            'subsections'     => [
1525
-                'return'         => new EE_Hidden_Input(
1526
-                    [
1527
-                        'name'    => 'return',
1528
-                        'default' => 'view_registration',
1529
-                    ]
1530
-                ),
1531
-                'REG_ID'         => new EE_Hidden_Input(
1532
-                    [
1533
-                        'name'    => 'REG_ID',
1534
-                        'default' => $this->_registration->ID(),
1535
-                    ]
1536
-                ),
1537
-            ],
1538
-        ];
1539
-        if (
1540
-            EE_Registry::instance()->CAP->current_user_can(
1541
-                'ee_edit_registration',
1542
-                'toggle_registration_status',
1543
-                $this->_registration->ID()
1544
-            )
1545
-        ) {
1546
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1547
-                $this->_get_reg_statuses(),
1548
-                [
1549
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1550
-                    'default'         => $this->_registration->status_ID(),
1551
-                ]
1552
-            );
1553
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1554
-                [
1555
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1556
-                    'default'         => false,
1557
-                    'html_help_text'  => esc_html__(
1558
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1559
-                        'event_espresso'
1560
-                    ),
1561
-                ]
1562
-            );
1563
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1564
-                [
1565
-                    'html_class'      => 'button--primary',
1566
-                    'html_label_text' => '&nbsp;',
1567
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1568
-                ]
1569
-            );
1570
-        }
1571
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1572
-    }
1573
-
1574
-
1575
-    /**
1576
-     * Returns an array of all the buttons for the various statuses and switch status actions
1577
-     *
1578
-     * @return array
1579
-     * @throws EE_Error
1580
-     * @throws InvalidArgumentException
1581
-     * @throws InvalidDataTypeException
1582
-     * @throws InvalidInterfaceException
1583
-     * @throws EntityNotFoundException
1584
-     */
1585
-    protected function _get_reg_statuses()
1586
-    {
1587
-        $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1588
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1589
-        // get current reg status
1590
-        $current_status = $this->_registration->status_ID();
1591
-        // is registration for free event? This will determine whether to display the pending payment option
1592
-        if (
1593
-            $current_status !== EEM_Registration::status_id_pending_payment
1594
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1595
-        ) {
1596
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1597
-        }
1598
-        return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1599
-    }
1600
-
1601
-
1602
-    /**
1603
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1604
-     *
1605
-     * @param bool $status REG status given for changing registrations to.
1606
-     * @param bool $notify Whether to send messages notifications or not.
1607
-     * @return array (array with reg_id(s) updated and whether update was successful.
1608
-     * @throws DomainException
1609
-     * @throws EE_Error
1610
-     * @throws EntityNotFoundException
1611
-     * @throws InvalidArgumentException
1612
-     * @throws InvalidDataTypeException
1613
-     * @throws InvalidInterfaceException
1614
-     * @throws ReflectionException
1615
-     * @throws RuntimeException
1616
-     */
1617
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1618
-    {
1619
-        $REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1620
-            ? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1621
-            : $this->request->getRequestParam('_REG_ID', [], 'int', true);
1622
-
1623
-        // sanitize $REG_IDs
1624
-        $REG_IDs = array_map('absint', $REG_IDs);
1625
-        // and remove empty entries
1626
-        $REG_IDs = array_filter($REG_IDs);
1627
-
1628
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1629
-
1630
-        /**
1631
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1632
-         * Currently this value is used downstream by the _process_resend_registration method.
1633
-         *
1634
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1635
-         * @param bool                     $status           The status registrations were changed to.
1636
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1637
-         * @param Registrations_Admin_Page $admin_page_object
1638
-         */
1639
-        $REG_ID = apply_filters(
1640
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1641
-            $result['REG_ID'],
1642
-            $status,
1643
-            $result['success'],
1644
-            $this
1645
-        );
1646
-        $this->request->setRequestParam('_REG_ID', $REG_ID);
1647
-
1648
-        // notify?
1649
-        if (
1650
-            $notify
1651
-            && $result['success']
1652
-            && ! empty($REG_ID)
1653
-            && EE_Registry::instance()->CAP->current_user_can(
1654
-                'ee_send_message',
1655
-                'espresso_registrations_resend_registration'
1656
-            )
1657
-        ) {
1658
-            $this->_process_resend_registration();
1659
-        }
1660
-        return $result;
1661
-    }
1662
-
1663
-
1664
-    /**
1665
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1666
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1667
-     *
1668
-     * @param array  $REG_IDs
1669
-     * @param string $status
1670
-     * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1671
-     *                       slug sent with setting the registration status.
1672
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1673
-     * @throws EE_Error
1674
-     * @throws InvalidArgumentException
1675
-     * @throws InvalidDataTypeException
1676
-     * @throws InvalidInterfaceException
1677
-     * @throws ReflectionException
1678
-     * @throws RuntimeException
1679
-     * @throws EntityNotFoundException
1680
-     * @throws DomainException
1681
-     */
1682
-    protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1683
-    {
1684
-        $success = false;
1685
-        // typecast $REG_IDs
1686
-        $REG_IDs = (array) $REG_IDs;
1687
-        if (! empty($REG_IDs)) {
1688
-            $success = true;
1689
-            // set default status if none is passed
1690
-            $status         = $status ?: EEM_Registration::status_id_pending_payment;
1691
-            $status_context = $notify
1692
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1693
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1694
-            // loop through REG_ID's and change status
1695
-            foreach ($REG_IDs as $REG_ID) {
1696
-                $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1697
-                if ($registration instanceof EE_Registration) {
1698
-                    $registration->set_status(
1699
-                        $status,
1700
-                        false,
1701
-                        new Context(
1702
-                            $status_context,
1703
-                            esc_html__(
1704
-                                'Manually triggered status change on a Registration Admin Page route.',
1705
-                                'event_espresso'
1706
-                            )
1707
-                        )
1708
-                    );
1709
-                    $result = $registration->save();
1710
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1711
-                    $success = $result !== false ? $success : false;
1712
-                }
1713
-            }
1714
-        }
1715
-
1716
-        // return $success and processed registrations
1717
-        return ['REG_ID' => $REG_IDs, 'success' => $success];
1718
-    }
1719
-
1720
-
1721
-    /**
1722
-     * Common logic for setting up success message and redirecting to appropriate route
1723
-     *
1724
-     * @param string $STS_ID status id for the registration changed to
1725
-     * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1726
-     * @return void
1727
-     * @throws DomainException
1728
-     * @throws EE_Error
1729
-     * @throws EntityNotFoundException
1730
-     * @throws InvalidArgumentException
1731
-     * @throws InvalidDataTypeException
1732
-     * @throws InvalidInterfaceException
1733
-     * @throws ReflectionException
1734
-     * @throws RuntimeException
1735
-     */
1736
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1737
-    {
1738
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1739
-            : ['success' => false];
1740
-        $success = isset($result['success']) && $result['success'];
1741
-        // setup success message
1742
-        if ($success) {
1743
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1744
-                $msg = sprintf(
1745
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1746
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1747
-                );
1748
-            } else {
1749
-                $msg = sprintf(
1750
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1751
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1752
-                );
1753
-            }
1754
-            EE_Error::add_success($msg);
1755
-        } else {
1756
-            EE_Error::add_error(
1757
-                esc_html__(
1758
-                    'Something went wrong, and the status was not changed',
1759
-                    'event_espresso'
1760
-                ),
1761
-                __FILE__,
1762
-                __LINE__,
1763
-                __FUNCTION__
1764
-            );
1765
-        }
1766
-        $return = $this->request->getRequestParam('return');
1767
-        $route  = $return === 'view_registration'
1768
-            ? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1769
-            : ['action' => 'default'];
1770
-        $route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1771
-        $this->_redirect_after_action($success, '', '', $route, true);
1772
-    }
1773
-
1774
-
1775
-    /**
1776
-     * incoming reg status change from reg details page.
1777
-     *
1778
-     * @return void
1779
-     * @throws EE_Error
1780
-     * @throws EntityNotFoundException
1781
-     * @throws InvalidArgumentException
1782
-     * @throws InvalidDataTypeException
1783
-     * @throws InvalidInterfaceException
1784
-     * @throws ReflectionException
1785
-     * @throws RuntimeException
1786
-     * @throws DomainException
1787
-     */
1788
-    protected function _change_reg_status()
1789
-    {
1790
-        $this->request->setRequestParam('return', 'view_registration');
1791
-        // set notify based on whether the send notifications toggle is set or not
1792
-        $notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1793
-        $reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1794
-        $this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1795
-        switch ($reg_status) {
1796
-            case EEM_Registration::status_id_approved:
1797
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1798
-                $this->approve_registration($notify);
1799
-                break;
1800
-            case EEM_Registration::status_id_pending_payment:
1801
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1802
-                $this->pending_registration($notify);
1803
-                break;
1804
-            case EEM_Registration::status_id_not_approved:
1805
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1806
-                $this->not_approve_registration($notify);
1807
-                break;
1808
-            case EEM_Registration::status_id_declined:
1809
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1810
-                $this->decline_registration($notify);
1811
-                break;
1812
-            case EEM_Registration::status_id_cancelled:
1813
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1814
-                $this->cancel_registration($notify);
1815
-                break;
1816
-            case EEM_Registration::status_id_wait_list:
1817
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1818
-                $this->wait_list_registration($notify);
1819
-                break;
1820
-            case EEM_Registration::status_id_incomplete:
1821
-            default:
1822
-                $this->request->unSetRequestParam('return');
1823
-                $this->_reg_status_change_return('');
1824
-                break;
1825
-        }
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * Callback for bulk action routes.
1831
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1832
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
1833
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1834
-     * when an action is happening on just a single registration).
1835
-     *
1836
-     * @param      $action
1837
-     * @param bool $notify
1838
-     */
1839
-    protected function bulk_action_on_registrations($action, $notify = false)
1840
-    {
1841
-        do_action(
1842
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1843
-            $this,
1844
-            $action,
1845
-            $notify
1846
-        );
1847
-        $method = $action . '_registration';
1848
-        if (method_exists($this, $method)) {
1849
-            $this->$method($notify);
1850
-        }
1851
-    }
1852
-
1853
-
1854
-    /**
1855
-     * approve_registration
1856
-     *
1857
-     * @param bool $notify whether or not to notify the registrant about their approval.
1858
-     * @return void
1859
-     * @throws EE_Error
1860
-     * @throws EntityNotFoundException
1861
-     * @throws InvalidArgumentException
1862
-     * @throws InvalidDataTypeException
1863
-     * @throws InvalidInterfaceException
1864
-     * @throws ReflectionException
1865
-     * @throws RuntimeException
1866
-     * @throws DomainException
1867
-     */
1868
-    protected function approve_registration($notify = false)
1869
-    {
1870
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1871
-    }
1872
-
1873
-
1874
-    /**
1875
-     * decline_registration
1876
-     *
1877
-     * @param bool $notify whether or not to notify the registrant about their status change.
1878
-     * @return void
1879
-     * @throws EE_Error
1880
-     * @throws EntityNotFoundException
1881
-     * @throws InvalidArgumentException
1882
-     * @throws InvalidDataTypeException
1883
-     * @throws InvalidInterfaceException
1884
-     * @throws ReflectionException
1885
-     * @throws RuntimeException
1886
-     * @throws DomainException
1887
-     */
1888
-    protected function decline_registration($notify = false)
1889
-    {
1890
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1891
-    }
1892
-
1893
-
1894
-    /**
1895
-     * cancel_registration
1896
-     *
1897
-     * @param bool $notify whether or not to notify the registrant about their status change.
1898
-     * @return void
1899
-     * @throws EE_Error
1900
-     * @throws EntityNotFoundException
1901
-     * @throws InvalidArgumentException
1902
-     * @throws InvalidDataTypeException
1903
-     * @throws InvalidInterfaceException
1904
-     * @throws ReflectionException
1905
-     * @throws RuntimeException
1906
-     * @throws DomainException
1907
-     */
1908
-    protected function cancel_registration($notify = false)
1909
-    {
1910
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1911
-    }
1912
-
1913
-
1914
-    /**
1915
-     * not_approve_registration
1916
-     *
1917
-     * @param bool $notify whether or not to notify the registrant about their status change.
1918
-     * @return void
1919
-     * @throws EE_Error
1920
-     * @throws EntityNotFoundException
1921
-     * @throws InvalidArgumentException
1922
-     * @throws InvalidDataTypeException
1923
-     * @throws InvalidInterfaceException
1924
-     * @throws ReflectionException
1925
-     * @throws RuntimeException
1926
-     * @throws DomainException
1927
-     */
1928
-    protected function not_approve_registration($notify = false)
1929
-    {
1930
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1931
-    }
1932
-
1933
-
1934
-    /**
1935
-     * decline_registration
1936
-     *
1937
-     * @param bool $notify whether or not to notify the registrant about their status change.
1938
-     * @return void
1939
-     * @throws EE_Error
1940
-     * @throws EntityNotFoundException
1941
-     * @throws InvalidArgumentException
1942
-     * @throws InvalidDataTypeException
1943
-     * @throws InvalidInterfaceException
1944
-     * @throws ReflectionException
1945
-     * @throws RuntimeException
1946
-     * @throws DomainException
1947
-     */
1948
-    protected function pending_registration($notify = false)
1949
-    {
1950
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1951
-    }
1952
-
1953
-
1954
-    /**
1955
-     * waitlist_registration
1956
-     *
1957
-     * @param bool $notify whether or not to notify the registrant about their status change.
1958
-     * @return void
1959
-     * @throws EE_Error
1960
-     * @throws EntityNotFoundException
1961
-     * @throws InvalidArgumentException
1962
-     * @throws InvalidDataTypeException
1963
-     * @throws InvalidInterfaceException
1964
-     * @throws ReflectionException
1965
-     * @throws RuntimeException
1966
-     * @throws DomainException
1967
-     */
1968
-    protected function wait_list_registration($notify = false)
1969
-    {
1970
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1971
-    }
1972
-
1973
-
1974
-    /**
1975
-     * generates HTML for the Registration main meta box
1976
-     *
1977
-     * @return void
1978
-     * @throws DomainException
1979
-     * @throws EE_Error
1980
-     * @throws InvalidArgumentException
1981
-     * @throws InvalidDataTypeException
1982
-     * @throws InvalidInterfaceException
1983
-     * @throws ReflectionException
1984
-     * @throws EntityNotFoundException
1985
-     */
1986
-    public function _reg_details_meta_box()
1987
-    {
1988
-        EEH_Autoloader::register_line_item_display_autoloaders();
1989
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1990
-        EE_Registry::instance()->load_helper('Line_Item');
1991
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1992
-            : EE_Transaction::new_instance();
1993
-        $this->_session = $transaction->session_data();
1994
-        $filters        = new EE_Line_Item_Filter_Collection();
1995
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1996
-        $filters->add(new EE_Non_Zero_Line_Item_Filter());
1997
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
1998
-            $filters,
1999
-            $transaction->total_line_item()
2000
-        );
2001
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
2002
-        $line_item_display                       = new EE_Line_Item_Display(
2003
-            'reg_admin_table',
2004
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2005
-        );
2006
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2007
-            $filtered_line_item_tree,
2008
-            ['EE_Registration' => $this->_registration]
2009
-        );
2010
-        $attendee                                = $this->_registration->attendee();
2011
-        if (
2012
-            EE_Registry::instance()->CAP->current_user_can(
2013
-                'ee_read_transaction',
2014
-                'espresso_transactions_view_transaction'
2015
-            )
2016
-        ) {
2017
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2018
-                EE_Admin_Page::add_query_args_and_nonce(
2019
-                    [
2020
-                        'action' => 'view_transaction',
2021
-                        'TXN_ID' => $transaction->ID(),
2022
-                    ],
2023
-                    TXN_ADMIN_URL
2024
-                ),
2025
-                esc_html__(' View Transaction', 'event_espresso'),
2026
-                'button button--secondary right',
2027
-                'dashicons dashicons-cart'
2028
-            );
2029
-        } else {
2030
-            $this->_template_args['view_transaction_button'] = '';
2031
-        }
2032
-        if (
2033
-            $attendee instanceof EE_Attendee
2034
-            && EE_Registry::instance()->CAP->current_user_can(
2035
-                'ee_send_message',
2036
-                'espresso_registrations_resend_registration'
2037
-            )
2038
-        ) {
2039
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2040
-                EE_Admin_Page::add_query_args_and_nonce(
2041
-                    [
2042
-                        'action'      => 'resend_registration',
2043
-                        '_REG_ID'     => $this->_registration->ID(),
2044
-                        'redirect_to' => 'view_registration',
2045
-                    ],
2046
-                    REG_ADMIN_URL
2047
-                ),
2048
-                esc_html__(' Resend Registration', 'event_espresso'),
2049
-                'button button--secondary right',
2050
-                'dashicons dashicons-email-alt'
2051
-            );
2052
-        } else {
2053
-            $this->_template_args['resend_registration_button'] = '';
2054
-        }
2055
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2056
-        $payment                               = $transaction->get_first_related('Payment');
2057
-        $payment                               = ! $payment instanceof EE_Payment
2058
-            ? EE_Payment::new_instance()
2059
-            : $payment;
2060
-        $payment_method                        = $payment->get_first_related('Payment_Method');
2061
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method
2062
-            ? EE_Payment_Method::new_instance()
2063
-            : $payment_method;
2064
-        $reg_details                           = [
2065
-            'payment_method'       => $payment_method->name(),
2066
-            'response_msg'         => $payment->gateway_response(),
2067
-            'registration_id'      => $this->_registration->get('REG_code'),
2068
-            'registration_session' => $this->_registration->session_ID(),
2069
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2070
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2071
-        ];
2072
-        if (isset($reg_details['registration_id'])) {
2073
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2074
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2075
-                'Registration ID',
2076
-                'event_espresso'
2077
-            );
2078
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2079
-        }
2080
-        if (isset($reg_details['payment_method'])) {
2081
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2082
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2083
-                'Most Recent Payment Method',
2084
-                'event_espresso'
2085
-            );
2086
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2087
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2088
-            $this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2089
-                'Payment method response',
2090
-                'event_espresso'
2091
-            );
2092
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2093
-        }
2094
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2095
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2096
-            'Registration Session',
2097
-            'event_espresso'
2098
-        );
2099
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2100
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2101
-        $this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2102
-            'Registration placed from IP',
2103
-            'event_espresso'
2104
-        );
2105
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2106
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2107
-        $this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2108
-            'Registrant User Agent',
2109
-            'event_espresso'
2110
-        );
2111
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2112
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2113
-            [
2114
-                'action'   => 'default',
2115
-                'event_id' => $this->_registration->event_ID(),
2116
-            ],
2117
-            REG_ADMIN_URL
2118
-        );
2119
-
2120
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2121
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2122
-
2123
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2124
-        EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2125
-    }
2126
-
2127
-
2128
-    /**
2129
-     * generates HTML for the Registration Questions meta box.
2130
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2131
-     * otherwise uses new forms system
2132
-     *
2133
-     * @return void
2134
-     * @throws DomainException
2135
-     * @throws EE_Error
2136
-     * @throws InvalidArgumentException
2137
-     * @throws InvalidDataTypeException
2138
-     * @throws InvalidInterfaceException
2139
-     * @throws ReflectionException
2140
-     */
2141
-    public function _reg_questions_meta_box()
2142
-    {
2143
-        // allow someone to override this method entirely
2144
-        if (
2145
-            apply_filters(
2146
-                'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2147
-                true,
2148
-                $this,
2149
-                $this->_registration
2150
-            )
2151
-        ) {
2152
-            $form = $this->_get_reg_custom_questions_form(
2153
-                $this->_registration->ID()
2154
-            );
2155
-
2156
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2157
-                ? $form->get_html_and_js()
2158
-                : '';
2159
-
2160
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2161
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2162
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2163
-            EEH_Template::display_template($template_path, $this->_template_args);
2164
-        }
2165
-    }
2166
-
2167
-
2168
-    /**
2169
-     * form_before_question_group
2170
-     *
2171
-     * @param string $output
2172
-     * @return        string
2173
-     * @deprecated    as of 4.8.32.rc.000
2174
-     */
2175
-    public function form_before_question_group($output)
2176
-    {
2177
-        EE_Error::doing_it_wrong(
2178
-            __CLASS__ . '::' . __FUNCTION__,
2179
-            esc_html__(
2180
-                '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.',
2181
-                'event_espresso'
2182
-            ),
2183
-            '4.8.32.rc.000'
2184
-        );
2185
-        return '
23
+	/**
24
+	 * @var EE_Registration
25
+	 */
26
+	private $_registration;
27
+
28
+	/**
29
+	 * @var EE_Event
30
+	 */
31
+	private $_reg_event;
32
+
33
+	/**
34
+	 * @var EE_Session
35
+	 */
36
+	private $_session;
37
+
38
+	/**
39
+	 * @var array
40
+	 */
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form;
50
+
51
+	/**
52
+	 * @var EEM_Registration $registration_model
53
+	 */
54
+	private $registration_model;
55
+
56
+	/**
57
+	 * @var EEM_Attendee $attendee_model
58
+	 */
59
+	private $attendee_model;
60
+
61
+	/**
62
+	 * @var EEM_Event $event_model
63
+	 */
64
+	private $event_model;
65
+
66
+	/**
67
+	 * @var EEM_Status $status_model
68
+	 */
69
+	private $status_model;
70
+
71
+
72
+	/**
73
+	 * @param bool $routing
74
+	 * @throws EE_Error
75
+	 * @throws InvalidArgumentException
76
+	 * @throws InvalidDataTypeException
77
+	 * @throws InvalidInterfaceException
78
+	 * @throws ReflectionException
79
+	 */
80
+	public function __construct($routing = true)
81
+	{
82
+		parent::__construct($routing);
83
+		add_action('wp_loaded', [$this, 'wp_loaded']);
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return EEM_Registration
89
+	 * @throws InvalidArgumentException
90
+	 * @throws InvalidDataTypeException
91
+	 * @throws InvalidInterfaceException
92
+	 * @since 4.10.2.p
93
+	 */
94
+	protected function getRegistrationModel()
95
+	{
96
+		if (! $this->registration_model instanceof EEM_Registration) {
97
+			$this->registration_model = $this->loader->getShared('EEM_Registration');
98
+		}
99
+		return $this->registration_model;
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return EEM_Attendee
105
+	 * @throws InvalidArgumentException
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws InvalidInterfaceException
108
+	 * @since 4.10.2.p
109
+	 */
110
+	protected function getAttendeeModel()
111
+	{
112
+		if (! $this->attendee_model instanceof EEM_Attendee) {
113
+			$this->attendee_model = $this->loader->getShared('EEM_Attendee');
114
+		}
115
+		return $this->attendee_model;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return EEM_Event
121
+	 * @throws InvalidArgumentException
122
+	 * @throws InvalidDataTypeException
123
+	 * @throws InvalidInterfaceException
124
+	 * @since 4.10.2.p
125
+	 */
126
+	protected function getEventModel()
127
+	{
128
+		if (! $this->event_model instanceof EEM_Event) {
129
+			$this->event_model = $this->loader->getShared('EEM_Event');
130
+		}
131
+		return $this->event_model;
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return EEM_Status
137
+	 * @throws InvalidArgumentException
138
+	 * @throws InvalidDataTypeException
139
+	 * @throws InvalidInterfaceException
140
+	 * @since 4.10.2.p
141
+	 */
142
+	protected function getStatusModel()
143
+	{
144
+		if (! $this->status_model instanceof EEM_Status) {
145
+			$this->status_model = $this->loader->getShared('EEM_Status');
146
+		}
147
+		return $this->status_model;
148
+	}
149
+
150
+
151
+	public function wp_loaded()
152
+	{
153
+		// when adding a new registration...
154
+		$action = $this->request->getRequestParam('action');
155
+		if ($action === 'new_registration') {
156
+			EE_System::do_not_cache();
157
+			if ($this->request->getRequestParam('processing_registration', 0, 'int') !== 1) {
158
+				// and it's NOT the attendee information reg step
159
+				// force cookie expiration by setting time to last week
160
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
161
+				// and update the global
162
+				$_COOKIE['ee_registration_added'] = 0;
163
+			}
164
+		}
165
+	}
166
+
167
+
168
+	protected function _init_page_props()
169
+	{
170
+		$this->page_slug        = REG_PG_SLUG;
171
+		$this->_admin_base_url  = REG_ADMIN_URL;
172
+		$this->_admin_base_path = REG_ADMIN;
173
+		$this->page_label       = esc_html__('Registrations', 'event_espresso');
174
+		$this->_cpt_routes      = [
175
+			'add_new_attendee' => 'espresso_attendees',
176
+			'edit_attendee'    => 'espresso_attendees',
177
+			'insert_attendee'  => 'espresso_attendees',
178
+			'update_attendee'  => 'espresso_attendees',
179
+		];
180
+		$this->_cpt_model_names = [
181
+			'add_new_attendee' => 'EEM_Attendee',
182
+			'edit_attendee'    => 'EEM_Attendee',
183
+		];
184
+		$this->_cpt_edit_routes = [
185
+			'espresso_attendees' => 'edit_attendee',
186
+		];
187
+		$this->_pagenow_map     = [
188
+			'add_new_attendee' => 'post-new.php',
189
+			'edit_attendee'    => 'post.php',
190
+			'trash'            => 'post.php',
191
+		];
192
+		add_action('edit_form_after_title', [$this, 'after_title_form_fields'], 10);
193
+		// add filters so that the comment urls don't take users to a confusing 404 page
194
+		add_filter('get_comment_link', [$this, 'clear_comment_link'], 10, 2);
195
+	}
196
+
197
+
198
+	/**
199
+	 * @param string     $link    The comment permalink with '#comment-$id' appended.
200
+	 * @param WP_Comment $comment The current comment object.
201
+	 * @return string
202
+	 */
203
+	public function clear_comment_link($link, WP_Comment $comment)
204
+	{
205
+		// gotta make sure this only happens on this route
206
+		$post_type = get_post_type($comment->comment_post_ID);
207
+		if ($post_type === 'espresso_attendees') {
208
+			return '#commentsdiv';
209
+		}
210
+		return $link;
211
+	}
212
+
213
+
214
+	protected function _ajax_hooks()
215
+	{
216
+		// todo: all hooks for registrations ajax goes in here
217
+		add_action('wp_ajax_toggle_checkin_status', [$this, 'toggle_checkin_status']);
218
+	}
219
+
220
+
221
+	protected function _define_page_props()
222
+	{
223
+		$this->_admin_page_title = $this->page_label;
224
+		$this->_labels           = [
225
+			'buttons'                      => [
226
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
227
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
228
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
229
+				'report'              => esc_html__('Event Registrations CSV Report', 'event_espresso'),
230
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
231
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
232
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
233
+				'contact_list_export' => esc_html__('Export Data', 'event_espresso'),
234
+			],
235
+			'publishbox'                   => [
236
+				'add_new_attendee' => esc_html__('Add Contact Record', 'event_espresso'),
237
+				'edit_attendee'    => esc_html__('Update Contact Record', 'event_espresso'),
238
+			],
239
+			'hide_add_button_on_cpt_route' => [
240
+				'edit_attendee' => true,
241
+			],
242
+		];
243
+	}
244
+
245
+
246
+	/**
247
+	 * grab url requests and route them
248
+	 *
249
+	 * @return void
250
+	 * @throws EE_Error
251
+	 */
252
+	public function _set_page_routes()
253
+	{
254
+		$this->_get_registration_status_array();
255
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
256
+		$REG_ID             = $this->request->getRequestParam('reg_status_change_form[REG_ID]', $REG_ID, 'int');
257
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
258
+		$ATT_ID             = $this->request->getRequestParam('post', $ATT_ID, 'int');
259
+		$this->_page_routes = [
260
+			'default'                             => [
261
+				'func'       => '_registrations_overview_list_table',
262
+				'capability' => 'ee_read_registrations',
263
+			],
264
+			'view_registration'                   => [
265
+				'func'       => '_registration_details',
266
+				'capability' => 'ee_read_registration',
267
+				'obj_id'     => $REG_ID,
268
+			],
269
+			'edit_registration'                   => [
270
+				'func'               => '_update_attendee_registration_form',
271
+				'noheader'           => true,
272
+				'headers_sent_route' => 'view_registration',
273
+				'capability'         => 'ee_edit_registration',
274
+				'obj_id'             => $REG_ID,
275
+				'_REG_ID'            => $REG_ID,
276
+			],
277
+			'trash_registrations'                 => [
278
+				'func'       => '_trash_or_restore_registrations',
279
+				'args'       => ['trash' => true],
280
+				'noheader'   => true,
281
+				'capability' => 'ee_delete_registrations',
282
+			],
283
+			'restore_registrations'               => [
284
+				'func'       => '_trash_or_restore_registrations',
285
+				'args'       => ['trash' => false],
286
+				'noheader'   => true,
287
+				'capability' => 'ee_delete_registrations',
288
+			],
289
+			'delete_registrations'                => [
290
+				'func'       => '_delete_registrations',
291
+				'noheader'   => true,
292
+				'capability' => 'ee_delete_registrations',
293
+			],
294
+			'new_registration'                    => [
295
+				'func'       => 'new_registration',
296
+				'capability' => 'ee_edit_registrations',
297
+			],
298
+			'process_reg_step'                    => [
299
+				'func'       => 'process_reg_step',
300
+				'noheader'   => true,
301
+				'capability' => 'ee_edit_registrations',
302
+			],
303
+			'redirect_to_txn'                     => [
304
+				'func'       => 'redirect_to_txn',
305
+				'noheader'   => true,
306
+				'capability' => 'ee_edit_registrations',
307
+			],
308
+			'change_reg_status'                   => [
309
+				'func'       => '_change_reg_status',
310
+				'noheader'   => true,
311
+				'capability' => 'ee_edit_registration',
312
+				'obj_id'     => $REG_ID,
313
+			],
314
+			'approve_registration'                => [
315
+				'func'       => 'approve_registration',
316
+				'noheader'   => true,
317
+				'capability' => 'ee_edit_registration',
318
+				'obj_id'     => $REG_ID,
319
+			],
320
+			'approve_and_notify_registration'     => [
321
+				'func'       => 'approve_registration',
322
+				'noheader'   => true,
323
+				'args'       => [true],
324
+				'capability' => 'ee_edit_registration',
325
+				'obj_id'     => $REG_ID,
326
+			],
327
+			'approve_registrations'               => [
328
+				'func'       => 'bulk_action_on_registrations',
329
+				'noheader'   => true,
330
+				'capability' => 'ee_edit_registrations',
331
+				'args'       => ['approve'],
332
+			],
333
+			'approve_and_notify_registrations'    => [
334
+				'func'       => 'bulk_action_on_registrations',
335
+				'noheader'   => true,
336
+				'capability' => 'ee_edit_registrations',
337
+				'args'       => ['approve', true],
338
+			],
339
+			'decline_registration'                => [
340
+				'func'       => 'decline_registration',
341
+				'noheader'   => true,
342
+				'capability' => 'ee_edit_registration',
343
+				'obj_id'     => $REG_ID,
344
+			],
345
+			'decline_and_notify_registration'     => [
346
+				'func'       => 'decline_registration',
347
+				'noheader'   => true,
348
+				'args'       => [true],
349
+				'capability' => 'ee_edit_registration',
350
+				'obj_id'     => $REG_ID,
351
+			],
352
+			'decline_registrations'               => [
353
+				'func'       => 'bulk_action_on_registrations',
354
+				'noheader'   => true,
355
+				'capability' => 'ee_edit_registrations',
356
+				'args'       => ['decline'],
357
+			],
358
+			'decline_and_notify_registrations'    => [
359
+				'func'       => 'bulk_action_on_registrations',
360
+				'noheader'   => true,
361
+				'capability' => 'ee_edit_registrations',
362
+				'args'       => ['decline', true],
363
+			],
364
+			'pending_registration'                => [
365
+				'func'       => 'pending_registration',
366
+				'noheader'   => true,
367
+				'capability' => 'ee_edit_registration',
368
+				'obj_id'     => $REG_ID,
369
+			],
370
+			'pending_and_notify_registration'     => [
371
+				'func'       => 'pending_registration',
372
+				'noheader'   => true,
373
+				'args'       => [true],
374
+				'capability' => 'ee_edit_registration',
375
+				'obj_id'     => $REG_ID,
376
+			],
377
+			'pending_registrations'               => [
378
+				'func'       => 'bulk_action_on_registrations',
379
+				'noheader'   => true,
380
+				'capability' => 'ee_edit_registrations',
381
+				'args'       => ['pending'],
382
+			],
383
+			'pending_and_notify_registrations'    => [
384
+				'func'       => 'bulk_action_on_registrations',
385
+				'noheader'   => true,
386
+				'capability' => 'ee_edit_registrations',
387
+				'args'       => ['pending', true],
388
+			],
389
+			'no_approve_registration'             => [
390
+				'func'       => 'not_approve_registration',
391
+				'noheader'   => true,
392
+				'capability' => 'ee_edit_registration',
393
+				'obj_id'     => $REG_ID,
394
+			],
395
+			'no_approve_and_notify_registration'  => [
396
+				'func'       => 'not_approve_registration',
397
+				'noheader'   => true,
398
+				'args'       => [true],
399
+				'capability' => 'ee_edit_registration',
400
+				'obj_id'     => $REG_ID,
401
+			],
402
+			'no_approve_registrations'            => [
403
+				'func'       => 'bulk_action_on_registrations',
404
+				'noheader'   => true,
405
+				'capability' => 'ee_edit_registrations',
406
+				'args'       => ['not_approve'],
407
+			],
408
+			'no_approve_and_notify_registrations' => [
409
+				'func'       => 'bulk_action_on_registrations',
410
+				'noheader'   => true,
411
+				'capability' => 'ee_edit_registrations',
412
+				'args'       => ['not_approve', true],
413
+			],
414
+			'cancel_registration'                 => [
415
+				'func'       => 'cancel_registration',
416
+				'noheader'   => true,
417
+				'capability' => 'ee_edit_registration',
418
+				'obj_id'     => $REG_ID,
419
+			],
420
+			'cancel_and_notify_registration'      => [
421
+				'func'       => 'cancel_registration',
422
+				'noheader'   => true,
423
+				'args'       => [true],
424
+				'capability' => 'ee_edit_registration',
425
+				'obj_id'     => $REG_ID,
426
+			],
427
+			'cancel_registrations'                => [
428
+				'func'       => 'bulk_action_on_registrations',
429
+				'noheader'   => true,
430
+				'capability' => 'ee_edit_registrations',
431
+				'args'       => ['cancel'],
432
+			],
433
+			'cancel_and_notify_registrations'     => [
434
+				'func'       => 'bulk_action_on_registrations',
435
+				'noheader'   => true,
436
+				'capability' => 'ee_edit_registrations',
437
+				'args'       => ['cancel', true],
438
+			],
439
+			'wait_list_registration'              => [
440
+				'func'       => 'wait_list_registration',
441
+				'noheader'   => true,
442
+				'capability' => 'ee_edit_registration',
443
+				'obj_id'     => $REG_ID,
444
+			],
445
+			'wait_list_and_notify_registration'   => [
446
+				'func'       => 'wait_list_registration',
447
+				'noheader'   => true,
448
+				'args'       => [true],
449
+				'capability' => 'ee_edit_registration',
450
+				'obj_id'     => $REG_ID,
451
+			],
452
+			'contact_list'                        => [
453
+				'func'       => '_attendee_contact_list_table',
454
+				'capability' => 'ee_read_contacts',
455
+			],
456
+			'add_new_attendee'                    => [
457
+				'func' => '_create_new_cpt_item',
458
+				'args' => [
459
+					'new_attendee' => true,
460
+					'capability'   => 'ee_edit_contacts',
461
+				],
462
+			],
463
+			'edit_attendee'                       => [
464
+				'func'       => '_edit_cpt_item',
465
+				'capability' => 'ee_edit_contacts',
466
+				'obj_id'     => $ATT_ID,
467
+			],
468
+			'duplicate_attendee'                  => [
469
+				'func'       => '_duplicate_attendee',
470
+				'noheader'   => true,
471
+				'capability' => 'ee_edit_contacts',
472
+				'obj_id'     => $ATT_ID,
473
+			],
474
+			'insert_attendee'                     => [
475
+				'func'       => '_insert_or_update_attendee',
476
+				'args'       => [
477
+					'new_attendee' => true,
478
+				],
479
+				'noheader'   => true,
480
+				'capability' => 'ee_edit_contacts',
481
+			],
482
+			'update_attendee'                     => [
483
+				'func'       => '_insert_or_update_attendee',
484
+				'args'       => [
485
+					'new_attendee' => false,
486
+				],
487
+				'noheader'   => true,
488
+				'capability' => 'ee_edit_contacts',
489
+				'obj_id'     => $ATT_ID,
490
+			],
491
+			'trash_attendees'                     => [
492
+				'func'       => '_trash_or_restore_attendees',
493
+				'args'       => [
494
+					'trash' => 'true',
495
+				],
496
+				'noheader'   => true,
497
+				'capability' => 'ee_delete_contacts',
498
+			],
499
+			'trash_attendee'                      => [
500
+				'func'       => '_trash_or_restore_attendees',
501
+				'args'       => [
502
+					'trash' => true,
503
+				],
504
+				'noheader'   => true,
505
+				'capability' => 'ee_delete_contacts',
506
+				'obj_id'     => $ATT_ID,
507
+			],
508
+			'restore_attendees'                   => [
509
+				'func'       => '_trash_or_restore_attendees',
510
+				'args'       => [
511
+					'trash' => false,
512
+				],
513
+				'noheader'   => true,
514
+				'capability' => 'ee_delete_contacts',
515
+				'obj_id'     => $ATT_ID,
516
+			],
517
+			'resend_registration'                 => [
518
+				'func'       => '_resend_registration',
519
+				'noheader'   => true,
520
+				'capability' => 'ee_send_message',
521
+			],
522
+			'registrations_report'                => [
523
+				'func'       => '_registrations_report',
524
+				'noheader'   => true,
525
+				'capability' => 'ee_read_registrations',
526
+			],
527
+			'contact_list_export'                 => [
528
+				'func'       => '_contact_list_export',
529
+				'noheader'   => true,
530
+				'capability' => 'export',
531
+			],
532
+			'contact_list_report'                 => [
533
+				'func'       => '_contact_list_report',
534
+				'noheader'   => true,
535
+				'capability' => 'ee_read_contacts',
536
+			],
537
+		];
538
+	}
539
+
540
+
541
+	protected function _set_page_config()
542
+	{
543
+		$REG_ID             = $this->request->getRequestParam('_REG_ID', 0, 'int');
544
+		$ATT_ID             = $this->request->getRequestParam('ATT_ID', 0, 'int');
545
+		$this->_page_config = [
546
+			'default'           => [
547
+				'nav'           => [
548
+					'label' => esc_html__('Overview', 'event_espresso'),
549
+					'order' => 5,
550
+				],
551
+				'help_tabs'     => [
552
+					'registrations_overview_help_tab'                       => [
553
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
554
+						'filename' => 'registrations_overview',
555
+					],
556
+					'registrations_overview_table_column_headings_help_tab' => [
557
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
558
+						'filename' => 'registrations_overview_table_column_headings',
559
+					],
560
+					'registrations_overview_filters_help_tab'               => [
561
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
562
+						'filename' => 'registrations_overview_filters',
563
+					],
564
+					'registrations_overview_views_help_tab'                 => [
565
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
566
+						'filename' => 'registrations_overview_views',
567
+					],
568
+					'registrations_regoverview_other_help_tab'              => [
569
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
570
+						'filename' => 'registrations_overview_other',
571
+					],
572
+				],
573
+				'list_table'    => 'EE_Registrations_List_Table',
574
+				'require_nonce' => false,
575
+			],
576
+			'view_registration' => [
577
+				'nav'           => [
578
+					'label'      => esc_html__('REG Details', 'event_espresso'),
579
+					'order'      => 15,
580
+					'url'        => $REG_ID
581
+						? add_query_arg(['_REG_ID' => $REG_ID], $this->_current_page_view_url)
582
+						: $this->_admin_base_url,
583
+					'persistent' => false,
584
+				],
585
+				'help_tabs'     => [
586
+					'registrations_details_help_tab'                    => [
587
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
588
+						'filename' => 'registrations_details',
589
+					],
590
+					'registrations_details_table_help_tab'              => [
591
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
592
+						'filename' => 'registrations_details_table',
593
+					],
594
+					'registrations_details_form_answers_help_tab'       => [
595
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
596
+						'filename' => 'registrations_details_form_answers',
597
+					],
598
+					'registrations_details_registrant_details_help_tab' => [
599
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
600
+						'filename' => 'registrations_details_registrant_details',
601
+					],
602
+				],
603
+				'metaboxes'     => array_merge(
604
+					$this->_default_espresso_metaboxes,
605
+					['_registration_details_metaboxes']
606
+				),
607
+				'require_nonce' => false,
608
+			],
609
+			'new_registration'  => [
610
+				'nav'           => [
611
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
612
+					'url'        => '#',
613
+					'order'      => 15,
614
+					'persistent' => false,
615
+				],
616
+				'metaboxes'     => $this->_default_espresso_metaboxes,
617
+				'labels'        => [
618
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
619
+				],
620
+				'require_nonce' => false,
621
+			],
622
+			'add_new_attendee'  => [
623
+				'nav'           => [
624
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
625
+					'order'      => 15,
626
+					'persistent' => false,
627
+				],
628
+				'metaboxes'     => array_merge(
629
+					$this->_default_espresso_metaboxes,
630
+					['_publish_post_box', 'attendee_editor_metaboxes']
631
+				),
632
+				'require_nonce' => false,
633
+			],
634
+			'edit_attendee'     => [
635
+				'nav'           => [
636
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
637
+					'order'      => 15,
638
+					'persistent' => false,
639
+					'url'        => $ATT_ID
640
+						? add_query_arg(['ATT_ID' => $ATT_ID], $this->_current_page_view_url)
641
+						: $this->_admin_base_url,
642
+				],
643
+				'metaboxes'     => array_merge(
644
+					$this->_default_espresso_metaboxes,
645
+					['attendee_editor_metaboxes']
646
+				),
647
+				'require_nonce' => false,
648
+			],
649
+			'contact_list'      => [
650
+				'nav'           => [
651
+					'label' => esc_html__('Contact List', 'event_espresso'),
652
+					'order' => 20,
653
+				],
654
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
655
+				'help_tabs'     => [
656
+					'registrations_contact_list_help_tab'                       => [
657
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
658
+						'filename' => 'registrations_contact_list',
659
+					],
660
+					'registrations_contact-list_table_column_headings_help_tab' => [
661
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
662
+						'filename' => 'registrations_contact_list_table_column_headings',
663
+					],
664
+					'registrations_contact_list_views_help_tab'                 => [
665
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
666
+						'filename' => 'registrations_contact_list_views',
667
+					],
668
+					'registrations_contact_list_other_help_tab'                 => [
669
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
670
+						'filename' => 'registrations_contact_list_other',
671
+					],
672
+				],
673
+				'metaboxes'     => [],
674
+				'require_nonce' => false,
675
+			],
676
+			// override default cpt routes
677
+			'create_new'        => '',
678
+			'edit'              => '',
679
+		];
680
+	}
681
+
682
+
683
+	/**
684
+	 * The below methods aren't used by this class currently
685
+	 */
686
+	protected function _add_screen_options()
687
+	{
688
+	}
689
+
690
+
691
+	protected function _add_feature_pointers()
692
+	{
693
+	}
694
+
695
+
696
+	public function admin_init()
697
+	{
698
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
699
+			'click "Update Registration Questions" to save your changes',
700
+			'event_espresso'
701
+		);
702
+	}
703
+
704
+
705
+	public function admin_notices()
706
+	{
707
+	}
708
+
709
+
710
+	public function admin_footer_scripts()
711
+	{
712
+	}
713
+
714
+
715
+	/**
716
+	 * get list of registration statuses
717
+	 *
718
+	 * @return void
719
+	 * @throws EE_Error
720
+	 */
721
+	private function _get_registration_status_array()
722
+	{
723
+		self::$_reg_status = EEM_Registration::reg_status_array([], true);
724
+	}
725
+
726
+
727
+	/**
728
+	 * @throws InvalidArgumentException
729
+	 * @throws InvalidDataTypeException
730
+	 * @throws InvalidInterfaceException
731
+	 * @since 4.10.2.p
732
+	 */
733
+	protected function _add_screen_options_default()
734
+	{
735
+		$this->_per_page_screen_option();
736
+	}
737
+
738
+
739
+	/**
740
+	 * @throws InvalidArgumentException
741
+	 * @throws InvalidDataTypeException
742
+	 * @throws InvalidInterfaceException
743
+	 * @since 4.10.2.p
744
+	 */
745
+	protected function _add_screen_options_contact_list()
746
+	{
747
+		$page_title              = $this->_admin_page_title;
748
+		$this->_admin_page_title = esc_html__('Contacts', 'event_espresso');
749
+		$this->_per_page_screen_option();
750
+		$this->_admin_page_title = $page_title;
751
+	}
752
+
753
+
754
+	public function load_scripts_styles()
755
+	{
756
+		// style
757
+		wp_register_style(
758
+			'espresso_reg',
759
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
760
+			['ee-admin-css'],
761
+			EVENT_ESPRESSO_VERSION
762
+		);
763
+		wp_enqueue_style('espresso_reg');
764
+		// script
765
+		wp_register_script(
766
+			'espresso_reg',
767
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
768
+			['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
769
+			EVENT_ESPRESSO_VERSION,
770
+			true
771
+		);
772
+		wp_enqueue_script('espresso_reg');
773
+	}
774
+
775
+
776
+	/**
777
+	 * @throws EE_Error
778
+	 * @throws InvalidArgumentException
779
+	 * @throws InvalidDataTypeException
780
+	 * @throws InvalidInterfaceException
781
+	 * @throws ReflectionException
782
+	 * @since 4.10.2.p
783
+	 */
784
+	public function load_scripts_styles_edit_attendee()
785
+	{
786
+		// stuff to only show up on our attendee edit details page.
787
+		$attendee_details_translations = [
788
+			'att_publish_text' => sprintf(
789
+			/* translators: The date and time */
790
+				wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
791
+				'<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
792
+			),
793
+		];
794
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
795
+		wp_enqueue_script('jquery-validate');
796
+	}
797
+
798
+
799
+	/**
800
+	 * @throws EE_Error
801
+	 * @throws InvalidArgumentException
802
+	 * @throws InvalidDataTypeException
803
+	 * @throws InvalidInterfaceException
804
+	 * @throws ReflectionException
805
+	 * @since 4.10.2.p
806
+	 */
807
+	public function load_scripts_styles_view_registration()
808
+	{
809
+		// styles
810
+		wp_enqueue_style('espresso-ui-theme');
811
+		// scripts
812
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
813
+		$this->_reg_custom_questions_form->wp_enqueue_scripts();
814
+	}
815
+
816
+
817
+	public function load_scripts_styles_contact_list()
818
+	{
819
+		wp_dequeue_style('espresso_reg');
820
+		wp_register_style(
821
+			'espresso_att',
822
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
823
+			['ee-admin-css'],
824
+			EVENT_ESPRESSO_VERSION
825
+		);
826
+		wp_enqueue_style('espresso_att');
827
+	}
828
+
829
+
830
+	public function load_scripts_styles_new_registration()
831
+	{
832
+		wp_register_script(
833
+			'ee-spco-for-admin',
834
+			REG_ASSETS_URL . 'spco_for_admin.js',
835
+			['underscore', 'jquery'],
836
+			EVENT_ESPRESSO_VERSION,
837
+			true
838
+		);
839
+		wp_enqueue_script('ee-spco-for-admin');
840
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
841
+		EE_Form_Section_Proper::wp_enqueue_scripts();
842
+		EED_Ticket_Selector::load_tckt_slctr_assets();
843
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
844
+	}
845
+
846
+
847
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
848
+	{
849
+		add_filter('FHEE_load_EE_messages', '__return_true');
850
+	}
851
+
852
+
853
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
854
+	{
855
+		add_filter('FHEE_load_EE_messages', '__return_true');
856
+	}
857
+
858
+
859
+	/**
860
+	 * @throws EE_Error
861
+	 * @throws InvalidArgumentException
862
+	 * @throws InvalidDataTypeException
863
+	 * @throws InvalidInterfaceException
864
+	 * @throws ReflectionException
865
+	 * @since 4.10.2.p
866
+	 */
867
+	protected function _set_list_table_views_default()
868
+	{
869
+		// for notification related bulk actions we need to make sure only active messengers have an option.
870
+		EED_Messages::set_autoloaders();
871
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
872
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
873
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
874
+		// key= bulk_action_slug, value= message type.
875
+		$match_array = [
876
+			'approve_registrations'    => 'registration',
877
+			'decline_registrations'    => 'declined_registration',
878
+			'pending_registrations'    => 'pending_approval',
879
+			'no_approve_registrations' => 'not_approved_registration',
880
+			'cancel_registrations'     => 'cancelled_registration',
881
+		];
882
+		$can_send    = EE_Registry::instance()->CAP->current_user_can(
883
+			'ee_send_message',
884
+			'batch_send_messages'
885
+		);
886
+		/** setup reg status bulk actions **/
887
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
888
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
889
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
890
+				'Approve and Notify Registrations',
891
+				'event_espresso'
892
+			);
893
+		}
894
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
895
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
896
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
897
+				'Decline and Notify Registrations',
898
+				'event_espresso'
899
+			);
900
+		}
901
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
902
+			'Set Registrations to Pending Payment',
903
+			'event_espresso'
904
+		);
905
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
906
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
907
+				'Set Registrations to Pending Payment and Notify',
908
+				'event_espresso'
909
+			);
910
+		}
911
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
912
+			'Set Registrations to Not Approved',
913
+			'event_espresso'
914
+		);
915
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
916
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
917
+				'Set Registrations to Not Approved and Notify',
918
+				'event_espresso'
919
+			);
920
+		}
921
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
922
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
923
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
924
+				'Cancel Registrations and Notify',
925
+				'event_espresso'
926
+			);
927
+		}
928
+		$def_reg_status_actions = apply_filters(
929
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
930
+			$def_reg_status_actions,
931
+			$active_mts,
932
+			$can_send
933
+		);
934
+
935
+		$this->_views = [
936
+			'all'   => [
937
+				'slug'        => 'all',
938
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
939
+				'count'       => 0,
940
+				'bulk_action' => array_merge(
941
+					$def_reg_status_actions,
942
+					[
943
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
944
+					]
945
+				),
946
+			],
947
+			'month' => [
948
+				'slug'        => 'month',
949
+				'label'       => esc_html__('This Month', 'event_espresso'),
950
+				'count'       => 0,
951
+				'bulk_action' => array_merge(
952
+					$def_reg_status_actions,
953
+					[
954
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
955
+					]
956
+				),
957
+			],
958
+			'today' => [
959
+				'slug'        => 'today',
960
+				'label'       => sprintf(
961
+					esc_html__('Today - %s', 'event_espresso'),
962
+					date('M d, Y', current_time('timestamp'))
963
+				),
964
+				'count'       => 0,
965
+				'bulk_action' => array_merge(
966
+					$def_reg_status_actions,
967
+					[
968
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
969
+					]
970
+				),
971
+			],
972
+		];
973
+		if (
974
+			EE_Registry::instance()->CAP->current_user_can(
975
+				'ee_delete_registrations',
976
+				'espresso_registrations_delete_registration'
977
+			)
978
+		) {
979
+			$this->_views['incomplete'] = [
980
+				'slug'        => 'incomplete',
981
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
982
+				'count'       => 0,
983
+				'bulk_action' => [
984
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
985
+				],
986
+			];
987
+			$this->_views['trash']      = [
988
+				'slug'        => 'trash',
989
+				'label'       => esc_html__('Trash', 'event_espresso'),
990
+				'count'       => 0,
991
+				'bulk_action' => [
992
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
993
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
994
+				],
995
+			];
996
+		}
997
+	}
998
+
999
+
1000
+	protected function _set_list_table_views_contact_list()
1001
+	{
1002
+		$this->_views = [
1003
+			'in_use' => [
1004
+				'slug'        => 'in_use',
1005
+				'label'       => esc_html__('In Use', 'event_espresso'),
1006
+				'count'       => 0,
1007
+				'bulk_action' => [
1008
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
1009
+				],
1010
+			],
1011
+		];
1012
+		if (
1013
+			EE_Registry::instance()->CAP->current_user_can(
1014
+				'ee_delete_contacts',
1015
+				'espresso_registrations_trash_attendees'
1016
+			)
1017
+		) {
1018
+			$this->_views['trash'] = [
1019
+				'slug'        => 'trash',
1020
+				'label'       => esc_html__('Trash', 'event_espresso'),
1021
+				'count'       => 0,
1022
+				'bulk_action' => [
1023
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
1024
+				],
1025
+			];
1026
+		}
1027
+	}
1028
+
1029
+
1030
+	/**
1031
+	 * @return array
1032
+	 * @throws EE_Error
1033
+	 */
1034
+	protected function _registration_legend_items()
1035
+	{
1036
+		$fc_items = [
1037
+			'star-icon'        => [
1038
+				'class' => 'dashicons dashicons-star-filled gold-icon',
1039
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
1040
+			],
1041
+			'view_details'     => [
1042
+				'class' => 'dashicons dashicons-clipboard',
1043
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
1044
+			],
1045
+			'edit_attendee'    => [
1046
+				'class' => 'dashicons dashicons-admin-users',
1047
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
1048
+			],
1049
+			'view_transaction' => [
1050
+				'class' => 'dashicons dashicons-cart',
1051
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
1052
+			],
1053
+			'view_invoice'     => [
1054
+				'class' => 'dashicons dashicons-media-spreadsheet',
1055
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
1056
+			],
1057
+		];
1058
+		if (
1059
+			EE_Registry::instance()->CAP->current_user_can(
1060
+				'ee_send_message',
1061
+				'espresso_registrations_resend_registration'
1062
+			)
1063
+		) {
1064
+			$fc_items['resend_registration'] = [
1065
+				'class' => 'dashicons dashicons-email-alt',
1066
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
1067
+			];
1068
+		} else {
1069
+			$fc_items['blank'] = ['class' => 'blank', 'desc' => ''];
1070
+		}
1071
+		if (
1072
+			EE_Registry::instance()->CAP->current_user_can(
1073
+				'ee_read_global_messages',
1074
+				'view_filtered_messages'
1075
+			)
1076
+		) {
1077
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
1078
+			if (is_array($related_for_icon) && isset($related_for_icon['css_class'], $related_for_icon['label'])) {
1079
+				$fc_items['view_related_messages'] = [
1080
+					'class' => $related_for_icon['css_class'],
1081
+					'desc'  => $related_for_icon['label'],
1082
+				];
1083
+			}
1084
+		}
1085
+		$sc_items = [
1086
+			'approved_status'   => [
1087
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1088
+				'desc'  => EEH_Template::pretty_status(
1089
+					EEM_Registration::status_id_approved,
1090
+					false,
1091
+					'sentence'
1092
+				),
1093
+			],
1094
+			'pending_status'    => [
1095
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1096
+				'desc'  => EEH_Template::pretty_status(
1097
+					EEM_Registration::status_id_pending_payment,
1098
+					false,
1099
+					'sentence'
1100
+				),
1101
+			],
1102
+			'wait_list'         => [
1103
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1104
+				'desc'  => EEH_Template::pretty_status(
1105
+					EEM_Registration::status_id_wait_list,
1106
+					false,
1107
+					'sentence'
1108
+				),
1109
+			],
1110
+			'incomplete_status' => [
1111
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1112
+				'desc'  => EEH_Template::pretty_status(
1113
+					EEM_Registration::status_id_incomplete,
1114
+					false,
1115
+					'sentence'
1116
+				),
1117
+			],
1118
+			'not_approved'      => [
1119
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1120
+				'desc'  => EEH_Template::pretty_status(
1121
+					EEM_Registration::status_id_not_approved,
1122
+					false,
1123
+					'sentence'
1124
+				),
1125
+			],
1126
+			'declined_status'   => [
1127
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1128
+				'desc'  => EEH_Template::pretty_status(
1129
+					EEM_Registration::status_id_declined,
1130
+					false,
1131
+					'sentence'
1132
+				),
1133
+			],
1134
+			'cancelled_status'  => [
1135
+				'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1136
+				'desc'  => EEH_Template::pretty_status(
1137
+					EEM_Registration::status_id_cancelled,
1138
+					false,
1139
+					'sentence'
1140
+				),
1141
+			],
1142
+		];
1143
+		return array_merge($fc_items, $sc_items);
1144
+	}
1145
+
1146
+
1147
+
1148
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1149
+
1150
+
1151
+	/**
1152
+	 * @throws DomainException
1153
+	 * @throws EE_Error
1154
+	 * @throws InvalidArgumentException
1155
+	 * @throws InvalidDataTypeException
1156
+	 * @throws InvalidInterfaceException
1157
+	 */
1158
+	protected function _registrations_overview_list_table()
1159
+	{
1160
+		$this->appendAddNewRegistrationButtonToPageTitle();
1161
+		$header_text                  = '';
1162
+		$admin_page_header_decorators = [
1163
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader',
1164
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader',
1165
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader',
1166
+			'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader',
1167
+		];
1168
+		foreach ($admin_page_header_decorators as $admin_page_header_decorator) {
1169
+			$filter_header_decorator = $this->loader->getNew($admin_page_header_decorator);
1170
+			$header_text = $filter_header_decorator->getHeaderText($header_text);
1171
+		}
1172
+		$this->_template_args['admin_page_header'] = $header_text;
1173
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_registration_legend_items());
1174
+		$this->display_admin_list_table_page_with_no_sidebar();
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * @throws EE_Error
1180
+	 * @throws InvalidArgumentException
1181
+	 * @throws InvalidDataTypeException
1182
+	 * @throws InvalidInterfaceException
1183
+	 */
1184
+	private function appendAddNewRegistrationButtonToPageTitle()
1185
+	{
1186
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
1187
+		if (
1188
+			$EVT_ID
1189
+			&& EE_Registry::instance()->CAP->current_user_can(
1190
+				'ee_edit_registrations',
1191
+				'espresso_registrations_new_registration',
1192
+				$EVT_ID
1193
+			)
1194
+		) {
1195
+			$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1196
+				'new_registration',
1197
+				'add-registrant',
1198
+				['event_id' => $EVT_ID],
1199
+				'add-new-h2'
1200
+			);
1201
+		}
1202
+	}
1203
+
1204
+
1205
+	/**
1206
+	 * This sets the _registration property for the registration details screen
1207
+	 *
1208
+	 * @return void
1209
+	 * @throws EE_Error
1210
+	 * @throws InvalidArgumentException
1211
+	 * @throws InvalidDataTypeException
1212
+	 * @throws InvalidInterfaceException
1213
+	 */
1214
+	private function _set_registration_object()
1215
+	{
1216
+		// get out if we've already set the object
1217
+		if ($this->_registration instanceof EE_Registration) {
1218
+			return;
1219
+		}
1220
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
1221
+		if ($this->_registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID)) {
1222
+			return;
1223
+		}
1224
+		$error_msg = sprintf(
1225
+			esc_html__(
1226
+				'An error occurred and the details for Registration ID #%s could not be retrieved.',
1227
+				'event_espresso'
1228
+			),
1229
+			$REG_ID
1230
+		);
1231
+		EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1232
+		$this->_registration = null;
1233
+	}
1234
+
1235
+
1236
+	/**
1237
+	 * Used to retrieve registrations for the list table.
1238
+	 *
1239
+	 * @param int  $per_page
1240
+	 * @param bool $count
1241
+	 * @param bool $this_month
1242
+	 * @param bool $today
1243
+	 * @return EE_Registration[]|int
1244
+	 * @throws EE_Error
1245
+	 * @throws InvalidArgumentException
1246
+	 * @throws InvalidDataTypeException
1247
+	 * @throws InvalidInterfaceException
1248
+	 */
1249
+	public function get_registrations(
1250
+		$per_page = 10,
1251
+		$count = false,
1252
+		$this_month = false,
1253
+		$today = false
1254
+	) {
1255
+		if ($this_month) {
1256
+			$this->request->setRequestParam('status', 'month');
1257
+		}
1258
+		if ($today) {
1259
+			$this->request->setRequestParam('status', 'today');
1260
+		}
1261
+		$query_params = $this->_get_registration_query_parameters($this->request->requestParams(), $per_page, $count);
1262
+		/**
1263
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1264
+		 *
1265
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1266
+		 * @see  https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1267
+		 *                      or if you have the development copy of EE you can view this at the path:
1268
+		 *                      /docs/G--Model-System/model-query-params.md
1269
+		 */
1270
+		$query_params['group_by'] = '';
1271
+
1272
+		return $count
1273
+			? $this->getRegistrationModel()->count($query_params)
1274
+			/** @type EE_Registration[] */
1275
+			: $this->getRegistrationModel()->get_all($query_params);
1276
+	}
1277
+
1278
+
1279
+	/**
1280
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1281
+	 * Note: this listens to values on the request for some of the query parameters.
1282
+	 *
1283
+	 * @param array $request
1284
+	 * @param int   $per_page
1285
+	 * @param bool  $count
1286
+	 * @return array
1287
+	 * @throws EE_Error
1288
+	 * @throws InvalidArgumentException
1289
+	 * @throws InvalidDataTypeException
1290
+	 * @throws InvalidInterfaceException
1291
+	 */
1292
+	protected function _get_registration_query_parameters(
1293
+		$request = [],
1294
+		$per_page = 10,
1295
+		$count = false
1296
+	) {
1297
+		/** @var EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder $list_table_query_builder */
1298
+		$list_table_query_builder = $this->loader->getNew(
1299
+			'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder',
1300
+			[null, null, $request]
1301
+		);
1302
+		return $list_table_query_builder->getQueryParams($per_page, $count);
1303
+	}
1304
+
1305
+
1306
+	public function get_registration_status_array()
1307
+	{
1308
+		return self::$_reg_status;
1309
+	}
1310
+
1311
+
1312
+
1313
+
1314
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1315
+	/**
1316
+	 * generates HTML for the View Registration Details Admin page
1317
+	 *
1318
+	 * @return void
1319
+	 * @throws DomainException
1320
+	 * @throws EE_Error
1321
+	 * @throws InvalidArgumentException
1322
+	 * @throws InvalidDataTypeException
1323
+	 * @throws InvalidInterfaceException
1324
+	 * @throws EntityNotFoundException
1325
+	 * @throws ReflectionException
1326
+	 */
1327
+	protected function _registration_details()
1328
+	{
1329
+		$this->_template_args = [];
1330
+		$this->_set_registration_object();
1331
+		if (is_object($this->_registration)) {
1332
+			$transaction                                   = $this->_registration->transaction()
1333
+				? $this->_registration->transaction()
1334
+				: EE_Transaction::new_instance();
1335
+			$this->_session                                = $transaction->session_data();
1336
+			$event_id                                      = $this->_registration->event_ID();
1337
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1338
+			$this->_template_args['reg_nmbr']['label']     = esc_html__('Registration Number', 'event_espresso');
1339
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1340
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1341
+			$this->_template_args['grand_total']           = $transaction->total();
1342
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1343
+			// link back to overview
1344
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1345
+			$this->_template_args['registration']                = $this->_registration;
1346
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1347
+				[
1348
+					'action'   => 'default',
1349
+					'event_id' => $event_id,
1350
+				],
1351
+				REG_ADMIN_URL
1352
+			);
1353
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1354
+				[
1355
+					'action' => 'default',
1356
+					'EVT_ID' => $event_id,
1357
+					'page'   => 'espresso_transactions',
1358
+				],
1359
+				admin_url('admin.php')
1360
+			);
1361
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1362
+				[
1363
+					'page'   => 'espresso_events',
1364
+					'action' => 'edit',
1365
+					'post'   => $event_id,
1366
+				],
1367
+				admin_url('admin.php')
1368
+			);
1369
+			// next and previous links
1370
+			$next_reg                                      = $this->_registration->next(
1371
+				null,
1372
+				[],
1373
+				'REG_ID'
1374
+			);
1375
+			$this->_template_args['next_registration']     = $next_reg
1376
+				? $this->_next_link(
1377
+					EE_Admin_Page::add_query_args_and_nonce(
1378
+						[
1379
+							'action'  => 'view_registration',
1380
+							'_REG_ID' => $next_reg['REG_ID'],
1381
+						],
1382
+						REG_ADMIN_URL
1383
+					),
1384
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1385
+				)
1386
+				: '';
1387
+			$previous_reg                                  = $this->_registration->previous(
1388
+				null,
1389
+				[],
1390
+				'REG_ID'
1391
+			);
1392
+			$this->_template_args['previous_registration'] = $previous_reg
1393
+				? $this->_previous_link(
1394
+					EE_Admin_Page::add_query_args_and_nonce(
1395
+						[
1396
+							'action'  => 'view_registration',
1397
+							'_REG_ID' => $previous_reg['REG_ID'],
1398
+						],
1399
+						REG_ADMIN_URL
1400
+					),
1401
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1402
+				)
1403
+				: '';
1404
+			// grab header
1405
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1406
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1407
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1408
+				$template_path,
1409
+				$this->_template_args,
1410
+				true
1411
+			);
1412
+		} else {
1413
+			$this->_template_args['admin_page_header'] = '';
1414
+			$this->_display_espresso_notices();
1415
+		}
1416
+		// the details template wrapper
1417
+		$this->display_admin_page_with_sidebar();
1418
+	}
1419
+
1420
+
1421
+	/**
1422
+	 * @throws EE_Error
1423
+	 * @throws InvalidArgumentException
1424
+	 * @throws InvalidDataTypeException
1425
+	 * @throws InvalidInterfaceException
1426
+	 * @throws ReflectionException
1427
+	 * @since 4.10.2.p
1428
+	 */
1429
+	protected function _registration_details_metaboxes()
1430
+	{
1431
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1432
+		$this->_set_registration_object();
1433
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1434
+		$this->addMetaBox(
1435
+			'edit-reg-status-mbox',
1436
+			esc_html__('Registration Status', 'event_espresso'),
1437
+			[$this, 'set_reg_status_buttons_metabox'],
1438
+			$this->_wp_page_slug
1439
+		);
1440
+		$this->addMetaBox(
1441
+			'edit-reg-details-mbox',
1442
+			'<span>' . esc_html__('Registration Details', 'event_espresso')
1443
+			. '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1444
+			[$this, '_reg_details_meta_box'],
1445
+			$this->_wp_page_slug
1446
+		);
1447
+		if (
1448
+			$attendee instanceof EE_Attendee
1449
+			&& EE_Registry::instance()->CAP->current_user_can(
1450
+				'ee_read_registration',
1451
+				'edit-reg-questions-mbox',
1452
+				$this->_registration->ID()
1453
+			)
1454
+		) {
1455
+			$this->addMetaBox(
1456
+				'edit-reg-questions-mbox',
1457
+				esc_html__('Registration Form Answers', 'event_espresso'),
1458
+				[$this, '_reg_questions_meta_box'],
1459
+				$this->_wp_page_slug
1460
+			);
1461
+		}
1462
+		$this->addMetaBox(
1463
+			'edit-reg-registrant-mbox',
1464
+			esc_html__('Contact Details', 'event_espresso'),
1465
+			[$this, '_reg_registrant_side_meta_box'],
1466
+			$this->_wp_page_slug,
1467
+			'side'
1468
+		);
1469
+		if ($this->_registration->group_size() > 1) {
1470
+			$this->addMetaBox(
1471
+				'edit-reg-attendees-mbox',
1472
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1473
+				[$this, '_reg_attendees_meta_box'],
1474
+				$this->_wp_page_slug
1475
+			);
1476
+		}
1477
+	}
1478
+
1479
+
1480
+	/**
1481
+	 * set_reg_status_buttons_metabox
1482
+	 *
1483
+	 * @return void
1484
+	 * @throws EE_Error
1485
+	 * @throws EntityNotFoundException
1486
+	 * @throws InvalidArgumentException
1487
+	 * @throws InvalidDataTypeException
1488
+	 * @throws InvalidInterfaceException
1489
+	 * @throws ReflectionException
1490
+	 */
1491
+	public function set_reg_status_buttons_metabox()
1492
+	{
1493
+		$this->_set_registration_object();
1494
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1495
+		$output                 = $change_reg_status_form->form_open(
1496
+			self::add_query_args_and_nonce(
1497
+				[
1498
+					'action' => 'change_reg_status',
1499
+				],
1500
+				REG_ADMIN_URL
1501
+			)
1502
+		);
1503
+		$output                 .= $change_reg_status_form->get_html();
1504
+		$output                 .= $change_reg_status_form->form_close();
1505
+		echo wp_kses($output, AllowedTags::getWithFormTags());
1506
+	}
1507
+
1508
+
1509
+	/**
1510
+	 * @return EE_Form_Section_Proper
1511
+	 * @throws EE_Error
1512
+	 * @throws InvalidArgumentException
1513
+	 * @throws InvalidDataTypeException
1514
+	 * @throws InvalidInterfaceException
1515
+	 * @throws EntityNotFoundException
1516
+	 * @throws ReflectionException
1517
+	 */
1518
+	protected function _generate_reg_status_change_form()
1519
+	{
1520
+		$reg_status_change_form_array = [
1521
+			'name'            => 'reg_status_change_form',
1522
+			'html_id'         => 'reg-status-change-form',
1523
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1524
+			'subsections'     => [
1525
+				'return'         => new EE_Hidden_Input(
1526
+					[
1527
+						'name'    => 'return',
1528
+						'default' => 'view_registration',
1529
+					]
1530
+				),
1531
+				'REG_ID'         => new EE_Hidden_Input(
1532
+					[
1533
+						'name'    => 'REG_ID',
1534
+						'default' => $this->_registration->ID(),
1535
+					]
1536
+				),
1537
+			],
1538
+		];
1539
+		if (
1540
+			EE_Registry::instance()->CAP->current_user_can(
1541
+				'ee_edit_registration',
1542
+				'toggle_registration_status',
1543
+				$this->_registration->ID()
1544
+			)
1545
+		) {
1546
+			$reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1547
+				$this->_get_reg_statuses(),
1548
+				[
1549
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1550
+					'default'         => $this->_registration->status_ID(),
1551
+				]
1552
+			);
1553
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1554
+				[
1555
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1556
+					'default'         => false,
1557
+					'html_help_text'  => esc_html__(
1558
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1559
+						'event_espresso'
1560
+					),
1561
+				]
1562
+			);
1563
+			$reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1564
+				[
1565
+					'html_class'      => 'button--primary',
1566
+					'html_label_text' => '&nbsp;',
1567
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1568
+				]
1569
+			);
1570
+		}
1571
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1572
+	}
1573
+
1574
+
1575
+	/**
1576
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1577
+	 *
1578
+	 * @return array
1579
+	 * @throws EE_Error
1580
+	 * @throws InvalidArgumentException
1581
+	 * @throws InvalidDataTypeException
1582
+	 * @throws InvalidInterfaceException
1583
+	 * @throws EntityNotFoundException
1584
+	 */
1585
+	protected function _get_reg_statuses()
1586
+	{
1587
+		$reg_status_array = $this->getRegistrationModel()->reg_status_array();
1588
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1589
+		// get current reg status
1590
+		$current_status = $this->_registration->status_ID();
1591
+		// is registration for free event? This will determine whether to display the pending payment option
1592
+		if (
1593
+			$current_status !== EEM_Registration::status_id_pending_payment
1594
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1595
+		) {
1596
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1597
+		}
1598
+		return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1599
+	}
1600
+
1601
+
1602
+	/**
1603
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1604
+	 *
1605
+	 * @param bool $status REG status given for changing registrations to.
1606
+	 * @param bool $notify Whether to send messages notifications or not.
1607
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1608
+	 * @throws DomainException
1609
+	 * @throws EE_Error
1610
+	 * @throws EntityNotFoundException
1611
+	 * @throws InvalidArgumentException
1612
+	 * @throws InvalidDataTypeException
1613
+	 * @throws InvalidInterfaceException
1614
+	 * @throws ReflectionException
1615
+	 * @throws RuntimeException
1616
+	 */
1617
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1618
+	{
1619
+		$REG_IDs = $this->request->requestParamIsSet('reg_status_change_form')
1620
+			? $this->request->getRequestParam('reg_status_change_form[REG_ID]', [], 'int', true)
1621
+			: $this->request->getRequestParam('_REG_ID', [], 'int', true);
1622
+
1623
+		// sanitize $REG_IDs
1624
+		$REG_IDs = array_map('absint', $REG_IDs);
1625
+		// and remove empty entries
1626
+		$REG_IDs = array_filter($REG_IDs);
1627
+
1628
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1629
+
1630
+		/**
1631
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1632
+		 * Currently this value is used downstream by the _process_resend_registration method.
1633
+		 *
1634
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1635
+		 * @param bool                     $status           The status registrations were changed to.
1636
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1637
+		 * @param Registrations_Admin_Page $admin_page_object
1638
+		 */
1639
+		$REG_ID = apply_filters(
1640
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1641
+			$result['REG_ID'],
1642
+			$status,
1643
+			$result['success'],
1644
+			$this
1645
+		);
1646
+		$this->request->setRequestParam('_REG_ID', $REG_ID);
1647
+
1648
+		// notify?
1649
+		if (
1650
+			$notify
1651
+			&& $result['success']
1652
+			&& ! empty($REG_ID)
1653
+			&& EE_Registry::instance()->CAP->current_user_can(
1654
+				'ee_send_message',
1655
+				'espresso_registrations_resend_registration'
1656
+			)
1657
+		) {
1658
+			$this->_process_resend_registration();
1659
+		}
1660
+		return $result;
1661
+	}
1662
+
1663
+
1664
+	/**
1665
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1666
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1667
+	 *
1668
+	 * @param array  $REG_IDs
1669
+	 * @param string $status
1670
+	 * @param bool   $notify Used to indicate whether notification was requested or not.  This determines the context
1671
+	 *                       slug sent with setting the registration status.
1672
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1673
+	 * @throws EE_Error
1674
+	 * @throws InvalidArgumentException
1675
+	 * @throws InvalidDataTypeException
1676
+	 * @throws InvalidInterfaceException
1677
+	 * @throws ReflectionException
1678
+	 * @throws RuntimeException
1679
+	 * @throws EntityNotFoundException
1680
+	 * @throws DomainException
1681
+	 */
1682
+	protected function _set_registration_status($REG_IDs = [], $status = '', $notify = false)
1683
+	{
1684
+		$success = false;
1685
+		// typecast $REG_IDs
1686
+		$REG_IDs = (array) $REG_IDs;
1687
+		if (! empty($REG_IDs)) {
1688
+			$success = true;
1689
+			// set default status if none is passed
1690
+			$status         = $status ?: EEM_Registration::status_id_pending_payment;
1691
+			$status_context = $notify
1692
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1693
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1694
+			// loop through REG_ID's and change status
1695
+			foreach ($REG_IDs as $REG_ID) {
1696
+				$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
1697
+				if ($registration instanceof EE_Registration) {
1698
+					$registration->set_status(
1699
+						$status,
1700
+						false,
1701
+						new Context(
1702
+							$status_context,
1703
+							esc_html__(
1704
+								'Manually triggered status change on a Registration Admin Page route.',
1705
+								'event_espresso'
1706
+							)
1707
+						)
1708
+					);
1709
+					$result = $registration->save();
1710
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1711
+					$success = $result !== false ? $success : false;
1712
+				}
1713
+			}
1714
+		}
1715
+
1716
+		// return $success and processed registrations
1717
+		return ['REG_ID' => $REG_IDs, 'success' => $success];
1718
+	}
1719
+
1720
+
1721
+	/**
1722
+	 * Common logic for setting up success message and redirecting to appropriate route
1723
+	 *
1724
+	 * @param string $STS_ID status id for the registration changed to
1725
+	 * @param bool   $notify indicates whether the _set_registration_status_from_request does notifications or not.
1726
+	 * @return void
1727
+	 * @throws DomainException
1728
+	 * @throws EE_Error
1729
+	 * @throws EntityNotFoundException
1730
+	 * @throws InvalidArgumentException
1731
+	 * @throws InvalidDataTypeException
1732
+	 * @throws InvalidInterfaceException
1733
+	 * @throws ReflectionException
1734
+	 * @throws RuntimeException
1735
+	 */
1736
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1737
+	{
1738
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1739
+			: ['success' => false];
1740
+		$success = isset($result['success']) && $result['success'];
1741
+		// setup success message
1742
+		if ($success) {
1743
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1744
+				$msg = sprintf(
1745
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1746
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1747
+				);
1748
+			} else {
1749
+				$msg = sprintf(
1750
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1751
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1752
+				);
1753
+			}
1754
+			EE_Error::add_success($msg);
1755
+		} else {
1756
+			EE_Error::add_error(
1757
+				esc_html__(
1758
+					'Something went wrong, and the status was not changed',
1759
+					'event_espresso'
1760
+				),
1761
+				__FILE__,
1762
+				__LINE__,
1763
+				__FUNCTION__
1764
+			);
1765
+		}
1766
+		$return = $this->request->getRequestParam('return');
1767
+		$route  = $return === 'view_registration'
1768
+			? ['action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])]
1769
+			: ['action' => 'default'];
1770
+		$route  = $this->mergeExistingRequestParamsWithRedirectArgs($route);
1771
+		$this->_redirect_after_action($success, '', '', $route, true);
1772
+	}
1773
+
1774
+
1775
+	/**
1776
+	 * incoming reg status change from reg details page.
1777
+	 *
1778
+	 * @return void
1779
+	 * @throws EE_Error
1780
+	 * @throws EntityNotFoundException
1781
+	 * @throws InvalidArgumentException
1782
+	 * @throws InvalidDataTypeException
1783
+	 * @throws InvalidInterfaceException
1784
+	 * @throws ReflectionException
1785
+	 * @throws RuntimeException
1786
+	 * @throws DomainException
1787
+	 */
1788
+	protected function _change_reg_status()
1789
+	{
1790
+		$this->request->setRequestParam('return', 'view_registration');
1791
+		// set notify based on whether the send notifications toggle is set or not
1792
+		$notify     = $this->request->getRequestParam('reg_status_change_form[send_notifications]', false, 'bool');
1793
+		$reg_status = $this->request->getRequestParam('reg_status_change_form[reg_status]', '');
1794
+		$this->request->setRequestParam('reg_status_change_form[reg_status]', $reg_status);
1795
+		switch ($reg_status) {
1796
+			case EEM_Registration::status_id_approved:
1797
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
1798
+				$this->approve_registration($notify);
1799
+				break;
1800
+			case EEM_Registration::status_id_pending_payment:
1801
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
1802
+				$this->pending_registration($notify);
1803
+				break;
1804
+			case EEM_Registration::status_id_not_approved:
1805
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
1806
+				$this->not_approve_registration($notify);
1807
+				break;
1808
+			case EEM_Registration::status_id_declined:
1809
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
1810
+				$this->decline_registration($notify);
1811
+				break;
1812
+			case EEM_Registration::status_id_cancelled:
1813
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
1814
+				$this->cancel_registration($notify);
1815
+				break;
1816
+			case EEM_Registration::status_id_wait_list:
1817
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
1818
+				$this->wait_list_registration($notify);
1819
+				break;
1820
+			case EEM_Registration::status_id_incomplete:
1821
+			default:
1822
+				$this->request->unSetRequestParam('return');
1823
+				$this->_reg_status_change_return('');
1824
+				break;
1825
+		}
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * Callback for bulk action routes.
1831
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
1832
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
1833
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
1834
+	 * when an action is happening on just a single registration).
1835
+	 *
1836
+	 * @param      $action
1837
+	 * @param bool $notify
1838
+	 */
1839
+	protected function bulk_action_on_registrations($action, $notify = false)
1840
+	{
1841
+		do_action(
1842
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
1843
+			$this,
1844
+			$action,
1845
+			$notify
1846
+		);
1847
+		$method = $action . '_registration';
1848
+		if (method_exists($this, $method)) {
1849
+			$this->$method($notify);
1850
+		}
1851
+	}
1852
+
1853
+
1854
+	/**
1855
+	 * approve_registration
1856
+	 *
1857
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1858
+	 * @return void
1859
+	 * @throws EE_Error
1860
+	 * @throws EntityNotFoundException
1861
+	 * @throws InvalidArgumentException
1862
+	 * @throws InvalidDataTypeException
1863
+	 * @throws InvalidInterfaceException
1864
+	 * @throws ReflectionException
1865
+	 * @throws RuntimeException
1866
+	 * @throws DomainException
1867
+	 */
1868
+	protected function approve_registration($notify = false)
1869
+	{
1870
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1871
+	}
1872
+
1873
+
1874
+	/**
1875
+	 * decline_registration
1876
+	 *
1877
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1878
+	 * @return void
1879
+	 * @throws EE_Error
1880
+	 * @throws EntityNotFoundException
1881
+	 * @throws InvalidArgumentException
1882
+	 * @throws InvalidDataTypeException
1883
+	 * @throws InvalidInterfaceException
1884
+	 * @throws ReflectionException
1885
+	 * @throws RuntimeException
1886
+	 * @throws DomainException
1887
+	 */
1888
+	protected function decline_registration($notify = false)
1889
+	{
1890
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1891
+	}
1892
+
1893
+
1894
+	/**
1895
+	 * cancel_registration
1896
+	 *
1897
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1898
+	 * @return void
1899
+	 * @throws EE_Error
1900
+	 * @throws EntityNotFoundException
1901
+	 * @throws InvalidArgumentException
1902
+	 * @throws InvalidDataTypeException
1903
+	 * @throws InvalidInterfaceException
1904
+	 * @throws ReflectionException
1905
+	 * @throws RuntimeException
1906
+	 * @throws DomainException
1907
+	 */
1908
+	protected function cancel_registration($notify = false)
1909
+	{
1910
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1911
+	}
1912
+
1913
+
1914
+	/**
1915
+	 * not_approve_registration
1916
+	 *
1917
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1918
+	 * @return void
1919
+	 * @throws EE_Error
1920
+	 * @throws EntityNotFoundException
1921
+	 * @throws InvalidArgumentException
1922
+	 * @throws InvalidDataTypeException
1923
+	 * @throws InvalidInterfaceException
1924
+	 * @throws ReflectionException
1925
+	 * @throws RuntimeException
1926
+	 * @throws DomainException
1927
+	 */
1928
+	protected function not_approve_registration($notify = false)
1929
+	{
1930
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1931
+	}
1932
+
1933
+
1934
+	/**
1935
+	 * decline_registration
1936
+	 *
1937
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1938
+	 * @return void
1939
+	 * @throws EE_Error
1940
+	 * @throws EntityNotFoundException
1941
+	 * @throws InvalidArgumentException
1942
+	 * @throws InvalidDataTypeException
1943
+	 * @throws InvalidInterfaceException
1944
+	 * @throws ReflectionException
1945
+	 * @throws RuntimeException
1946
+	 * @throws DomainException
1947
+	 */
1948
+	protected function pending_registration($notify = false)
1949
+	{
1950
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1951
+	}
1952
+
1953
+
1954
+	/**
1955
+	 * waitlist_registration
1956
+	 *
1957
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1958
+	 * @return void
1959
+	 * @throws EE_Error
1960
+	 * @throws EntityNotFoundException
1961
+	 * @throws InvalidArgumentException
1962
+	 * @throws InvalidDataTypeException
1963
+	 * @throws InvalidInterfaceException
1964
+	 * @throws ReflectionException
1965
+	 * @throws RuntimeException
1966
+	 * @throws DomainException
1967
+	 */
1968
+	protected function wait_list_registration($notify = false)
1969
+	{
1970
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1971
+	}
1972
+
1973
+
1974
+	/**
1975
+	 * generates HTML for the Registration main meta box
1976
+	 *
1977
+	 * @return void
1978
+	 * @throws DomainException
1979
+	 * @throws EE_Error
1980
+	 * @throws InvalidArgumentException
1981
+	 * @throws InvalidDataTypeException
1982
+	 * @throws InvalidInterfaceException
1983
+	 * @throws ReflectionException
1984
+	 * @throws EntityNotFoundException
1985
+	 */
1986
+	public function _reg_details_meta_box()
1987
+	{
1988
+		EEH_Autoloader::register_line_item_display_autoloaders();
1989
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1990
+		EE_Registry::instance()->load_helper('Line_Item');
1991
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1992
+			: EE_Transaction::new_instance();
1993
+		$this->_session = $transaction->session_data();
1994
+		$filters        = new EE_Line_Item_Filter_Collection();
1995
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1996
+		$filters->add(new EE_Non_Zero_Line_Item_Filter());
1997
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
1998
+			$filters,
1999
+			$transaction->total_line_item()
2000
+		);
2001
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
2002
+		$line_item_display                       = new EE_Line_Item_Display(
2003
+			'reg_admin_table',
2004
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2005
+		);
2006
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2007
+			$filtered_line_item_tree,
2008
+			['EE_Registration' => $this->_registration]
2009
+		);
2010
+		$attendee                                = $this->_registration->attendee();
2011
+		if (
2012
+			EE_Registry::instance()->CAP->current_user_can(
2013
+				'ee_read_transaction',
2014
+				'espresso_transactions_view_transaction'
2015
+			)
2016
+		) {
2017
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2018
+				EE_Admin_Page::add_query_args_and_nonce(
2019
+					[
2020
+						'action' => 'view_transaction',
2021
+						'TXN_ID' => $transaction->ID(),
2022
+					],
2023
+					TXN_ADMIN_URL
2024
+				),
2025
+				esc_html__(' View Transaction', 'event_espresso'),
2026
+				'button button--secondary right',
2027
+				'dashicons dashicons-cart'
2028
+			);
2029
+		} else {
2030
+			$this->_template_args['view_transaction_button'] = '';
2031
+		}
2032
+		if (
2033
+			$attendee instanceof EE_Attendee
2034
+			&& EE_Registry::instance()->CAP->current_user_can(
2035
+				'ee_send_message',
2036
+				'espresso_registrations_resend_registration'
2037
+			)
2038
+		) {
2039
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2040
+				EE_Admin_Page::add_query_args_and_nonce(
2041
+					[
2042
+						'action'      => 'resend_registration',
2043
+						'_REG_ID'     => $this->_registration->ID(),
2044
+						'redirect_to' => 'view_registration',
2045
+					],
2046
+					REG_ADMIN_URL
2047
+				),
2048
+				esc_html__(' Resend Registration', 'event_espresso'),
2049
+				'button button--secondary right',
2050
+				'dashicons dashicons-email-alt'
2051
+			);
2052
+		} else {
2053
+			$this->_template_args['resend_registration_button'] = '';
2054
+		}
2055
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2056
+		$payment                               = $transaction->get_first_related('Payment');
2057
+		$payment                               = ! $payment instanceof EE_Payment
2058
+			? EE_Payment::new_instance()
2059
+			: $payment;
2060
+		$payment_method                        = $payment->get_first_related('Payment_Method');
2061
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method
2062
+			? EE_Payment_Method::new_instance()
2063
+			: $payment_method;
2064
+		$reg_details                           = [
2065
+			'payment_method'       => $payment_method->name(),
2066
+			'response_msg'         => $payment->gateway_response(),
2067
+			'registration_id'      => $this->_registration->get('REG_code'),
2068
+			'registration_session' => $this->_registration->session_ID(),
2069
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2070
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2071
+		];
2072
+		if (isset($reg_details['registration_id'])) {
2073
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2074
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2075
+				'Registration ID',
2076
+				'event_espresso'
2077
+			);
2078
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2079
+		}
2080
+		if (isset($reg_details['payment_method'])) {
2081
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2082
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2083
+				'Most Recent Payment Method',
2084
+				'event_espresso'
2085
+			);
2086
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2087
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
2088
+			$this->_template_args['reg_details']['response_msg']['label']   = esc_html__(
2089
+				'Payment method response',
2090
+				'event_espresso'
2091
+			);
2092
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2093
+		}
2094
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2095
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2096
+			'Registration Session',
2097
+			'event_espresso'
2098
+		);
2099
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2100
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
2101
+		$this->_template_args['reg_details']['ip_address']['label']           = esc_html__(
2102
+			'Registration placed from IP',
2103
+			'event_espresso'
2104
+		);
2105
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
2106
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
2107
+		$this->_template_args['reg_details']['user_agent']['label']           = esc_html__(
2108
+			'Registrant User Agent',
2109
+			'event_espresso'
2110
+		);
2111
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
2112
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(
2113
+			[
2114
+				'action'   => 'default',
2115
+				'event_id' => $this->_registration->event_ID(),
2116
+			],
2117
+			REG_ADMIN_URL
2118
+		);
2119
+
2120
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2121
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2122
+
2123
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2124
+		EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2125
+	}
2126
+
2127
+
2128
+	/**
2129
+	 * generates HTML for the Registration Questions meta box.
2130
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2131
+	 * otherwise uses new forms system
2132
+	 *
2133
+	 * @return void
2134
+	 * @throws DomainException
2135
+	 * @throws EE_Error
2136
+	 * @throws InvalidArgumentException
2137
+	 * @throws InvalidDataTypeException
2138
+	 * @throws InvalidInterfaceException
2139
+	 * @throws ReflectionException
2140
+	 */
2141
+	public function _reg_questions_meta_box()
2142
+	{
2143
+		// allow someone to override this method entirely
2144
+		if (
2145
+			apply_filters(
2146
+				'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2147
+				true,
2148
+				$this,
2149
+				$this->_registration
2150
+			)
2151
+		) {
2152
+			$form = $this->_get_reg_custom_questions_form(
2153
+				$this->_registration->ID()
2154
+			);
2155
+
2156
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2157
+				? $form->get_html_and_js()
2158
+				: '';
2159
+
2160
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2161
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2162
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2163
+			EEH_Template::display_template($template_path, $this->_template_args);
2164
+		}
2165
+	}
2166
+
2167
+
2168
+	/**
2169
+	 * form_before_question_group
2170
+	 *
2171
+	 * @param string $output
2172
+	 * @return        string
2173
+	 * @deprecated    as of 4.8.32.rc.000
2174
+	 */
2175
+	public function form_before_question_group($output)
2176
+	{
2177
+		EE_Error::doing_it_wrong(
2178
+			__CLASS__ . '::' . __FUNCTION__,
2179
+			esc_html__(
2180
+				'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.',
2181
+				'event_espresso'
2182
+			),
2183
+			'4.8.32.rc.000'
2184
+		);
2185
+		return '
2186 2186
 	<table class="form-table ee-width-100">
2187 2187
 		<tbody>
2188 2188
 			';
2189
-    }
2190
-
2191
-
2192
-    /**
2193
-     * form_after_question_group
2194
-     *
2195
-     * @param string $output
2196
-     * @return        string
2197
-     * @deprecated    as of 4.8.32.rc.000
2198
-     */
2199
-    public function form_after_question_group($output)
2200
-    {
2201
-        EE_Error::doing_it_wrong(
2202
-            __CLASS__ . '::' . __FUNCTION__,
2203
-            esc_html__(
2204
-                '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.',
2205
-                'event_espresso'
2206
-            ),
2207
-            '4.8.32.rc.000'
2208
-        );
2209
-        return '
2189
+	}
2190
+
2191
+
2192
+	/**
2193
+	 * form_after_question_group
2194
+	 *
2195
+	 * @param string $output
2196
+	 * @return        string
2197
+	 * @deprecated    as of 4.8.32.rc.000
2198
+	 */
2199
+	public function form_after_question_group($output)
2200
+	{
2201
+		EE_Error::doing_it_wrong(
2202
+			__CLASS__ . '::' . __FUNCTION__,
2203
+			esc_html__(
2204
+				'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.',
2205
+				'event_espresso'
2206
+			),
2207
+			'4.8.32.rc.000'
2208
+		);
2209
+		return '
2210 2210
 			<tr class="hide-if-no-js">
2211 2211
 				<th> </th>
2212 2212
 				<td class="reg-admin-edit-attendee-question-td">
2213 2213
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2214
-               . esc_attr__('click to edit question', 'event_espresso')
2215
-               . '">
2214
+			   . esc_attr__('click to edit question', 'event_espresso')
2215
+			   . '">
2216 2216
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2217
-               . esc_html__('edit the above question group', 'event_espresso')
2218
-               . '</span>
2217
+			   . esc_html__('edit the above question group', 'event_espresso')
2218
+			   . '</span>
2219 2219
 						<div class="dashicons dashicons-edit"></div>
2220 2220
 					</a>
2221 2221
 				</td>
@@ -2223,636 +2223,636 @@  discard block
 block discarded – undo
2223 2223
 		</tbody>
2224 2224
 	</table>
2225 2225
 ';
2226
-    }
2227
-
2228
-
2229
-    /**
2230
-     * form_form_field_label_wrap
2231
-     *
2232
-     * @param string $label
2233
-     * @return        string
2234
-     * @deprecated    as of 4.8.32.rc.000
2235
-     */
2236
-    public function form_form_field_label_wrap($label)
2237
-    {
2238
-        EE_Error::doing_it_wrong(
2239
-            __CLASS__ . '::' . __FUNCTION__,
2240
-            esc_html__(
2241
-                '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.',
2242
-                'event_espresso'
2243
-            ),
2244
-            '4.8.32.rc.000'
2245
-        );
2246
-        return '
2226
+	}
2227
+
2228
+
2229
+	/**
2230
+	 * form_form_field_label_wrap
2231
+	 *
2232
+	 * @param string $label
2233
+	 * @return        string
2234
+	 * @deprecated    as of 4.8.32.rc.000
2235
+	 */
2236
+	public function form_form_field_label_wrap($label)
2237
+	{
2238
+		EE_Error::doing_it_wrong(
2239
+			__CLASS__ . '::' . __FUNCTION__,
2240
+			esc_html__(
2241
+				'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.',
2242
+				'event_espresso'
2243
+			),
2244
+			'4.8.32.rc.000'
2245
+		);
2246
+		return '
2247 2247
 			<tr>
2248 2248
 				<th>
2249 2249
 					' . $label . '
2250 2250
 				</th>';
2251
-    }
2252
-
2253
-
2254
-    /**
2255
-     * form_form_field_input__wrap
2256
-     *
2257
-     * @param string $input
2258
-     * @return        string
2259
-     * @deprecated    as of 4.8.32.rc.000
2260
-     */
2261
-    public function form_form_field_input__wrap($input)
2262
-    {
2263
-        EE_Error::doing_it_wrong(
2264
-            __CLASS__ . '::' . __FUNCTION__,
2265
-            esc_html__(
2266
-                '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.',
2267
-                'event_espresso'
2268
-            ),
2269
-            '4.8.32.rc.000'
2270
-        );
2271
-        return '
2251
+	}
2252
+
2253
+
2254
+	/**
2255
+	 * form_form_field_input__wrap
2256
+	 *
2257
+	 * @param string $input
2258
+	 * @return        string
2259
+	 * @deprecated    as of 4.8.32.rc.000
2260
+	 */
2261
+	public function form_form_field_input__wrap($input)
2262
+	{
2263
+		EE_Error::doing_it_wrong(
2264
+			__CLASS__ . '::' . __FUNCTION__,
2265
+			esc_html__(
2266
+				'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.',
2267
+				'event_espresso'
2268
+			),
2269
+			'4.8.32.rc.000'
2270
+		);
2271
+		return '
2272 2272
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2273 2273
 					' . $input . '
2274 2274
 				</td>
2275 2275
 			</tr>';
2276
-    }
2277
-
2278
-
2279
-    /**
2280
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2281
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2282
-     * to display the page
2283
-     *
2284
-     * @return void
2285
-     * @throws EE_Error
2286
-     * @throws InvalidArgumentException
2287
-     * @throws InvalidDataTypeException
2288
-     * @throws InvalidInterfaceException
2289
-     * @throws ReflectionException
2290
-     */
2291
-    protected function _update_attendee_registration_form()
2292
-    {
2293
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2294
-        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2295
-            $REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2296
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2297
-            if ($success) {
2298
-                $what  = esc_html__('Registration Form', 'event_espresso');
2299
-                $route = $REG_ID
2300
-                    ? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2301
-                    : ['action' => 'default'];
2302
-                $this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2303
-            }
2304
-        }
2305
-    }
2306
-
2307
-
2308
-    /**
2309
-     * Gets the form for saving registrations custom questions (if done
2310
-     * previously retrieves the cached form object, which may have validation errors in it)
2311
-     *
2312
-     * @param int $REG_ID
2313
-     * @return EE_Registration_Custom_Questions_Form
2314
-     * @throws EE_Error
2315
-     * @throws InvalidArgumentException
2316
-     * @throws InvalidDataTypeException
2317
-     * @throws InvalidInterfaceException
2318
-     * @throws ReflectionException
2319
-     */
2320
-    protected function _get_reg_custom_questions_form($REG_ID)
2321
-    {
2322
-        if (! $this->_reg_custom_questions_form) {
2323
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2324
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2325
-                $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2326
-            );
2327
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2328
-        }
2329
-        return $this->_reg_custom_questions_form;
2330
-    }
2331
-
2332
-
2333
-    /**
2334
-     * Saves
2335
-     *
2336
-     * @param bool $REG_ID
2337
-     * @return bool
2338
-     * @throws EE_Error
2339
-     * @throws InvalidArgumentException
2340
-     * @throws InvalidDataTypeException
2341
-     * @throws InvalidInterfaceException
2342
-     * @throws ReflectionException
2343
-     */
2344
-    private function _save_reg_custom_questions_form($REG_ID = 0)
2345
-    {
2346
-        if (! $REG_ID) {
2347
-            EE_Error::add_error(
2348
-                esc_html__(
2349
-                    'An error occurred. No registration ID was received.',
2350
-                    'event_espresso'
2351
-                ),
2352
-                __FILE__,
2353
-                __FUNCTION__,
2354
-                __LINE__
2355
-            );
2356
-        }
2357
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2358
-        $form->receive_form_submission($this->request->requestParams());
2359
-        $success = false;
2360
-        if ($form->is_valid()) {
2361
-            foreach ($form->subforms() as $question_group_form) {
2362
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2363
-                    $where_conditions    = [
2364
-                        'QST_ID' => $question_id,
2365
-                        'REG_ID' => $REG_ID,
2366
-                    ];
2367
-                    $possibly_new_values = [
2368
-                        'ANS_value' => $input->normalized_value(),
2369
-                    ];
2370
-                    $answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2371
-                    if ($answer instanceof EE_Answer) {
2372
-                        $success = $answer->save($possibly_new_values);
2373
-                    } else {
2374
-                        // insert it then
2375
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2376
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
2377
-                        $success     = $answer->save();
2378
-                    }
2379
-                }
2380
-            }
2381
-        } else {
2382
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2383
-        }
2384
-        return $success;
2385
-    }
2386
-
2387
-
2388
-    /**
2389
-     * generates HTML for the Registration main meta box
2390
-     *
2391
-     * @return void
2392
-     * @throws DomainException
2393
-     * @throws EE_Error
2394
-     * @throws InvalidArgumentException
2395
-     * @throws InvalidDataTypeException
2396
-     * @throws InvalidInterfaceException
2397
-     * @throws ReflectionException
2398
-     */
2399
-    public function _reg_attendees_meta_box()
2400
-    {
2401
-        $REG = $this->getRegistrationModel();
2402
-        // get all other registrations on this transaction, and cache
2403
-        // the attendees for them so we don't have to run another query using force_join
2404
-        $registrations                           = $REG->get_all(
2405
-            [
2406
-                [
2407
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2408
-                    'REG_ID' => ['!=', $this->_registration->ID()],
2409
-                ],
2410
-                'force_join'               => ['Attendee'],
2411
-                'default_where_conditions' => 'other_models_only',
2412
-            ]
2413
-        );
2414
-        $this->_template_args['attendees']       = [];
2415
-        $this->_template_args['attendee_notice'] = '';
2416
-        if (
2417
-            empty($registrations)
2418
-            || (is_array($registrations)
2419
-                && ! EEH_Array::get_one_item_from_array($registrations))
2420
-        ) {
2421
-            EE_Error::add_error(
2422
-                esc_html__(
2423
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2424
-                    'event_espresso'
2425
-                ),
2426
-                __FILE__,
2427
-                __FUNCTION__,
2428
-                __LINE__
2429
-            );
2430
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2431
-        } else {
2432
-            $att_nmbr = 1;
2433
-            foreach ($registrations as $registration) {
2434
-                /* @var $registration EE_Registration */
2435
-                $attendee                                                      = $registration->attendee()
2436
-                    ? $registration->attendee()
2437
-                    : $this->getAttendeeModel()->create_default_object();
2438
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2439
-                $this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2440
-                $this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2441
-                $this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2442
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2443
-                $this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2444
-                    ', ',
2445
-                    $attendee->full_address_as_array()
2446
-                );
2447
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2448
-                    [
2449
-                        'action' => 'edit_attendee',
2450
-                        'post'   => $attendee->ID(),
2451
-                    ],
2452
-                    REG_ADMIN_URL
2453
-                );
2454
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2455
-                    $registration->event_obj() instanceof EE_Event
2456
-                        ? $registration->event_obj()->name()
2457
-                        : '';
2458
-                $att_nmbr++;
2459
-            }
2460
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2461
-        }
2462
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2463
-        EEH_Template::display_template($template_path, $this->_template_args);
2464
-    }
2465
-
2466
-
2467
-    /**
2468
-     * generates HTML for the Edit Registration side meta box
2469
-     *
2470
-     * @return void
2471
-     * @throws DomainException
2472
-     * @throws EE_Error
2473
-     * @throws InvalidArgumentException
2474
-     * @throws InvalidDataTypeException
2475
-     * @throws InvalidInterfaceException
2476
-     * @throws ReflectionException
2477
-     */
2478
-    public function _reg_registrant_side_meta_box()
2479
-    {
2480
-        /*@var $attendee EE_Attendee */
2481
-        $att_check = $this->_registration->attendee();
2482
-        $attendee  = $att_check instanceof EE_Attendee
2483
-            ? $att_check
2484
-            : $this->getAttendeeModel()->create_default_object();
2485
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2486
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2487
-        // primary registration object (that way we know if we need to show create button or not)
2488
-        if (! $this->_registration->is_primary_registrant()) {
2489
-            $primary_registration = $this->_registration->get_primary_registration();
2490
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2491
-                : null;
2492
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2493
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2494
-                // custom attendee object so let's not worry about the primary reg.
2495
-                $primary_registration = null;
2496
-            }
2497
-        } else {
2498
-            $primary_registration = null;
2499
-        }
2500
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2501
-        $this->_template_args['fname']             = $attendee->fname();
2502
-        $this->_template_args['lname']             = $attendee->lname();
2503
-        $this->_template_args['email']             = $attendee->email();
2504
-        $this->_template_args['phone']             = $attendee->phone();
2505
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2506
-        // edit link
2507
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2508
-            [
2509
-                'action' => 'edit_attendee',
2510
-                'post'   => $attendee->ID(),
2511
-            ],
2512
-            REG_ADMIN_URL
2513
-        );
2514
-        $this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2515
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2516
-        // create link
2517
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2518
-            ? EE_Admin_Page::add_query_args_and_nonce(
2519
-                [
2520
-                    'action'  => 'duplicate_attendee',
2521
-                    '_REG_ID' => $this->_registration->ID(),
2522
-                ],
2523
-                REG_ADMIN_URL
2524
-            ) : '';
2525
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2526
-        $this->_template_args['att_check'] = $att_check;
2527
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2528
-        EEH_Template::display_template($template_path, $this->_template_args);
2529
-    }
2530
-
2531
-
2532
-    /**
2533
-     * trash or restore registrations
2534
-     *
2535
-     * @param boolean $trash whether to archive or restore
2536
-     * @return void
2537
-     * @throws EE_Error
2538
-     * @throws InvalidArgumentException
2539
-     * @throws InvalidDataTypeException
2540
-     * @throws InvalidInterfaceException
2541
-     * @throws RuntimeException
2542
-     */
2543
-    protected function _trash_or_restore_registrations($trash = true)
2544
-    {
2545
-        // if empty _REG_ID then get out because there's nothing to do
2546
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2547
-        if (empty($REG_IDs)) {
2548
-            EE_Error::add_error(
2549
-                sprintf(
2550
-                    esc_html__(
2551
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2552
-                        'event_espresso'
2553
-                    ),
2554
-                    $trash ? 'trash' : 'restore'
2555
-                ),
2556
-                __FILE__,
2557
-                __LINE__,
2558
-                __FUNCTION__
2559
-            );
2560
-            $this->_redirect_after_action(false, '', '', [], true);
2561
-        }
2562
-        $success        = 0;
2563
-        $overwrite_msgs = false;
2564
-        // Checkboxes
2565
-        $reg_count = count($REG_IDs);
2566
-        // cycle thru checkboxes
2567
-        foreach ($REG_IDs as $REG_ID) {
2568
-            /** @var EE_Registration $REG */
2569
-            $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2570
-            $payments = $REG->registration_payments();
2571
-            if (! empty($payments)) {
2572
-                $name           = $REG->attendee() instanceof EE_Attendee
2573
-                    ? $REG->attendee()->full_name()
2574
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2575
-                $overwrite_msgs = true;
2576
-                EE_Error::add_error(
2577
-                    sprintf(
2578
-                        esc_html__(
2579
-                            '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.',
2580
-                            'event_espresso'
2581
-                        ),
2582
-                        $name
2583
-                    ),
2584
-                    __FILE__,
2585
-                    __FUNCTION__,
2586
-                    __LINE__
2587
-                );
2588
-                // can't trash this registration because it has payments.
2589
-                continue;
2590
-            }
2591
-            $updated = $trash ? $REG->delete() : $REG->restore();
2592
-            if ($updated) {
2593
-                $success++;
2594
-            }
2595
-        }
2596
-        $this->_redirect_after_action(
2597
-            $success === $reg_count, // were ALL registrations affected?
2598
-            $success > 1
2599
-                ? esc_html__('Registrations', 'event_espresso')
2600
-                : esc_html__('Registration', 'event_espresso'),
2601
-            $trash
2602
-                ? esc_html__('moved to the trash', 'event_espresso')
2603
-                : esc_html__('restored', 'event_espresso'),
2604
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2605
-            $overwrite_msgs
2606
-        );
2607
-    }
2608
-
2609
-
2610
-    /**
2611
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2612
-     * registration but also.
2613
-     * 1. Removing relations to EE_Attendee
2614
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2615
-     * ALSO trashed.
2616
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2617
-     * 4. Removing relationships between all tickets and the related registrations
2618
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2619
-     * 6. Deleting permanently any related Checkins.
2620
-     *
2621
-     * @return void
2622
-     * @throws EE_Error
2623
-     * @throws InvalidArgumentException
2624
-     * @throws InvalidDataTypeException
2625
-     * @throws InvalidInterfaceException
2626
-     * @throws ReflectionException
2627
-     */
2628
-    protected function _delete_registrations()
2629
-    {
2630
-        $REG_MDL = $this->getRegistrationModel();
2631
-        $success = 0;
2632
-        // Checkboxes
2633
-        $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2634
-
2635
-        if (! empty($REG_IDs)) {
2636
-            // if array has more than one element than success message should be plural
2637
-            $success = count($REG_IDs) > 1 ? 2 : 1;
2638
-            // cycle thru checkboxes
2639
-            foreach ($REG_IDs as $REG_ID) {
2640
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2641
-                if (! $REG instanceof EE_Registration) {
2642
-                    continue;
2643
-                }
2644
-                $deleted = $this->_delete_registration($REG);
2645
-                if (! $deleted) {
2646
-                    $success = 0;
2647
-                }
2648
-            }
2649
-        }
2650
-
2651
-        $what        = $success > 1
2652
-            ? esc_html__('Registrations', 'event_espresso')
2653
-            : esc_html__('Registration', 'event_espresso');
2654
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2655
-        $this->_redirect_after_action(
2656
-            $success,
2657
-            $what,
2658
-            $action_desc,
2659
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2660
-            true
2661
-        );
2662
-    }
2663
-
2664
-
2665
-    /**
2666
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2667
-     * models get affected.
2668
-     *
2669
-     * @param EE_Registration $REG registration to be deleted permanently
2670
-     * @return bool true = successful deletion, false = fail.
2671
-     * @throws EE_Error
2672
-     * @throws InvalidArgumentException
2673
-     * @throws InvalidDataTypeException
2674
-     * @throws InvalidInterfaceException
2675
-     * @throws ReflectionException
2676
-     */
2677
-    protected function _delete_registration(EE_Registration $REG)
2678
-    {
2679
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2680
-        // registrations on the transaction that are NOT trashed.
2681
-        $TXN = $REG->get_first_related('Transaction');
2682
-        if (! $TXN instanceof EE_Transaction) {
2683
-            EE_Error::add_error(
2684
-                sprintf(
2685
-                    esc_html__(
2686
-                        'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2687
-                        'event_espresso'
2688
-                    ),
2689
-                    $REG->id()
2690
-                ),
2691
-                __FILE__,
2692
-                __FUNCTION__,
2693
-                __LINE__
2694
-            );
2695
-            return false;
2696
-        }
2697
-        $REGS        = $TXN->get_many_related('Registration');
2698
-        $all_trashed = true;
2699
-        foreach ($REGS as $registration) {
2700
-            if (! $registration->get('REG_deleted')) {
2701
-                $all_trashed = false;
2702
-            }
2703
-        }
2704
-        if (! $all_trashed) {
2705
-            EE_Error::add_error(
2706
-                esc_html__(
2707
-                    '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.',
2708
-                    'event_espresso'
2709
-                ),
2710
-                __FILE__,
2711
-                __FUNCTION__,
2712
-                __LINE__
2713
-            );
2714
-            return false;
2715
-        }
2716
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2717
-        // separately from THIS one).
2718
-        foreach ($REGS as $registration) {
2719
-            // delete related answers
2720
-            $registration->delete_related_permanently('Answer');
2721
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2722
-            $attendee = $registration->get_first_related('Attendee');
2723
-            if ($attendee instanceof EE_Attendee) {
2724
-                $registration->_remove_relation_to($attendee, 'Attendee');
2725
-            }
2726
-            // now remove relationships to tickets on this registration.
2727
-            $registration->_remove_relations('Ticket');
2728
-            // now delete permanently the checkins related to this registration.
2729
-            $registration->delete_related_permanently('Checkin');
2730
-            if ($registration->ID() === $REG->ID()) {
2731
-                continue;
2732
-            } //we don't want to delete permanently the existing registration just yet.
2733
-            // remove relation to transaction for these registrations if NOT the existing registrations
2734
-            $registration->_remove_relations('Transaction');
2735
-            // delete permanently any related messages.
2736
-            $registration->delete_related_permanently('Message');
2737
-            // now delete this registration permanently
2738
-            $registration->delete_permanently();
2739
-        }
2740
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2741
-        // (the transaction and line items should be all that's left).
2742
-        // delete the line items related to the transaction for this registration.
2743
-        $TXN->delete_related_permanently('Line_Item');
2744
-        // we need to remove all the relationships on the transaction
2745
-        $TXN->delete_related_permanently('Payment');
2746
-        $TXN->delete_related_permanently('Extra_Meta');
2747
-        $TXN->delete_related_permanently('Message');
2748
-        // now we can delete this REG permanently (and the transaction of course)
2749
-        $REG->delete_related_permanently('Transaction');
2750
-        return $REG->delete_permanently();
2751
-    }
2752
-
2753
-
2754
-    /**
2755
-     *    generates HTML for the Register New Attendee Admin page
2756
-     *
2757
-     * @throws DomainException
2758
-     * @throws EE_Error
2759
-     * @throws InvalidArgumentException
2760
-     * @throws InvalidDataTypeException
2761
-     * @throws InvalidInterfaceException
2762
-     * @throws ReflectionException
2763
-     */
2764
-    public function new_registration()
2765
-    {
2766
-        if (! $this->_set_reg_event()) {
2767
-            throw new EE_Error(
2768
-                esc_html__(
2769
-                    'Unable to continue with registering because there is no Event ID in the request',
2770
-                    'event_espresso'
2771
-                )
2772
-            );
2773
-        }
2774
-        /** @var CurrentPage $current_page */
2775
-        $current_page = $this->loader->getShared(CurrentPage::class);
2776
-        $current_page->setEspressoPage(true);
2777
-        // gotta start with a clean slate if we're not coming here via ajax
2778
-        if (
2779
-            ! $this->request->isAjax()
2780
-            && (
2781
-                ! $this->request->requestParamIsSet('processing_registration')
2782
-                || $this->request->requestParamIsSet('step_error')
2783
-            )
2784
-        ) {
2785
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2786
-        }
2787
-        $this->_template_args['event_name'] = '';
2788
-        // event name
2789
-        if ($this->_reg_event) {
2790
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2791
-            $edit_event_url                     = self::add_query_args_and_nonce(
2792
-                [
2793
-                    'action' => 'edit',
2794
-                    'post'   => $this->_reg_event->ID(),
2795
-                ],
2796
-                EVENTS_ADMIN_URL
2797
-            );
2798
-            $edit_event_lnk                     = '<a href="'
2799
-                                                  . $edit_event_url
2800
-                                                  . '" title="'
2801
-                                                  . esc_attr__('Edit ', 'event_espresso')
2802
-                                                  . $this->_reg_event->name()
2803
-                                                  . '">'
2804
-                                                  . esc_html__('Edit Event', 'event_espresso')
2805
-                                                  . '</a>';
2806
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2807
-                                                   . $edit_event_lnk
2808
-                                                   . '</span>';
2809
-        }
2810
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2811
-        if ($this->request->isAjax()) {
2812
-            $this->_return_json();
2813
-        }
2814
-        // grab header
2815
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2816
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2817
-            $template_path,
2818
-            $this->_template_args,
2819
-            true
2820
-        );
2821
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2822
-        // the details template wrapper
2823
-        $this->display_admin_page_with_sidebar();
2824
-    }
2825
-
2826
-
2827
-    /**
2828
-     * This returns the content for a registration step
2829
-     *
2830
-     * @return string html
2831
-     * @throws DomainException
2832
-     * @throws EE_Error
2833
-     * @throws InvalidArgumentException
2834
-     * @throws InvalidDataTypeException
2835
-     * @throws InvalidInterfaceException
2836
-     * @throws ReflectionException
2837
-     */
2838
-    protected function _get_registration_step_content()
2839
-    {
2840
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2841
-            $warning_msg = sprintf(
2842
-                esc_html__(
2843
-                    '%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',
2844
-                    'event_espresso'
2845
-                ),
2846
-                '<br />',
2847
-                '<h3 class="important-notice">',
2848
-                '</h3>',
2849
-                '<div class="float-right">',
2850
-                '<span id="redirect_timer" class="important-notice">30</span>',
2851
-                '</div>',
2852
-                '<b>',
2853
-                '</b>'
2854
-            );
2855
-            return '
2276
+	}
2277
+
2278
+
2279
+	/**
2280
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2281
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2282
+	 * to display the page
2283
+	 *
2284
+	 * @return void
2285
+	 * @throws EE_Error
2286
+	 * @throws InvalidArgumentException
2287
+	 * @throws InvalidDataTypeException
2288
+	 * @throws InvalidInterfaceException
2289
+	 * @throws ReflectionException
2290
+	 */
2291
+	protected function _update_attendee_registration_form()
2292
+	{
2293
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2294
+		if ($_SERVER['REQUEST_METHOD'] === 'POST') {
2295
+			$REG_ID  = $this->request->getRequestParam('_REG_ID', 0, 'int');
2296
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2297
+			if ($success) {
2298
+				$what  = esc_html__('Registration Form', 'event_espresso');
2299
+				$route = $REG_ID
2300
+					? ['action' => 'view_registration', '_REG_ID' => $REG_ID]
2301
+					: ['action' => 'default'];
2302
+				$this->_redirect_after_action(true, $what, esc_html__('updated', 'event_espresso'), $route);
2303
+			}
2304
+		}
2305
+	}
2306
+
2307
+
2308
+	/**
2309
+	 * Gets the form for saving registrations custom questions (if done
2310
+	 * previously retrieves the cached form object, which may have validation errors in it)
2311
+	 *
2312
+	 * @param int $REG_ID
2313
+	 * @return EE_Registration_Custom_Questions_Form
2314
+	 * @throws EE_Error
2315
+	 * @throws InvalidArgumentException
2316
+	 * @throws InvalidDataTypeException
2317
+	 * @throws InvalidInterfaceException
2318
+	 * @throws ReflectionException
2319
+	 */
2320
+	protected function _get_reg_custom_questions_form($REG_ID)
2321
+	{
2322
+		if (! $this->_reg_custom_questions_form) {
2323
+			require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2324
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2325
+				$this->getRegistrationModel()->get_one_by_ID($REG_ID)
2326
+			);
2327
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2328
+		}
2329
+		return $this->_reg_custom_questions_form;
2330
+	}
2331
+
2332
+
2333
+	/**
2334
+	 * Saves
2335
+	 *
2336
+	 * @param bool $REG_ID
2337
+	 * @return bool
2338
+	 * @throws EE_Error
2339
+	 * @throws InvalidArgumentException
2340
+	 * @throws InvalidDataTypeException
2341
+	 * @throws InvalidInterfaceException
2342
+	 * @throws ReflectionException
2343
+	 */
2344
+	private function _save_reg_custom_questions_form($REG_ID = 0)
2345
+	{
2346
+		if (! $REG_ID) {
2347
+			EE_Error::add_error(
2348
+				esc_html__(
2349
+					'An error occurred. No registration ID was received.',
2350
+					'event_espresso'
2351
+				),
2352
+				__FILE__,
2353
+				__FUNCTION__,
2354
+				__LINE__
2355
+			);
2356
+		}
2357
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2358
+		$form->receive_form_submission($this->request->requestParams());
2359
+		$success = false;
2360
+		if ($form->is_valid()) {
2361
+			foreach ($form->subforms() as $question_group_form) {
2362
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2363
+					$where_conditions    = [
2364
+						'QST_ID' => $question_id,
2365
+						'REG_ID' => $REG_ID,
2366
+					];
2367
+					$possibly_new_values = [
2368
+						'ANS_value' => $input->normalized_value(),
2369
+					];
2370
+					$answer              = EEM_Answer::instance()->get_one([$where_conditions]);
2371
+					if ($answer instanceof EE_Answer) {
2372
+						$success = $answer->save($possibly_new_values);
2373
+					} else {
2374
+						// insert it then
2375
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2376
+						$answer      = EE_Answer::new_instance($cols_n_vals);
2377
+						$success     = $answer->save();
2378
+					}
2379
+				}
2380
+			}
2381
+		} else {
2382
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2383
+		}
2384
+		return $success;
2385
+	}
2386
+
2387
+
2388
+	/**
2389
+	 * generates HTML for the Registration main meta box
2390
+	 *
2391
+	 * @return void
2392
+	 * @throws DomainException
2393
+	 * @throws EE_Error
2394
+	 * @throws InvalidArgumentException
2395
+	 * @throws InvalidDataTypeException
2396
+	 * @throws InvalidInterfaceException
2397
+	 * @throws ReflectionException
2398
+	 */
2399
+	public function _reg_attendees_meta_box()
2400
+	{
2401
+		$REG = $this->getRegistrationModel();
2402
+		// get all other registrations on this transaction, and cache
2403
+		// the attendees for them so we don't have to run another query using force_join
2404
+		$registrations                           = $REG->get_all(
2405
+			[
2406
+				[
2407
+					'TXN_ID' => $this->_registration->transaction_ID(),
2408
+					'REG_ID' => ['!=', $this->_registration->ID()],
2409
+				],
2410
+				'force_join'               => ['Attendee'],
2411
+				'default_where_conditions' => 'other_models_only',
2412
+			]
2413
+		);
2414
+		$this->_template_args['attendees']       = [];
2415
+		$this->_template_args['attendee_notice'] = '';
2416
+		if (
2417
+			empty($registrations)
2418
+			|| (is_array($registrations)
2419
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2420
+		) {
2421
+			EE_Error::add_error(
2422
+				esc_html__(
2423
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2424
+					'event_espresso'
2425
+				),
2426
+				__FILE__,
2427
+				__FUNCTION__,
2428
+				__LINE__
2429
+			);
2430
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2431
+		} else {
2432
+			$att_nmbr = 1;
2433
+			foreach ($registrations as $registration) {
2434
+				/* @var $registration EE_Registration */
2435
+				$attendee                                                      = $registration->attendee()
2436
+					? $registration->attendee()
2437
+					: $this->getAttendeeModel()->create_default_object();
2438
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2439
+				$this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2440
+				$this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2441
+				$this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2442
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2443
+				$this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2444
+					', ',
2445
+					$attendee->full_address_as_array()
2446
+				);
2447
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2448
+					[
2449
+						'action' => 'edit_attendee',
2450
+						'post'   => $attendee->ID(),
2451
+					],
2452
+					REG_ADMIN_URL
2453
+				);
2454
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2455
+					$registration->event_obj() instanceof EE_Event
2456
+						? $registration->event_obj()->name()
2457
+						: '';
2458
+				$att_nmbr++;
2459
+			}
2460
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2461
+		}
2462
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2463
+		EEH_Template::display_template($template_path, $this->_template_args);
2464
+	}
2465
+
2466
+
2467
+	/**
2468
+	 * generates HTML for the Edit Registration side meta box
2469
+	 *
2470
+	 * @return void
2471
+	 * @throws DomainException
2472
+	 * @throws EE_Error
2473
+	 * @throws InvalidArgumentException
2474
+	 * @throws InvalidDataTypeException
2475
+	 * @throws InvalidInterfaceException
2476
+	 * @throws ReflectionException
2477
+	 */
2478
+	public function _reg_registrant_side_meta_box()
2479
+	{
2480
+		/*@var $attendee EE_Attendee */
2481
+		$att_check = $this->_registration->attendee();
2482
+		$attendee  = $att_check instanceof EE_Attendee
2483
+			? $att_check
2484
+			: $this->getAttendeeModel()->create_default_object();
2485
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2486
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2487
+		// primary registration object (that way we know if we need to show create button or not)
2488
+		if (! $this->_registration->is_primary_registrant()) {
2489
+			$primary_registration = $this->_registration->get_primary_registration();
2490
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2491
+				: null;
2492
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2493
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2494
+				// custom attendee object so let's not worry about the primary reg.
2495
+				$primary_registration = null;
2496
+			}
2497
+		} else {
2498
+			$primary_registration = null;
2499
+		}
2500
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2501
+		$this->_template_args['fname']             = $attendee->fname();
2502
+		$this->_template_args['lname']             = $attendee->lname();
2503
+		$this->_template_args['email']             = $attendee->email();
2504
+		$this->_template_args['phone']             = $attendee->phone();
2505
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2506
+		// edit link
2507
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2508
+			[
2509
+				'action' => 'edit_attendee',
2510
+				'post'   => $attendee->ID(),
2511
+			],
2512
+			REG_ADMIN_URL
2513
+		);
2514
+		$this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2515
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2516
+		// create link
2517
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2518
+			? EE_Admin_Page::add_query_args_and_nonce(
2519
+				[
2520
+					'action'  => 'duplicate_attendee',
2521
+					'_REG_ID' => $this->_registration->ID(),
2522
+				],
2523
+				REG_ADMIN_URL
2524
+			) : '';
2525
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2526
+		$this->_template_args['att_check'] = $att_check;
2527
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2528
+		EEH_Template::display_template($template_path, $this->_template_args);
2529
+	}
2530
+
2531
+
2532
+	/**
2533
+	 * trash or restore registrations
2534
+	 *
2535
+	 * @param boolean $trash whether to archive or restore
2536
+	 * @return void
2537
+	 * @throws EE_Error
2538
+	 * @throws InvalidArgumentException
2539
+	 * @throws InvalidDataTypeException
2540
+	 * @throws InvalidInterfaceException
2541
+	 * @throws RuntimeException
2542
+	 */
2543
+	protected function _trash_or_restore_registrations($trash = true)
2544
+	{
2545
+		// if empty _REG_ID then get out because there's nothing to do
2546
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2547
+		if (empty($REG_IDs)) {
2548
+			EE_Error::add_error(
2549
+				sprintf(
2550
+					esc_html__(
2551
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2552
+						'event_espresso'
2553
+					),
2554
+					$trash ? 'trash' : 'restore'
2555
+				),
2556
+				__FILE__,
2557
+				__LINE__,
2558
+				__FUNCTION__
2559
+			);
2560
+			$this->_redirect_after_action(false, '', '', [], true);
2561
+		}
2562
+		$success        = 0;
2563
+		$overwrite_msgs = false;
2564
+		// Checkboxes
2565
+		$reg_count = count($REG_IDs);
2566
+		// cycle thru checkboxes
2567
+		foreach ($REG_IDs as $REG_ID) {
2568
+			/** @var EE_Registration $REG */
2569
+			$REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2570
+			$payments = $REG->registration_payments();
2571
+			if (! empty($payments)) {
2572
+				$name           = $REG->attendee() instanceof EE_Attendee
2573
+					? $REG->attendee()->full_name()
2574
+					: esc_html__('Unknown Attendee', 'event_espresso');
2575
+				$overwrite_msgs = true;
2576
+				EE_Error::add_error(
2577
+					sprintf(
2578
+						esc_html__(
2579
+							'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.',
2580
+							'event_espresso'
2581
+						),
2582
+						$name
2583
+					),
2584
+					__FILE__,
2585
+					__FUNCTION__,
2586
+					__LINE__
2587
+				);
2588
+				// can't trash this registration because it has payments.
2589
+				continue;
2590
+			}
2591
+			$updated = $trash ? $REG->delete() : $REG->restore();
2592
+			if ($updated) {
2593
+				$success++;
2594
+			}
2595
+		}
2596
+		$this->_redirect_after_action(
2597
+			$success === $reg_count, // were ALL registrations affected?
2598
+			$success > 1
2599
+				? esc_html__('Registrations', 'event_espresso')
2600
+				: esc_html__('Registration', 'event_espresso'),
2601
+			$trash
2602
+				? esc_html__('moved to the trash', 'event_espresso')
2603
+				: esc_html__('restored', 'event_espresso'),
2604
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2605
+			$overwrite_msgs
2606
+		);
2607
+	}
2608
+
2609
+
2610
+	/**
2611
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2612
+	 * registration but also.
2613
+	 * 1. Removing relations to EE_Attendee
2614
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2615
+	 * ALSO trashed.
2616
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2617
+	 * 4. Removing relationships between all tickets and the related registrations
2618
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2619
+	 * 6. Deleting permanently any related Checkins.
2620
+	 *
2621
+	 * @return void
2622
+	 * @throws EE_Error
2623
+	 * @throws InvalidArgumentException
2624
+	 * @throws InvalidDataTypeException
2625
+	 * @throws InvalidInterfaceException
2626
+	 * @throws ReflectionException
2627
+	 */
2628
+	protected function _delete_registrations()
2629
+	{
2630
+		$REG_MDL = $this->getRegistrationModel();
2631
+		$success = 0;
2632
+		// Checkboxes
2633
+		$REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2634
+
2635
+		if (! empty($REG_IDs)) {
2636
+			// if array has more than one element than success message should be plural
2637
+			$success = count($REG_IDs) > 1 ? 2 : 1;
2638
+			// cycle thru checkboxes
2639
+			foreach ($REG_IDs as $REG_ID) {
2640
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2641
+				if (! $REG instanceof EE_Registration) {
2642
+					continue;
2643
+				}
2644
+				$deleted = $this->_delete_registration($REG);
2645
+				if (! $deleted) {
2646
+					$success = 0;
2647
+				}
2648
+			}
2649
+		}
2650
+
2651
+		$what        = $success > 1
2652
+			? esc_html__('Registrations', 'event_espresso')
2653
+			: esc_html__('Registration', 'event_espresso');
2654
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2655
+		$this->_redirect_after_action(
2656
+			$success,
2657
+			$what,
2658
+			$action_desc,
2659
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2660
+			true
2661
+		);
2662
+	}
2663
+
2664
+
2665
+	/**
2666
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2667
+	 * models get affected.
2668
+	 *
2669
+	 * @param EE_Registration $REG registration to be deleted permanently
2670
+	 * @return bool true = successful deletion, false = fail.
2671
+	 * @throws EE_Error
2672
+	 * @throws InvalidArgumentException
2673
+	 * @throws InvalidDataTypeException
2674
+	 * @throws InvalidInterfaceException
2675
+	 * @throws ReflectionException
2676
+	 */
2677
+	protected function _delete_registration(EE_Registration $REG)
2678
+	{
2679
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2680
+		// registrations on the transaction that are NOT trashed.
2681
+		$TXN = $REG->get_first_related('Transaction');
2682
+		if (! $TXN instanceof EE_Transaction) {
2683
+			EE_Error::add_error(
2684
+				sprintf(
2685
+					esc_html__(
2686
+						'Unable to permanently delete registration %d because its related transaction has already been deleted. If you can restore the related transaction to the database then this registration can be deleted.',
2687
+						'event_espresso'
2688
+					),
2689
+					$REG->id()
2690
+				),
2691
+				__FILE__,
2692
+				__FUNCTION__,
2693
+				__LINE__
2694
+			);
2695
+			return false;
2696
+		}
2697
+		$REGS        = $TXN->get_many_related('Registration');
2698
+		$all_trashed = true;
2699
+		foreach ($REGS as $registration) {
2700
+			if (! $registration->get('REG_deleted')) {
2701
+				$all_trashed = false;
2702
+			}
2703
+		}
2704
+		if (! $all_trashed) {
2705
+			EE_Error::add_error(
2706
+				esc_html__(
2707
+					'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.',
2708
+					'event_espresso'
2709
+				),
2710
+				__FILE__,
2711
+				__FUNCTION__,
2712
+				__LINE__
2713
+			);
2714
+			return false;
2715
+		}
2716
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2717
+		// separately from THIS one).
2718
+		foreach ($REGS as $registration) {
2719
+			// delete related answers
2720
+			$registration->delete_related_permanently('Answer');
2721
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2722
+			$attendee = $registration->get_first_related('Attendee');
2723
+			if ($attendee instanceof EE_Attendee) {
2724
+				$registration->_remove_relation_to($attendee, 'Attendee');
2725
+			}
2726
+			// now remove relationships to tickets on this registration.
2727
+			$registration->_remove_relations('Ticket');
2728
+			// now delete permanently the checkins related to this registration.
2729
+			$registration->delete_related_permanently('Checkin');
2730
+			if ($registration->ID() === $REG->ID()) {
2731
+				continue;
2732
+			} //we don't want to delete permanently the existing registration just yet.
2733
+			// remove relation to transaction for these registrations if NOT the existing registrations
2734
+			$registration->_remove_relations('Transaction');
2735
+			// delete permanently any related messages.
2736
+			$registration->delete_related_permanently('Message');
2737
+			// now delete this registration permanently
2738
+			$registration->delete_permanently();
2739
+		}
2740
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2741
+		// (the transaction and line items should be all that's left).
2742
+		// delete the line items related to the transaction for this registration.
2743
+		$TXN->delete_related_permanently('Line_Item');
2744
+		// we need to remove all the relationships on the transaction
2745
+		$TXN->delete_related_permanently('Payment');
2746
+		$TXN->delete_related_permanently('Extra_Meta');
2747
+		$TXN->delete_related_permanently('Message');
2748
+		// now we can delete this REG permanently (and the transaction of course)
2749
+		$REG->delete_related_permanently('Transaction');
2750
+		return $REG->delete_permanently();
2751
+	}
2752
+
2753
+
2754
+	/**
2755
+	 *    generates HTML for the Register New Attendee Admin page
2756
+	 *
2757
+	 * @throws DomainException
2758
+	 * @throws EE_Error
2759
+	 * @throws InvalidArgumentException
2760
+	 * @throws InvalidDataTypeException
2761
+	 * @throws InvalidInterfaceException
2762
+	 * @throws ReflectionException
2763
+	 */
2764
+	public function new_registration()
2765
+	{
2766
+		if (! $this->_set_reg_event()) {
2767
+			throw new EE_Error(
2768
+				esc_html__(
2769
+					'Unable to continue with registering because there is no Event ID in the request',
2770
+					'event_espresso'
2771
+				)
2772
+			);
2773
+		}
2774
+		/** @var CurrentPage $current_page */
2775
+		$current_page = $this->loader->getShared(CurrentPage::class);
2776
+		$current_page->setEspressoPage(true);
2777
+		// gotta start with a clean slate if we're not coming here via ajax
2778
+		if (
2779
+			! $this->request->isAjax()
2780
+			&& (
2781
+				! $this->request->requestParamIsSet('processing_registration')
2782
+				|| $this->request->requestParamIsSet('step_error')
2783
+			)
2784
+		) {
2785
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2786
+		}
2787
+		$this->_template_args['event_name'] = '';
2788
+		// event name
2789
+		if ($this->_reg_event) {
2790
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2791
+			$edit_event_url                     = self::add_query_args_and_nonce(
2792
+				[
2793
+					'action' => 'edit',
2794
+					'post'   => $this->_reg_event->ID(),
2795
+				],
2796
+				EVENTS_ADMIN_URL
2797
+			);
2798
+			$edit_event_lnk                     = '<a href="'
2799
+												  . $edit_event_url
2800
+												  . '" title="'
2801
+												  . esc_attr__('Edit ', 'event_espresso')
2802
+												  . $this->_reg_event->name()
2803
+												  . '">'
2804
+												  . esc_html__('Edit Event', 'event_espresso')
2805
+												  . '</a>';
2806
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2807
+												   . $edit_event_lnk
2808
+												   . '</span>';
2809
+		}
2810
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2811
+		if ($this->request->isAjax()) {
2812
+			$this->_return_json();
2813
+		}
2814
+		// grab header
2815
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2816
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2817
+			$template_path,
2818
+			$this->_template_args,
2819
+			true
2820
+		);
2821
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2822
+		// the details template wrapper
2823
+		$this->display_admin_page_with_sidebar();
2824
+	}
2825
+
2826
+
2827
+	/**
2828
+	 * This returns the content for a registration step
2829
+	 *
2830
+	 * @return string html
2831
+	 * @throws DomainException
2832
+	 * @throws EE_Error
2833
+	 * @throws InvalidArgumentException
2834
+	 * @throws InvalidDataTypeException
2835
+	 * @throws InvalidInterfaceException
2836
+	 * @throws ReflectionException
2837
+	 */
2838
+	protected function _get_registration_step_content()
2839
+	{
2840
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2841
+			$warning_msg = sprintf(
2842
+				esc_html__(
2843
+					'%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',
2844
+					'event_espresso'
2845
+				),
2846
+				'<br />',
2847
+				'<h3 class="important-notice">',
2848
+				'</h3>',
2849
+				'<div class="float-right">',
2850
+				'<span id="redirect_timer" class="important-notice">30</span>',
2851
+				'</div>',
2852
+				'<b>',
2853
+				'</b>'
2854
+			);
2855
+			return '
2856 2856
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2857 2857
 	<script >
2858 2858
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2865,840 +2865,840 @@  discard block
 block discarded – undo
2865 2865
 	        }
2866 2866
 	    }, 800 );
2867 2867
 	</script >';
2868
-        }
2869
-        $template_args = [
2870
-            'title'                    => '',
2871
-            'content'                  => '',
2872
-            'step_button_text'         => '',
2873
-            'show_notification_toggle' => false,
2874
-        ];
2875
-        // to indicate we're processing a new registration
2876
-        $hidden_fields = [
2877
-            'processing_registration' => [
2878
-                'type'  => 'hidden',
2879
-                'value' => 0,
2880
-            ],
2881
-            'event_id'                => [
2882
-                'type'  => 'hidden',
2883
-                'value' => $this->_reg_event->ID(),
2884
-            ],
2885
-        ];
2886
-        // if the cart is empty then we know we're at step one, so we'll display the ticket selector
2887
-        $cart = EE_Registry::instance()->SSN->cart();
2888
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2889
-        switch ($step) {
2890
-            case 'ticket':
2891
-                $hidden_fields['processing_registration']['value'] = 1;
2892
-                $template_args['title']                            = esc_html__(
2893
-                    'Step One: Select the Ticket for this registration',
2894
-                    'event_espresso'
2895
-                );
2896
-                $template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2897
-                $template_args['content'] .= '</div>';
2898
-                $template_args['step_button_text'] = esc_html__(
2899
-                    'Add Tickets and Continue to Registrant Details',
2900
-                    'event_espresso'
2901
-                );
2902
-                $template_args['show_notification_toggle']         = false;
2903
-                break;
2904
-            case 'questions':
2905
-                $hidden_fields['processing_registration']['value'] = 2;
2906
-                $template_args['title']                            = esc_html__(
2907
-                    'Step Two: Add Registrant Details for this Registration',
2908
-                    'event_espresso'
2909
-                );
2910
-                // in theory, we should be able to run EED_SPCO at this point
2911
-                // because the cart should have been set up properly by the first process_reg_step run.
2912
-                $template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2913
-                $template_args['step_button_text'] = esc_html__(
2914
-                    'Save Registration and Continue to Details',
2915
-                    'event_espresso'
2916
-                );
2917
-                $template_args['show_notification_toggle'] = true;
2918
-                break;
2919
-        }
2920
-        // we come back to the process_registration_step route.
2921
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2922
-        return EEH_Template::display_template(
2923
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2924
-            $template_args,
2925
-            true
2926
-        );
2927
-    }
2928
-
2929
-
2930
-    /**
2931
-     * set_reg_event
2932
-     *
2933
-     * @return bool
2934
-     * @throws EE_Error
2935
-     * @throws InvalidArgumentException
2936
-     * @throws InvalidDataTypeException
2937
-     * @throws InvalidInterfaceException
2938
-     */
2939
-    private function _set_reg_event()
2940
-    {
2941
-        if (is_object($this->_reg_event)) {
2942
-            return true;
2943
-        }
2944
-
2945
-        $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2946
-        if (! $EVT_ID) {
2947
-            return false;
2948
-        }
2949
-        $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2950
-        return true;
2951
-    }
2952
-
2953
-
2954
-    /**
2955
-     * process_reg_step
2956
-     *
2957
-     * @return void
2958
-     * @throws DomainException
2959
-     * @throws EE_Error
2960
-     * @throws InvalidArgumentException
2961
-     * @throws InvalidDataTypeException
2962
-     * @throws InvalidInterfaceException
2963
-     * @throws ReflectionException
2964
-     * @throws RuntimeException
2965
-     */
2966
-    public function process_reg_step()
2967
-    {
2968
-        EE_System::do_not_cache();
2969
-        $this->_set_reg_event();
2970
-        /** @var CurrentPage $current_page */
2971
-        $current_page = $this->loader->getShared(CurrentPage::class);
2972
-        $current_page->setEspressoPage(true);
2973
-        $this->request->setRequestParam('uts', time());
2974
-        // what step are we on?
2975
-        $cart = EE_Registry::instance()->SSN->cart();
2976
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2977
-        // if doing ajax then we need to verify the nonce
2978
-        if ($this->request->isAjax()) {
2979
-            $nonce = $this->request->getRequestParam($this->_req_nonce, '');
2980
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2981
-        }
2982
-        switch ($step) {
2983
-            case 'ticket':
2984
-                // process ticket selection
2985
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2986
-                if ($success) {
2987
-                    EE_Error::add_success(
2988
-                        esc_html__(
2989
-                            'Tickets Selected. Now complete the registration.',
2990
-                            'event_espresso'
2991
-                        )
2992
-                    );
2993
-                } else {
2994
-                    $this->request->setRequestParam('step_error', true);
2995
-                    $query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
2996
-                }
2997
-                if ($this->request->isAjax()) {
2998
-                    $this->new_registration(); // display next step
2999
-                } else {
3000
-                    $query_args = [
3001
-                        'action'                  => 'new_registration',
3002
-                        'processing_registration' => 1,
3003
-                        'event_id'                => $this->_reg_event->ID(),
3004
-                        'uts'                     => time(),
3005
-                    ];
3006
-                    $this->_redirect_after_action(
3007
-                        false,
3008
-                        '',
3009
-                        '',
3010
-                        $query_args,
3011
-                        true
3012
-                    );
3013
-                }
3014
-                break;
3015
-            case 'questions':
3016
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3017
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3018
-                }
3019
-                // process registration
3020
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3021
-                if ($cart instanceof EE_Cart) {
3022
-                    $grand_total = $cart->get_grand_total();
3023
-                    if ($grand_total instanceof EE_Line_Item) {
3024
-                        $grand_total->save_this_and_descendants_to_txn();
3025
-                    }
3026
-                }
3027
-                if (! $transaction instanceof EE_Transaction) {
3028
-                    $query_args = [
3029
-                        'action'                  => 'new_registration',
3030
-                        'processing_registration' => 2,
3031
-                        'event_id'                => $this->_reg_event->ID(),
3032
-                        'uts'                     => time(),
3033
-                    ];
3034
-                    if ($this->request->isAjax()) {
3035
-                        // display registration form again because there are errors (maybe validation?)
3036
-                        $this->new_registration();
3037
-                        return;
3038
-                    }
3039
-                    $this->_redirect_after_action(
3040
-                        false,
3041
-                        '',
3042
-                        '',
3043
-                        $query_args,
3044
-                        true
3045
-                    );
3046
-                    return;
3047
-                }
3048
-                // maybe update status, and make sure to save transaction if not done already
3049
-                if (! $transaction->update_status_based_on_total_paid()) {
3050
-                    $transaction->save();
3051
-                }
3052
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3053
-                $query_args = [
3054
-                    'action'        => 'redirect_to_txn',
3055
-                    'TXN_ID'        => $transaction->ID(),
3056
-                    'EVT_ID'        => $this->_reg_event->ID(),
3057
-                    'event_name'    => urlencode($this->_reg_event->name()),
3058
-                    'redirect_from' => 'new_registration',
3059
-                ];
3060
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3061
-                break;
3062
-        }
3063
-        // what are you looking here for?  Should be nothing to do at this point.
3064
-    }
3065
-
3066
-
3067
-    /**
3068
-     * redirect_to_txn
3069
-     *
3070
-     * @return void
3071
-     * @throws EE_Error
3072
-     * @throws InvalidArgumentException
3073
-     * @throws InvalidDataTypeException
3074
-     * @throws InvalidInterfaceException
3075
-     * @throws ReflectionException
3076
-     */
3077
-    public function redirect_to_txn()
3078
-    {
3079
-        EE_System::do_not_cache();
3080
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3081
-        $query_args = [
3082
-            'action' => 'view_transaction',
3083
-            'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3084
-            'page'   => 'espresso_transactions',
3085
-        ];
3086
-        if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3087
-            $query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3088
-            $query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3089
-            $query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3090
-        }
3091
-        EE_Error::add_success(
3092
-            esc_html__(
3093
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3094
-                'event_espresso'
3095
-            )
3096
-        );
3097
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3098
-    }
3099
-
3100
-
3101
-    /**
3102
-     * generates HTML for the Attendee Contact List
3103
-     *
3104
-     * @return void
3105
-     * @throws DomainException
3106
-     * @throws EE_Error
3107
-     */
3108
-    protected function _attendee_contact_list_table()
3109
-    {
3110
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3111
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3112
-        $this->display_admin_list_table_page_with_no_sidebar();
3113
-    }
3114
-
3115
-
3116
-    /**
3117
-     * get_attendees
3118
-     *
3119
-     * @param      $per_page
3120
-     * @param bool $count whether to return count or data.
3121
-     * @param bool $trash
3122
-     * @return array|int
3123
-     * @throws EE_Error
3124
-     * @throws InvalidArgumentException
3125
-     * @throws InvalidDataTypeException
3126
-     * @throws InvalidInterfaceException
3127
-     */
3128
-    public function get_attendees($per_page, $count = false, $trash = false)
3129
-    {
3130
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3131
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3132
-        $orderby = $this->request->getRequestParam('orderby');
3133
-        switch ($orderby) {
3134
-            case 'ATT_ID':
3135
-            case 'ATT_fname':
3136
-            case 'ATT_email':
3137
-            case 'ATT_city':
3138
-            case 'STA_ID':
3139
-            case 'CNT_ID':
3140
-                break;
3141
-            case 'Registration_Count':
3142
-                $orderby = 'Registration_Count';
3143
-                break;
3144
-            default:
3145
-                $orderby = 'ATT_lname';
3146
-        }
3147
-        $sort         = $this->request->getRequestParam('order', 'ASC');
3148
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
3149
-        $per_page     = absint($per_page) ? $per_page : 10;
3150
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3151
-        $_where       = [];
3152
-        $search_term  = $this->request->getRequestParam('s');
3153
-        if ($search_term) {
3154
-            $search_term  = '%' . $search_term . '%';
3155
-            $_where['OR'] = [
3156
-                'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3157
-                'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3158
-                'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3159
-                'ATT_fname'                         => ['LIKE', $search_term],
3160
-                'ATT_lname'                         => ['LIKE', $search_term],
3161
-                'ATT_short_bio'                     => ['LIKE', $search_term],
3162
-                'ATT_email'                         => ['LIKE', $search_term],
3163
-                'ATT_address'                       => ['LIKE', $search_term],
3164
-                'ATT_address2'                      => ['LIKE', $search_term],
3165
-                'ATT_city'                          => ['LIKE', $search_term],
3166
-                'Country.CNT_name'                  => ['LIKE', $search_term],
3167
-                'State.STA_name'                    => ['LIKE', $search_term],
3168
-                'ATT_phone'                         => ['LIKE', $search_term],
3169
-                'Registration.REG_final_price'      => ['LIKE', $search_term],
3170
-                'Registration.REG_code'             => ['LIKE', $search_term],
3171
-                'Registration.REG_group_size'       => ['LIKE', $search_term],
3172
-            ];
3173
-        }
3174
-        $offset     = ($current_page - 1) * $per_page;
3175
-        $limit      = $count ? null : [$offset, $per_page];
3176
-        $query_args = [
3177
-            $_where,
3178
-            'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3179
-            'limit'         => $limit,
3180
-        ];
3181
-        if (! $count) {
3182
-            $query_args['order_by'] = [$orderby => $sort];
3183
-        }
3184
-        $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3185
-        return $count
3186
-            ? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3187
-            : $this->getAttendeeModel()->get_all($query_args);
3188
-    }
3189
-
3190
-
3191
-    /**
3192
-     * This is just taking care of resending the registration confirmation
3193
-     *
3194
-     * @return void
3195
-     * @throws EE_Error
3196
-     * @throws InvalidArgumentException
3197
-     * @throws InvalidDataTypeException
3198
-     * @throws InvalidInterfaceException
3199
-     * @throws ReflectionException
3200
-     */
3201
-    protected function _resend_registration()
3202
-    {
3203
-        $this->_process_resend_registration();
3204
-        $REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3205
-        $redirect_to = $this->request->getRequestParam('redirect_to');
3206
-        $query_args  = $redirect_to
3207
-            ? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3208
-            : ['action' => 'default'];
3209
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3210
-    }
3211
-
3212
-
3213
-    /**
3214
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3215
-     * to use when selecting registrations
3216
-     *
3217
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3218
-     *                                                     the query parameters from the request
3219
-     * @return void ends the request with a redirect or download
3220
-     */
3221
-    public function _registrations_report_base($method_name_for_getting_query_params)
3222
-    {
3223
-        $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3224
-            ? $this->request->getRequestParam('EVT_ID', 0, DataType::INT)
3225
-            : null;
3226
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3227
-            $return_url = $this->request->getRequestParam('return_url', '', DataType::URL);
3228
-            $filters = $this->request->getRequestParam('filters', [], DataType::STRING, true);
3229
-            $use_filters = $this->request->getRequestParam('use_filters', false, DataType::BOOL);
3230
-            wp_redirect(
3231
-                EE_Admin_Page::add_query_args_and_nonce(
3232
-                    [
3233
-                        'page'        => EED_Batch::PAGE_SLUG,
2868
+		}
2869
+		$template_args = [
2870
+			'title'                    => '',
2871
+			'content'                  => '',
2872
+			'step_button_text'         => '',
2873
+			'show_notification_toggle' => false,
2874
+		];
2875
+		// to indicate we're processing a new registration
2876
+		$hidden_fields = [
2877
+			'processing_registration' => [
2878
+				'type'  => 'hidden',
2879
+				'value' => 0,
2880
+			],
2881
+			'event_id'                => [
2882
+				'type'  => 'hidden',
2883
+				'value' => $this->_reg_event->ID(),
2884
+			],
2885
+		];
2886
+		// if the cart is empty then we know we're at step one, so we'll display the ticket selector
2887
+		$cart = EE_Registry::instance()->SSN->cart();
2888
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2889
+		switch ($step) {
2890
+			case 'ticket':
2891
+				$hidden_fields['processing_registration']['value'] = 1;
2892
+				$template_args['title']                            = esc_html__(
2893
+					'Step One: Select the Ticket for this registration',
2894
+					'event_espresso'
2895
+				);
2896
+				$template_args['content'] = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2897
+				$template_args['content'] .= '</div>';
2898
+				$template_args['step_button_text'] = esc_html__(
2899
+					'Add Tickets and Continue to Registrant Details',
2900
+					'event_espresso'
2901
+				);
2902
+				$template_args['show_notification_toggle']         = false;
2903
+				break;
2904
+			case 'questions':
2905
+				$hidden_fields['processing_registration']['value'] = 2;
2906
+				$template_args['title']                            = esc_html__(
2907
+					'Step Two: Add Registrant Details for this Registration',
2908
+					'event_espresso'
2909
+				);
2910
+				// in theory, we should be able to run EED_SPCO at this point
2911
+				// because the cart should have been set up properly by the first process_reg_step run.
2912
+				$template_args['content'] = EED_Single_Page_Checkout::registration_checkout_for_admin();
2913
+				$template_args['step_button_text'] = esc_html__(
2914
+					'Save Registration and Continue to Details',
2915
+					'event_espresso'
2916
+				);
2917
+				$template_args['show_notification_toggle'] = true;
2918
+				break;
2919
+		}
2920
+		// we come back to the process_registration_step route.
2921
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2922
+		return EEH_Template::display_template(
2923
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2924
+			$template_args,
2925
+			true
2926
+		);
2927
+	}
2928
+
2929
+
2930
+	/**
2931
+	 * set_reg_event
2932
+	 *
2933
+	 * @return bool
2934
+	 * @throws EE_Error
2935
+	 * @throws InvalidArgumentException
2936
+	 * @throws InvalidDataTypeException
2937
+	 * @throws InvalidInterfaceException
2938
+	 */
2939
+	private function _set_reg_event()
2940
+	{
2941
+		if (is_object($this->_reg_event)) {
2942
+			return true;
2943
+		}
2944
+
2945
+		$EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2946
+		if (! $EVT_ID) {
2947
+			return false;
2948
+		}
2949
+		$this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
2950
+		return true;
2951
+	}
2952
+
2953
+
2954
+	/**
2955
+	 * process_reg_step
2956
+	 *
2957
+	 * @return void
2958
+	 * @throws DomainException
2959
+	 * @throws EE_Error
2960
+	 * @throws InvalidArgumentException
2961
+	 * @throws InvalidDataTypeException
2962
+	 * @throws InvalidInterfaceException
2963
+	 * @throws ReflectionException
2964
+	 * @throws RuntimeException
2965
+	 */
2966
+	public function process_reg_step()
2967
+	{
2968
+		EE_System::do_not_cache();
2969
+		$this->_set_reg_event();
2970
+		/** @var CurrentPage $current_page */
2971
+		$current_page = $this->loader->getShared(CurrentPage::class);
2972
+		$current_page->setEspressoPage(true);
2973
+		$this->request->setRequestParam('uts', time());
2974
+		// what step are we on?
2975
+		$cart = EE_Registry::instance()->SSN->cart();
2976
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2977
+		// if doing ajax then we need to verify the nonce
2978
+		if ($this->request->isAjax()) {
2979
+			$nonce = $this->request->getRequestParam($this->_req_nonce, '');
2980
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2981
+		}
2982
+		switch ($step) {
2983
+			case 'ticket':
2984
+				// process ticket selection
2985
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2986
+				if ($success) {
2987
+					EE_Error::add_success(
2988
+						esc_html__(
2989
+							'Tickets Selected. Now complete the registration.',
2990
+							'event_espresso'
2991
+						)
2992
+					);
2993
+				} else {
2994
+					$this->request->setRequestParam('step_error', true);
2995
+					$query_args['step_error'] = $this->request->getRequestParam('step_error', true, 'bool');
2996
+				}
2997
+				if ($this->request->isAjax()) {
2998
+					$this->new_registration(); // display next step
2999
+				} else {
3000
+					$query_args = [
3001
+						'action'                  => 'new_registration',
3002
+						'processing_registration' => 1,
3003
+						'event_id'                => $this->_reg_event->ID(),
3004
+						'uts'                     => time(),
3005
+					];
3006
+					$this->_redirect_after_action(
3007
+						false,
3008
+						'',
3009
+						'',
3010
+						$query_args,
3011
+						true
3012
+					);
3013
+				}
3014
+				break;
3015
+			case 'questions':
3016
+				if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3017
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3018
+				}
3019
+				// process registration
3020
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3021
+				if ($cart instanceof EE_Cart) {
3022
+					$grand_total = $cart->get_grand_total();
3023
+					if ($grand_total instanceof EE_Line_Item) {
3024
+						$grand_total->save_this_and_descendants_to_txn();
3025
+					}
3026
+				}
3027
+				if (! $transaction instanceof EE_Transaction) {
3028
+					$query_args = [
3029
+						'action'                  => 'new_registration',
3030
+						'processing_registration' => 2,
3031
+						'event_id'                => $this->_reg_event->ID(),
3032
+						'uts'                     => time(),
3033
+					];
3034
+					if ($this->request->isAjax()) {
3035
+						// display registration form again because there are errors (maybe validation?)
3036
+						$this->new_registration();
3037
+						return;
3038
+					}
3039
+					$this->_redirect_after_action(
3040
+						false,
3041
+						'',
3042
+						'',
3043
+						$query_args,
3044
+						true
3045
+					);
3046
+					return;
3047
+				}
3048
+				// maybe update status, and make sure to save transaction if not done already
3049
+				if (! $transaction->update_status_based_on_total_paid()) {
3050
+					$transaction->save();
3051
+				}
3052
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3053
+				$query_args = [
3054
+					'action'        => 'redirect_to_txn',
3055
+					'TXN_ID'        => $transaction->ID(),
3056
+					'EVT_ID'        => $this->_reg_event->ID(),
3057
+					'event_name'    => urlencode($this->_reg_event->name()),
3058
+					'redirect_from' => 'new_registration',
3059
+				];
3060
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3061
+				break;
3062
+		}
3063
+		// what are you looking here for?  Should be nothing to do at this point.
3064
+	}
3065
+
3066
+
3067
+	/**
3068
+	 * redirect_to_txn
3069
+	 *
3070
+	 * @return void
3071
+	 * @throws EE_Error
3072
+	 * @throws InvalidArgumentException
3073
+	 * @throws InvalidDataTypeException
3074
+	 * @throws InvalidInterfaceException
3075
+	 * @throws ReflectionException
3076
+	 */
3077
+	public function redirect_to_txn()
3078
+	{
3079
+		EE_System::do_not_cache();
3080
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3081
+		$query_args = [
3082
+			'action' => 'view_transaction',
3083
+			'TXN_ID' => $this->request->getRequestParam('TXN_ID', 0, 'int'),
3084
+			'page'   => 'espresso_transactions',
3085
+		];
3086
+		if ($this->request->requestParamIsSet('EVT_ID') && $this->request->requestParamIsSet('redirect_from')) {
3087
+			$query_args['EVT_ID']        = $this->request->getRequestParam('EVT_ID', 0, 'int');
3088
+			$query_args['event_name']    = urlencode($this->request->getRequestParam('event_name'));
3089
+			$query_args['redirect_from'] = $this->request->getRequestParam('redirect_from');
3090
+		}
3091
+		EE_Error::add_success(
3092
+			esc_html__(
3093
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3094
+				'event_espresso'
3095
+			)
3096
+		);
3097
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3098
+	}
3099
+
3100
+
3101
+	/**
3102
+	 * generates HTML for the Attendee Contact List
3103
+	 *
3104
+	 * @return void
3105
+	 * @throws DomainException
3106
+	 * @throws EE_Error
3107
+	 */
3108
+	protected function _attendee_contact_list_table()
3109
+	{
3110
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3111
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3112
+		$this->display_admin_list_table_page_with_no_sidebar();
3113
+	}
3114
+
3115
+
3116
+	/**
3117
+	 * get_attendees
3118
+	 *
3119
+	 * @param      $per_page
3120
+	 * @param bool $count whether to return count or data.
3121
+	 * @param bool $trash
3122
+	 * @return array|int
3123
+	 * @throws EE_Error
3124
+	 * @throws InvalidArgumentException
3125
+	 * @throws InvalidDataTypeException
3126
+	 * @throws InvalidInterfaceException
3127
+	 */
3128
+	public function get_attendees($per_page, $count = false, $trash = false)
3129
+	{
3130
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3131
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3132
+		$orderby = $this->request->getRequestParam('orderby');
3133
+		switch ($orderby) {
3134
+			case 'ATT_ID':
3135
+			case 'ATT_fname':
3136
+			case 'ATT_email':
3137
+			case 'ATT_city':
3138
+			case 'STA_ID':
3139
+			case 'CNT_ID':
3140
+				break;
3141
+			case 'Registration_Count':
3142
+				$orderby = 'Registration_Count';
3143
+				break;
3144
+			default:
3145
+				$orderby = 'ATT_lname';
3146
+		}
3147
+		$sort         = $this->request->getRequestParam('order', 'ASC');
3148
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
3149
+		$per_page     = absint($per_page) ? $per_page : 10;
3150
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
3151
+		$_where       = [];
3152
+		$search_term  = $this->request->getRequestParam('s');
3153
+		if ($search_term) {
3154
+			$search_term  = '%' . $search_term . '%';
3155
+			$_where['OR'] = [
3156
+				'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3157
+				'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
3158
+				'Registration.Event.EVT_short_desc' => ['LIKE', $search_term],
3159
+				'ATT_fname'                         => ['LIKE', $search_term],
3160
+				'ATT_lname'                         => ['LIKE', $search_term],
3161
+				'ATT_short_bio'                     => ['LIKE', $search_term],
3162
+				'ATT_email'                         => ['LIKE', $search_term],
3163
+				'ATT_address'                       => ['LIKE', $search_term],
3164
+				'ATT_address2'                      => ['LIKE', $search_term],
3165
+				'ATT_city'                          => ['LIKE', $search_term],
3166
+				'Country.CNT_name'                  => ['LIKE', $search_term],
3167
+				'State.STA_name'                    => ['LIKE', $search_term],
3168
+				'ATT_phone'                         => ['LIKE', $search_term],
3169
+				'Registration.REG_final_price'      => ['LIKE', $search_term],
3170
+				'Registration.REG_code'             => ['LIKE', $search_term],
3171
+				'Registration.REG_group_size'       => ['LIKE', $search_term],
3172
+			];
3173
+		}
3174
+		$offset     = ($current_page - 1) * $per_page;
3175
+		$limit      = $count ? null : [$offset, $per_page];
3176
+		$query_args = [
3177
+			$_where,
3178
+			'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3179
+			'limit'         => $limit,
3180
+		];
3181
+		if (! $count) {
3182
+			$query_args['order_by'] = [$orderby => $sort];
3183
+		}
3184
+		$query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
3185
+		return $count
3186
+			? $this->getAttendeeModel()->count($query_args, 'ATT_ID', true)
3187
+			: $this->getAttendeeModel()->get_all($query_args);
3188
+	}
3189
+
3190
+
3191
+	/**
3192
+	 * This is just taking care of resending the registration confirmation
3193
+	 *
3194
+	 * @return void
3195
+	 * @throws EE_Error
3196
+	 * @throws InvalidArgumentException
3197
+	 * @throws InvalidDataTypeException
3198
+	 * @throws InvalidInterfaceException
3199
+	 * @throws ReflectionException
3200
+	 */
3201
+	protected function _resend_registration()
3202
+	{
3203
+		$this->_process_resend_registration();
3204
+		$REG_ID      = $this->request->getRequestParam('_REG_ID', 0, 'int');
3205
+		$redirect_to = $this->request->getRequestParam('redirect_to');
3206
+		$query_args  = $redirect_to
3207
+			? ['action' => $redirect_to, '_REG_ID' => $REG_ID]
3208
+			: ['action' => 'default'];
3209
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3210
+	}
3211
+
3212
+
3213
+	/**
3214
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3215
+	 * to use when selecting registrations
3216
+	 *
3217
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3218
+	 *                                                     the query parameters from the request
3219
+	 * @return void ends the request with a redirect or download
3220
+	 */
3221
+	public function _registrations_report_base($method_name_for_getting_query_params)
3222
+	{
3223
+		$EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3224
+			? $this->request->getRequestParam('EVT_ID', 0, DataType::INT)
3225
+			: null;
3226
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3227
+			$return_url = $this->request->getRequestParam('return_url', '', DataType::URL);
3228
+			$filters = $this->request->getRequestParam('filters', [], DataType::STRING, true);
3229
+			$use_filters = $this->request->getRequestParam('use_filters', false, DataType::BOOL);
3230
+			wp_redirect(
3231
+				EE_Admin_Page::add_query_args_and_nonce(
3232
+					[
3233
+						'page'        => EED_Batch::PAGE_SLUG,
3234 3234
 						'batch' 	  => EED_Batch::batch_file_job,
3235
-                        'EVT_ID'      => $EVT_ID,
3236
-                        'filters'     => urlencode(serialize($this->$method_name_for_getting_query_params($filters))),
3237
-                        'use_filters' => urlencode($use_filters),
3238
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3239
-                        'return_url'  => urlencode($return_url),
3240
-                    ]
3241
-                )
3242
-            );
3243
-        } else {
3244
-            // Pull the current request params
3245
-            $request_args = $this->request->requestParams();
3246
-            // Set the required request_args to be passed to the export
3247
-            $required_request_args = [
3248
-                'export' => 'report',
3249
-                'action' => 'registrations_report_for_event',
3250
-                'EVT_ID' => $EVT_ID,
3251
-            ];
3252
-            // Merge required request args, overriding any currently set
3253
-            $request_args = array_merge($request_args, $required_request_args);
3254
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3255
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3256
-                $EE_Export = EE_Export::instance($request_args);
3257
-                $EE_Export->export();
3258
-            }
3259
-        }
3260
-    }
3261
-
3262
-
3263
-    /**
3264
-     * Creates a registration report using only query parameters in the request
3265
-     *
3266
-     * @return void
3267
-     */
3268
-    public function _registrations_report()
3269
-    {
3270
-        $this->_registrations_report_base('_get_registration_query_parameters');
3271
-    }
3272
-
3273
-
3274
-    public function _contact_list_export()
3275
-    {
3276
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3277
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3278
-            $EE_Export = EE_Export::instance($this->request->requestParams());
3279
-            $EE_Export->export_attendees();
3280
-        }
3281
-    }
3282
-
3283
-
3284
-    public function _contact_list_report()
3285
-    {
3286
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3287
-            wp_redirect(
3288
-                EE_Admin_Page::add_query_args_and_nonce(
3289
-                    [
3290
-                        'page'        => EED_Batch::PAGE_SLUG,
3291
-                        'batch'       => EED_Batch::batch_file_job,
3292
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3293
-                        'return_url'  => urlencode($this->request->getRequestParam('return_url', '', DataType::URL)),
3294
-                    ]
3295
-                )
3296
-            );
3297
-        } else {
3298
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3299
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3300
-                $EE_Export = EE_Export::instance($this->request->requestParams());
3301
-                $EE_Export->report_attendees();
3302
-            }
3303
-        }
3304
-    }
3305
-
3306
-
3307
-
3308
-
3309
-
3310
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3311
-    /**
3312
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3313
-     *
3314
-     * @return void
3315
-     * @throws EE_Error
3316
-     * @throws InvalidArgumentException
3317
-     * @throws InvalidDataTypeException
3318
-     * @throws InvalidInterfaceException
3319
-     * @throws ReflectionException
3320
-     */
3321
-    protected function _duplicate_attendee()
3322
-    {
3323
-        $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3324
-        $action = $this->request->getRequestParam('return', 'default');
3325
-        // verify we have necessary info
3326
-        if (! $REG_ID) {
3327
-            EE_Error::add_error(
3328
-                esc_html__(
3329
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3330
-                    'event_espresso'
3331
-                ),
3332
-                __FILE__,
3333
-                __LINE__,
3334
-                __FUNCTION__
3335
-            );
3336
-            $query_args = ['action' => $action];
3337
-            $this->_redirect_after_action('', '', '', $query_args, true);
3338
-        }
3339
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3340
-        $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3341
-        if (! $registration instanceof EE_Registration) {
3342
-            throw new RuntimeException(
3343
-                sprintf(
3344
-                    esc_html__(
3345
-                        'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3346
-                        'event_espresso'
3347
-                    ),
3348
-                    $REG_ID
3349
-                )
3350
-            );
3351
-        }
3352
-        $attendee = $registration->attendee();
3353
-        // remove relation of existing attendee on registration
3354
-        $registration->_remove_relation_to($attendee, 'Attendee');
3355
-        // new attendee
3356
-        $new_attendee = clone $attendee;
3357
-        $new_attendee->set('ATT_ID', 0);
3358
-        $new_attendee->save();
3359
-        // add new attendee to reg
3360
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3361
-        EE_Error::add_success(
3362
-            esc_html__(
3363
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3364
-                'event_espresso'
3365
-            )
3366
-        );
3367
-        // redirect to edit page for attendee
3368
-        $query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3369
-        $this->_redirect_after_action('', '', '', $query_args, true);
3370
-    }
3371
-
3372
-
3373
-    /**
3374
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3375
-     *
3376
-     * @param int     $post_id
3377
-     * @param WP_Post $post
3378
-     * @throws DomainException
3379
-     * @throws EE_Error
3380
-     * @throws InvalidArgumentException
3381
-     * @throws InvalidDataTypeException
3382
-     * @throws InvalidInterfaceException
3383
-     * @throws LogicException
3384
-     * @throws InvalidFormSubmissionException
3385
-     * @throws ReflectionException
3386
-     */
3387
-    protected function _insert_update_cpt_item($post_id, $post)
3388
-    {
3389
-        $success  = true;
3390
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3391
-            ? $this->getAttendeeModel()->get_one_by_ID($post_id)
3392
-            : null;
3393
-        // for attendee updates
3394
-        if ($attendee instanceof EE_Attendee) {
3395
-            // note we should only be UPDATING attendees at this point.
3396
-            $fname          = $this->request->getRequestParam('ATT_fname', '');
3397
-            $lname          = $this->request->getRequestParam('ATT_lname', '');
3398
-            $updated_fields = [
3399
-                'ATT_fname'     => $fname,
3400
-                'ATT_lname'     => $lname,
3401
-                'ATT_full_name' => "{$fname} {$lname}",
3402
-                'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3403
-                'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3404
-                'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3405
-                'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3406
-                'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3407
-                'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3408
-            ];
3409
-            foreach ($updated_fields as $field => $value) {
3410
-                $attendee->set($field, $value);
3411
-            }
3412
-
3413
-            // process contact details metabox form handler (which will also save the attendee)
3414
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3415
-            $success              = $contact_details_form->process($this->request->requestParams());
3416
-
3417
-            $attendee_update_callbacks = apply_filters(
3418
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3419
-                []
3420
-            );
3421
-            foreach ($attendee_update_callbacks as $a_callback) {
3422
-                if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3423
-                    throw new EE_Error(
3424
-                        sprintf(
3425
-                            esc_html__(
3426
-                                '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.',
3427
-                                'event_espresso'
3428
-                            ),
3429
-                            $a_callback
3430
-                        )
3431
-                    );
3432
-                }
3433
-            }
3434
-        }
3435
-
3436
-        if ($success === false) {
3437
-            EE_Error::add_error(
3438
-                esc_html__(
3439
-                    'Something went wrong with updating the meta table data for the registration.',
3440
-                    'event_espresso'
3441
-                ),
3442
-                __FILE__,
3443
-                __FUNCTION__,
3444
-                __LINE__
3445
-            );
3446
-        }
3447
-    }
3448
-
3449
-
3450
-    public function trash_cpt_item($post_id)
3451
-    {
3452
-    }
3453
-
3454
-
3455
-    public function delete_cpt_item($post_id)
3456
-    {
3457
-    }
3458
-
3459
-
3460
-    public function restore_cpt_item($post_id)
3461
-    {
3462
-    }
3463
-
3464
-
3465
-    protected function _restore_cpt_item($post_id, $revision_id)
3466
-    {
3467
-    }
3468
-
3469
-
3470
-    /**
3471
-     * @throws EE_Error
3472
-     * @throws ReflectionException
3473
-     * @since 4.10.2.p
3474
-     */
3475
-    public function attendee_editor_metaboxes()
3476
-    {
3477
-        $this->verify_cpt_object();
3478
-        remove_meta_box(
3479
-            'postexcerpt',
3480
-            $this->_cpt_routes[ $this->_req_action ],
3481
-            'normal'
3482
-        );
3483
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3484
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3485
-            $this->addMetaBox(
3486
-                'postexcerpt',
3487
-                esc_html__('Short Biography', 'event_espresso'),
3488
-                'post_excerpt_meta_box',
3489
-                $this->_cpt_routes[ $this->_req_action ]
3490
-            );
3491
-        }
3492
-        if (post_type_supports('espresso_attendees', 'comments')) {
3493
-            $this->addMetaBox(
3494
-                'commentsdiv',
3495
-                esc_html__('Notes on the Contact', 'event_espresso'),
3496
-                'post_comment_meta_box',
3497
-                $this->_cpt_routes[ $this->_req_action ],
3498
-                'normal',
3499
-                'core'
3500
-            );
3501
-        }
3502
-        $this->addMetaBox(
3503
-            'attendee_contact_info',
3504
-            esc_html__('Contact Info', 'event_espresso'),
3505
-            [$this, 'attendee_contact_info'],
3506
-            $this->_cpt_routes[ $this->_req_action ],
3507
-            'side',
3508
-            'core'
3509
-        );
3510
-        $this->addMetaBox(
3511
-            'attendee_details_address',
3512
-            esc_html__('Address Details', 'event_espresso'),
3513
-            [$this, 'attendee_address_details'],
3514
-            $this->_cpt_routes[ $this->_req_action ],
3515
-            'normal',
3516
-            'core'
3517
-        );
3518
-        $this->addMetaBox(
3519
-            'attendee_registrations',
3520
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3521
-            [$this, 'attendee_registrations_meta_box'],
3522
-            $this->_cpt_routes[ $this->_req_action ]
3523
-        );
3524
-    }
3525
-
3526
-
3527
-    /**
3528
-     * Metabox for attendee contact info
3529
-     *
3530
-     * @param WP_Post $post wp post object
3531
-     * @return void attendee contact info ( and form )
3532
-     * @throws EE_Error
3533
-     * @throws InvalidArgumentException
3534
-     * @throws InvalidDataTypeException
3535
-     * @throws InvalidInterfaceException
3536
-     * @throws LogicException
3537
-     * @throws DomainException
3538
-     */
3539
-    public function attendee_contact_info($post)
3540
-    {
3541
-        // get attendee object ( should already have it )
3542
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3543
-        $form->enqueueStylesAndScripts();
3544
-        echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3545
-    }
3546
-
3547
-
3548
-    /**
3549
-     * Return form handler for the contact details metabox
3550
-     *
3551
-     * @param EE_Attendee $attendee
3552
-     * @return AttendeeContactDetailsMetaboxFormHandler
3553
-     * @throws DomainException
3554
-     * @throws InvalidArgumentException
3555
-     * @throws InvalidDataTypeException
3556
-     * @throws InvalidInterfaceException
3557
-     */
3558
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3559
-    {
3560
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3561
-    }
3562
-
3563
-
3564
-    /**
3565
-     * Metabox for attendee details
3566
-     *
3567
-     * @param WP_Post $post wp post object
3568
-     * @throws EE_Error
3569
-     * @throws ReflectionException
3570
-     */
3571
-    public function attendee_address_details($post)
3572
-    {
3573
-        // get attendee object (should already have it)
3574
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
3575
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3576
-            new EE_Question_Form_Input(
3577
-                EE_Question::new_instance(
3578
-                    [
3579
-                        'QST_ID'           => 0,
3580
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3581
-                        'QST_system'       => 'admin-state',
3582
-                    ]
3583
-                ),
3584
-                EE_Answer::new_instance(
3585
-                    [
3586
-                        'ANS_ID'    => 0,
3587
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3588
-                    ]
3589
-                ),
3590
-                [
3591
-                    'input_id'       => 'STA_ID',
3592
-                    'input_name'     => 'STA_ID',
3593
-                    'input_prefix'   => '',
3594
-                    'append_qstn_id' => false,
3595
-                ]
3596
-            )
3597
-        );
3598
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3599
-            new EE_Question_Form_Input(
3600
-                EE_Question::new_instance(
3601
-                    [
3602
-                        'QST_ID'           => 0,
3603
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3604
-                        'QST_system'       => 'admin-country',
3605
-                    ]
3606
-                ),
3607
-                EE_Answer::new_instance(
3608
-                    [
3609
-                        'ANS_ID'    => 0,
3610
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3611
-                    ]
3612
-                ),
3613
-                [
3614
-                    'input_id'       => 'CNT_ISO',
3615
-                    'input_name'     => 'CNT_ISO',
3616
-                    'input_prefix'   => '',
3617
-                    'append_qstn_id' => false,
3618
-                ]
3619
-            )
3620
-        );
3621
-        $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3622
-        EEH_Template::display_template($template, $this->_template_args);
3623
-    }
3624
-
3625
-
3626
-    /**
3627
-     * _attendee_details
3628
-     *
3629
-     * @param $post
3630
-     * @return void
3631
-     * @throws DomainException
3632
-     * @throws EE_Error
3633
-     * @throws InvalidArgumentException
3634
-     * @throws InvalidDataTypeException
3635
-     * @throws InvalidInterfaceException
3636
-     * @throws ReflectionException
3637
-     */
3638
-    public function attendee_registrations_meta_box($post)
3639
-    {
3640
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
3641
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3642
-        $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3643
-        EEH_Template::display_template($template, $this->_template_args);
3644
-    }
3645
-
3646
-
3647
-    /**
3648
-     * add in the form fields for the attendee edit
3649
-     *
3650
-     * @param WP_Post $post wp post object
3651
-     * @return void echos html for new form.
3652
-     * @throws DomainException
3653
-     */
3654
-    public function after_title_form_fields($post)
3655
-    {
3656
-        if ($post->post_type === 'espresso_attendees') {
3657
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3658
-            $template_args['attendee'] = $this->_cpt_model_obj;
3659
-            EEH_Template::display_template($template, $template_args);
3660
-        }
3661
-    }
3662
-
3663
-
3664
-    /**
3665
-     * _trash_or_restore_attendee
3666
-     *
3667
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3668
-     * @return void
3669
-     * @throws EE_Error
3670
-     * @throws InvalidArgumentException
3671
-     * @throws InvalidDataTypeException
3672
-     * @throws InvalidInterfaceException
3673
-     */
3674
-    protected function _trash_or_restore_attendees($trash = true)
3675
-    {
3676
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3677
-        $status = $trash ? 'trash' : 'publish';
3678
-        // Checkboxes
3679
-        if ($this->request->requestParamIsSet('checkbox')) {
3680
-            $ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3681
-            // if array has more than one element than success message should be plural
3682
-            $success = count($ATT_IDs) > 1 ? 2 : 1;
3683
-            // cycle thru checkboxes
3684
-            foreach ($ATT_IDs as $ATT_ID) {
3685
-                $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3686
-                if (! $updated) {
3687
-                    $success = 0;
3688
-                }
3689
-            }
3690
-        } else {
3691
-            // grab single id and delete
3692
-            $ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3693
-            // update attendee
3694
-            $success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3695
-        }
3696
-        $what        = $success > 1
3697
-            ? esc_html__('Contacts', 'event_espresso')
3698
-            : esc_html__('Contact', 'event_espresso');
3699
-        $action_desc = $trash
3700
-            ? esc_html__('moved to the trash', 'event_espresso')
3701
-            : esc_html__('restored', 'event_espresso');
3702
-        $this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3703
-    }
3235
+						'EVT_ID'      => $EVT_ID,
3236
+						'filters'     => urlencode(serialize($this->$method_name_for_getting_query_params($filters))),
3237
+						'use_filters' => urlencode($use_filters),
3238
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3239
+						'return_url'  => urlencode($return_url),
3240
+					]
3241
+				)
3242
+			);
3243
+		} else {
3244
+			// Pull the current request params
3245
+			$request_args = $this->request->requestParams();
3246
+			// Set the required request_args to be passed to the export
3247
+			$required_request_args = [
3248
+				'export' => 'report',
3249
+				'action' => 'registrations_report_for_event',
3250
+				'EVT_ID' => $EVT_ID,
3251
+			];
3252
+			// Merge required request args, overriding any currently set
3253
+			$request_args = array_merge($request_args, $required_request_args);
3254
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3255
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3256
+				$EE_Export = EE_Export::instance($request_args);
3257
+				$EE_Export->export();
3258
+			}
3259
+		}
3260
+	}
3261
+
3262
+
3263
+	/**
3264
+	 * Creates a registration report using only query parameters in the request
3265
+	 *
3266
+	 * @return void
3267
+	 */
3268
+	public function _registrations_report()
3269
+	{
3270
+		$this->_registrations_report_base('_get_registration_query_parameters');
3271
+	}
3272
+
3273
+
3274
+	public function _contact_list_export()
3275
+	{
3276
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3277
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3278
+			$EE_Export = EE_Export::instance($this->request->requestParams());
3279
+			$EE_Export->export_attendees();
3280
+		}
3281
+	}
3282
+
3283
+
3284
+	public function _contact_list_report()
3285
+	{
3286
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3287
+			wp_redirect(
3288
+				EE_Admin_Page::add_query_args_and_nonce(
3289
+					[
3290
+						'page'        => EED_Batch::PAGE_SLUG,
3291
+						'batch'       => EED_Batch::batch_file_job,
3292
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3293
+						'return_url'  => urlencode($this->request->getRequestParam('return_url', '', DataType::URL)),
3294
+					]
3295
+				)
3296
+			);
3297
+		} else {
3298
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3299
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3300
+				$EE_Export = EE_Export::instance($this->request->requestParams());
3301
+				$EE_Export->report_attendees();
3302
+			}
3303
+		}
3304
+	}
3305
+
3306
+
3307
+
3308
+
3309
+
3310
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3311
+	/**
3312
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3313
+	 *
3314
+	 * @return void
3315
+	 * @throws EE_Error
3316
+	 * @throws InvalidArgumentException
3317
+	 * @throws InvalidDataTypeException
3318
+	 * @throws InvalidInterfaceException
3319
+	 * @throws ReflectionException
3320
+	 */
3321
+	protected function _duplicate_attendee()
3322
+	{
3323
+		$REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3324
+		$action = $this->request->getRequestParam('return', 'default');
3325
+		// verify we have necessary info
3326
+		if (! $REG_ID) {
3327
+			EE_Error::add_error(
3328
+				esc_html__(
3329
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3330
+					'event_espresso'
3331
+				),
3332
+				__FILE__,
3333
+				__LINE__,
3334
+				__FUNCTION__
3335
+			);
3336
+			$query_args = ['action' => $action];
3337
+			$this->_redirect_after_action('', '', '', $query_args, true);
3338
+		}
3339
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3340
+		$registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3341
+		if (! $registration instanceof EE_Registration) {
3342
+			throw new RuntimeException(
3343
+				sprintf(
3344
+					esc_html__(
3345
+						'Unable to create the contact because a valid registration could not be retrieved for REG ID: %1$d',
3346
+						'event_espresso'
3347
+					),
3348
+					$REG_ID
3349
+				)
3350
+			);
3351
+		}
3352
+		$attendee = $registration->attendee();
3353
+		// remove relation of existing attendee on registration
3354
+		$registration->_remove_relation_to($attendee, 'Attendee');
3355
+		// new attendee
3356
+		$new_attendee = clone $attendee;
3357
+		$new_attendee->set('ATT_ID', 0);
3358
+		$new_attendee->save();
3359
+		// add new attendee to reg
3360
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3361
+		EE_Error::add_success(
3362
+			esc_html__(
3363
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3364
+				'event_espresso'
3365
+			)
3366
+		);
3367
+		// redirect to edit page for attendee
3368
+		$query_args = ['post' => $new_attendee->ID(), 'action' => 'edit_attendee'];
3369
+		$this->_redirect_after_action('', '', '', $query_args, true);
3370
+	}
3371
+
3372
+
3373
+	/**
3374
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3375
+	 *
3376
+	 * @param int     $post_id
3377
+	 * @param WP_Post $post
3378
+	 * @throws DomainException
3379
+	 * @throws EE_Error
3380
+	 * @throws InvalidArgumentException
3381
+	 * @throws InvalidDataTypeException
3382
+	 * @throws InvalidInterfaceException
3383
+	 * @throws LogicException
3384
+	 * @throws InvalidFormSubmissionException
3385
+	 * @throws ReflectionException
3386
+	 */
3387
+	protected function _insert_update_cpt_item($post_id, $post)
3388
+	{
3389
+		$success  = true;
3390
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3391
+			? $this->getAttendeeModel()->get_one_by_ID($post_id)
3392
+			: null;
3393
+		// for attendee updates
3394
+		if ($attendee instanceof EE_Attendee) {
3395
+			// note we should only be UPDATING attendees at this point.
3396
+			$fname          = $this->request->getRequestParam('ATT_fname', '');
3397
+			$lname          = $this->request->getRequestParam('ATT_lname', '');
3398
+			$updated_fields = [
3399
+				'ATT_fname'     => $fname,
3400
+				'ATT_lname'     => $lname,
3401
+				'ATT_full_name' => "{$fname} {$lname}",
3402
+				'ATT_address'   => $this->request->getRequestParam('ATT_address', ''),
3403
+				'ATT_address2'  => $this->request->getRequestParam('ATT_address2', ''),
3404
+				'ATT_city'      => $this->request->getRequestParam('ATT_city', ''),
3405
+				'STA_ID'        => $this->request->getRequestParam('STA_ID', ''),
3406
+				'CNT_ISO'       => $this->request->getRequestParam('CNT_ISO', ''),
3407
+				'ATT_zip'       => $this->request->getRequestParam('ATT_zip', ''),
3408
+			];
3409
+			foreach ($updated_fields as $field => $value) {
3410
+				$attendee->set($field, $value);
3411
+			}
3412
+
3413
+			// process contact details metabox form handler (which will also save the attendee)
3414
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3415
+			$success              = $contact_details_form->process($this->request->requestParams());
3416
+
3417
+			$attendee_update_callbacks = apply_filters(
3418
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3419
+				[]
3420
+			);
3421
+			foreach ($attendee_update_callbacks as $a_callback) {
3422
+				if (false === call_user_func_array($a_callback, [$attendee, $this->request->requestParams()])) {
3423
+					throw new EE_Error(
3424
+						sprintf(
3425
+							esc_html__(
3426
+								'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.',
3427
+								'event_espresso'
3428
+							),
3429
+							$a_callback
3430
+						)
3431
+					);
3432
+				}
3433
+			}
3434
+		}
3435
+
3436
+		if ($success === false) {
3437
+			EE_Error::add_error(
3438
+				esc_html__(
3439
+					'Something went wrong with updating the meta table data for the registration.',
3440
+					'event_espresso'
3441
+				),
3442
+				__FILE__,
3443
+				__FUNCTION__,
3444
+				__LINE__
3445
+			);
3446
+		}
3447
+	}
3448
+
3449
+
3450
+	public function trash_cpt_item($post_id)
3451
+	{
3452
+	}
3453
+
3454
+
3455
+	public function delete_cpt_item($post_id)
3456
+	{
3457
+	}
3458
+
3459
+
3460
+	public function restore_cpt_item($post_id)
3461
+	{
3462
+	}
3463
+
3464
+
3465
+	protected function _restore_cpt_item($post_id, $revision_id)
3466
+	{
3467
+	}
3468
+
3469
+
3470
+	/**
3471
+	 * @throws EE_Error
3472
+	 * @throws ReflectionException
3473
+	 * @since 4.10.2.p
3474
+	 */
3475
+	public function attendee_editor_metaboxes()
3476
+	{
3477
+		$this->verify_cpt_object();
3478
+		remove_meta_box(
3479
+			'postexcerpt',
3480
+			$this->_cpt_routes[ $this->_req_action ],
3481
+			'normal'
3482
+		);
3483
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3484
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3485
+			$this->addMetaBox(
3486
+				'postexcerpt',
3487
+				esc_html__('Short Biography', 'event_espresso'),
3488
+				'post_excerpt_meta_box',
3489
+				$this->_cpt_routes[ $this->_req_action ]
3490
+			);
3491
+		}
3492
+		if (post_type_supports('espresso_attendees', 'comments')) {
3493
+			$this->addMetaBox(
3494
+				'commentsdiv',
3495
+				esc_html__('Notes on the Contact', 'event_espresso'),
3496
+				'post_comment_meta_box',
3497
+				$this->_cpt_routes[ $this->_req_action ],
3498
+				'normal',
3499
+				'core'
3500
+			);
3501
+		}
3502
+		$this->addMetaBox(
3503
+			'attendee_contact_info',
3504
+			esc_html__('Contact Info', 'event_espresso'),
3505
+			[$this, 'attendee_contact_info'],
3506
+			$this->_cpt_routes[ $this->_req_action ],
3507
+			'side',
3508
+			'core'
3509
+		);
3510
+		$this->addMetaBox(
3511
+			'attendee_details_address',
3512
+			esc_html__('Address Details', 'event_espresso'),
3513
+			[$this, 'attendee_address_details'],
3514
+			$this->_cpt_routes[ $this->_req_action ],
3515
+			'normal',
3516
+			'core'
3517
+		);
3518
+		$this->addMetaBox(
3519
+			'attendee_registrations',
3520
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3521
+			[$this, 'attendee_registrations_meta_box'],
3522
+			$this->_cpt_routes[ $this->_req_action ]
3523
+		);
3524
+	}
3525
+
3526
+
3527
+	/**
3528
+	 * Metabox for attendee contact info
3529
+	 *
3530
+	 * @param WP_Post $post wp post object
3531
+	 * @return void attendee contact info ( and form )
3532
+	 * @throws EE_Error
3533
+	 * @throws InvalidArgumentException
3534
+	 * @throws InvalidDataTypeException
3535
+	 * @throws InvalidInterfaceException
3536
+	 * @throws LogicException
3537
+	 * @throws DomainException
3538
+	 */
3539
+	public function attendee_contact_info($post)
3540
+	{
3541
+		// get attendee object ( should already have it )
3542
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3543
+		$form->enqueueStylesAndScripts();
3544
+		echo wp_kses($form->display(), AllowedTags::getWithFormTags());
3545
+	}
3546
+
3547
+
3548
+	/**
3549
+	 * Return form handler for the contact details metabox
3550
+	 *
3551
+	 * @param EE_Attendee $attendee
3552
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3553
+	 * @throws DomainException
3554
+	 * @throws InvalidArgumentException
3555
+	 * @throws InvalidDataTypeException
3556
+	 * @throws InvalidInterfaceException
3557
+	 */
3558
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3559
+	{
3560
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3561
+	}
3562
+
3563
+
3564
+	/**
3565
+	 * Metabox for attendee details
3566
+	 *
3567
+	 * @param WP_Post $post wp post object
3568
+	 * @throws EE_Error
3569
+	 * @throws ReflectionException
3570
+	 */
3571
+	public function attendee_address_details($post)
3572
+	{
3573
+		// get attendee object (should already have it)
3574
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
3575
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(
3576
+			new EE_Question_Form_Input(
3577
+				EE_Question::new_instance(
3578
+					[
3579
+						'QST_ID'           => 0,
3580
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3581
+						'QST_system'       => 'admin-state',
3582
+					]
3583
+				),
3584
+				EE_Answer::new_instance(
3585
+					[
3586
+						'ANS_ID'    => 0,
3587
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3588
+					]
3589
+				),
3590
+				[
3591
+					'input_id'       => 'STA_ID',
3592
+					'input_name'     => 'STA_ID',
3593
+					'input_prefix'   => '',
3594
+					'append_qstn_id' => false,
3595
+				]
3596
+			)
3597
+		);
3598
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3599
+			new EE_Question_Form_Input(
3600
+				EE_Question::new_instance(
3601
+					[
3602
+						'QST_ID'           => 0,
3603
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3604
+						'QST_system'       => 'admin-country',
3605
+					]
3606
+				),
3607
+				EE_Answer::new_instance(
3608
+					[
3609
+						'ANS_ID'    => 0,
3610
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3611
+					]
3612
+				),
3613
+				[
3614
+					'input_id'       => 'CNT_ISO',
3615
+					'input_name'     => 'CNT_ISO',
3616
+					'input_prefix'   => '',
3617
+					'append_qstn_id' => false,
3618
+				]
3619
+			)
3620
+		);
3621
+		$template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3622
+		EEH_Template::display_template($template, $this->_template_args);
3623
+	}
3624
+
3625
+
3626
+	/**
3627
+	 * _attendee_details
3628
+	 *
3629
+	 * @param $post
3630
+	 * @return void
3631
+	 * @throws DomainException
3632
+	 * @throws EE_Error
3633
+	 * @throws InvalidArgumentException
3634
+	 * @throws InvalidDataTypeException
3635
+	 * @throws InvalidInterfaceException
3636
+	 * @throws ReflectionException
3637
+	 */
3638
+	public function attendee_registrations_meta_box($post)
3639
+	{
3640
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
3641
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3642
+		$template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3643
+		EEH_Template::display_template($template, $this->_template_args);
3644
+	}
3645
+
3646
+
3647
+	/**
3648
+	 * add in the form fields for the attendee edit
3649
+	 *
3650
+	 * @param WP_Post $post wp post object
3651
+	 * @return void echos html for new form.
3652
+	 * @throws DomainException
3653
+	 */
3654
+	public function after_title_form_fields($post)
3655
+	{
3656
+		if ($post->post_type === 'espresso_attendees') {
3657
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3658
+			$template_args['attendee'] = $this->_cpt_model_obj;
3659
+			EEH_Template::display_template($template, $template_args);
3660
+		}
3661
+	}
3662
+
3663
+
3664
+	/**
3665
+	 * _trash_or_restore_attendee
3666
+	 *
3667
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3668
+	 * @return void
3669
+	 * @throws EE_Error
3670
+	 * @throws InvalidArgumentException
3671
+	 * @throws InvalidDataTypeException
3672
+	 * @throws InvalidInterfaceException
3673
+	 */
3674
+	protected function _trash_or_restore_attendees($trash = true)
3675
+	{
3676
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3677
+		$status = $trash ? 'trash' : 'publish';
3678
+		// Checkboxes
3679
+		if ($this->request->requestParamIsSet('checkbox')) {
3680
+			$ATT_IDs = $this->request->getRequestParam('checkbox', [], 'int', true);
3681
+			// if array has more than one element than success message should be plural
3682
+			$success = count($ATT_IDs) > 1 ? 2 : 1;
3683
+			// cycle thru checkboxes
3684
+			foreach ($ATT_IDs as $ATT_ID) {
3685
+				$updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3686
+				if (! $updated) {
3687
+					$success = 0;
3688
+				}
3689
+			}
3690
+		} else {
3691
+			// grab single id and delete
3692
+			$ATT_ID = $this->request->getRequestParam('ATT_ID', 0, 'int');
3693
+			// update attendee
3694
+			$success = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID) ? 1 : 0;
3695
+		}
3696
+		$what        = $success > 1
3697
+			? esc_html__('Contacts', 'event_espresso')
3698
+			: esc_html__('Contact', 'event_espresso');
3699
+		$action_desc = $trash
3700
+			? esc_html__('moved to the trash', 'event_espresso')
3701
+			: esc_html__('restored', 'event_espresso');
3702
+		$this->_redirect_after_action($success, $what, $action_desc, ['action' => 'contact_list']);
3703
+	}
3704 3704
 }
Please login to merge, or discard this patch.
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     protected function getRegistrationModel()
95 95
     {
96
-        if (! $this->registration_model instanceof EEM_Registration) {
96
+        if ( ! $this->registration_model instanceof EEM_Registration) {
97 97
             $this->registration_model = $this->loader->getShared('EEM_Registration');
98 98
         }
99 99
         return $this->registration_model;
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     protected function getAttendeeModel()
111 111
     {
112
-        if (! $this->attendee_model instanceof EEM_Attendee) {
112
+        if ( ! $this->attendee_model instanceof EEM_Attendee) {
113 113
             $this->attendee_model = $this->loader->getShared('EEM_Attendee');
114 114
         }
115 115
         return $this->attendee_model;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      */
126 126
     protected function getEventModel()
127 127
     {
128
-        if (! $this->event_model instanceof EEM_Event) {
128
+        if ( ! $this->event_model instanceof EEM_Event) {
129 129
             $this->event_model = $this->loader->getShared('EEM_Event');
130 130
         }
131 131
         return $this->event_model;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     protected function getStatusModel()
143 143
     {
144
-        if (! $this->status_model instanceof EEM_Status) {
144
+        if ( ! $this->status_model instanceof EEM_Status) {
145 145
             $this->status_model = $this->loader->getShared('EEM_Status');
146 146
         }
147 147
         return $this->status_model;
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
         // style
757 757
         wp_register_style(
758 758
             'espresso_reg',
759
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
759
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
760 760
             ['ee-admin-css'],
761 761
             EVENT_ESPRESSO_VERSION
762 762
         );
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
         // script
765 765
         wp_register_script(
766 766
             'espresso_reg',
767
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
767
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
768 768
             ['jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'],
769 769
             EVENT_ESPRESSO_VERSION,
770 770
             true
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
             'att_publish_text' => sprintf(
789 789
             /* translators: The date and time */
790 790
                 wp_strip_all_tags(__('Created on: %s', 'event_espresso')),
791
-                '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>'
791
+                '<b>'.$this->_cpt_model_obj->get_datetime('ATT_created').'</b>'
792 792
             ),
793 793
         ];
794 794
         wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
@@ -819,7 +819,7 @@  discard block
 block discarded – undo
819 819
         wp_dequeue_style('espresso_reg');
820 820
         wp_register_style(
821 821
             'espresso_att',
822
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
822
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
823 823
             ['ee-admin-css'],
824 824
             EVENT_ESPRESSO_VERSION
825 825
         );
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
     {
832 832
         wp_register_script(
833 833
             'ee-spco-for-admin',
834
-            REG_ASSETS_URL . 'spco_for_admin.js',
834
+            REG_ASSETS_URL.'spco_for_admin.js',
835 835
             ['underscore', 'jquery'],
836 836
             EVENT_ESPRESSO_VERSION,
837 837
             true
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
             'no_approve_registrations' => 'not_approved_registration',
880 880
             'cancel_registrations'     => 'cancelled_registration',
881 881
         ];
882
-        $can_send    = EE_Registry::instance()->CAP->current_user_can(
882
+        $can_send = EE_Registry::instance()->CAP->current_user_can(
883 883
             'ee_send_message',
884 884
             'batch_send_messages'
885 885
         );
@@ -984,7 +984,7 @@  discard block
 block discarded – undo
984 984
                     'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
985 985
                 ],
986 986
             ];
987
-            $this->_views['trash']      = [
987
+            $this->_views['trash'] = [
988 988
                 'slug'        => 'trash',
989 989
                 'label'       => esc_html__('Trash', 'event_espresso'),
990 990
                 'count'       => 0,
@@ -1084,7 +1084,7 @@  discard block
 block discarded – undo
1084 1084
         }
1085 1085
         $sc_items = [
1086 1086
             'approved_status'   => [
1087
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_approved,
1087
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_approved,
1088 1088
                 'desc'  => EEH_Template::pretty_status(
1089 1089
                     EEM_Registration::status_id_approved,
1090 1090
                     false,
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
                 ),
1093 1093
             ],
1094 1094
             'pending_status'    => [
1095
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_pending_payment,
1095
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_pending_payment,
1096 1096
                 'desc'  => EEH_Template::pretty_status(
1097 1097
                     EEM_Registration::status_id_pending_payment,
1098 1098
                     false,
@@ -1100,7 +1100,7 @@  discard block
 block discarded – undo
1100 1100
                 ),
1101 1101
             ],
1102 1102
             'wait_list'         => [
1103
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_wait_list,
1103
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_wait_list,
1104 1104
                 'desc'  => EEH_Template::pretty_status(
1105 1105
                     EEM_Registration::status_id_wait_list,
1106 1106
                     false,
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
                 ),
1109 1109
             ],
1110 1110
             'incomplete_status' => [
1111
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_incomplete,
1111
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_incomplete,
1112 1112
                 'desc'  => EEH_Template::pretty_status(
1113 1113
                     EEM_Registration::status_id_incomplete,
1114 1114
                     false,
@@ -1116,7 +1116,7 @@  discard block
 block discarded – undo
1116 1116
                 ),
1117 1117
             ],
1118 1118
             'not_approved'      => [
1119
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_not_approved,
1119
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_not_approved,
1120 1120
                 'desc'  => EEH_Template::pretty_status(
1121 1121
                     EEM_Registration::status_id_not_approved,
1122 1122
                     false,
@@ -1124,7 +1124,7 @@  discard block
 block discarded – undo
1124 1124
                 ),
1125 1125
             ],
1126 1126
             'declined_status'   => [
1127
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_declined,
1127
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_declined,
1128 1128
                 'desc'  => EEH_Template::pretty_status(
1129 1129
                     EEM_Registration::status_id_declined,
1130 1130
                     false,
@@ -1132,7 +1132,7 @@  discard block
 block discarded – undo
1132 1132
                 ),
1133 1133
             ],
1134 1134
             'cancelled_status'  => [
1135
-                'class' => 'ee-status-legend ee-status-bg--' . EEM_Registration::status_id_cancelled,
1135
+                'class' => 'ee-status-legend ee-status-bg--'.EEM_Registration::status_id_cancelled,
1136 1136
                 'desc'  => EEH_Template::pretty_status(
1137 1137
                     EEM_Registration::status_id_cancelled,
1138 1138
                     false,
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
                 $EVT_ID
1193 1193
             )
1194 1194
         ) {
1195
-            $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1195
+            $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1196 1196
                 'new_registration',
1197 1197
                 'add-registrant',
1198 1198
                 ['event_id' => $EVT_ID],
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
                 ],
1351 1351
                 REG_ADMIN_URL
1352 1352
             );
1353
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(
1353
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1354 1354
                 [
1355 1355
                     'action' => 'default',
1356 1356
                     'EVT_ID' => $event_id,
@@ -1358,7 +1358,7 @@  discard block
 block discarded – undo
1358 1358
                 ],
1359 1359
                 admin_url('admin.php')
1360 1360
             );
1361
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(
1361
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1362 1362
                 [
1363 1363
                     'page'   => 'espresso_events',
1364 1364
                     'action' => 'edit',
@@ -1367,12 +1367,12 @@  discard block
 block discarded – undo
1367 1367
                 admin_url('admin.php')
1368 1368
             );
1369 1369
             // next and previous links
1370
-            $next_reg                                      = $this->_registration->next(
1370
+            $next_reg = $this->_registration->next(
1371 1371
                 null,
1372 1372
                 [],
1373 1373
                 'REG_ID'
1374 1374
             );
1375
-            $this->_template_args['next_registration']     = $next_reg
1375
+            $this->_template_args['next_registration'] = $next_reg
1376 1376
                 ? $this->_next_link(
1377 1377
                     EE_Admin_Page::add_query_args_and_nonce(
1378 1378
                         [
@@ -1384,7 +1384,7 @@  discard block
 block discarded – undo
1384 1384
                     'dashicons dashicons-arrow-right ee-icon-size-22'
1385 1385
                 )
1386 1386
                 : '';
1387
-            $previous_reg                                  = $this->_registration->previous(
1387
+            $previous_reg = $this->_registration->previous(
1388 1388
                 null,
1389 1389
                 [],
1390 1390
                 'REG_ID'
@@ -1402,7 +1402,7 @@  discard block
 block discarded – undo
1402 1402
                 )
1403 1403
                 : '';
1404 1404
             // grab header
1405
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1405
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1406 1406
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1407 1407
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1408 1408
                 $template_path,
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
         );
1440 1440
         $this->addMetaBox(
1441 1441
             'edit-reg-details-mbox',
1442
-            '<span>' . esc_html__('Registration Details', 'event_espresso')
1442
+            '<span>'.esc_html__('Registration Details', 'event_espresso')
1443 1443
             . '&nbsp;<span class="dashicons dashicons-clipboard"></span></span>',
1444 1444
             [$this, '_reg_details_meta_box'],
1445 1445
             $this->_wp_page_slug
@@ -1543,7 +1543,7 @@  discard block
 block discarded – undo
1543 1543
                 $this->_registration->ID()
1544 1544
             )
1545 1545
         ) {
1546
-            $reg_status_change_form_array['subsections']['reg_status']         = new EE_Select_Input(
1546
+            $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1547 1547
                 $this->_get_reg_statuses(),
1548 1548
                 [
1549 1549
                     'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
@@ -1560,7 +1560,7 @@  discard block
 block discarded – undo
1560 1560
                     ),
1561 1561
                 ]
1562 1562
             );
1563
-            $reg_status_change_form_array['subsections']['submit']             = new EE_Submit_Input(
1563
+            $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1564 1564
                 [
1565 1565
                     'html_class'      => 'button--primary',
1566 1566
                     'html_label_text' => '&nbsp;',
@@ -1585,7 +1585,7 @@  discard block
 block discarded – undo
1585 1585
     protected function _get_reg_statuses()
1586 1586
     {
1587 1587
         $reg_status_array = $this->getRegistrationModel()->reg_status_array();
1588
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1588
+        unset($reg_status_array[EEM_Registration::status_id_incomplete]);
1589 1589
         // get current reg status
1590 1590
         $current_status = $this->_registration->status_ID();
1591 1591
         // is registration for free event? This will determine whether to display the pending payment option
@@ -1593,7 +1593,7 @@  discard block
 block discarded – undo
1593 1593
             $current_status !== EEM_Registration::status_id_pending_payment
1594 1594
             && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1595 1595
         ) {
1596
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1596
+            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1597 1597
         }
1598 1598
         return $this->getStatusModel()->localized_status($reg_status_array, false, 'sentence');
1599 1599
     }
@@ -1684,7 +1684,7 @@  discard block
 block discarded – undo
1684 1684
         $success = false;
1685 1685
         // typecast $REG_IDs
1686 1686
         $REG_IDs = (array) $REG_IDs;
1687
-        if (! empty($REG_IDs)) {
1687
+        if ( ! empty($REG_IDs)) {
1688 1688
             $success = true;
1689 1689
             // set default status if none is passed
1690 1690
             $status         = $status ?: EEM_Registration::status_id_pending_payment;
@@ -1844,7 +1844,7 @@  discard block
 block discarded – undo
1844 1844
             $action,
1845 1845
             $notify
1846 1846
         );
1847
-        $method = $action . '_registration';
1847
+        $method = $action.'_registration';
1848 1848
         if (method_exists($this, $method)) {
1849 1849
             $this->$method($notify);
1850 1850
         }
@@ -1994,7 +1994,7 @@  discard block
 block discarded – undo
1994 1994
         $filters        = new EE_Line_Item_Filter_Collection();
1995 1995
         $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1996 1996
         $filters->add(new EE_Non_Zero_Line_Item_Filter());
1997
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor(
1997
+        $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
1998 1998
             $filters,
1999 1999
             $transaction->total_line_item()
2000 2000
         );
@@ -2007,7 +2007,7 @@  discard block
 block discarded – undo
2007 2007
             $filtered_line_item_tree,
2008 2008
             ['EE_Registration' => $this->_registration]
2009 2009
         );
2010
-        $attendee                                = $this->_registration->attendee();
2010
+        $attendee = $this->_registration->attendee();
2011 2011
         if (
2012 2012
             EE_Registry::instance()->CAP->current_user_can(
2013 2013
                 'ee_read_transaction',
@@ -2089,7 +2089,7 @@  discard block
 block discarded – undo
2089 2089
                 'Payment method response',
2090 2090
                 'event_espresso'
2091 2091
             );
2092
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
2092
+            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2093 2093
         }
2094 2094
         $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2095 2095
         $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
@@ -2120,7 +2120,7 @@  discard block
 block discarded – undo
2120 2120
         $this->_template_args['REG_ID'] = $this->_registration->ID();
2121 2121
         $this->_template_args['event_id'] = $this->_registration->event_ID();
2122 2122
 
2123
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2123
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2124 2124
         EEH_Template::display_template($template_path, $this->_template_args); // already escaped
2125 2125
     }
2126 2126
 
@@ -2159,7 +2159,7 @@  discard block
 block discarded – undo
2159 2159
 
2160 2160
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2161 2161
             $this->_template_args['REG_ID'] = $this->_registration->ID();
2162
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2162
+            $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2163 2163
             EEH_Template::display_template($template_path, $this->_template_args);
2164 2164
         }
2165 2165
     }
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
     public function form_before_question_group($output)
2176 2176
     {
2177 2177
         EE_Error::doing_it_wrong(
2178
-            __CLASS__ . '::' . __FUNCTION__,
2178
+            __CLASS__.'::'.__FUNCTION__,
2179 2179
             esc_html__(
2180 2180
                 '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.',
2181 2181
                 'event_espresso'
@@ -2199,7 +2199,7 @@  discard block
 block discarded – undo
2199 2199
     public function form_after_question_group($output)
2200 2200
     {
2201 2201
         EE_Error::doing_it_wrong(
2202
-            __CLASS__ . '::' . __FUNCTION__,
2202
+            __CLASS__.'::'.__FUNCTION__,
2203 2203
             esc_html__(
2204 2204
                 '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.',
2205 2205
                 'event_espresso'
@@ -2236,7 +2236,7 @@  discard block
 block discarded – undo
2236 2236
     public function form_form_field_label_wrap($label)
2237 2237
     {
2238 2238
         EE_Error::doing_it_wrong(
2239
-            __CLASS__ . '::' . __FUNCTION__,
2239
+            __CLASS__.'::'.__FUNCTION__,
2240 2240
             esc_html__(
2241 2241
                 '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.',
2242 2242
                 'event_espresso'
@@ -2246,7 +2246,7 @@  discard block
 block discarded – undo
2246 2246
         return '
2247 2247
 			<tr>
2248 2248
 				<th>
2249
-					' . $label . '
2249
+					' . $label.'
2250 2250
 				</th>';
2251 2251
     }
2252 2252
 
@@ -2261,7 +2261,7 @@  discard block
 block discarded – undo
2261 2261
     public function form_form_field_input__wrap($input)
2262 2262
     {
2263 2263
         EE_Error::doing_it_wrong(
2264
-            __CLASS__ . '::' . __FUNCTION__,
2264
+            __CLASS__.'::'.__FUNCTION__,
2265 2265
             esc_html__(
2266 2266
                 '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.',
2267 2267
                 'event_espresso'
@@ -2270,7 +2270,7 @@  discard block
 block discarded – undo
2270 2270
         );
2271 2271
         return '
2272 2272
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2273
-					' . $input . '
2273
+					' . $input.'
2274 2274
 				</td>
2275 2275
 			</tr>';
2276 2276
     }
@@ -2319,8 +2319,8 @@  discard block
 block discarded – undo
2319 2319
      */
2320 2320
     protected function _get_reg_custom_questions_form($REG_ID)
2321 2321
     {
2322
-        if (! $this->_reg_custom_questions_form) {
2323
-            require_once(REG_ADMIN . 'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2322
+        if ( ! $this->_reg_custom_questions_form) {
2323
+            require_once(REG_ADMIN.'form_sections/EE_Registration_Custom_Questions_Form.form.php');
2324 2324
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2325 2325
                 $this->getRegistrationModel()->get_one_by_ID($REG_ID)
2326 2326
             );
@@ -2343,7 +2343,7 @@  discard block
 block discarded – undo
2343 2343
      */
2344 2344
     private function _save_reg_custom_questions_form($REG_ID = 0)
2345 2345
     {
2346
-        if (! $REG_ID) {
2346
+        if ( ! $REG_ID) {
2347 2347
             EE_Error::add_error(
2348 2348
                 esc_html__(
2349 2349
                     'An error occurred. No registration ID was received.',
@@ -2360,7 +2360,7 @@  discard block
 block discarded – undo
2360 2360
         if ($form->is_valid()) {
2361 2361
             foreach ($form->subforms() as $question_group_form) {
2362 2362
                 foreach ($question_group_form->inputs() as $question_id => $input) {
2363
-                    $where_conditions    = [
2363
+                    $where_conditions = [
2364 2364
                         'QST_ID' => $question_id,
2365 2365
                         'REG_ID' => $REG_ID,
2366 2366
                     ];
@@ -2401,7 +2401,7 @@  discard block
 block discarded – undo
2401 2401
         $REG = $this->getRegistrationModel();
2402 2402
         // get all other registrations on this transaction, and cache
2403 2403
         // the attendees for them so we don't have to run another query using force_join
2404
-        $registrations                           = $REG->get_all(
2404
+        $registrations = $REG->get_all(
2405 2405
             [
2406 2406
                 [
2407 2407
                     'TXN_ID' => $this->_registration->transaction_ID(),
@@ -2435,23 +2435,23 @@  discard block
 block discarded – undo
2435 2435
                 $attendee                                                      = $registration->attendee()
2436 2436
                     ? $registration->attendee()
2437 2437
                     : $this->getAttendeeModel()->create_default_object();
2438
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID']      = $registration->status_ID();
2439
-                $this->_template_args['attendees'][ $att_nmbr ]['fname']       = $attendee->fname();
2440
-                $this->_template_args['attendees'][ $att_nmbr ]['lname']       = $attendee->lname();
2441
-                $this->_template_args['attendees'][ $att_nmbr ]['email']       = $attendee->email();
2442
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2443
-                $this->_template_args['attendees'][ $att_nmbr ]['address']     = implode(
2438
+                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2439
+                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();
2440
+                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();
2441
+                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();
2442
+                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2443
+                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(
2444 2444
                     ', ',
2445 2445
                     $attendee->full_address_as_array()
2446 2446
                 );
2447
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link']    = self::add_query_args_and_nonce(
2447
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2448 2448
                     [
2449 2449
                         'action' => 'edit_attendee',
2450 2450
                         'post'   => $attendee->ID(),
2451 2451
                     ],
2452 2452
                     REG_ADMIN_URL
2453 2453
                 );
2454
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name']  =
2454
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] =
2455 2455
                     $registration->event_obj() instanceof EE_Event
2456 2456
                         ? $registration->event_obj()->name()
2457 2457
                         : '';
@@ -2459,7 +2459,7 @@  discard block
 block discarded – undo
2459 2459
             }
2460 2460
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2461 2461
         }
2462
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2462
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2463 2463
         EEH_Template::display_template($template_path, $this->_template_args);
2464 2464
     }
2465 2465
 
@@ -2485,11 +2485,11 @@  discard block
 block discarded – undo
2485 2485
         // now let's determine if this is not the primary registration.  If it isn't then we set the
2486 2486
         // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2487 2487
         // primary registration object (that way we know if we need to show create button or not)
2488
-        if (! $this->_registration->is_primary_registrant()) {
2488
+        if ( ! $this->_registration->is_primary_registrant()) {
2489 2489
             $primary_registration = $this->_registration->get_primary_registration();
2490 2490
             $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2491 2491
                 : null;
2492
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2492
+            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2493 2493
                 // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2494 2494
                 // custom attendee object so let's not worry about the primary reg.
2495 2495
                 $primary_registration = null;
@@ -2504,7 +2504,7 @@  discard block
 block discarded – undo
2504 2504
         $this->_template_args['phone']             = $attendee->phone();
2505 2505
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2506 2506
         // edit link
2507
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(
2507
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2508 2508
             [
2509 2509
                 'action' => 'edit_attendee',
2510 2510
                 'post'   => $attendee->ID(),
@@ -2514,7 +2514,7 @@  discard block
 block discarded – undo
2514 2514
         $this->_template_args['att_edit_title'] = esc_html__('View details for this contact.', 'event_espresso');
2515 2515
         $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2516 2516
         // create link
2517
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2517
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2518 2518
             ? EE_Admin_Page::add_query_args_and_nonce(
2519 2519
                 [
2520 2520
                     'action'  => 'duplicate_attendee',
@@ -2524,7 +2524,7 @@  discard block
 block discarded – undo
2524 2524
             ) : '';
2525 2525
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2526 2526
         $this->_template_args['att_check'] = $att_check;
2527
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2527
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2528 2528
         EEH_Template::display_template($template_path, $this->_template_args);
2529 2529
     }
2530 2530
 
@@ -2568,7 +2568,7 @@  discard block
 block discarded – undo
2568 2568
             /** @var EE_Registration $REG */
2569 2569
             $REG      = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
2570 2570
             $payments = $REG->registration_payments();
2571
-            if (! empty($payments)) {
2571
+            if ( ! empty($payments)) {
2572 2572
                 $name           = $REG->attendee() instanceof EE_Attendee
2573 2573
                     ? $REG->attendee()->full_name()
2574 2574
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2632,17 +2632,17 @@  discard block
 block discarded – undo
2632 2632
         // Checkboxes
2633 2633
         $REG_IDs = $this->request->getRequestParam('_REG_ID', [], 'int', true);
2634 2634
 
2635
-        if (! empty($REG_IDs)) {
2635
+        if ( ! empty($REG_IDs)) {
2636 2636
             // if array has more than one element than success message should be plural
2637 2637
             $success = count($REG_IDs) > 1 ? 2 : 1;
2638 2638
             // cycle thru checkboxes
2639 2639
             foreach ($REG_IDs as $REG_ID) {
2640 2640
                 $REG = $REG_MDL->get_one_by_ID($REG_ID);
2641
-                if (! $REG instanceof EE_Registration) {
2641
+                if ( ! $REG instanceof EE_Registration) {
2642 2642
                     continue;
2643 2643
                 }
2644 2644
                 $deleted = $this->_delete_registration($REG);
2645
-                if (! $deleted) {
2645
+                if ( ! $deleted) {
2646 2646
                     $success = 0;
2647 2647
                 }
2648 2648
             }
@@ -2679,7 +2679,7 @@  discard block
 block discarded – undo
2679 2679
         // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2680 2680
         // registrations on the transaction that are NOT trashed.
2681 2681
         $TXN = $REG->get_first_related('Transaction');
2682
-        if (! $TXN instanceof EE_Transaction) {
2682
+        if ( ! $TXN instanceof EE_Transaction) {
2683 2683
             EE_Error::add_error(
2684 2684
                 sprintf(
2685 2685
                     esc_html__(
@@ -2697,11 +2697,11 @@  discard block
 block discarded – undo
2697 2697
         $REGS        = $TXN->get_many_related('Registration');
2698 2698
         $all_trashed = true;
2699 2699
         foreach ($REGS as $registration) {
2700
-            if (! $registration->get('REG_deleted')) {
2700
+            if ( ! $registration->get('REG_deleted')) {
2701 2701
                 $all_trashed = false;
2702 2702
             }
2703 2703
         }
2704
-        if (! $all_trashed) {
2704
+        if ( ! $all_trashed) {
2705 2705
             EE_Error::add_error(
2706 2706
                 esc_html__(
2707 2707
                     '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.',
@@ -2763,7 +2763,7 @@  discard block
 block discarded – undo
2763 2763
      */
2764 2764
     public function new_registration()
2765 2765
     {
2766
-        if (! $this->_set_reg_event()) {
2766
+        if ( ! $this->_set_reg_event()) {
2767 2767
             throw new EE_Error(
2768 2768
                 esc_html__(
2769 2769
                     'Unable to continue with registering because there is no Event ID in the request',
@@ -2795,7 +2795,7 @@  discard block
 block discarded – undo
2795 2795
                 ],
2796 2796
                 EVENTS_ADMIN_URL
2797 2797
             );
2798
-            $edit_event_lnk                     = '<a href="'
2798
+            $edit_event_lnk = '<a href="'
2799 2799
                                                   . $edit_event_url
2800 2800
                                                   . '" title="'
2801 2801
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2812,7 +2812,7 @@  discard block
 block discarded – undo
2812 2812
             $this->_return_json();
2813 2813
         }
2814 2814
         // grab header
2815
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2815
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2816 2816
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2817 2817
             $template_path,
2818 2818
             $this->_template_args,
@@ -2853,7 +2853,7 @@  discard block
 block discarded – undo
2853 2853
                 '</b>'
2854 2854
             );
2855 2855
             return '
2856
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2856
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2857 2857
 	<script >
2858 2858
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2859 2859
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2920,7 +2920,7 @@  discard block
 block discarded – undo
2920 2920
         // we come back to the process_registration_step route.
2921 2921
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
2922 2922
         return EEH_Template::display_template(
2923
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
2923
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
2924 2924
             $template_args,
2925 2925
             true
2926 2926
         );
@@ -2943,7 +2943,7 @@  discard block
 block discarded – undo
2943 2943
         }
2944 2944
 
2945 2945
         $EVT_ID = $this->request->getRequestParam('event_id', 0, 'int');
2946
-        if (! $EVT_ID) {
2946
+        if ( ! $EVT_ID) {
2947 2947
             return false;
2948 2948
         }
2949 2949
         $this->_reg_event = $this->getEventModel()->get_one_by_ID($EVT_ID);
@@ -3013,7 +3013,7 @@  discard block
 block discarded – undo
3013 3013
                 }
3014 3014
                 break;
3015 3015
             case 'questions':
3016
-                if (! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3016
+                if ( ! $this->request->requestParamIsSet('txn_reg_status_change[send_notifications]')) {
3017 3017
                     add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3018 3018
                 }
3019 3019
                 // process registration
@@ -3024,7 +3024,7 @@  discard block
 block discarded – undo
3024 3024
                         $grand_total->save_this_and_descendants_to_txn();
3025 3025
                     }
3026 3026
                 }
3027
-                if (! $transaction instanceof EE_Transaction) {
3027
+                if ( ! $transaction instanceof EE_Transaction) {
3028 3028
                     $query_args = [
3029 3029
                         'action'                  => 'new_registration',
3030 3030
                         'processing_registration' => 2,
@@ -3046,7 +3046,7 @@  discard block
 block discarded – undo
3046 3046
                     return;
3047 3047
                 }
3048 3048
                 // maybe update status, and make sure to save transaction if not done already
3049
-                if (! $transaction->update_status_based_on_total_paid()) {
3049
+                if ( ! $transaction->update_status_based_on_total_paid()) {
3050 3050
                     $transaction->save();
3051 3051
                 }
3052 3052
                 EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
@@ -3128,7 +3128,7 @@  discard block
 block discarded – undo
3128 3128
     public function get_attendees($per_page, $count = false, $trash = false)
3129 3129
     {
3130 3130
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3131
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3131
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3132 3132
         $orderby = $this->request->getRequestParam('orderby');
3133 3133
         switch ($orderby) {
3134 3134
             case 'ATT_ID':
@@ -3151,7 +3151,7 @@  discard block
 block discarded – undo
3151 3151
         $_where       = [];
3152 3152
         $search_term  = $this->request->getRequestParam('s');
3153 3153
         if ($search_term) {
3154
-            $search_term  = '%' . $search_term . '%';
3154
+            $search_term  = '%'.$search_term.'%';
3155 3155
             $_where['OR'] = [
3156 3156
                 'Registration.Event.EVT_name'       => ['LIKE', $search_term],
3157 3157
                 'Registration.Event.EVT_desc'       => ['LIKE', $search_term],
@@ -3178,7 +3178,7 @@  discard block
 block discarded – undo
3178 3178
             'extra_selects' => ['Registration_Count' => ['Registration.REG_ID', 'count', '%d']],
3179 3179
             'limit'         => $limit,
3180 3180
         ];
3181
-        if (! $count) {
3181
+        if ( ! $count) {
3182 3182
             $query_args['order_by'] = [$orderby => $sort];
3183 3183
         }
3184 3184
         $query_args[0]['status'] = $trash ? ['!=', 'publish'] : ['IN', ['publish']];
@@ -3223,7 +3223,7 @@  discard block
 block discarded – undo
3223 3223
         $EVT_ID = $this->request->requestParamIsSet('EVT_ID')
3224 3224
             ? $this->request->getRequestParam('EVT_ID', 0, DataType::INT)
3225 3225
             : null;
3226
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3226
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3227 3227
             $return_url = $this->request->getRequestParam('return_url', '', DataType::URL);
3228 3228
             $filters = $this->request->getRequestParam('filters', [], DataType::STRING, true);
3229 3229
             $use_filters = $this->request->getRequestParam('use_filters', false, DataType::BOOL);
@@ -3251,8 +3251,8 @@  discard block
 block discarded – undo
3251 3251
             ];
3252 3252
             // Merge required request args, overriding any currently set
3253 3253
             $request_args = array_merge($request_args, $required_request_args);
3254
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3255
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3254
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3255
+                require_once(EE_CLASSES.'EE_Export.class.php');
3256 3256
                 $EE_Export = EE_Export::instance($request_args);
3257 3257
                 $EE_Export->export();
3258 3258
             }
@@ -3273,8 +3273,8 @@  discard block
 block discarded – undo
3273 3273
 
3274 3274
     public function _contact_list_export()
3275 3275
     {
3276
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3277
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3276
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3277
+            require_once(EE_CLASSES.'EE_Export.class.php');
3278 3278
             $EE_Export = EE_Export::instance($this->request->requestParams());
3279 3279
             $EE_Export->export_attendees();
3280 3280
         }
@@ -3283,7 +3283,7 @@  discard block
 block discarded – undo
3283 3283
 
3284 3284
     public function _contact_list_report()
3285 3285
     {
3286
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3286
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3287 3287
             wp_redirect(
3288 3288
                 EE_Admin_Page::add_query_args_and_nonce(
3289 3289
                     [
@@ -3295,8 +3295,8 @@  discard block
 block discarded – undo
3295 3295
                 )
3296 3296
             );
3297 3297
         } else {
3298
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3299
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3298
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3299
+                require_once(EE_CLASSES.'EE_Export.class.php');
3300 3300
                 $EE_Export = EE_Export::instance($this->request->requestParams());
3301 3301
                 $EE_Export->report_attendees();
3302 3302
             }
@@ -3323,7 +3323,7 @@  discard block
 block discarded – undo
3323 3323
         $REG_ID = $this->request->getRequestParam('_REG_ID', 0, 'int');
3324 3324
         $action = $this->request->getRequestParam('return', 'default');
3325 3325
         // verify we have necessary info
3326
-        if (! $REG_ID) {
3326
+        if ( ! $REG_ID) {
3327 3327
             EE_Error::add_error(
3328 3328
                 esc_html__(
3329 3329
                     'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
@@ -3338,7 +3338,7 @@  discard block
 block discarded – undo
3338 3338
         }
3339 3339
         // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3340 3340
         $registration = $this->getRegistrationModel()->get_one_by_ID($REG_ID);
3341
-        if (! $registration instanceof EE_Registration) {
3341
+        if ( ! $registration instanceof EE_Registration) {
3342 3342
             throw new RuntimeException(
3343 3343
                 sprintf(
3344 3344
                     esc_html__(
@@ -3477,16 +3477,16 @@  discard block
 block discarded – undo
3477 3477
         $this->verify_cpt_object();
3478 3478
         remove_meta_box(
3479 3479
             'postexcerpt',
3480
-            $this->_cpt_routes[ $this->_req_action ],
3480
+            $this->_cpt_routes[$this->_req_action],
3481 3481
             'normal'
3482 3482
         );
3483
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal');
3483
+        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal');
3484 3484
         if (post_type_supports('espresso_attendees', 'excerpt')) {
3485 3485
             $this->addMetaBox(
3486 3486
                 'postexcerpt',
3487 3487
                 esc_html__('Short Biography', 'event_espresso'),
3488 3488
                 'post_excerpt_meta_box',
3489
-                $this->_cpt_routes[ $this->_req_action ]
3489
+                $this->_cpt_routes[$this->_req_action]
3490 3490
             );
3491 3491
         }
3492 3492
         if (post_type_supports('espresso_attendees', 'comments')) {
@@ -3494,7 +3494,7 @@  discard block
 block discarded – undo
3494 3494
                 'commentsdiv',
3495 3495
                 esc_html__('Notes on the Contact', 'event_espresso'),
3496 3496
                 'post_comment_meta_box',
3497
-                $this->_cpt_routes[ $this->_req_action ],
3497
+                $this->_cpt_routes[$this->_req_action],
3498 3498
                 'normal',
3499 3499
                 'core'
3500 3500
             );
@@ -3503,7 +3503,7 @@  discard block
 block discarded – undo
3503 3503
             'attendee_contact_info',
3504 3504
             esc_html__('Contact Info', 'event_espresso'),
3505 3505
             [$this, 'attendee_contact_info'],
3506
-            $this->_cpt_routes[ $this->_req_action ],
3506
+            $this->_cpt_routes[$this->_req_action],
3507 3507
             'side',
3508 3508
             'core'
3509 3509
         );
@@ -3511,7 +3511,7 @@  discard block
 block discarded – undo
3511 3511
             'attendee_details_address',
3512 3512
             esc_html__('Address Details', 'event_espresso'),
3513 3513
             [$this, 'attendee_address_details'],
3514
-            $this->_cpt_routes[ $this->_req_action ],
3514
+            $this->_cpt_routes[$this->_req_action],
3515 3515
             'normal',
3516 3516
             'core'
3517 3517
         );
@@ -3519,7 +3519,7 @@  discard block
 block discarded – undo
3519 3519
             'attendee_registrations',
3520 3520
             esc_html__('Registrations for this Contact', 'event_espresso'),
3521 3521
             [$this, 'attendee_registrations_meta_box'],
3522
-            $this->_cpt_routes[ $this->_req_action ]
3522
+            $this->_cpt_routes[$this->_req_action]
3523 3523
         );
3524 3524
     }
3525 3525
 
@@ -3618,7 +3618,7 @@  discard block
 block discarded – undo
3618 3618
                 ]
3619 3619
             )
3620 3620
         );
3621
-        $template = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3621
+        $template = REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3622 3622
         EEH_Template::display_template($template, $this->_template_args);
3623 3623
     }
3624 3624
 
@@ -3639,7 +3639,7 @@  discard block
 block discarded – undo
3639 3639
     {
3640 3640
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
3641 3641
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3642
-        $template = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3642
+        $template = REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3643 3643
         EEH_Template::display_template($template, $this->_template_args);
3644 3644
     }
3645 3645
 
@@ -3654,7 +3654,7 @@  discard block
 block discarded – undo
3654 3654
     public function after_title_form_fields($post)
3655 3655
     {
3656 3656
         if ($post->post_type === 'espresso_attendees') {
3657
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3657
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3658 3658
             $template_args['attendee'] = $this->_cpt_model_obj;
3659 3659
             EEH_Template::display_template($template, $template_args);
3660 3660
         }
@@ -3683,7 +3683,7 @@  discard block
 block discarded – undo
3683 3683
             // cycle thru checkboxes
3684 3684
             foreach ($ATT_IDs as $ATT_ID) {
3685 3685
                 $updated = $this->getAttendeeModel()->update_by_ID(['status' => $status], $ATT_ID);
3686
-                if (! $updated) {
3686
+                if ( ! $updated) {
3687 3687
                     $success = 0;
3688 3688
                 }
3689 3689
             }
Please login to merge, or discard this patch.