Non-core contributed modules

Quiz import: CSV format for multichoices questions

Details

  • Type: New Feature New Feature
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.9.5
  • Fix Version/s: None
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE

Description

Simple format for importing multiple choice questions with one or more correct answers and no feedback. It can be written with any spreadsheet using tables and saved in CSV format.

Making multichoise questions quizes using spreadsheet tables (ex. in Excel or OpenCalc) is really fast an intuitive so my users do not need to know anything about ASCII formats or learn any other special software than that what they use every day - OfficeSuite.

The file format looks like this (Comma Separated Values):

"Category";"Question text";"CA 1";"CA 2";...;"CA n";"";"WA 1";"WA 2";...;"WA m"

Which represents the table:

Category Question text CA1 CA 2 ... CA n empty field WA 1 WA 2 ... WA m

That is

  • CA - Correct Answer, WA - Wrong Answer
  • one question - one row
  • empty cell(s) (one or more) separates correct answers from wrong ones
  • first field is taken as Category if it is selected in import form to take category from file, if not - first field is treated as question text
  • rows with empty Category if it is used or with empty Question text are omitted
  • also rows without CAs or WAs are omitted
  • number of CAs and WAs may differ from each other inside the row and between rows

Attachements:

  • mdl195-quiz_import-csv_format-20101019.diff.gz
    • full patch in diff format with changes in lang files
  • quiz_import-csv_format-20101019.zip
    • just zipped csv plugin directory without lang changes

INSTALL:

  • In your moodle directory apply diff file with command:

    zcat file.diff.gz | patch -p0

  • or unpack zip file in question/format directory and apply lang changes manually from diff file.

NOTICE:

  • not tested on php >= 5.3.0 when function str_getcsv is present (look in the getCsvRow() method)

Activity

Hide
Pawel Suwinski added a comment -

Upps, I have noticed that attached diff file did not have full paths of files to add/change inside. So I am resending it corrected, please use this one:
mdl195-quiz_import-csv_format-201010191200.diff.gz

Show
Pawel Suwinski added a comment - Upps, I have noticed that attached diff file did not have full paths of files to add/change inside. So I am resending it corrected, please use this one: mdl195-quiz_import-csv_format-201010191200.diff.gz
Hide
Pawel Suwinski added a comment -

I am attaching new improved version:
mdl195-quiz_import-csv_format-201011161600.diff.gz

CHANGELOG:

  • use fgetcsv() by overriding readdata() method instead of tricky and unreliable (case of CSV from MS Excel) getCsvRow() function
  • treat all fields from csv by addslashed() - I some how omitted it last version
  • fix category creation for omitted question

NOTICE:

  • to use MS Excel save quiz as "Text CSV" and after convert it to UTF-8 for example using Notepad (MS Excel does not allow to configure csv export like Open Office does)
  • to use csv with macintosh eol's there may be needed to set auto_detect_line_endings in php.ini
Show
Pawel Suwinski added a comment - I am attaching new improved version: mdl195-quiz_import-csv_format-201011161600.diff.gz CHANGELOG:
  • use fgetcsv() by overriding readdata() method instead of tricky and unreliable (case of CSV from MS Excel) getCsvRow() function
  • treat all fields from csv by addslashed() - I some how omitted it last version
  • fix category creation for omitted question
NOTICE:
  • to use MS Excel save quiz as "Text CSV" and after convert it to UTF-8 for example using Notepad (MS Excel does not allow to configure csv export like Open Office does)
  • to use csv with macintosh eol's there may be needed to set auto_detect_line_endings in php.ini
Hide
Niju Mohan added a comment - - edited

Guys,

help me out here. I'm new to moodle.

I'm using moodle on a windows 7 with wamp. What exactly has to be done here? I have imported the quiz_import-csv_format-20101019.zip properly and the question import option shows me the option to choose csv during import. But the import is not working properly (I have made it utf-8 using notepad). It says
"Parsing questions from import file.
There are no questions in the import file"

