Monthly Archives: September 2018

WatuPRO Developer’s API: Custom Grade Calculation

From version 6.0.4 WatuPro has a filter that allows plugging in your own custom grade calculation that replaces the built-in calculation. This can be useful in very specific quizzes where the grade is calculated in a non-standard way and cannot be handled by the existing functions.

This filter is a bit more complicated to explain hence we have created a separate post for it. If you are looking for the general developer’s API guide it’s here.

Using the filter:

You need to add the filter in the following way:

add_filter('watupro_calculate_grade', 'your_callback_function', 10, 8);

As you can see the filter needs 8 arguments. Here is how your callback function should be structured, with explanation of all arguments:

function your_callback_function($return_arr, $taking_id, $exam_id, $points, $percent, $cat_id, $user_grade_ids, $points_percent) {
   // expand $return_arr in the 4 constructing variables if you need:
   list($grade_text, $certificate_id, $redirect_url, $grade_object) = $return_arr;

   // your custom calculation here which may modify each of the 4 $return_arr elements
   // ...

   // return array of 4 elements
   return array($grade_text, $certificate_id, $redirect_url, $grade_object);
}

 

Attributes / Arguments

Here are the attributes in detail:

$return_arr is an array of 4 variables: $grade_text is the human-readable grade or personality type returned from the test (title and description); $certificate_id is ID of the assigned certificate, if any, otherwise 0; $redirect_url is optional URL where the user should be redirected to at the end of quiz, or false if no redirect; $grade_object is the grade as DB object returned from the wp_watupro_grades table. You can construct it yourself with the minimum required properties: “title” and “description”.

$taking_id is the ID from the watupro_taken_exams table which corresponds to this quiz attempt. VERY IMPORTANT: at the time of grade calculation the $taking_id already exists however the full details are not yet populated in watupro_taken_exams table. That’s why we pass points, percent correct, etc. as additional variables. The purpose of passing $taking_id is that it allows you to access all the individual answers from wp_watupro_student_answers table in your custom grade calculator, should you need so. Example query:

$answers = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".WATUPRO_STUDENT_ANSWERS." WHERE taking_id=%d ORDER BY ID", $taking_id));

$exam_id is the ID of the test / quiz.

$points is the number of points collected. If $cat_id is 0, then $points are the total points collected on the attempt. If $cat_id is not 0, then $points is the number of points collected for that specific category ID.

$percent is the % correct answers collected. If $cat_id is 0, then $percent is the % correct answers on the whole attempt. If $cat_id is no 0, then $percent is the % correct answers for that specific category ID.

$cat_id is the ID of the category for which the grade is calculated. When 0 this means we are calculating the grade / result for the test attempt. When not 0 we are calculating grade for that specific category and you should return grade for that specific category, or none.

$user_grade_ids is used only on personality tests. It contains array with IDs of the personality types in a specific format.

$points_percent contains the percent of maximum points on this quiz attempt. If $cat_id is not 0, then it’s the percent of maximum points for that category ID.

Your custom function should always return an array of 4 elements as explained in $return_arr above – changed or unchanged. Be very careful not to mess the order of variables as you won’t be getting the expected result.

User Registration / Login and WatuPRO

This post has the goal to answer one of the often asked questions – can you have WatuPRO tie quiz attempts to user accounts? The short answer is yes, of course.

Here are more details:

How Does It Work

It’s very easy. In Edit Quiz -> User and Email Related Settings tab you need to select “Require user login”:

A lot of new options appear when you select this but they are not related to user registration itself.

So, once you select this the quiz will not be accessible to users without accounts. If you want to allow users to register themselves make sure the following option on your General WordPress Settings page (not a WatuPRO page!) is selected:

If you don’t want users to register themselves, you need this to be unchecked.

What’s important to understand is that WatuPRO uses the underlying WordPress user login and registration system rather than inventing its own. This has a lot of advantages, with the main one being that any plugins you use to customize user registration and profile pages will affect WatuPRO as well.

About Emails Sent on Registration

Emails that are sent at the time of user registration are controlled by WordPress, not by WatuPRO. If you want to change the email contents you can do it with various other plugins. For example, see this tutorial.

About Customized User Profiles

If you have customized the user profiles with other plugin or theme, or with your custom code, this should also work fine with WatuPRO. However before rushing to install a custom profile plugin just because you want to collect some contact information along with the quiz, check the option “Ask user for contact details” which we provide at Edit Quiz -> User and Email Related Settings tab:

 

About Integration With Membership and Other Plugins

Because WatuPRO uses the built-in WordPress user management system, integration with any other plugins which do so is seamless. Fortunately almost all membership plugins and other plugins dealing with user profile use it as well instead of investing their own. This is the beauty of WordPress.

Please have in mind integration does not mean WatuPro will automatically show custom profile fields somewhere in the quizzes or that other plugins will automatically show WatuPro stats on user profile pages. It means just that any changes that other plugins do to user profile affect the same users that take quizzes.

Copy, Reuse or Import Questions in WatuPRO: What’s The Difference?

WatuPRO has several options that make managing and creation of lots of questions easy. Each of them has different purpose, so let’s dive into it:

Copy Questions

You can copy questions (and also grades and quiz settings) from one quiz to a new quiz that will be created on the fly or to an existing quiz. This feature is accessible from two places:

  • The Edit Quiz page -> link “Copy into another quiz” on top
  • The Manage Questions page -> link “Copy quiz and/or questions” above the table.

Here is how it looks:

When you copy questions you are creating their duplicates into the new quiz. You can then go and modify them in the new place and your changes will be applied on the copied questions only. This is exactly the same as re-making these questions manually, it just saves a lot of time.

So, “copy questions” is most suitable when you want to create new quizzes fast and these new quizzes will have similar settings and questions as the one you copied from. It’s good because you can make changes to them without affecting the originals.

But what if you want to have many quizzes pulling questions from question banks? If ten quizzes pull from a bank of 100 questions, it’s not a good idea to copy these questions at ten places – just one typo and you’ll have to edit it ten times.

This is where reusing is far more useful:

Reuse Questions

The “Reuse Questions” feature is part of the Intelligence module.

To reuse questions go to the Manage Questions page of the test and select the checkbox:

This super powerful feature lets you use just any other quiz in the system as a question bank and even combine multiple question banks into a single quiz in any way you can imagine.

Reusing does not create copies of the questions. It uses them “on the fly”. This means that if you want to change a question you can go to the original quiz where it’s created, change it there and the changes will automatically affect all tests which reuse this question.

So if you want slightly modified questions in another quiz, copy them. If you want exactly the same questions but perhaps in different order, from only some categories or with different quiz settings, then reuse.

From version 6.3.8 you can use the enhanced reuse questions feature as a question bank.

Import Questions

Another way of quickly creating questions is importing them from CSV (Excel) or Aiken (simple Moodle format) file (see exact formats available).

Importing lets you quickly adds a lot of questions if you prefer to use Excel or text file for creating them. It’s not good way of editing existing questions of a quiz: if you want to do this, you will have to delete the old questions when you import the edited one. So it’s best to use import only for initial creation.

Import also works great if you want to copy questions between different sites or sub-sites in a network – as long as they all run WatuPRO. Just export the questions from one site and import them to the other site.

Once the questions are imported into a quiz they can be copied and reused just like all other questions.