not able to get the user response in render.php page of question type

not able to get the user response in render.php page of question type

Ranjan Jha -
回帖数:20

We have created custom question type in moodle 1.6 and now we r upgrading it for moodle 2.0 we r facing problem to get the user response.

In render.php page the following code doesn't set the value of response.

how can i set the value of response if there is anyother method by which i can set the value of response please suggest me.

 

$response = $qa->get_last_qt_var('answer', ' ');

回复Ranjan Jha

Re: not able to get the user response in render.php page of question type

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

Well, what var name does your question type use?

回复Tim Hunt

Re: not able to get the user response in render.php page of question type

Ranjan Jha -

class qtype_custom_renderer extends qtype_renderer {
function formulation_and_controls(question_attempt $qa,
question_display_options $options) {
global $CFG;

$question = $qa->get_question();
$response = $qa->get_last_qt_var('answer','');

$inputname = $qa->get_qt_field_name('answer');

 

this is some part of my code. i have marked a line as bold where i am facing problem. 

pls go throug this code and reply me...

回复Ranjan Jha

Re: not able to get the user response in render.php page of question type

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

That is probably no where the problem is.

The problem will be with the code that is supposed to store the student's response in that variable. (So, probably in get_expected_data() method in your question.php, and whether that matches the HTML form fields that you output when the question is displayed.)

回复Tim Hunt

Re: not able to get the user response in render.php page of question type

Ranjan Jha -

my problem is when i submit and finish the question the $response variable doesn't store it's value. 

In the case of TrueFalse question type th $response varibale hold something true(1) or false(0) when we submit the data. because Truefalse 

question type store response in boolean format.

 

But in my custom question type i want to store the $response variable something string like:

Fever

Not Fever

 

how is it possible and which method i should use to overcome this problem.

回复Ranjan Jha

Re: not able to get the user response in render.php page of question type

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

In your renderer, what do you output when the question is first stared? (That is, the first time the studnet gets to attempt.php before they have had a change to enter anything.)

回复Tim Hunt

Re: not able to get the user response in render.php page of question type

Ashok Kumar -

Hi Tim,

I am developing a new question type using true false question type. This question

has three part each having two option present and absent similar to true and false.

On the basis of student attempt present and absent, for each present there is

1 mark. The problem is same above I am not getting response in renderer.php.

The response will be text type I have also changed param_integer to param_text

in get_expected_data() function in question.php

If it become possible to get response whole problem can be solve.

Please reply

回复Ashok Kumar

Re: not able to get the user response in render.php page of question type

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

This is not very helpful, but the only advice I can give is that it works for all the other question types, so the problem is almost certainly in your code. Try comparing your code with similar code from other question types, and add some debugigng, to work out what is going on.

回复Tim Hunt

Re: not able to get the user response in render.php page of question type

Ashok Kumar -

The whole question type like this

Q1 Questiontext

      part1

          present

          absent

    part2

        present

        absent

   part3

       present

       absent

I want response as into one string like PPA as student attempt p for present A for absent

I debug whole code of true false I want to know its exact position where it genereates when user attempt.

回复Ashok Kumar

How to use protected variable

Ashok Kumar -

Hi Tim,

 I am creating new Question type I have a problem I want response summary in a

variable in renderer.php

 

some of part of object is

 [responsesummary:protected] => P,A,P
    [rightanswer:protected] => A,A,P
    [steps:protected] => Array
        (
            [0] => question_attempt_step_read_only Object
                (
                    [id:question_attempt_step:private] => 1269
                    [state:question_attempt_step:private] => question_state_todo Object
                        (
                        )


as shown above responsesummary is protected how can i store it in a variable

I want responsesummary in specific_feedback() function in renderer.php
回复Ashok Kumar

Re: How to use protected variable

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

I think don't do that.

In the renderer, you have access to the quetsion. Just call $question->summarise_response(...) again.

回复Tim Hunt

Re: how to make export/import for new question type

Ashok Kumar -

Hi Tim,

 I have developed new question type in moodle 2.2.1 for same above. The question type working fine. The problem when I try to export and import question.

shows error message when export questions

no handler no for question type qtype_name

How can I overcome this problem. Shall I make own question type parser in format.php

please reply

回复Ashok Kumar

Re: how to make export/import for new question type

Jean-Michel Védrine -

Hello,

If you want your questions to be included in moodle xml export then you have to write an export_to_xml method in the questiontype.php file.

See examples in some third party question types to learn how to write this method.

In a similar way, you will have to write an import_from_xml method so that your questions are imported from an xml question file.

You don't have to write anything in the question/format subdirectory.

回复Jean-Michel Védrine

Re: how to make export/import for new question type

Ashok Kumar -

Thanks Michel

I want export/import GIFT format how it can be done.

回复Ashok Kumar

Re: how to make export/import for new question type

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

Very similar, you need to create import_from_gift and export_to_gift functions in your question type. I don't think anyone has implemented that before, so I cannot suggest any examples to start from, but it should work.

回复Tim Hunt

Re: how to make export/import for new question type

Ashok Kumar -

thanks

I have developed in Moodle XML format. I will also try to developed in GIFT format.

回复Ashok Kumar

Re: how to make export/import for new question type

Jean-Michel Védrine -

Hello Ashok,

the developper documentation for questions import/export is here

回复Jean-Michel Védrine

Re:Import gift for questions

Ashok Kumar -

Hi jean,

I have done export to gift foramt for my new question type export is working fine

is there a similar function like import_from_gift() provide documentation if any...

 

回复Ashok Kumar

Re:Import gift for questions

Jean-Michel Védrine -

Yes it exists, but I don't know of any question type that implement it.

Look at the documentation page linked in  my previous message especially the paragraph :

For import GIFT is unusual in that the question type cannot be established until the question has been completely parsed. Unlike other formats where try_importing_using_qtypes() is called at the "end" where it has been established that no built in handler exists, GIFT makes this call before built in question handlers are considered. This makes it doubly important that the plugin code checks that the data is appropriate for the qtype and returns false if not.

The only other documentation is in the code itself in question/format/gift/format. php :

        // determine QUESTION TYPE
        $question->qtype = NULL;

        // give plugins first try
        // plugins must promise not to intercept standard qtypes
        // MDL-12346, this could be called from lesson mod which has its own base class =(
        if (method_exists($this, 'try_importing_using_qtypes') && ($try_question = $this->try_importing_using_qtypes($lines, $question, $answertext))) {
            return $try_question;
        }

So if you don't take care import of your question type will work but all others questions types import will fail because your question type will "eat" all questions !

回复Jean-Michel Védrine

Re:Import gift for questions

Ashok Kumar -

Hi Jean

 Can you provide me import_from_gift() function exact signature I am using this function but it doesn't return all exported data. Provide me its syntax, no of parameter taken

etc.