add set_fraction() and set_state() on new attempt

add set_fraction() and set_state() on new attempt

by Alan Padiernos -
Number of replies: 2

Hi all,

My problem is setting a default mark/fraction on new question attempt  based on the last graded question attempt.

I would like to know if it is possible to set new fraction and set new state on already created attempt object?

$attemptobj = quiz_attempt::create($attemptid);

I tried this one but no luck:

$attemptobj->get_question_attempt($slot)->get_last_step()->set_fraction($fraction);

I've been trying to solve this for a week, but still I can't do it. Hope someone can help me.

Thanks.

Average of ratings: -
In reply to Alan Padiernos

Re: add set_fraction() and set_state() on new attempt

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You cant do that.

A question is a real thing, with real properties. If a question has not been answered yet, its mark is null.

So, calling $qa->set_fraction(0.5) makes about as much sense as calling $alan_padiernos->set_weight('50 kg'). I mean, what are we supposed to do, chop your arms off? (Joke)

Now, it may be that you want to display a message next to the question, like "In your last attempt you scored 0.50." However, that is a different thing. In Moodle 2.9 or later, you might be able to use question_display_options::$extrainfocontent https://github.com/moodle/moodle/blob/v2.9.0/question/engine/lib.php#L594

(P.S. For the benefit of any physics pedants out there, I know it should be set_mass, not set_weight.)

In reply to Tim Hunt

Re: add set_fraction() and set_state() on new attempt

by Alan Padiernos -

Thanks Tim.

I will ask my boss if they want to edit the qbehaviour_manualgraded object to set marks before and/or after the attempt.