Completed
Branch BUG/work-with-wp-41305 (460121)
by
unknown
429:02 queued 380:35
created
core/libraries/batch/JobHandlers/RegistrationsReport.php 2 patches
Indentation   +504 added lines, -504 removed lines patch added patch discarded remove patch
@@ -31,524 +31,524 @@
 block discarded – undo
31 31
  */
32 32
 class RegistrationsReport extends JobHandlerFile
33 33
 {
34
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
-    // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
-    /**
37
-     * Performs any necessary setup for starting the job. This is also a good
38
-     * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
-     * when continue_job will be called
40
-     *
41
-     * @param JobParameters $job_parameters
42
-     * @throws BatchRequestException
43
-     * @return JobStepResponse
44
-     */
45
-    public function create_job(JobParameters $job_parameters)
46
-    {
47
-        $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
-            throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
-        }
51
-        $filepath = $this->create_file_from_job_with_name(
52
-            $job_parameters->job_id(),
53
-            $this->get_filename($event_id)
54
-        );
55
-        $job_parameters->add_extra_data('filepath', $filepath);
56
-        if ($job_parameters->request_datum('use_filters', false)) {
57
-            $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
-        } else {
59
-            $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
-                array(
61
-                    'OR'                 => array(
62
-                        // don't include registrations from failed or abandoned transactions...
63
-                        'Transaction.STS_ID' => array(
64
-                            'NOT IN',
65
-                            array(
66
-                                EEM_Transaction::failed_status_code,
67
-                                EEM_Transaction::abandoned_status_code,
68
-                            ),
69
-                        ),
70
-                        // unless the registration is approved, in which case include it regardless of transaction status
71
-                        'STS_ID'             => \EEM_Registration::status_id_approved,
72
-                    ),
73
-                    'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
-                ),
75
-                'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
-                'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
-                'caps'       => \EEM_Base::caps_read_admin,
78
-            ), $event_id);
79
-            if ($event_id) {
80
-                $query_params[0]['EVT_ID'] = $event_id;
81
-            } else {
82
-                $query_params['force_join'][] = 'Event';
83
-            }
84
-        }
85
-        if (! isset($query_params['force_join'])) {
86
-            $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
-        }
88
-        $job_parameters->add_extra_data('query_params', $query_params);
89
-        $question_labels = $this->_get_question_labels($query_params);
90
-        $job_parameters->add_extra_data('question_labels', $question_labels);
91
-        $job_parameters->set_job_size(
92
-            \EEM_Registration::instance()->count(
93
-                array_diff_key(
94
-                    $query_params,
95
-                    array_flip(
96
-                        array('limit')
97
-                    )
98
-                )
99
-            )
100
-        );
101
-        // we should also set the header columns
102
-        $csv_data_for_row = $this->get_csv_data_for(
103
-            $event_id,
104
-            0,
105
-            1,
106
-            $job_parameters->extra_datum('question_labels'),
107
-            $job_parameters->extra_datum('query_params')
108
-        );
109
-        EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
-        // if we actually processed a row there, record it
111
-        if ($job_parameters->job_size()) {
112
-            $job_parameters->mark_processed(1);
113
-        }
114
-        return new JobStepResponse(
115
-            $job_parameters,
116
-            __('Registrations report started successfully...', 'event_espresso')
117
-        );
118
-    }
34
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
+	// phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
36
+	/**
37
+	 * Performs any necessary setup for starting the job. This is also a good
38
+	 * place to setup the $job_arguments which will be used for subsequent HTTP requests
39
+	 * when continue_job will be called
40
+	 *
41
+	 * @param JobParameters $job_parameters
42
+	 * @throws BatchRequestException
43
+	 * @return JobStepResponse
44
+	 */
45
+	public function create_job(JobParameters $job_parameters)
46
+	{
47
+		$event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
+		if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49
+			throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50
+		}
51
+		$filepath = $this->create_file_from_job_with_name(
52
+			$job_parameters->job_id(),
53
+			$this->get_filename($event_id)
54
+		);
55
+		$job_parameters->add_extra_data('filepath', $filepath);
56
+		if ($job_parameters->request_datum('use_filters', false)) {
57
+			$query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array())));
58
+		} else {
59
+			$query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array(
60
+				array(
61
+					'OR'                 => array(
62
+						// don't include registrations from failed or abandoned transactions...
63
+						'Transaction.STS_ID' => array(
64
+							'NOT IN',
65
+							array(
66
+								EEM_Transaction::failed_status_code,
67
+								EEM_Transaction::abandoned_status_code,
68
+							),
69
+						),
70
+						// unless the registration is approved, in which case include it regardless of transaction status
71
+						'STS_ID'             => \EEM_Registration::status_id_approved,
72
+					),
73
+					'Ticket.TKT_deleted' => array('IN', array(true, false)),
74
+				),
75
+				'order_by'   => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'),
76
+				'force_join' => array('Transaction', 'Ticket', 'Attendee'),
77
+				'caps'       => \EEM_Base::caps_read_admin,
78
+			), $event_id);
79
+			if ($event_id) {
80
+				$query_params[0]['EVT_ID'] = $event_id;
81
+			} else {
82
+				$query_params['force_join'][] = 'Event';
83
+			}
84
+		}
85
+		if (! isset($query_params['force_join'])) {
86
+			$query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87
+		}
88
+		$job_parameters->add_extra_data('query_params', $query_params);
89
+		$question_labels = $this->_get_question_labels($query_params);
90
+		$job_parameters->add_extra_data('question_labels', $question_labels);
91
+		$job_parameters->set_job_size(
92
+			\EEM_Registration::instance()->count(
93
+				array_diff_key(
94
+					$query_params,
95
+					array_flip(
96
+						array('limit')
97
+					)
98
+				)
99
+			)
100
+		);
101
+		// we should also set the header columns
102
+		$csv_data_for_row = $this->get_csv_data_for(
103
+			$event_id,
104
+			0,
105
+			1,
106
+			$job_parameters->extra_datum('question_labels'),
107
+			$job_parameters->extra_datum('query_params')
108
+		);
109
+		EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true);
110
+		// if we actually processed a row there, record it
111
+		if ($job_parameters->job_size()) {
112
+			$job_parameters->mark_processed(1);
113
+		}
114
+		return new JobStepResponse(
115
+			$job_parameters,
116
+			__('Registrations report started successfully...', 'event_espresso')
117
+		);
118
+	}
119 119
 
