From fef9b51dac107ae2f8fe0ba3a646c4b4a324ee8a Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Sat, 5 Mar 2005 12:55:26 +0000 Subject: [PATCH] Now can add a single question to quiz with a single click. --- lang/en/quiz.php | 1 + mod/quiz/edit.php | 27 ++++++++++++++++++++++++++- mod/quiz/locallib.php | 34 ++++++++++++++++++---------------- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/lang/en/quiz.php b/lang/en/quiz.php index 1fb53e3c565..5ba553dd64d 100644 --- a/lang/en/quiz.php +++ b/lang/en/quiz.php @@ -10,6 +10,7 @@ $string['addquestionstoquiz'] = 'Add questions to current quiz'; $string['addrandom1'] = ' Add '; $string['addrandom2'] = 'random questions '; $string['addselectedtoquiz'] = 'Add selected to quiz'; +$string['addtoquiz'] = 'Add to quiz'; $string['affectedstudents'] = 'Affected $a'; $string['aiken'] = 'Aiken format'; $string['allinone'] = 'Unlimited'; diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index ab80eacf6d6..1014ab993ff 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -101,7 +101,32 @@ } } - if (isset($_REQUEST['add']) and confirm_sesskey()) { /// Add a question to the current quiz + if (isset($_REQUEST['addquestion']) and confirm_sesskey()) { /// Add a single question to the current quiz + + // add question to quiz->questions + $key = $_REQUEST['addquestion']; + if (!empty($modform->questions)) { + $questions = explode(",", $modform->questions); + } + $questions[] = $key; + $modform->questions = implode(",", $questions); + if (!set_field('quiz', 'questions', $modform->questions, 'id', $modform->instance)) { + error('Could not save question list'); + } + + // update question grades + $questionrecord = get_record("quiz_questions", "id", $key); + if (!empty($questionrecord->defaultgrade)) { + $modform->grades[$key] = $questionrecord->defaultgrade; + } else if ($questionrecord->qtype == DESCRIPTION){ + $modform->grades[$key] = 0; + } else { + $modform->grades[$key] = 1; + } + quiz_questiongrades_update($modform->grades, $modform->instance); + } + + if (isset($_REQUEST['add']) and confirm_sesskey()) { /// Add selected questions to the current quiz $rawquestions = $_POST; if (!empty($modform->questions)) { $questions = explode(",", $modform->questions); diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 2cb52d3d22e..41c70ed9d89 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -1338,8 +1338,10 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse= $strquestionname = get_string("questionname", "quiz"); $strdelete = get_string("delete"); $stredit = get_string("edit"); + $straction = get_string("action"); $straddselectedtoquiz = get_string("addselectedtoquiz", "quiz"); + $straddtoquiz = get_string("addtoquiz", "quiz"); $strtype = get_string("type", "quiz"); $strcreatemultiple = get_string("createmultiple", "quiz"); $strpreview = get_string("preview","quiz"); @@ -1412,32 +1414,22 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse= echo "sesskey\">"; echo ""; echo ""; - if ($quizselected) { - echo ""; + if ($canedit) { + echo ""; } echo ""; - if ($canedit) { - echo ""; - } echo "\n"; foreach ($questions as $question) { if ($question->qtype == RANDOM) { //continue; } echo "\n"; - if ($quizselected) { - echo ""; - } - echo "\n"; - echo "\n"; if ($canedit) { echo "\n"; } + + echo "\n"; + echo "\n"; echo "\n"; } $numquestions = count_records_select('quiz_questions', "category IN ($categorylist) AND qtype != '".RANDOM."'");
$strselect$straction$strquestionname$strtype$stredit
"; - echo "id\" value=\"1\" />\n"; - echo "".$question->name."\n"; - quiz_print_question_icon($question, $canedit); - echo "\n"; - echo "id&delete=$question->id\">\n\"$strdelete\" "; + if ($quizselected) { + echo "id&sesskey=$USER->sesskey\">\"$straddtoquiz\" "; + } echo "id','$strpreview','scrollbars=yes,resizable=yes,width=700,height=480', false)\">\"$strpreview\" "; echo "id\">id&hide=$hideshow&sesskey=$USER->sesskey\">\"$strhideshow\""; + echo "id&delete=$question->id\">\n\"$strdelete\""; + if ($quizselected) { + echo " id\" value=\"1\" />"; + } echo "".$question->name."\n"; + quiz_print_question_icon($question, $canedit); + echo "