Support » Plugin: Wp-Pro-Quiz » Can we bind a quiz to users (quiz creator)?

  • Resolved Mitesh Patel


    Can we bind a quiz to the users who created that quiz?

    Any person who can create a quiz should be able to edit only his own quiz, not other peoples’ quiz. This is because I want to allow more than a few people (teachers) to create quizes.

    I think quiz created in wp-pro-quiz are custom post types. If so, a quiz can be bound to the logged in user while it is being created. If this feature is not worthy to be added to the plugin, let me know where to edit, and I will make relevant changes by tinkering with the code files, and post them here, if successful 🙂

    I think there will be two changes (minimum).
    1. Add userID to the custom post meta (if there is any) or in a new table where quizID and userID would be entered as key_value pair (if this is the case, join query will kill all the fun).
    2. Check logged in user and show only his quizes while rendering the quizes in backend.

    Also, a similar solution is needed for who can take the quiz. For example, only CPM user group 2013 (students) can take Chemistry_quiz_2013. For this to work, the quiz should have some sort of taxonomy support. Like, a quiz can be given a single or multiple category(ies) (there is category support for questions in wp-pro-quiz, but not for the quiz itself). This category can be bound to user groups. This has a workaround however, as the short code can be put in a post of certain category, which can be bound to some user group.

    This is it, for now 🙂

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I got it working (bind a quiz to the users who created that quiz) with some tinkering, and reporting it here, so that others in need of such a solution can do so.

    The goal was,

    1. Only the user, who created the quiz can modify/delete the quiz.
    2. Admin can modify/delete any quiz.

    It must be noted that I contacted the plugin author Julius, and he graciously responded with suggestions. Thanks Julius.

    However, 1. I’m not really a programer 2. I had already made the following changes (make-shift, really) to get the job done, and was testing it.

    I am not sure the following is the best way to do it, but that seems to work. In short, the following that I am reporting is not based on his suggestions, so this may be buggy.

    I achieved it via the following changes, and I would like to submit them as patch.

    1. in the file WpProQuiz_Helper_DbUpgrade.php, I added a single line to the function “install ()” for inserting a column for user ID into table wp_pro_quiz_master as user varchar(200) NOT NULL (you will find similar lines in this function. Add this one before all, as first of such lines. Each of this lines create a column in the database table)

    2. in the file WpProQuiz_Model_QuizMapper.php I made three changes.

    a. added an item in the $set array (in the beginning) the function save () thus ‘user’ => wp_get_current_user()->ID, (again, you will find similar lines in this function. Add this one before all, as first of such lines)

    b. added added “%s” to the update and insert queries in the same save function
    (at the bottom of the function. here as well, you will find a line with many %s, %s, %d, %d, %d, … in this function. Add one before all)

    c. replaced a line of code with following code block to the “fetchAll ()” function to filter the quiz results.
    The line replaced is
    $results = $this->_wpdb->get_results(“SELECT * FROM {$this->_table}” , ARRAY_A);

    add this at second line of the function instead. See that the replaced line is still there in the if statement.

    $uid = wp_get_current_user()->ID;
    if ($uid == 1) {
    $results = $this->_wpdb->get_results(“SELECT * FROM {$this->_table}” , ARRAY_A);
    } else {
    $results = $this->_wpdb->get_results(“SELECT * FROM {$this->_table} WHERE user = $uid” , ARRAY_A);

    Also, A minore bug I came across related to “question category” and statistics for imported questions.

    I created a quiz.
    I added questions, two of them were assigned a category.
    I exported the quiz (for backup).
    I imported the quiz on a fresh install.
    Now the fresh install didn’t have any categories. The statistics did not appear.
    I edited the questions, and assigned them “–no category–“. The results appear.

    I don’t need it fixed. I just thought you should know.

    Finally, marking the topic resolved.

    How can I use this tool to allow non-admin users to create quizzes?

    You can use another plugin like role-scoper or such, that can modify capabilities/roles of individual users or roles. It’s really simple. I use a plugin called “members” that does the same thing.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Can we bind a quiz to users (quiz creator)?’ is closed to new replies.