WordPress.org

Ready to get started?Download WordPress

Forums

SS Quiz
How to set 3 attempts to make the quiz? (5 posts)

  1. dgstr
    Member
    Posted 10 months ago #

    Hello,

    I need to let the user have 3 chances to make the quiz, and after these 3 chances, it becomes unavailable.

    There's anyway I can do it?
    I can only make no chances number or one chance, but I need 3 chances.

    Thank you.

    http://wordpress.org/plugins/ssquiz/

  2. kvanbiesen
    Member
    Posted 10 months ago #

    Dirty hack - will break on update most likely

    open client-quiz.php

    replace (line 83-90)

    // Did current user tried this quiz
    if( $info->one_chance ) {
    		$attempts = $wpdb->get_var( "
    			SELECT count(*) FROM {$wpdb->base_prefix}ssquiz_history WHERE user_id = {$info->user->id} AND quiz_id = {$info->quiz->id}
    		");
    		if( $attempts > 0 )
    			return ssquiz_return_quiz_body( '<h2>'.__('You already took this quiz', 'ssquiz').'</h2>' );
    	}

    with

    //remove one_change and replaced with chances
    	if( isset( $params["chances"])) {
    		$attempts = $wpdb->get_var( "
    			SELECT count(*) FROM {$wpdb->base_prefix}ssquiz_history WHERE user_id = {$info->user->id} AND quiz_id = {$info->quiz->id}
    		");
    		if( $attempts >= intval( $params["chances"]) )
    			return ssquiz_return_quiz_body( '<h2>'.__('You already took this quiz', 'ssquiz').'</h2>' );
    	}

    then in your yourcode, add chances=3 to make 3 attempts. (1 for once_change)

  3. dgstr
    Member
    Posted 10 months ago #

    I've replaced the code, and in my quiz page, I've put this:
    [ssquiz id=3 qrandom timer=300 not_correct arandom chances=3]

    But it didn't work. It says that I already took the quiz, even with the statistics cleared.

    What am I doing wrong?

    Thank you!

  4. kvanbiesen
    Member
    Posted 10 months ago #

    you sure you published the page?

    dont use the back button to retake the quiz

    it work fine here, multiple browsers

    what happens if you add? it will show a dirty attemps and maxtries (it will only look a the attemps when loading the page, so use back for browser = no worky.

    if( isset( $params["chances"])) {
    		$attempts = $wpdb->get_var( "
    			SELECT count(*) FROM {$wpdb->base_prefix}ssquiz_history WHERE user_id = {$info->user->id} AND quiz_id = {$info->quiz->id}
    		");
    		echo "Attempts Saved: ".$attempts." Max_chances". intval( $params["chances"]);
    		if( $attempts >= intval( $params["chances"]) )
    			return ssquiz_return_quiz_body( '<h2>'.__('You already took this quiz', 'ssquiz').'</h2>' );
    	}

    ps, tried both logged in and logout users

  5. dgstr
    Member
    Posted 10 months ago #

    I have used Ctrl+F5 to clear cache and refresh the page.

    Now with this new code it runs perfectly!

    Thank you very much!

Reply

You must log in to post.

About this Plugin

About this Topic