Support

Home Forums Event Espresso Premium EE4 – Count registration by ticket

EE4 – Count registration by ticket

Posted: August 29, 2017 at 11:28 am


JacquesMivi

August 29, 2017 at 11:28 am

Hello,

I try to count number of registrations by ticket and status, but its not working with a filter on the TKT_ID

$registrations_approved = EEM_Registration::instance()->count(array( array( ‘TKT_ID’ => $ticket->ID(), ‘STS_ID’ => EEM_Registration::status_id_approved ) ), ‘REG_ID’, true);

The “$ticket” object works.
Its also works if I replace TKT_ID by EVT_ID, like this example :

$registrations_approved = EEM_Registration::instance()->count(array( array( ‘EVT_ID’ => $id_event, ‘STS_ID’ => EEM_Registration::status_id_approved ) ), ‘REG_ID’, true);

Do you have a suggestion to fix it ?
Thanks a lot,


JacquesMivi

August 29, 2017 at 11:30 am

Hello,

I try to count number of registrations by ticket and status, but its not working with a filter on the TKT_ID

$registrations_approved = EEM_Registration::instance()->count(array( array( ‘TKT_ID’ => $ticket->ID(), ‘STS_ID’ => EEM_Registration::status_id_approved ) ), ‘REG_ID’, true);

The “$ticket” object works.
Its also works if I replace TKT_ID by EVT_ID, like this example :

$registrations_approved = EEM_Registration::instance()->count(array( array( ‘EVT_ID’ => $id_event, ‘STS_ID’ => EEM_Registration::status_id_approved ) ), ‘REG_ID’, true);

Do you have a suggestion to fix it ?
Thanks a lot,


Tony

  • Support Staff

August 29, 2017 at 11:42 am

Hi there,

When you say it’s not working, what is happening?

I copied your query above and used it within Debug console on a test site replacing $ticket-ID() with a valid ticket ID – http://take.ms/YIF0N

A count of 3 is expected for that ticket – http://take.ms/1DtjF

What happens on your site?


JacquesMivi

August 29, 2017 at 11:56 am

Thx for your reply. Effectively I don’t see a difference between our codes.
For my part I got 0 on my results for every tickets.
Even if I put directly the ticket ID by a valid number.
Here is my code

// Get the ID of the page.
$event = EEM_Event::instance()->get_one_by_ID($id_event);

if ($event instanceof EE_Event) {
$tickets = $event->tickets();

foreach ($tickets as $ticket) {
if ($ticket instanceof EE_Ticket) {
$registrations_approved = EEM_Registration::instance()->count(array( array( 'TKT_ID' => $ticket->ID(), 'STS_ID' => EEM_Registration::status_id_approved ) ), 'REG_ID', true);
$registrations_not_approved = EEM_Registration::instance()->count(array( array( 'TKT_ID' => $ticket->ID(), 'STS_ID' => EEM_Registration::status_id_not_approved ) ), 'REG_ID', true);
?>
<li>
<a href="/outil-tableau-de-bord/?type=event&evtid=<?php echo $id_event; ?>&tktid=<?php echo $ticket->ID(); ?>">
<?php echo $ticket->ID() . ' - ' . $ticket->get('TKT_name') . ' - ' . $registrations_approved . 'A ' . $registrations_not_approved . 'NA' ?>
</a>
</li>
<?php
}
}
}

Here is the results of this code

781 – Test 24 | 200€ – 0A 0NA
789 – T1 | 120€ – 0A 0NA
790 – T3 | 199€ – 0A 0NA
791 – T4 | 31€ – 0A 0NA
792 – T5 | 130€ – 0A 0NA
793 – T6 | 2€ – 0A 0NA
794 – T7 – BABA | 120€ – 0A 0NA
795 – T8 | 120€ – 0A 0NA
796 – T9 AB | 120€ – 0A 0NA


JacquesMivi

August 29, 2017 at 11:57 am

I’m sure to have registration for this tickets.
I just updated the last version of EE core.


Tony

  • Support Staff

August 29, 2017 at 12:08 pm

Again, that code works fine for me – http://take.ms/Gu1NH

EEM_Registration::status_id_approved will only pull registrations that have a status of ‘Approved’.

EEM_Registration::status_id_not_approved will only pull registrations that are set to ‘Not Approved’ (no other status).

So to confirm, do you have registrations with those statuses on the event? For example here are the registrations for my event – http://take.ms/PeiwS

The ‘status’ bar on the left gives a quick reference, green = approved, orange = not approved, blue = pending payment (there is a legend at the bottom of the list)


JacquesMivi

August 29, 2017 at 12:33 pm

Yes I got registrations on my back-end.

I think I find something. My tickets IDs displayed are wrong. For example the first row “$ticket->ID()” displays “781” in place of “747”. If I put directly 747, I find my registrations.

I’m looking how to correct this.


Tony

  • Support Staff

August 29, 2017 at 12:44 pm

That’s not displaying incorrectly, it’s a different ticket.

var_dump the variable $event and confirm your getting the event you expect.

Then dump out the $tickets array and confirm the tickets are for the event in $event.

Basically step through each step of your code and find where you’re getting the wrong data.


JacquesMivi

August 29, 2017 at 1:03 pm

The ticket has been duplicated by EventEspresso system security.
And when I use “$event->tickets()” it doesn’t bring the locked ticket. And its the ticket where I got my registrations.

I have to find the query_param to bring back this locked ticket.


Tony

  • Support Staff

August 29, 2017 at 1:12 pm

Ah, yeah I see.

You’ll need to remove the default where conditions used on tickets(), try:

$tickets = $event->tickets(array(array(), 'default_where_conditions' => 'none'));


JacquesMivi

August 29, 2017 at 1:21 pm

Thats works 🙂 Many thanks !! You saved me lot of hours.

Have a good evening.

The support post ‘EE4 – Count registration by ticket’ 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