New question type: drag-and-drop ordering question

New question type: drag-and-drop ordering question

by Adriane Boyd -
Number of replies: 26

For my Google Summer of Code project I have been working on an ordering question type that has a drag-and-drop javascript version and a non-javascript fallback that looks like the matching question. Screenshots are on the project page.

This question type requires a recent version of 1.9 dev. There is a small caveat: in DEVELOPER debug mode, the question will be displayed, but it isn't updated correctly on submission. It works fine in any other debug mode.

I have tried to test this question type on a wide range of browsers. The drag-and-drop version works on Firefox 1.5 and 2, Opera 9, and Internet Explorer 6. The fallback works correctly on Safari 1.3 and Internet Explorer 5.

Please let me know if you have problems getting it to install or work properly or if you have any other suggestions!

The next step is to add more grading options. Right now the grading is based on the absolute position of the item in the list, so if you are off by one (like 2-3-4-5-1), the answer will be entirely wrong. I think I will add a grading option that looks for the longest sequence of items whose positions are correct relative to each other. Are there any other grading options you all would like to see?

Average of ratings: -
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Adriane Boyd -
An updated version of this question type which fixes a few bugs with the "I don't know" checkbox.
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Adriane Boyd -
Here is an updated version with backup/restore working correctly. Import/export will hopefully be next.
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Adriane,
Just tested the Export/Import of drag & drop ordering question. When I export a question with vertical setup (i.e. horizontal = 0), it is indeed exported to XML with <horizontal>0</horizontal>
However, upon importing, this is changed to 1, and items to be ordered now appear horizontally...
Joseph
Attachment image00.jpg
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Adriane,
Just tested again your drag & drop question type, latest version. There is a problem with the correct expected order upon editing the question.
Create new question. Question text: arrange these words in alphabetical order
1- cat
2- dog
3- zebra
Works fine.
Now, edit same question and add one item to get this:
1- cat
2- dog
3- mouse
4- zebra
Result: correct ordering is not recognized by question (see attached screen).
Hope you can find a solution.
Joseph
EDIT
Here are the contents of your Table: mdl_question_order_sub
After creation of new question
code question questiontext answertext
27 329132080 29 cat 1
28 361511231 29 dog 2
29 437713623 29 mouse 3
After adding one item:
-----------
id code question questiontext answertext
27 329132080 29 cat 1
28 361511231 29 dog 2
29 437713623 29 mouse 3
30 177215576 29 zebra 1
Attachment image00.jpg
In reply to Joseph Rézeau

Re: New question type: drag-and-drop ordering question

by Adriane Boyd -

Thanks for the feedback!

The editing problem has been fixed. I discovered that the import problem is due to the empty() check in getpath() format/xml/format.php, where 0 counts as empty. I had the default set to 1, so that was how the 1 crept in. I changed the default to 0 so that it works correctly for the moment, but I will suggest that the empty() check be changed.

(I copied this from the shuffleanswers check for the matching question where the default is 1. If you set shuffleanswers to 0 and import a matching question, it will become 1 because of this problem.)

In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Adriane,
This is to confirm that both problems have indeed been corrected and things work OK now. Thanks!
Joseph
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Adriane,
Just discovered a bug in your drag&drop ordering question. In teacher preview mode, the Fill with correct option does not work. Here is a fix. In order/questiontype.php, replace
 function get_correct_responses(&$question, &$state) {
 $responses = array();
 foreach ($state->options->subquestions as $sub) {
 foreach ($sub->options->answers as $answer) {
 if (1 == $answer->fraction && $sub->questiontext) {
 $responses[$sub->id] = $answer->id;
 }
 }
 }
 return empty($responses) ? null : $responses;
 }
with
 function get_correct_responses(&$question, &$state) {
 $responses = array();
 foreach ($question->options->subquestions as $sub) {
 $responses[$sub->code] = $sub->answertext;
 }
 return empty($responses) ? null : $responses;
 }

NOTE.- See attached screen shot to view the different rendering with JS enabled/disabled. With JS disabled it would look nicer if the items were ordered (and the dropdown list numbers ranged from 1 to ...n). But I do not know how to do it and - given the low number of people who surf the Internet with JS disabled anyway - I do not think it worthwhile to spend time on it.

