Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - Format likert field data in seperate column wise while exporting entry #1332

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions includes/export/class-evf-entry-csv-exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,18 @@
if ( ! empty( $form_data['form_fields'] ) ) {
foreach ( $form_data['form_fields'] as $field ) {
if ( ! in_array( $field['type'], array( 'html', 'title', 'captcha', 'divider' ), true ) ) {
$columns[ $field['id'] ] = evf_clean( $field['label'] );
switch ( $field['type'] ) {
case 'likert':
$field_id = $field['id'];
foreach ( $field['likert_rows'] as $key => $col_row ) {
$col_row_key = "$field_id-likert-$key";
$columns[ $col_row_key ] = $col_row;
}
break;
default:
$columns[ $field['id'] ] = evf_clean( $field['label'] );
break;
}
}
}
}
Expand Down Expand Up @@ -267,12 +278,17 @@
* @return array
*/
protected function generate_row_data( $entry ) {

$columns = $this->get_column_names();
$row = array();
$fields = json_decode( $entry->fields, true );
foreach ( $columns as $column_id => $column_name ) {
$column_id = strstr( $column_id, ':' ) ? current( explode( ':', $column_id ) ) : $column_id;
$position = strpos( $column_id, '-likert-' );

if ( $position !== false ) {

Check failure on line 288 in includes/export/class-evf-entry-csv-exporter.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4 , WP Latest)

Use Yoda Condition checks, you must.
$column_id = substr( $column_id, 0, $position );
}

$value = '';
$raw_value = '';

Expand Down Expand Up @@ -368,6 +384,28 @@
}
}
break;
case 'likert':
$form = evf()->form->get( $entry->form_id );
$form_data = evf_decode( $form->post_content );
$form_fields = $form_data['form_fields'];
$form_field = '';
$selected_likert = array();
if ( array_key_exists( $column_id, $form_fields ) ) {
$form_field = $form_fields[ $column_id ];
$likert_columns = $form_field['likert_columns'];
$likert_rows = $form_field['likert_rows'];
if ( ! empty( $fields[ $column_id ]['value_raw'] ) ) {
foreach ( $fields[ $column_id ]['value_raw'] as $likert_key ) {
$selected_likert[] = $likert_columns[ $likert_key ];
}
} else {
foreach ( $likert_rows as $likert_rows ) {
$selected_likert[] = '';
}
}
}
$value = $selected_likert;
break;
default:
$value = apply_filters( 'everest_forms_html_field_value', $fields[ $column_id ]['value'], $fields[ $column_id ], $entry, 'export-csv' );
break;
Expand All @@ -377,8 +415,16 @@
$value = $this->{"get_column_value_{$column_id}"}( $entry );
$raw_value = $value;
}
$column_type = $this->get_entry_type( $column_id, $entry );
$row[ $column_id ] = apply_filters( 'everest_forms_format_csv_field_data', preg_match( '/textarea/', $column_type ) ? sanitize_textarea_field( $value ) : sanitize_text_field( $value ), $raw_value, $column_id, $column_name, $columns, $entry );
$column_type = $this->get_entry_type( $column_id, $entry );
if ( is_array( $value ) && isset( $fields[ $column_id ], $fields[ $column_id ]['type'] ) && in_array( $fields[ $column_id ]['type'], array( 'likert' ), true ) ) {
foreach ( $value as $key => $val ) {
$key = $key + 1;

Check failure on line 421 in includes/export/class-evf-entry-csv-exporter.php

View workflow job for this annotation

GitHub Actions / Code sniff (PHP 7.4 , WP Latest)

Increment operators should be used where possible; found "$key = $key + 1;" but expected "++$key"
$col_row_key = "$column_id-likert-$key";
$row[ $col_row_key ] = $val;
}
} else {
$row[ $column_id ] = apply_filters( 'everest_forms_format_csv_field_data', preg_match( '/textarea/', $column_type ) ? sanitize_textarea_field( $value ) : $value, $raw_value, $column_id, $column_name, $columns, $entry );
}
if ( empty( $this->request_data ) ) {
$row['status'] = (
isset( $entry->meta['status'] ) && ! empty( $entry->meta['status'] )
Expand Down
Loading