From: vyshane Date: Mon, 18 Dec 2006 06:07:44 +0000 (+0000) Subject: Added 2 new functions: question_get_feedback_image() and question_get_feedback_class(). X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=bc75cc52104b8ccaee6357247c049d111168583a;p=moodle.git Added 2 new functions: question_get_feedback_image() and question_get_feedback_class(). --- diff --git a/lib/questionlib.php b/lib/questionlib.php index 41c4496658..5fc0621345 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -855,6 +855,67 @@ function question_extract_responses($questions, $formdata, $defaultevent=QUESTIO } +/** + * Returns the html for question feedback image. + * @param float $fraction value representing the correctness of the user's + * response to a question. + * @param boolean $selected whether or not the answer is the one that the + * user picked. + * @return string + */ +function question_get_feedback_image($fraction, $selected=true) { + + global $CFG; + + if ($fraction >= 1.0) { + if ($selected) { + $feedbackimg = ''; + } else { + $feedbackimg = ''; + } + } else if ($fraction > 0.0 && $fraction < 1.0) { + if ($selected) { + $feedbackimg = ''; + } else { + $feedbackimg = ''; + } + } else { + if ($selected) { + $feedbackimg = ''; + } else { + $feedbackimg = ''; + } + } + return $feedbackimg; +} + + +/** + * Returns the class name for question feedback. + * @param float $fraction value representing the correctness of the user's + * response to a question. + * @return string + */ +function question_get_feedback_class($fraction) { + + global $CFG; + + if ($fraction >= 1.0) { + $class = 'correct'; + } else if ($fraction > 0.0 && $fraction < 1.0) { + $class = 'partiallycorrect'; + } else { + $class = 'incorrect'; + } + return $class; +} + /** * For a given question in an attempt we walk the complete history of states