|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00028 defined('MOODLE_INTERNAL') || die(); 00029 00030 00038 class qbehaviour_adaptive_renderer extends qbehaviour_renderer { 00039 00040 public function controls(question_attempt $qa, question_display_options $options) { 00041 return $this->submit_button($qa, $options); 00042 } 00043 00044 public function feedback(question_attempt $qa, question_display_options $options) { 00045 if ($qa->get_state() == question_state::$invalid) { 00046 // If the latest answer was invalid, display an informative message 00047 $output = ''; 00048 $info = $this->disregarded_info(); 00049 if ($info) { 00050 $output = html_writer::tag('div', $info, array('class' => 'gradingdetails')); 00051 } 00052 return $output; 00053 } 00054 00055 // Try to find the last graded step. 00056 00057 $gradedstep = $qa->get_behaviour()->get_graded_step($qa); 00058 if (is_null($gradedstep) || $qa->get_max_mark() == 0 || 00059 $options->marks < question_display_options::MARK_AND_MAX) { 00060 return ''; 00061 } 00062 00063 // Display the grading details from the last graded state 00064 $mark = new stdClass(); 00065 $mark->max = $qa->format_max_mark($options->markdp); 00066 00067 $actualmark = $gradedstep->get_fraction() * $qa->get_max_mark(); 00068 $mark->cur = format_float($actualmark, $options->markdp); 00069 00070 $rawmark = $gradedstep->get_behaviour_var('_rawfraction') * $qa->get_max_mark(); 00071 $mark->raw = format_float($rawmark, $options->markdp); 00072 00073 // let student know wether the answer was correct 00074 if ($qa->get_state()->is_commented()) { 00075 $class = $qa->get_state()->get_feedback_class(); 00076 } else { 00077 $class = question_state::graded_state_for_fraction( 00078 $gradedstep->get_behaviour_var('_rawfraction'))->get_feedback_class(); 00079 } 00080 00081 $gradingdetails = get_string('gradingdetails', 'qbehaviour_adaptive', $mark); 00082 00083 $gradingdetails .= $this->penalty_info($qa, $mark, $options); 00084 00085 $output = ''; 00086 $output .= html_writer::tag('div', get_string($class, 'question'), 00087 array('class' => 'correctness ' . $class)); 00088 $output .= html_writer::tag('div', $gradingdetails, 00089 array('class' => 'gradingdetails')); 00090 return $output; 00091 } 00092 00099 protected function penalty_info(question_attempt $qa, $mark, 00100 question_display_options $options) { 00101 00102 $currentpenalty = $qa->get_question()->penalty * $qa->get_max_mark(); 00103 $totalpenalty = $currentpenalty * $qa->get_last_behaviour_var('_try', 0); 00104 00105 if ($currentpenalty == 0) { 00106 return ''; 00107 } 00108 $output = ''; 00109 00110 // Print details of grade adjustment due to penalties 00111 if ($mark->raw != $mark->cur) { 00112 $output .= ' ' . get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark); 00113 } 00114 00115 // Print information about any new penalty, only relevant if the answer can be improved. 00116 if ($qa->get_behaviour()->is_state_improvable($qa->get_state())) { 00117 $output .= ' ' . get_string('gradingdetailspenalty', 'qbehaviour_adaptive', 00118 format_float($currentpenalty, $options->markdp)); 00119 00120 // Print information about total penalties so far, if larger than current penalty. 00121 if ($totalpenalty > $currentpenalty) { 00122 $output .= ' ' . get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive', 00123 format_float($totalpenalty, $options->markdp)); 00124 } 00125 } 00126 00127 return $output; 00128 } 00129 00133 protected function disregarded_info() { 00134 return get_string('disregardedwithoutpenalty', 'qbehaviour_adaptive'); 00135 } 00136 00137 }