- Question – Shuffle Answers Default changed to true for GIFT Import to allow imported questions to be shuffled. I have requested this be changed in Moodle core (bug #6768). Further I have requested that GIFT format be expanded to allow for this option to be specifically set during import and export (bug #6769)
a. \question\format.php
i. change line 179 from
1. $question->shuffleanswers = 0;
ii. to
1. $question->shuffleanswers = 1;
Hi
The default to not shuffle answers is a pain when you have hundreds of questions to write. Looking back through posts it says you can change the default by editing the file mod.html in moodle/mod/quiz. Is this the only file our administrator would need to edit, so that all questions (uploaded from file or created manually) would show Shuffle Answers with YES by default?
regards
Paul
I think you are right. Unless anybody objects I will change it to default on. This will affect all import formats not just GIFT of course.
I am raising a follow up question as to whether it is better for it to be a site variable or a course variable. I think making it a course variable would provide greater flexibility. I am also questioning whether the naming of the variable would not more accurately be questions->shuffleanswers rather than quiz_shuffleanswers because we are talking about an option for the question. It really is a question option/variable and not a quiz variable. Both the quiz and lesson modules could check to see whether a particular question is set to be 'shuffle-able'. When Tim gets a chance, hopefully he will be able to shed some light on this.
Peace - Anthony
Anyway (maybe this prompted your post), I updated the code in 1.7+ and HEAD to use this setting. If this needs to change, please let me know!
I would be easy enough to wrap the code in question/format.php in a check to make sure it is defined.
Oh, in my inexperience, I missed where it was being defined which is an example of where having the changes made in CVS listed on the tracker report would be helpful. So the code should be OK. I better understand now what your change is doing - which is setting the question->shuffleanswers value to whatever the default value is for the quiz->shuffleanswers and thus making the two consistent and configurable for the site. In my mind, I was thinking that quiz->shuffleanswers was new but the light bulb finally went off and made the connection. The next step would be to allow it to be configured per course or perhaps per instructor but that is a task for another day. Thanks for your work on this and patience with me. Peace.
Doing imports - which is the way I often do quizzes - means not having any choice at all. And since I often have questions with a fixed and repeating set of answers, shuffling them is not desirable.
Some options:
1. Allow the setting to be teacher or course specific.
2. Allow the setting to be specified in GIFT format.
3. Allow the setting to be easily changed in the Editing Quiz screen.
Oh, and the same should go for the numbering option.
However, things have moved on a bit in the code. I'll take a look and report back.
I am still using a very old moodle and GIFT import. I can't seem to find where a shuffle answers setting became part of the GIFT import format, or where the default is set when importing.
There is no mention of the word "shuffle" in this change log.
http://cvs.moodle.org/moodle/question/format/gift/format.php
nor instance of the string in the what appears to be the latest version of gift/format.php
Hmm...I have shuffle answers set to on in my administration settings, but that is for the quizes and not for the questions. Now that questions is seperate from quiz, it would be nice if it had its own Administration Configuration Questions. Or perhaps it does these days.
I know from this thread that respondus import format.php does include a shuffle answers setting as of March this year.
I am thinking of including
$question->shuffleanswers = 1;
or even to use the brainwave of Tim Hunt
$question->shuffleanswers = $CFG->quiz_shuffleanswers;
Just before the
//$question->defaultgrade = 1;
//$question->image = ""; // No images with this format
Which is also in my much older version.
The code to import multiple choice questions is below, with the suggested change.
BUT id did not work!
An error occurred during import processing |
However
$question->shuffleanswers = 1;
does seem to work okay
case MULTICHOICE:
if (strpos($answertext,"=") === false) {
$question->single = 0; // multiple answers are enabled if no single answer is 100% correct
} else {
$question->single = 1; // only one answer allowed (the default)
}
$answertext = str_replace("=", "~=", $answertext);
$answers = explode("~", $answertext);
if (isset($answers[0])) {
$answers[0] = trim($answers[0]);
}
if (empty($answers[0])) {
array_shift($answers);
}
$countanswers = count($answers);
if (!$this->check_answer_count( 2,$answers,$text )) {
return false;
break;
}
foreach ($answers as $key => $answer) {
$answer = trim($answer);
// determine answer weight
if ($answer[0] == "=") {
$answer_weight = 1;
$answer = substr($answer, 1);
} elseif (preg_match($gift_answerweight_regex, $answer)) { // check for properly formatted answer weight
$answer_weight = $this->answerweightparser($answer);
} else { //default, i.e., wrong anwer
$answer_weight = 0;
}
$question->fraction[$key] = $answer_weight;
$question->feedback[$key] = $this->commentparser($answer); // commentparser also removes comment from $answer
$question->answer[$key] = $this->escapedchar_post($answer);
$question->correctfeedback = '';
$question->partiallycorrectfeedback = '';
$question->incorrectfeedback = '';
} // end foreach answer
// $question->shuffleanswers = $CFG->quiz_shuffleanswers; //Takemoto did not work
//$question->defaultgrade = 1;
//$question->image = ""; // No images with this format
return $question;
break;
Tim
Re: Shuffle answers default of no for GIFT upload
Yes. that seems to work okay.
I am not sure why it is not in there already. Perhaps no one uses GIFT any more!? Or perhaps lots of people are THINKING that their tests are being shuffled when in fact (if they have imported them via GIFT in the past couple of years) then they are not. Or am I the only person that dim.
Should I file a bug report? Searching the bugtracker I realise that I did create a bug for this MDL5377. The conclusion in MDL5369 was to create a post-plugin question/format.php which is referenced in this thread. But there now appears to be no such thing as question/format.php (although it is still mentioned in the only file question/readme.txt).
Perhpas the default for the shuffling of questions is now controled by some nifty "Aministration > questions" interface that I know nothing of.
Where has the uber format.php gone to?
I hope everyone is well.
Tim
The most likely reason your change failed is that you forgot to add
global $CFG; to that function. (I do that all the time
Thank you Tim
I was looking in the wrong place. It is still at (in my install) line 179
$question->shuffleanswers = 0;
I could have just changed that.
global $CFG ah. Yes. That is what I needed to do .
Until there is a way of setting the defaults in format.php via the admininstration then I think that your suggestion in this thread, above is a good one.
function defaultquestion() {
// returns an "empty" question
// Somewhere to specify question parameters that are not handled
// by import but are required db fields.
// This should not be overridden.
global $CFG;
$question = new stdClass();
$question->shuffleanswers = $CFG->quiz_shuffleanswers;
$question->defaultgrade = 1;
$question->image = "";
$question->usecase = 0;
$question->multiplier = array();
return $question;
}
Perhaps we also need an admin page for import/export formats at some point.
Or, are you talking about question-type specific settings while you are importing, so you can set options like multichoice shuffle answers for just one import? That would be nice too, but some work.
Would need quite a lot of rework in the formats, but no harm in that in the 2.0 or 2.1 time-frames.
Well, I'm not going to promise anything
Thanks Tim, hi Howard
Waffle.
A configuration page for questions as a whole sounds fine for me (I only use GIFT).
If there were to be a configuration page for seperate formats then I would rather that it were not a *step* in the process. If a configuration page exists then I'd like it to exist as a seperate configuration page (accessable from the questions configuration page presumably).
But then....no...
I am the sole user of my moodles. Most moodles have an administrator and teachers that can not access the administration pages.
And I am using a very old moodle. In more recent moodle versions one can specify the category in the GIFT file so there is no need for a lot of GIFT file imports.
When I am creating a ten question test, I create ten categories, then import a gift file containing two or three question-variations into each of those categories, and form the quiz by adding a random question from each of those categories. With the inclusion of category specification and creation (I presume) in the GIFT format, then there is only the need to upload one GIFT file and have it create and populate the ten different categories. (Does GIFT category specification/creation exist in 1.6 stable, I wonder).
All the same, extra *steps* are not ideal. So, perhaps, like on the quiz settings page, an "advanced settings" button might be included on the import page, for teachers to set whether they want e.g. shuffleanswers to be on or of.
This is entirely theoretical because I can't seem myself upgrading even into 1.7. because (apart from the modules/hacks I would loose) I am scared of the speed penalty (and complexity) of roles.
As a language teacher, I use high speed vocabulary tests. Vocabularly tests need to be high speed otherwise the student can use a dictionary as they answer the test. There is no meaning to slowly accessed vocab skill (vocab is a skill, not a knowledge). Even on my 1.6.x speed is an issue especially when there are a lot of students using the moodle. I would like to be able to set 30 or 40 seconds for the time that students can take to answer the test, but when it takes a few seconds for the page to display, and a few for the results to reach the server then this becomes very problematic.
I wish that I knew how much slower a 1.9 or 2.0 is compared to a 1.6 stable. Perhaps there is little speed penalty.
Tim