Index: theme/standard/styles_color.css =================================================================== RCS file: /cvsroot/moodle/moodle/theme/standard/styles_color.css,v retrieving revision 1.197 diff -u -r1.197 styles_color.css --- theme/standard/styles_color.css 25 Feb 2009 07:14:05 -0000 1.197 +++ theme/standard/styles_color.css 6 Mar 2009 06:55:30 -0000 @@ -1114,8 +1114,11 @@ #mod-quiz-report .negcovar{ border :medium solid pink; } +#mod-quiz-edit .quizeditwarnings { + background-color: #fdd; +} #mod-quiz-edit .statusdisplay{ - background-color:#ffc; +/* background-color: #ffc;*/ } #mod-quiz-edit div.quizpage span.pagetitle{ color:#006; Index: theme/standard/styles_layout.css =================================================================== RCS file: /cvsroot/moodle/moodle/theme/standard/styles_layout.css,v retrieving revision 1.679 diff -u -r1.679 styles_layout.css --- theme/standard/styles_layout.css 3 Mar 2009 07:47:32 -0000 1.679 +++ theme/standard/styles_layout.css 6 Mar 2009 06:55:31 -0000 @@ -4622,14 +4622,16 @@ padding-right:1em; } +#mod-quiz-edit .quizeditwarnings p { + margin: 0.2em; +} +#mod-quiz-edit .quizeditwarnings, #mod-quiz-edit .statusdisplay{ - clear:both; - display:block; - border:0.2em #FFF solid; - margin-bottom:0.3em; - margin-right:1em; - margin-top:0.3em; - padding:0.1em; + clear: both; + display: block; + border: 0.2em solid #FFF; + margin-bottom: 0.3em 1em 0.3em 0; + padding: 0 0.1em; } #mod-quiz-edit div.quizpage{ display:block; Index: mod/quiz/locallib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/locallib.php,v retrieving revision 1.174 diff -u -r1.174 locallib.php --- mod/quiz/locallib.php 27 Feb 2009 08:45:05 -0000 1.174 +++ mod/quiz/locallib.php 6 Mar 2009 06:55:30 -0000 @@ -222,6 +222,15 @@ } } +/** + * @param integer $quizid The quiz id. + * @return boolean whether this quiz has any (non-preview) attempts. + */ +function quiz_has_attempts($quizid) { + global $DB; + return $DB->record_exists('quiz_attempts', array('quiz' => $quizid, 'preview' => 0)); +} + /// Functions to do with quiz layout and pages //////////////////////////////// /** Index: mod/quiz/editlib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/editlib.php,v retrieving revision 1.118 diff -u -r1.118 editlib.php --- mod/quiz/editlib.php 6 Mar 2009 04:06:48 -0000 1.118 +++ mod/quiz/editlib.php 6 Mar 2009 06:55:29 -0000 @@ -356,10 +356,10 @@ '' . '
'; + $strreorderquestions . '" />'; $reordercontrols2bottom = '
' . '
' . + $strreorderquestions . '" />
' . get_string('moveselectedonpage', 'quiz', $a) . ' ' . '
'; @@ -482,7 +482,7 @@ echo $questioncountstring; $qno += $question->length; } else { - echo "$reordercheckboxlabel * $reordercheckboxlabelclose" . + echo "$reordercheckboxlabel ? $reordercheckboxlabelclose" . " $reordercheckbox"; } @@ -528,13 +528,13 @@
- :
+ :
hidden_params_out(); ?> decimalpoints + 2) . '" - value="' . (0 + $quiz->grades[$qnum]) . + echo ''; ?> @@ -554,10 +554,10 @@ ?>
id . '" size="2" value="' . (10*$count + 10) . '" tabindex="' . ($lastindex + $qno) . - '" ' . $movedisabled . ' />'; + '" />'; ?> @@ -597,18 +597,18 @@ //a page break: end the existing page. if ($qnum == 0) { if ($pageopen) { - if (!$reordertool) { + if (!$reordertool && !($quiz->shufflequestions && $i < $questiontotalcount - 1)) { quiz_print_pagecontrols($quiz, $pageurl, $pagecount, $hasattempts); - } else if ($i<$questiontotalcount - 1) { + } else if ($i < $questiontotalcount - 1) { //do not include the last page break for reordering //to avoid creating a new extra page in the end - echo ''; } echo "
"; - if (!$reordertool) { + if (!$reordertool && !$quiz->shufflequestions) { echo "
"; print_single_button($pageurl->out(true), array('cmid' => $quiz->cmid, @@ -623,7 +623,6 @@ $hasattempts); echo "
"; } - $pagecount; $pageopen = false; $count++; } @@ -1202,32 +1201,6 @@ $dates = implode(', ', $dates); echo ' | ' . $currentstatus . ''; - // If questions are shuffled, notify the user about the - // question order not making much sense - $updateurl = new moodle_url("$CFG->wwwroot/course/mod.php", - array('return' => 'true', 'update' => $quiz->cmid, 'sesskey' => sesskey())); - echo '
'; - print_string('updatethis', '', get_string('modulename', 'quiz')); - echo ': '; - if ($quiz->shufflequestions) { - echo "*"; - } - if ($quiz->shufflequestions) { - $shuffleqs= get_string('yes'); - } - else { - $shuffleqs= get_string('no'); - } - echo get_string('shufflequestionsx', 'quiz', $shuffleqs); - echo " | "; - $questionsperpagebool = ($quiz->questionsperpage < 1) ? 0 : 1; - if ($questionsperpagebool) { - $valquestionsparpage = $quiz->questionsperpage; - } else { - $valquestionsparpage = get_string('unlimited'); - } - print_string('questionsperpagex', 'quiz', $valquestionsparpage); - ?>
id); if ($quiz_reordertool != 0) { $thispageurl->param('reordertool', $quiz_reordertool); @@ -155,6 +155,7 @@ } $questionbank = new quiz_question_bank_view($contexts, $thispageurl, $course, $cm); +$questionbank->set_quiz_has_attempts($quizhasattempts); // Log this visit. add_to_log($cm->course, 'quiz', 'editquestions', @@ -163,11 +164,16 @@ // You need mod/quiz:manage in addition to question capabilities to access this page. require_capability('mod/quiz:manage', $contexts->lowest()); -if (isset($quiz->instance) && empty($quiz->grades)) { // Construct an array to hold all the grades. +if (empty($quiz->grades)) { // Construct an array to hold all the grades. $quiz->grades = quiz_get_all_question_grades($quiz); } // Process commands ============================================================ +if ($quiz->shufflequestions) { + // Strip page breaks before processing actions, so that re-ordering works + // as expected when shuffle questions is on. + $quiz->questions = quiz_repaginate($quiz->questions, 0); +} // Get the list of question ids had their check-boxes ticked. $selectedquestionids = array(); @@ -343,97 +349,79 @@ if (optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) { $oldquestions = explode(',', $quiz->questions); // the questions in the old order $questions = array(); // for questions in the new order - $rawgrades = (array) data_submitted(); + $rawdata = (array) data_submitted(); $moveonpagequestions = array(); - $moveselectedonpage = 0; - $moveselectedonpagetop = optional_param('moveselectedonpagetop', 0, PARAM_INT); - $moveselectedonpagebottom = optional_param("moveselectedonpagebottom", 0, PARAM_INT); - if ($moveselectedonpagetop) { - $moveselectedonpage = $moveselectedonpagetop; - } else if($moveselectedonpagebottom) { - $moveselectedonpage = $moveselectedonpagebottom; + $moveselectedonpage = optional_param('moveselectedonpagetop', 0, PARAM_INT); + if (!$moveselectedonpage) { + $moveselectedonpage = optional_param('moveselectedonpagebottom', 0, PARAM_INT); } - foreach ($rawgrades as $key => $value) { + foreach ($rawdata as $key => $value) { if (preg_match('!^g([0-9]+)$!', $key, $matches)) { /// Parse input for question -> grades - $key = $matches[1]; - $quiz->grades[$key] = $value; - quiz_update_question_instance($quiz->grades[$key], $key, $quiz->instance); + $questionid = $matches[1]; + $quiz->grades[$questionid] = $value; + quiz_update_question_instance($quiz->grades[$questionid], $questionid, $quiz->id); + quiz_delete_previews($quiz); + quiz_update_sumgrades($quiz); - } else if (preg_match('!^o([0-9]+)$!', $key, $matches)) { + } else if (preg_match('!^o(pg)?([0-9]+)$!', $key, $matches)) { /// Parse input for ordering info - $key = $matches[1]; - // Make sure two questions don't overwrite each other. - // If we get a second - // question with the same position, shift the second one - // along to the next gap. + $questionid = $matches[2]; + // Make sure two questions don't overwrite each other. If we get a second + // question with the same position, shift the second one along to the next gap. while (array_key_exists($value, $questions)) { $value++; } - $questions[$value] = $oldquestions[$key]; + if ($matches[1]) { + // This is a page-break entry. + $questions[$value] = 0; + } else { + $questions[$value] = $questionid; + } } } // If ordering info was given, reorder the questions if ($questions) { ksort($questions); - $quiz->questions = implode(',', $questions) . ',0'; - $quiz->questions = quiz_clean_layout($quiz->questions); + $questions[] = 0; + $quiz->questions = implode(',', $questions); + quiz_save_new_layout($quiz); + quiz_delete_previews($quiz); } //get a list of questions to move, later to be added in the appropriate //place in the string if ($moveselectedonpage) { $questions = explode(',', $quiz->questions); - foreach ($selectedquestionids as $page => $question) { - //remove the questions from their original positions first - while (($delpos = array_search($question, $questions)) !== FALSE) { - //in case there are multiple instances because of an error, remove all - unset($questions[$delpos]); + $newquestions = array(); + //remove the questions from their original positions first + foreach ($questions as $questionid) { + if (!in_array($questionid, $selectedquestionids)) { + $newquestions[] = $questionid; } } - //reindex - foreach ($questions as $question) { - $newquestions[] = $question; - } $questions = $newquestions; - //find all pagebreaks - $pagecount = quiz_number_of_pages($quiz->questions); - if ($moveselectedonpage > $pagecount) { - // move to the last page is a page beyond last page was requested - $moveselectedonpage = $pagecount; - } - if ($moveselectedonpage < 1) { - $moveselectedonpage = 1; - } - $pagebreakpositions = array_keys($questions, 0); //move to the end of the selected page + $pagebreakpositions = array_keys($questions, 0); + $numpages = count($pagebreakpositions); + // Ensure the target page number is in range. + $moveselectedonpage = max(1, min($moveselectedonpage, $pagebreakpositions)); $moveselectedpos = $pagebreakpositions[$moveselectedonpage - 1]; - foreach ($selectedquestionids as $question) { - array_splice($questions, $moveselectedpos, 0, $question); - //place the next one after this one: - $moveselectedpos++; - } + array_splice($questions, $moveselectedpos, 0, $selectedquestionids); $quiz->questions = implode(',', $questions); + quiz_save_new_layout($quiz); + quiz_delete_previews($quiz); } - if ($moveselectedonpage || $questions) { - if (!$DB->set_field('quiz', 'questions', $quiz->questions, - array('id' => $quiz->instance))) { - print_error('cannotsavequestion', 'quiz'); - } - } + // If rescaling is required save the new maximum $maxgrade = optional_param('maxgrade', -1, PARAM_NUMBER); if ($maxgrade >= 0) { - if (!quiz_set_grade($maxgrade, $quiz)) { - print_error('cannotsetgrade', 'quiz'); - } + quiz_set_grade($maxgrade, $quiz); } - quiz_update_sumgrades($quiz); - quiz_delete_previews($quiz); redirect($thispageurl->out()); } @@ -441,11 +429,6 @@ // End of process commands ===================================================== -if (isset($quiz->instance) && $DB->record_exists_select('quiz_attempts', - 'quiz = ? AND preview = 0', array($quiz->instance))) { - $questionbank->set_quiz_has_attempts(true); -} - // Print the header. $questionbankmanagement = ''. @@ -467,7 +450,7 @@ // Initialise the JavaScript. $quizeditconfig = new stdClass; $quizeditconfig->url = $thispageurl->out(false, array('qbanktool' => '0')); -$quizeditconfig->dialoglisteners =array(); +$quizeditconfig->dialoglisteners = array(); $numberoflisteners = max(quiz_number_of_pages($quiz->questions), 1); for ($pageiter = 1; $pageiter <= $numberoflisteners; $pageiter++) { $quizeditconfig->dialoglisteners[] = 'addrandomdialoglaunch_' . $pageiter; @@ -514,15 +497,11 @@ echo ''; print_side_block_end(); -if (!$quizname = $DB->get_field($cm->modname, 'name', array('id' => $cm->instance))) { - print_error('cannotmodulename'); -} - echo '
'; -$questionsperpagebool = ($quiz->questionsperpage < 1) ? 0 : 1; -if ($questionsperpagebool) { +if ($quiz->shufflequestions) { $repaginatingdisabledhtml = 'disabled="disabled"'; $repaginatingdisabled = true; + $quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage); } else { $repaginatingdisabledhtml = ''; $repaginatingdisabled = false; @@ -532,40 +511,32 @@ get_string('repaginatecommand', 'quiz').'...'; echo '
'; } -print_heading($pagetitle.": ".$quizname, 'left', 2); +print_heading($pagetitle.": ".$quiz->name, 'left', 2); helpbutton('editconcepts', get_string('basicideasofquiz', 'quiz'), 'quiz', true, get_string('basicideasofquiz', 'quiz')); -$notifystring = ''; -if ($quiz_has_attempts) { +$tabindex = 0; +if (!$quiz_reordertool) { + quiz_print_grading_form($quiz, $thispageurl, $tabindex); +} + +$notifystrings = array(); +if ($quizhasattempts) { $string = get_string('cannoteditafterattempts', 'quiz'); $string .= '
' . - quiz_num_attempt_summary($quiz, $cm) . '
' ; - $notifystring .= notify($string, 'notifyproblem', 'center', true); + quiz_num_attempt_summary($quiz, $cm) . '
' ; + $notifystrings[] = $string; } -if ($questionsperpagebool && $quiz_reordertool) { +if ($quiz->shufflequestions) { $updateurl = new moodle_url("$CFG->wwwroot/course/mod.php", array('return' => 'true', 'update' => $quiz->cmid, 'sesskey' => sesskey())); $linkstring = ''; $linkstring .= get_string('updatethis', '', get_string('modulename', 'quiz')); $linkstring .= ''; - $string = get_string('questionsperpageselected', 'quiz', $linkstring); - $notifystring .= notify($string, 'notifyproblem', 'center', true); + $notifystrings[] = get_string('shufflequestionsselected', 'quiz', $linkstring); } -if ($quiz->shufflequestions && $quiz_reordertool) { - $updateurl = new moodle_url("$CFG->wwwroot/course/mod.php", - array('return' => 'true', 'update' => $quiz->cmid, 'sesskey' => sesskey())); - $linkstring = ''; - $linkstring .= get_string('updatethis', '', get_string('modulename', 'quiz')); - $linkstring .= ''; - $string = get_string('shufflequestionsselected', 'quiz', $linkstring); - $notifystring .= notify($string, 'notifyproblem', 'center', true); -} -if (!empty($notifystring)) { - //TODO: make the box closable so it is not in the way - print_box_start(); - echo $notifystring; - print_box_end(); +if (!empty($notifystrings)) { + print_box('

