Using the Rules module to solve this challenge is part of the solution you're looking for. But the key part of your challenge is that your question is about something (= access that node
) which:
- has to be repeated (=
X number of times
).
- within a specified timeframe (=
over a time span of 24 hours
).
- don't all happen at the very same moment.
Rules is great (amazing), but it does not support any of the 3 bullets above. So far the bad news ...
However, your question seems like a pretty good fit for using the Goals module (disclosure: I'm its maintainer), together with the Rules module. Below is a possible configuration to achieve your Goal, using Goals.
Configure a goal
Navigate to the relative path admin/config/goals/manage
and use the link "Add a goal" to define just 1 goal, with a description (say):
View some node, 8 times within 24 hours with a limit of 1 view per hour
.
Obviously, you can replace the 8
by whatever value of X
you'd want.
Configure a task
To achieve the above goal, define the Task(s) to be completed. Even though there could be multiple tasks to be completed for a single goal, in your case you just need 1. It's simply View a node
(assume we use a machine name like view_a_node
).
Obviously, that doesn't take into account the 8 times within 24 hours
-part of your question. For that you would use some of the more advanced ways to use (configure) Goals, i.e. by using these optional configuration options for this specific task:
- this task has to be repeated multiple times: in your case 8 times.
- this task requires some amount of time to expire in between any 2 similar tasks: in your case, if a user performs multiple refreshes of the same page in just a few seconds, only the first one of them should count. That why I'd use a limit of 1 view per hour.
- this task must be completed within a specific time frame (a number of times, expressed in hours, days or weeks): in your case 24 hours.
Track progress while performing tasks
To track the progress made by a single user to complete this task, you only have to write an appropriate rule, using the Rules module, to record relevant events happening in your site, which are related to the completion of the task to reach the goal.
For the goal/task described above, you'd only need 1 (extremely basic) rule, which would look like so:
Rules Event
: Content is viewed.
Rules Events
:
- Check user has role "authenticated" (how else would you know which user it is ...).
- Check the node id of the node being viewed.
Rules Action
: Record a task for Goals (obviously, the task to be recorded is "View a node"). This is where part of the Goals magic happens, such as verifying the requirements in the optional task configuration options for a task (only once an hour, etc).
Here is a rule that you could probably use for this (if you have a "task" defined with the exact machine name view_a_node
, just use the Rules UI to import it in your own site to get you going, if not adapt that machine name prior to starting such import):
{ "rules_record_task_view_a_node" : {
"LABEL" : "Record task view_a_node",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "goals" ],
"REQUIRES" : [ "rules", "goals" ],
"ON" : { "node_view" : [] },
"IF" : [
{ "user_has_role" : {
"account" : [ "site:current-user" ],
"roles" : { "value" : { "2" : "2" } }
}
},
{ "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "article" : "article" } } } },
{ "data_is" : { "data" : [ "node:nid" ], "value" : "123" } }
],
"DO" : [
{ "goals_task_record" : {
"task_name" : "view_a_node",
"user_to_save_for" : "[site:current-user]",
"task_id" : "Node ID of viewed node = [node:nid]"
}
}
]
}
}
Use Rules to process completed goals
After all tasks specific to a goal are completed by a user, the goal is automagically marked as completed. But, that's where it gets really interesting: you can also create additional rules that will be triggered (Rules Event) when a goal is completed by a user.
With that, the answer to your question is extremely easy. You actually have 2 possible answers to pick from:
- Just let the Goals grant the user points (if you have the Goals Extras submodule enabled).
- Perform a Rules Action to "... grant user points to the user who completed the goal" ... which is exactly what your question is about, no?
More info
Refer to my answer to "How to implement gamification in a Drupal site and award incentives?" for additional details about the Goals module.
Note: Using Goals only requires typical administration tasks (configuration), though it does come with various hooks also for custom module development (if you want to).