Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Recoding choice and stemorder when restoring the response
  • Loading branch information
leabaertschi committed Aug 23, 2012
1 parent 022ee35 commit fa9ed73
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions backup/moodle2/restore_qtype_order_plugin.class.php
Expand Up @@ -71,13 +71,13 @@ public function process_orderoptions($data) {
// Keep question_order->subquestions unmodified
// after_execute_question() will perform the remapping once all subquestions
// have been created

//Added by justin hunt 20120131, previously errors occured here cos no default value for these fields in DB
//yet since these members are new in 2.x, the 1.9 backups didn't contain them
if(!isset($data->correctfeedback)){ $data->correctfeedback =" ";}
if(!isset($data->partiallycorrectfeedback)){ $data->partiallycorrectfeedback =" ";}
if(!isset($data->incorrectfeedback)){ $data->incorrectfeedback =" ";}

// Insert record
$newitemid = $DB->insert_record('question_order', $data);
// Create mapping
Expand Down Expand Up @@ -198,4 +198,29 @@ static public function define_decode_contents() {

return $contents;
}

public function recode_response($questionid, $sequencenumber, array $response) {
if (array_key_exists('_choiceorder', $response)) {
$response['_choiceorder'] = $this->recode_order($response['_choiceorder']);
}
if (array_key_exists('_stemorder', $response)) {
$response['_stemorder'] = $this->recode_order($response['_stemorder']);
}
return $response;
}

/**
* Recode the choice and/or stem order as stored in the response.
* @param string $order the original order.
* @return string the recoded order.
*/
protected function recode_order($order) {
$neworder = array();
foreach (explode(',', $order) as $id) {
if (($newid = $this->get_mappingid('question_order_sub', $id))) {
$neworder[] = $newid;
}
}
return implode(',', $neworder);
}
}

0 comments on commit fa9ed73

Please sign in to comment.