quiz settings: MDL-17333 Resolve the interrelations between shufflequestions and questionsperpage.

* change the wording of the settings.
* add a repaginate now checkbox (disabled if shuffle is on).
* JavaScript to automatically check the checkbox when qpp changes.
* (remove some irrelevant return value checks now we use exceptions.)
This commit is contained in:
tjhunt 2009-03-17 07:08:33 +00:00
parent 64115dc8b3
commit eeab18f0b3
4 changed files with 69 additions and 20 deletions

View file

@ -64,6 +64,7 @@ $string['answerswithacceptederrormarginmustbenumeric'] = 'Answers with accepted
$string['answertoolong'] = 'Answer too long after line $a (255 char. max)';
$string['aon'] = 'AON format';
$string['areyousureremoveselected'] = 'Are you sure you want to remove all the selected questions?';
$string['asshownoneditscreen'] = 'As shown on the edit screen';
$string['attempt'] = 'Attempt $a';
$string['attemptalreadyclosed'] = 'This attempt has already be finished.';
$string['attemptclosed'] = 'Attempt has not closed yet';
@ -283,6 +284,8 @@ $string['event6'] = 'Close&Grade';
$string['event7'] = 'Submit';
$string['event8'] = 'Close';
$string['event9'] = 'Manual Grade';
$string['everynquestions'] = 'Every $a questions';
$string['everyquestion'] = 'Every question';
$string['everythingon'] = 'Everything on';
$string['examview'] = 'Examview';
$string['export'] = 'Export';
@ -430,6 +433,7 @@ $string['multichoice'] = 'Multiple Choice';
$string['multipleanswers'] = 'Choose at least one answer.';
$string['multiplier'] = 'Multiplier';
$string['name'] = 'Name';
$string['neverallononepage'] = 'Never, all questions on one page';
$string['newattemptfail'] = 'Error: Could not start a new attempt at the quiz';
$string['newpageevery'] = 'Automatically start a new page';
$string['noanswers'] = 'No answers were selected!';
@ -522,6 +526,7 @@ $string['questionname'] = 'Question name';
$string['questionnametoolong'] = 'Question name too long at line $a (255 char. max). It has been truncated.';
$string['questionno'] = 'Question $a';
$string['questionnotloaded'] = 'Question $a has not been loaded from the database';
$string['questionorder'] = 'Question order';
$string['questions'] = 'Questions';
$string['questionsinclhidden'] = 'Questions (including hidden)';
$string['questionsinthisquiz'] = 'Questions in this quiz';
@ -597,6 +602,7 @@ $string['reorderquestions'] = 'Reorder questions';
$string['reordertool'] = 'Show the reordering tool';
$string['repaginate'] = 'Repaginate with $a questions per page';
$string['repaginatecommand'] = 'Repaginate';
$string['repaginatenow'] = 'Repaginate now';
$string['replace'] = 'Replace';
$string['replacementoptions'] = 'Replacement Options';
$string['report'] = 'Reports';
@ -675,6 +681,7 @@ $string['showteacherattempts'] = 'Show teacher attempts';
$string['showuserpicture'] = 'Show the user\'s picture';
$string['shuffle'] = 'Shuffle';
$string['shuffleanswers'] = 'Shuffle answers';
$string['shuffledrandomly'] = 'Shuffled randomly';
$string['shufflequestions'] = 'Shuffle questions';
$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';

View file

