Rules Mastery 06 -- component for awarding points (solution)
Channel: Johan Falk
Date: 2012-03-05

This screencast shows, somehow lengthy, how to convert the previous point-awarding actions into a single component. In short:

* Browse configuration, workflow, Rules, components and create a new Rules component. A rule set is probably the best choice, but an action set or a rule would work too (so far).
* Give the component a sensible name, such as "Award Drupal points".
* Add two parameters -- input data -- to the component. You will need a user account (to give points to), and an integer with a number of points.
* Save the rule set, and then add a new rule inside it. The rule can, too, be called "Award Drupal points". (Follow the link to do add a rule -- don't go back and add a new reaction rule!)
* Add an action in the rule, that calculates the new Drupal points value. (Use the "calculate a value" action.)
* In the "calculate a value" action, add the account's current Drupal points to the points provided as parameter. Give the resulting sum a nice name.
* Add a new action for setting the account's new Drupal points -- use the "set a data value" action.
* Finally, add a new action to display a message on the site. Use the "show a mesasge on the site" action, found under "system".
* Add a message you find appropriate, such as "The user [account:name] now has [account:field-user-drupalpoints] Drupal points!".

Your component is now done! Now edit all your reaction rules and have them call your new component (found at the bottom of the actions list) instead of using the "set a data value" action. You will need to send in a user account and a points value as parameters to the component.


BONUS EXERCISES:
* Make this component display the user name only if the acting user is different from the rewarded user -- otherwise it should say "You *now* have XX Drupal points".
* Make the component display a different message if points are subtracted from a user (instead of added).

(This video is a part of the training found at http://denver2012.drupal.org/content/rules-mastery.)