' . implode('

', $notifystrings) . '

', 'quizeditwarnings'); } if ($quiz_reordertool) { @@ -592,18 +563,12 @@ echo ' '; echo ''; } -$tabindex = 0; -if (!$quiz_reordertool) { - quiz_print_grading_form($quiz, $thispageurl, $tabindex); -} quiz_print_status_bar($quiz); -?> -
- -
-'; +quiz_print_question_list($quiz, $thispageurl, true, + $quiz_reordertool, $quiz_qbanktool, $quizhasattempts); +echo ''; // Close
: echo '
'; Index: lang/en_utf8/quiz.php =================================================================== RCS file: /cvsroot/moodle/moodle/lang/en_utf8/quiz.php,v retrieving revision 1.133 diff -u -r1.133 quiz.php --- lang/en_utf8/quiz.php 25 Feb 2009 07:27:02 -0000 1.133 +++ lang/en_utf8/quiz.php 6 Mar 2009 06:55:28 -0000 @@ -376,6 +376,10 @@ $string['itemsourceformat'] = 'Item Source Format'; $string['itemtypes'] = 'Remote Question Types'; $string['lastanswer'] = 'Your last answer was'; +$string['layoutshuffledandpaged'] = 'Questions randomly shuffled with $a questions per page.'; +$string['layoutasshown'] = 'Page layout as shown.'; +$string['layoutasshownwithpages'] = 'Page layout as shown. (Automatic new page every $a questions.)'; +$string['layoutshuffledsinglepage'] = 'Questions randomly shuffled, all on one page.'; $string['learnwise'] = 'Learnwise format'; $string['link'] = 'Link'; $string['listitems'] = 'Listing of Items in Quiz'; @@ -658,8 +662,7 @@ $string['shuffle'] = 'Shuffle'; $string['shuffleanswers'] = 'Shuffle answers'; $string['shufflequestions'] = 'Shuffle questions'; -$string['shufflequestionsx'] = 'Shuffle questions: $a'; -$string['shufflequestionsselected'] = '* Shuffle questions has been set so question order is random. As a result, the button Reorder questions has been disabled. You can change this in $a.'; +$string['shufflequestionsselected'] = 'Shuffle questions has been set, so some actions relating to pages are not available. To change the shuffle option go to $a.'; $string['shufflewithin'] = 'Shuffle within questions'; $string['significantfigures'] = 'with $a'; $string['significantfiguresformat'] = 'significant figures';