@ -21,9 +21,9 @@ function quiz_edit_init() {
//show the dialog and depending on from which form (corresponding
// a specific quiz page) it was triggered, set the value of the form's
// rqpage input element to the form number
YAHOO.util.Event.addListener(this.dialoglisteners, "click",
YAHOO.util.Event.addListener(quiz_edit_config.dialoglisteners, "click",
function(e){
this.show();
this.show();
var rbutton = YAHOO.util.Event.getTarget(e);
var rbform = YAHOO.util.Dom.getAncestorByClassName(rbutton,"randomquestionform");
//this depends on the fact that the element hierarchy be:
@ -91,5 +91,31 @@ function quiz_edit_init() {
}
YAHOO.util.Event.onDOMReady(quiz_edit_init, quiz_edit_config, true);
YAHOO.util.Dom.setStyle('repaginatedialog', 'display', 'block');
function quiz_settings_init() {
var repaginatecheckbox = document.getElementById('id_repaginatenow');
if (!repaginatecheckbox) {
// This checkbox does not appear on the create new quiz form.
return;
}
var qppselect = document.getElementById('id_questionsperpage');
var qppinitialvalue = qppselect.value;
YAHOO.util.Event.addListener([qppselect, 'id_shufflequestions'] , 'change', function() {
setTimeout(function() { // Annoyingly, this handler runs before the formlib disabledif code, hence the timeout.
if (!repaginatecheckbox.disabled) {
repaginatecheckbox.checked = qppselect.value != qppinitialvalue;
}
}, 50);
});
}
function quiz_edit_generic_init() {
switch (document.body.id) {
case 'mod-quiz-edit':
quiz_edit_init();
break;
case 'mod-quiz-mod':
quiz_settings_init();
}
}
YAHOO.util.Event.onDOMReady(quiz_edit_generic_init);

View file

@ -118,9 +118,7 @@ function quiz_add_instance($quiz) {
}
// Try to store it in the database.
if (!$quiz->id = $DB->insert_record("quiz", $quiz)) {
return false;
}
$quiz->id = $DB->insert_record('quiz', $quiz);
// Do the processing required after an add or an update.
quiz_after_add_or_update($quiz);
@ -136,8 +134,8 @@ function quiz_add_instance($quiz) {
* @param object $quiz the data that came from the form.
* @return mixed true on success, false or a string error message on failure.
*/
function quiz_update_instance($quiz) {
global $DB;
function quiz_update_instance($quiz, $mform) {
global $CFG, $DB;
// Process the options from the form.
$result = quiz_process_options($quiz);
@ -145,11 +143,17 @@ function quiz_update_instance($quiz) {
return $result;
}
// Repaginate, if asked to.
if (!$quiz->shufflequestions && !empty($quiz->repaginatenow)) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
$quiz->questions = $DB->get_field('quiz', 'questions', array('id' => $quiz->instance));
$quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
}
unset($quiz->repaginatenow);
// Update the database.
$quiz->id = $quiz->instance;
if (!$DB->update_record("quiz", $quiz)) {
return false; // some error occurred
}
$DB->update_record('quiz', $quiz);
// Do the processing required after an add or an update.
quiz_after_add_or_update($quiz);

View file

@ -94,23 +94,35 @@ class mod_quiz_mod_form extends moodleform_mod {
$mform->addElement('header', 'layouthdr', get_string('layout', 'quiz'));
/// Shuffle questions.
$mform->addElement('selectyesno', 'shufflequestions', get_string('shufflequestions', 'quiz'));
$shuffleoptions = array(0 => get_string('asshownoneditscreen', 'quiz'), 1 => get_string('shuffledrandomly', 'quiz'));
$mform->addElement('select', 'shufflequestions', get_string('questionorder', 'quiz'), $shuffleoptions, array('id' => 'id_shufflequestions'));
$mform->setHelpButton('shufflequestions', array('shufflequestions', get_string('shufflequestions','quiz'), 'quiz'));
$mform->setAdvanced('shufflequestions', $quizconfig->fix_shufflequestions);
$mform->setDefault('shufflequestions', $quizconfig->shufflequestions);
/// Questions per page.
$perpage = array();
$perpage[0] = get_string('never');
$perpage[1] = get_string('aftereachquestion', 'quiz');
$pageoptions = array();
$pageoptions[0] = get_string('neverallononepage', 'quiz');
$pageoptions[1] = get_string('everyquestion', 'quiz');
for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION; ++$i) {
$perpage[$i] = get_string('afternquestions', 'quiz', $i);
$pageoptions[$i] = get_string('everynquestions', 'quiz', $i);
}
$mform->addElement('select', 'questionsperpage', get_string('newpageevery', 'quiz'), $perpage);
$mform->setHelpButton('questionsperpage', array('questionsperpage', get_string('newpageevery', 'quiz'), 'quiz'));
$mform->setAdvanced('questionsperpage', $quizconfig->fix_questionsperpage);
$pagegroup = array();
$pagegroup[] = &$mform->createElement('select', 'questionsperpage', get_string('newpage', 'quiz'), $pageoptions, array('id' => 'id_questionsperpage'));
$mform->setDefault('questionsperpage', $quizconfig->questionsperpage);
if (!empty($this->_cm)) {
$pagegroup[] = &$mform->createElement('checkbox', 'repaginatenow', '', get_string('repaginatenow', 'quiz'), array('id' => 'id_repaginatenow'));
$mform->disabledIf('repaginatenow', 'shufflequestions', 'eq', 1);
require_js(array('yui_yahoo', 'yui_dom', 'yui_event'));
require_js('mod/quiz/edit.js');
}
$mform->addGroup($pagegroup, 'questionsperpagegrp', get_string('newpage', 'quiz'), null, false);
$mform->setHelpButton('questionsperpagegrp', array('questionsperpage', get_string('newpageevery', 'quiz'), 'quiz'));
$mform->setAdvanced('questionsperpagegrp', $quizconfig->fix_questionsperpage);
//-------------------------------------------------------------------------------
$mform->addElement('header', 'interactionhdr', get_string('questionbehaviour', 'quiz'));