• Resolved Cristhian Bacusoy

    (@cristhianbh98)


    Hi I want to know if is there a method to know if the user already did a specific test. Is there a function that return all the users that did a test? Or is there another function thar returns a boolean whether the user did a test or did not a test?

    Thanks for the help.
    Regards

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor ustimenko

    (@ustimenko)

    hi @cristhianbh98
    there is no such function yet.

    Thread Starter Cristhian Bacusoy

    (@cristhianbh98)

    Hi Alexander, thank you for you answer and your time.

    I can see that in the add-on Wp-testing — Export there is a section where you can query users that did a specific test, I know beacuse I purchased that add-on, so I want to know if in that section you did a query to thee database or use a function to display the users.

    Great plugin btw.
    Regards.

    Thread Starter Cristhian Bacusoy

    (@cristhianbh98)

    Hi, I could solve my problem, if anyone want to know how do this, just copy the next code.

    
    function wpt_user_has_submit($test_id = 0, $user_id = 0) {
    	global $wpdb;
    	$has_submit = false;
    	
    	$row = $wpdb->get_results( "SELECT * FROM wp_t_passings WHERE test_id = $test_id AND  respondent_id = $user_id LIMIT 1");
    		
    	if(count($row) > 0) {
    		$has_submit = true;
    	}
    	
    	return $has_submit;
    }
    

    You can call the function providing the user id and the test id you want to query, this return a boolean whether the user has submitted a test or not.

    Plugin Contributor ustimenko

    (@ustimenko)

    A little bit more optimal version:

    
    function wpt_user_has_submit($test_id = 0, $user_id = 0) {
    	global $wpdb;
    	return $wpdb->get_var("SELECT count(*) FROM wp_t_passings WHERE test_id = $test_id AND  respondent_id = $user_id") > 0;
    }
    

    Also pls note, that table name can be different as of prefix and can be not wp_t_passings.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How can i know is a user already did a test?’ is closed to new replies.