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