From c033e37f169f3dd43b038f6a7992cd33df2959dc Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 20 Sep 2007 15:57:02 +0000 Subject: [PATCH] Notices on restore. --- question/restorelib.php | 22 +++++++++++++--------- question/type/truefalse/questiontype.php | 6 +++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/question/restorelib.php b/question/restorelib.php index fa48d6ddef..72f88e28ef 100644 --- a/question/restorelib.php +++ b/question/restorelib.php @@ -319,11 +319,7 @@ $question->questiontext = backup_todb($que_info['#']['QUESTIONTEXT']['0']['#']); $question->questiontextformat = backup_todb($que_info['#']['QUESTIONTEXTFORMAT']['0']['#']); $question->image = backup_todb($que_info['#']['IMAGE']['0']['#']); - if (array_key_exists('GENERALFEEDBACK', $que_info['#'])) { - $question->generalfeedback = backup_todb($que_info['#']['GENERALFEEDBACK']['0']['#']); - } else { - $question->generalfeedback = ''; - } + $question->generalfeedback = backup_todb_optional_field($que_info, 'GENERALFEEDBACK', ''); $question->defaultgrade = backup_todb($que_info['#']['DEFAULTGRADE']['0']['#']); $question->penalty = backup_todb($que_info['#']['PENALTY']['0']['#']); $question->qtype = backup_todb($que_info['#']['QTYPE']['0']['#']); @@ -331,10 +327,10 @@ $question->stamp = backup_todb($que_info['#']['STAMP']['0']['#']); $question->version = backup_todb($que_info['#']['VERSION']['0']['#']); $question->hidden = backup_todb($que_info['#']['HIDDEN']['0']['#']); - $question->timecreated = backup_todb($que_info['#']['TIMECREATED']['0']['#']); - $question->timemodified = backup_todb($que_info['#']['TIMEMODIFIED']['0']['#']); - $question->createdby = backup_todb($que_info['#']['CREATEDBY']['0']['#']); - $question->modifiedby = backup_todb($que_info['#']['MODIFIEDBY']['0']['#']); + $question->timecreated = backup_todb_optional_field($que_info, 'TIMECREATED', 0); + $question->timemodified = backup_todb_optional_field($que_info, 'TIMEMODIFIED', 0); + $question->createdby = backup_todb_optional_field($que_info, 'CREATEDBY', null); + $question->modifiedby = backup_todb_optional_field($que_info, 'MODIFIEDBY', null); if ($restore->backup_version < 2006032200) { // The qtype was an integer that now needs to be converted to the name @@ -468,6 +464,14 @@ return $status; } + function backup_todb_optional_field($data, $field, $default) { + if (array_key_exists($field, $data['#'])) { + return backup_todb($data['#'][$field]['0']['#']); + } else { + return $default; + } + } + function question_restore_answers ($old_question_id,$new_question_id,$info,$restore) { global $CFG; diff --git a/question/type/truefalse/questiontype.php b/question/type/truefalse/questiontype.php index ed485029c3..1877b83cf7 100644 --- a/question/type/truefalse/questiontype.php +++ b/question/type/truefalse/questiontype.php @@ -283,7 +283,11 @@ class question_truefalse_qtype extends default_questiontype { $status = true; //Get the truefalse array - $truefalses = $info['#']['TRUEFALSE']; + if (array_key_exists('TRUEFALSE', $info['#'])) { + $truefalses = $info['#']['TRUEFALSE']; + } else { + $truefalses = array(); + } //Iterate over truefalse for($i = 0; $i < sizeof($truefalses); $i++) { -- 2.39.5