Support

Home Forums WP User Integration Fetch position of ticket in ESPRESSO_MY_EVENTS

Fetch position of ticket in ESPRESSO_MY_EVENTS

Posted: May 9, 2017 at 10:26 pm

Viewing 9 reply threads


faeger

May 9, 2017 at 10:26 pm

Hi there!

We are working hard on our event-site and people are satisfied with what they get, thanks to your plugin and work! – however…

As we have lots of waitlist-events with lots of attendees on, people keep asking us, at which position on the waitlist they’d stand in order to decide wether it would be worth waiting longer.

Is there a way to show the position of a ticket inside ESPRESSO_MY_EVENTS?

For exmaple: Ms. Marples would log in and go to “My tickets” and see, that she is the 4th person who bought a particular ticket. As only confirmed tickets would count, this number could change as soon as somebody left the waitlist (cancellation of the ticket from back-end). So Ms. Marples would then see, that she is the 3rd person who bought this ticket.

Thanks for your help and advice!
Cheers
Philip


faeger

May 10, 2017 at 3:40 am

I have tried this query on phpMyAdmin

SELECT *,
@curRow := @curRow + 1 AS row_number
FROM (
SELECT wp_esp_attendee_meta.ATTM_ID, wp_esp_registration.REG_ID, wp_esp_registration.EVT_ID, wp_esp_registration.REG_date

FROM wp_esp_registration
INNER JOIN wp_esp_attendee_meta
ON wp_esp_attendee_meta.ATT_ID=wp_esp_registration.ATT_ID
WHERE wp_esp_registration.EVT_ID = 8904
ORDER BY wp_esp_registration.REG_date) a
JOIN (SELECT @curRow := 0) r;

How I can implement this via php based on the current user and ticket-row in ESPRESSO_MY_EVENTS or, if that would be too complicated… how can I implement this on a single-event-template in order to output the row_number which in this case would be the position…

Thanks!


Josh

  • Support Staff

May 10, 2017 at 6:40 am

Hi Philip,

We received your Support token form and are reviewing your request. Can you clarify something so we can understand this a bit better? Are these “waitlist events” as you call them being used to only capture interest in getting a registration for an already booked event?

Also, I tried to log in with the credentials you sent but the WordFence plugin isn’t allowing access.


faeger

May 10, 2017 at 6:58 am

Hi Josh

Sorry for the putting a fence 🙂 It should work now!

The “waitlist events” are normal EE-events but have a default status of “not confirmed”. We then move attendees from one to another.

The reason we need this query to work is we need to show the position of the ticket based on the REG_Date inside ESPRESSO_MY_EVENTS.

We already tried this in the meantime, but this only kind of works on single-event-pages… we cannot figure out a way to implement it inside the shortcode as we don’t quite understand the relations…

<?php

global $wpdb;

$sqlCount = "SELECT count(*) as cnt FROM wp_esp_registration INNER JOIN wp_esp_attendee_meta ON wp_esp_attendee_meta.ATT_ID=wp_esp_registration.ATT_ID WHERE wp_esp_registration.EVT_ID = ". get_the_ID() .";";

$results = $wpdb->get_results( $sqlCount );

if ( $results[0]->cnt )
{
	$user_id = get_current_user_id();
	$sql = "SELECT *, @curRow := @curRow + 1 AS row_number FROM ( SELECT wp_esp_attendee_meta.ATTM_ID, wp_esp_registration.REG_ID, wp_esp_registration.EVT_ID, wp_esp_registration.REG_date FROM wp_esp_registration INNER JOIN wp_esp_attendee_meta ON wp_esp_attendee_meta.ATT_ID=wp_esp_registration.ATT_ID WHERE wp_esp_registration.EVT_ID = ". get_the_ID() ." ORDER BY wp_esp_registration.REG_date) a JOIN (SELECT @curRow := 0) r;";

	$results = $wpdb->get_results( $sql );
	
	$userPositions = [];
	
	foreach ( $results as $result )
	{
		if ( $user_id == $user_id->ATTM_ID )
		{
			$userPositions[] = $result->row_number;
		}
	}
	
	echo "<p>positions for user Id: ". $user_id .'</p>';
	
        //print_r( $userPositions;)
	if ( $userPositions )
	{
		echo '<p>Position for event is '. min( $userPositions ) .'</p>';
	}
}

?>

Thanks Josh!
Cheers
Philip


Josh

  • Support Staff

May 10, 2017 at 7:09 am

OK thanks. One thing that you should plan on doing is you should only run these additional queries on upcoming events.


Josh

  • Support Staff

May 10, 2017 at 8:43 am

Hi Philip,

I’m combing through the code you posted here and I’m not exactly what you are trying to retreive from these two queries. The first one appears to only get a count of all registrations for the event (the joins aren’t really doing anything). Are you trying to get all the registrations for that event or is there something else you’re looking to do with the JOINS?

If you can explain exactly what data you’re looking to retrieve with each of the queries it may help.


Josh

  • Support Staff

May 10, 2017 at 10:29 am

One thing I don’t see in your query example is anything that filters away a cancelled registration. So I went ahead and wrote up something that I think is what you’re looking to do and put it in this gist:

https://gist.github.com/joshfeck/1c2dcbd044e0922e1a3add7d45643b21

Hope that helps!


faeger

May 10, 2017 at 2:28 pm

Josh, you are my hero!

Thanks, that’s exactly what we needed!

Have a great day!
Cheers
Philip


faeger

May 10, 2017 at 2:33 pm

…one question though: would it be possible to implement this function inside the ESPRESSO_MY_EVENTS-shortcode as additional column next to every single ticket?

Anyway, thanks for your great support! Appreciate it!
Cheers
Philip


Josh

  • Support Staff

May 12, 2017 at 12:26 pm

You’d have to re-work the code and add the additional column to template, but it should be possible. Also, like I mentioned before you should only run the query on upcoming events because otherwise the page with ESPRESSO_MY_EVENTS will get very slow with all those extra queries running on it.

Viewing 9 reply threads

The support post ‘Fetch position of ticket in ESPRESSO_MY_EVENTS’ 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