示例#1
0
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $responseoutput = $question->get_format_renderer($this->page);
     // Answer field.
     $step = $qa->get_last_step_with_qt_var('answer');
     if (empty($options->readonly)) {
         $answer = $responseoutput->response_area_input('answer', $qa, $step, $question->responsefieldlines, $options->context);
     } else {
         $answer = $responseoutput->response_area_read_only('answer', $qa, $step, $question->responsefieldlines, $options->context);
     }
     $files = '';
     if ($question->attachments) {
         if (empty($options->readonly)) {
             $files = $this->files_input($qa, $question->attachments, $options);
         } else {
             $files = $this->files_read_only($qa, $options);
         }
     }
     $result = '';
     $result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));
     $result .= html_writer::start_tag('div', array('class' => 'ablock'));
     $result .= html_writer::tag('div', $answer, array('class' => 'answer'));
     $result .= html_writer::tag('div', $files, array('class' => 'attachments'));
     $result .= html_writer::end_tag('div');
     return $result;
 }
示例#2
0
 /**
  * Generates the web-side when te student is attempting the question. This is the side which is showed with the
  * question text and the response field
  */
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     global $DB;
     $question = $qa->get_question();
     $responseoutput = $question->get_format_renderer($this->page);
     // Answer field.
     $step = $qa->get_last_step_with_qt_var('answer');
     // Get the question options to show the question text
     $question->options = $DB->get_record('qtype_javaunittest_options', array('questionid' => $question->id));
     $studentscode = $question->options->givencode;
     if (empty($options->readonly)) {
         $answer = $responseoutput->response_area_input('answer', $qa, $step, $question->responsefieldlines, $options->context, $studentscode);
     } else {
         $answer = $responseoutput->response_area_read_only('answer', $qa, $step, $question->responsefieldlines, $options->context, $studentscode);
     }
     // Generate the html code which will be showed
     $result = '';
     $result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));
     $result .= html_writer::start_tag('div', array('class' => 'ablock'));
     $result .= html_writer::tag('div', $answer, array('class' => 'answer'));
     $result .= html_writer::end_tag('div');
     return $result;
 }
 /**
  *
  *
  * @param array                              $answers The overall answers array that handles the count of answers
  * @param \question_attempt                  $qa
  * @param \qtype_multichoice_single_question $questiondef
  *
  */
 protected function update_answers_single(&$answers, $qa, $questiondef)
 {
     // get the latest step that has an answer
     $lastanswerstep = $qa->get_last_step_with_qt_var('answer');
     if ($lastanswerstep->has_qt_var('answer')) {
         // may not as if the step doesn't exist get last step will return empty read only step
         // get the student answer from the last answer step
         // along with the answers within the
         $answerorder = $questiondef->get_order($qa);
         $response = $lastanswerstep->get_qt_data();
         // make sure the response answer actually exists in the order
         if (array_key_exists($response['answer'], $answerorder)) {
             $studentanswer = $questiondef->answers[$answerorder[$response['answer']]];
             // update the count of the answerid on the answers array
             if (isset($answers[$studentanswer->id])) {
                 $current = (int) $answers[$studentanswer->id];
                 $answers[$studentanswer->id] = $current + 1;
             } else {
                 $answers[$studentanswer->id] = 1;
             }
         }
     }
 }