Skip to content

Commit

Permalink
get_actual_response() method for cloze question type contributed by J…
Browse files Browse the repository at this point in the history
…ean-Michel, see http://moodle.org/mod/forum/discuss.php?d=27730#181773

Also merged some comments from HEAD
  • Loading branch information
gustav_delius committed Feb 11, 2006
1 parent 27cc4df commit c8a6cdb
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion mod/quiz/questiontypes/multianswer/questiontype.php
Expand Up @@ -38,15 +38,27 @@ function get_question_options(&$question) {
if (!$QUIZ_QTYPES[$wrapped->qtype]->get_question_options($wrapped)) {
notify("Unable to get options for questiontype {$wrapped->qtype} (id={$wrapped->id})");
}
// for wrapped questions the maxgrade is always equal to the defaultgrade,
// there is no entry in the quiz_question_instances table for them
$wrapped->maxgrade = $wrapped->defaultgrade;
$question->options->questions[$sequence[$wrapped->id]] = clone($wrapped);

$question->options->questions[$sequence[$wrapped->id]] = clone($wrapped); // ??? Why do we need a clone here?
}

return true;
}

function save_question_options($question) {
global $QUIZ_QTYPES;

// This function needs to be able to handle the case where the existing set of wrapped
// questions does not match the new set of wrapped questions so that some need to be
// created, some modified and some deleted
// Unfortunately the code currently simply overwrites existing ones in sequence. This
// will make re-marking after a re-ordering of wrapped questions impossible and
// will also create difficulties if questiontype specific tables reference the id.

// First we get all the existing wrapped questions
if (!$oldwrappedids = get_records('quiz_questions', 'parent', $question->id, '', 'id, id')) {
// We need to select 'id, id' because the first one is consumed by
// get_records.
Expand All @@ -55,6 +67,7 @@ function save_question_options($question) {
$oldwrappedids = array_keys($oldwrappedids);
$sequence = array();
foreach($question->options->questions as $wrapped) {
// if we still have some old wrapped question ids, reuse the next of them
if ($oldwrappedid = array_shift($oldwrappedids)) {
$wrapped->id = $oldwrappedid;
}
Expand Down Expand Up @@ -328,6 +341,21 @@ function grade_responses(&$question, &$state, $quiz) {

return true;
}

function get_actual_response($question, $state) {
global $QUIZ_QTYPES;
$teststate = clone($state);
foreach($question->options->questions as $key => $wrapped) {
$state->responses[$key] = html_entity_decode($state->responses[$key]);
$teststate->responses = array('' => $state->responses[$key]);
$correct = $QUIZ_QTYPES[$wrapped->qtype]
->get_actual_response($wrapped, $teststate);
// change separator here if you want
$responsesseparator = ',';
$responses[$key] = implode($responsesseparator, $correct);
}
return $responses;
}
}
//// END OF CLASS ////

Expand Down

0 comments on commit c8a6cdb

Please sign in to comment.