Merge branch 'MDL-31729' of git://github.com/timhunt/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2012-02-27 19:01:34 +01:00
commit 869f80e4f3
8 changed files with 59 additions and 0 deletions

View File

@ -1839,6 +1839,7 @@ class qtype_calculated extends question_type {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_answers($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
}
protected function delete_files($questionid, $contextid) {
@ -1846,6 +1847,7 @@ class qtype_calculated extends question_type {
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid);
$this->delete_files_in_hints($questionid, $contextid);
}
}

View File

@ -276,6 +276,7 @@ class qtype_calculatedmulti extends qtype_calculated {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_answers($questionid, $oldcontextid, $newcontextid, true);
$this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'qtype_calculatedmulti', 'correctfeedback', $questionid);
@ -290,6 +291,7 @@ class qtype_calculatedmulti extends qtype_calculated {
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid, true);
$this->delete_files_in_hints($questionid, $contextid);
$fs->delete_area_files($contextid, 'qtype_calculatedmulti',
'correctfeedback', $questionid);

View File

@ -208,6 +208,7 @@ class qtype_match extends question_type {
}
$this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
}
protected function delete_files($questionid, $contextid) {
@ -223,5 +224,6 @@ class qtype_match extends question_type {
}
$this->delete_files_in_combined_feedback($questionid, $contextid);
$this->delete_files_in_hints($questionid, $contextid);
}
}

View File

@ -223,6 +223,16 @@ class qtype_multianswer extends question_type {
}
return $fractionsum / $fractionmax;
}
public function move_files($questionid, $oldcontextid, $newcontextid) {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
}
protected function delete_files($questionid, $contextid) {
parent::delete_files($questionid, $contextid);
$this->delete_files_in_hints($questionid, $contextid);
}
}

View File

@ -240,11 +240,13 @@ class qtype_multichoice extends question_type {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_answers($questionid, $oldcontextid, $newcontextid, true);
$this->move_files_in_combined_feedback($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
}
protected function delete_files($questionid, $contextid) {
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid, true);
$this->delete_files_in_combined_feedback($questionid, $contextid);
$this->delete_files_in_hints($questionid, $contextid);
}
}

View File

@ -470,6 +470,7 @@ class qtype_numerical extends question_type {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_answers($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
}
protected function delete_files($questionid, $contextid) {
@ -477,6 +478,7 @@ class qtype_numerical extends question_type {
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid);
$this->delete_files_in_hints($questionid, $contextid);
}
}

View File

@ -1103,6 +1103,27 @@ class question_type {
}
}
/**
* Move all the files belonging to this question's hints when the question
* is moved from one context to another.
* @param int $questionid the question being moved.
* @param int $oldcontextid the context it is moving from.
* @param int $newcontextid the context it is moving to.
* @param bool $answerstoo whether there is an 'answer' question area,
* as well as an 'answerfeedback' one. Default false.
*/
protected function move_files_in_hints($questionid, $oldcontextid, $newcontextid) {
global $DB;
$fs = get_file_storage();
$hintids = $DB->get_records_menu('question_hints',
array('questionid' => $questionid), 'id', 'id,1');
foreach ($hintids as $hintid => $notused) {
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'question', 'hint', $hintid);
}
}
/**
* Move all the files belonging to this question's answers when the question
* is moved from one context to another.
@ -1157,6 +1178,22 @@ class question_type {
}
}
/**
* Delete all the files belonging to this question's hints.
* @param int $questionid the question being deleted.
* @param int $contextid the context the question is in.
*/
protected function delete_files_in_hints($questionid, $contextid) {
global $DB;
$fs = get_file_storage();
$hintids = $DB->get_records_menu('question_hints',
array('questionid' => $questionid), 'id', 'id,1');
foreach ($hintids as $hintid => $notused) {
$fs->delete_area_files($contextid, 'question', 'hint', $hintid);
}
}
/**
* Delete all the files belonging to this question's answers.
* @param int $questionid the question being deleted.

View File

@ -49,11 +49,13 @@ class qtype_shortanswer extends question_type {
public function move_files($questionid, $oldcontextid, $newcontextid) {
parent::move_files($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_answers($questionid, $oldcontextid, $newcontextid);
$this->move_files_in_hints($questionid, $oldcontextid, $newcontextid);
}
protected function delete_files($questionid, $contextid) {
parent::delete_files($questionid, $contextid);
$this->delete_files_in_answers($questionid, $contextid);
$this->delete_files_in_hints($questionid, $contextid);
}
public function save_question_options($question) {