mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
Due to changes in Quiz which allows commenting and manual grading of all question types, essay no longer needs its two tables: question_essay and question_essay_states
backuplib.php removed backup code related to question_essay_states type/essay/db/mysql.sql and postgres7.sql removed all SQL type/essay/display.html improved essay display type/essay/questiontype.php, editquestion.php, and editquestion.html removed all uses of the two tables - this resulted in a great simplification of the essay question type
This commit is contained in:
parent
116bd4ec0d
commit
53354ec03c
@ -318,7 +318,6 @@
|
||||
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));
|
||||
}
|
||||
@ -378,28 +377,6 @@
|
||||
}
|
||||
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) {
|
||||
|
@ -1,30 +0,0 @@
|
||||
|
||||
|
||||
--
|
||||
-- Table structure for table `mdl_question_essay`
|
||||
--
|
||||
|
||||
CREATE TABLE `prefix_question_essay` (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`question` int(10) unsigned NOT NULL default '0',
|
||||
`answer` varchar(255) NOT NULL default '',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `question` (`question`)
|
||||
) TYPE=MyISAM COMMENT='Options for essay questions';
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Table structure for table `mdl_question_essay_states`
|
||||
--
|
||||
|
||||
CREATE TABLE `prefix_question_essay_states` (
|
||||
`id` int(10) unsigned NOT NULL auto_increment,
|
||||
`stateid` int(10) unsigned NOT NULL default '0',
|
||||
`graded` tinyint(4) unsigned NOT NULL default '0',
|
||||
`fraction` float NOT NULL default '0',
|
||||
`response` text NOT NULL default '',
|
||||
PRIMARY KEY (`id`)
|
||||
) TYPE=MyISAM COMMENT='essay question type specific state information';
|
||||
|
||||
-- --------------------------------------------------------
|
@ -1,27 +0,0 @@
|
||||
|
||||
# --------------------------------------------------------
|
||||
|
||||
#
|
||||
# Table structure for table prefix_question_essay
|
||||
#
|
||||
|
||||
CREATE TABLE prefix_question_essay (
|
||||
id serial NOT NULL,
|
||||
question integer NOT NULL DEFAULT 0,
|
||||
answer varchar(255) NOT NULL DEFAULT ''
|
||||
);
|
||||
|
||||
|
||||
# --------------------------------------------------------
|
||||
|
||||
#
|
||||
# Table structure for table prefix_question_essay_states
|
||||
#
|
||||
|
||||
CREATE TABLE prefix_question_essay_states (
|
||||
id serial NOT NULL,
|
||||
stateid integer NOT NULL DEFAULT 0,
|
||||
graded integer NOT NULL DEFAULT 0,
|
||||
response text NOT NULL DEFAULT '',
|
||||
fraction real NOT NULL DEFAULT 0
|
||||
);
|
@ -18,7 +18,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="c0 feedback">
|
||||
<td class="feedback">
|
||||
<?php echo $feedback; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -86,7 +86,7 @@
|
||||
<b><?php print_string("feedback", "quiz") ?>:</b>
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="feedback" rows="2" cols="50" wrap="virtual"><?php p($essayfeedback->feedback) ?></textarea>
|
||||
<textarea name="feedback" rows="2" cols="50" wrap="virtual"><?php p($options->answer->feedback) ?></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -1,13 +1,9 @@
|
||||
<?php // $Id$
|
||||
|
||||
if (!empty($question->id)) {
|
||||
$options = get_record("question_essay", "question", "$question->id");
|
||||
}
|
||||
|
||||
if (!empty($options->answer)) {
|
||||
$essayfeedback = get_record("question_answers", "id", $options->answer);
|
||||
$options->answer = get_record("question_answers", "question", $question->id);
|
||||
} else {
|
||||
$essayfeedback->feedback = "";
|
||||
$options->answer->feedback = '';
|
||||
}
|
||||
|
||||
print_heading_with_help(get_string("editingessay", "quiz"), "essay", "quiz");
|
||||
|
@ -11,26 +11,10 @@ class question_essay_qtype extends default_questiontype {
|
||||
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)) {
|
||||
@ -40,7 +24,7 @@ class question_essay_qtype extends default_questiontype {
|
||||
} 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)) {
|
||||
@ -48,33 +32,6 @@ class question_essay_qtype extends default_questiontype {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -108,8 +65,7 @@ class question_essay_qtype extends default_questiontype {
|
||||
}
|
||||
|
||||
// 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 = "";
|
||||
@ -122,7 +78,7 @@ class question_essay_qtype extends default_questiontype {
|
||||
} 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");
|
||||
@ -142,106 +98,7 @@ class question_essay_qtype extends default_questiontype {
|
||||
|
||||
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 ////
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user