/**
  * This is a copy of the history function in the question renderer class
  * Since the access to that function is protected I cannot access it outside of the renderer class.
  *
  * There are a few changes to this function to facilitate simpler use
  *
  * @param \question_attempt $qa
  * @return string
  */
 public function question_attempt_history($qa)
 {
     $table = new \html_table();
     $table->head = array(get_string('step', 'question'), get_string('time'), get_string('action', 'question'));
     foreach ($qa->get_full_step_iterator() as $i => $step) {
         $stepno = $i + 1;
         $rowclass = '';
         if ($stepno == $qa->get_num_steps()) {
             $rowclass = 'current';
         }
         $user = new \stdClass();
         $user->id = $step->get_user_id();
         $row = array($stepno, userdate($step->get_timecreated(), get_string('strftimedatetimeshort')), s($qa->summarise_action($step)));
         $table->rowclasses[] = $rowclass;
         $table->data[] = $row;
     }
     return \html_writer::tag('h4', get_string('responsehistory', 'question'), array('class' => 'responsehistoryheader')) . \html_writer::tag('div', \html_writer::table($table, true), array('class' => 'responsehistoryheader'));
 }
Esempio n. 2
0
 /**
  * Generate the display of the response history part of the question. This
  * is the table showing all the steps the question has been through.
  *
  * @param question_attempt $qa the question attempt to display.
  * @param qbehaviour_renderer $behaviouroutput the renderer to output the behaviour
  *      specific parts.
  * @param qtype_renderer $qtoutput the renderer to output the question type
  *      specific parts.
  * @param question_display_options $options controls what should and should not be displayed.
  * @return HTML fragment.
  */
 protected function response_history(question_attempt $qa, qbehaviour_renderer $behaviouroutput, qtype_renderer $qtoutput, question_display_options $options)
 {
     if (!$options->history) {
         return '';
     }
     $table = new html_table();
     $table->head = array(get_string('step', 'question'), get_string('time'), get_string('action', 'question'), get_string('state', 'question'));
     if ($options->marks >= question_display_options::MARK_AND_MAX) {
         $table->head[] = get_string('marks', 'question');
     }
     foreach ($qa->get_full_step_iterator() as $i => $step) {
         $stepno = $i + 1;
         $rowclass = '';
         if ($stepno == $qa->get_num_steps()) {
             $rowclass = 'current';
         } else {
             if (!empty($options->questionreviewlink)) {
                 $url = new moodle_url($options->questionreviewlink, array('slot' => $qa->get_slot(), 'step' => $i));
                 $stepno = $this->output->action_link($url, $stepno, new popup_action('click', $url, 'reviewquestion', array('width' => 450, 'height' => 650)), array('title' => get_string('reviewresponse', 'question')));
             }
         }
         $restrictedqa = new question_attempt_with_restricted_history($qa, $i, null);
         $user = new stdClass();
         $user->id = $step->get_user_id();
         $row = array($stepno, userdate($step->get_timecreated(), get_string('strftimedatetimeshort')), s($qa->summarise_action($step)), $restrictedqa->get_state_string($options->correctness));
         if ($options->marks >= question_display_options::MARK_AND_MAX) {
             $row[] = $qa->format_fraction_as_mark($step->get_fraction(), $options->markdp);
         }
         $table->rowclasses[] = $rowclass;
         $table->data[] = $row;
     }
     return html_writer::tag('h4', get_string('responsehistory', 'question'), array('class' => 'responsehistoryheader')) . $options->extrahistorycontent . html_writer::tag('div', html_writer::table($table, true), array('class' => 'responsehistoryheader'));
 }
 /**
  * Create a question_attempt_with_restricted_history
  * @param question_attempt $baseqa The question_attempt to make a restricted version of.
  * @param int $lastseq the index of the last step to include.
  * @param string $preferredbehaviour the preferred behaviour. It is slightly
  *      annoyting that this needs to be passed, but unavoidable for now.
  */
 public function __construct(question_attempt $baseqa, $lastseq, $preferredbehaviour)
 {
     if ($lastseq < 0 || $lastseq >= $baseqa->get_num_steps()) {
         throw new coding_exception('$seq out of range', $seq);
     }
     $this->baseqa = $baseqa;
     $this->steps = array_slice($baseqa->steps, 0, $lastseq + 1);
     $this->observer = new question_usage_null_observer();
     // This should be a straight copy of all the remaining fields.
     $this->id = $baseqa->id;
     $this->usageid = $baseqa->usageid;
     $this->slot = $baseqa->slot;
     $this->question = $baseqa->question;
     $this->maxmark = $baseqa->maxmark;
     $this->minfraction = $baseqa->minfraction;
     $this->questionsummary = $baseqa->questionsummary;
     $this->responsesummary = $baseqa->responsesummary;
     $this->rightanswer = $baseqa->rightanswer;
     $this->flagged = $baseqa->flagged;
     // Except behaviour, where we need to create a new one.
     $this->behaviour = question_engine::make_behaviour($baseqa->get_behaviour_name(), $this, $preferredbehaviour);
 }