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

Add filter hooks for Inbound Messages CSV export #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
48 changes: 33 additions & 15 deletions includes/csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,35 +143,53 @@ public function print_data() {
return;
}

$labels = array_keys( $items[0]->fields );

echo flamingo_csv_row(
array_merge( $labels, array( __( 'Date', 'flamingo' ) ) )
$form_field_keys = array_keys( $items[0]->fields );

// Print header
$csv_header = array_merge(
array(
'id' => __( 'ID', 'flamingo' ),
'date' => __( 'Date', 'flamingo' )
),
array_combine( $form_field_keys, $form_field_keys )
);
$csv_header = apply_filters( 'flamingo_inbound_csv_header', $csv_header, $items );

echo flamingo_csv_row( $csv_header );

// Print items
$template_row = array_fill_keys( array_keys( $csv_header ), '' );

foreach ( $items as $item ) {
echo "\r\n";

$row = array();
$row = $template_row;

foreach ( $labels as $label ) {
$col = isset( $item->fields[$label] ) ? $item->fields[$label] : '';
// Iterate form fields
foreach ( $form_field_keys as $field_key ) {

if ( is_array( $col ) ) {
$col = flamingo_array_flatten( $col );
$col = array_filter( array_map( 'trim', $col ) );
$col = implode( ', ', $col );
}
if ( array_key_exists( $field_key, $row ) ) {

$col = isset( $item->fields[ $field_key ] ) ? $item->fields[ $field_key ] : '';

$row[] = $col;
if ( is_array( $col ) ) {
$col = flamingo_array_flatten( $col );
$col = array_filter( array_map( 'trim', $col ) );
$col = implode( ', ', $col );
}

$row[ $field_key ] = $col;
}
}

$row[] = get_post_time( 'c', false, $item->id() ); // Date
$row['id'] = $item->id(); // Post ID
$row['date'] = get_post_time( 'c', false, $item->id() ); // Date

$row = apply_filters( 'flamingo_inbound_csv_item', $row, $item, $csv_header );

echo flamingo_csv_row( $row );
}
}

}


Expand Down