Support

Home Forums Event Espresso Premium REST API Payment amount credit/deduct points (cont'd)

REST API Payment amount credit/deduct points (cont'd)

Posted: August 3, 2022 at 11:55 am


He Zhengrui

August 3, 2022 at 11:55 am

Hi Tony,

Related to this topic
https://eventespresso.com/topic/rest-api-payment-amount-credit-deduct-points/

I have managed to set up Kint Debugger and I manage to pull out all the information that I need when I run examples like this:

d(EEM_Registration::instance()->get_one_by_ID(8647)-> get('STS_ID'));

However, I am unable to retrieve the current ATT_ID or any other array values for that matter in my function unless specified statically.

$user_id = mycred_get_user_id(EEM_Attendee::instance()->get_one_by_ID('5282')->get('ATT_email'));

Any advice?


Tony

  • Support Staff

August 3, 2022 at 4:48 pm

d(EEM_Registration::instance()->get_one_by_ID(8647)-> get('STS_ID'));

Is going to output a STS_ID through kint.

Try:

$registration = EEM_Registration::instance()->get_one_by_ID(8647);
d($registration);

Now you’ll see a LOT more information like what properties are set and the methods available to pull data.

However, I am unable to retrieve the current ATT_ID or any other array values for that matter in my function unless specified statically.

Can you explain this further, please?

Similar situation with this:

$user_id = mycred_get_user_id(EEM_Attendee::instance()->get_one_by_ID('5282')->get('ATT_email'));

Don’t do this all in one go, what if you want more than one detail?

$attendee = EEM_Attendee::instance()->get_one_by_ID(5282);
$user_id = mycred_get_user_id($attendee->email());

There are ‘getter’ methods for pulling in the email rather than using get() which will suit you more here.

Is that ATT_ID from the registration you pulled in earlier? Because you can pull the EE_Attendee object directly from the EE_Registration object using our models to make this easier.


He Zhengrui

August 7, 2022 at 10:57 pm

Thanks Tony! Let me try it and get back as soon as I can, thanks!


Tony

  • Support Staff

August 8, 2022 at 8:53 am

You’re most welcome.

Let me know and I’ll help more if needed πŸ™‚


He Zhengrui

August 8, 2022 at 10:01 am

Hi Tony,

Thanks for the reply and your suggestions are awesome;

To clarify, where are the other ‘getter’ methods in the documentation in the Model system? I’ve scoured through the entire documentation to no avail unfortunately :/

Is that ATT_ID from the registration you pulled in earlier? Because you can pull the EE_Attendee object directly from the EE_Registration object using our models to make this easier.

And how may I go about this?

Thank you Tony, I’m making great progress!


Tony

  • Support Staff

August 8, 2022 at 3:18 pm

To clarify, where are the other β€˜getter’ methods in the documentation in the Model system?

We don’t have every single method within our models documented which is why I recommend kint.

I’ll give you an example of how I use it so you can find various details.

A EE_Registration’s link everything together, the contact, the event, the ticket etc. So first lets say we need an EE_Registration with ID 425… this is how I’d get it:

https://monosnap.com/file/NNFJz1LjPfxEMx3pZS383XWy6qfoZy

Kint gives me a nice readable format, click on the EE_Registration object (never use the + sign, it opens all children… not good with out models as there can be a lot of them, just click on the name to open that level).

That gives you a breakdown of the objects properties:

https://monosnap.com/file/xFvmU7KNxMZZSTPexlArUQ7dspbCzL

What you need, are the available methods, there’s a tab for them:

https://monosnap.com/file/ShjjiwwbgMVulx9xAiYcg67oZRvItP

The EE_Registration object currently has 197 methods.

‘Getters’ and ‘setters’ are basically just methods used to ‘get’ or ‘set’ something (easy when you put that together πŸ˜‰ )

So to give an example there is a get_primary_registration() getter, which, returns the primary registration for a group:

https://monosnap.com/file/ShKAKoLZaDqrkoV7QmX7IH0UNLDX4h

You can go through and find all kinds of methods there and the names are pretty self-explanatory so in this case, if you are looking for get/set methods you are better looking over the method available and finding them by name rather than going through the documentation.

And how may I go about this?

You do the above πŸ™‚

What you’ll then find is an attendee() method, which returns the related EE_Attendee object.

https://monosnap.com/file/SX6COxMAAk9wcpFq8pqQEZYZ7OFiHL

Honestly, taking the time to learn how the models work will save you so much time if your going to be working with EE and custom code.

$registration = EEM_Registration::instance()->get_one_by_ID(8647);
if(! $registration instanceof EE_Registration) {
    return;
}
$attendee = $registration->attendee();
if(! $attendee instanceof EE_Attendee) {
    return;
}

At this point you know that $registration is an EE_Registration object and $attendee is the EE_Attendee object related to it. See how it becomes much easier just by knowing a little more above the models πŸ™‚

d($attendee);

Gives you all kinds of useful info: https://monosnap.com/file/sd54mvv3lJ0dzCrgsZgtyUTBBeE81i

164 methods on an EE_Attendee object, any related to email? lets check. Searching for email gives me 2 methods.

email(): https://monosnap.com/file/lxq1QcsjY7RmsMEpmKuNMJJGxl1yCH

Returns the attendees email address, that’s basically a getter for email and does get('ATT_email') in the background. But email() could more obvious, not so much in this use case, but the setters and getters take the logic away from what you are getting and jut give you it. You don’t need to know what ATT_email is…. email() gives you it!

It also gives you a setter, set_email(): https://monosnap.com/file/WzZ2XEPjKNVpBBqiLYboKoCYksvEAQ

To be honest, you shouldn’t be using that unless you need to change the email address of the attendee through code, which you shouldn’t. But as I’ve mentioned setters I might as well use the example.

$attendee->set_email('example@example.com');

Would set the email on that attendee to the value you just passed… thats a setter. Again, you didn’t need to know about ATT_email as the setter handles that for you etc.

So the idea here is to get familiar with the methods available and how the models work. Spending the time to get familiar with them will help you much more than reading the docs for specific methods.

There is more than enough info to get you familiar with them in the docs available: https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System

But playing around with them to find what you need with a little bit of basic knowledge of them, helps πŸ™‚


He Zhengrui

August 10, 2022 at 12:58 am

Roger that Tony!

Thank you for such a detailed explanation and examples.

I will once again go with this new information and give it a try!

Cheers!


Tony

  • Support Staff

August 10, 2022 at 7:03 am

You’re most welcome πŸ™‚

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

Event Espresso