Jump to content

Getting started with User Profiles and related Tables/Fields


i3i2uno
 Share

Recommended Posts

Hello, I am starting to build a project for a client that wants a customer portal. I have begun playing around with the FrontEndUserProfile module and all is working. My question is essentially wrapping my head around exactly how to setup my "tables/fields" so that I can have a many to one relationship. (most of my experience is with MSSQL and asp.net)

Basically I need to create a table that holds donation amounts for users. Each user can have multiple donation amounts. And I want to be able to call "Select * donations where $user->id == $donationId orderby dateAsc" (I know that this context is off but I hope you get the idea)

I am still wrapping my head around exactly how PW makes these api calls and how the fieldtypes work, and I am probably making this harder than it has to be because it seems that PW has an easy answer for nearly everything. Can someone point me in the right direction on how best to accomplish this with PWire?

Thanks!

Link to comment
Share on other sites

There are a couple of ways to accomplish this from creating your own inputfield to using templates. This is how I would do this. You create a template called 'donations' (/donations/) and a template called 'donation' (/donations/donation). You create a

called 'donations'. You add the donations fieldtype to the user template - be sure to enable "Show system templates" in the filter option above the templates in the admin. Now you can create a donation through the API:
// Create a new donation page
$donation = new Page();
$donation->parent = $pages->get("/donations/");
$donation->title = "Some random title";
$donation->amount = 10; // Or any number
$donation->save();

// Assuming the right user is logged in
$user->donations->add($donation);
$user->save();

And it is saved in the Page fieldtype with the users. As a reference see the excellent cheatsheet by Soma and Ryan.

You sure need some code for a user to login, to process the donation itself, bit this gives a basic example of how to save through the API. Note: this is all written in the browser so it might generate some error.

  • Like 2
Link to comment
Share on other sites

You're welcome. It takes some time to get used to the 'simple' way of thinking, but after a while you see the greatness of the simplicity and you build all kinds of this stuff. Do not hesitate to ask more questions.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...