120 120
 
121
-    /**
122
-     * Gets the filename
123
-     *
124
-     * @return string
125
-     */
126
-    protected function get_filename()
127
-    {
128
-        return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
129
-    }
121
+	/**
122
+	 * Gets the filename
123
+	 *
124
+	 * @return string
125
+	 */
126
+	protected function get_filename()
127
+	{
128
+		return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql')));
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * Gets the questions which are to be used for this report, so they
134
-     * can be remembered for later
135
-     *
136
-     * @param array $registration_query_params
137
-     * @return array question admin labels to be used for this report
138
-     */
139
-    protected function _get_question_labels($registration_query_params)
140
-    {
141
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
142
-        $question_query_params = array();
143
-        if ($where !== null) {
144
-            $question_query_params = array(
145
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
146
-            );
147
-        }
148
-        $question_query_params[0]['QST_system'] = array(
149
-            'NOT_IN',
150
-            array_keys(EEM_Attendee::instance()->system_question_to_attendee_field_mapping()),
151
-        );
152
-        if (apply_filters(
153
-            'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
154
-            false,
155
-            $registration_query_params
156
-        )) {
157
-            $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
158
-        }
159
-        $question_query_params['group_by'] = array('QST_ID');
160
-        return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
161
-    }
132
+	/**
133
+	 * Gets the questions which are to be used for this report, so they
134
+	 * can be remembered for later
135
+	 *
136
+	 * @param array $registration_query_params
137
+	 * @return array question admin labels to be used for this report
138
+	 */
139
+	protected function _get_question_labels($registration_query_params)
140
+	{
141
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
142
+		$question_query_params = array();
143
+		if ($where !== null) {
144
+			$question_query_params = array(
145
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
146
+			);
147
+		}
148
+		$question_query_params[0]['QST_system'] = array(
149
+			'NOT_IN',
150
+			array_keys(EEM_Attendee::instance()->system_question_to_attendee_field_mapping()),
151
+		);
152
+		if (apply_filters(
153
+			'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
154
+			false,
155
+			$registration_query_params
156
+		)) {
157
+			$question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
158
+		}
159
+		$question_query_params['group_by'] = array('QST_ID');
160
+		return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
161
+	}
162 162
 
163 163
 
164
-    /**
165
-     * Takes where params meant for registrations and changes them to work for questions
166
-     *
167
-     * @param array $reg_where_params
168
-     * @return array
169
-     */
170
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
171
-    {
172
-        $question_where_params = array();
173
-        foreach ($reg_where_params as $key => $val) {
174
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
175
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
176
-            } else {
177
-                // it's a normal where condition
178
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
179
-            }
180
-        }
181
-        return $question_where_params;
182
-    }
164
+	/**
165
+	 * Takes where params meant for registrations and changes them to work for questions
166
+	 *
167
+	 * @param array $reg_where_params
168
+	 * @return array
169
+	 */
170
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
171
+	{
172
+		$question_where_params = array();
173
+		foreach ($reg_where_params as $key => $val) {
174
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
175
+				$question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
176
+			} else {
177
+				// it's a normal where condition
178
+				$question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
179
+			}
180
+		}
181
+		return $question_where_params;
182
+	}
183 183
 
184 184
 
