Skip to content
Permalink
Browse files

MDL-34640: adding code to pass contextid and question type to questio…

…n_file_loader.
  • Loading branch information
scyrma authored and timhunt committed Aug 14, 2012
1 parent 8a1e7b7 commit d0782585c809dbce3a5ceeab693e80a478b71a23
Showing with 17 additions and 11 deletions.
  1. +5 −4 question/engine/datalib.php
  2. +1 −1 question/engine/questionattempt.php
  3. +11 −6 question/engine/questionattemptstep.php
@@ -227,6 +227,7 @@ public function load_question_attempt_step($stepid) {
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() {
@@ -1285,7 +1285,7 @@ public static function load_from_records($records, $questionattemptid,
$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) {
@@ -370,9 +370,11 @@ public function get_all_data() {
* 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 @@ public static function load_from_records($records, $attemptstepid) {
// 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($step, $area, $step->get_qt_var($area), $contextid);
}

$step->data[$area] = new question_file_loader($this, $area, $step->data[$area], $contextid)
}

return $step;

0 comments on commit d078258

Please sign in to comment.
You can’t perform that action at this time.