]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10899 - There is some data associated with some questons that needs to be udpated...
authortjhunt <tjhunt>
Fri, 9 May 2008 15:05:36 +0000 (15:05 +0000)
committertjhunt <tjhunt>
Fri, 9 May 2008 15:05:36 +0000 (15:05 +0000)
lang/en_utf8/question.php
lib/questionlib.php
question/category_class.php
question/contextmoveq.php
question/editlib.php

index 8c6ae25ac3f01f3e746687336837cd17306fccc8..7f8b04982721e2333432fa139b10353f05f00cc2 100644 (file)
@@ -32,6 +32,7 @@ $string['editingquestion'] = 'Editing a question';
 $string['erroraccessingcontext'] = 'Cannot access context';
 $string['errorfilecannotbecopied'] = 'Error cannot copy file $a.';
 $string['errorfilecannotbemoved'] = 'Error cannot move file $a.';
+$string['errormovingquestions'] = 'Error while moving questions with ids $a.';
 $string['errorfileschanged'] = 'Error files linked to from questions have changed since form was displayed.';
 $string['exportcategory'] = 'Export category';
 $string['filesareasite']= 'the site files area';
index 94259e5b97a1f378805fa9de27cb673127d2c718..22cb029d3ddadf078a4d8448546f54b00319817c 100644 (file)
@@ -559,6 +559,30 @@ function question_delete_activity($cm, $feedback=true) {
     }
     return true;
 }
+
+/**
+ * This function should be considered private to the question bank, it is called from
+ * question/editlib.php question/contextmoveq.php and a few similar places to to the work of
+ * acutally moving questions and associated data. However, callers of this function also have to
+ * do other work, which is why you should not call this method directly from outside the questionbank.
+ *
+ * @param string $questionids a comma-separated list of question ids.
+ * @param integer $newcategory the id of the category to move to.
+ */
+function question_move_questions_to_category($questionids, $newcategory) {
+    $result = true;
+
+    // Move the questions themselves.
+    $result = $result && set_field_select('question', 'category', $newcategory, "id IN ($questionids)");
+
+    // Move any subquestions belonging to them.
+    $result = $result && set_field_select('question', 'category', $newcategory, "parent IN ($questionids)");
+
+    // TODO Deal with datasets.
+
+    return $result;
+}
+
 /**
  * @param array $row tab objects
  * @param question_edit_contexts $contexts object representing contexts available from this context
index 879f353de74e03d95a7c86f04d2c2bce24b58dc7..80c5fe16fd16603283357ba96d180b7d2d705074 100644 (file)
@@ -352,8 +352,9 @@ class question_category_object {
     }
 
     function move_questions($oldcat, $newcat){
-        if (!set_field('question', 'category', $newcat, 'category', $oldcat)) {
-            print_error("Error while moving questions from category '$oldcat' to '$newcat'", '', $this->pageurl->out());
+        $questionids = get_records_select_menu('question', "category = $oldcat AND parent = 0", '', 'id,1');
+        if (!question_move_questions_to_category(implode(',', array_keys($questionids)), $newcat)) {
+            print_error('errormovingquestions', 'question', $returnurl, $ids);
         }
     }
 
index 9bcd9dce2cc75bb49c5ea745f6c670a0d32ef742..9973c6d66b9dad7c0d8596e92f5ebfd5df48a3b9 100644 (file)
@@ -159,9 +159,10 @@ if ($contextmoveform->is_cancelled()){
 
         }
     }
-    //now move questions
-    if (!execute_sql("UPDATE {$CFG->prefix}question SET category = {$tocat->id} WHERE id IN ({$ids})", false)){
-        print_error("Could not move the questions {$ids} to category ".$tocat->name, '', $returnurl);
+
+/// Now move questions.
+    if (!question_move_questions_to_category($ids, $tocat->id)) {
+        print_error('errormovingquestions', 'question', $returnurl, $ids);
     }
     redirect($returnurl);
 }
index 38315a66b2e40b675e4020211e896fb12e719c36..b80d7f892d178bde48e1df39091a16ce692e5181 100644 (file)
@@ -447,11 +447,8 @@ function question_showbank_actions($pageurl, $cm){
             }
             $returnurl = $pageurl->out(false, array('category'=>"$tocategoryid,$contextid"));
             if (!$checkforfiles){
-                foreach ($questionids as $questionid){
-                    //move question
-                    if (!set_field('question', 'category', $tocategory->id, 'id', $questionid)) {
-                        error('Could not update category field');
-                    }
+                if (!question_move_questions_to_category(implode(',', $questionids), $tocategory->id)) {
+                    print_error('errormovingquestions', 'question', $returnurl, $questionids);
                 }
                 redirect($returnurl);
             } else {