]> git.mjollnir.org Git - moodle.git/commitdiff
Solving MDL-12063 qtype_questions where left orphans when questions whe deleted or
authorpichetp <pichetp>
Tue, 20 Nov 2007 03:48:29 +0000 (03:48 +0000)
committerpichetp <pichetp>
Tue, 20 Nov 2007 03:48:29 +0000 (03:48 +0000)
 qtype change

question/type/multianswer/questiontype.php

index fc65b95c0ab973530123d2c75bddb4c007b61ed5..bef538b231128222979bbda3e1bd1506323477c8 100644 (file)
@@ -74,6 +74,24 @@ class embedded_cloze_qtype extends default_questiontype {
             // if we still have some old wrapped question ids, reuse the next of them
             if ($oldwrappedid = array_shift($oldwrappedids)) {
                 $wrapped->id = $oldwrappedid;
+                //
+                $oldqtype = get_field('question', 'qtype', 'id',$oldwrappedid) ;
+                if($oldqtype != $wrapped->qtype ) {
+                    echo "<p>oldqtype $oldqtype newqtype".$wrapped->qtype."</p>";
+                    switch ($oldqtype) {
+                        case 'multichoice':
+                             delete_records('question_multichoice', 'question', $oldwrappedid);
+                            break;
+                        case 'shortanswer':
+                             delete_records('question_shortanswer', 'question', $oldwrappedid);
+                            break;
+                        case 'numerical':
+                             delete_records('question_numerical', 'question', $oldwrappedid);
+                            break;
+                        default:
+                            error("questiontype $wrapped->qtype not recognized");
+                    }
+                }
             }
             $wrapped->name = $question->name;
             $wrapped->parent = $question->id;
@@ -85,8 +103,9 @@ class embedded_cloze_qtype extends default_questiontype {
 
         // Delete redundant wrapped questions
         if(is_array($oldwrappedids) && count($oldwrappedids)){ 
-            $oldwrappedids = implode(',', $oldwrappedids);
-            delete_records_select('question', "id IN ($oldwrappedids)");
+            foreach ($oldwrappedids as $id) {
+                delete_question($id) ;
+            }
         }
 
         if (!empty($sequence)) {