示例#1
0
 protected function adjusted_fraction($fraction, $prevtries)
 {
     if (!isset($this->question->penaltyregime) || $this->question->penaltyregime === '') {
         return parent::adjusted_fraction($fraction, $prevtries);
     } else {
         if ($prevtries == 0) {
             return $fraction;
         } else {
             $penalties = explode(",", $this->question->penaltyregime);
             $n = count($penalties);
             if (trim($penalties[$n - 1]) === '...') {
                 $delta = floatval($penalties[$n - 2]) - floatval($penalties[$n - 3]);
                 $penalties[$n - 1] = min(100, $penalties[$n - 2] + $delta);
                 while ($penalties[$n - 1] < 100) {
                     $penalties[] = min(100, $penalties[$n - 1] + $delta);
                     $n++;
                 }
             }
             $i = min($n - 1, $prevtries - 1);
             $penalty = floatval($penalties[$i]) / 100.0;
             return $fraction - $penalty;
         }
     }
 }
 protected function adjusted_fraction($fraction, $prevtries)
 {
     $numprechecks = $this->qa->get_last_behaviour_var('_numprechecks', 0);
     $prevtries -= $numprechecks;
     // Deduct prechecks from tries.
     if (!isset($this->question->penaltyregime) || $this->question->penaltyregime === '') {
         return parent::adjusted_fraction($fraction, $prevtries);
     } else {
         if ($prevtries == 0) {
             return $fraction;
         } else {
             $penalties = explode(",", $this->question->penaltyregime);
             $n = count($penalties);
             if (trim($penalties[$n - 1]) === '...') {
                 $delta = floatval($penalties[$n - 2]) - floatval($penalties[$n - 3]);
                 $penalties[$n - 1] = min(100, $penalties[$n - 2] + $delta);
                 while ($penalties[$n - 1] < 100) {
                     $penalties[] = min(100, $penalties[$n - 1] + $delta);
                     $n++;
                 }
             }
             $i = min($n - 1, $prevtries - 1);
             $penalty = floatval($penalties[$i]) / 100.0;
             return $fraction - $penalty;
         }
     }
 }