Skip to content

Commit

Permalink
MDL-20296 improving grading code and display
Browse files Browse the repository at this point in the history
  • Loading branch information
ppichet committed May 13, 2010
1 parent e2f6bdd commit aa384ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
9 changes: 7 additions & 2 deletions question/type/numerical/display.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
<fieldset class="clearfix" id="generalheader">
<legend class="ftoggler">
<?php echo get_string('unit', 'quiz');
//echo $question->options->units[0]->unit ;
?>
</legend>
<input type="hidden"
Expand Down Expand Up @@ -134,6 +133,11 @@
//display the units as choice
if ( isset($question->options->units)){?>
<div class="answer">
<fieldset class="clearfix" id="generalheader">
<legend class="ftoggler">
<?php echo get_string('unit', 'quiz');
?>
</legend>
<table class="answer">

<?php foreach ($question->options->units as $key => $unit) {
Expand All @@ -142,7 +146,7 @@

$type = 'type="radio"';
// $nameunit = "name=\"".$question->name_prefix;//."unit\"";
if (isset($state->responses['unit'])){
if (isset($state->responses['unit']) && $state->responses['unit'] != '' ){
if ($state->responses['unit'] == $unit->unit) {
$checked = 'checked="checked"';
$chosen = true;
Expand Down Expand Up @@ -191,6 +195,7 @@
<?php } ?>

</table>
</fieldset>

</div>
<?php } // end unit choices
Expand Down
17 changes: 8 additions & 9 deletions question/type/numerical/questiontype.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ function delete_question($questionid) {


function compare_responses(&$question, $state, $teststate) {

if ($question->options->showunits == NUMERICALQUESTIONUNITMULTICHOICEDISPLAY && isset($question->options->units) && isset($question->options->units[$state->responses['unit']] )){
$state->responses['unit']=$question->options->units[$state->responses['unit']]->unit;
};
Expand Down Expand Up @@ -451,9 +452,9 @@ function test_response(&$question, &$state, $answer) {
* for NUMERICALQUESTIONUNITTEXTDISPLAY and NUMERICALQUESTIONUNITNODISPLAY
*
*/
// echo "<p> test1 response response answer $answer->answer numerical state <pre>";print_r($state);echo "</pre></p>";
if ( ($question->options->showunits == NUMERICALQUESTIONUNITMULTICHOICEDISPLAY ||
$question->options->showunits == NUMERICALQUESTIONUNITTEXTINPUTDISPLAY ) &&
$question->options->showunits == NUMERICALQUESTIONUNITTEXTINPUTDISPLAY ||
$question->options->showunits == NUMERICALQUESTIONUNITTEXTDISPLAY ) &&
isset($state->responses['unit']) ){
$state->responses['']= $state->responses['answer'].$state->responses['unit'] ;

Expand All @@ -463,8 +464,6 @@ function test_response(&$question, &$state, $answer) {
}

$response = $this->apply_unit($state->responses[''], $question->options->units);
// echo "<p> test response $response answer $answer->answer numerical state <pre>";print_r($state);echo "</pre></p>";
// echo "<p> test response $response answer $answer->answer numerical state <pre>";print_r($question->options->units);echo "</pre></p>";

if ($response === false) {
return false; // The student did not type a number.
Expand Down Expand Up @@ -512,14 +511,16 @@ function grade_responses(&$question, &$state, $cmoptions) {
}
}
// in all cases the unit should be tested
if( $question->options->showunits == NUMERICALQUESTIONUNITNODISPLAY ) {
$this->valid_numerical_unit == true ;
if( $question->options->showunits == NUMERICALQUESTIONUNITNODISPLAY ||
$question->options->showunits == NUMERICALQUESTIONUNITTEXTDISPLAY ) {
$this->valid_numerical_unit = true ;
}else {
$this->valid_numerical_unit = $this->valid_unit($state->responses[''], $question->options->units);
}
// apply unit penalty
$this->raw_unitpenalty = 0 ;
if(!empty($question->options->unitpenalty)&& !$this->valid_numerical_unit ){
if(!empty($question->options->unitpenalty)&& $this->valid_numerical_unit != true ){

if($question->options->unitgradingtype == 1){
$this->raw_unitpenalty = $question->options->unitpenalty * $state->raw_grade ;
}else {
Expand Down Expand Up @@ -670,12 +671,10 @@ function apply_unit($rawresponse, $units) {
$replace = array('', '.');
}
$rawresponse = str_replace($search, $replace, $rawresponse);
// echo "<p> apply_unit rawresponse $rawresponse answer answer->answer numerical state <pre>";print_r($units);echo "</pre></p>";

// Apply any unit that is present.
if (preg_match('~^([+-]?([0-9]+(\\.[0-9]*)?|\\.[0-9]+)([eE][-+]?[0-9]+)?)([^0-9].*)?$~',
$rawresponse, $responseparts)) {
// echo "<p> test response $rawresponse answer answer->answer numerical responseparts <pre>";print_r($responseparts);echo "</pre></p>";

if (!empty($responseparts[5])) {

Expand Down

0 comments on commit aa384ad

Please sign in to comment.