Completed
Branch feature/checkins-to-csv (902377)
by
unknown
12:52 queued 10:47
created
core/libraries/batch/JobHandlers/RegistrationsReport.php 2 patches
Indentation   +555 added lines, -555 removed lines patch added patch discarded remove patch
@@ -31,575 +31,575 @@
 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(esc_html__('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($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
-            esc_html__('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(esc_html__('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($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
+			esc_html__('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 apply_filters(
129
-            'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
130
-            sprintf(
131
-                "event-espresso-registrations-%s.csv",
132
-                str_replace(array(':', ' '), '-', current_time('mysql'))
133
-            )
134
-        );
135
-    }
121
+	/**
122
+	 * Gets the filename
123
+	 *
124
+	 * @return string
125
+	 */
126
+	protected function get_filename()
127
+	{
128
+		return apply_filters(
129
+			'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename',
130
+			sprintf(
131
+				"event-espresso-registrations-%s.csv",
132
+				str_replace(array(':', ' '), '-', current_time('mysql'))
133
+			)
134
+		);
135
+	}
136 136
 
137 137
 
138
-    /**
139
-     * Gets the questions which are to be used for this report, so they
140
-     * can be remembered for later
141
-     *
142
-     * @param array $registration_query_params
143
-     * @return array question admin labels to be used for this report
144
-     */
145
-    protected function _get_question_labels($registration_query_params)
146
-    {
147
-        $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
148
-        $question_query_params = array();
149
-        if ($where !== null) {
150
-            $question_query_params = array(
151
-                $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
152
-            );
153
-        }
154
-        // Make sure it's not a system question
155
-        $question_query_params[0]['OR*not-system-questions'] = [
156
-            'QST_system' => '',
157
-            'QST_system*null' => ['IS_NULL']
158
-        ];
159
-        if (
160
-            apply_filters(
161
-                'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
162
-                false,
163
-                $registration_query_params
164
-            )
165
-        ) {
166
-            $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
167
-        }
168
-        $question_query_params['group_by'] = array('QST_ID');
169
-        return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
170
-    }
138
+	/**
139
+	 * Gets the questions which are to be used for this report, so they
140
+	 * can be remembered for later
141
+	 *
142
+	 * @param array $registration_query_params
143
+	 * @return array question admin labels to be used for this report
144
+	 */
145
+	protected function _get_question_labels($registration_query_params)
146
+	{
147
+		$where = isset($registration_query_params[0]) ? $registration_query_params[0] : null;
148
+		$question_query_params = array();
149
+		if ($where !== null) {
150
+			$question_query_params = array(
151
+				$this->_change_registration_where_params_to_question_where_params($registration_query_params[0]),
152
+			);
153
+		}
154
+		// Make sure it's not a system question
155
+		$question_query_params[0]['OR*not-system-questions'] = [
156
+			'QST_system' => '',
157
+			'QST_system*null' => ['IS_NULL']
158
+		];
159
+		if (
160
+			apply_filters(
161
+				'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions',
162
+				false,
163
+				$registration_query_params
164
+			)
165
+		) {
166
+			$question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL');
167
+		}
168
+		$question_query_params['group_by'] = array('QST_ID');
169
+		return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label'));
170
+	}
171 171
 
172 172
 
173
-    /**
174
-     * Takes where params meant for registrations and changes them to work for questions
175
-     *
176
-     * @param array $reg_where_params
177
-     * @return array
178
-     */
179
-    protected function _change_registration_where_params_to_question_where_params($reg_where_params)
180
-    {
181
-        $question_where_params = array();
182
-        foreach ($reg_where_params as $key => $val) {
183
-            if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
184
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
185
-            } else {
186
-                // it's a normal where condition
187
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
188
-            }
189
-        }
190
-        return $question_where_params;
191
-    }
173
+	/**
174
+	 * Takes where params meant for registrations and changes them to work for questions
175
+	 *
176
+	 * @param array $reg_where_params
177
+	 * @return array
178
+	 */
179
+	protected function _change_registration_where_params_to_question_where_params($reg_where_params)
180
+	{
181
+		$question_where_params = array();
182
+		foreach ($reg_where_params as $key => $val) {
183
+			if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
184
+				$question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
185
+			} else {
186
+				// it's a normal where condition
187
+				$question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
188
+			}
189
+		}
190
+		return $question_where_params;
191
+	}
192 192
 
193 193
 
194
-    /**
195
-     * Performs another step of the job
196
-     *
197
-     * @param JobParameters $job_parameters
198
-     * @param int           $batch_size
199
-     * @return JobStepResponse
200
-     * @throws \EE_Error
201
-     */
202
-    public function continue_job(JobParameters $job_parameters, $batch_size = 50)
203
-    {
204
-        if ($job_parameters->units_processed() < $job_parameters->job_size()) {
205
-            $csv_data = $this->get_csv_data_for(
206
-                $job_parameters->request_datum('EVT_ID', '0'),
207
-                $job_parameters->units_processed(),
208
-                $batch_size,
209
-                $job_parameters->extra_datum('question_labels'),
210
-                $job_parameters->extra_datum('query_params')
211
-            );
212
-            EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
213
-            $units_processed = count($csv_data);
214
-        } else {
215
-            $csv_data = array();
216
-            $units_processed = 0;
217
-        }
218
-        $job_parameters->mark_processed($units_processed);
219
-        $extra_response_data = array(
220
-            'file_url' => '',
221
-        );
222
-        if ($units_processed < $batch_size) {
223
-            $job_parameters->set_status(JobParameters::status_complete);
224
-            $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
225
-        }
194
+	/**
195
+	 * Performs another step of the job
196
+	 *
197
+	 * @param JobParameters $job_parameters
198
+	 * @param int           $batch_size
199
+	 * @return JobStepResponse
200
+	 * @throws \EE_Error
201
+	 */
202
+	public function continue_job(JobParameters $job_parameters, $batch_size = 50)
203
+	{
204
+		if ($job_parameters->units_processed() < $job_parameters->job_size()) {
205
+			$csv_data = $this->get_csv_data_for(
206
+				$job_parameters->request_datum('EVT_ID', '0'),
207
+				$job_parameters->units_processed(),
208
+				$batch_size,
209
+				$job_parameters->extra_datum('question_labels'),
210
+				$job_parameters->extra_datum('query_params')
211
+			);
212
+			EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false);
213
+			$units_processed = count($csv_data);
214
+		} else {
215
+			$csv_data = array();
216
+			$units_processed = 0;
217
+		}
218
+		$job_parameters->mark_processed($units_processed);
219
+		$extra_response_data = array(
220
+			'file_url' => '',
221
+		);
222
+		if ($units_processed < $batch_size) {
223
+			$job_parameters->set_status(JobParameters::status_complete);
224
+			$extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath'));
225
+		}
226 226
 
227
-        return new JobStepResponse(
228
-            $job_parameters,
229
-            sprintf(esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
230
-            $extra_response_data
231
-        );
232
-    }
227
+		return new JobStepResponse(
228
+			$job_parameters,
229
+			sprintf(esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)),
230
+			$extra_response_data
231
+		);
232
+	}
233 233
 
