How to pull test questions and answers from database or the interface?

How to pull test questions and answers from database or the interface?

by wendy lee -
Number of replies: 9

Hi all,

I have 160 students who took the test.  Now,  I would like is to retrieve all 160 students results along with the test questions and their answers on a soft copy so that they can print it out to see their answers to the questions.  I don't know what is the most efficient way to do this?  Through the interface or through the database? If it's done through the database (back-end), what is the query that I have to write to pull that data together? 

Thanks,

Wendy

Average of ratings: -
In reply to wendy lee

Re: How to pull test questions and answers from database or the interface?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The easiest way to do this is to download and install the detailed resonses plugin from the Modules and Plugins database.
In reply to Tim Hunt

Re: How to pull test questions and answers from database or the interface?

by wendy lee -

Thanks, Tim, for the response. 

But I'm more interested to pull the data from the backend, how do I go about and do this?

Thanks,

Wendy

In reply to wendy lee

Re: How to pull test questions and answers from database or the interface?

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 really hard. Look at the code of the detailed responses report wink
In reply to Tim Hunt

Re: How to pull test questions and answers from database or the interface?

by wendy lee -

Can we do it through sql?  Pull every students' responses along with the questions and their grades.

Thanks,

WEndy

In reply to wendy lee

Re: How to pull test questions and answers from database or the interface?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The reason it is difficult is that different question types use different extra tables to store parts of their definition, and the students results are stored in the mdl_question_states table in the answer field in a way that is question-type dependant.

So if you only use a few question types in your quiz, and stare hard at http://docs.moodle.org/en/Development:Quiz_database_structure, you can probably come up with a query that is good enough. If you want a general solution that works perfectly, you will have to use PHP code and include the individual question type classes.
In reply to Tim Hunt

Re: How to pull test questions and answers from database or the interface?

by wendy lee -

Thanks for the info, Tim.  When I come up with the query, I will let everyone know because I know there are people who would want to use this query also.

Wendy

Average of ratings: Useful (1)
In reply to wendy lee

Re: How to pull test questions and answers from database or the interface?

by wendy lee -

Hi Tim,

You said that the answer field in the question_states table contains students' responses.  However, I found out that with multichoice questions, there are multi-answers in the answer field; for example 2193,2194,2195,2196: (each number is associated with an answer text, (which I found in the question_answers table) but how do I know which answer did the student selected?   

Thanks for your help again,

Wendy

Average of ratings: Useful (1)
In reply to wendy lee

Re: How to pull test questions and answers from database or the interface?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
For a particular question, in a particular question_attempt (and so belonging to a particular user) you will see there are several rows in question_states with different seq_numbers, and also critically different values in the event column.

The numbers in the event column are given names at the top of lib/questionlib.php. For example 0 = QUESTION_EVENTOPEN, 2 = QUESTION_EVENTSAVE, and so on. What you are looking at is the first state of the question which just tells you which order the answers were shown to the student (in case shuffle answers was one). You need to look for a later state, which will have a number after the colon, which will be the student's choice. Actually, you one the one corresponding to EVENT_CLOSE or EVENT_CLOSEANDGRADE which will be the final answer that the student submitted.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: How to pull test questions and answers from database or the interface?

by wendy lee -

Okay.  I have created a php report. It's not sophisticated, but it works!

The attached php shows the student's name, student's score, the question texts, possible answers, the answer(s) they chose and the correct answer.

Have fun,

Wendy

Average of ratings: Useful (1)