mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
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:
parent
64115dc8b3
commit
eeab18f0b3
4 changed files with 69 additions and 20 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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'));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue