It has been suggested that I post some destructions about how I have used this successfully at Earlham. Here they are:
Moodle Data Import via flat file
This conversation on moodle.org details the development of a simple plugin to create a collection of courses from data in a simple comma delimited text file. A version which is compatible with Moodle 1.7 has been created by students at Appalachian State University ( details ).
I had to perform a couple of hacks in order to make it work with the courses I had to create:
- increase length of shortname from 15 -> 20 chars (the database can handle 256 char length) on line 627.
- similarly, increase the default category length from 30 to 50 chars (line 208).
Code (including hacks listed above)
Hacks needed for Moodle
One of the more frustrating aspects of administering moodle and adding courses is the arbitrary limit on the Shortname field size. This has nothing to do with the database where the shortname field in the mdl_course table is of type varchar(100). In fact, it's a consequence of two 'magic numbers' located in the code that displays the editing and request form. Here are AWyatt's hacks (login needed) which increase the size of the shortname field in the relevant forms:
Increase shortname field length in the course request form and the course creation form.
In moodle/course/edit_form.php line 72
$mform->addElement('text','shortname', get_string('shortname'),'maxlength="25" size="25"');
moodle/course/request_form.php line 13
$mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="25" size="25"');
I tried these out on my test 1.8 Moodle site and they worked:
1. Faculty Account creation
Despite claims to the contrary, the uploadcourse does not create user accounts for teachers; these have to be created prior to the course upload. We used this perl script to extract names and email addresses from the WebDb database, format them and output to a web page (note that this setup is unique to Earlham -- you'll have to find some other way of creating the comma delimited file). Example file to create faculty accounts
Go to Users : Accounts : Upload users on your Moodle site and browse for the comma delimited file of faculty account and upload it. The accounts should be created automatically.
Since many of the courses have yet to be assigned to a professor we use a moniker "TBA" to substitute the prof's name and this account must be created as well.
2. Extract and format the course data
We used this perl course creation script to run against the Earlham Webdb system which extracts and formats the data. Fell free to modify this script. There were a number of issues to cope with and here's what we did:
- drop all AWPE courses — these are all practical and are not likely to require an online presence.
- discard CS courses as well since we know they're not wanted.
- if multiple teachers are listed for the course only the first teacher is selected.
- courses that are cross listed have more than one course entry for the same course. It's impossible to determine which course is the canonical one (basically it would be the course corresponding to the teacher's department), so we leave these out too.
- Apart from BIOL courses (ie Eco Bio) crosslisted which stay in this main listing as a special case.
- discard any courses with '340' as being ephemeral.
- handling multiple sections of the same course. Rather than label every course with "-1" the default section is left blank and subsequent sections have the section number attached. Thus BIOL111 , BIOL111-2, BIOL111-3. These are sufficiently rare so that the "-1" can be added by hand in Excel if need be.
- use full email addresses as teacher names to avoid problems with multiple last names (eg Van Buskirk) and middle names (eg Scott D. Hess)
- change role from "Teacher" to "editingteacher" (this is a logical bug)
- placing "/" around category names (eg /Art (ART)/ ) will automatically create the category (and as an added bonus they'll be in alphabetical order too! Note: Add a dummy course for the Miscellaneous category so that this gets created too.
- Note that the default outline format used is 'weeks' (course start date 19th Aug, # weeks 16) – we could change known courses to topics using Excel, but restoring courses would make this superfluous on the whole.
All of the above issues are coped with in the perl script. No other tweaking is required but it's always well worth loading the data into Excel to eyeball prior to uploading.
The format we used was <dept><course number><section>:<banner termcode>, thus BIOL111-2:200810. As explained above we apply a modest hack to accomodate the longer shortname (>15 chars).
Full name format
Here we used <shortname> – <course title>, eg BIOL111-2:200810 – Ecological Biology L & L. This means that courses can be uniquely identified by their fullname across years.
Cross listed courses are handled separately.
Instructions for installation and use
- Download uploadcourse.zip and unzip. This contains two files uploadcourse.php & example_course.csv.
- Create Faculty accounts as described above
- Extract the course data from Banner/other as described above.
- Modify the forms fields in Moodle to account for longer shortname field as described above.
- Open example_course.csv in Excel and check that you have the correct format for the course import file.
- Copy uploadcourse.php into /moodle/admin directory. Make sure permissions and ownership are set correctly (ie, match them to other .php files there)
- Login as Moodle administrator and run http://moodle/admin/uploadcourse.php ; browse for the course import file and execute!
I tested this on a testbed version 1.8.1+. Here's a successful import:
Parsed 340 course(s) from CSV Created 322 course(s) out of 340
18 course(s) were skipped (duplicate ShortName)
33 new category(ies) were created
You may wish to manually Re-Sort the categories
ANALYZE Database Tables OK
OPTIMIZE Database Tables OK
Total Execution Time: 25.16 s
Handling cross listed courses
Cross listed courses were extracted with a modified sql script which produces a comma delimited format file. This has to be editted in Excel and the supernumary crosslisting course references removed. I have seen somewhere a system by which multiple course lables can point to the same course within Moodle but I cannot find it.
Based on information from my Moodle Issues tiddlywiki Mark Pearson July 3rd 2007
You mileage WILL vary, but the principles are here. A big huge thank you to the workers at Applacian State for their excellent script.