What is to be done with the diff file? I hope mdl195-quiz_import-csv_format-20101019.diff.gz is the last file? how to see my my moodle version? my readme.txt in moodle directory shows v 1.9.14.1 2007/11/14 23:40:50.

Also can you attach a sample question in csv format?

Show
Niju Mohan added a comment - - edited Guys, help me out here. I'm new to moodle. I'm using moodle on a windows 7 with wamp. What exactly has to be done here? I have imported the quiz_import-csv_format-20101019.zip properly and the question import option shows me the option to choose csv during import. But the import is not working properly (I have made it utf-8 using notepad). It says "Parsing questions from import file. There are no questions in the import file" What is to be done with the diff file? I hope mdl195-quiz_import-csv_format-20101019.diff.gz is the last file? how to see my my moodle version? my readme.txt in moodle directory shows v 1.9.14.1 2007/11/14 23:40:50. Also can you attach a sample question in csv format?
Hide
Pawel Suwinski added a comment -

Hi

> I have imported the quiz_import-csv_format-20101019.zip properly (...)

Use 201011161600 version of the patch. That is the last one and it fix the "There are no questions in the import file" case Excel case.

> What is to be done with the diff file?

http://docs.moodle.org/en/Development:How_to_apply_a_patch

In this case use '-p0' switch.

You can also add it manually by opening it in notepad or IE and making the changes described in the diff file ('-row' delete the row, '+row' add the row).

> Also can you attach a sample question in csv format?
I have no Excel, just OpenOffice. But just fill columns in Excel by:

Category|Question 1|CA1| | WA1 | WA2 | WA3 |
Category|Question 2|CA1| | WA1 | WA2 | WA3 | WA4 |

and save it as CSV Text and convert to utf-8 in notepad and it is it.

Show
Pawel Suwinski added a comment - Hi > I have imported the quiz_import-csv_format-20101019.zip properly (...) Use 201011161600 version of the patch. That is the last one and it fix the "There are no questions in the import file" case Excel case. > What is to be done with the diff file? http://docs.moodle.org/en/Development:How_to_apply_a_patch In this case use '-p0' switch. You can also add it manually by opening it in notepad or IE and making the changes described in the diff file ('-row' delete the row, '+row' add the row). > Also can you attach a sample question in csv format? I have no Excel, just OpenOffice. But just fill columns in Excel by: Category|Question 1|CA1| | WA1 | WA2 | WA3 | Category|Question 2|CA1| | WA1 | WA2 | WA3 | WA4 | and save it as CSV Text and convert to utf-8 in notepad and it is it.
Hide
Pawel Suwinski added a comment -

I am attaching zip package for 201011161600 version. For those having troubles with diff. But notice that zip package does not have changes in lang files.

Show
Pawel Suwinski added a comment - I am attaching zip package for 201011161600 version. For those having troubles with diff. But notice that zip package does not have changes in lang files.
Hide
Jean-Michel Vedrine added a comment -

You don't have to provide a patch, just add a lang subfolder to your question/format/csv/ folder and put one en_utf8 subfolder in this lang folder with a qformat_csv.php file in it. For help files put them into question/format/csv/lang/en_utf8/help/cvs/ (yes I know it may seem strange to have cvs at 2 differents levels but it's the way it works for plugins).with that, a zip will be enought to install your import/export format. Don't forget to define a 'csv' string in your qformat_csv.php lang file with the name that you want to display in the list of Import/export formats on screen.

Show
Jean-Michel Vedrine added a comment - You don't have to provide a patch, just add a lang subfolder to your question/format/csv/ folder and put one en_utf8 subfolder in this lang folder with a qformat_csv.php file in it. For help files put them into question/format/csv/lang/en_utf8/help/cvs/ (yes I know it may seem strange to have cvs at 2 differents levels but it's the way it works for plugins).with that, a zip will be enought to install your import/export format. Don't forget to define a 'csv' string in your qformat_csv.php lang file with the name that you want to display in the list of Import/export formats on screen.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: