Search code examples
drupaldrupal-7userpointsfivestar

Drupal 7 - Fivestar and Userpoints


i have a content type and the possibility for logged in users to vote on it. there are 5 different fivestar votings (categories) on the node. now i want to add userpoints and wanted to ask if it is possible that when a user votes that he gets 1 point for every vote on a node, so 5 points if he votes in every category. he has the possibility to change the vote later, but then he shouldn´t get any points anymore. is this possible?

greets


Solution

  • While it doesn't look like there is an existing 7.x or 8.x module that accomplishes this, there are two ways you should be able to accomplish your goal:

    • Write a module. The Userpoints API is fairly well-documented and it should be possible to create a module to increment a user's userpoint count when a fivestar field is modified. To avoid duplication, note that this field looks like it should accomplish the de-duping you are looking for (assuming you set txn_id to some combination of the current node ID, field ID, and user ID:

    'txn_id' => (int) Transaction ID of a current points record. If present an UPDATE occurs

    • Use Rules. The userpoints module integrates with Rules, so you should be able to accomplish your userpoints use case without writing any code. According tho the Userpoints Rules integration notes, you can compare the current userpoints to the number of points before the transaction:

    Compare Userpoints before the transaction - This condition is used to compare the amount of userpoints the user had before the userpoints was added to/deducted from the user against a specified value. - The 'Amount to compare' value is checked as >= (greater than or equal to) and the Negate checkbox will change the condition to < (less than) as it will be any value other than >=. If you would like to get an exact value, say 1, you can add two of the condition to use >= and < to specify one number. Simple math stuff here =)

    I hope this helps. Let me know how it goes!