fwrite ($bf,full_tag("PENALTY",8,false,$state->penalty));
// now back up question type specific state information
$status = backup_question_rqp_state ($bf,$preferences,$state->id);
- $status = backup_question_essay_state ($bf,$preferences,$state->id);
//End state
$status = fwrite ($bf,end_tag("STATE",7,true));
}
}
return $status;
}
-
- //Backup question_essay_state contents (executed from backup_question_states)
- function backup_question_essay_state ($bf,$preferences,$state) {
-
- global $CFG;
-
- $status = true;
-
- $essay_state = get_record("question_essay_states", "stateid", $state);
- //If there is a state
- if ($essay_state) {
- //Write start tag
- $status = fwrite ($bf,start_tag("ESSAY_STATE",8,true));
- //Print state contents
- fwrite ($bf,full_tag("GRADED",9,false,$essay_state->graded));
- fwrite ($bf,full_tag("FRACTION",9,false,$essay_state->fraction));
- fwrite ($bf,full_tag("RESPONSE",9,false,$essay_state->response));
- //Write end tag
- $status = fwrite ($bf,end_tag("ESSAY_STATE",8,true));
- }
- return $status;
- }
//Returns an array of categories id
function question_category_ids_by_backup ($backup_unique_code) {
return 'essay';
}
- function get_question_options(&$question) {
- // Get additional information from database
- // and attach it to the question object
- if (!$question->options = get_record('question_essay', 'question', $question->id)) {
- notify('Error: Missing question options!');
- return false;
- }
-
- if (!$question->options->answers = get_records('question_answers', 'question',
- $question->id)) {
- notify('Error: Missing question answers!');
- return false;
- }
- return true;
- }
-
function save_question_options($question) {
if ($answer = get_record("question_answers", "question", $question->id)) {
// Existing answer, so reuse it
- $answer->answer = $question->feedback;
+ $answer->answer = $question->feedback;
$answer->feedback = $question->feedback;
$answer->fraction = $question->fraction;
if (!update_record("question_answers", $answer)) {
} else {
unset($answer);
$answer->question = $question->id;
- $answer->answer = $question->feedback;
+ $answer->answer = $question->feedback;
$answer->feedback = $question->feedback;
$answer->fraction = $question->fraction;
if (!$answer->id = insert_record("question_answers", $answer)) {
return $result;
}
}
- if ($options = get_record("question_essay", "question", $question->id)) {
- // No need to do anything, since the answer IDs won't have changed
- // But we'll do it anyway, just for robustness
- $options->answer = $answer->id;
- if (!update_record("question_essay", $options)) {
- $result->error = "Could not update quiz essay options! (id=$options->id)";
- return $result;
- }
- } else {
- unset($options);
- $options->question = $question->id;
- $options->answer = $answer->id;
- if (!insert_record("question_essay", $options)) {
- $result->error = "Could not insert quiz essay options!";
- return $result;
- }
- }
- return true;
- }
-
- /**
- * Deletes a question from the question-type specific tables
- *
- * @param object $question The question being deleted
- */
- function delete_question($questionid) {
- delete_records("question_essay", "question", $questionid);
return true;
}
}
// get response value
- if (isset($state->responses[''])) {
- // security problem. responses[''] is never cleaned before it is sent to the db (I think)
+ if (isset($state->responses[''])) {
$value = stripslashes_safe($state->responses['']);
} else {
$value = "";
} else {
// it is read only, so just format the students answer and output it
$answer = format_text($value, $question->questiontextformat,
- $formatoptions, $cmoptions->course);
+ $formatoptions, $cmoptions->course);
}
include("$CFG->dirroot/question/type/essay/display.html");
return true;
}
-
-/// BACKUP FUNCTIONS ////////////////////////////
-
- /*
- * Backup the data in a truefalse question
- *
- * This is used in question/backuplib.php
- */
- function backup($bf,$preferences,$question,$level=6) {
-
- $status = true;
-
- $essays = get_records('question_essay', 'question', $question, "id");
- //If there are essays
- if ($essays) {
- //Iterate over each essay
- foreach ($essays as $essay) {
- $status = fwrite ($bf,start_tag("ESSAY",$level,true));
- //Print essay contents
- fwrite ($bf,full_tag("ANSWER",$level+1,false,$essay->answer));
- $status = fwrite ($bf,end_tag("ESSAY",$level,true));
- }
- //Now print question_answers
- $status = question_backup_answers($bf,$preferences,$question);
- }
- return $status;
- }
-
-/// RESTORE FUNCTIONS /////////////////
-
- /*
- * Restores the data in the question
- *
- * This is used in question/restorelib.php
- */
- function restore($old_question_id,$new_question_id,$info,$restore) {
-
- $status = true;
-
- //Get the truefalse array
- $essays = $info['#']['ESSAY'];
-
- //Iterate over truefalse
- for($i = 0; $i < sizeof($essays); $i++) {
- $essay_info = $essays[$i];
-
- //Now, build the question_essay record structure
- $essay->question = $new_question_id;
- $essay->answer = backup_todb($essay_info['#']['ANSWER']['0']['#']);
-
- ////We have to recode the answer field
- $answer = backup_getid($restore->backup_unique_code,"question_answers",$essay->answer);
- if ($answer) {
- $essay->answer = $answer->new_id;
- }
-
- //The structure is equal to the db, so insert the question_essay
- $newid = insert_record ("question_essay",$essay);
-
- //Do some output
- if (($i+1) % 50 == 0) {
- echo ".";
- if (($i+1) % 1000 == 0) {
- echo "<br />";
- }
- backup_flush(300);
- }
-
- if (!$newid) {
- $status = false;
- }
- }
-
- return $status;
- }
-
-
- //This function restores the question_essay_states
- function restore_state($state_id,$info,$restore) {
-
- $status = true;
-
- //Get the question_essay_state
- $essay_state = $info['#']['ESSAY_STATE']['0'];
- if ($essay_state) {
-
- //Now, build the ESSAY_STATES record structure
- $state->stateid = $state_id;
- $state->graded = backup_todb($essay_state['#']['GRADED']['0']['#']);
- $state->fraction = backup_todb($essay_state['#']['FRACTION']['0']['#']);
- $state->response = backup_todb($essay_state['#']['RESPONSE']['0']['#']);
-
- //The structure is equal to the db, so insert the question_states
- $newid = insert_record ("question_essay_states",$state);
- }
-
- return $status;
- }
-
-}
+}
//// END OF CLASS ////
//////////////////////////////////////////////////////////////////////////