From d0782585c809dbce3a5ceeab693e80a478b71a23 Mon Sep 17 00:00:00 2001 From: Mathieu Petit-Clair Date: Tue, 14 Aug 2012 11:58:41 -0400 Subject: [PATCH] MDL-34640: adding code to pass contextid and question type to question_file_loader. --- question/engine/datalib.php | 9 +++++---- question/engine/questionattempt.php | 2 +- question/engine/questionattemptstep.php | 17 +++++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/question/engine/datalib.php b/question/engine/datalib.php index c742312c2ce..8e5a3849db3 100644 --- a/question/engine/datalib.php +++ b/question/engine/datalib.php @@ -227,6 +227,7 @@ WHERE throw new coding_exception('Failed to load question_attempt_step ' . $stepid); } + // TODO: pass a question_type and a contextid to load_from_records to get response files $step = question_attempt_step::load_from_records($records, $stepid); $records->close(); @@ -1355,10 +1356,10 @@ class question_file_loader implements question_response_files { * @param int $contextid the context id that the files belong to. */ public function __construct(question_attempt_step $step, $name, $value, $contextid) { - $this->draftitemid = $draftitemid; - $this->component = $component; - $this->filearea = $filearea; - $this->value = $this->compute_value($draftitemid, $text); + $this->step = $step; + $this->name = $name; + $this->value = $value; + $this->contextid = $contextid; } public function __toString() { diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index ae4be3820c9..b31bdf71404 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -1285,7 +1285,7 @@ class question_attempt { $autosavedsequencenumber = null; while ($record && $record->questionattemptid == $questionattemptid && !is_null($record->attemptstepid)) { $sequencenumber = $record->sequencenumber; - $nextstep = question_attempt_step::load_from_records($records, $record->attemptstepid); + $nextstep = question_attempt_step::load_from_records($records, $record->attemptstepid, $qa->get_question(), $record->contextid); if ($sequencenumber < 0) { if (!$autosavedstep) { diff --git a/question/engine/questionattemptstep.php b/question/engine/questionattemptstep.php index 6145f4158bb..c5318e94a4b 100644 --- a/question/engine/questionattemptstep.php +++ b/question/engine/questionattemptstep.php @@ -370,9 +370,11 @@ class question_attempt_step { * 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 + * @param int $contextid The contextid of this question attempt * @return question_attempt_step The newly constructed question_attempt_step. */ - public static function load_from_records($records, $attemptstepid) { + public static function load_from_records($records, $attemptstepid, $qtype = null, $contextid = null) { $currentrec = $records->current(); while ($currentrec->attemptstepid != $attemptstepid) { $records->next(); @@ -407,12 +409,15 @@ class question_attempt_step { // 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. - foreach (question_bank::get_qtype($qtype)->response_file_areas() as $area) { - if (empty($step->data[$area])) { - continue; - } + // Can we only return files when it's possible? Should there be some kind of warning? + if ($qtype && $contextid) { + foreach (question_bank::get_qtype($qtype)->response_file_areas() as $area) { + if (empty($step->data[$area])) { + continue; + } - $step->data[$area] = new question_file_loader($this, $area, $step->data[$area], $contextid) + $step->data[$area] = new question_file_loader($step, $area, $step->get_qt_var($area), $contextid); + } } return $step;