185
-    /**
186
-     * Performs another step of the job
187
-     *
188
-     * @param JobParameters $job_parameters
189
-     * @param int           $batch_size
190
-     * @return JobStepResponse
191
-     * @throws \EE_Error
192
-     */
193
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
194
-    {
195
-        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
196
-            $csv_data = $this->get_csv_data_for(
197
-                $job_parameters->request_datum('EVT_ID', '0'),
198
-                $job_parameters->units_processed(),
199
-                $batch_size,
200
-                $job_parameters->extra_datum('question_labels'),
201
-                $job_parameters->extra_datum('query_params')
202
-            );
203
-            EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
204
-            $units_processed = count($csv_data);
205
-        } else {
206
-            $csv_data = array();
207
-            $units_processed = 0;
208
-        }
209
-        $job_parameters->mark_processed($units_processed);
210
-        $extra_response_data = array(
211
-            'file_url' => '',
212
-        );
213
-        if ($units_processed < $batch_size) {
214
-            $job_parameters->set_status(JobParameters::status_complete);
215
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
216
-        }
185
+	/**
186
+	 * Performs another step of the job
187
+	 *
188
+	 * @param JobParameters $job_parameters
189
+	 * @param int           $batch_size
190
+	 * @return JobStepResponse
191
+	 * @throws \EE_Error
192
+	 */
193
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
194
+	{
195
+		if ($job_parameters->units_processed() < $job_parameters->job_size()) {
196
+			$csv_data = $this->get_csv_data_for(
197
+				$job_parameters->request_datum('EVT_ID', '0'),
198
+				$job_parameters->units_processed(),
199
+				$batch_size,
200
+				$job_parameters->extra_datum('question_labels'),
201
+				$job_parameters->extra_datum('query_params')
202
+			);
203
+			EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
204
+			$units_processed = count($csv_data);
205
+		} else {
206
+			$csv_data = array();
207
+			$units_processed = 0;
208
+		}
209
+		$job_parameters->mark_processed($units_processed);
210
+		$extra_response_data = array(
211
+			'file_url' => '',
212
+		);
213
+		if ($units_processed < $batch_size) {
214
+			$job_parameters->set_status(JobParameters::status_complete);
215
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
216
+		}
217 217
 
218
-        return new JobStepResponse(
219
-            $job_parameters,
220
-            sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
221
-            $extra_response_data
222
-        );
223
-    }
218
+		return new JobStepResponse(
219
+			$job_parameters,
220
+			sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
221
+			$extra_response_data
222
+		);
223
+	}
224 224
 
225 225
 
