Exemplo n.º 1
0
 /**
  * exitoptions
  *
  * @param xxx $hotpot
  * @return xxx
  */
 public function exitfeedback($hotpot)
 {
     global $CFG;
     $percentsign = '%';
     $feedback = array();
     if ($hotpot->gradeweighting == 0) {
         if ($hotpot->exitoptions & hotpot::EXITOPTIONS_ATTEMPTSCORE || $hotpot->exitoptions & hotpot::EXITOPTIONS_HOTPOTGRADE) {
             $text = get_string('exit_noscore', 'hotpot');
             $feedback[] = html_writer::tag('li', $text);
         }
     } else {
         if ($hotpot->get_gradeitem() && $hotpot->get_attempt()) {
             if ($hotpot->exitoptions & hotpot::EXITOPTIONS_ENCOURAGEMENT) {
                 switch (true) {
                     case $hotpot->attempt->score >= 90:
                         $text = get_string('exit_excellent', 'hotpot');
                         break;
                     case $hotpot->attempt->score >= 60:
                         $text = get_string('exit_welldone', 'hotpot');
                         break;
                     case $hotpot->attempt->score > 0:
                         $text = get_string('exit_goodtry', 'hotpot');
                         break;
                     default:
                         $text = get_string('exit_areyouok', 'hotpot');
                 }
                 $feedback[] = html_writer::tag('li', $text, array('class' => 'hotpotexitencouragement'));
             }
             if ($hotpot->exitoptions & hotpot::EXITOPTIONS_ATTEMPTSCORE) {
                 $text = get_string('exit_attemptscore', 'hotpot', $hotpot->attempt->score . $percentsign);
                 $feedback[] = html_writer::tag('li', $text);
             }
             if ($hotpot->exitoptions & hotpot::EXITOPTIONS_HOTPOTGRADE) {
                 switch ($hotpot->grademethod) {
                     case hotpot::GRADEMETHOD_HIGHEST:
                         if ($hotpot->attempt->score < $hotpot->gradeitem->percent) {
                             // current attempt is less than the highest so far
                             $text = get_string('exit_hotpotgrade_highest', 'hotpot', $hotpot->gradeitem->percent . $percentsign);
                             $feedback[] = html_writer::tag('li', $text);
                         } else {
                             if ($hotpot->attempt->score == 0) {
                                 // zero score is best so far
                                 $text = get_string('exit_hotpotgrade_highest_zero', 'hotpot', $hotpot->attempt->score . $percentsign);
                                 $feedback[] = html_writer::tag('li', $text);
                             } else {
                                 if ($hotpot->get_attempts()) {
                                     // current attempt is highest so far
                                     $maxscore = null;
                                     foreach ($hotpot->attempts as $attempt) {
                                         if ($attempt->id == $hotpot->attempt->id) {
                                             continue;
                                             // skip current attempt
                                         }
                                         if (is_null($maxscore) || $maxscore < $attempt->score) {
                                             $maxscore = $attempt->score;
                                         }
                                     }
                                     if (is_null($maxscore)) {
                                         // do nothing (no previous attempt)
                                     } else {
                                         if ($maxscore == $hotpot->attempt->score) {
                                             // attempt grade equals previous best
                                             $text = get_string('exit_hotpotgrade_highest_equal', 'hotpot');
                                             $feedback[] = html_writer::tag('li', $text);
                                         } else {
                                             $text = get_string('exit_hotpotgrade_highest_previous', 'hotpot', $maxscore . $percentsign);
                                             $feedback[] = html_writer::tag('li', $text);
                                         }
                                     }
                                 } else {
                                     die('oops, no attempts');
                                 }
                             }
                         }
                         break;
                     case hotpot::GRADEMETHOD_AVERAGE:
                         $text = get_string('exit_hotpotgrade_average', 'hotpot', $hotpot->gradeitem->percent . $percentsign);
                         $feedback[] = html_writer::tag('li', $text);
                         break;
                         // case hotpot::GRADEMETHOD_TOTAL:
                         // case hotpot::GRADEMETHOD_FIRST:
                         // case hotpot::GRADEMETHOD_LAST:
                     // case hotpot::GRADEMETHOD_TOTAL:
                     // case hotpot::GRADEMETHOD_FIRST:
                     // case hotpot::GRADEMETHOD_LAST:
                     default:
                         $text = get_string('exit_hotpotgrade', 'hotpot', $hotpot->gradeitem->percent . $percentsign);
                         $feedback[] = html_writer::tag('li', $text);
                         break;
                 }
             }
         }
     }
     if (count($feedback)) {
         $feedback = html_writer::tag('ul', implode('', $feedback), array('class' => 'hotpotexitfeedback'));
         return $this->box($feedback);
     } else {
         return '';
     }
 }