I'm trying to implement bonus calculation system to my website. It should calculate bonuses for users.

This is how it should work:

  • User1 can get 2% bonus
  • User2 has for example 100 points
  • The bonus for User1 is calculated as User2 points * User1 bonus % * level x%

There are different levels of bonuses.

  • Level1 x% bonus: User1 gets amount x% of bonus from three users who have registered after User1. So User1 gets bonus from User2, User3 and User4.

  • Level2 y% bonus: User1 gets amount y% of bonus from nine who have registered after User1, User2, User3 and User4. Like this: User1 gets bonus from User5, User6, User7, User8, User9, User10, User11 and User 12.

There are 9 levels and it continues like explained above. Users are multiplicated by 3 so users where User1 gets bonuses are: 3, 9, 27, 81.. etc.

Any ideas how to implement bonus calculation? I was thinking about using the Rules module, but I am not sure how it can handle this. Does performance suffer, if there are ten of thousands or even more users?

The Userpoints module will be used.

  • WHEN exactly should such calculations happen? HOW do you want to present these calculations (in their profile, or via some tabular overview of all users together)? For level2 bonus: shouldn't that also include user13 (if not there are only 8). Isn't there (at least) 1 typo in your 3rd bullet to calculate bonus for user1: what is 'user 1 bonus %, + why does it not include anything for level 2 y% bonus? What do you mean by "users are multiplicated by 3". Why would you use Rules for this (to do what)? I'm thinking of a straight forward solution, but first I need to understand your calculations. Commented Mar 3, 2016 at 14:37

1 Answer 1


Treat bonuses as fields, and use Computed Field to manage calculations:

Computed Field is a very powerful CCK field module that lets you add a custom "computed fields" to your content types. These computed fields are populated with values that you define via PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it. (Feeling the power yet? :) ) You can also choose whether to store your computed field values in the database with other content fields, or have them "calculated" on the fly during node views. (Although you should note that Views use requires database stored values.) This field is literally the Swiss Army knife of CCK fields. So start cooking up your PHP based values!

In user's profile, keep an Entity Reference to all users that registered from his links or gave his name at registration. Use simple recursion or deep scan to make actual computation, and you're there.

  • Okey, thank you for your answer. But in this case users gets bonus from all users who have registered after them. So no need to register through link are give name/code at registration form. So somehow there should be able to calculate bonuses from users who have registered after UserX.
    – hene
    Commented Sep 2, 2013 at 7:48
  • @hene in Computed Field you can query for all users registered after this one all right. Either directly with db_select or "properly" with EntityFieldQuery. But "how to get next X users that registered after user with known uid?" should be separate question IMO.
    – Mołot
    Commented Sep 2, 2013 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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