Support

Home Forums Event Espresso Premium CSV Exports Issues – No Event Name or Exporting All Registrations

CSV Exports Issues – No Event Name or Exporting All Registrations

Posted: April 11, 2018 at 8:22 am


bld_espresso

April 11, 2018 at 8:22 am

Hello,
I’m running into another issue with CSV export that I apparently just didn’t notice earlier. I’m not sure if the issue is related to this previous topic: https://eventespresso.com/topic/custom-ordered-csv-columns-issue/

When exporting the CSV from a specific event (Navigating to Events > Click Registrations under the event I would like to export data for), the two buttons are both behaving in unexpected ways. The first button (Event Registrations CSV Report) is exporting the expected dataset of all the registrations for the event but is NOT filling out the column for the event name: ( ‘Event’, ‘event_espresso’ ), however the second button (Filtered CSV Report) does export with the event name column filled. I would just tell my client to use the filtered export functionality in that case but the Filtered CSV Report is also exporting ALL registrations on the system (not just the registrations for the event that is selected.)

Is these issues related to column ordering? Is there some way to get the event name differently so that the column will populate on the normal CSV report? I don’t really care that much about the filtered CSV report not behaving as I expect if I can resolve the event name issue for the normal CSV export.

Here is the code used for re-order / filtering of the columns being exported.

function tw_ee_espresso_reg_report_filter_columns_ordered( $csv_row, $registration_db_row ) {
	//Set the allowed fields here and also set them in the order you want them to be displayed within the CSV
	$allowed_fields_in_order = array(
		__( 'Registration ID', 'event_espresso' ) . '[REG_ID]',
		__( 'Event', 'event_espresso' ),
		__( 'affiliated-membership', 'event_espresso' ),
		__( 'Ticket Name', 'event_espresso' ),
		__( 'First Name', 'event_espresso' ) . '[ATT_fname]',
		__( 'middle_initial', 'event_espresso' ),
		__( 'Last Name', 'event_espresso' ) . '[ATT_lname]',
		__( 'Email Address', 'event_espresso' ) . '[ATT_email]',
		__( 'county_official', 'event_espresso' ),
		__( 'county', 'event_espresso' ),
		__( 'title', 'event_espresso' ),
		__( 'employer', 'event_espresso' ),
		__( 'departmentdivision', 'event_espresso' ),
		__( 'gluten-free', 'event_espresso' ),
		__( 'vegetarian', 'event_espresso' ),
		__( 'vegan', 'event_espresso' ),
		__( 'authorizing_name', 'event_espresso' ),
		__( 'authorizing_title', 'event_espresso' ),
		__( 'authorizing_email', 'event_espresso' ),
		__( 'Address Part 1', 'event_espresso' ) . '[ATT_address]',
		__( 'Address Part 2', 'event_espresso' ) . '[ATT_address2]',
		__( 'City', 'event_espresso' ) . '[ATT_city]',
		__( 'State', 'event_espresso' ) . '[STA_ID]',
		__( 'Country', 'event_espresso' ) . '[CNT_ISO]',
		__( 'ZIP/Postal Code', 'event_espresso' ) . '[ATT_zip]',
		__( 'Phone', 'event_espresso' ) . '[ATT_phone]',
		__( 'cell_number', 'event_espresso' ),
		__( 'fax', 'event_espresso' ),
		__( 'comments', 'event_espresso' ),
		__( 'Registration's share of the transaction total', 'event_espresso' ) . '[REG_final_price]',
		__( 'Amount Paid', 'event_espresso' ),
		__( 'Registration Status', 'event_espresso' ),
		__( 'Time registration occurred', 'event_espresso' ) . '[REG_date]',
	);
	//Flip the array so the values are now the keys.
    $allowed_fields_in_order = array_flip($allowed_fields_in_order);
    
    //Set the value for each of the array elements to an empty string.
    //This is incase any of the above questions do not exist in the current registration's questions,
    //they still need to be included in the row but the value should be nothing.
    $allowed_fields_in_order = array_fill_keys(array_keys($allowed_fields_in_order), '');
    
    //Sets $filtered_csv_row to only contain the 'allowed' fields.
    $filtered_csv_row = array_intersect_key(
        $csv_row,
        $allowed_fields_in_order
    );
    //Now lets set $filtered_csv_row to use the same custom order we set $allowed_fields_in_order to
    $filtered_csv_row = array_merge( $allowed_fields_in_order, $filtered_csv_row );
    return $filtered_csv_row;
}
add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'tw_ee_espresso_reg_report_filter_columns_ordered', 10, 2);

Let me know if you have any additional questions,
Thanks!


Tony

  • Support Staff

April 11, 2018 at 10:00 am

Hi there,

Have you recently changed the above code? Unless the forum has altered the content its currently invalid. This line:

__( 'Registration's share of the transaction total', 'event_espresso' ) . '[REG_final_price]',

The apostrophe ends the string so that would throw a syntax error. You need:

__( 'Registration\'s share of the transaction total', 'event_espresso' ) . '[REG_final_price]',

When you export registrations for a specific event EE does not include the Event Name by default, because all of the registrations are for a specific event so its just duplicate data.

However, it’s simple enough to add into the CSV using the function above, add this;

//If the event name is empty, pull the event from the DB using the Registration.EVT_ID value and set the event name
if( empty($filtered_csv_row[__( 'Event', 'event_espresso' )])) {
    $event = EEM_Event::instance()->get_one_by_ID($registration_db_row['Registration.EVT_ID']);
    $filtered_csv_row[__( 'Event', 'event_espresso' )] = $event instanceof EE_Event ? $event->name() : '';
}

Just above return $filtered_csv_row;


bld_espresso

April 11, 2018 at 11:22 am

Tony,
the apostrophe is escaped properly in my code (must have gotten changed in the copy and paste into the forum) so no issue there.

The provided code to add the title back to the single event registrations export worked perfectly.

Thank you so much!


Tony

  • Support Staff

April 11, 2018 at 1:36 pm

You’re most welcome, I’m glad that worked for you 🙂

The support post ‘CSV Exports Issues – No Event Name or Exporting All Registrations’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Tony 6 months, 1 week ago ago

Topic Tags

Tagged: 

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!