2

I need to calculate a score for users in D7 based on 3 variables and then assign an appropriate text label and a CSS class.

So, using data from Voting API, time ago joined, and number of nodes published, it needs to select and display one of 15 text labels such as "Promising newcomer, reliable veteran, etc".

Given that I am a site builder with limited PHP skills, where should I start? Should I setup 15 different rules to set a value on a list field?

Before investing time in Computed Field, Display Suite Custom Field or Views PHP, I would love advice from the Drupal community.

Looking for something similar to SE badges.

  • for Drupal 7 or 8? – No Sssweat Jul 5 '16 at 5:59
  • Drupal 7, but needs to have an upgrade path to D8 in the medium term. – JohnD Jul 5 '16 at 6:11
  • I could setup 15 different rules to set a value on a list field but is it the best way? – JohnD Jul 5 '16 at 6:18
  • I need to calculate a score what action exactly triggers this calculation? (when do you need to do the calculation?) – No Sssweat Jul 5 '16 at 6:25
  • 1
    @NoSssweat : IMO the goal of this question seems mostly to be related to calculations ... (after you get them right, leave it to themers to visiualize them ...). – Pierre.Vriens Jul 5 '16 at 8:54
0

A possible answer is to trigger Rules Actions based on a combination of Rules Events that happen asynchronously, and optionally after they were repeated multiple times. Which also requires some type of recording of the progress being made. Pretty challenging specs, but there is a solution (module) for it, as further explained below.

Goals module

You may want to look at the Goals module (disclosure: I'm its maintainer) as a possible alternative. To start using it only requires typical administration tasks (configuration), though it does come with various hooks also for custom module development (if you want to).

Since the Goals module is entity based, it has out-of-the-box integrations with modules such as Views, Rules, Flag, etc.

Requirements mapping

I need to calculate a score for users in D7 based on 3 variables and then assign an appropriate text label and a CSS class.

calculate: that's what Goals will do for you, by recording the progress made on the completion of each task required to reach a goal.

3 variables: that sounds like 3 tasks to be completed to achieve 1 goal.

assign an appropriate text label: you can optionally attach a (custom) image to each goal. The goals completed by a user, can be shown on a Views block included with Goals, with title "Your completed goals".

So, using data from Voting API, time ago joined, and number of nodes published, it needs to select and display one of 15 text labels such as "Promising newcomer, reliable veteran, etc".

using data from...: if you can think of a Rules Event to discover these events, you use the appropriate Rules Action (provided by Goals) to record progress on the completion of a task. E.g. if 1 such task would be to "create 10 nodes of type XYZ", then each time such nodes are saved (there is a Rules Event for it!), then Goals will record so. And if 10 such nodes were recorded, the task is considered completed. And if all tasks of a specific goal or completed, then the goal is reached.

Here is a screenprint of a rule to record a task activity about posting comments:

enter image description here

15 text labels: that sounds like 15 goals you'd have to configure using the admin interface of the Goals module (no custom coding involved).

More details

For more details about the Goals module, refer to my answer to "How to implement gamification in a Drupal site and award incentives?".

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.