Cant get_last_step is always default step

Cant get_last_step is always default step

by Henri Burau -
Number of replies: 5

Im trying to get values out of my last question_attempt_step. But even when i do $step->get_all_data() it will only return one (i think default) key-value pair instead of my values.


    public function formulation_and_controls ( question_attempt $qa, question_display_options $options ) {

        $step = $qa->get_last_step();

        $result = $step->get_all_data();

        foreach($result as $key => $value)

        {

            echo $key.'=>'.$value;

        }

...

        $inputname = $qa->get_qt_field_name ( $name );

        return $this->textarea ( $step->get_qt_var ( $name ), $code, $lines, array (

                'name' => $inputname 

        ) ) 

...

    protected function textarea ( $response, $code, $lines, $attributes ) {

        $attributes['class'] = $this->class_name () . ' qtype_javaunittest_response';

        $attributes['rows'] = $lines;

        $attributes['cols'] = 60;

        if ( empty ( $response ) ) {

            return html_writer::tag ( 'textarea', s ( $code ), $attributes );

        }

        return html_writer::tag ( 'textarea', s ( $response ), $attributes );

    }

Average of ratings: -
In reply to Henri Burau

Re: Cant get_last_step is always default step

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

It's not supposed to work like that.

Have a look at some of the standard Moodle question types.

(Sorry, not the most helpful response, but I have had a long day.)

In reply to Tim Hunt

Re: Cant get_last_step is always default step

by Henri Burau -

Then how does it work? I looked it up in different plugins and the way to get the responses of a student seems to be qa->get_last_qt_var($fieldname). But it doesn't work for me. I never get any data. Even when i just copy-pasted the short answer code into my plugin i won't work. Is there a method I need to implement in my question.php or questiontype.php in order to get the get_last_qt_var() working? 

In reply to Henri Burau

Re: Cant get_last_step is always default step

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

It is a good idea to use this query https://docs.moodle.org/dev/Overview_of_the_Moodle_question_engine#Detailed_data_about_an_attempt to see what is happening as your question is attempted.

The most likely method you might have missed is get_expected_data in the question class.

In reply to Tim Hunt

Re: Cant get_last_step is always default step

by Henri Burau -

Thank you for your reply. I did implement get_expected_data and also summarise_response/get_correct_response/is_complete_response. 

But I'm not completely sure how to implement get_expected_data right. Right now I only return an array of fields I want to use to grade the response. But in my renderer.php there is also another field that is just for display purpose. Should I add that too?

I'm extending the question_graded_automatically question type. When i look at the http-request I can also see that my form-data is transmitted. Also when I print out the $response parameter from the methods mentioned above it looks like it is completely empty. 

When I look at the database there is only a entry in the mdl_question_attempt_step_data when I submit the correct response.

In reply to Henri Burau

Re: Cant get_last_step is always default step

by Henri Burau -

I found my mistake. You were completely right. I forgot the return statement in get_expected_data. Never wasted more time in my life as I did searching for this mistake.