MDL-79863 qtype_ordering: qtype/ordering try a few improvements for Moodle 2.0

This commit is contained in:
Gordon Bateson 2014-12-04 18:00:51 +09:00 committed by Mathew May
parent 4ff27d340b
commit 7eb3838acd
2 changed files with 20 additions and 15 deletions

View File

@ -1286,9 +1286,10 @@ class question_type extends default_questiontype {
}
shuffle($answerids);
$response_name = 'q'.$question->id;
$response_id = 'id_q'.$question->id;
$sortable_id = 'id_sortable'.$question->id;
// $question->name_prefix is 'resp'.$question->id.'_'
$response_name = 'resp'.$question->id.'_answers';
$response_id = 'id_resp'.$question->id.'_answers';
$sortable_id = 'id_sortable_'.$question->id;
$output = '';
@ -1323,13 +1324,19 @@ class question_type extends default_questiontype {
$output .= html_writer::start_tag('div', array('class' => 'answer'));
$output .= html_writer::start_tag('ul', array('class' => 'sortablelist', 'id' => $sortable_id));
if (isset($CFG->passwordsaltmain)) {
$salt = $CFG->passwordsaltmain;
} else {
$salt = ''; // complex_random_string()
}
$class = 'sortableitem';
// generate ordering items
foreach ($answerids as $i => $answerid) {
// the original "id" revealed the correct order of the answers
// because $answer->fraction holds the correct order number
// $id = 'ordering_item_'.$answerid.'_'.intval($answers[$answerid]->fraction);
$id = 'ordering_item_'.md5($CFG->passwordsaltmain.$answers[$answerid]->answer);
$class = 'sortableitem';
$id = 'ordering_item_'.md5($salt.$answers[$answerid]->answer);
$params = array('class' => $class, 'id' => $id);
$output .= html_writer::tag('li', $answers[$answerid]->answer, $params);
}

View File

@ -195,16 +195,10 @@ class qtype_ordering_question extends question_graded_automatically {
// we use $SESSION instead of accessing $_SESSION directly
// $_SESSION['SESSION']->quiz_answer['q'.$this->id] = $grade;
if (! isset($SESSION)) {
$SESSION = array();
if (empty($SESSION->quiz_answer)) {
$SESSION->quiz_answer = array();
}
if (! isset($SESSION['SESSION'])) {
$SESSION['SESSION'] = new stdClass();
}
if (! isset($SESSION['SESSION']->quiz_answer)) {
$SESSION['SESSION']->quiz_answer = array();
}
$SESSION['SESSION']->quiz_answer['q'.$this->id] = $grade;
$SESSION->quiz_answer['q'.$this->id] = $grade;
return true;
}
@ -237,7 +231,11 @@ class qtype_ordering_question extends question_graded_automatically {
public function grade_response(array $response) {
global $SESSION;
$fraction = $SESSION['SESSION']->quiz_answer['q'.$this->id];
if (empty($SESSION->quiz_answer['q'.$this->id])) {
$fraction = 0;
} else {
$fraction = $SESSION->quiz_answer['q'.$this->id];
}
return array($fraction, question_state::graded_state_for_fraction($fraction));
}