* 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.)
$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';
$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';
$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!';
$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';
$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';
$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';
//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:
}
-YAHOO.util.Event.onDOMReady(quiz_edit_init, quiz_edit_config, true);
-YAHOO.util.Dom.setStyle('repaginatedialog', 'display', 'block');
\ No newline at end of file
+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);
}
// 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);
* @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);
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);
$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'));