2

Using the User Points module, I have this use case to design:

"move user points from User A to User B"

What are the possible approaches we have here?

  • Welcome to Drupal Answers! The best is always subjective. What is the best for a user could not be the best for another one. – kiamlaluno Jul 15 '16 at 12:45
  • Asking for a list of things also doesn't suit Q+A, as we're looking for questions with a single, objective answer. – Clive Jul 15 '16 at 12:46
  • Also the question is a bit too broad, to be answerable. What did you try? What problems did you have when trying to achieve what you described? What modules are you willing to install? What modules did you already install? – kiamlaluno Jul 15 '16 at 12:49
  • Thanks for pointing out. What I really need is actually an idea, an approach, a scenario. Do you think I'd better to remove this question away from here? – augusto Jul 15 '16 at 13:03
  • Yes, it would be best to remove it @augusto. it's always going to be too broad, the fact that the answer begins with "there are at least 2 approaches" says it all really. If you can get it a lot more narrow, then editing this post isn't the right way to go, as it will invalidate the answer and cause confusion. So deleting it and re-asking when you have a more direct question would be great. If you can't delete it but would like to, please just flag for a mod to do it – Clive Jul 15 '16 at 14:22
1

There are at least 2 approaches you can choose from, as further detailed below ...

User points donations

Use the Userpoints Donation module, which is one of the modules included in the (D7 version of the) Userpoints Contrib module.

To use it, make sure to also grant the required permission related to it (and to avoid asking yourself "How is the module Userpoints Donation intended to work?" ...).

Rules

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) +25 and -25, you've a prototype to transfer (25) user points from one user to another.

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 25 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".

However, the above Rules example may need further refinements, e.g. if you want to ensure that after moving points van 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.

| improve this answer | |
  • Approach 1 did the job. Thanks for sharing @Pierre Vriens. IMO, "Points donations" name is not appropiate, since in my use case the act is "give", not "donate". – augusto Jul 18 '16 at 12:28
  • @augusto : merci for the feedback, and accept. You're right about the "donations" name ... that's one of the advantages if you'd use Rules (= roll your own cookies, and use names/labels that fit for you). – Pierre.Vriens Jul 18 '16 at 12:34
  • Make sense. I need Users to input the amount of points. For this, Approach 1 ready to use form works pretty well. Thanks! – augusto Jul 18 '16 at 12:47
  • 1
    The advantage of using Drupal, pick what fits best for you, right? I understand that a ready to use form may be attractive, but using the flag module that's only like adding 1 extra field to the flag (fieldable flags!) also. And Rules+Flag have official releases, while userpoints donations is part of a module that is still in dev status. So if "I" was to decide for "my" site, I'd go for Rules+Flag (2 modules I'd probably have in my site already anyway, so no need for an extra module that does just donations). Not to try to change your mind though! – Pierre.Vriens Jul 18 '16 at 12:54

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