226
-    /**
227
-     * Gets the csv data for a batch of registrations
228
-     *
229
-     * @param int|null $event_id
230
-     * @param int $offset
231
-     * @param int $limit
232
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
233
-     * @param array $query_params for using where querying the model
234
-     * @return array top-level keys are numeric, next-level keys are column headers
235
-     * @throws \EE_Error
236
-     */
237
-    public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
238
-    {
239
-        $reg_fields_to_include = array(
240
-            'TXN_ID',
241
-            'ATT_ID',
242
-            'REG_ID',
243
-            'REG_date',
244
-            'REG_code',
245
-            'REG_count',
246
-            'REG_final_price',
247
-        );
248
-        $att_fields_to_include = array(
249
-            'ATT_fname',
250
-            'ATT_lname',
251
-            'ATT_email',
252
-            'ATT_address',
253
-            'ATT_address2',
254
-            'ATT_city',
255
-            'STA_ID',
256
-            'CNT_ISO',
257
-            'ATT_zip',
258
-            'ATT_phone',
259
-        );
260
-        $registrations_csv_ready_array = array();
261
-        $reg_model = EE_Registry::instance()->load_model('Registration');
262
-        $query_params['limit'] = array($offset, $limit);
263
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
264
-        $registration_ids = array();
265
-        foreach ($registration_rows as $reg_row) {
266
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
267
-        }
268
-        foreach ($registration_rows as $reg_row) {
269
-            if (is_array($reg_row)) {
270
-                $reg_csv_array = array();
271
-                if (! $event_id) {
272
-                    // get the event's name and Id
273
-                    $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
274
-                        /* translators: 1: event name, 2: event ID */
275
-                        __('%1$s (%2$s)', 'event_espresso'),
276
-                        EEH_Export::prepare_value_from_db_for_display(
277
-                            EEM_Event::instance(),
278
-                            'EVT_name',
279
-                            $reg_row['Event_CPT.post_title']
280
-                        ),
281
-                        $reg_row['Event_CPT.ID']
282
-                    );
283
-                }
284
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
285
-                /*@var $reg_row EE_Registration */
286
-                foreach ($reg_fields_to_include as $field_name) {
287
-                    $field = $reg_model->field_settings_for($field_name);
288
-                    if ($field_name == 'REG_final_price') {
289
-                        $value = EEH_Export::prepare_value_from_db_for_display(
290
-                            $reg_model,
291
-                            $field_name,
292
-                            $reg_row['Registration.REG_final_price'],
293
-                            'localized_float'
294
-                        );
295
-                    } elseif ($field_name == 'REG_count') {
296
-                        $value = sprintf(
297
-                            /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
298
-                            __('%1$s of %2$s', 'event_espresso'),
299
-                            EEH_Export::prepare_value_from_db_for_display(
300
-                                $reg_model,
301
-                                'REG_count',
302
-                                $reg_row['Registration.REG_count']
303
-                            ),
304
-                            EEH_Export::prepare_value_from_db_for_display(
305
-                                $reg_model,
306
-                                'REG_group_size',
307
-                                $reg_row['Registration.REG_group_size']
308
-                            )
309
-                        );
310
-                    } elseif ($field_name == 'REG_date') {
311
-                        $value = EEH_Export::prepare_value_from_db_for_display(
312
-                            $reg_model,
313
-                            $field_name,
314
-                            $reg_row['Registration.REG_date'],
315
-                            'no_html'
316
-                        );
317
-                    } else {
318
-                        $value = EEH_Export::prepare_value_from_db_for_display(
319
-                            $reg_model,
320
-                            $field_name,
321
-                            $reg_row[ $field->get_qualified_column() ]
322
-                        );
323
-                    }
324
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
325
-                    if ($field_name == 'REG_final_price') {
326
-                        // add a column named Currency after the final price
327
-                        $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
328
-                    }
329
-                }
330
-                // get pretty status
331
-                $stati = EEM_Status::instance()->localized_status(
332
-                    array(
333
-                        $reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
334
-                        $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
335
-                    ),
336
-                    false,
337
-                    'sentence'
338
-                );
339
-                $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
340
-                // get pretty transaction status
341
-                $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
342
-                $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
343
-                    ? EEH_Export::prepare_value_from_db_for_display(
344
-                        EEM_Transaction::instance(),
345
-                        'TXN_total',
346
-                        $reg_row['TransactionTable.TXN_total'],
347
-                        'localized_float'
348
-                    ) : '0.00';
349
-                $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
350
-                    ? EEH_Export::prepare_value_from_db_for_display(
351
-                        EEM_Transaction::instance(),
352
-                        'TXN_paid',
353
-                        $reg_row['TransactionTable.TXN_paid'],
354
-                        'localized_float'
355
-                    ) : '0.00';
356
-                $payment_methods = array();
357
-                $gateway_txn_ids_etc = array();
358
-                $payment_times = array();
359
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
360
-                    $payments_info = EEM_Payment::instance()->get_all_wpdb_results(
361
-                        array(
362
-                            array(
363
-                                'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
364
-                                'STS_ID' => EEM_Payment::status_id_approved,
365
-                            ),
366
-                            'force_join' => array('Payment_Method'),
367
-                        ),
368
-                        ARRAY_A,
369
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
370
-                    );
371
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
372
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
373
-                            ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
374
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
375
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
376
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
377
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
378
-                    }
379
-                }
380
-                $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
381
-                $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
382
-                $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
383
-                    ',',
384
-                    $gateway_txn_ids_etc
385
-                );
386
-                // get whether or not the user has checked in
387
-                $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
388
-                    $reg_row['Registration.REG_ID'],
389
-                    'Checkin'
390
-                );
391
-                // get ticket of registration and its price
392
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
393
-                if ($reg_row['Ticket.TKT_ID']) {
394
-                    $ticket_name = EEH_Export::prepare_value_from_db_for_display(
395
-                        $ticket_model,
396
-                        'TKT_name',
397
-                        $reg_row['Ticket.TKT_name']
398
-                    );
399
-                    $datetimes_strings = array();
400
-                    foreach (EEM_Datetime::instance()->get_all_wpdb_results(
401
-                        array(
402
-                            array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
403
-                            'order_by'                 => array('DTT_EVT_start' => 'ASC'),
404
-                            'default_where_conditions' => 'none',
405
-                        )
406
-                    ) as $datetime) {
407
-                        $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
408
-                            EEM_Datetime::instance(),
409
-                            'DTT_EVT_start',
410
-                            $datetime['Datetime.DTT_EVT_start']
411
-                        );
412
-                    }
413
-                } else {
414
-                    $ticket_name = __('Unknown', 'event_espresso');
415
-                    $datetimes_strings = array(__('Unknown', 'event_espresso'));
416
-                }
417
-                $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
418
-                $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
419
-                // get datetime(s) of registration
420
-                // add attendee columns
421
-                foreach ($att_fields_to_include as $att_field_name) {
422
-                    $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
423
-                    if ($reg_row['Attendee_CPT.ID']) {
424
-                        if ($att_field_name == 'STA_ID') {
425
-                            $value = EEM_State::instance()->get_var(
426
-                                array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
427
-                                'STA_name'
428
-                            );
429
-                        } elseif ($att_field_name == 'CNT_ISO') {
430
-                            $value = EEM_Country::instance()->get_var(
431
-                                array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
432
-                                'CNT_name'
433
-                            );
434
-                        } else {
435
-                            $value = EEH_Export::prepare_value_from_db_for_display(
436
-                                EEM_Attendee::instance(),
437
-                                $att_field_name,
438
-                                $reg_row[ $field_obj->get_qualified_column() ]
439
-                            );
440
-                        }
441
-                    } else {
442
-                        $value = '';
443
-                    }
444
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
445
-                }
446
-                // make sure each registration has the same questions in the same order
447
-                foreach ($question_labels as $question_label) {
448
-                    if (! isset($reg_csv_array[ $question_label ])) {
449
-                        $reg_csv_array[ $question_label ] = null;
450
-                    }
451
-                }
452
-                $answers = EEM_Answer::instance()->get_all_wpdb_results(array(
453
-                    array('REG_ID' => $reg_row['Registration.REG_ID']),
454
-                    'force_join' => array('Question'),
455
-                ));
456
-                // now fill out the questions THEY answered
457
-                foreach ($answers as $answer_row) {
458
-                    if ($answer_row['Question.QST_ID']) {
459
-                        $question_label = EEH_Export::prepare_value_from_db_for_display(
460
-                            EEM_Question::instance(),
461
-                            'QST_admin_label',
462
-                            $answer_row['Question.QST_admin_label']
463
-                        );
464
-                    } else {
465
-                        $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
466
-                    }
467
-                    if (isset($answer_row['Question.QST_type'])
468
-                        && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
469
-                    ) {
470
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
471
-                            $answer_row['Answer.ANS_value']
472
-                        );
473
-                    } else {
474
-                        // this isn't for html, so don't show html entities
475
-                        $reg_csv_array[ $question_label ] = html_entity_decode(
476
-                            EEH_Export::prepare_value_from_db_for_display(
477
-                                EEM_Answer::instance(),
478
-                                'ANS_value',
479
-                                $answer_row['Answer.ANS_value']
480
-                            )
481
-                        );
482
-                    }
483
-                }
226
+	/**
227
+	 * Gets the csv data for a batch of registrations
228
+	 *
229
+	 * @param int|null $event_id
230
+	 * @param int $offset
231
+	 * @param int $limit
232
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
233
+	 * @param array $query_params for using where querying the model
234
+	 * @return array top-level keys are numeric, next-level keys are column headers
235
+	 * @throws \EE_Error
236
+	 */
237
+	public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
238
+	{
239
+		$reg_fields_to_include = array(
240
+			'TXN_ID',
241
+			'ATT_ID',
242
+			'REG_ID',
243
+			'REG_date',
244
+			'REG_code',
245
+			'REG_count',
246
+			'REG_final_price',
247
+		);
248
+		$att_fields_to_include = array(
249
+			'ATT_fname',
250
+			'ATT_lname',
251
+			'ATT_email',
252
+			'ATT_address',
253
+			'ATT_address2',
254
+			'ATT_city',
255
+			'STA_ID',
256
+			'CNT_ISO',
257
+			'ATT_zip',
258
+			'ATT_phone',
259
+		);
260
+		$registrations_csv_ready_array = array();
261
+		$reg_model = EE_Registry::instance()->load_model('Registration');
262
+		$query_params['limit'] = array($offset, $limit);
263
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
264
+		$registration_ids = array();
265
+		foreach ($registration_rows as $reg_row) {
266
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
267
+		}
268
+		foreach ($registration_rows as $reg_row) {
269
+			if (is_array($reg_row)) {
270
+				$reg_csv_array = array();
271
+				if (! $event_id) {
272
+					// get the event's name and Id
273
+					$reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
274
+						/* translators: 1: event name, 2: event ID */
275
+						__('%1$s (%2$s)', 'event_espresso'),
276
+						EEH_Export::prepare_value_from_db_for_display(
277
+							EEM_Event::instance(),
278
+							'EVT_name',
279
+							$reg_row['Event_CPT.post_title']
280
+						),
281
+						$reg_row['Event_CPT.ID']
282
+					);
283
+				}
284
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
285
+				/*@var $reg_row EE_Registration */
286
+				foreach ($reg_fields_to_include as $field_name) {
287
+					$field = $reg_model->field_settings_for($field_name);
288
+					if ($field_name == 'REG_final_price') {
289
+						$value = EEH_Export::prepare_value_from_db_for_display(
290
+							$reg_model,
291
+							$field_name,
292
+							$reg_row['Registration.REG_final_price'],
293
+							'localized_float'
294
+						);
295
+					} elseif ($field_name == 'REG_count') {
296
+						$value = sprintf(
297
+							/* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
298
+							__('%1$s of %2$s', 'event_espresso'),
299
+							EEH_Export::prepare_value_from_db_for_display(
300
+								$reg_model,
301
+								'REG_count',
302
+								$reg_row['Registration.REG_count']
303
+							),
304
+							EEH_Export::prepare_value_from_db_for_display(
305
+								$reg_model,
306
+								'REG_group_size',
307
+								$reg_row['Registration.REG_group_size']
308
+							)
309
+						);
310
+					} elseif ($field_name == 'REG_date') {
311
+						$value = EEH_Export::prepare_value_from_db_for_display(
312
+							$reg_model,
313
+							$field_name,
314
+							$reg_row['Registration.REG_date'],
315
+							'no_html'
316
+						);
317
+					} else {
318
+						$value = EEH_Export::prepare_value_from_db_for_display(
319
+							$reg_model,
320
+							$field_name,
321
+							$reg_row[ $field->get_qualified_column() ]
322
+						);
323
+					}
324
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
325
+					if ($field_name == 'REG_final_price') {
326
+						// add a column named Currency after the final price
327
+						$reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
328
+					}
329
+				}
330
+				// get pretty status
331
+				$stati = EEM_Status::instance()->localized_status(
332
+					array(
333
+						$reg_row['Registration.STS_ID']     => __('unknown', 'event_espresso'),
334
+						$reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'),
335
+					),
336
+					false,
337
+					'sentence'
338
+				);
339
+				$reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
340
+				// get pretty transaction status
341
+				$reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
342
+				$reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
343
+					? EEH_Export::prepare_value_from_db_for_display(
344
+						EEM_Transaction::instance(),
345
+						'TXN_total',
346
+						$reg_row['TransactionTable.TXN_total'],
347
+						'localized_float'
348
+					) : '0.00';
349
+				$reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
350
+					? EEH_Export::prepare_value_from_db_for_display(
351
+						EEM_Transaction::instance(),
352
+						'TXN_paid',
353
+						$reg_row['TransactionTable.TXN_paid'],
354
+						'localized_float'
355
+					) : '0.00';
356
+				$payment_methods = array();
357
+				$gateway_txn_ids_etc = array();
358
+				$payment_times = array();
359
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
360
+					$payments_info = EEM_Payment::instance()->get_all_wpdb_results(
361
+						array(
362
+							array(
363
+								'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
364
+								'STS_ID' => EEM_Payment::status_id_approved,
365
+							),
366
+							'force_join' => array('Payment_Method'),
367
+						),
368
+						ARRAY_A,
369
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
370
+					);
371
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
372
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
373
+							? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso');
374
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
375
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
376
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
377
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
378
+					}
379
+				}
380
+				$reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
381
+				$reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
382
+				$reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
383
+					',',
384
+					$gateway_txn_ids_etc
385
+				);
386
+				// get whether or not the user has checked in
387
+				$reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
388
+					$reg_row['Registration.REG_ID'],
389
+					'Checkin'
390
+				);
391
+				// get ticket of registration and its price
392
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
393
+				if ($reg_row['Ticket.TKT_ID']) {
394
+					$ticket_name = EEH_Export::prepare_value_from_db_for_display(
395
+						$ticket_model,
396
+						'TKT_name',
397
+						$reg_row['Ticket.TKT_name']
398
+					);
399
+					$datetimes_strings = array();
400
+					foreach (EEM_Datetime::instance()->get_all_wpdb_results(
401
+						array(
402
+							array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']),
403
+							'order_by'                 => array('DTT_EVT_start' => 'ASC'),
404
+							'default_where_conditions' => 'none',
405
+						)
406
+					) as $datetime) {
407
+						$datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
408
+							EEM_Datetime::instance(),
409
+							'DTT_EVT_start',
410
+							$datetime['Datetime.DTT_EVT_start']
411
+						);
412
+					}
413
+				} else {
414
+					$ticket_name = __('Unknown', 'event_espresso');
415
+					$datetimes_strings = array(__('Unknown', 'event_espresso'));
416
+				}
417
+				$reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
418
+				$reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
419
+				// get datetime(s) of registration
420
+				// add attendee columns
421
+				foreach ($att_fields_to_include as $att_field_name) {
422
+					$field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
423
+					if ($reg_row['Attendee_CPT.ID']) {
424
+						if ($att_field_name == 'STA_ID') {
425
+							$value = EEM_State::instance()->get_var(
426
+								array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])),
427
+								'STA_name'
428
+							);
429
+						} elseif ($att_field_name == 'CNT_ISO') {
430
+							$value = EEM_Country::instance()->get_var(
431
+								array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])),
432
+								'CNT_name'
433
+							);
434
+						} else {
435
+							$value = EEH_Export::prepare_value_from_db_for_display(
436
+								EEM_Attendee::instance(),
437
+								$att_field_name,
438
+								$reg_row[ $field_obj->get_qualified_column() ]
439
+							);
440
+						}
441
+					} else {
442
+						$value = '';
443
+					}
444
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
445
+				}
446
+				// make sure each registration has the same questions in the same order
447
+				foreach ($question_labels as $question_label) {
448
+					if (! isset($reg_csv_array[ $question_label ])) {
449
+						$reg_csv_array[ $question_label ] = null;
450
+					}
451
+				}
452
+				$answers = EEM_Answer::instance()->get_all_wpdb_results(array(
453
+					array('REG_ID' => $reg_row['Registration.REG_ID']),
454
+					'force_join' => array('Question'),
455
+				));
456
+				// now fill out the questions THEY answered
457
+				foreach ($answers as $answer_row) {
458
+					if ($answer_row['Question.QST_ID']) {
459
+						$question_label = EEH_Export::prepare_value_from_db_for_display(
460
+							EEM_Question::instance(),
461
+							'QST_admin_label',
462
+							$answer_row['Question.QST_admin_label']
463
+						);
464
+					} else {
465
+						$question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
466
+					}
467
+					if (isset($answer_row['Question.QST_type'])
468
+						&& $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
469
+					) {
470
+						$reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
471
+							$answer_row['Answer.ANS_value']
472
+						);
473
+					} else {
474
+						// this isn't for html, so don't show html entities
475
+						$reg_csv_array[ $question_label ] = html_entity_decode(
476
+							EEH_Export::prepare_value_from_db_for_display(
477
+								EEM_Answer::instance(),
478
+								'ANS_value',
479
+								$answer_row['Answer.ANS_value']
480
+							)
481
+						);
482
+					}
483
+				}
484 484
 
485
-                /**
486
-                 * Filter to change the contents of each row of the registrations report CSV file.
487
-                 * This can be used to add or remote columns from the CSV file, or change their values.
488
-                 * Note when using: all rows in the CSV should have the same columns.
489
-                 * @param array $reg_csv_array keys are the column names, values are their cell values
490
-                 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
491
-                 */
492
-                $registrations_csv_ready_array[] = apply_filters(
493
-                    'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
494
-                    $reg_csv_array,
495
-                    $reg_row
496
-                );
497
-            }
498
-        }
499
-        // if we couldn't export anything, we want to at least show the column headers
500
-        if (empty($registrations_csv_ready_array)) {
501
-            $reg_csv_array = array();
502
-            $model_and_fields_to_include = array(
503
-                'Registration' => $reg_fields_to_include,
504
-                'Attendee'     => $att_fields_to_include,
505
-            );
506
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
507
-                $model = EE_Registry::instance()->load_model($model_name);
508
-                foreach ($field_list as $field_name) {
509
-                    $field = $model->field_settings_for($field_name);
510
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
511
-                }
512
-            }
513
-            $registrations_csv_ready_array[] = $reg_csv_array;
514
-        }
515
-        return $registrations_csv_ready_array;
516
-    }
485
+				/**
486
+				 * Filter to change the contents of each row of the registrations report CSV file.
487
+				 * This can be used to add or remote columns from the CSV file, or change their values.
488
+				 * Note when using: all rows in the CSV should have the same columns.
489
+				 * @param array $reg_csv_array keys are the column names, values are their cell values
490
+				 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
491
+				 */
492
+				$registrations_csv_ready_array[] = apply_filters(
493
+					'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
494
+					$reg_csv_array,
495
+					$reg_row
496
+				);
497
+			}
498
+		}
499
+		// if we couldn't export anything, we want to at least show the column headers
500
+		if (empty($registrations_csv_ready_array)) {
501
+			$reg_csv_array = array();
502
+			$model_and_fields_to_include = array(
503
+				'Registration' => $reg_fields_to_include,
504
+				'Attendee'     => $att_fields_to_include,
505
+			);
506
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
507
+				$model = EE_Registry::instance()->load_model($model_name);
508
+				foreach ($field_list as $field_name) {
509
+					$field = $model->field_settings_for($field_name);
510
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
511
+				}
512
+			}
513
+			$registrations_csv_ready_array[] = $reg_csv_array;
514
+		}
515
+		return $registrations_csv_ready_array;
516
+	}
517 517
 
