• Resolved boka003

    (@boka003)


    Hello there,

    I have written to email support, but this is a better place to start a discussion.

    We use turot to create a quiz for our employees.

    Each employee can take the quiz more than once, but must pass the quiz at least once.

    How can we filter WordPress users who haven’t taken the quiz or haven’t passed it even once?


    Here is an approach that I have tried:
    (but it das not working).

    <?php
    /*
    Plugin Name: Employee Test Report
    Description: Generates a report of employees who haven't taken or passed the test using Tutor plugin.
    Version: 1.0
    Author: Boris K.
    */
    
    // Add a custom admin menu item
    function employee_test_report_menu() {
        add_menu_page(
            'Employee Test Report',
            'Employee Test Report',
            'manage_options',
            'employee-test-report',
            'display_employee_test_report'
        );
    }
    add_action('admin_menu', 'employee_test_report_menu');
    
    // Function to display the employee test report
    function display_employee_test_report() {
        global $wpdb;
    
        // Get all users
        $users = get_users();
    
        // Initialize an array to store users who haven't taken or passed any quizzes
        $users_not_taken_or_passed_quiz = array();
    
        // Loop through each user
        foreach ($users as $user) {
            // Check if the user has quiz results metadata
            $quiz_results = get_user_meta($user->ID, 'quiz_results', true);
    
            // If the user doesn't have quiz results metadata, add them to the array
            if (!$quiz_results) {
                $users_not_taken_or_passed_quiz[] = $user;
            }
        }
    
        // Display the results
        echo '<div class="wrap">';
        echo '<h1>Employees Who Haven\'t Taken or Passed the Test</h1>';
    
        if (!empty($users_not_taken_or_passed_quiz)) {
            echo '<table class="widefat">';
            echo '<thead><tr><th>User ID</th><th>Username</th><th>Email</th></tr></thead>';
            echo '<tbody>';
            foreach ($users_not_taken_or_passed_quiz as $user) {
                echo '<tr>';
                echo '<td>' . $user->ID . '</td>';
                echo '<td>' . $user->user_login . '</td>';
                echo '<td>' . $user->user_email . '</td>';
                echo '</tr>';
            }
            echo '</tbody>';
            echo '</table>';
        } else {
            echo '<p>No employees found who haven\'t taken or passed the test.</p>';
        }
    
        echo '</div>';
    }
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter boka003

    (@boka003)

    We use a plugin to create a test for our employees.
    All our employees need to take the quiz.
    They can take the quiz multiple times until they pass it.

    On the Results page, how we can filter users who did not take a quiz?
    We want to force all our users to take a test.
    Also, all our users get auto-logged in when they visit our website (using LDAP). So we know which user takes a test.

    After we know which users did not take a test, how we can filter users who haven’t passed the test even once?
    – We want to force all our users to pass the test.
    They can have multiple tries until they pass it.

    Regards

    Plugin Support Md Rashed Hossain

    (@wprashed)

    Dear @boka003

    It seems like you’re attempting to create a plugin for WordPress that generates a report of employees who haven’t taken or passed a quiz using the Tutor plugin. Your approach is on the right track, but there are a few issues that need to be addressed in your code:

    1. Quiz Results Meta Key: You’re checking for the existence of the ‘quiz_results’ user meta key to determine if a user has taken the quiz. However, Tutor might not necessarily use this key for storing quiz results.

    2. Logic for Checking Quiz Results: You need to modify the logic to accurately determine if a user has taken or passed the quiz. This might involve querying Tutor’s database tables or using its provided functions to retrieve quiz results.

    3. Displaying Quiz Results: Once you have correctly identified users who haven’t taken or passed the quiz, you can display this information in the admin menu page.

    Here’s a revised version of your plugin code with comments indicating where changes are needed:

    // Add a custom admin menu item
    function employee_test_report_menu() {
        add_menu_page(
            'Employee Test Report',
            'Employee Test Report',
            'manage_options',
            'employee-test-report',
            'display_employee_test_report'
        );
    }
    add_action('admin_menu', 'employee_test_report_menu');
    
    // Function to display the employee test report
    function display_employee_test_report() {
        global $wpdb;
    
        // Retrieve users who have taken or passed the quiz using Tutor's functions or database queries
        // Modify this part according to Tutor's API or database structure
        $users_with_quiz_results = array(); // Populate this array with users who have taken or passed the quiz
    
        // Get all WordPress users
        $users = get_users();
    
        // Initialize an array to store users who haven't taken or passed the quiz
        $users_not_taken_or_passed_quiz = array();
    
        // Loop through each user
        foreach ($users as $user) {
            // Check if the user is not in the $users_with_quiz_results array
            if (!in_array($user, $users_with_quiz_results)) {
                // If the user hasn't taken or passed the quiz, add them to the array
                $users_not_taken_or_passed_quiz[] = $user;
            }
        }
    
        // Display the results
        echo '<div class="wrap">';
        echo '<h1>Employees Who Haven\'t Taken or Passed the Test</h1>';
    
        if (!empty($users_not_taken_or_passed_quiz)) {
            echo '<table class="widefat">';
            echo '<thead><tr><th>User ID</th><th>Username</th><th>Email</th></tr></thead>';
            echo '<tbody>';
            foreach ($users_not_taken_or_passed_quiz as $user) {
                echo '<tr>';
                echo '<td>' . $user->ID . '</td>';
                echo '<td>' . $user->user_login . '</td>';
                echo '<td>' . $user->user_email . '</td>';
                echo '</tr>';
            }
            echo '</tbody>';
            echo '</table>';
        } else {
            echo '<p>No employees found who haven\'t taken or passed the test.</p>';
        }
    
        echo '</div>';
    }

    Remember to replace the placeholder logic with the actual logic to retrieve quiz results from Tutor plugin. Additionally, ensure that you’re using the correct functions or database queries provided by Tutor to fetch this information.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to filter users who did not pass test at Report?’ is closed to new replies.