It would be easy to write one or more simple snippets to check and/or update the credits field to use with ClassExtender, but getting them to act at the right time and cause the result you want might be tricky.
Hmm. Maybe the credits can be placed in tv or other independent structure, that might be a much easier way.
CE is mostly for user info, not for values that are expected to change a lot or have a front-end changing system. AFAIK, CE values are pretty much expected to be fixed and only changeable from within the manager or through the update profile snippet for login. At least that's how I interpret Bob's answer.
What do you think, Bob? Payment is outside the system, and the adding of credits can easily be a manual tool that the manager will carry out. What structure is suitable to hold those credits and allow them to be subtracted by the logged-in user when choosing a class to attend?
I wonder if its worth it to look at some of the e-shopping extras...
But this seems like it could just be in a tv or other very basic structure. I use xpoResources or whatever its called to track hits on my pages, and all you want is the same function where the adding and subtracting of values are in a simple button on the page...it should be mad simple.
On the page with the button it is just, get current user, check if user has credits or block out button, then click button=[-1credits], unclick is +1 credits...and then the manager has to know where and how to add credits.
I am sure some users have good ideas.
It depends on how many users there will be and how much you want to automate things. It sounds like you want to have the system automatically update the credits and allow or deny users to perform certain actions. That will require some custom snippets.
I don't think a TV is a good option for a variety of reasons, the main one being that they are tied to resources, not users, and the credits belong to specific users.
Actually, if credits are the only thing you want to store, you could re-purpose an unused User Profile field like fax, photo, or mobilephone.
If you have other user fields to store that are not in the profile fields, using ClassExtender to extend modUser and store those fields as well as the credits is a good option.
@nuan88: Interesting idea, store the credits in a TV. I've been in contact with Mark Hamstra from modmore and the buying/paying credits it's no problem with simplecart, one of the shopping extras.
@BobRay: Thanks for joining this discussion. They're goanna be not be more than 100 users for now.
The storage of the credits I believed I'm helped with, so thanks all of you. The only thing I have to figure out is how to update credits on attending to a event. The adding of the credits I can do manually or arrange something with the shopping extra.
Thanks so much guys,
Ilja
Ok glad you are sorted. Keep in touch!
With due respect to nuan88, I really don't think a TV is going to be a good solution, since its values will be tied to specific resources, not specific users. TVs are also notoriously slow and inefficient for storing data you need to access regularly.
It depends on where you store it (User Profile field, or custom table with ClassExtender) and whether you want to update manually or automatically.
In either storage case, you can update it manually on the Create/Edit User panel.
If you use the fax field of the User Profile, for example, and you want to update it in code for the current user:
$addedCredits = 10;
$profile = $modx->user->getOne('Profile');
if ($profile) {
$currentCredits = $profile->get('fax');
$newCredits = $currentCredits + $addedCredits;
$profile->set('fax', $newCredits);
$profile->save();
}