518 518
 
519
-    /**
520
-     * Counts total unit to process
521
-     *
522
-     * @deprecated since 4.9.19
523
-     * @param int|array $event_id
524
-     * @return int
525
-     */
526
-    public function count_units_to_process($event_id)
527
-    {
528
-        // use the legacy filter
529
-        if ($event_id) {
530
-            $query_params[0]['EVT_ID'] = $event_id;
531
-        } else {
532
-            $query_params['force_join'][] = 'Event';
533
-        }
534
-        return \EEM_Registration::instance()->count($query_params);
535
-    }
519
+	/**
520
+	 * Counts total unit to process
521
+	 *
522
+	 * @deprecated since 4.9.19
523
+	 * @param int|array $event_id
524
+	 * @return int
525
+	 */
526
+	public function count_units_to_process($event_id)
527
+	{
528
+		// use the legacy filter
529
+		if ($event_id) {
530
+			$query_params[0]['EVT_ID'] = $event_id;
531
+		} else {
532
+			$query_params['force_join'][] = 'Event';
533
+		}
534
+		return \EEM_Registration::instance()->count($query_params);
535
+	}
536 536
 
537 537
 
538
-    /**
539
-     * Performs any clean-up logic when we know the job is completed.
540
-     * In this case, we delete the temporary file
541
-     *
542
-     * @param JobParameters $job_parameters
543
-     * @return boolean
544
-     */
545
-    public function cleanup_job(JobParameters $job_parameters)
546
-    {
547
-        $this->_file_helper->delete(
548
-            \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
549
-            true,
550
-            'd'
551
-        );
552
-        return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
553
-    }
538
+	/**
539
+	 * Performs any clean-up logic when we know the job is completed.
540
+	 * In this case, we delete the temporary file
541
+	 *
542
+	 * @param JobParameters $job_parameters
543
+	 * @return boolean
544
+	 */
545
+	public function cleanup_job(JobParameters $job_parameters)
546
+	{
547
+		$this->_file_helper->delete(
548
+			\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
549
+			true,
550
+			'd'
551
+		);
552
+		return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso'));
553
+	}
554 554
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     public function create_job(JobParameters $job_parameters)
46 46
     {
47 47
         $event_id = intval($job_parameters->request_datum('EVT_ID', '0'));
48
-        if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
48
+        if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) {
49 49
             throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso'));
50 50
         }
