mirror of
https://github.com/moodle/moodle.git
synced 2025-03-19 15:10:05 +01:00
MDL-79863 qtype_ordering: qtype_ordering force standard settings for Ordering questions used by Reader quizzes
This commit is contained in:
parent
fc9263f9fe
commit
eb1db13b70
@ -185,6 +185,28 @@ function xmldb_qtype_ordering_upgrade($oldversion) {
|
||||
upgrade_plugin_savepoint(true, $newversion, 'qtype', 'ordering');
|
||||
}
|
||||
|
||||
$newversion = 2016032947;
|
||||
if ($oldversion < $newversion) {
|
||||
if ($dbman->table_exists('reader_question_instances')) {
|
||||
$select = 'rqi.question, COUNT(*) AS countquestion';
|
||||
$from = '{reader_question_instances} rqi '.
|
||||
'LEFT JOIN {question} q ON rqi.question = q.id';
|
||||
$where = 'q.qtype = ?';
|
||||
$group = 'rqi.question';
|
||||
$params = array('ordering');
|
||||
if ($questions = $DB->get_records_sql("SELECT $select FROM $from WHERE $where GROUP BY $group", $params)) {
|
||||
$questions = array_keys($questions);
|
||||
list($select, $params) = $DB->get_in_or_equal($questions);
|
||||
$select = "questionid $select";
|
||||
$table = 'qtype_ordering_options';
|
||||
$DB->set_field_select($table, 'layouttype', 0, $select, $params); // VERTICAL
|
||||
$DB->set_field_select($table, 'selecttype', 1, $select, $params); // RANDOM
|
||||
$DB->set_field_select($table, 'selectcount', 6, $select, $params); // 6
|
||||
$DB->set_field_select($table, 'gradingtype', 1, $select, $params); // RELATIVE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
$options = qtype_ordering_question::get_layout_types();
|
||||
$mform->addElement('select', $name, $label, $options);
|
||||
$mform->addHelpButton($name, $name, $plugin);
|
||||
$mform->setDefault($name, qtype_ordering_question::LAYOUT_VERTICAL);
|
||||
$mform->setDefault($name, $this->get_default_value($name, 0)); // 0 = VERTICAL
|
||||
|
||||
// selecttype
|
||||
$name = 'selecttype';
|
||||
@ -79,7 +79,7 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
$options = qtype_ordering_question::get_select_types();
|
||||
$mform->addElement('select', $name, $label, $options);
|
||||
$mform->addHelpButton($name, $name, $plugin);
|
||||
$mform->setDefault($name, qtype_ordering_question::SELECT_RANDOM);
|
||||
$mform->setDefault($name, $this->get_default_value($name, 0)); // 0 = ALL
|
||||
|
||||
// selectcount
|
||||
$name = 'selectcount';
|
||||
@ -99,7 +99,7 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
$options = qtype_ordering_question::get_grading_types();
|
||||
$mform->addElement('select', $name, $label, $options);
|
||||
$mform->addHelpButton($name, $name, $plugin);
|
||||
$mform->setDefault($name, qtype_ordering_question::GRADING_ABSOLUTE_POSITION);
|
||||
$mform->setDefault($name, $this->get_default_value($name, 0)); // 0 = ABSOLUTE
|
||||
|
||||
// answers (=items)
|
||||
// get_per_answer_fields()
|
||||
@ -292,32 +292,19 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
$question->fraction[$i] = ($i + 1);
|
||||
}
|
||||
|
||||
// layouttype
|
||||
if (isset($question->options->layouttype)) {
|
||||
$question->layouttype = $question->options->layouttype;
|
||||
} else {
|
||||
$question->layouttype = qtype_ordering_question::LAYOUT_VERTICAL;
|
||||
}
|
||||
|
||||
// selecttype
|
||||
if (isset($question->options->selecttype)) {
|
||||
$question->selecttype = $question->options->selecttype;
|
||||
} else {
|
||||
$question->selecttype = qtype_ordering_question::SELECT_RANDOM;
|
||||
}
|
||||
|
||||
// selectcount
|
||||
if (isset($question->options->selectcount)) {
|
||||
$question->selectcount = $question->options->selectcount;
|
||||
} else {
|
||||
$question->selectcount = max(3, count($question->answer));
|
||||
}
|
||||
|
||||
// gradingtype
|
||||
if (isset($question->options->gradingtype)) {
|
||||
$question->gradingtype = $question->options->gradingtype;
|
||||
} else {
|
||||
$question->gradingtype = qtype_ordering_question::GRADING_ABSOLUTE_POSITION;
|
||||
$names = array(
|
||||
// $name => $default value
|
||||
'layouttype' => 0, // VERTICAL
|
||||
'selecttype' => 0, // ALL
|
||||
'selectcount' => 0, // ALL
|
||||
'gradingtype' => 0, // ABSOLUTE
|
||||
);
|
||||
foreach ($names as $name => $default) {
|
||||
if (isset($question->options->$name)) {
|
||||
$question->$name = $question->options->$name;
|
||||
} else {
|
||||
$question->$name = $this->get_default_value($name, $default);
|
||||
}
|
||||
}
|
||||
|
||||
return $question;
|
||||
@ -343,6 +330,16 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
case 1: $errors['answer[1]'] = get_string('notenoughanswers', $plugin, 2);
|
||||
}
|
||||
|
||||
// if adding a new ordering question, update defaults
|
||||
if (empty($errors) && empty($data['id'])) {
|
||||
$fields = array('layouttype', 'selecttype', 'selectcount', 'gradingtype');
|
||||
foreach ($fields as $field) {
|
||||
if (array_key_exists($field, $data)) {
|
||||
$this->set_default_value($field, $data[$field]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
@ -409,6 +406,28 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
return $question;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_default_value
|
||||
*
|
||||
* @param $name
|
||||
* @param $default (optional, default = null)
|
||||
* @return default value for field with this $name
|
||||
*/
|
||||
protected function get_default_value($name, $default=null) {
|
||||
return get_user_preferences("qtype_ordering_$name", $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* get_default_value
|
||||
*
|
||||
* @param $name
|
||||
* @param $default (optional, default = null)
|
||||
* @return default value for field with this $name
|
||||
*/
|
||||
protected function set_default_value($name, $value) {
|
||||
return set_user_preferences(array("qtype_ordering_$name" => $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* this javascript could be useful for inserting buttons
|
||||
* into the form once it has loaded in the browser
|
||||
|
@ -31,5 +31,5 @@ $plugin->cron = 0;
|
||||
$plugin->component = 'qtype_ordering';
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
$plugin->requires = 2010112400; // Moodle 2.0
|
||||
$plugin->version = 2016032846;
|
||||
$plugin->release = '2016-03-28 (46)';
|
||||
$plugin->version = 2016032947;
|
||||
$plugin->release = '2016-03-29 (47)';
|
||||
|
Loading…
x
Reference in New Issue
Block a user