I wanna set the limit of -200 points. Users can donate to other users till this limit. is this possible?
thanks very much

Comments

berdir’s picture

Project: User Points » User Points Contributed modules
Version: 7.x-1.0-beta2 » 7.x-1.x-dev
Component: Code: userpoints » Code
Category: support » feature

This is currently not possible.

Moving over to the correct project and changing to a feature request.

The code that validates the points is below, it would be relatively simple to introduce a variable that allows to configure the limit, defaulting to 0.

  $current_points = userpoints_get_current_points($user->uid, $tid);
  if ($form_state['values']['amount'] > $current_points) {
    $categories = userpoints_get_categories();
    $arguments = array_merge(userpoints_translation() + array('@points' => $current_points, '@category' => $categories[$tid]));
    form_set_error('amount', t("You don't have enough !points available in the @category category to give away that many. You currently have @points !points available.", $arguments));
    return;
  }

Patches are welcome.

kwstasm83’s picture

is working!
thank you very much!

berdir’s picture

If you make your hack configurable using variable_get() and provide it as a patch, I can commit it and add it as a feature to this module.

Otherwise, your hack will get overridden each time you update the userpoints_contrib module and you will need to re-apply it.

kwstasm83’s picture

hi there!
I am quite new in development. I just change a bit the code. I put:
if ($form_state['values']['amount'] > $current_points + 200) {

But if You tell me how to use variable_get() and provide it as a patch or if you drive me to the right tuttorials i promise that i ll work in this.
Thank you

berdir’s picture

To make it configurable, you'd need something like this:

// Check that the user would still have more than the configured minimum points after the transaction.
if ($form_state['values']['amount'] - $current_points >= variable_get('userpoints_donate_minimum', 0)) {

Note that I slightly changed the code to make it (IMHO) more readable. In your case, you'd then need to set that variable to "-200". To do that, you need to expose the variable in the existing confirmation form. Have a look at the existing form fields, you simply need to give the new form element the same name as the variable and it will automatically be saved as one. Check out http://drupal.org/node/751826 to learn the basics about building forms in Drupal.

Lastly, you should also add a variable_del('userpoints_donate_minimum') into the uninstall hook, so that the variable is deleted when the module is uninstalled.

Feel free to ask if you have any questions.

edufol’s picture

Hi Berdir,

Thanks for your reply. :)
I would like to make the limit configurable for every user. I created a field for every user (field_ecos_limit) that establish the maximum debit that the user can have.
Is it possible to put the field inside this code?:

if ($form_state['values']['amount'] - $current_points >= variable_get('userpoints_donate_minimum', 0)) {

Thank you very much for your support. Sorry for my english :)

Eduard