/** * Create a question_attempt_step from records loaded from the database. * @param Iterator $records Raw records loaded from the database. * @param int $stepid The id of the records to extract. * @param string $qtype The question type of which this is an attempt. * If not given, each record must include a qtype field. * @return question_attempt_step The newly constructed question_attempt_step. */ public static function load_from_records($records, $attemptstepid, $qtype = null) { $currentrec = $records->current(); while ($currentrec->attemptstepid != $attemptstepid) { $records->next(); if (!$records->valid()) { throw new coding_exception('Question attempt step ' . $attemptstepid . ' not found in the database.'); } $currentrec = $records->current(); } $record = $currentrec; $contextid = null; $data = array(); while ($currentrec && $currentrec->attemptstepid == $attemptstepid) { if (!is_null($currentrec->name)) { $data[$currentrec->name] = $currentrec->value; } $records->next(); if ($records->valid()) { $currentrec = $records->current(); } else { $currentrec = false; } } $step = new question_attempt_step_read_only($data, $record->timecreated, $record->userid); $step->state = question_state::get($record->state); $step->id = $record->attemptstepid; if (!is_null($record->fraction)) { $step->fraction = $record->fraction + 0; } // This next chunk of code requires getting $contextid and $qtype here. // Somehow, we need to get that information to this point by modifying // all the paths by which this method can be called. // Can we only return files when it's possible? Should there be some kind of warning? if (is_null($qtype)) { $qtype = $record->qtype; } foreach (question_bank::get_qtype($qtype)->response_file_areas() as $area) { if (empty($step->data[$area])) { continue; } $step->data[$area] = new question_file_loader($step, $area, $step->data[$area], $record->contextid); } return $step; }
/** * Make a link to review an individual question in a popup window. * * @param string $data HTML fragment. The text to make into the link. * @param object $attempt data for the row of the table being output. * @param int $slot the number used to identify this question within this usage. */ public function make_review_link($data, $attempt, $slot) { global $OUTPUT; $stepdata = $this->lateststeps[$attempt->usageid][$slot]; $state = question_state::get($stepdata->state); $flag = ''; if ($stepdata->flagged) { $flag = $OUTPUT->pix_icon('i/flagged', get_string('flagged', 'question'), 'moodle', array('class' => 'questionflag')); } $feedbackimg = ''; if ($state->is_finished() && $state != question_state::$needsgrading) { $feedbackimg = $this->icon_for_fraction($stepdata->fraction); } $output = html_writer::tag('span', $feedbackimg . html_writer::tag('span', $data, array('class' => $state->get_state_class(true))) . $flag, array('class' => 'que')); $url = new moodle_url('/mod/quiz/reviewquestion.php', array('attempt' => $attempt->attempt, 'slot' => $slot)); $output = $OUTPUT->action_link($url, $output, new popup_action('click', $url, 'reviewquestion', array('height' => 450, 'width' => 650)), array('title' => get_string('reviewresponse', 'quiz'))); return $output; }
/** * @param string $colname the name of the column. * @param object $attempt the row of data - see the SQL in display() in * mod/quiz/report/overview/report.php to see what fields are present, * and what they are called. * @return string the contents of the cell. */ public function other_cols($colname, $attempt) { if (!preg_match('/^qsgrade(\\d+)$/', $colname, $matches)) { return null; } $slot = $matches[1]; $question = $this->questions[$slot]; if (!isset($this->lateststeps[$attempt->usageid][$slot])) { return '-'; } $stepdata = $this->lateststeps[$attempt->usageid][$slot]; $state = question_state::get($stepdata->state); if ($question->maxmark == 0) { $grade = '-'; } else { if (is_null($stepdata->fraction)) { if ($state == question_state::$needsgrading) { $grade = get_string('requiresgrading', 'question'); } else { $grade = '-'; } } else { $grade = quiz_rescale_grade($stepdata->fraction * $question->maxmark, $this->quiz, 'question'); } } if ($this->is_downloading()) { return $grade; } if (isset($this->regradedqs[$attempt->usageid][$slot])) { $gradefromdb = $grade; $newgrade = quiz_rescale_grade($this->regradedqs[$attempt->usageid][$slot]->newfraction * $question->maxmark, $this->quiz, 'question'); $oldgrade = quiz_rescale_grade($this->regradedqs[$attempt->usageid][$slot]->oldfraction * $question->maxmark, $this->quiz, 'question'); $grade = html_writer::tag('del', $oldgrade) . '/' . html_writer::empty_tag('br') . $newgrade; } return $this->make_review_link($grade, $attempt, $slot); }
/** * @param object $attempt the row data * @param int $slot * @return question_state */ protected function slot_state($attempt, $slot) { $stepdata = $this->lateststeps[$attempt->usageid][$slot]; return question_state::get($stepdata->state); }
/** * Create a question_attempt_step from records loaded from the database. * @param Iterator $records Raw records loaded from the database. * @param int $stepid The id of the records to extract. * @return question_attempt_step The newly constructed question_attempt_step. */ public static function load_from_records($records, $attemptstepid) { $currentrec = $records->current(); while ($currentrec->attemptstepid != $attemptstepid) { $records->next(); if (!$records->valid()) { throw new coding_exception('Question attempt step ' . $attemptstepid . ' not found in the database.'); } $currentrec = $records->current(); } $record = $currentrec; $data = array(); while ($currentrec && $currentrec->attemptstepid == $attemptstepid) { if ($currentrec->name) { $data[$currentrec->name] = $currentrec->value; } $records->next(); if ($records->valid()) { $currentrec = $records->current(); } else { $currentrec = false; } } $step = new question_attempt_step_read_only($data, $record->timecreated, $record->userid); $step->state = question_state::get($record->state); $step->id = $record->attemptstepid; if (!is_null($record->fraction)) { $step->fraction = $record->fraction + 0; } return $step; }