Support

Home Forums Event Espresso Premium Add instructor, venue and custom fields to csv report

Add instructor, venue and custom fields to csv report

Posted: February 21, 2018 at 7:56 am

Viewing 30 reply threads


motio

February 21, 2018 at 7:56 am

Hi, I would like to add the following variables to the csv report. You guys have a really great support forum in which I found a lot to customize event espresso to our needs. We would be glad if you you could help us with the following.

– Add instructors from the people add-on
I’ve tried to change the code which I found here (https://eventespresso.com/topic/adding-venue-to-csv-or-giving-us-an-event-export/) for the venues and worked great but I don’t know how to edit it correctly to add “people”. I’ve tried the following but there is an error:

//* Adds "People" to the csv attendee export
add_filter( 'FHEE__EE_Export__report_registrations__reg_csv_array', 'espresso_add_people_to_report', 10, 2);
function espresso_add_people_to_report( $reg_csv_array, $reg_row ) {
	$event_id = $reg_row['Registration.EVT_ID'];
	$event = EEM_Event::instance()->get_one_by_ID( $event_id );
	if ( $event instanceof espresso_people ) {
		$people = $event->get_first_related( 'People' );
		if ( $people instanceof espresso_people ) {
			$people_name = !empty( $people ) ? $people->name() : '';
			$reg_csv_array['People'] = $people_name;
		}
	}
	return $reg_csv_array;
}

– can the quantity of event-dates and also duration in minutes (e.g. of the first date) be exported as a value in the csv report?

– also the date and time of the first event?


Tony

  • Support Staff

February 22, 2018 at 12:24 pm

Hi there,

The people add-on works differently to the venues, they are part of core.

For people, you can use something like this:

https://gist.github.com/Pebblo/e38dd403563b793c8cd2dde0189deed3

That adds a column called ‘People’ and loops over all people on the event adding “{person_name}({person_type})” to the CSV.

– can the quantity of event-dates and also duration in minutes (e.g. of the first date) be exported as a value in the csv report?

Hmm, I’m not sure I follow the first part. You want a count of the datetimes on the event?

How do you have your events set up? Do you have a single ticket on multiple datetimes?

– also the date and time of the first event?

You mean datetime? It depends on your setup.

Can you link to an event so I can see your ticket setup?


motio

February 23, 2018 at 9:17 am

Thank you Tony for the support.
By adding the code for the “people” column the page that generates the export is blank and nothing happens. When I remove the code the export is functioning again. Could there be an error in the code?


Tony

  • Support Staff

February 23, 2018 at 9:25 am

If you enable WP_DEBUG and retest the code, does it show an error?

I’m using the above on a test site without a problem so will need the error to see what is happening.

You enable WP_Debug within your wp-config.php file, you’ll have:

define( 'WP_DEBUG', false );

Set that to:

define( 'WP_DEBUG', true );


Josh

  • Support Staff

February 23, 2018 at 9:25 am

The code has actually been tested and verified to be working on a few test sites. You might have a missing bracket somewhere in your copy or maybe you copied in the opening PHP tag?


motio

February 23, 2018 at 12:24 pm

The following message is shown:

Fatal error: Uncaught Error: Call to undefined function write_log() in /pages/da/7f/d0013688/home/htdocs/motio_web/wordpress/testpage/wp-content/plugins/ee4-customization/ee4_customization_csv.php:34 Stack trace: #0 /pages/da/7f/d0013688/home/htdocs/motio_web/wordpress/testpage/wp-includes/class-wp-hook.php(286): tw_espresso_add_people_to_report(Array, Array) #1 /pages/da/7f/d0013688/home/htdocs/motio_web/wordpress/testpage/wp-includes/plugin.php(203): WP_Hook->apply_filters(Array, Array) #2 /pages/da/7f/d0013688/home/htdocs/motio_web/wordpress/testpage/wp-content/plugins/event-espresso-core-reg/core/libraries/batch/JobHandlers/RegistrationsReport.php(407): apply_filters(‘FHEE__EE_Export…’, Array, Array) #3 /pages/da/7f/d0013688/home/htdocs/motio_web/wordpress/testpage/wp-content/plugins/event-espresso-core-reg/core/libraries/batch/JobHandlers/RegistrationsReport.php(93): EventEspressoBatchRequest\JobHandlers\RegistrationsReport->get_csv_data_for(0, 0, 1, Array, Array) #4 /pages/da/7f/d0013688/home/htdocs/motio_web/word in /pages/da/7f/d0013688/home/htdocs/motio_web/wordpress/testpage/wp-content/plugins/ee4-customization/ee4_customization_csv.php on line 34

In line 34 the following is following value:
write_log(‘what about here’);

After erasing this line the export with the “People” is working. Do I need the line?


Josh

  • Support Staff

February 23, 2018 at 12:34 pm

You don’t need that line.


motio

February 23, 2018 at 1:28 pm

Thank you a lot. So we have now our instructors in the report.

I am using custom fields to display the count of dates for the event, duration of one date of the event and other fields in the description and also be able to pull the information for the report.
Is it possible to show the count of dates and duration of the first date (all dates have the same duration) in the description? So the system count how many dates for the event there are, so I don’t have to typ it in for every event manually?

In the filtered report the name of the event is shown with the internal number in brackets. I would like to use the report without the number, only the event name. Is it possible to add the event name to the Event Registrant CSV Report or exclude the number from the Event (“Veranstaltung”) column in the filtered report?


Tony

  • Support Staff

February 26, 2018 at 2:00 pm

I am using custom fields to display the count of dates for the event, duration of one date of the event and other fields in the description and also be able to pull the information for the report.

So you already have those saved on the event and want to pull the values for those custom fields into the CSV.

Is it possible to show the count of dates and duration of the first date (all dates have the same duration) in the description? So the system count how many dates for the event there are, so I don’t have to typ it in for every event manually?

The CSV is filtered before each row is generated, they are all passed through this filter – FHEE__EE_Export__report_registrations__reg_csv_array

So you can hook in and add any additional details you need.

Note that we don’t not provide support for customizations, if we can help we’ll try to point you in the right direction and possible provide code examples such as the above but if you need more than that you’ll need the help of a developer.

Is it possible to show the count of dates and duration of the first date (all dates have the same duration) in the description? So the system count how many dates for the event there are, so I don’t have to typ it in for every event manually?

Count how many datetimes are on the event you mean? And then automatically fill in your custom field with the qty of datetimes? It is likely possible but not something we have an example for so you’ll need some custom development.

In the filtered report the name of the event is shown with the internal number in brackets. I would like to use the report without the number, only the event name. Is it possible to add the event name to the Event Registrant CSV Report or exclude the number from the Event (“Veranstaltung”) column in the filtered report?

Do you not need the Event ID in any of the reports?


motio

February 27, 2018 at 2:55 pm

Hi Tony,

thank you for the infos. We just started with event espresso and I am figuring out, what I can do on my own and where we need help in and in what scope. For example the count and duration was a question to understand how to optimize our system for the long run. I am tryin to adapt the workflow to the new system and the report is essential to that.
I fully understand that you only provide support and no customization. I’ve searched the forum for various topics and found a lot of help here. I hope maybe there already solution for my problems that I wasn’t able to find.

It would be great if you could help me with this two things to complete my report settings.
– Event ID in the Event Name
No we don’t need the Event ID behind the Event Name in any report because we have an own Event ID (that comes in via custom field). Is it possible to erase that from a file or do I need to add code to our customization plugin?
– Additional information from the instructor
Do you have an example how I can pull more informations (e.g. address, email or other fields) from the instructor (people) to the export?


Tony

  • Support Staff

February 28, 2018 at 4:23 am

Is it possible to erase that from a file or do I need to add code to our customization plugin?

Please don’t edit core file to do any customization, we have filters to allow you to change the output so generally its unnecessary, if no filters are available we are more than happy to add them.

So, yes you would need to add additional code to your customization plugin.

You actually have a couple of options to remove that ID number, the code used to build the '{Event Name} ({event_id})' string is translatable so you can use the funtion here:

https://eventespresso.com/wiki/how-to-change-wording-with-poedit/#custom-function

The string you want to translate is '%1$s (%2$s)' so your strings array would have at least:

$strings = array(
     '%1$s (%2$s)' => '%1$s',
);

Or the other option is to use the above filter again, $reg_csv_array is an array of all of the values that will be written to the CSV for each specific registration. SO you will the event name column and filter the content to be just event name.

– Additional information from the instructor
Do you have an example how I can pull more informations (e.g. address, email or other fields) from the instructor (people) to the export?

At line 20 you have an EE Person object:

https://gist.github.com/Pebblo/e38dd403563b793c8cd2dde0189deed3#file-example-php-L20

Take a look at the \eea-people-addon\core\db_classes\EE_Person.class.php to find all of the available methods you can use on that object.

For example to pull the address you can do:

$address_array = $person->full_address_as_array();

You then have an array containing all of that person address info to do whatever you prefer.

Email you can grab using $email = $person->email();

Then add them to $reg_csv_array wherever you prefer.


motio

February 28, 2018 at 5:12 am

Thank you Tony.

Change wording is the easiest solution and works great.

The additional information for the instructors are also working for me. Although the term “full_address_as_array()” brings the text “Array” into the export. But I added three function with address(), city(), zip(). I can work with that.

I have also a custom field for the person “qualification” and understand that I have to add the get_post_meta but I don’t where.
I’ve tried the following in line 23 but that doesn’t work.
$person->get_post_meta( $people_in_types, ‘qualification’, true );

I understand which variable I have to edit but I cannot write my own code, so maybe there is also an example for the last part, that I could use.


Tony

  • Support Staff

February 28, 2018 at 5:31 am

Although the term “full_address_as_array()” brings the text “Array” into the export.

That’s because its an array and your adding the array directly.

You can do something like $full_address = implode(', ', $person->full_address_as_array()); which will join each of the elements in the array together using ‘, ‘.

Or use the individual methods you mentioned above.

$person->get_post_meta( $people_in_types, ‘qualification’, true );

Remove $people_in_types.

When using our models if you call get_post_meta() on the object, it already passes the ID of the current object, so you just pass it the key and single.

$person->get_post_meta('qualification', true);

  • This reply was modified 6 years, 9 months ago by Tony. Reason: Fixed implode order


motio

February 28, 2018 at 7:41 am

That worked, thanks a lot. So my idea wasn’t that wrong.

What/where do I have to add to have only the “staff” (People Types) in the report. That would the People Add-on more powerful to us.


Tony

  • Support Staff

March 1, 2018 at 4:04 am

You can use something like:

EEM_Person::instance()->get_people_for_event_and_type($event_id, $people_type_id);

You’ll obviously need to pass the event_id for the current event, and the type ID for the people type you want to pull.


motio

March 1, 2018 at 6:53 am

I’ve add the following line above the load_helper( ‘People_View’ ) and tried a couple things but there still multiple persons/types in the report.
EEM_Person::instance()->get_people_for_event_and_type('Registration.EVT_ID', '3');
The 3 is the type id for “staff”. Could hint me in the correct direction? What did I miss?


Tony

  • Support Staff

March 1, 2018 at 7:11 am

Yeah, it’s not as simple as adding the above line into the code and ‘Registration.EVT_ID’ doesn’t actually mean anything above.

$people = EEH_People_View::get_people_for_event_and_type($reg_row['Registration.EVT_ID'], 3);

Would return an array of people for the event from the type with ID 3.

See: https://gist.github.com/Pebblo/e38dd403563b793c8cd2dde0189deed3#file-example2-php


motio

March 1, 2018 at 7:31 am

Yeah, I am trying to learn php but the more I get to it, the more complex it gets.

I tried at first also with $reg_row[‘Registration.EVT_ID’] but that didn’t work either.

With the code example2 I got an Fatal Error:

Fatal error: Uncaught Error: Call to undefined method EEH_People_View::get_people_for_event_and_type()

The line that brings the error is:
$people = EEH_People_View::get_people_for_event_and_type($reg_row['Registration.EVT_ID'], 3);


Tony

  • Support Staff

March 1, 2018 at 8:16 am

My apologies, that’s a copy & paste error.

I’ve fixed the code in my gist.


motio

March 1, 2018 at 8:21 am

Tony you’r the best. Thank you for your patience and the great support.


Tony

  • Support Staff

March 1, 2018 at 9:06 am

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


motio

March 8, 2018 at 8:45 am

One more thing…
I am trying to combine the two things: Specific Typ from the People Add-on and the custom field for that. So the custom field only for the specific typ:

https://gist.github.com/lorenzocaum/3bd7098e4ec311419fea8d02e85f36a8

I get as result “Array” and not the custom field.
It is probably a small thing but I cannot detect what.


Josh

  • Support Staff

March 9, 2018 at 7:51 am

$peoples_names[] = $person->get_post_meta( 'qualifikation', true );
should probably be changed to:
$peoples_names[] = get_post_meta( $person->ID(), 'qualifikation', true );


motio

March 14, 2018 at 2:40 pm

Do you have another idea? It still brings „Array“ as result.


Josh

  • Support Staff

March 14, 2018 at 3:35 pm

The code works for me, here’s a gist of what I tested:

https://gist.github.com/joshfeck/95cfda40985010f0476d27fe0b279138


motio

March 14, 2018 at 4:17 pm

I‘ve tried it with an other custom field and it worked. The „qualifikation“ custom field is a checkbox field. Do you have an example how it would work with a checkbox field?


Tony

  • Support Staff

March 15, 2018 at 6:30 am

I‘ve tried it with an other custom field and it worked. The „qualifikation“ custom field is a checkbox field.

WordPress itself does not support ‘checkbox’ custom fields, so that will have been added by a plugin. From your other threads I know that is likely to be ACF and yes it makes a difference as a checkbox field will return an array of values which needs to be handled differently that single text field (which would be the default type from WP).

Do you have an example how it would work with a checkbox field?

Something like this should work:

https://gist.github.com/Pebblo/4afdb79db1db59485047c142d5c22cf8


motio

March 19, 2018 at 1:13 pm

That’s really great. That will help me a lot in the workflow by processing the course after it has ended.
Is it possible also possible to output the key instead of the value of the custom field. Is get_post_meta the right function for that?


Tony

  • Support Staff

March 20, 2018 at 6:07 am

Sure its possible, but you need the help of a developer.

Your using ACF so you need to use the functions available within that:
https://www.advancedcustomfields.com/resources/checkbox/

And: https://www.advancedcustomfields.com/resources/get_field/

We can’t provide support for custom development and working with other plugins, if you are not currently working with a developer we have some that are familiar with Event Espresso here:

https://eventespresso.com/developers/event-espresso-pros/


motio

March 21, 2018 at 10:01 am

Hey Tony, I could only find how to get the value but not the key. I understand that this reaches over the scope of the support and will try not to post those question.


Josh

  • Support Staff

March 23, 2018 at 12:36 pm

One way to get the key:

https://stackoverflow.com/a/34923462

Viewing 30 reply threads

The support post ‘Add instructor, venue and custom fields to csv report’ 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.

Event Espresso