]> git.mjollnir.org Git - moodle.git/commitdiff
quiz editing: MDL-17294 changed quiz_process_randomquestion_formdata to always return...
authorpilpi <pilpi>
Fri, 28 Nov 2008 17:29:04 +0000 (17:29 +0000)
committerpilpi <pilpi>
Fri, 28 Nov 2008 17:29:04 +0000 (17:29 +0000)
mod/quiz/addrandom.php
mod/quiz/edit.php
mod/quiz/editlib.php

index bb0e6d7030412d3e9cf3dafab1d49460140f29fd..63bee48d3cb2fa38cc528e9903fc77b954197d5a 100644 (file)
 
     //setting the second parameter of process_randomquestion_formdata to true causes it to redirect on success
     //TODO: process if returns false?
-    quiz_process_randomquestion_formdata($qcobject,true, $cmid);
-
+    $newquestioninfo=quiz_process_randomquestion_formdata($qcobject);
+    if($newquestioninfo){
+        redirect($CFG->wwwroot."/mod/quiz/edit.php?cmid=$cmid&addonpage=$newquestioninfo->addonpage&addrandom=1&categoryid=$newquestioninfo->newrandomcategory&randomcount=1&sesskey=".sesskey());
+    }
+    
     //these params are only passed from page request to request while we stay on this page
     //otherwise they would go in question_edit_setup
     $quiz_page = optional_param('quiz_page', 0, PARAM_SEQUENCE);
index 50014e62c4fdfe991003cd797a423983846dfe0b..6d1670e7b2944336d6ce6742c463c97108cb098a 100644 (file)
@@ -244,7 +244,15 @@ $qcobject = new question_category_object(
     null,
     $contexts->having_cap('moodle/question:add'));
 
-$newrandomcategory=quiz_process_randomquestion_formdata($qcobject);
+$newrandomcategory=false;
+$newquestioninfo=quiz_process_randomquestion_formdata($qcobject);
+if($newquestioninfo){
+    $newrandomcategory=$newquestioninfo->newrandomcategory;
+    if (!$newrandomcategory){
+        print_r($newquestioninfo);
+        print_error("cannotcreatecategory");
+    }
+}
 
 if ((optional_param('addrandom', false, PARAM_BOOL) OR $newrandomcategory)
         and confirm_sesskey()) {
index 4c75ff4d2c047e31d3d05385713ffe0a26a1cbc4..9a9aa7336c82d08589569530fb134e3b9c1ce23e 100644 (file)
@@ -649,45 +649,37 @@ function quiz_print_pagecontrols($quiz,$pageurl,$page, $hasattempts){
  * cmid
  *
  * @param object $qcobject
- * @param boolean $redirect if true, redirect to edit.php with GET
- * parameters to add the question
- * @param integer $cmid id of the quiz' course module; required if $redirect=true
- * @return mixed category_id if $redirect==false and operation successfull, returns new category's id. if operation failed, returns false.
+ * @return object an object with properties newrandomcategory and addonpage if operation successful.
+ *      if operation failed, returns false.
  */
-function quiz_process_randomquestion_formdata(&$qcobject, $redirect=false, $cmid=0){
+function quiz_process_randomquestion_formdata(&$qcobject){
     global $CFG,$DB;
     $newrandomcategory=0;
     $addonpage=0;
-    if ($redirect && !$cmid){
-        return false;
-    }
+    $newquestioninfo=false;
     if ($qcobject->catform_rand->is_cancelled()){
         return false;
     }elseif ($catformdata = $qcobject->catform_rand->get_data()) {
+        $newquestioninfo=new stdClass;
         $addonpage=$catformdata->addonpage;
+        $newquestioninfo->addonpage=$catformdata->addonpage;
         if (!$catformdata->id) {//new category
             $newrandomcategory=$qcobject->add_category($catformdata->parent,
                     $catformdata->name, $catformdata->info,true);
             if(!is_null($newrandomcategory)){
                 if (! $newcategory = $DB->get_record('question_categories',
                         array('id'=>$newrandomcategory))) {
-                    print_error('invalidcategoryid');
+                    return false;
                 }
             }else{
-                print_error("cannotcreatecategory");
                 return false;
             }
         } else {
-            print_error("cannotcreatecategory");
             return false;
         }
+        $newquestioninfo->newrandomcategory=$newrandomcategory;
     }
-    if ($redirect && $newrandomcategory){
-        redirect($CFG->wwwroot."/mod/quiz/edit.php?cmid=$cmid&addonpage=$addonpage&addrandom=1&categoryid=$newrandomcategory&randomcount=1&sesskey=".sesskey());
-    }else{
-        return($newrandomcategory);
-
-    }
+    return($newquestioninfo);
 }