MDL-34640: adding code to pass contextid and question type to question_file_loader.

This commit is contained in:
Mathieu Petit-Clair 2012-08-14 11:58:41 -04:00 committed by Tim Hunt
parent 8a1e7b7756
commit d0782585c8
3 changed files with 17 additions and 11 deletions

View File

@ -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() {

View File

@ -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) {

View File

@ -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;