Following my silly posting of this support/feature request in the wrong place, here it is hopefully in a better place.

Does anyone know how you could perform a rules action after a quiz is passed in Drupal 7?

I've tried a roundabout route by triggering a custom action at the end of the quiz that takes them to a URL, fires the rule that looks at a view which lists the tests the user has passed. Sadly there doesn't seem to be any way to filter by either passed tests or score in views (for Drupal 7, there does seem to be a patch for 6) so I'm stuck there. I then thought about using the user points module to give points and trigger the rule if the amount of points to be given would be the pass rate but that seems like a really roundabout approach.

Ideally there'd be a "A user passes a test" event in Rules.

Or a filter by pass or fail status in views.

Or even a filter by score in views.

I'm happy to just use a php snippet in Rules as in this issue http://drupal.org/node/1149930 but am having no luck adapting it to work without error messages as things have probably changed in rules, core and quiz between Drupal versions.

Has anyone worked anything like this out for D7?

Thanks in advance for any help offered.

Comments

romaingar’s picture

Hi,
Did you find any solution or is there any news about this feature ?
Thanks

FilipNest’s picture

I've hacked something together with Rules and Views Bulk Operations but a built in rule would be great.

elearner’s picture

Would this be useful?

For rule turn on php filter module and in the rule select "execute custom php code" as action. No conditions.

Sample Code from v-a-1 to iterate through quizzes, figure out if user has passed and do relevant action.

   // get details of quizzes attempted for the current user
    $result = db_query_range( 'SELECT n.nid, n.score, n.vid, n.time_end 
                                FROM {quiz_node_results} n 
                                WHERE n.uid = %d', $user->uid, 0, 1000 );

    // now iterate through result
    while ( $r = db_fetch_object( $result ) ) {
        $quizvid = $r->vid;

        // now get pass rate for each quiz node using vid. each vid might have different pass rates
        // so dont use nid
        $res = db_query( 'SELECT n.pass_rate
                            FROM {quiz_node_properties} n 
                            WHERE n.vid = %d', $quizvid );
                            
        // iterate through result
        while ( $r2 = db_fetch_object( $res ) ) {
          
            // if score is equal or higher than pass rate,
            // user has already passed the test. testing against nid, because future revisions
            // might end up making a user un-passed. so dont use vid here.
            if ( $r->score >= $r2->pass_rate ) {
                //DO WHATEVER ACTION CODE HERE
                //LIKE ASSIGNING ROLE TO USER
                //not sure how it works. i am sure you can find it if you search for it.
            }
            else {
            }

        }

    }
djdevin’s picture

Version: 7.x-4.x-dev » 7.x-5.x-dev
Issue summary: View changes
Status: Active » Closed (fixed)

Fixed in 5.x.