234 234
 
235
-    /**
236
-     * Gets the csv data for a batch of registrations
237
-     *
238
-     * @param int|null $event_id
239
-     * @param int $offset
240
-     * @param int $limit
241
-     * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
242
-     * @param array $query_params for using where querying the model
243
-     * @return array top-level keys are numeric, next-level keys are column headers
244
-     * @throws \EE_Error
245
-     */
246
-    public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
247
-    {
248
-        $reg_fields_to_include = [
249
-            'TXN_ID',
250
-            'ATT_ID',
251
-            'REG_ID',
252
-            'REG_date',
253
-            'REG_code',
254
-            'REG_count',
255
-            'REG_final_price',
256
-        ];
257
-        $att_fields_to_include = [
258
-            'ATT_fname',
259
-            'ATT_lname',
260
-            'ATT_email',
261
-            'ATT_address',
262
-            'ATT_address2',
263
-            'ATT_city',
264
-            'STA_ID',
265
-            'CNT_ISO',
266
-            'ATT_zip',
267
-            'ATT_phone',
268
-        ];
269
-        $registrations_csv_ready_array = [];
270
-        $reg_model = EE_Registry::instance()->load_model('Registration');
271
-        $query_params['limit'] = [$offset, $limit];
272
-        $registration_rows = $reg_model->get_all_wpdb_results($query_params);
273
-        $registration_ids = [];
274
-        foreach ($registration_rows as $reg_row) {
275
-            $registration_ids[] = intval($reg_row['Registration.REG_ID']);
276
-        }
277
-        foreach ($registration_rows as $reg_row) {
278
-            if (is_array($reg_row)) {
279
-                $reg_csv_array = [];
280
-                if (! $event_id) {
281
-                    // get the event's name and Id
282
-                    $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf(
283
-                        /* translators: 1: event name, 2: event ID */
284
-                        esc_html__('%1$s (%2$s)', 'event_espresso'),
285
-                        EEH_Export::prepare_value_from_db_for_display(
286
-                            EEM_Event::instance(),
287
-                            'EVT_name',
288
-                            $reg_row['Event_CPT.post_title']
289
-                        ),
290
-                        $reg_row['Event_CPT.ID']
291
-                    );
292
-                }
293
-                $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
294
-                /*@var $reg_row EE_Registration */
295
-                foreach ($reg_fields_to_include as $field_name) {
296
-                    $field = $reg_model->field_settings_for($field_name);
297
-                    if ($field_name == 'REG_final_price') {
298
-                        $value = EEH_Export::prepare_value_from_db_for_display(
299
-                            $reg_model,
300
-                            $field_name,
301
-                            $reg_row['Registration.REG_final_price'],
302
-                            'localized_float'
303
-                        );
304
-                    } elseif ($field_name == 'REG_count') {
305
-                        $value = sprintf(
306
-                            /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
307
-                            esc_html__('%1$s of %2$s', 'event_espresso'),
308
-                            EEH_Export::prepare_value_from_db_for_display(
309
-                                $reg_model,
310
-                                'REG_count',
311
-                                $reg_row['Registration.REG_count']
312
-                            ),
313
-                            EEH_Export::prepare_value_from_db_for_display(
314
-                                $reg_model,
315
-                                'REG_group_size',
316
-                                $reg_row['Registration.REG_group_size']
317
-                            )
318
-                        );
319
-                    } elseif ($field_name == 'REG_date') {
320
-                        $value = EEH_Export::prepare_value_from_db_for_display(
321
-                            $reg_model,
322
-                            $field_name,
323
-                            $reg_row['Registration.REG_date'],
324
-                            'no_html'
325
-                        );
326
-                    } else {
327
-                        $value = EEH_Export::prepare_value_from_db_for_display(
328
-                            $reg_model,
329
-                            $field_name,
330
-                            $reg_row[ $field->get_qualified_column() ]
331
-                        );
332
-                    }
333
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
334
-                    if ($field_name == 'REG_final_price') {
335
-                        // add a column named Currency after the final price
336
-                        $reg_csv_array[ (string) esc_html__("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
337
-                    }
338
-                }
339
-                // get pretty status
340
-                $stati = EEM_Status::instance()->localized_status(
341
-                    [
342
-                        $reg_row['Registration.STS_ID']     => esc_html__('unknown', 'event_espresso'),
343
-                        $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'),
344
-                    ],
345
-                    false,
346
-                    'sentence'
347
-                );
348
-                $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
349
-                // get pretty transaction status
350
-                $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
351
-                $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
352
-                    ? EEH_Export::prepare_value_from_db_for_display(
353
-                        EEM_Transaction::instance(),
354
-                        'TXN_total',
355
-                        $reg_row['TransactionTable.TXN_total'],
356
-                        'localized_float'
357
-                    ) : '0.00';
358
-                $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg
359
-                    ? EEH_Export::prepare_value_from_db_for_display(
360
-                        EEM_Transaction::instance(),
361
-                        'TXN_paid',
362
-                        $reg_row['TransactionTable.TXN_paid'],
363
-                        'localized_float'
364
-                    ) : '0.00';
365
-                $payment_methods = [];
366
-                $gateway_txn_ids_etc = [];
367
-                $payment_times = [];
368
-                if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
369
-                    $payments_info = EEM_Payment::instance()->get_all_wpdb_results(
370
-                        [
371
-                            [
372
-                                'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
373
-                                'STS_ID' => EEM_Payment::status_id_approved,
374
-                            ],
375
-                            'force_join' => ['Payment_Method'],
376
-                        ],
377
-                        ARRAY_A,
378
-                        'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
379
-                    );
380
-                    foreach ($payments_info as $payment_method_and_gateway_txn_id) {
381
-                        $payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
382
-                            ? $payment_method_and_gateway_txn_id['name'] : esc_html__('Unknown', 'event_espresso');
383
-                        $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
384
-                            ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
385
-                        $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
386
-                            ? $payment_method_and_gateway_txn_id['payment_time'] : '';
387
-                    }
388
-                }
389
-                $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
390
-                $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
391
-                $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
392
-                    ',',
393
-                    $gateway_txn_ids_etc
394
-                );
395
-                // get whether or not the user has checked in
396
-                $reg_csv_array[ (string) esc_html__('Check-Ins', 'event_espresso') ] = $reg_model->count_related(
397
-                    $reg_row['Registration.REG_ID'],
398
-                    'Checkin'
399
-                );
400
-                $checkin_rows = (array) \EEM_Checkin::instance()->get_all_wpdb_results(
401
-                    [
402
-                        [
403
-                            'REG_ID' => $reg_row['Registration.REG_ID'],
404
-                        ],
405
-                    ]
406
-                );
407
-                $checkins_for_csv_col = [];
408
-                $datetime_checkins_for_csv_col = [];
409
-                foreach ($checkin_rows as $checkin_row) {
410
-                    $checkins_for_csv_col[] = $checkin_row['Checkin.CHK_timestamp'];
411
-                    $checkin_for_dtt_id = $checkin_row['Checkin.DTT_ID'];
412
-                    $checkin_for_dtt_name = \EEM_Datetime::instance()->get_var(
413
-                        [
414
-                            ['DTT_ID' => $checkin_for_dtt_id]
415
-                        ],
416
-                        'DTT_name'
417
-                    );
418
-                    $datetime_checkins_for_csv_col[] = $checkin_for_dtt_name ?
419
-                        $checkin_for_dtt_name . ' - ID ' . $checkin_for_dtt_id :
420
-                        $checkin_for_dtt_id;
421
-                }
422
-                $reg_csv_array[ (string) esc_html__('Check-In for Datetime(s)', 'event_espresso') ] = implode(
423
-                    ' + ',
424
-                    $datetime_checkins_for_csv_col
425
-                );
426
-                $reg_csv_array[ (string) esc_html__('Check-In Time(s)', 'event_espresso') ] = implode(
427
-                    ' + ',
428
-                    $checkins_for_csv_col
429
-                );
430
-                // get ticket of registration and its price
431
-                $ticket_model = EE_Registry::instance()->load_model('Ticket');
432
-                if ($reg_row['Ticket.TKT_ID']) {
433
-                    $ticket_name = EEH_Export::prepare_value_from_db_for_display(
434
-                        $ticket_model,
435
-                        'TKT_name',
436
-                        $reg_row['Ticket.TKT_name']
437
-                    );
438
-                    $datetimes_strings = [];
439
-                    foreach (
440
-                        EEM_Datetime::instance()->get_all_wpdb_results(
441
-                            [
442
-                                ['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']],
443
-                                'order_by' => ['DTT_EVT_start' => 'ASC'],
444
-                                'default_where_conditions' => 'none',
445
-                            ]
446
-                        ) as $datetime
447
-                    ) {
448
-                        $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
449
-                            EEM_Datetime::instance(),
450
-                            'DTT_EVT_start',
451
-                            $datetime['Datetime.DTT_EVT_start']
452
-                        );
453
-                    }
454
-                } else {
455
-                    $ticket_name = esc_html__('Unknown', 'event_espresso');
456
-                    $datetimes_strings = [esc_html__('Unknown', 'event_espresso')];
457
-                }
458
-                $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
459
-                $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
460
-                // get datetime(s) of registration
461
-                // add attendee columns
462
-                foreach ($att_fields_to_include as $att_field_name) {
463
-                    $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
464
-                    if ($reg_row['Attendee_CPT.ID']) {
465
-                        if ($att_field_name == 'STA_ID') {
466
-                            $value = EEM_State::instance()->get_var(
467
-                                [
468
-                                    ['STA_ID' => $reg_row['Attendee_Meta.STA_ID']]
469
-                                ],
470
-                                'STA_name'
471
-                            );
472
-                        } elseif ($att_field_name == 'CNT_ISO') {
473
-                            $value = EEM_Country::instance()->get_var(
474
-                                [
475
-                                    ['CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO']]
476
-                                ],
477
-                                'CNT_name'
478
-                            );
479
-                        } else {
480
-                            $value = EEH_Export::prepare_value_from_db_for_display(
481
-                                EEM_Attendee::instance(),
482
-                                $att_field_name,
483
-                                $reg_row[ $field_obj->get_qualified_column() ]
484
-                            );
485
-                        }
486
-                    } else {
487
-                        $value = '';
488
-                    }
489
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
490
-                }
491
-                // make sure each registration has the same questions in the same order
492
-                foreach ($question_labels as $question_label) {
493
-                    if (! isset($reg_csv_array[ $question_label ])) {
494
-                        $reg_csv_array[ $question_label ] = null;
495
-                    }
496
-                }
497
-                $answers = EEM_Answer::instance()->get_all_wpdb_results([
498
-                    ['REG_ID' => $reg_row['Registration.REG_ID']],
499
-                    'force_join' => ['Question'],
500
-                ]);
501
-                // now fill out the questions THEY answered
502
-                foreach ($answers as $answer_row) {
503
-                    if ($answer_row['Question.QST_system']) {
504
-                        // it's an answer to a system question. That was already displayed as part of the attendee
505
-                        // fields, so don't write it out again thanks.
506
-                        continue;
507
-                    }
508
-                    if ($answer_row['Question.QST_ID']) {
509
-                        $question_label = EEH_Export::prepare_value_from_db_for_display(
510
-                            EEM_Question::instance(),
511
-                            'QST_admin_label',
512
-                            $answer_row['Question.QST_admin_label']
513
-                        );
514
-                    } else {
515
-                        $question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
516
-                    }
517
-                    if (
518
-                        isset($answer_row['Question.QST_type'])
519
-                        && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
520
-                    ) {
521
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
522
-                            $answer_row['Answer.ANS_value']
523
-                        );
524
-                    } else {
525
-                        // this isn't for html, so don't show html entities
526
-                        $reg_csv_array[ $question_label ] = html_entity_decode(
527
-                            EEH_Export::prepare_value_from_db_for_display(
528
-                                EEM_Answer::instance(),
529
-                                'ANS_value',
530
-                                $answer_row['Answer.ANS_value']
531
-                            )
532
-                        );
533
-                    }
534
-                }
235
+	/**
236
+	 * Gets the csv data for a batch of registrations
237
+	 *
238
+	 * @param int|null $event_id
239
+	 * @param int $offset
240
+	 * @param int $limit
241
+	 * @param array $question_labels the IDs for all the questions which were answered by someone in this selection
242
+	 * @param array $query_params for using where querying the model
243
+	 * @return array top-level keys are numeric, next-level keys are column headers
244
+	 * @throws \EE_Error
245
+	 */
246
+	public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params)
247
+	{
248
+		$reg_fields_to_include = [
249
+			'TXN_ID',
250
+			'ATT_ID',
251
+			'REG_ID',
252
+			'REG_date',
253
+			'REG_code',
254
+			'REG_count',
255
+			'REG_final_price',
256
+		];
257
+		$att_fields_to_include = [
258
+			'ATT_fname',
259
+			'ATT_lname',
260
+			'ATT_email',
261
+			'ATT_address',
262
+			'ATT_address2',
263
+			'ATT_city',
264
+			'STA_ID',
265
+			'CNT_ISO',
266
+			'ATT_zip',
267
+			'ATT_phone',
268
+		];
269
+		$registrations_csv_ready_array = [];
270
+		$reg_model = EE_Registry::instance()->load_model('Registration');
271
+		$query_params['limit'] = [$offset, $limit];
272
+		$registration_rows = $reg_model->get_all_wpdb_results($query_params);
273
+		$registration_ids = [];
274
+		foreach ($registration_rows as $reg_row) {
275
+			$registration_ids[] = intval($reg_row['Registration.REG_ID']);
276
+		}
277
+		foreach ($registration_rows as $reg_row) {
278
+			if (is_array($reg_row)) {
279
+				$reg_csv_array = [];
280
+				if (! $event_id) {
281
+					// get the event's name and Id
282
+					$reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf(
283
+						/* translators: 1: event name, 2: event ID */
284
+						esc_html__('%1$s (%2$s)', 'event_espresso'),
285
+						EEH_Export::prepare_value_from_db_for_display(
286
+							EEM_Event::instance(),
287
+							'EVT_name',
288
+							$reg_row['Event_CPT.post_title']
289
+						),
290
+						$reg_row['Event_CPT.ID']
291
+					);
292
+				}
293
+				$is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false;
294
+				/*@var $reg_row EE_Registration */
295
+				foreach ($reg_fields_to_include as $field_name) {
296
+					$field = $reg_model->field_settings_for($field_name);
297
+					if ($field_name == 'REG_final_price') {
298
+						$value = EEH_Export::prepare_value_from_db_for_display(
299
+							$reg_model,
300
+							$field_name,
301
+							$reg_row['Registration.REG_final_price'],
302
+							'localized_float'
303
+						);
304
+					} elseif ($field_name == 'REG_count') {
305
+						$value = sprintf(
306
+							/* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */
307
+							esc_html__('%1$s of %2$s', 'event_espresso'),
308
+							EEH_Export::prepare_value_from_db_for_display(
309
+								$reg_model,
310
+								'REG_count',
311
+								$reg_row['Registration.REG_count']
312
+							),
313
+							EEH_Export::prepare_value_from_db_for_display(
314
+								$reg_model,
315
+								'REG_group_size',
316
+								$reg_row['Registration.REG_group_size']
317
+							)
318
+						);
319
+					} elseif ($field_name == 'REG_date') {
320
+						$value = EEH_Export::prepare_value_from_db_for_display(
321
+							$reg_model,
322
+							$field_name,
323
+							$reg_row['Registration.REG_date'],
324
+							'no_html'
325
+						);
326
+					} else {
327
+						$value = EEH_Export::prepare_value_from_db_for_display(
328
+							$reg_model,
329
+							$field_name,
330
+							$reg_row[ $field->get_qualified_column() ]
331
+						);
332
+					}
333
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
334
+					if ($field_name == 'REG_final_price') {
335
+						// add a column named Currency after the final price
336
+						$reg_csv_array[ (string) esc_html__("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
337
+					}
338
+				}
339
+				// get pretty status
340
+				$stati = EEM_Status::instance()->localized_status(
341
+					[
342
+						$reg_row['Registration.STS_ID']     => esc_html__('unknown', 'event_espresso'),
343
+						$reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'),
344
+					],
345
+					false,
346
+					'sentence'
347
+				);
348
+				$reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
349
+				// get pretty transaction status
350
+				$reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
351
+				$reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
352
+					? EEH_Export::prepare_value_from_db_for_display(
353
+						EEM_Transaction::instance(),
354
+						'TXN_total',
355
+						$reg_row['TransactionTable.TXN_total'],
356
+						'localized_float'
357
+					) : '0.00';
358
+				$reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg
359
+					? EEH_Export::prepare_value_from_db_for_display(
360
+						EEM_Transaction::instance(),
361
+						'TXN_paid',
362
+						$reg_row['TransactionTable.TXN_paid'],
363
+						'localized_float'
364
+					) : '0.00';
365
+				$payment_methods = [];
366
+				$gateway_txn_ids_etc = [];
367
+				$payment_times = [];
368
+				if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) {
369
+					$payments_info = EEM_Payment::instance()->get_all_wpdb_results(
370
+						[
371
+							[
372
+								'TXN_ID' => $reg_row['TransactionTable.TXN_ID'],
373
+								'STS_ID' => EEM_Payment::status_id_approved,
374
+							],
375
+							'force_join' => ['Payment_Method'],
376
+						],
377
+						ARRAY_A,
378
+						'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'
379
+					);
380
+					foreach ($payments_info as $payment_method_and_gateway_txn_id) {
381
+						$payment_methods[] = isset($payment_method_and_gateway_txn_id['name'])
382
+							? $payment_method_and_gateway_txn_id['name'] : esc_html__('Unknown', 'event_espresso');
383
+						$gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id'])
384
+							? $payment_method_and_gateway_txn_id['gateway_txn_id'] : '';
385
+						$payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time'])
386
+							? $payment_method_and_gateway_txn_id['payment_time'] : '';
387
+					}
388
+				}
389
+				$reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
390
+				$reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
391
+				$reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
392
+					',',
393
+					$gateway_txn_ids_etc
394
+				);
395
+				// get whether or not the user has checked in
396
+				$reg_csv_array[ (string) esc_html__('Check-Ins', 'event_espresso') ] = $reg_model->count_related(
397
+					$reg_row['Registration.REG_ID'],
398
+					'Checkin'
399
+				);
400
+				$checkin_rows = (array) \EEM_Checkin::instance()->get_all_wpdb_results(
401
+					[
402
+						[
403
+							'REG_ID' => $reg_row['Registration.REG_ID'],
404
+						],
405
+					]
406
+				);
407
+				$checkins_for_csv_col = [];
408
+				$datetime_checkins_for_csv_col = [];
409
+				foreach ($checkin_rows as $checkin_row) {
410
+					$checkins_for_csv_col[] = $checkin_row['Checkin.CHK_timestamp'];
411
+					$checkin_for_dtt_id = $checkin_row['Checkin.DTT_ID'];
412
+					$checkin_for_dtt_name = \EEM_Datetime::instance()->get_var(
413
+						[
414
+							['DTT_ID' => $checkin_for_dtt_id]
415
+						],
416
+						'DTT_name'
417
+					);
418
+					$datetime_checkins_for_csv_col[] = $checkin_for_dtt_name ?
419
+						$checkin_for_dtt_name . ' - ID ' . $checkin_for_dtt_id :
420
+						$checkin_for_dtt_id;
421
+				}
422
+				$reg_csv_array[ (string) esc_html__('Check-In for Datetime(s)', 'event_espresso') ] = implode(
423
+					' + ',
424
+					$datetime_checkins_for_csv_col
425
+				);
426
+				$reg_csv_array[ (string) esc_html__('Check-In Time(s)', 'event_espresso') ] = implode(
427
+					' + ',
428
+					$checkins_for_csv_col
429
+				);
430
+				// get ticket of registration and its price
431
+				$ticket_model = EE_Registry::instance()->load_model('Ticket');
432
+				if ($reg_row['Ticket.TKT_ID']) {
433
+					$ticket_name = EEH_Export::prepare_value_from_db_for_display(
434
+						$ticket_model,
435
+						'TKT_name',
436
+						$reg_row['Ticket.TKT_name']
437
+					);
438
+					$datetimes_strings = [];
439
+					foreach (
440
+						EEM_Datetime::instance()->get_all_wpdb_results(
441
+							[
442
+								['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']],
443
+								'order_by' => ['DTT_EVT_start' => 'ASC'],
444
+								'default_where_conditions' => 'none',
445
+							]
446
+						) as $datetime
447
+					) {
448
+						$datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display(
449
+							EEM_Datetime::instance(),
450
+							'DTT_EVT_start',
451
+							$datetime['Datetime.DTT_EVT_start']
452
+						);
453
+					}
454
+				} else {
455
+					$ticket_name = esc_html__('Unknown', 'event_espresso');
456
+					$datetimes_strings = [esc_html__('Unknown', 'event_espresso')];
457
+				}
458
+				$reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
459
+				$reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
460
+				// get datetime(s) of registration
461
+				// add attendee columns
462
+				foreach ($att_fields_to_include as $att_field_name) {
463
+					$field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name);
464
+					if ($reg_row['Attendee_CPT.ID']) {
465
+						if ($att_field_name == 'STA_ID') {
466
+							$value = EEM_State::instance()->get_var(
467
+								[
468
+									['STA_ID' => $reg_row['Attendee_Meta.STA_ID']]
469
+								],
470
+								'STA_name'
471
+							);
472
+						} elseif ($att_field_name == 'CNT_ISO') {
473
+							$value = EEM_Country::instance()->get_var(
474
+								[
475
+									['CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO']]
476
+								],
477
+								'CNT_name'
478
+							);
479
+						} else {
480
+							$value = EEH_Export::prepare_value_from_db_for_display(
481
+								EEM_Attendee::instance(),
482
+								$att_field_name,
483
+								$reg_row[ $field_obj->get_qualified_column() ]
484
+							);
485
+						}
486
+					} else {
487
+						$value = '';
488
+					}
489
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
490
+				}
491
+				// make sure each registration has the same questions in the same order
492
+				foreach ($question_labels as $question_label) {
493
+					if (! isset($reg_csv_array[ $question_label ])) {
494
+						$reg_csv_array[ $question_label ] = null;
495
+					}
496
+				}
497
+				$answers = EEM_Answer::instance()->get_all_wpdb_results([
498
+					['REG_ID' => $reg_row['Registration.REG_ID']],
499
+					'force_join' => ['Question'],
500
+				]);
501
+				// now fill out the questions THEY answered
502
+				foreach ($answers as $answer_row) {
503
+					if ($answer_row['Question.QST_system']) {
504
+						// it's an answer to a system question. That was already displayed as part of the attendee
505
+						// fields, so don't write it out again thanks.
506
+						continue;
507
+					}
508
+					if ($answer_row['Question.QST_ID']) {
509
+						$question_label = EEH_Export::prepare_value_from_db_for_display(
510
+							EEM_Question::instance(),
511
+							'QST_admin_label',
512
+							$answer_row['Question.QST_admin_label']
513
+						);
514
+					} else {
515
+						$question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']);
516
+					}
517
+					if (
518
+						isset($answer_row['Question.QST_type'])
519
+						&& $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
520
+					) {
521
+						$reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
522
+							$answer_row['Answer.ANS_value']
523
+						);
524
+					} else {
525
+						// this isn't for html, so don't show html entities
526
+						$reg_csv_array[ $question_label ] = html_entity_decode(
527
+							EEH_Export::prepare_value_from_db_for_display(
528
+								EEM_Answer::instance(),
529
+								'ANS_value',
530
+								$answer_row['Answer.ANS_value']
531
+							)
532
+						);
533
+					}
534
+				}
535 535
 
