Support

Home Forums Event Espresso Premium Some events not displaying when using get_all_registrations_for_attendee

Some events not displaying when using get_all_registrations_for_attendee

Posted: November 20, 2019 at 3:19 am


deon@dieselbrook.co.za

November 20, 2019 at 3:19 am

I implemented some code on a client’s site. But this code isn’t returning some events. I checked whether the event status has something to do with it. But it doesn’t seem like it. Some events like http://www.pia.org.za/events/professional-practice-programme-session-5/ just doesn’t show up, even though there are registrations (and check-ins) for that event, The code:

http://wpbin.io/91yehj

  • This topic was modified 3 weeks, 1 day ago by  Josh. Reason: removed large block of code and replaced with a link


Tony

  • Support Staff

November 20, 2019 at 3:33 am

Hi there,

Your not pulling events, your pulling registrations and then using the registration to get the event, so if an event isn’t showing its more likely to be something with the registration than the event with your code.

Have you confirmed that the $att_id matches the contact for the ‘missing’ registrations?

A registration will only be linked to a contact if their first name, last name and email address match the contact exactly, so the missing registrations may well be linked to another contact.

If you view the registration list within EE and then hover over the contact icon (this) you’ll see a post=x in the URL (or click on it and view the value in the address bar).

Does that ID number match the $att_id value?


deon@dieselbrook.co.za

November 20, 2019 at 3:55 am

Okay, so I see that this indeed doesn’t match. And I also see in the source that you can’t get this from any other field, ie. email. I think this is affecting quite a few registrations, and I have no way of quantifying which of the registrations were affected.

Any way to revert the id to the users’ old id? Or any advice that you can give me to connect the data again?


Tony

  • Support Staff

November 20, 2019 at 4:55 am

And I also see in the source that you can’t get this from any other field, ie. email.

Sure you can.

You can use our models to pass EE_Attendee the email address to pull all contacts using that email, example:

$contacts = EEM_Attendee::instance()->get_all(array(array('ATT_email' => '{email}')));

That will return an array of EE_Contacts in the system that has the email address passed.

You can also pull all of the registrations linked to any contact with a specific email address:

$registrations = EEM_Registration::instance()->get_all(
    array(
        array(
            'Attendee.ATT_email' => '{email}'
        )
    )
);

Now I can’t say this will work for all use cases but if you are looking for all of the registrations made with the user’s current email address you can use the above. EE does not have a method to pull every registration created by a user if they have use different attendee details on those registrations.

I think this is affecting quite a few registrations, and I have no way of quantifying which of the registrations were affected.

Just to clarify, affected in what way?

Every registration that has different attendee details will have its own contact for that attendee data. If you change the att_id you change the attendee (Note this is different from the wp user) that registration is linked to, meaning the registration will show that ‘new’ users details as it is not just a ‘link to the user that created the registration.

So to be clear, if you change the att_id on a registration to something else, you’ll update the details shown for that registration to whatever contact details that new ID has. This isn’t the WP User details, it’s the EE Contact details which you can see in Event Espresso -> Registrations -> Contact list.


deon@dieselbrook.co.za

November 20, 2019 at 6:34 am

Thank you very much for this. I will implement this and see if it is a better fit for our system.

Just to clarify, maybe affected wasn’t the best word choice. But rather, I can’t really quantify which registrations took place, but aren’t showing on the users profile due to a mismatch in ids.


Tony

  • Support Staff

November 20, 2019 at 8:15 am

If you haven’t done so already I highly recommend taking a look over the docs for our model’s system:

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

There’s a lot of info you can pull through the models fairly easily.

Just to clarify, maybe affected wasn’t the best word choice. But rather, I can’t really quantify which registrations took place, but aren’t showing on the users profile due to a mismatch in ids.

Ah, ok, yeah I understand.

EE doesn’t store the ID of the user that made a registration with that registration, so there’s currently no way to pull all registrations made by a specific user.


deon@dieselbrook.co.za

November 28, 2019 at 2:41 am

Thank you, sorry for only replying now. This works fine. I am going to do a combination of the two, both id and email. Because what happens is the admins register for the users sometimes from the backend, and i suspect that this is why the contacts are changed.

