]> git.mjollnir.org Git - moodle.git/commitdiff
Refactored printing of feedback images and printing of feedback html classes. See...
authorvyshane <vyshane>
Mon, 18 Dec 2006 06:04:47 +0000 (06:04 +0000)
committervyshane <vyshane>
Mon, 18 Dec 2006 06:04:47 +0000 (06:04 +0000)
question/type/match/questiontype.php
question/type/multianswer/questiontype.php
question/type/multichoice/questiontype.php
question/type/shortanswer/questiontype.php
question/type/truefalse/display.html
question/type/truefalse/questiontype.php

index fb382778f6c59dd89364412e0cb88cbbda2bcab5..628a2b54895704121356f82f89a155bf6dd49153 100644 (file)
@@ -275,27 +275,32 @@ class question_match_qtype extends default_questiontype {
                 $a = new stdClass;
                 $a->text = $this->format_text($subquestion->questiontext,
                         $question->questiontextformat, $cmoptions);
-    
+
                 /// Drop-down list:
                 $menuname = $nameprefix.$subquestion->id;
                 $response = isset($state->responses[$subquestion->id])
                             ? $state->responses[$subquestion->id] : '0';
+
+                $a->class = ' ';
+                $a->feedbackimg = ' ';
+
                 if ($options->readonly
-                    and $options->correct_responses
-                    and isset($correctanswers[$subquestion->id])
-                    and ($correctanswers[$subquestion->id] == $response)) {
-                    $a->class = ' correct ';
-                                       $a->feedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_green_big.gif" alt="'.get_string('correct', 'quiz').'" width="16" height="16" />';
-                } else if ($response) {
-                    $a->class = ' incorrect ';
-                                       $a->feedbackimg = '<img src="'.$CFG->pixpath.'/i/cross_red_big.gif" alt="'.get_string('incorrect', 'quiz').'" width="16" height="16" />';
+                            and $options->correct_responses
+                            and isset($correctanswers[$subquestion->id])
+                            and ($correctanswers[$subquestion->id] == $response)) {
+
+                    $correctresponse = 1;
                 } else {
-                                       $a->class = ' ';
-                                       $a->feedbackimg = ' ';
-                               }
-    
-                $a->control = choose_from_menu($answers, $menuname, $response, 'choose', '', 0,
-                 true, $options->readonly);
+                    $correctresponse = 0;
+                }
+
+                if ($response) {
+                    $a->class = question_get_feedback_class($correctresponse);
+                    $a->feedbackimg = question_get_feedback_image($correctresponse);
+                }
+
+                $a->control = choose_from_menu($answers, $menuname, $response, 'choose',
+                                               '', 0, true, $options->readonly);
     
                 // Neither the editing interface or the database allow to provide
                 // fedback for this question type.
@@ -306,7 +311,7 @@ class question_match_qtype extends default_questiontype {
                 // && !empty($subquestion->options->answers[$responses[$key]]->feedback)) {
                 //    print_comment($subquestion->options->answers[$responses[$key]]->feedback);
                 //}
-    
+
                 $anss[] = $a;
             }
         }
