Step 1 - Create a flag for tracking Passed Quizes
Use the Flag module to create a flag labeled (e.g) Passed Quizes. Here is an export of the flag I used for this (you should be able to import it in your own site also):
$flags = array();
// Exported flag: "Passed Quizes".
$flags['passed_quizes'] = array (
'entity_type' => 'node',
'title' => 'Passed Quizes',
'global' => '0',
'types' =>
array (
0 => 'quiz',
),
'flag_short' => 'Flag this item',
'flag_long' => '',
'flag_message' => '',
'unflag_short' => 'Unflag this item',
'unflag_long' => '',
'unflag_message' => '',
'unflag_denied_text' => '',
'link_type' => 'toggle',
'weight' => 0,
'show_in_links' =>
array (
'full' => 'full',
'teaser' => 'teaser',
'rss' => 0,
'search_index' => 0,
'search_result' => 0,
'answers_full_node' => 0,
'print' => 0,
'question' => 0,
'token' => 0,
),
'show_as_field' => 0,
'show_on_form' => 0,
'access_author' => '',
'show_contextual_link' => 0,
'i18n' => 0,
'api_version' => 3,
);
return $flags;
This flag will be used in the custom rule, detailed in the next step.
Step 2 - Create a single rule to cover all situations
Here is a rule which illustrates how to resolve the challenge in your question:
{ "rules_process_a_quiz_when_passed_the_very_first_time" : {
"LABEL" : "Process a quiz when passed the very first time",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "quiz" ],
"REQUIRES" : [ "rules", "rules_conditional", "flag", "entity" ],
"ON" : { "quiz_result_update" : [] },
"IF" : [
{ "entity_is_of_type" : { "entity" : [ "quiz-result:nid" ], "type" : "node" } },
{ "data_is" : { "data" : [ "quiz-result-unchanged:is-evaluated" ], "value" : "0" } },
{ "data_is" : { "data" : [ "quiz-result:is-evaluated" ], "value" : "1" } },
{ "NOT data_is" : {
"data" : [ "quiz-result:score" ],
"op" : "\u003C",
"value" : [ "quiz-result:nid:quiz:pass-rate" ]
}
}
],
"DO" : [
{ "CONDITIONAL" : [
{
"IF" : { "NOT flag_flagged_node" : {
"flag" : "passed_quizes",
"node" : [ "quiz-result:nid" ],
"flagging_user" : [ "site:current-user" ]
}
},
"DO" : [
{ "drupal_message" : { "message" : "Congratulations, this is the FIRST time you passed this quiz (with a score of [quiz-result:score] %, whereas the pass rate is [quiz-result:nid:quiz:pass-rate] %)." } },
{ "flag_flagnode" : {
"flag" : "passed_quizes",
"node" : [ "quiz-result:nid" ],
"flagging_user" : [ "site:current-user" ],
"permission_check" : "1"
}
}
]
},
{ "ELSE" : [
{ "drupal_message" : { "message" : "Congratulations, you passed this quiz yet ANOTHER time (with a score of [quiz-result:score] %, whereas the pass rate is [quiz-result:nid:quiz:pass-rate] %)." } }
]
}
]
}
]
}
}
This rule requires the Conditional Rules module to be enabled (head over to the next step for some (multiple!) alternatives which does not need this extra module).
Here are the critical pieces of this rule to make Rules-magic happen:
- The very first Rules Condition, which is "the" way to get access to all sorts of data about the quiz node itself (starting from "a" quiz result).
- If the quiz node (to which this quiz result relates) is not yet flagged (by the flag from Step 1), and the quiz result is that it is at leastd equal to the pass rate of that quiz, then you have your very first hit you're looking for. At which time the quiz node gets flagged.
Use the Rules UI to import the above rule in your own site, after you enabled the Conditional Rules module and completed Step 1. After you are convinced it works as designed, simply add your additional Rules Action(s) to grant the User points ... only the very first time.
Step 3 - Possible Rules variations
Some variations of the rule included in Step 2, which should also achieve a similar result:
- Replace the logic implemented via the Condtional Rules module by 2 equivalent Rules Components (so that you don't need the extra module). Refer to "What's the alternative to using the Conditional Rules module?" for way more details on this.
- If you DO NOT want anything to happen if the quiz was already passed before, then the "else"-part of the Conditional Rules logic is empty. In that case you could rework the remaining Conditional Rules logic to a regular Rules Condition (to be executed as the very last one). As a variation, clone such rule variation in a 2nd variation, in which you just reverse that very same Rules Condition (with Rules Action as in the "else" part of the Conditional Rules logic).
Showtime
Here is a sample of a message I received after passing a quiz:
The very first time:
Congratulations, this is the FIRST time you passed this quiz (with a score of 80 %, whereas the pass rate is 75 %).
The next time:
Congratulations, you passed this quiz yet ANOTHER time (with a score of 100 %, whereas the pass rate is 75 %).
PS: I'm assuming this question is about D7 ...