I installed, and activated the module, but I don't understand when it should block a user from creating a node.
In the module source I find the following lines:

function userpoints_nodelimit_check($nodetype) {
  global $user;

  $current_points = userpoints_get_current_points($user->uid);

  $node_points = variable_get(USERPOINTS_POST . $nodetype, 0);

  if (($current_points + $node_points) < 0) {
    return FALSE;
  }
  else {
    return TRUE;
  }
}

That means the user will be blocked only when the sum of $current_points, and $node_points is negative, which turns to be true only when one of the values is negative, and its absolute value is greater than the other value; because $node_points is generally positive (we don't want to take off points to users who contribute by creating a node, do we?), then the module will take actions only when a user has negative points.
If a Drupal installation uses also userpoints_no_negative.module, that will never happen.

Comments

jredding’s picture

I believe this module was created such that a node creation is a "charge" so yes when a node is created it would subtract points. Then when the user has no more points they can't create any more nodes.

The use case would be a job posting/classified ads (i.e. you pay for so many points and can use them however you want).

This should be better documented in the module or flipped around so that the number can be post or negative "nodes can't be created with a point value higher/lower than X "

avpaderno’s picture

Title: When does userpoints_nodelimit.module block a user from creating a node? » userpoints_nodelimit.module should better document how to use it
Category: support » feature

I change the title of the issue.
The module should better document how to use it. I activated it thinking it would limit the number of nodes a user could create, but because normally one give points for the creation of a node, userpoints_nodelimit.module will never take actions.

kbahey’s picture

Status: Active » Needs work

Please create a patch with the appropriate help and/or README that would describe this.

avpaderno’s picture

Status: Needs work » Needs review
StatusFileSize
new1.44 KB

The objective of the module should also be better described in the project page too.

jredding’s picture

yes.. I'll be sure to update the project page.

I agree documentation is best for this but why not simply adding a setting to the module to configure a point value wherein the node limit kicks in?

The only difference would be on that line of code, instead of 0 it'd be $limit_value.

This way you could use it the way you though it'd work (when I user reached a certain height of points) or in the way it was originally intended (i.e. they couldn't dip below 0).

just a thought.

avpaderno’s picture

That is a good idea.

-- Kiam@AVPnet

kbahey’s picture

Status: Needs review » Needs work

Setting this to CNW.

Kiam, if you can roll a patch to do what jredding said, that would be good.

avpaderno’s picture

Status: Needs work » Needs review
StatusFileSize
new3.04 KB

Done.
The implementation in the patch uses a value which is unique for every kind of node, that avoids to pass to userpoints_nodelimit_check() the kind of node being created.

The new patch also fixes a little "bug" present in the previous one (I forgot to call userpoints_translation()), and it optimizes a little userpoints_nodelimit_check() (the last if instruction has been replaced by a single return instruction). It also changes the line:

  $form = NULL;

to:

  $form = array();
kbahey’s picture

Status: Needs review » Needs work
(Stripping trailing CRs from patch.)
patching file userpoints_nodelimit.module
Hunk #1 FAILED at 18.
Hunk #2 FAILED at 71.
Hunk #3 FAILED at 87.
Hunk #4 FAILED at 91.
4 out of 4 hunks FAILED -- saving rejects to file userpoints_nodelimit.module.rej

The patch fails to apply.

Please reroll it against what is in CVS now.

avpaderno’s picture

Done.

avpaderno’s picture

Status: Needs work » Needs review

I forgot to change the issue status.

kbahey’s picture

Status: Needs review » Needs work

It we better if we had a patch attached.

avpaderno’s picture

Oops.
May I suggest to close this issue, and continue on #265677: userpoints_nodelimit.module needs cleanup? In that way I can put a global patch for both the issues.

kbahey’s picture

Status: Needs work » Closed (duplicate)