51 51
         $filepath = $this->create_file_from_job_with_name(
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                 $query_params['force_join'][] = 'Event';
83 83
             }
84 84
         }
85
-        if (! isset($query_params['force_join'])) {
85
+        if ( ! isset($query_params['force_join'])) {
86 86
             $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee');
87 87
         }
88 88
         $job_parameters->add_extra_data('query_params', $query_params);
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
         $question_where_params = array();
173 173
         foreach ($reg_where_params as $key => $val) {
174 174
             if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
175
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
175
+                $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
176 176
             } else {
177 177
                 // it's a normal where condition
178
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
178
+                $question_where_params['Question_Group.Event.Registration.'.$key] = $val;
179 179
             }
180 180
         }
181 181
         return $question_where_params;
@@ -268,9 +268,9 @@  discard block
 block discarded – undo
268 268
         foreach ($registration_rows as $reg_row) {
269 269
             if (is_array($reg_row)) {
270 270
                 $reg_csv_array = array();
271
-                if (! $event_id) {
271
+                if ( ! $event_id) {
272 272
                     // get the event's name and Id
273
-                    $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf(
273
+                    $reg_csv_array[(string) __('Event', 'event_espresso')] = sprintf(
274 274
                         /* translators: 1: event name, 2: event ID */
275 275
                         __('%1$s (%2$s)', 'event_espresso'),
276 276
                         EEH_Export::prepare_value_from_db_for_display(
@@ -318,13 +318,13 @@  discard block
 block discarded – undo
318 318
                         $value = EEH_Export::prepare_value_from_db_for_display(
319 319
                             $reg_model,
320 320
                             $field_name,
321
-                            $reg_row[ $field->get_qualified_column() ]
321
+                            $reg_row[$field->get_qualified_column()]
322 322
                         );
323 323
                     }
324
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
324
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = $value;
325 325
                     if ($field_name == 'REG_final_price') {
326 326
                         // add a column named Currency after the final price
327
-                        $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
327
+                        $reg_csv_array[(string) __("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
328 328
                     }
329 329
                 }
330 330
                 // get pretty status
@@ -336,17 +336,17 @@  discard block
 block discarded – undo
336 336
                     false,
337 337
                     'sentence'
338 338
                 );
339
-                $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
339
+                $reg_csv_array[(string) __("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
340 340
                 // get pretty transaction status
341
-                $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
342
-                $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
341
+                $reg_csv_array[(string) __("Transaction Status", 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
342
+                $reg_csv_array[(string) __('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
343 343
                     ? EEH_Export::prepare_value_from_db_for_display(
344 344
                         EEM_Transaction::instance(),
345 345
                         'TXN_total',
346 346
                         $reg_row['TransactionTable.TXN_total'],
347 347
                         'localized_float'
348 348
                     ) : '0.00';
349
-                $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg
349
+                $reg_csv_array[(string) __('Amount Paid', 'event_espresso')] = $is_primary_reg
350 350
                     ? EEH_Export::prepare_value_from_db_for_display(
351 351
                         EEM_Transaction::instance(),
352 352
                         'TXN_paid',
@@ -377,14 +377,14 @@  discard block
 block discarded – undo
377 377
                             ? $payment_method_and_gateway_txn_id['payment_time'] : '';
378 378
                     }
379 379
                 }
380
-                $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
381
-                $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
382
-                $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
380
+                $reg_csv_array[(string) __('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
381
+                $reg_csv_array[(string) __('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
382
+                $reg_csv_array[(string) __('Gateway Transaction ID(s)', 'event_espresso')] = implode(
383 383
                     ',',
384 384
                     $gateway_txn_ids_etc
385 385
                 );
386 386
                 // get whether or not the user has checked in
387
-                $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related(
387
+                $reg_csv_array[(string) __("Check-Ins", "event_espresso")] = $reg_model->count_related(
388 388
                     $reg_row['Registration.REG_ID'],
389 389
                     'Checkin'
390 390
                 );
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
                     $ticket_name = __('Unknown', 'event_espresso');
415 415
                     $datetimes_strings = array(__('Unknown', 'event_espresso'));
416 416
                 }
417
-                $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
418
-                $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
417
+                $reg_csv_array[(string) $ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
418
+                $reg_csv_array[(string) __("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
419 419
                 // get datetime(s) of registration
420 420
                 // add attendee columns
421 421
                 foreach ($att_fields_to_include as $att_field_name) {
@@ -435,18 +435,18 @@  discard block
 block discarded – undo
435 435
                             $value = EEH_Export::prepare_value_from_db_for_display(
436 436
                                 EEM_Attendee::instance(),
437 437
                                 $att_field_name,
438
-                                $reg_row[ $field_obj->get_qualified_column() ]
438
+                                $reg_row[$field_obj->get_qualified_column()]
439 439
                             );
440 440
                         }
441 441
                     } else {
442 442
                         $value = '';
443 443
                     }
444
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
444
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field_obj)] = $value;
445 445
                 }
446 446
                 // make sure each registration has the same questions in the same order
447 447
                 foreach ($question_labels as $question_label) {
448
-                    if (! isset($reg_csv_array[ $question_label ])) {
449
-                        $reg_csv_array[ $question_label ] = null;
448
+                    if ( ! isset($reg_csv_array[$question_label])) {
449
+                        $reg_csv_array[$question_label] = null;
450 450
                     }
451 451
                 }
452 452
                 $answers = EEM_Answer::instance()->get_all_wpdb_results(array(
@@ -467,12 +467,12 @@  discard block
 block discarded – undo
467 467
                     if (isset($answer_row['Question.QST_type'])
468 468
                         && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
469 469
                     ) {
470
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
470
+                        $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID(
471 471
                             $answer_row['Answer.ANS_value']
472 472
                         );
473 473
                     } else {
474 474
                         // this isn't for html, so don't show html entities
475
-                        $reg_csv_array[ $question_label ] = html_entity_decode(
475
+                        $reg_csv_array[$question_label] = html_entity_decode(
476 476
                             EEH_Export::prepare_value_from_db_for_display(
477 477
                                 EEM_Answer::instance(),
478 478
                                 'ANS_value',
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
                 $model = EE_Registry::instance()->load_model($model_name);
508 508
                 foreach ($field_list as $field_name) {
509 509
                     $field = $model->field_settings_for($field_name);
510
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
510
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null;
511 511
                 }
512 512
             }
513 513
             $registrations_csv_ready_array[] = $reg_csv_array;
Please login to merge, or discard this patch.