Permalink
Browse files

MDL-36570 question editing: group answer/choice fields better.

  • Loading branch information...
Colin Chambers authored and timhunt committed Mar 19, 2013
1 parent d8201d4 commit c7218aef8d4b366beb751574eef86a47ac859991
View
@@ -25,6 +25,7 @@
$string['addmorechoiceblanks'] = 'Blanks for {no} more choices';
$string['addcategory'] = 'Add category';
$string['adminreport'] = 'Report on possible problems in your question database.';
+$string['answers'] = 'Answers';
$string['availableq'] = 'Available?';
$string['badbase'] = 'Bad base before **: {$a}**';
$string['behaviour'] = 'Behaviour';
@@ -54,9 +54,9 @@ public function __construct($submiturl, $question, $category, $contexts,
$this->question = $question;
$this->reload = optional_param('reload', false, PARAM_BOOL);
- if (!$this->reload) { // use database data as this is first pass
+ if (!$this->reload) { // Use database data as this is first pass.
if (isset($this->question->id)) {
- // remove prefix #{..}# if exists
+ // Remove prefix #{..}# if exists.
$this->initialname = $question->name;
$regs= array();
if (preg_match('~#\{([^[:space:]]*)#~', $question->name , $regs)) {
@@ -72,27 +72,49 @@ public function get_per_answer_fields($mform, $label, $gradeoptions,
$repeated = parent::get_per_answer_fields($mform, $label, $gradeoptions,
$repeatedoptions, $answersoption);
- // 1 is the answer. 3 is tolerance.
- $repeated[1]->setLabel(get_string('correctanswerformula', 'qtype_calculated') . '=');
- $repeated[3]->setLabel(get_string('tolerance', 'qtype_calculated') . '=');
+ // Reorganise answer options group. 0 is the answer. 1 is tolerance. 2 is Grade.
+ $answeroptions = $repeated[0]->getElements();
+ // Tolerance field will be part of its own group.
+ $tolerance = $answeroptions[1];
+
+ // Update Answer options group to contain only answer and grade fields.
+ $answeroptions = array($answeroptions[0], $answeroptions[2]);
+ $repeated[0]->setElements($answeroptions);
+
+ // Update answer field and group label.
+ $repeated[0]->setLabel(get_string('answerformula', 'qtype_calculated', '{no}') . ' =');
+ $answeroptions[0]->setLabel(get_string('answerformula', 'qtype_calculated', '{no}') . ' =');
+
+ // Get feedback field to re append later.
+ $feedback = array_pop($repeated);
+
+ // Create tolerance group.
+ $answertolerance = array();
+ $tolerance->setLabel(get_string('tolerance', 'qtype_calculated') . '=');
+ $answertolerance[] = $tolerance;
+ $answertolerance[] = $mform->createElement('select', 'tolerancetype',
+ get_string('tolerancetype', 'qtype_calculated'), $this->qtypeobj->tolerance_types());
+ $repeated[] = $mform->createElement('group', 'answertolerance',
+ get_string('tolerance', 'qtype_calculated'), $answertolerance, null, false);
$repeatedoptions['tolerance']['default'] = 0.01;
- $addrepeated = array();
- $addrepeated[] = $mform->createElement('select', 'tolerancetype',
- get_string('tolerancetype', 'qtype_numerical'), $this->qtypeobj->tolerance_types());
-
- $addrepeated[] = $mform->createElement('select', 'correctanswerlength',
- get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
+ // Create display group.
+ $answerdisplay = array();
+ $answerdisplay[] = $mform->createElement('select', 'correctanswerlength',
+ get_string('answerdisplay', 'qtype_calculated'), range(0, 9));
$repeatedoptions['correctanswerlength']['default'] = 2;
$answerlengthformats = array(
'1' => get_string('decimalformat', 'qtype_numerical'),
'2' => get_string('significantfiguresformat', 'qtype_calculated')
);
- $addrepeated[] = $mform->createElement('select', 'correctanswerformat',
+ $answerdisplay[] = $mform->createElement('select', 'correctanswerformat',
get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
+ $repeated[] = $mform->createElement('group', 'answerdisplay',
+ get_string('answerdisplay', 'qtype_calculated'), $answerdisplay, null, false);
- array_splice($repeated, 4, 0, $addrepeated);
+ // Add feedback.
+ $repeated[] = $feedback;
return $repeated;
}
@@ -124,7 +146,7 @@ protected function definition_inner($mform) {
$mform->createElement('submit', $addfieldsname, $addstring), 'listcategory');
$mform->registerNoSubmitButton('createoptionbutton');
- //editing as regular
+ // Editing as regular.
$mform->setType('single', PARAM_INT);
$mform->addElement('hidden', 'shuffleanswers', '1');
@@ -141,7 +163,7 @@ protected function definition_inner($mform) {
$this->add_unit_fields($mform, $this);
$this->add_interactive_settings();
- // Hidden elements
+ // Hidden elements.
$mform->addElement('hidden', 'synchronize', '');
$mform->setType('synchronize', PARAM_INT);
$mform->addElement('hidden', 'wizard', 'datasetdefinitions');
@@ -190,7 +212,7 @@ public function qtype() {
public function validation($data, $files) {
- // verifying for errors in {=...} in question text;
+ // Verifying for errors in {=...} in question text.
$qtext = "";
$qtextremaining = $data['questiontext']['text'];
$possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']['text']);
@@ -26,6 +26,8 @@
$string['additem'] = 'Add item';
$string['addmoreanswerblanks'] = 'Add another answer blank.';
$string['addsets'] = 'Add set(s)';
+$string['answerformula'] = 'Answer {$a} formula';
+$string['answerdisplay'] = 'Answer display';
$string['answerhdr'] = 'Answer';
$string['answerstoleranceparam'] = 'Answers tolerance parameters';
$string['answerwithtolerance'] = '{$a->answer} (±{$a->tolerance} {$a->tolerancetype})';
@@ -129,6 +131,7 @@
$string['synchronizeyes']='Synchronize';
$string['synchronizeyesdisplay']='Synchronize and display the shared datasets name as prefix of the question name';
$string['tolerance'] = 'Tolerance ±';
+$string['tolerancetype'] = 'Type';
$string['trueanswerinsidelimits'] = 'Correct answer : {$a->correct} inside limits of true value {$a->true}';
$string['trueansweroutsidelimits'] = '<span class="error">ERROR Correct answer : {$a->correct} outside limits of true value {$a->true}</span>';
$string['uniform'] = 'Uniform';
@@ -20,3 +20,56 @@
direction: ltr;
text-align: left;
}
+
+/* Editing form. */
+body#page-question-type-calculated div[id^=fgroup_id_][id*=answeroptions_],
+body#page-question-type-calculatedmulti div[id^=fgroup_id_][id*=answeroptions_] {
+ background: #EEE;
+ margin-top: 0;
+ margin-bottom: 0;
+ padding-bottom: 5px;
+ padding-top: 5px;
+ border: 1px solid #BBB;
+ border-bottom: 0;
+}
+
+body#page-question-type-calculated div[id^=fgroup_id_][id*=answeroptions_] .fgrouplabel label,
+body#page-question-type-calculatedmulti div[id^=fgroup_id_][id*=answeroptions_] .fgrouplabel label {
+ font-weight: bold;
+}
+
+body#page-question-type-calculated div[id^=fgroup_id_][id*=answeroptions_] label[for^='id_answer_'],
+body#page-question-type-calculated div[id^=fgroup_id_][id*=answertolerance_] label[for^='id_tolerance_'],
+body#page-question-type-calculated div[id^=fgroup_id_][id*=answerdisplay_] label[for^='id_correctanswerlength_'],
+body#page-question-type-calculatedmulti div[id^=fgroup_id_][id*=answeroptions_] label[for^='id_answer_'],
+body#page-question-type-calculatedmulti div[id^=fgroup_id_][id*=answerdisplay_] label[for^='id_correctanswerlength_'] {
+ position: absolute;
+ left: -10000px;
+ font-weight: normal;
+ font-size: 1em;
+}
+
+body#page-question-type-calculated div[id^=fgroup_id_][id*=answertolerance_],
+body#page-question-type-calculated div[id^=fgroup_id_][id*=answerdisplay_],
+body#page-question-type-calculatedmulti div[id^=fgroup_id_][id*=answertolerance_],
+body#page-question-type-calculatedmulti div[id^=fgroup_id_][id*=answerdisplay_] {
+ background: #EEE;
+ margin-bottom: 0;
+ margin-top: 0;
+ padding-bottom: 5px;
+ padding-top: 5px;
+ border: 1px solid #BBB;
+ border-top: 0;
+ border-bottom: 0;
+}
+
+body#page-question-type-calculated div[id^=fitem_id_][id*=feedback_],
+body#page-question-type-calculatedmulti div[id^=fitem_id_][id*=feedback_] {
+ background: #EEE;
+ margin-bottom: 2em;
+ margin-top: 0;
+ padding-bottom: 5px;
+ padding-top: 5px;
+ border: 1px solid #BBB;
+ border-top: 0;
+}
@@ -50,9 +50,9 @@ public function __construct($submiturl, $question, $category,
$this->qtypeobj = question_bank::get_qtype('calculatedmulti');
$this->reload = optional_param('reload', false, PARAM_BOOL);
if (!$this->reload) {
- // use database data as this is first pass
+ // Use database data as this is first pass.
if (isset($this->question->id)) {
- // remove prefix #{..}# if exists
+ // Remove prefix #{..}# if exists.
$this->initialname = $question->name;
$regs= array();
if (preg_match('~#\{([^[:space:]]*)#~', $question->name , $regs)) {
@@ -66,13 +66,16 @@ public function __construct($submiturl, $question, $category,
public function get_per_answer_fields($mform, $label, $gradeoptions,
&$repeatedoptions, &$answersoption) {
$repeated = array();
- $repeated[] = $mform->createElement('header', 'answerhdr', $label);
- $repeated[] = $mform->createElement('text', 'answer',
- get_string('answer', 'question'), array('size' => 50));
- $repeated[] = $mform->createElement('select', 'fraction',
+ $answeroptions = array();
+ $answeroptions[] = $mform->createElement('text', 'answer',
+ $label, array('size' => 50));
+ $answeroptions[] = $mform->createElement('select', 'fraction',
get_string('grade'), $gradeoptions);
- $repeated[] = $mform->createElement('editor', 'feedback',
- get_string('feedback', 'question'), null, $this->editoroptions);
+ $repeated[] = $mform->createElement('group', 'answeroptions',
+ $label, $answeroptions, null, false);
+
+ // Added answeroptions help button in definition_inner() after called to add_per_answer_fields.
+
$repeatedoptions['answer']['type'] = PARAM_RAW;
$repeatedoptions['fraction']['default'] = 0;
$answersoption = 'answers';
@@ -85,18 +88,24 @@ public function get_per_answer_fields($mform, $label, $gradeoptions,
$repeatedoptions['tolerance']['type'] = PARAM_FLOAT;
$repeatedoptions['tolerance']['default'] = 0.01;
- $addrepeated[] = $mform->createElement('select', 'correctanswerlength',
- get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
+ // Create display group.
+ $answerdisplay = array();
+ $answerdisplay[] = $mform->createElement('select', 'correctanswerlength',
+ get_string('answerdisplay', 'qtype_calculated'), range(0, 9));
$repeatedoptions['correctanswerlength']['default'] = 2;
$answerlengthformats = array(
'1' => get_string('decimalformat', 'qtype_numerical'),
'2' => get_string('significantfiguresformat', 'qtype_calculated')
);
- $addrepeated[] = $mform->createElement('select', 'correctanswerformat',
+ $answerdisplay[] = $mform->createElement('select', 'correctanswerformat',
get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
- array_splice($repeated, 3, 0, $addrepeated);
- $repeated[1]->setLabel('...<strong>{={x}+..}</strong>...');
+ $repeated[] = $mform->createElement('group', 'answerdisplay',
+ get_string('answerdisplay', 'qtype_calculated'), $answerdisplay, null, false);
+
+ // Add feedback.
+ $repeated[] = $mform->createElement('editor', 'feedback',
+ get_string('feedback', 'question'), null, $this->editoroptions);
return $repeated;
}
@@ -145,6 +154,7 @@ protected function definition_inner($mform) {
$this->add_per_answer_fields($mform, get_string('choiceno', 'qtype_multichoice', '{no}'),
question_bank::fraction_options_full(), max(5, QUESTION_NUMANS_START));
+ $mform->addHelpButton('answeroptions[0]', 'answeroptions', 'qtype_calculatedmulti');
$repeated = array();
// if ($this->editasmultichoice == 1) {
@@ -166,7 +176,7 @@ protected function definition_inner($mform) {
$this->add_interactive_settings(true, true);
- //hidden elements
+ // Hidden elements.
$mform->addElement('hidden', 'synchronize', '');
$mform->setType('synchronize', PARAM_INT);
if (isset($this->question->options) && isset($this->question->options->synchronize)) {
@@ -221,7 +231,7 @@ protected function data_preprocessing_answers($question, $withanswerfiles = fals
public function validation($data, $files) {
$errors = parent::validation($data, $files);
- //verifying for errors in {=...} in question text;
+ // Verifying for errors in {=...} in question text.
$qtext = '';
$qtextremaining = $data['questiontext']['text'];
$possibledatasets = $this->qtypeobj->find_dataset_names($data['questiontext']['text']);
@@ -268,7 +278,7 @@ public function validation($data, $files) {
$errors['fraction['.$key.']'] = get_string('errgradesetanswerblank', 'qtype_multichoice');
}
if ($trimmedanswer != '' || $answercount == 0) {
- //verifying for errors in {=...} in answer text;
+ // Verifying for errors in {=...} in answer text.
$qanswer = '';
$qanswerremaining = $trimmedanswer;
$possibledatasets = $this->qtypeobj->find_dataset_names($trimmedanswer);
@@ -318,7 +328,7 @@ public function validation($data, $files) {
$errors['answer[1]'] = get_string('notenoughanswers', 'qtype_multichoice', 2);
}
- /// Perform sanity checks on fractional grades
+ // Perform sanity checks on fractional grades.
if ($data['single']== 1 ) {
if ($maxfraction != 1) {
$errors['fraction[0]'] = get_string('errfractionsnomax', 'qtype_multichoice',
@@ -22,7 +22,8 @@
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
+$string['answeroptions'] = 'Choice options';
+$string['answeroptions_help'] = 'The suggested choice formula is ...<strong>{={x}+..}</strong>...';
$string['pluginname'] = 'Calculated multichoice';
$string['pluginname_help'] = 'Calculated multichoice questions are like multichoice questions which in their choice elements can be included numerical formula results using wildcards in curly brackets that are substituted with individual values when the quiz is taken. For example, if the question "What is the area of a rectangle of length {l} and width {w}?" one of the choice is {={l}*{w}} (where * denotes multiplication). ';
$string['pluginname_link'] = 'question/type/calculatedmulti';
@@ -6,3 +6,49 @@
.que.calculatedsimple .answer input[type="text"] {
width: 30%;
}
+
+/* Editing form. */
+body#page-question-type-calculatedsimple div[id^=fgroup_id_][id*=answeroptions_] {
+ background: #EEE;
+ margin-top: 0;
+ margin-bottom: 0;
+ padding-bottom: 5px;
+ padding-top: 5px;
+ border: 1px solid #BBB;
+ border-bottom: 0;
+}
+
+body#page-question-type-calculatedsimple div[id^=fgroup_id_][id*=answeroptions_] .fgrouplabel label{
+ font-weight: bold;
+}
+
+body#page-question-type-calculatedsimple div[id^=fgroup_id_][id*=answeroptions_] label[for^='id_answer_'],
+body#page-question-type-calculatedsimple div[id^=fgroup_id_][id*=answertolerance_] label[for^='id_tolerance_'],
+body#page-question-type-calculatedsimple div[id^=fgroup_id_][id*=answerdisplay_] label[for^='id_correctanswerlength_'] {
+ position: absolute;
+ left: -10000px;
+ font-weight: normal;
+ font-size: 1em;
+}
+
+body#page-question-type-calculatedsimple div[id^=fgroup_id_][id*=answertolerance_],
+body#page-question-type-calculatedsimple div[id^=fgroup_id_][id*=answerdisplay_] {
+ background: #EEE;
+ margin-bottom: 0;
+ margin-top: 0;
+ padding-bottom: 5px;
+ padding-top: 5px;
+ border: 1px solid #BBB;
+ border-top: 0;
+ border-bottom: 0;
+}
+
+body#page-question-type-calculatedsimple div[id^=fitem_id_][id*=feedback_] {
+ background: #EEE;
+ margin-bottom: 2em;
+ margin-top: 0;
+ padding-bottom: 5px;
+ padding-top: 5px;
+ border: 1px solid #BBB;
+ border-top: 0;
+}
Oops, something went wrong.

0 comments on commit c7218ae

Please sign in to comment.