Support

Home Forums Event Espresso Premium Modify [ESPRESSO_MY_EVENTS template=simple_list_table])

Modify [ESPRESSO_MY_EVENTS template=simple_list_table])

Posted: May 6, 2020 at 4:02 pm


web@the-collaborative.net

May 6, 2020 at 4:02 pm

I’m trying to do two things with the shortcode [ESPRESSO_MY_EVENTS template=simple_list_table])

#1: Is it possible to display the event date/time on this simple table? (Previously we had just [ESPRESSO_MY_EVENTS] that showed the date and time, but there was just too much – the simple table works better for our needs)

#2: Is it possible to show under the ticket whether the registration is complete or waitlisted? We’d like that column to show “confirmed”, “canceled”, or “waitlisted” if possible.


Tony

  • Support Staff

May 7, 2020 at 6:32 am

Hi there,

#1: Is it possible to display the event date/time on this simple table? (Previously we had just [ESPRESSO_MY_EVENTS] that showed the date and time, but there was just too much – the simple table works better for our needs)

Yes, it is possible.

You can override many of the templates used within EE by copying them to your themes root directory (preferably using a child theme) and EE will use those in place of the defaults.

In the WP user Integration add-on you can see the templates in:

/eea-wpuser-integration/teampltes/

For the simple list template, the first template loaded is loop-espresso_my_events-simple_list_table.template.php and from there additional template parts are loaded, you’ll see those in that template, e.g:

$template = 'content-espresso_my_events-simple_list_table.template.php';
EEH_Template::locate_template($template, $template_args, true, false);

Is loading the content template into the above.

So depends on where you want to add the additional details you copy the template you need and modify it there.

The simple list table works with EE_Registration objects and you can use our model system to pull pretty much any details you need from that object:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

You’ll see an example of how the event is pulled from the EE_Registration object in the content template I mentioned above.

#2: Is it possible to show under the ticket whether the registration is complete or waitlisted? We’d like that column to show “confirmed”, “canceled”, or “waitlisted” if possible.

Sure, again you’ll use the model system to do this, with an EE_Registration object in $registration you can do something like:

$registration->pretty_status()

or

$registration->e_pretty_status()

e_ will echo directly.


web@the-collaborative.net

May 7, 2020 at 11:19 pm

Amazing. This all worked beautifully. Thank you SO much.

One more question… On the basic template of My Events, I found a snippet to sort based on date/time (https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/tw_ee_filter_getTemplateObjects__query_args.php)

Is there a way to apply this same sort to the simple table?


Tony

  • Support Staff

May 8, 2020 at 4:03 am

That snippet isn’t for sorting, it’s excluding expired events from the queries and should work on both templates.

If you are looking to change the $query_args passed to the models you can use that same filter FHEE__Espresso_My_Events__getTemplateObjects__query_args to change the default values.

The simple_list template use the EEM_Registration model, the default template uses the EEM_Event model so you’ll want to check the object type in the same way the above snippet does before applying any additional code as each model will take slightly different parameters.

Here are some details on passing order_by within the query params:

https://github.com/eventespresso/event-espresso-core/blob/master/docs/G–Model-System/model-query-params.md#user-content-order_by


web@the-collaborative.net

May 8, 2020 at 10:59 am

I seem to be missing something.

This is what I’ve got:

/* This code is for sorting the My Events Simple Table in descending order */

