MDL-20636 Essay question type, make is_same_response consider files. #216

This commit is contained in:
Tim Hunt
2011-03-31 12:45:07 +01:00
parent 217f9a618c
commit cd3557e64c
3 changed files with 38 additions and 12 deletions
+35 -2
View File
@@ -954,6 +954,12 @@ class question_file_saver {
/** @var string the file area name. */
protected $filearea;
/**
* @var string the value to store in the question_attempt_step_data to
* represent these files.
*/
protected $value = null;
/**
* Constuctor.
* @param int $draftitemid the draft area to save the files from.
@@ -966,9 +972,36 @@ class question_file_saver {
$this->filearea = $filearea;
}
protected function get_value() {
global $USER;
if (!is_null($this->value)) {
return $this->value;
}
$fs = get_file_storage();
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
$files = $fs->get_area_files($usercontext->id, 'user', 'draft',
$this->draftitemid, 'sortorder, filepath, filename', false);
$string = '';
foreach ($files as $file) {
$string .= $file->get_filepath() . $file->get_filename() . '|' .
$file->get_contenthash() . '|';
}
if ($string) {
$this->value = md5($string);
} else {
$this->value = '';
}
return $this->value;
}
public function __toString() {
// When stored in the database, we want this value to appear as 1.
return '1';
return $this->get_value();
}
/**