Thank you for this awesome solution.

Would it be possible to add Flag and/or UserPoints integration? Along with Voting API integration these two would add a great opportunity to draw users to register. Think of displaying messages like "You have collected 6 Awards! Log in or Register to claim your prizes." I already have a need for this but I'm sure many others would use it too.

Comments

icecreamyou’s picture

Status: Active » Postponed

This module is more proof-of-concept than anything and I don't have the time to work on it right now. It's been on my to-do list for over a year now and I'll get it to a more useful and stable state at some point but something like this won't happen until after the D7 port.

queryblitz’s picture

Thank you for the quick reply. I'll look around to see if I can build that functionality...

edit: Wow apparently Flag 2.0 already does this. Big oversight there on my part. I'll try to use Rules to grant UserPoints retroactively, then we're good.

queryblitz’s picture

Ok I figured out how to do this. I used Flags, UserPoints, Token, Custom Tokens, Rules, and probably a few others.

In my case, I wanted to give UserPoints to anonymous users for two flags, "Yes" and "No". In order to do this, I had to add a third flag to keep track of which nodes were flagged and which ones weren't. I named this flag "Answered" to denote that a node had been answered. For all three of these flags, I set "Roles that may use this flag:" to all the roles I had, but hide the "Answered" flag from being displayed by making sure none of the display options were checked. Using the Rules module, I created four different rules:

1. A node has been flagged, under "Yes"
2. A node has been flagged, under "No"
3. A node has been UNflagged, under "Yes"
4. A node has been UNflagged, under "No"

For the first two, I added the action "Flag a node" and set the "Flagged content:" to "flagged content:", the "User on whose behalf to flag:" to "flagging user," and the Flag being flagged to "Answered".

For the last two, I added the action "Unflag a node" and set the "Flagged content:" to "flagged content:", the "User on whose behalf to flag:" to "flagging user," and the Flag being flagged to "Answered".

This all sounds very repetitive but I had to keep track of which ones were answered and which ones weren't.

Once I had all this set up, I created a new token with the Custom Tokens module, set the Type as User and in the PHP text area placed the following, exactly as it shows here:

$uid = $account->uid;
$flag = flag_get_flag('answered') or die('no "answered" flag');

$count = $flag->get_user_count($uid);

print $count;

Then I set up a trigger that occurs "When a user account has been created", and added the action "Grant points to a user" and for the User I selected "registered user". For "Number of points", I placed the token I created with Custom Tokens, which was something like [account:token_custom_answered_nodes]. That gives the user 1 point per answer. That's pretty much it!

To test it out, go to queryblitz.com and click "Answer Queries", and after you answer a few set up an account and see how many QueryPoints you have! (Default is 20 QueryPoints, so add that in).

I've created a tutorial here: http://drupal.org/node/1367480