Example #1
0
 /**
  * Generates the specific feedback from the database when the attempt is finished and the question is answered.
  */
 public function specific_feedback(question_attempt $qa)
 {
     global $DB, $CFG;
     // get feedback from the database
     $record = $DB->get_record('qtype_javaunittest_feedback', array('questionattemptid' => $qa->get_database_id()), 'feedback');
     if ($record === false) {
         return '';
     }
     $feedback = $record->feedback;
     $question = $qa->get_question();
     return $question->format_text($feedback, 0, $qa, 'question', 'answerfeedback', 1);
 }
Example #2
0
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $response = $qa->get_last_qt_data();
     $questiontext = $question->questiontextinstantiated;
     // Replace inputs.
     $inputstovaldiate = array();
     $qaid = null;
     foreach ($question->inputs as $name => $input) {
         $fieldname = $qa->get_qt_field_name($name);
         $state = $question->get_input_state($name, $response);
         $questiontext = str_replace("[[input:{$name}]]", $input->render($state, $fieldname, $options->readonly), $questiontext);
         $feedback = $this->input_validation($fieldname . '_val', $input->render_validation($state, $fieldname));
         $questiontext = str_replace("[[validation:{$name}]]", $feedback, $questiontext);
         $qaid = $qa->get_database_id();
         if ($input->requires_validation()) {
             $inputstovaldiate[] = $name;
         }
     }
     // Replace PRTs.
     foreach ($question->prts as $index => $prt) {
         $feedback = '';
         if ($options->feedback) {
             $feedback = $this->prt_feedback($index, $response, $qa, $options, true);
         } else {
             if (in_array($qa->get_behaviour_name(), array('interactivecountback', 'adaptivemulipart'))) {
                 // The behaviour name test here is a hack. The trouble is that interactive
                 // behaviour or adaptivemulipart does not show feedback if the input
                 // is invalid, but we want to show the CAS errors from the PRT.
                 $result = $question->get_prt_result($index, $response, $qa->get_state()->is_finished());
                 $feedback = html_writer::nonempty_tag('div', $result->errors, array('class' => 'stackprtfeedback stackprtfeedback-' . $name));
             }
         }
         $questiontext = str_replace("[[feedback:{$index}]]", $feedback, $questiontext);
     }
     // Now format the questiontext.  This should be done after the subsitutions of inputs and PRTs.
     $questiontext = $question->format_text(stack_maths::process_display_castext($questiontext, $this), $question->questiontextformat, $qa, 'question', 'questiontext', $question->id);
     // Initialise automatic validation, if enabled.
     if ($qaid && stack_utils::get_config()->ajaxvalidation) {
         $this->page->requires->yui_module('moodle-qtype_stack-input', 'M.qtype_stack.init_inputs', array($inputstovaldiate, $qaid, $qa->get_field_prefix()));
     }
     $result = '';
     $result .= $this->question_tests_link($question, $options) . $questiontext;
     if ($qa->get_state() == question_state::$invalid) {
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error($response), array('class' => 'validationerror'));
     }
     return $result;
 }
Example #3
0
 public function notify_step_modified(question_attempt_step $step, question_attempt $qa, $seq)
 {
     if (array_key_exists($qa->get_slot(), $this->attemptsadded)) {
         return;
     }
     if (($key = $this->is_step_added($step)) !== false) {
         return;
     }
     if (($key = $this->is_step_deleted($step)) !== false) {
         throw new coding_exception('Cannot modify a step after it has been deleted.');
     }
     $stepid = $step->get_id();
     if (empty($stepid)) {
         throw new coding_exception('Cannot modify a step that has never been stored in the database.');
     }
     $this->stepsmodified[] = array($step, $qa->get_database_id(), $seq);
 }
Example #4
0
 /**
  * Get the postdata that needs to be sent to question/toggleflag.php to change the flag state.
  * You need to append &newstate=0/1 to this.
  * @return the post data to send.
  */
 public static function get_postdata(question_attempt $qa)
 {
     $qaid = $qa->get_database_id();
     $qubaid = $qa->get_usage_id();
     $qid = $qa->get_question()->id;
     $slot = $qa->get_slot();
     $checksum = self::get_toggle_checksum($qubaid, $qid, $qaid, $slot);
     return "qaid={$qaid}&qubaid={$qubaid}&qid={$qid}&slot={$slot}&checksum={$checksum}&sesskey=" . sesskey() . '&newstate=';
 }
 private static function to_unique_identifier(question_attempt $qa, $identifier)
 {
     return $identifier . "-" . $qa->get_database_id();
 }
 public function notify_step_added(question_attempt_step $step, question_attempt $qa, $seq)
 {
     if (array_key_exists($qa->get_slot(), $this->attemptsadded)) {
         return;
     }
     $this->stepsadded[] = array($step, $qa->get_database_id(), $seq);
 }