Exemple #1
1
 public function controls(question_attempt $qa, question_display_options $options)
 {
     if ($options->readonly || $qa->get_state() != question_state::$todo) {
         return '';
     }
     // Hidden input to move the question into the complete state.
     return html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $qa->get_behaviour_field_name('seen'), 'value' => 1));
 }
Exemple #2
0
    public function feedback(question_attempt $qa, question_display_options $options) {
        if (!$options->feedback) {
            return '';
        }

        if ($qa->get_state() == question_state::$gaveup || $qa->get_state() ==
                question_state::$mangaveup) {
            return '';
        }

        $feedback = '';
        if (!$qa->get_last_behaviour_var('certainty') &&
                $qa->get_last_behaviour_var('_assumedcertainty')) {
            $feedback .= html_writer::tag('p',
                    get_string('assumingcertainty', 'qbehaviour_deferredcbm',
                    question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty'))));
        }

        if ($options->marks >= question_display_options::MARK_AND_MAX) {
            $a = new stdClass();
            $a->rawmark = format_float($qa->get_last_behaviour_var('_rawfraction') *
                    $qa->get_max_mark(), $options->markdp);
            $a->mark = $qa->format_mark($options->markdp);
            $feedback .= html_writer::tag('p',
                    get_string('markadjustment', 'qbehaviour_deferredcbm', $a));
        }

        return $feedback;
    }
Exemple #3
0
 public function feedback(question_attempt $qa, question_display_options $options)
 {
     if (!$options->feedback) {
         return '';
     }
     if ($qa->get_state() == question_state::$gaveup || $qa->get_state() == question_state::$mangaveup) {
         return '';
     }
     $feedback = '';
     if (!$qa->get_last_behaviour_var('certainty') && $qa->get_last_behaviour_var('_assumedcertainty')) {
         $feedback .= html_writer::tag('p', get_string('assumingcertainty', 'qbehaviour_deferredcbm', question_cbm::get_string($qa->get_last_behaviour_var('_assumedcertainty'))));
     }
     return $feedback;
 }
Exemple #4
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);
 }
Exemple #5
0
 public function feedback(question_attempt $qa, question_display_options $options)
 {
     if (!$qa->get_state()->is_active() || !$options->readonly) {
         return '';
     }
     $attributes = array('type' => 'submit', 'id' => $qa->get_behaviour_field_name('tryagain'), 'name' => $qa->get_behaviour_field_name('tryagain'), 'value' => get_string('tryagain', 'qbehaviour_interactive'), 'class' => 'submit btn');
     if ($options->readonly !== qbehaviour_interactive::READONLY_EXCEPT_TRY_AGAIN) {
         $attributes['disabled'] = 'disabled';
     }
     $output = html_writer::empty_tag('input', $attributes);
     if (empty($attributes['disabled'])) {
         $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', array($attributes['id'], $qa->get_slot()));
     }
     return $output;
 }
 /**
  * Construct the HTML for the optional 'precheck' button, which triggers
  * a partial submit in which no penalties are imposed but only the
  * 'Use as example' test cases are run.
  * This code is identical to the 'submit_button' code in
  * qbehaviour_renderer::submit_button except for the id and name of the
  * button.
  */
 protected function precheck_button(question_attempt $qa, question_display_options $options)
 {
     if (!$qa->get_state()->is_active()) {
         return '';
         // Not sure if this can happen, but the submit button does it.
     }
     $attributes = array('type' => 'submit', 'id' => $qa->get_behaviour_field_name('precheck'), 'name' => $qa->get_behaviour_field_name('precheck'), 'value' => get_string('precheck', 'qbehaviour_adaptive_adapted_for_coderunner'), 'class' => 'submit btn');
     if ($options->readonly) {
         $attributes['disabled'] = 'disabled';
     }
     $output = html_writer::empty_tag('input', $attributes);
     if (!$options->readonly) {
         $this->page->requires->js_init_call('M.core_question_engine.init_submit_button', array($attributes['id'], $qa->get_slot()));
     }
     return $output;
 }
 public function correct_response(question_attempt $qa)
 {
     if ($qa->get_state()->is_correct()) {
         // The answer was correct so we don't need to do anything further.
         return '';
     }
     $question = $qa->get_question();
     $stemorder = $question->get_stem_order();
     $choices = $this->format_choices($qa, true);
     $table = new html_table();
     $table->attributes['class'] = 'generaltable correctanswertable';
     $table->size = array('50%', '50%');
     foreach ($stemorder as $key => $stemid) {
         $row = new html_table_row();
         $row->cells[] = $question->format_text($question->stems[$stemid], $question->stemformat[$stemid], $qa, 'qtype_ddmatch', 'subquestion', $stemid);
         $row->cells[] = $choices[$question->get_right_choice_for($stemid)];
         $table->data[] = $row;
     }
     return get_string('correctansweris', 'qtype_match', html_writer::table($table));
 }
 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;
 }