add_filter(
	'FHEE__Espresso_My_Events__getTemplateObjects__query_args',
	'tw_ee_filter_getTemplateObjects__query_args',
	10,
	3
);
function tw_ee_filter_getTemplateObjects__query_args( $query_args, $template_args, $att_id) {
	if ($template_args['object_type'] === 'Event') {
		$query_params = array (
			'order_by'=>array('Datetime.DTT_EVT_start'=>'DESC')
			);
EEM_Registration::instance()->get_all($query_params);
	}
	

But I keep getting errors. Can you help me figure out where I’ve gone wrong?

Thank you!


Tony

  • Support Staff

May 8, 2020 at 11:34 am

if ($template_args['object_type'] === 'Event') {

Why are you targeting Event objects? Are you no longer using simple_list_table?

The simple_list template use the EEM_Registration model

So your object_type will be ‘Registration’, you’re using the wrong example conditional from that snippet :), it should be:

if ($template_args['object_type'] === 'Registration') {

This code:

$query_params = array(
    'order_by' => array(
        'Datetime.DTT_EVT_start'=>'DESC'
    )
);

I’m not really sure why you are doing this, why a new $query_params with a new array containing just an ‘order_by’ value? You’re filtering the $query_args array before it is passed to the model to pull the details using the args set, so you want to add/modify the current $query_args passed to the callback function and return it.

Just this:

$query_args['order_by'] = array(
        'Datetime.DTT_EVT_start'=>'DESC'
    )
);

I’m not really sure why you are doing this:

EEM_Registration::instance()->get_all($query_params);

Why are you pulling the registrations in here? The add-on pulls the object for you, this filter is just filtering the query_params passed to whichever models it needs to use, so you don’t pull any objects in here.

Using my snippet as an example, you could have just done something like this:

if ($template_args['object_type'] === 'Registration') {
    $query_args[0]['Event.Datetime.DTT_EVT_end'] = array( '>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'));	
    $query_args['order_by'] = array(
        'Event.Datetime.DTT_EVT_end'=>'DESC'
    );
}

That would do both, sort by DTT_EVT_End DESC and remove expired events. If you don’t want to filter expired events then just remove the first line in that conditional.

(Note, I’m writing the above in the forum to reply and have not tested this)


web@the-collaborative.net

May 8, 2020 at 11:59 am

Honestly, I’m not sure what I’m doing at this point. I might be past my brain limits here.

I can’t seem to get it to sort by date. Even with the code you shared. I really appreciate your response, but I’m still struggling with this one!

I don’t need to filter the expired events, I just want the events to be sorted by datetime. So the oldest events would be on the bottom, and the newest events on the top.

I’m still using the simple_list_table, but I modified it to show the ticket type, and event date instead of location. (See here:https://share.getcloudapp.com/8LujgQzg)

I’m probably making this harder than it needs to be…


Tony

  • Support Staff

May 8, 2020 at 2:44 pm

All you need is this:

add_filter(
	'FHEE__Espresso_My_Events__getTemplateObjects__query_args',
	'tw_ee_filter_getTemplateObjects__query_args',
	10,
	3
);
function tw_ee_filter_getTemplateObjects__query_args( $query_args, $template_args, $att_id) {
	if ($template_args['object_type'] === 'Registration') {
		$query_args['order_by'] = array('Event.Datetime.DTT_EVT_start' => 'DESC');	
	}
	return $query_args;
}


web@the-collaborative.net

May 8, 2020 at 4:57 pm

Thank you SO MUCH.

You are wonderful.

If I wanted to leave the expired events, which part of this code would I remove?


Tony

  • Support Staff

May 9, 2020 at 3:27 pm

?? My code above does not remove expired events.

If you do not want to exclude expired events, do not add this snippet to your site:

https://github.com/eventespresso/ee-code-snippet-library/blob/master/addons/eea-wp-user/tw_ee_filter_getTemplateObjects__query_args.php


web@the-collaborative.net

May 9, 2020 at 11:34 pm

Thanks so much.


Tony

  • Support Staff

May 11, 2020 at 4:48 am

Hi there,

Just checking in to see if you got this working how you wanted?

If you don’t want to exclude expired events then the only code you need is the what I posted here:

https://eventespresso.com/topic/modify-espresso_my_events-templatesimple_list_table/#post-311526

The other snippet specifically removes expired events, so you don’t need that if displaying them.

The support post ‘Modify [ESPRESSO_MY_EVENTS template=simple_list_table])’ 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