index e8aa50bd4ca118314b55a4844cd1cabd2576ba88..6f28fc8698c733e968556a003d660fa905e6473c 100644 (file)
@@ -237,7 +237,7 @@ class embedded_cloze_qtype extends default_questiontype {
             // Determine feedback popup if any
             $popup = '';
             $style = '';
-                       $feedbackimg = '';
+            $feedbackimg = '';
             if ($options->feedback) {
                 $chosenanswer = null;
                 switch ($wrapped->qtype) {
@@ -276,24 +276,12 @@ class embedded_cloze_qtype extends default_questiontype {
                 }
 
                 /// Determine style
-                if (!empty($chosenanswer) && $options->correct_responses) {
-                    if (!isset($chosenanswer->fraction)
-                            || $chosenanswer->fraction <= 0.0) {
-                        // The response must have been totally wrong.
-                        $style = 'class="incorrect"';
-                                               $feedbackimg = '<img src="'.$CFG->pixpath.'/i/cross_red_big.gif" alt="'.get_string('incorrect', 'quiz').'" width="16" height="16" />';
-                    } else if ($chosenanswer->fraction >= 1.0) {
-                        // The response was correct.
-                        $style = 'class="correct"';
-                                               $feedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_green_big.gif" alt="'.get_string('correct', 'quiz').'" width="16" height="16" />';
-                    } else {
-                        // This response did at least give some credit.
-                        $style = 'class="partiallycorrect"';
-                                               $feedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_amber_big.gif" alt="'.get_string('partiallycorrect', 'quiz').'" width="16" height="16" />';
-                    }
+                if (!empty($response)) {
+                    $style = 'class = "'.question_get_feedback_class($chosenanswer->fraction).'"';
+                    $feedbackimg = question_get_feedback_image($chosenanswer->fraction);
                 } else {
                     $style = '';
-                                       $feedbackimg = '';
+                    $feedbackimg = '';
                 }
             }
 
@@ -306,7 +294,7 @@ class embedded_cloze_qtype extends default_questiontype {
                     if (!empty($feedback) && $USER->screenreader) {
                         echo "<img src=\"$CFG->pixpath/i/feedback.gif\" alt=\"$feedback\" />";
                     }
-                                       echo $feedbackimg;
+                    echo $feedbackimg;
                     break;
                 case 'multichoice':
                     $outputoptions = '<option></option>'; // Default empty option
@@ -320,16 +308,16 @@ class embedded_cloze_qtype extends default_questiontype {
                     // displaying the feedback does not work. Of course, we should
                     // not be relying on JS (for accessibility reasons), but that is
                     // a bigger problem.
-                                       //
-                                       // The span is used for safari, which does not allow styling of
-                                       // selects.
+                    //
+                    // The span is used for safari, which does not allow styling of
+                    // selects.
                     echo "<span $style><select $popup $readonly $style name=\"$inputname\">";
                     echo $outputoptions;
                     echo '</select></span>';
                     if (!empty($feedback) && $USER->screenreader) {
                         echo "<img src=\"$CFG->pixpath/i/feedback.gif\" alt=\"$feedback\" />";
                     }
-                                   echo $feedbackimg;
+                    echo $feedbackimg;
                     break;
                 default:
                     error("Unable to recognize questiontype ($wrapped->qtype) of
index 6e4d1f7a3c866a88a362eb8c76eb788871175991..cfa9bee52a9039382eeae22a62f0e62f9991e8d4 100644 (file)
@@ -283,58 +283,40 @@ class question_multichoice_qtype extends default_questiontype {
             $answer = &$answers[$aid];
             $qnumchar = chr(ord('a') + $key);
             $checked = '';
-                       $chosen = false;
-                       
+            $chosen = false;
+            
             if ($question->options->single) {
                 $type = 'type="radio"';
                 $name   = "name=\"{$question->name_prefix}\"";
                 if (isset($state->responses['']) and $aid == $state->responses['']) {
                     $checked = 'checked="checked"';
-                                       $chosen = true;
+                    $chosen = true;
                 }
             } else {
                 $type = ' type="checkbox" ';
                 $name   = "name=\"{$question->name_prefix}{$aid}\"";
                 if (isset($state->responses[$aid])) {
-                                       $checked = 'checked="checked"';
-                                       $chosen = true;
-                               }
+                    $checked = 'checked="checked"';
+                    $chosen = true;
+                }
             }
 
             $a = new stdClass;
             $a->id   = $question->name_prefix . $aid;
-                       $a->class = '';
-                       $a->feedbackimg = '';
+            $a->class = '';
+            $a->feedbackimg = '';
 
             // Print the control
             $a->control = "<input $readonly id=\"$a->id\" $name $checked $type value=\"$aid\"" .
                  " alt=\"" . s($answer->answer) . '" />';
 
-                       if ($options->readonly) {
-                               // Means we need to display answer correctness.
-                               if ($answer->fraction == 1) {
-                                       if ($chosen) {
-                                               $a->class = 'correct';
-                                               $a->feedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_green_big.gif" alt="'.get_string('correct', 'quiz').'" width="16" height="16" />';
-                                       } else {
-                                               $a->feedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_green_small.gif" alt="'.get_string('correct', 'quiz').'" width="16" height="16" />';
-                                       }
-                               } else if ($answer->fraction > 0 && $answer->fraction < 1) {
-                                       if ($chosen) {
-                                               $a->class = 'partiallycorrect';
-                                               $a->feedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_amber_big.gif" alt="'.get_string('partiallycorrect', 'quiz').'" width="16" height="16" />';
-                                       } else {
-                                               $a->feedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_amber_small.gif" alt="'.get_string('partiallycorrect', 'quiz').'" width="16" height="16" />';
-                                       }
-                               } else {
-                                       if ($chosen) {
-                                               $a->class = 'incorrect';
-                                               $a->feedbackimg = '<img src="'.$CFG->pixpath.'/i/cross_red_big.gif" alt="'.get_string('incorrect', 'quiz').'" width="16" height="16" />';
-                                       } else {
-                                               $a->feedbackimg = '<img src="'.$CFG->pixpath.'/i/cross_red_small.gif" alt="'.get_string('incorrect', 'quiz').'" width="16" height="16" />';
-                                       }
-                               }
-                       }
+            if ($options->readonly) {
+                // Means we need to display answer correctness.
+                if ($chosen) {
+                    $a->class = question_get_feedback_class($answer->fraction);
+                }
+                $a->feedbackimg = question_get_feedback_image($answer->fraction, $chosen);
+            }
 
             // Print the answer text
             $a->text = format_text("$qnumchar. $answer->answer", FORMAT_MOODLE, $formatoptions, $cmoptions->course);
index f72398e3ecb68ebd7fdccc14a00e0e6788890757..6d7aa9149a190c30ad4280401c8edee1b8742734 100644 (file)
@@ -146,27 +146,21 @@ class question_shortanswer_qtype extends default_questiontype {
         $inputname = ' name="'.$nameprefix.'" ';
 
         $feedback = '';
-        $class = '';
-        $feedbackimg = '';
+        // Assume wrong answer first.
+        $class = question_get_feedback_class(0);
+        $feedbackimg = question_get_feedback_image(0);
 
         if ($options->feedback) {
             foreach($question->options->answers as $answer) {
+
                 if ($this->test_response($question, $state, $answer)) {
                     // Answer was correct or partially correct.
-                    if ($answer->fraction == 1) {
-                        $class = 'correct';
-                        $feedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_green_big.gif" alt="'.get_string('correct', 'quiz').'" width="16" height="16" />';
-                    } else {
-                        $class = 'partiallycorrect';
-                        $feedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_amber_big.gif" alt="'.get_string('partiallycorrect', 'quiz').'" width="16" height="16" />';                  
-                    }
+                    $class = question_get_feedback_class($answer->fraction);
+                    $feedbackimg = question_get_feedback_image($answer->fraction);
                     if ($answer->feedback) {
                         $feedback = format_text($answer->feedback, true, $formatoptions, $cmoptions->course);
                     }
                     break;
-                } else {
-                    $class = 'incorrect';
-                    $feedbackimg = '<img src="'.$CFG->pixpath.'/i/cross_red_big.gif" alt="'.get_string('incorrect', 'quiz').'" width="16" height="16" />';
                 }
             }
         }
index e60642507a66942f544613ffbd6bc4c6865f3582..ea9e536fbc7cc3a3a45107b962c8abb3231ce331 100644 (file)
   </div>
 
   <div class="answer">
-    <span <?php echo $trueclass; ?>>
+    <span <?php echo 'class="'.$trueclass.'"'; ?>>
         <?php echo $radiotrue ?>
         <?php echo $truefeedbackimg; ?>
     </span>
-    <span <?php echo $falseclass; ?>>
+    <span <?php echo 'class="'.$falseclass.'"'; ?>>
         <?php echo $radiofalse ?>
         <?php echo $falsefeedbackimg; ?>
     </span>
index 1877b11e09b710e2569f9469e96e2583d9287c9b..d32a654e663036c80631ced3a9d1c7c746c4c885 100644 (file)
@@ -155,41 +155,25 @@ class question_truefalse_qtype extends default_questiontype {
         $falseanswer = &$answers[$question->options->falseanswer];
         $correctanswer = ($trueanswer->fraction == 1) ? $trueanswer : $falseanswer;
 
-               $trueclass = '';
-               $falseclass = '';
-               $truefeedbackimg = '';
-               $falsefeedbackimg = '';
+        $trueclass = '';
+        $falseclass = '';
+        $truefeedbackimg = '';
+        $falsefeedbackimg = '';
 
         // Work out which radio button to select (if any)
         $truechecked = ($state->responses[''] == $trueanswer->id) ? ' checked="checked"' : '';
         $falsechecked = ($state->responses[''] == $falseanswer->id) ? ' checked="checked"' : '';
 
         // Work out visual feedback for answer correctness.
-               if ($truechecked) {
-                       if ($correctanswer == $trueanswer) {
-                               $trueclass = ' class="correct"';
-                               $falseclass = '';
-                               $truefeedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_green_big.gif" alt="'.get_string('correct', 'quiz').'" width="16" height="16" />';
-                               $falsefeedbackimg = '<img src="'.$CFG->pixpath.'/i/cross_red_small.gif" alt="'.get_string('incorrect', 'quiz').'" width="16" height="16" />';
-                       } else if ($correctanswer == $falseanswer) {
-                               $trueclass = '';
-                               $falseclass = ' class="correct"';
-                               $truefeedbackimg = '<img src="'.$CFG->pixpath.'/i/cross_red_small.gif" alt="'.get_string('incorrect', 'quiz').'" width="16" height="16" />';
-                               $falsefeedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_green_big.gif" alt="'.get_string('correct', 'quiz').'" width="16" height="16" />';
-                       }
-               } else if ($falsechecked) {
-                       if ($correctanswer == $trueanswer) {
-                               $trueclass = '';
-                               $falseclass = ' class="incorrect"';
-                               $truefeedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_green_small.gif" alt="'.get_string('correct', 'quiz').'" width="16" height="16" />';
-                               $falsefeedbackimg = '<img src="'.$CFG->pixpath.'/i/cross_red_big.gif" alt="'.get_string('incorrect', 'quiz').'" width="16" height="16" />';
-                       } else if ($correctanswer == $falseanswer) {
-                               $trueclass = ' class="incorrect"';
-                               $falseclass = '';
-                               $truefeedbackimg = '<img src="'.$CFG->pixpath.'/i/cross_red_big.gif" alt="'.get_string('incorrect', 'quiz').'" width="16" height="16" />';
-                               $falsefeedbackimg = '<img src="'.$CFG->pixpath.'/i/tick_green_small.gif" alt="'.get_string('correct', 'quiz').'" width="16" height="16" />';
-                       }
-               }
+        if ($truechecked) {
+            $trueclass = question_get_feedback_class($trueanswer->fraction);
+        } else if ($falsechecked) {
+            $falseclass = question_get_feedback_class($falseanswer->fraction);
+        }
+        if (isset($answers[$state->responses['']])) {
+            $truefeedbackimg = question_get_feedback_image($trueanswer->fraction, !empty($truechecked));
+            $falsefeedbackimg = question_get_feedback_image($falseanswer->fraction, !empty($falsechecked));
+        }
 
         $inputname = ' name="'.$question->name_prefix.'" ';
         $trueid    = $question->name_prefix.'true';