Exemple #9
0
 protected function get_state_string(question_attempt $qa, $showcorrectness)
 {
     if ($qa->get_question()->length > 0) {
         return $qa->get_state_string($showcorrectness);
     }
     // Special case handling for 'information' items.
     if ($qa->get_state() == question_state::$todo) {
         return get_string('notyetviewed', 'quiz');
     } else {
         return get_string('viewed', 'quiz');
     }
 }
 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;
 }
Exemple #11
0
    /**
     * Check a request for access to a file belonging to a combined feedback field.
     * @param question_attempt $qa the question attempt being displayed.
     * @param question_display_options $options the options that control display of the question.
     * @param string $filearea the name of the file area.
     * @return bool whether access to the file should be allowed.
     */
    protected function check_combined_feedback_file_access($qa, $options, $filearea) {
        $state = $qa->get_state();

        if (!$state->is_finished()) {
            $response = $qa->get_last_qt_data();
            if (!$this->is_gradable_response($response)) {
                return false;
            }
            list($notused, $state) = $this->grade_response($response);
        }

        return $options->feedback && $state->get_feedback_class() . 'feedback' == $filearea;
    }
 protected function combined_feedback(question_attempt $qa)
 {
     $question = $qa->get_question();
     $state = $qa->get_state();
     if (!$state->is_finished()) {
         $response = $qa->get_last_qt_data();
         if (!$qa->get_question()->is_gradable_response($response)) {
             return '';
         }
         list($notused, $state) = $qa->get_question()->grade_response($response);
     }
     $feedback = '';
     $field = $state->get_feedback_class() . 'feedback';
     $format = $state->get_feedback_class() . 'feedbackformat';
     if ($question->{$field}) {
         $feedback .= $question->format_text($question->{$field}, $question->{$format}, $qa, 'question', $field, $question->id);
     }
     return $feedback;
 }
 public function correct_response(question_attempt $qa)
 {
     if ($qa->get_state()->is_correct()) {
         return '';
     }
     $question = $qa->get_question();
     $choices = $question->get_choice_order();
     if (count($choices)) {
         $table = new html_table();
         $table->attributes['class'] = 'generaltable correctanswertable';
         foreach ($choices as $key => $subqid) {
             $table->data[][] = $question->format_text($question->stems[$subqid], $question->stemformat[$subqid], $qa, 'qtype_order', 'subquestion', $subqid);
         }
         return get_string('correctansweris', 'qtype_match', html_writer::table($table));
     }
     return '';
 }
 /**
  * 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;
 }
 /**
  * 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)
 {
     if (!$qa->get_question()->penalty) {
         return '';
     }
     $output = '';
     // print details of grade adjustment due to penalties
     if ($mark->raw != $mark->cur) {
         $output .= ' ' . get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark);
     }
     // print info about new penalty
     // penalty is relevant only if the answer is not correct and further attempts are possible
     if (!$qa->get_state()->is_finished()) {
         $output .= ' ' . get_string('gradingdetailspenalty', 'qbehaviour_adaptive', format_float($qa->get_question()->penalty, $options->markdp));
     }
     return $output;
 }
 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;
     }
 }