Ejemplo n.º 1
0
 public function feedback(question_attempt $qa, question_display_options $options)
 {
     // If the latest answer was invalid, display an informative message.
     if ($qa->get_state() == question_state::$invalid) {
         return html_writer::nonempty_tag('div', $this->disregarded_info(), array('class' => 'gradingdetails'));
     }
     // Otherwise get the details.
     return $this->render_adaptive_marks($qa->get_behaviour()->get_adaptive_marks(), $options);
 }
 public function feedback(question_attempt $qa, question_display_options $options)
 {
     // Try to find the last graded step.
     $isstateimprovable = $qa->get_behaviour()->is_state_improvable($qa->get_state());
     $gradedstep = $this->get_graded_step($qa);
     if ($gradedstep) {
         if ($gradedstep->has_behaviour_var('_helps')) {
             return $this->extra_help($qa, $options);
         }
     }
     if (is_null($gradedstep) || $qa->get_max_mark() == 0 || $options->marks < question_display_options::MARK_AND_MAX) {
         return '';
     }
     // Display the grading details from the last graded state
     $mark = new stdClass();
     $mark->max = $qa->format_max_mark($options->markdp);
     $actualmark = $gradedstep->get_fraction() * $qa->get_max_mark();
     $mark->cur = format_float($actualmark, $options->markdp);
     $rawmark = $gradedstep->get_behaviour_var('_rawfraction') * $qa->get_max_mark();
     $mark->raw = format_float($rawmark, $options->markdp);
     // let student know wether the answer was correct
     if ($qa->get_state()->is_commented()) {
         $class = $qa->get_state()->get_feedback_class();
     } else {
         $class = question_state::graded_state_for_fraction($gradedstep->get_behaviour_var('_rawfraction'))->get_feedback_class();
     }
     $gradingdetails = get_string('gradingdetails', 'qbehaviour_adaptive', $mark);
     $penalty = $qa->get_question()->penalty;
     if ($penalty != 0) {
         $gradingdetails .= $this->penalty_info($qa, $mark, $options);
     }
     $output = '';
     $output .= html_writer::tag('div', get_string($class, 'question'), array('class' => 'correctness ' . $class));
     $output .= html_writer::tag('div', $gradingdetails, array('class' => 'gradingdetails'));
     $nbtries = $gradedstep->get_behaviour_var('_try');
     if ($nbtries && $isstateimprovable) {
         $totalpenalties = $qa->get_behaviour()->get_help_penalty($nbtries * $penalty, $options->markdp, 'totalpenalties');
         $output .= $totalpenalties;
     }
     return $output;
 }
 protected function penalty_info(question_attempt $qa, $mark, question_display_options $options)
 {
     if (!$qa->get_question()->penalty && !$qa->get_last_behaviour_var('_hashint', false)) {
         // No penalty for the attempts and no hinting done.
         return '';
     }
     $output = '';
     // Print details of grade adjustment due to penalties.
     if ($mark->raw != $mark->cur) {
         $output .= ' ' . get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark);
     }
     // Print information about any new penalty, only relevant if the answer can be improved.
     if ($qa->get_behaviour()->is_state_improvable($qa->get_state())) {
         $output .= ' ' . get_string('gradingdetailspenalty', 'qbehaviour_adaptive', format_float($qa->get_last_step()->get_behaviour_var('_penalty'), $options->markdp));
     }
     return $output;
 }
Ejemplo n.º 4
0
 public function manual_comment_view(question_attempt $qa, question_display_options $options)
 {
     $output = '';
     if ($qa->has_manual_comment()) {
         $output .= get_string('commentx', 'question', $qa->get_behaviour()->format_comment());
     }
     if ($options->manualcommentlink) {
         $url = new moodle_url($options->manualcommentlink, array('slot' => $qa->get_slot()));
         $link = $this->output->action_link($url, get_string('commentormark', 'question'), new popup_action('click', $url, 'commentquestion', array('width' => 600, 'height' => 800)));
         $output .= html_writer::tag('div', $link, array('class' => 'commentlink'));
     }
     return $output;
 }
