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 '
';
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';