1

I'm currently awarding medals to the users on my website by using the Goals and Rules modules: a medal awarding Rule fires when a Goal is completed. However, I'd like to get rid of the Goals module, because it is no longer maintained at the time of writing and it doesn't fully provide the functionalities that I need.

The Goals module has a nice feature, though: it is possible to record tasks that were completed within a certain period. I would like to keep this functionality, because some of my medals are granted to users who created X nodes in X days time.

Therefore, I had the idea to add a condition to my medal awarding Rules that checks whether the user created, say, 5 nodes in 10 days time. Is it possible to do this?

3
  • 1
    To whom it may concern: the "... it is no longer maintained..." part of this question is no longer valid as of yesterday, when I became the new maintainer of the Goals module. For more details, refer to drupal.org/node/2701961 . @Jeroen: maybe you want to update that part of your question, and change it to something like "for a while it was no longer maintained"? Commented Apr 8, 2016 at 9:21
  • @Pierre.Vriens: Nice to let everyone know you're blowing new life into the Goals project! I've rephrased my sentence into "at the time of writing".
    – Jeroen
    Commented Apr 8, 2016 at 16:48
  • 1
    Merci! ... For the updated question ... and the kudos! Commented Apr 8, 2016 at 16:52

2 Answers 2

1

I don't think rules by itself has the capability to do that - unless you get very deeply embedded into components, and by then it's almost the same as programming.

You probably need to write a custom module with a cron hook that checks how many nodes were created in the last 10 days. Do you want to know how many nodes were created at all, or just by a particular user? Either way that seems the best way to do it.

0
0

I've written the following function in my custom module in order to count the amount of published nodes of a certain user in the last period:

function MYMODULE_count_nodes($uid, $days) {
  $seconds = $days*24*60*60;
  $period = REQUEST_TIME - $seconds;
  $count = db_query("SELECT COUNT(*) FROM node WHERE uid=$uid AND status=1 AND created >= $periode")->fetchField();
  return $count;
}

Afterwards, I've created a Rule where the condition evaluates this code:

$count= MYMODULE_count_nodes($uid, 10);
return $count == 5;

Mind that the variable $uid isn't always provided directly in the Rule. In my case I used $uid = $flagged_node->uid;

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.