]> git.mjollnir.org Git - moodle.git/commitdiff
Due to changes in Quiz which allows commenting and manual grading of all question...
authormark-nielsen <mark-nielsen>
Mon, 1 May 2006 02:56:06 +0000 (02:56 +0000)
committermark-nielsen <mark-nielsen>
Mon, 1 May 2006 02:56:06 +0000 (02:56 +0000)
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

question/backuplib.php
question/type/essay/db/mysql.sql
question/type/essay/db/postgres7.sql
question/type/essay/display.html
question/type/essay/editquestion.html
question/type/essay/editquestion.php
question/type/essay/questiontype.php

index 2d7aba9ed27e8faaec5bf236f8258b939695429e..0127db089eaed10fcdd2be9d3e71ab679f4352b8 100644 (file)
                 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) {
index cf0f6e991931596da73ec423a703fe84f7fbd2a6..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -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';
-
--- --------------------------------------------------------
\ No newline at end of file
index 57c594d56b62c254717053c80268f5f2bb50bf2f..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -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
-);
\ No newline at end of file
index 70b98d8ab68910f38b6e5e226f7235fa6b7a8261..5dc9954f6e99229af390394f059fa9096e77571a 100644 (file)
@@ -18,7 +18,7 @@
           </td>
       </tr>
       <tr>
-          <td class="c0 feedback">
+          <td class="feedback">
               <?php echo $feedback; ?>
           </td>
       </tr>
index 42cac0dd5b2839fc4b4965eb503276287dab51b9..682c4341b8d429609a51bfaba348d59ca76050f4 100644 (file)
@@ -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>
index 2f87d648f0b0de49a7e30981431d6d2b7a2278c3..26d62635459af3a85bed518ad8c8ffe04370467d 100644 (file)
@@ -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");
index 4846590da25abfa6498e908bf4254ee8da91606d..a15be1e6329499449e5a4a94ed2c1119384ace79 100644 (file)
@@ -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 ////
 
 //////////////////////////////////////////////////////////////////////////