536
-                /**
537
-                 * Filter to change the contents of each row of the registrations report CSV file.
538
-                 * This can be used to add or remote columns from the CSV file, or change their values.
539
-                 * Note when using: all rows in the CSV should have the same columns.
540
-                 * @param array $reg_csv_array keys are the column names, values are their cell values
541
-                 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
542
-                 */
543
-                $registrations_csv_ready_array[] = apply_filters(
544
-                    'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
545
-                    $reg_csv_array,
546
-                    $reg_row
547
-                );
548
-            }
549
-        }
550
-        // if we couldn't export anything, we want to at least show the column headers
551
-        if (empty($registrations_csv_ready_array)) {
552
-            $reg_csv_array = [];
553
-            $model_and_fields_to_include = [
554
-                'Registration' => $reg_fields_to_include,
555
-                'Attendee'     => $att_fields_to_include,
556
-            ];
557
-            foreach ($model_and_fields_to_include as $model_name => $field_list) {
558
-                $model = EE_Registry::instance()->load_model($model_name);
559
-                foreach ($field_list as $field_name) {
560
-                    $field = $model->field_settings_for($field_name);
561
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
562
-                }
563
-            }
564
-            $registrations_csv_ready_array[] = $reg_csv_array;
565
-        }
566
-        return $registrations_csv_ready_array;
567
-    }
536
+				/**
537
+				 * Filter to change the contents of each row of the registrations report CSV file.
538
+				 * This can be used to add or remote columns from the CSV file, or change their values.
539
+				 * Note when using: all rows in the CSV should have the same columns.
540
+				 * @param array $reg_csv_array keys are the column names, values are their cell values
541
+				 * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results()
542
+				 */
543
+				$registrations_csv_ready_array[] = apply_filters(
544
+					'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
545
+					$reg_csv_array,
546
+					$reg_row
547
+				);
548
+			}
549
+		}
550
+		// if we couldn't export anything, we want to at least show the column headers
551
+		if (empty($registrations_csv_ready_array)) {
552
+			$reg_csv_array = [];
553
+			$model_and_fields_to_include = [
554
+				'Registration' => $reg_fields_to_include,
555
+				'Attendee'     => $att_fields_to_include,
556
+			];
557
+			foreach ($model_and_fields_to_include as $model_name => $field_list) {
558
+				$model = EE_Registry::instance()->load_model($model_name);
559
+				foreach ($field_list as $field_name) {
560
+					$field = $model->field_settings_for($field_name);
561
+					$reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
562
+				}
563
+			}
564
+			$registrations_csv_ready_array[] = $reg_csv_array;
565
+		}
566
+		return $registrations_csv_ready_array;
567
+	}
568 568
 
