Quellcode durchsuchen

Quiz: Add quiz_open_question_decimal_score conf setting - refs BT#16152

Allow the teacher to rate the open, oral expression and annotation question types with a decimal score.
Angel Fernando Quiroz Campos vor 5 Jahren
Ursprung
Commit
a7948972a8
2 geänderte Dateien mit 60 neuen und 24 gelöschten Zeilen
  1. 58 24
      main/exercise/exercise_show.php
  2. 2 0
      main/install/configuration.dist.php

+ 58 - 24
main/exercise/exercise_show.php

@@ -210,8 +210,16 @@ if ($action != 'export') {
                 var oHidn = document.createElement("input");
                 oHidn.type = "hidden";
                 var selname = oHidn.name = "marks_" + m_id[i];
-                var selid = document.forms['marksform_' + m_id[i]].marks.selectedIndex;
-                oHidn.value = document.forms['marksform_' + m_id[i]].marks.options[selid].value;
+
+                var foo = document.forms['marksform_' + m_id[i]].marks;
+
+                if (foo.tagName.toLowerCase() === 'select') {
+                    var selid = document.forms['marksform_' + m_id[i]].marks.selectedIndex;
+                    oHidn.value = document.forms['marksform_' + m_id[i]].marks.options[selid].value;
+                } else if (foo.tagName.toLowerCase() === 'input') {
+                    oHidn.value = document.forms['marksform_' + m_id[i]].marks.value;
+                }
+
                 f.appendChild(oHidn);
             }
 
@@ -667,34 +675,60 @@ foreach ($questionList as $questionId) {
 
                 echo '<div id="'.$marksname.'" class="hidden">';
 
+                $allowDecimalScore = api_get_configuration_value('quiz_open_question_decimal_score');
                 $formMark = new FormValidator('marksform_'.$questionId, 'post');
                 $formMark->addHeader(get_lang('AssignMarks'));
-                $select = $formMark->addSelect(
-                    'marks',
-                    get_lang('AssignMarks'),
-                    [],
-                    ['disable_js' => true, 'extra_class' => 'grade_select']
-                );
                 $model = ExerciseLib::getCourseScoreModel();
-                if (empty($model)) {
-                    for ($i = 0; $i <= $questionWeighting; $i++) {
-                        $attributes = [];
-                        if ($questionScore == $i) {
-                            $attributes['selected'] = 'selected';
-                        }
-                        $select->addOption($i, $i, $attributes);
-                    }
+
+                if ($allowDecimalScore && empty($model)) {
+                    $formMark->addElement(
+                        'number',
+                        'marks',
+                        get_lang('AssignMarks'),
+                        [
+                            'step' => 0.01,
+                            'min' => 0,
+                            'max' => $questionWeighting,
+                            'placeholder' => 0,
+                            'class' => 'grade_select',
+                            'id' => "select_marks_$questionId",
+                        ]
+                    );
+                    $formMark->setDefaults(['marks' => $questionScore]);
+                    $formMark->applyFilter('marks', 'stripslashes');
+                    $formMark->applyFilter('marks', 'trim');
+                    $formMark->applyFilter('marks', 'floatval');
+                    $formMark->addRule('marks', get_lang('Numeric'), 'numeric');
+                    $formMark->addRule('marks', get_lang('ValueTooSmall'), 'min_numeric_length', 0);
+                    $formMark->addRule('marks', get_lang('ValueTooBig'), 'max_numeric_length', $questionWeighting);
                 } else {
-                    foreach ($model['score_list'] as $item) {
-                        $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
-                        $model = ExerciseLib::getModelStyle($item, $i);
-                        $attributes = ['class' => $item['css_class']];
-                        if ($questionScore == $i) {
-                            $attributes['selected'] = 'selected';
+                    $select = $formMark->addSelect(
+                        'marks',
+                        get_lang('AssignMarks'),
+                        [],
+                        ['disable_js' => true, 'extra_class' => 'grade_select']
+                    );
+
+                    if (empty($model)) {
+                        for ($i = 0; $i <= $questionWeighting; $i++) {
+                            $attributes = [];
+                            if ($questionScore == $i) {
+                                $attributes['selected'] = 'selected';
+                            }
+                            $select->addOption($i, $i, $attributes);
+                        }
+                    } else {
+                        foreach ($model['score_list'] as $item) {
+                            $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
+                            $model = ExerciseLib::getModelStyle($item, $i);
+                            $attributes = ['class' => $item['css_class']];
+                            if ($questionScore == $i) {
+                                $attributes['selected'] = 'selected';
+                            }
+                            $select->addOption($model, $i, $attributes);
                         }
-                        $select->addOption($model, $i, $attributes);
+                        $select->updateSelectWithSelectedOption($formMark);
                     }
-                    $select->updateSelectWithSelectedOption($formMark);
                 }
 
                 $formMark->display();

+ 2 - 0
main/install/configuration.dist.php

@@ -584,6 +584,8 @@ $_configuration['send_all_emails_to'] = [
 // Generate certificate when ending a quiz.
 // The quiz needs to be linked to a gradebook category and have set the pass percentage.
 //$_configuration['quiz_generate_certificate_ending'] = false;
+// Allow the teacher to rate the open, oral expression and annotation question types with a decimal score.
+//$_configuration['quiz_open_question_decimal_score'] = false;
 
 // Hide search form in session list
 //$_configuration['hide_search_form_in_session_list'] = false;