From c7c7f25a840346b15e80f618042fbd06733700d4 Mon Sep 17 00:00:00 2001 From: pilpi Date: Fri, 28 Nov 2008 17:29:04 +0000 Subject: [PATCH] quiz editing: MDL-17294 changed quiz_process_randomquestion_formdata to always return (instead of sometimes redirecting) --- mod/quiz/addrandom.php | 7 +++++-- mod/quiz/edit.php | 10 +++++++++- mod/quiz/editlib.php | 26 +++++++++----------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/mod/quiz/addrandom.php b/mod/quiz/addrandom.php index bb0e6d7030..63bee48d3c 100644 --- a/mod/quiz/addrandom.php +++ b/mod/quiz/addrandom.php @@ -30,8 +30,11 @@ //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); diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 50014e62c4..6d1670e7b2 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -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()) { diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index 4c75ff4d2c..9a9aa7336c 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -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); } -- 2.39.5