However, when I run the code above, it is giving me an error on the date for the event, relating to the start_date function on line 34. Apparently the object for get_related_primary_datetime() is null, the specific error:
Fatal error: Uncaught Error: Call to a member function start_date() on null
,but if I remove this function then it gives me the name of the event. Do I need to create an instance of EE_event and then run this?


Tony

  • Support Staff

November 28, 2019 at 4:46 am

No, you don’t need an instance EE_Event to run the above, but that mehtod has been deprecated, it threw the following notice since 4.9.17:

Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()

So use something like:

$latest_datetime = $registration->get_latest_related_datetime();
if($latest_datetime instanceof EE_Datetime){
    // Do something with $latest_datetime as an EE_Datetime object.
}

The above 2 methods order the datetimes related to the ticket on a registration based on the DTT_EVT_start value.


deon@dieselbrook.co.za

November 28, 2019 at 11:37 pm

Thank you for your help. However, when I implement this, I get the name of the event, and the id in brackets? Even if I add it within the instanceof conditional. Does the function normally return the title?


Tony

  • Support Staff

November 29, 2019 at 2:48 am

The code I gave you above doesn’t return/output anything so it will depend on what you’ve done with it. The get_latest_related_datetime() method returns an EE_Datetime object, which you can then run various methods on to output details.

Can you post the code you are now using to something like http://wpbin.io/ and add the link here for us to view?


deon@dieselbrook.co.za

November 29, 2019 at 3:04 am

Sure, apologies for the messy code, this is still on a development server while I sort out the event list. With this I just hook into the buddypress after profile hook and echo the shortcode that I create to display the event list there.

For the reference by ID section (the top code), I used the deprecated function, which still works correctly. Then I just append the new get via email section. The javascript function at the end just hides duplicate entries for the admin who registeres lot of users from the backend.

http://wpbin.io/jonlob


Tony

  • Support Staff

November 29, 2019 at 3:48 am

Ok, so the problem is your using objects as strings and your also confusing ‘Datetime objects’ with dates and times.

For example:

$reg_date_start = $registration->get_earliest_related_datetime() ;
$reg_date_end = $registration->get_earliest_related_datetime();

Using $reg_date_start and $reg_date_end variable names here is misleading and it’s going to confuse you. Those variables now hold EE_Datetime objects, not values, so when you use them like this:

$html .= '<td class="my-event-duration">' . $reg_date_start . ' - ' . $reg_date_end . '</td>';

You will not get what you are expecting, which is what I assume you mean with this:

However, when I implement this, I get the name of the event, and the id in brackets? Even if I add it within the instanceof conditional. Does the function normally return the title?

You are not getting the event name and ID there, you are getting the Datetime Name and ID but even then, this isn’t how you use objects and its only working because PHP is converting the object to a string for you, but then you have no control over what you output.

In the above example $reg_date_start and $reg_date_end could actually be 2 complete different DateTime objects, each with total different start and end dates, which again is going to cause more confusion.

Right now I can tell that changing $reg_date_start to be $reg_date_start->start_date() would fix that output for that call, but that’s only half the problem here and doesn’t change how both of those variables could be completely different datetime objects.

Similar code stands out in other locations, such as

$reg_event_id = $registration->event();

event() will NOT return and ID, it returns an EE_Event object.

Further on you have:

$reg_event_id = $registration->event();
$bracket_pos = strpos( $reg_event_id,"(") +1;
		
$reg_event_id = substr($reg_event_id, $bracket_pos, -1);

Because $reg_event_id is actually an EE_Event object at that point to get the ID you simply do $reg_event_id->ID(); (again I recommend changing the variable names as that is more confusing than it needs to be)

I highly recommend you read over the Model system documentation I linked to above, this:

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

You are running into multiple problems simply because your not using PHP objects correctly and you’re going to run into more of them until you understand what EE_Datetime and EE_Event objects (and the various others we have) are and how to use them. A lot of what you are trying to do is much easier to do once you use the objects.

You must be logged in to reply to this support post. Sign In or Register for an Account

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: publish

Updated by  Tony 1 week, 6 days ago ago

Topic Tags

Notifications

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