1

I want to achieve the following functionality and I'm wondering if this could be possible:

For each purchase, one can gain userpoints (I can handle this using Rules).

Those userpoints will then be used to vote nominees. So if I have 1000 userpoints, i can use 300 for Candidate A, 500 for Candidate B, and and 200 for Candidate C. ( 1 userpoint = 1 ballot)

Can some give a hint/suggestion on how I could implement this. Workflow would be:

  1. I select a candidate.

  2. "Input" a vote amount.

  3. Vote gets recorded.

  4. Vote amount will be deducted from my userpoints.

1

Use the integration between the User Points module and the Rules module to "roll your own cookies", by writing some custom rules to transfer user points from one account to another.

As a sample, have a look at this rule, which is used in combination with voting of a node, whereas the author looses "-2" points, and the voter looses "-1" points:

{ "rules_votedown_question" : {
    "LABEL" : "votedown_question",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "answers" ],
    "REQUIRES" : [ "rules", "voting_rules", "userpoints_rules" ],
    "ON" : { "voting_rules_insert_node" : [] },
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : { "answers_question" : "answers_question" } }
        }
      },
      { "voting_rules_condition_check_vote_value" : { "vote" : [ "vote" ], "value" : "-1" } }
    ],
    "DO" : [
      { "userpoints_action_grant_points" : {
          "user" : [ "node:author" ],
          "points" : "-2",
          "tid" : "0",
          "entity" : [ "" ],
          "description" : "Receive downvote to [node:type-name] \u0022[node:title]\u0022",
          "operation" : "QuestionDownvoteReceived",
          "reference" : "By uid=[vote:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
          "display" : "1",
          "moderate" : "default"
        }
      },
      { "userpoints_action_grant_points" : {
          "user" : [ "vote:user" ],
          "points" : "-1",
          "tid" : "0",
          "entity" : [ "" ],
          "description" : "Issue downvote to [node:type-name] \u0022[node:title]\u0022",
          "operation" : "QuestionDownvoteIssued",
          "reference" : "From uid=[node:author:uid], for [node:type-name] to q=\u003Ca href=\u0022\/node\/[node:nid]\u0022\u003E[node:title]\u003C\/a\u003E",
          "display" : "1",
          "moderate" : "default"
        }
      }
    ]
  }
}

If you simply adapt the amount of points (-2 and -1) to something like (eg) +300 and -300, you've a prototype to transfer (300) user points from one user to another (eg Candidate A). Just repeat for Candidate B and C.

If you replace the Rules event by an event like "something is flagged" (created with the Flag module), a simple click could be used to indicate "I want to transfer some predefined (hardcoded) amount of user points of mine to this user). You could take this even a step further: since flags are fieldable, you could add a field to indicate the amount of points to be "moved", so that the user could enter "300" for Candidate A (instead of some hardcoded, fixed amount).

However, the above Rules example may need further refinements, e.g. if you want to ensure that after moving points from User A to User B, the remaining points for User A is not negative. Refer to "How to check whether one's current User Points are negative with the Rules module?" for details about how you can implement such refinement also.

PS: I'm assuming this question is about D7.

0

First of all i think you need to elaborate the question a bit more. And as far as i understand your question, you can do this using flag, you can provide the user some flag to vote and set a rule where the nominee will be donate the vote from his points when the flag is flagged. Hope it helps

  • Thanks. I'll try to make it more clearer. :) I need "Userpoints" in order to vote for a candidate/node. (And I can only be granted userpoints when I purchase products. $1 - 1point) <- Could be easily done using Rules. Now for instance, I have 300 points, and I'd only like to give 233 points to Candidate A and 67 points to Candidate B, how do I go through with this? With flags, isn't it only limited to a single vote/unvote per user? I'd like to have the functionality to "Input" a "desired amount of votes" to a candidate/node. With the deduction of userpoints,I could do this with Rules also. – rareglove99 Apr 3 '13 at 8:05
0

So according to your desired workflow. You can follow these steps:

  1. Create a drupal form having two fields 'select candidate' and 'input vote'.

  2. Now check if input vote < userpoint.

  3. And if yes on form submit record the vote and grant nominee points and deduct from the logged in user. You can use form_rules to trigger a rule on form submit or validate or alternatively you can use userpoints api to grant or deduct points.

  4. And if no , show the user a message that user don't have enough points.

  • Thanks for your replies nit3ch. But what would be the "field/widget" used in the "input vote" field? (Because i need to retrieve the data for monitoring of who is leading/winning and show it as a real time graph/poll) Do i need additional modules/APIs? I already looked into a lot of voting modules like Rate, Fivestar, Poll, and similar modules but all of them does not have the functionality to input a "desired amount of votes" (Maybe trying to find solutions by using "voting" modules is not the right track to solve this special "voting" functionality). I Really appreciate your time on this. – rareglove99 Apr 4 '13 at 0:37
  • you can use custom int field and also you can retive data using view and show it as a graph.Since user is just donating their userpoints to nominee so it is easier to find the leading nominee on the basis of points. – nit3ch Apr 4 '13 at 6:05
  • Let me clarify if this is what you mean. Add an "integer" field to the form as the "Input vote" field, then since it is a form, I should be able to collect all the votes when a user "submits" his votes. Is that what you mean? (I have no problem with making the monitoring/graphing functionality) – rareglove99 Apr 4 '13 at 6:16
  • Btw, is it possible to reference nodes to webforms? Since I will need to create a content type to encode all the candidates (might reach a hundred). And based on your suggestion, I'm assuming that I could just assign the "Inputted vote" to the selected candidate in the form? – rareglove99 Apr 4 '13 at 6:23
  • when the user input vote they are actually donating userpoints to the nominee, the input vote (userpoints) is deducted from the user on form submit, granting and deducting userpoints can be done using userpoints_api as i stated earlier.So the nominee having maximum userpoints is the winner.Hope i am clear enough this time. :) – nit3ch Apr 4 '13 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.