Ejemplo n.º 5
0
 /**
  * Actually generate the display of the PRT feedback.
  * @param string $name the PRT name.
  * @param question_attempt $qa the question attempt to display.
  * @param question_definition $question the question being displayed.
  * @param stack_potentialresponse_tree_state $result the results to display.
  * @param question_display_options $options controls what should and should not be displayed.
  * @return string nicely formatted feedback, for display.
  */
 protected function prt_feedback_display($name, question_attempt $qa, question_definition $question, stack_potentialresponse_tree_state $result, question_display_options $options, $includestandardfeedback)
 {
     $err = '';
     if ($result->errors) {
         $err = $result->errors;
     }
     $feedback = '';
     $feedbackbits = $result->get_feedback();
     if ($feedbackbits) {
         $feedback = array();
         $format = null;
         foreach ($feedbackbits as $bit) {
             $feedback[] = $qa->rewrite_pluginfile_urls($bit->feedback, 'qtype_stack', $bit->filearea, $bit->itemid);
             if (!is_null($bit->format)) {
                 if (is_null($format)) {
                     $format = $bit->format;
                 }
                 if ($bit->format != $format) {
                     throw new coding_exception('Inconsistent feedback formats found in PRT ' . $name);
                 }
             }
         }
         if (is_null($format)) {
             $format = FORMAT_HTML;
         }
         $feedback = $result->substitue_variables_in_feedback(implode(' ', $feedback));
         $feedback = format_text(stack_maths::process_display_castext($feedback, $this), $format, array('noclean' => true, 'para' => false));
     }
     $gradingdetails = '';
     if (!$result->errors && $qa->get_behaviour_name() == 'adaptivemultipart') {
         // This is rather a hack, but it will probably work.
         $renderer = $this->page->get_renderer('qbehaviour_adaptivemultipart');
         $gradingdetails = $renderer->render_adaptive_marks($qa->get_behaviour()->get_part_mark_details($name), $options);
     }
     if ($includestandardfeedback) {
         $standardfeedback = $this->standard_prt_feedback($qa, $question, $result);
     } else {
         $standardfeedback = '';
     }
     return html_writer::nonempty_tag('div', $standardfeedback . $err . $feedback . $gradingdetails, array('class' => 'stackprtfeedback stackprtfeedback-' . $name));
 }
Ejemplo n.º 6
0
 /**
  * Display the information about the penalty calculations.
  * @param question_attempt $qa the question attempt.
  * @param object $mark contains information about the current mark.
  * @param question_display_options $options display options.
  */
 protected function penalty_info(question_attempt $qa, $mark, question_display_options $options)
 {
     $currentpenalty = $qa->get_question()->penalty * $qa->get_max_mark();
     $totalpenalty = $currentpenalty * $qa->get_last_behaviour_var('_try', 0);
     if ($currentpenalty == 0) {
         return '';
     }
     $output = '';
     // Print details of grade adjustment due to penalties
     if ($mark->raw != $mark->cur) {
         $output .= ' ' . get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark);
     }
     // Print information about any new penalty, only relevant if the answer can be improved.
     if ($qa->get_behaviour()->is_state_improvable($qa->get_state())) {
         $output .= ' ' . get_string('gradingdetailspenalty', 'qbehaviour_adaptive', format_float($currentpenalty, $options->markdp));
         // Print information about total penalties so far, if larger than current penalty.
         if ($totalpenalty > $currentpenalty) {
             $output .= ' ' . get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive', format_float($totalpenalty, $options->markdp));
         }
     }
     return $output;
 }
Ejemplo n.º 7
0
 public function specific_feedback(question_attempt $qa)
 {
     $question = $qa->get_question();
     $currentanswer = remove_blanks($qa->get_last_qt_var('answer'));
     $ispreview = false;
     $completemessage = '';
     $closestcomplete = false;
     foreach ($qa->get_reverse_step_iterator() as $step) {
         $hintadded = $step->has_behaviour_var('_helps') === true;
         break;
     }
     $closest = $question->closest;
     if ($hintadded) {
         // hint added one letter or hint added letter and answer is complete
         $answer = $question->get_matching_answer(array('answer' => $closest[0]));
         // help has added letter OR word and answer is complete
         $isstateimprovable = $qa->get_behaviour()->is_state_improvable($qa->get_state());
         if ($closest[2] == 'complete' && $isstateimprovable) {
             $closestcomplete = true;
             $class = '"correctness correct"';
             $completemessage = '<div class=' . $class . '>' . get_string("clicktosubmit", "qtype_regexp") . '</div>';
         }
     } else {
         $answer = $question->get_matching_answer(array('answer' => $qa->get_last_qt_var('answer')));
     }
     if ($closest[3]) {
         $closest[3] = '[' . $closest[3] . ']';
         // rest of submitted answer, in red
     }
     $f = '';
     // student's response with corrections to be displayed in feedback div
     $f = '<span style="color:#0000FF;">' . $closest[1] . '<strong>' . $closest[4] . '</strong></span> ' . $closest[3];
     // color blue for correct words/letters
     if ($answer && $answer->feedback || $closestcomplete == true) {
         return $question->format_text($f . $answer->feedback . $completemessage, $answer->feedbackformat, $qa, 'question', 'answerfeedback', $answer->id);
     } else {
         return $f;
     }
 }