569 569
 
570
-    /**
571
-     * Counts total unit to process
572
-     *
573
-     * @deprecated since 4.9.19
574
-     * @param int|array $event_id
575
-     * @return int
576
-     */
577
-    public function count_units_to_process($event_id)
578
-    {
579
-        // use the legacy filter
580
-        if ($event_id) {
581
-            $query_params[0]['EVT_ID'] = $event_id;
582
-        } else {
583
-            $query_params['force_join'][] = 'Event';
584
-        }
585
-        return \EEM_Registration::instance()->count($query_params);
586
-    }
570
+	/**
571
+	 * Counts total unit to process
572
+	 *
573
+	 * @deprecated since 4.9.19
574
+	 * @param int|array $event_id
575
+	 * @return int
576
+	 */
577
+	public function count_units_to_process($event_id)
578
+	{
579
+		// use the legacy filter
580
+		if ($event_id) {
581
+			$query_params[0]['EVT_ID'] = $event_id;
582
+		} else {
583
+			$query_params['force_join'][] = 'Event';
584
+		}
585
+		return \EEM_Registration::instance()->count($query_params);
586
+	}
587 587
 
588 588
 
589
-    /**
590
-     * Performs any clean-up logic when we know the job is completed.
591
-     * In this case, we delete the temporary file
592
-     *
593
-     * @param JobParameters $job_parameters
594
-     * @return boolean
595
-     */
596
-    public function cleanup_job(JobParameters $job_parameters)
597
-    {
598
-        $this->_file_helper->delete(
599
-            \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
600
-            true,
601
-            'd'
602
-        );
603
-        return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso'));
604
-    }
589
+	/**
590
+	 * Performs any clean-up logic when we know the job is completed.
591
+	 * In this case, we delete the temporary file
592
+	 *
593
+	 * @param JobParameters $job_parameters
594
+	 * @return boolean
595
+	 */
596
+	public function cleanup_job(JobParameters $job_parameters)
597
+	{
598
+		$this->_file_helper->delete(
599
+			\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')),
600
+			true,
601
+			'd'
602
+		);
603
+		return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso'));
604
+	}
605 605
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -30 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(esc_html__('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);
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
         $question_where_params = array();
182 182
         foreach ($reg_where_params as $key => $val) {
183 183
             if (\EEM_Registration::instance()->is_logic_query_param_key($key)) {
184
-                $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val);
184
+                $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val);
185 185
             } else {
186 186
                 // it's a normal where condition
187
-                $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val;
187
+                $question_where_params['Question_Group.Event.Registration.'.$key] = $val;
188 188
             }
189 189
         }
