How to check if user has passed the quiz already before granting user points? I'm awarding users points for passing a quiz successfully. However, there's nothing stopping the user taking the quiz again and again to score more points.

I have thought of these options, but I don't know how to implement them:


check if the user has achieved a certain score before awarding points
lock down the quiz for users who have already passed it, redirecting them to their results page
tagging the quiz with users ID when they complete it the first time and and denying points when they complete it again.


Any help?
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' =&gt; 'node',
  'title' =&gt; 'Passed Quizes',
  'global' =&gt; '0',
  'types' =&gt; 
  array (
    0 =&gt; 'quiz',
  ),
  'flag_short' =&gt; 'Flag this item',
  'flag_long' =&gt; '',
  'flag_message' =&gt; '',
  'unflag_short' =&gt; 'Unflag this item',
  'unflag_long' =&gt; '',
  'unflag_message' =&gt; '',
  'unflag_denied_text' =&gt; '',
  'link_type' =&gt; 'toggle',
  'weight' =&gt; 0,
  'show_in_links' =&gt; 
  array (
    'full' =&gt; 'full',
    'teaser' =&gt; 'teaser',
    'rss' =&gt; 0,
    'search_index' =&gt; 0,
    'search_result' =&gt; 0,
    'answers_full_node' =&gt; 0,
    'print' =&gt; 0,
    'question' =&gt; 0,
    'token' =&gt; 0,
  ),
  'show_as_field' =&gt; 0,
  'show_on_form' =&gt; 0,
  'access_author' =&gt; '',
  'show_contextual_link' =&gt; 0,
  'i18n' =&gt; 0,
  'api_version' =&gt; 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&#39;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 ...