Joseph
Attachment image00.jpg
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Adriane,
One (minor) display bug occurs when I put on the same page of a Quiz one drag and drop matching question (Q1) followed by one drag and drop ordering question (Q2), and that drag and drop ordering question (Q2) is set as horizontal display. Upon clicking and dragging one item of Q2, that item is positioned above the other items baseline and it is not possible to drag it any lower, which makes the activity not impossible but rather difficult to achieve. See attached screen shot.
Joseph
Attachment image00.jpg
In reply to Joseph Rézeau

Re: New question type: drag-and-drop ordering question

by Adriane Boyd -
I think all the dynamically-inserted elements are causing problems with the position constraints I put on ordering elements. The constraints were meant to be helpful, but they're not need, so I just took the constraints out and this shouldn't happen any more.
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
There is a (minor) display problem in the drag & drop ordering question. With fairly long text items, such as phrases or sentences, it is usually preferable to select the vertical display option. However, for continuous text re-construction, a teacher may prefer to have the horizontal display on. In that case, the height of the box surrounding the items is too small, which causes an overlapping problem (see screenshots #1 and #3). A workaround is to add this CSS rule to standard theme (or the course's actual theme):
.draglist.inline {
 line-height:2.2em;
}

It works (see screenshots #2 and #4). However, you might consider adding this extra height to the item boxes directly in your questiontype.php file.

Joseph

PS 1.- Note that in any case the longish text items may overflow over to the next line. Personally I do not find this a problem.

PS 2.- With text items displayed over more than one line, the drag & drop will only work from the beginning part of the item. For example, in #4, although the drag & drop cursor will appear when hovering over "Source software package designed etc." it will not be possible to carry out a drop & drag action there; drop & drag will only work on the "a free, Open" part. It would be more user-friendly not to display the drag & drop cursor on an item part which is not draggable, but this might entail complex programming.

Attachment image00.jpg
In reply to Joseph Rézeau

Re: New question type: drag-and-drop ordering question

by Adriane Boyd -
I hadn't really intended it to be used with a long paragraph. I added the CSS and still found it too clunky to try to move phrases where I wanted, but if you like it, by all means...

I'm not sure how to differentiate the first half of the box from the second half (for 4) or how to get the second half to be draggable (which I think would be the best solution).
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Found a bug in edit mode of the drag & drop question when you want to create a question with more than 6 items in it. For exemple create a question with 7 items in it.

  • Create a new "ordering" type question.
  • enter question name and question text
  • enter 3 items
  • click on Add more items button
  • enter items 4 to 6
  • click on Add more items button
  • enter item #7
  • click on the Save changes button
  • you can't save your question!

The only way to create more than 6 items is to create a question with 3 or 6 items only, save it, then edit it, add the extra items, and save it again.

Joseph

In reply to Joseph Rézeau

Re: New question type: drag-and-drop ordering question

by Adriane Boyd -
Indeed a major bug. Here's an updated version that also includes updates for the other problems discussed above. Grading options to come...
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Adriane,

Thanks for all the mods and fixes. Your latest version (2007081200) now works OK and there only remain 2 improvements to be done as far as I'm concerned:

  • find a way to drag & drop longish text items which overflow to the next line of text in horizontal display mode (if at all possible)
  • propose absolute & relative grading options to the teacher

Thanks for all your work!

Joseph

In reply to Joseph Rézeau

Re: New question type: drag-and-drop ordering question

by Adriane Boyd -
If there were an easy fix for the horizontal display mode with longer items, I would do it, but I don't think there is, so I don't intend to work on it (at least for now). I think vertical mode would better for those cases.

Do you think the grading options should be the same three from this post: Thomas Robb's list of grading options?
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Based on Thomas Robb's list of grading options, here is my list of grading options:

  1. exact answer = start counting points with first item correctly ordered and stop counting as soon as item is not correctly ordered;
  2. relative = count one point for each pair of consecutively ordered items (shown as pipe character | in attached example) + count one more point if first and last items are in place;
  3. absolute = this is more like counting the points in a matching exercise, it counts items individually matched to their correct order; item sequences are not taken into account.

Grading option #2 is my preferred option for an activity of re-ordering jumbled words or phrases. It may be the most difficult to program.

Obviously, some real-world examples should be provided so that the choice of grading option makes more sense.

Joseph

Attachment image00.jpg
In reply to Adriane Boyd

Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Adriane,
As I continue to test your drag & drop ordering question type with "real" examples from my own teaching, I suddently realize that another ordering question type was proposed by Thomas Robb, not so long ago (this thread). Have you been in contact with Thomas at all?
Anyway, as you will find out from that thread is that after some discussion re the scoring system of the ordering question type, we were finally agreed that 2 scoring systems ought to be available to the teacher, one "absolute" and one "relative".
Could you fit this scoring scheme in your question plug-in?
Joseph
In reply to Joseph Rézeau

Tárgy: Re: New question type: drag-and-drop ordering question

by Deni Nagy -
Hello,

I have experienced an error symptome with D&D ordering question: It works fine until I check the exercises in the preview mode but it doesn't work after moving over to the lesson's questions from the bank.

After moving it over only one element is visible and all others disappear. I use Moodle 1.9 b2.


I hope you can help me with this problem.


Thanks!
Deni
In reply to Deni Nagy

Re: Tárgy: Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Deni > it doesn't work after moving over to the lesson's questions from the bank.

Do you mean you have imported a drag and drop question from the questions bank into the Lesson activity in Moodle? That will not work, since that question type does not exist in the Lesson module.

If you mean something else, please explain.

Joseph

In reply to Joseph Rézeau

Tárgy: Re: Tárgy: Re: New question type: drag-and-drop ordering question

by Deni Nagy -
Hello,

No. Sorry, I might mix moodle-terminology with those we use in our company...
So. I call a unit inside a course a lesson and a course is called a module at us (thought I guess you don't care...). smile

So, we create theory parts of lessons as IMS and upload them as resources and we create exercises collected into quizes (not as lessons (as moodle module), they don't work as fine as quizes). So I create the exercise in the bank and than move over to the quiz which contains the batch of exercises available for students.

The ordering dies after moving it over to the quiz.

Anyway, I'll try Adriane's new file and get beck to him in a few minutes...

Thanks, I really appreciate your fast reply! ;) Deni
In reply to Deni Nagy

Re: Tárgy: Re: New question type: drag-and-drop ordering question

by Adriane Boyd -
Hi,

I'm aware of this bug, but I need to get my contrib access straightened out before I can commit the fix for the Modules and plugins download area. In the meanwhile, here is an updated questiontype.php that should fix this problem.

Thanks,
Adriane


In reply to Adriane Boyd

Re: Tárgy: Re: New question type: drag-and-drop ordering question

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Adriane,
Which bug is it exactly? As you can see from my previous post I did not understand Deni's problem...
Joseph
In reply to Joseph Rézeau

Re: Tárgy: Re: New question type: drag-and-drop ordering question

by Adriane Boyd -
The bug is that under certain conditions you only see one of the items to be ordered. I noticed it a few times over the summer, but refreshing the page fixed the problem and I didn't track it down. Someone reported it to me as a bug in November or December, so I figured out what was going on. After some more testing, I think that it only happens when you view or preview a quiz for the first time.

I think my fix here is a hack. (I think I need to fix something in the session initialization, but I can't figure out what's going wrong.) Before, I was only checking for whether the values in $responses were unset to see if I needed to initialize the item positions to a default random order. In some cases (such as the initial quiz preview) the values in $responses were initialized to 0, so the items were overwriting each other in position 0 in the displayed list and you end up only seeing the last one in the list. What's weird is that refreshing the page fixes the problem. Anyway, I added a check so that if they're < 1, it also does the position initialization.

-Adriane
In reply to Adriane Boyd

Tárgy: Re: Tárgy: Re: New question type: drag-and-drop ordering question

by Deni Nagy -
YES YES YES!!!!
HUHHHUUUUU!!!! smile

It works!!!

Thanks Adriane, this is what I meant!


Deni
(I'll write again if anything goes wrong but it works with the same texts with which it didn't work before.)