190 190
         return $question_where_params;
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
         foreach ($registration_rows as $reg_row) {
278 278
             if (is_array($reg_row)) {
279 279
                 $reg_csv_array = [];
280
-                if (! $event_id) {
280
+                if ( ! $event_id) {
281 281
                     // get the event's name and Id
282
-                    $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf(
282
+                    $reg_csv_array[(string) esc_html__('Event', 'event_espresso')] = sprintf(
283 283
                         /* translators: 1: event name, 2: event ID */
284 284
                         esc_html__('%1$s (%2$s)', 'event_espresso'),
285 285
                         EEH_Export::prepare_value_from_db_for_display(
@@ -327,13 +327,13 @@  discard block
 block discarded – undo
327 327
                         $value = EEH_Export::prepare_value_from_db_for_display(
328 328
                             $reg_model,
329 329
                             $field_name,
330
-                            $reg_row[ $field->get_qualified_column() ]
330
+                            $reg_row[$field->get_qualified_column()]
331 331
                         );
332 332
                     }
333
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value;
333
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = $value;
334 334
                     if ($field_name == 'REG_final_price') {
335 335
                         // add a column named Currency after the final price
336
-                        $reg_csv_array[ (string) esc_html__("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code;
336
+                        $reg_csv_array[(string) esc_html__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code;
337 337
                     }
338 338
                 }
339 339
                 // get pretty status
@@ -345,17 +345,17 @@  discard block
 block discarded – undo
345 345
                     false,
346 346
                     'sentence'
347 347
                 );
348
-                $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ];
348
+                $reg_csv_array[(string) esc_html__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']];
349 349
                 // get pretty transaction status
350
-                $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ];
351
-                $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg
350
+                $reg_csv_array[(string) esc_html__("Transaction Status", 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']];
351
+                $reg_csv_array[(string) esc_html__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg
352 352
                     ? EEH_Export::prepare_value_from_db_for_display(
353 353
                         EEM_Transaction::instance(),
354 354
                         'TXN_total',
355 355
                         $reg_row['TransactionTable.TXN_total'],
356 356
                         'localized_float'
357 357
                     ) : '0.00';
358
-                $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg
358
+                $reg_csv_array[(string) esc_html__('Amount Paid', 'event_espresso')] = $is_primary_reg
359 359
                     ? EEH_Export::prepare_value_from_db_for_display(
360 360
                         EEM_Transaction::instance(),
361 361
                         'TXN_paid',
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
                             ? $payment_method_and_gateway_txn_id['payment_time'] : '';
387 387
                     }
388 388
                 }
389
-                $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times);
390
-                $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods);
391
-                $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode(
389
+                $reg_csv_array[(string) esc_html__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times);
390
+                $reg_csv_array[(string) esc_html__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods);
391
+                $reg_csv_array[(string) esc_html__('Gateway Transaction ID(s)', 'event_espresso')] = implode(
392 392
                     ',',
393 393
                     $gateway_txn_ids_etc
394 394
                 );
395 395
                 // get whether or not the user has checked in
396
-                $reg_csv_array[ (string) esc_html__('Check-Ins', 'event_espresso') ] = $reg_model->count_related(
396
+                $reg_csv_array[(string) esc_html__('Check-Ins', 'event_espresso')] = $reg_model->count_related(
397 397
                     $reg_row['Registration.REG_ID'],
398 398
                     'Checkin'
399 399
                 );
@@ -416,14 +416,13 @@  discard block
 block discarded – undo
416 416
                         'DTT_name'
417 417
                     );
418 418
                     $datetime_checkins_for_csv_col[] = $checkin_for_dtt_name ?
419
-                        $checkin_for_dtt_name . ' - ID ' . $checkin_for_dtt_id :
420
-                        $checkin_for_dtt_id;
419
+                        $checkin_for_dtt_name.' - ID '.$checkin_for_dtt_id : $checkin_for_dtt_id;
421 420
                 }
422
-                $reg_csv_array[ (string) esc_html__('Check-In for Datetime(s)', 'event_espresso') ] = implode(
421
+                $reg_csv_array[(string) esc_html__('Check-In for Datetime(s)', 'event_espresso')] = implode(
423 422
                     ' + ',
424 423
                     $datetime_checkins_for_csv_col
425 424
                 );
426
-                $reg_csv_array[ (string) esc_html__('Check-In Time(s)', 'event_espresso') ] = implode(
425
+                $reg_csv_array[(string) esc_html__('Check-In Time(s)', 'event_espresso')] = implode(
427 426
                     ' + ',
428 427
                     $checkins_for_csv_col
429 428
                 );
@@ -455,8 +454,8 @@  discard block
 block discarded – undo
455 454
                     $ticket_name = esc_html__('Unknown', 'event_espresso');
456 455
                     $datetimes_strings = [esc_html__('Unknown', 'event_espresso')];
457 456
                 }
458
-                $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name;
459
-                $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings);
457
+                $reg_csv_array[(string) $ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name;
458
+                $reg_csv_array[(string) esc_html__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings);
460 459
                 // get datetime(s) of registration
461 460
                 // add attendee columns
462 461
                 foreach ($att_fields_to_include as $att_field_name) {
@@ -480,18 +479,18 @@  discard block
 block discarded – undo
480 479
                             $value = EEH_Export::prepare_value_from_db_for_display(
481 480
                                 EEM_Attendee::instance(),
482 481
                                 $att_field_name,
483
-                                $reg_row[ $field_obj->get_qualified_column() ]
482
+                                $reg_row[$field_obj->get_qualified_column()]
484 483
                             );
485 484
                         }
486 485
                     } else {
487 486
                         $value = '';
488 487
                     }
489
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value;
488
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field_obj)] = $value;
490 489
                 }
491 490
                 // make sure each registration has the same questions in the same order
492 491
                 foreach ($question_labels as $question_label) {
493
-                    if (! isset($reg_csv_array[ $question_label ])) {
494
-                        $reg_csv_array[ $question_label ] = null;
492
+                    if ( ! isset($reg_csv_array[$question_label])) {
493
+                        $reg_csv_array[$question_label] = null;
495 494
                     }
496 495
                 }
497 496
                 $answers = EEM_Answer::instance()->get_all_wpdb_results([
@@ -518,12 +517,12 @@  discard block
 block discarded – undo
518 517
                         isset($answer_row['Question.QST_type'])
519 518
                         && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state
520 519
                     ) {
521
-                        $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID(
520
+                        $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID(
522 521
                             $answer_row['Answer.ANS_value']
523 522
                         );
524 523
                     } else {
525 524
                         // this isn't for html, so don't show html entities
526
-                        $reg_csv_array[ $question_label ] = html_entity_decode(
525
+                        $reg_csv_array[$question_label] = html_entity_decode(
527 526
                             EEH_Export::prepare_value_from_db_for_display(
528 527
                                 EEM_Answer::instance(),
529 528
                                 'ANS_value',
@@ -558,7 +557,7 @@  discard block
 block discarded – undo
558 557
                 $model = EE_Registry::instance()->load_model($model_name);
559 558
                 foreach ($field_list as $field_name) {
560 559
                     $field = $model->field_settings_for($field_name);
561
-                    $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null;
560
+                    $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null;
562 561
                 }
563 562
             }
564 563
             $registrations_csv_ready_array[] = $reg_csv_array;
Please login to merge, or discard this patch.