Problem/Motivation

The expected behavior is that this should return question count, possible score, numeric score, percentage score based on a result ID. Calling quiz_calculate_score($result_id) is not returning data as expected. Only is_evaluated = 1 which is set in code and not retrieved from the entity like the other data.

Proposed resolution

Change the 2nd argument to FALSE instead of NULL.

Comments

adamelleston created an issue. See original summary.

adamelleston’s picture

adamelleston’s picture

Status: Active » Needs review
adamelleston’s picture

Status: Needs review » Needs work
adamelleston’s picture

Status: Needs work » Needs review
djdevin’s picture

Version: 7.x-5.0-beta3 » 7.x-5.x-dev

Hi,

Thanks for the patch. Where did you see this affecting Quiz? I'm surprised none of the tests were failing before, so we should probably write a test.

adamelleston’s picture

I am currently working on a lot of custom reporting for quiz's on a project and tried calling quiz_calculate_score() from my own module.

I noticed that when logged in as admin and viewing each of the results for a quiz node it seemed to work out but when calling it myself it was returning nothing.

adamelleston’s picture

I haven't written tests before but happy to give it a go if I can find some time to do it.

How would you write a test to replicate calling the function directly from another module?

djdevin’s picture

Yeah the strange thing is, Quiz calls it too, so I wonder why it's not broken there. The patch is definitely correct I'm just confused why none of the Quiz tests about scoring are broken.

If you don't have time I could write the test too, but I need to know how to make it fail. To replicate calling the function you have to programmatically set up the Quiz in the test the same way you are setting it up on your site. There are some examples in quiz/tests if you want to dig in or try and make steps to reproduce.

adamelleston’s picture

Yeah I looked right past that as a cause for my issue at first and the quiz module calls it just fine.

Looking at the tests I am not sure how you would go about calling the quiz_calculate_score() function directly to bring back data on a specific result from an external module. I am calling it from the following hook hook_views_pre_render() if that helps.

djdevin’s picture

Status: Needs review » Fixed

This is the right approach anyway, so committing. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.