It is not very difficult to add the all or nothing flag to your Moodle. Just change the code as follows:
Open the language file:
lang/en_utf8/qtype_multichoice.php
and add the string:
$string['allornothing'] = 'All or nothing';
If you have a german language pack to the same and add 'Alles oder nichts'.
Write a help file and describe what the all or nothing flag does. Save it as:
lang/en_utf8/help/qtype_multichoice/allornothing.html
If you want a german version you can take the one in the attached zip. If you want a correct english version, it would be a better idea to write your own.
In your Moodle database change the table 'question_multichoice'. Add the field 'allornothing' (type int, default 1).
Now open the following files and add the lines with the plus (but not the plus):
question/type/multichoice/edit_multichoice_form.php
:
$menu = array(get_string('answersingleno', 'qtype_multichoice'), get_string('answersingleyes', 'qtype_multichoice'));
$mform->addElement('select', 'single', get_string('answerhowmany', 'qtype_multichoice'), $menu);
$mform->setDefault('single', 1);
+ $mform->addElement('advcheckbox', 'allornothing', get_string('allornothing', 'qtype_multichoice'), null, null, array(0,1));
+ $mform->setDefault('allornothing', 1);
$mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffleanswers', 'qtype_multichoice'), null, null, array(0,1));
$mform->setHelpButton('shuffleanswers', array('multichoiceshuffle', get_string('shuffleanswers','qtype_multichoice'), 'quiz'));
$mform->setDefault('shuffleanswers', 1);
and same file:
$default_values['single'] = $question->options->single;
+ $default_values['allornothing'] = $question->options->allornothing;
$default_values['answernumbering'] = $question->options->answernumbering;
question/type/multichoice/questiontype.php
:
$options->answernumbering = $question->answernumbering;
$options->shuffleanswers = $question->shuffleanswers;
+ if (isset($question->allornothing)) {
+ $options->allornothing = $question->allornothing;
+ }
$options->correctfeedback = trim($question->correctfeedback);
$options->partiallycorrectfeedback = trim($question->partiallycorrectfeedback);
Same file in the function grade_resposes:
} else {
foreach ($state->responses as $response) {
if ($response) {
$state->raw_grade += $question->options->answers[$response]->fraction;
}
}
+ if ($question->options->allornothing && $state->raw_grade < 0.9999) {
+ $state->raw_grade = 0;
+ }
}
Same file in the function backup:
fwrite ($bf,full_tag("SHUFFLEANSWERS",$level+1,false,$multichoice->shuffleanswers));
+ fwrite ($bf,full_tag("ALLORNOTHING",$level+1,false,$multichoice->allornothing));
fwrite ($bf,full_tag("CORRECTFEEDBACK",$level+1,false,$multichoice->correctfeedback));
And in the function restore:
$multichoice->single = backup_todb($mul_info['#']['SINGLE']['0']['#']);
+ $multichoice->allornothing = backup_todb($mul_info['#']['ALLORNOTHING']['0']['#']);
$multichoice->shuffleanswers = isset($mul_info['#']['SHUFFLEANSWERS']['0']['#'])?backup_todb($mul_info['#']['SHUFFLEANSWERS']['0']['#']):'';
To make sure that Moodle-XML-format works with the new flag open question/format/xml/format.php
and add:
$qo->answernumbering = $this->getpath( $question, array('#','answernumbering',0,'#'), 'abc' );
$qo->shuffleanswers = $this->trans_single($shuffleanswers);
+ $allornothing = $this->getpath( $question, array('#','allornothing',0,'#'), 'false' );
+ $qo->allornothing = $this->trans_single($allornothing);
$qo->correctfeedback = $this->getpath( $question, array('#','correctfeedback',0,'#','text',0,'#'), '', true );
And in the same file:
case MULTICHOICE:
$expout .= " <single>".$this->get_single($question->options->single)."</single>\n";
$expout .= " <shuffleanswers>".$this->get_single($question->options->shuffleanswers)."</shuffleanswers>\n";
+ $expout .= " <allornothing>".$this->get_single($question->options->allornothing)."</allornothing>\n";
$expout .= " <correctfeedback>".$this->writetext($question->options->correctfeedback, 3)."</correctfeedback>\n";
You can also set a new option in the import form to overrule this flag if someone has a format without allornothing (like GIFT) and doesn't like your default value. To do this change:
question/import_form.php
:
$mform->disabledIf('categorygroup', 'catfromfile', 'notchecked');
$mform->setDefault('catfromfile', 1);
$mform->setDefault('contextfromfile', 1);
+ $allornothing = array();
+ $allornothing['default'] = get_string('default');
+ $allornothing['true'] = get_string('yes');
+ $allornothing['false'] = get_string('no');
+ $mform->addElement('select', 'allornothing', get_string('allornothing','qtype_multichoice'), $allornothing);
+ $mform->setHelpButton('allornothing', array('allornothing', get_string('allornothing','qtype_multichoice'), 'qtype_multichoice'));
$matchgrades = array();
$matchgrades['error'] = get_string('matchgradeserror','quiz');
question/import.php:
$qformat->setRealfilename($realfilename);
$qformat->setMatchgrades($form->matchgrades);
+ $qformat->setAllornothing($form->allornothing);
$qformat->setCatfromfile(!empty($form->catfromfile));
$qformat->setContextfromfile(!empty($form->contextfromfile));
question/format.php
function setMatchgrades( $matchgrades ) {
$this->matchgrades = $matchgrades;
}
+ /**
+ * set allornothing
+ * @param string allornothing
+ */
+ function setAllornothing( $allornothing ) {
+ if ($allornothing == 'true') {
+ $this->allornothing = true;
+ } else if ($allornothing == 'false') {
+ $this->allornothing = false;
+ }
+ }
This is all. If it doesn't work, feel free to contact me and complain. The files I attached should be compatible with 1.9.4 but be careful, there could be other local changes in them.
It is not very difficult to add the all or nothing flag to your Moodle. Just change the code as follows:
Open the language file:
lang/en_utf8/qtype_multichoice.php
and add the string:
If you have a german language pack to the same and add 'Alles oder nichts'.
Write a help file and describe what the all or nothing flag does. Save it as:
lang/en_utf8/help/qtype_multichoice/allornothing.html
If you want a german version you can take the one in the attached zip. If you want a correct english version, it would be a better idea to write your own.
In your Moodle database change the table 'question_multichoice'. Add the field 'allornothing' (type int, default 1).
Now open the following files and add the lines with the plus (but not the plus):
question/type/multichoice/edit_multichoice_form.php
:
$menu = array(get_string('answersingleno', 'qtype_multichoice'), get_string('answersingleyes', 'qtype_multichoice')); $mform->addElement('select', 'single', get_string('answerhowmany', 'qtype_multichoice'), $menu); $mform->setDefault('single', 1); + $mform->addElement('advcheckbox', 'allornothing', get_string('allornothing', 'qtype_multichoice'), null, null, array(0,1)); + $mform->setDefault('allornothing', 1); $mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffleanswers', 'qtype_multichoice'), null, null, array(0,1)); $mform->setHelpButton('shuffleanswers', array('multichoiceshuffle', get_string('shuffleanswers','qtype_multichoice'), 'quiz')); $mform->setDefault('shuffleanswers', 1);and same file:
$default_values['single'] = $question->options->single; + $default_values['allornothing'] = $question->options->allornothing; $default_values['answernumbering'] = $question->options->answernumbering;question/type/multichoice/questiontype.php
:
$options->answernumbering = $question->answernumbering; $options->shuffleanswers = $question->shuffleanswers; + if (isset($question->allornothing)) { + $options->allornothing = $question->allornothing; + } $options->correctfeedback = trim($question->correctfeedback); $options->partiallycorrectfeedback = trim($question->partiallycorrectfeedback);Same file in the function grade_resposes:
Same file in the function backup:
And in the function restore:
$multichoice->single = backup_todb($mul_info['#']['SINGLE']['0']['#']); + $multichoice->allornothing = backup_todb($mul_info['#']['ALLORNOTHING']['0']['#']); $multichoice->shuffleanswers = isset($mul_info['#']['SHUFFLEANSWERS']['0']['#'])?backup_todb($mul_info['#']['SHUFFLEANSWERS']['0']['#']):'';To make sure that Moodle-XML-format works with the new flag open question/format/xml/format.php
and add:
And in the same file:
You can also set a new option in the import form to overrule this flag if someone has a format without allornothing (like GIFT) and doesn't like your default value. To do this change:
question/import_form.php
:
$mform->disabledIf('categorygroup', 'catfromfile', 'notchecked'); $mform->setDefault('catfromfile', 1); $mform->setDefault('contextfromfile', 1); + $allornothing = array(); + $allornothing['default'] = get_string('default'); + $allornothing['true'] = get_string('yes'); + $allornothing['false'] = get_string('no'); + $mform->addElement('select', 'allornothing', get_string('allornothing','qtype_multichoice'), $allornothing); + $mform->setHelpButton('allornothing', array('allornothing', get_string('allornothing','qtype_multichoice'), 'qtype_multichoice')); $matchgrades = array(); $matchgrades['error'] = get_string('matchgradeserror','quiz');question/import.php:
$qformat->setRealfilename($realfilename); $qformat->setMatchgrades($form->matchgrades); + $qformat->setAllornothing($form->allornothing); $qformat->setCatfromfile(!empty($form->catfromfile)); $qformat->setContextfromfile(!empty($form->contextfromfile));question/format.php
function setMatchgrades( $matchgrades ) { $this->matchgrades = $matchgrades; } + /** + * set allornothing + * @param string allornothing + */ + function setAllornothing( $allornothing ) { + if ($allornothing == 'true') { + $this->allornothing = true; + } else if ($allornothing == 'false') { + $this->allornothing = false; + } + }This is all. If it doesn't work, feel free to contact me and complain. The files I attached should be compatible with 1.9.4 but be careful, there could be other local changes in them.
$menu = array(get_string('answersingleno', 'qtype_multichoice'), get_string('answersingleyes', 'qtype_multichoice')); $mform->addElement('select', 'single', get_string('answerhowmany', 'qtype_multichoice'), $menu); $mform->setDefault('single', 1); + $mform->addElement('advcheckbox', 'allornothing', get_string('allornothing', 'qtype_multichoice'), null, null, array(0,1)); + $mform->setDefault('allornothing', 1); $mform->addElement('advcheckbox', 'shuffleanswers', get_string('shuffleanswers', 'qtype_multichoice'), null, null, array(0,1)); $mform->setHelpButton('shuffleanswers', array('multichoiceshuffle', get_string('shuffleanswers','qtype_multichoice'), 'quiz')); $mform->setDefault('shuffleanswers', 1);$default_values['single'] = $question->options->single; + $default_values['allornothing'] = $question->options->allornothing; $default_values['answernumbering'] = $question->options->answernumbering;$options->answernumbering = $question->answernumbering; $options->shuffleanswers = $question->shuffleanswers; + if (isset($question->allornothing)) { + $options->allornothing = $question->allornothing; + } $options->correctfeedback = trim($question->correctfeedback); $options->partiallycorrectfeedback = trim($question->partiallycorrectfeedback);$multichoice->single = backup_todb($mul_info['#']['SINGLE']['0']['#']); + $multichoice->allornothing = backup_todb($mul_info['#']['ALLORNOTHING']['0']['#']); $multichoice->shuffleanswers = isset($mul_info['#']['SHUFFLEANSWERS']['0']['#'])?backup_todb($mul_info['#']['SHUFFLEANSWERS']['0']['#']):'';$mform->disabledIf('categorygroup', 'catfromfile', 'notchecked'); $mform->setDefault('catfromfile', 1); $mform->setDefault('contextfromfile', 1); + $allornothing = array(); + $allornothing['default'] = get_string('default'); + $allornothing['true'] = get_string('yes'); + $allornothing['false'] = get_string('no'); + $mform->addElement('select', 'allornothing', get_string('allornothing','qtype_multichoice'), $allornothing); + $mform->setHelpButton('allornothing', array('allornothing', get_string('allornothing','qtype_multichoice'), 'qtype_multichoice')); $matchgrades = array(); $matchgrades['error'] = get_string('matchgradeserror','quiz');$qformat->setRealfilename($realfilename); $qformat->setMatchgrades($form->matchgrades); + $qformat->setAllornothing($form->allornothing); $qformat->setCatfromfile(!empty($form->catfromfile)); $qformat->setContextfromfile(!empty($form->contextfromfile));function setMatchgrades( $matchgrades ) { $this->matchgrades = $matchgrades; } + /** + * set allornothing + * @param string allornothing + */ + function setAllornothing( $allornothing ) { + if ($allornothing == 'true') { + $this->allornothing = true; + } else if ($allornothing == 'false') { + $this->allornothing = false; + } + }