importing grades from external data

Re: importing grades from external data

by Zbigniew Fiedorowicz -
Number of replies: 7
I've attached our quick and dirty modification to allow import of grades from a comma delimited file. We've been using it here at Ohio State University for over a year to import hundreds of grades. This version works with Moodle v. 1.4 (and probably with any version other than the gradebook2 version (which may or may not work)). You should put the import_grades.php attached here into the course subfolder of your moodle installation.

The import file format looks like this:

username,###
smith,27
jones,43
ames,78

Here ### in the first line should be replaced by the assignment number into which you are uploading the grades. If you click on the assignment link the url will look like: http://yourmoodlesite/mod/assignment/view.php?id=###

You also need to make a few modifications to your course/grades.php
file (make a backup first). Add the line:

require_once("./import_grades.php");

right before the line:

$strgrades = get_string("grades");

Also right after the line:

print_single_button("grades.php", $options, get_string("downloadtext"));

add the following lines:

echo "</td></tr><tr><td colspan=\"2\">\n".
"<form method=\"post\" enctype=\"multipart/form-data\" action=\"grades.php\">\n".
"<input type=\"submit\" value=\"Import Grades\">".
"<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"get_max_upload_file_size()\">\n".
"<input type=\"hidden\" name=\"id\" value=\"$course->id\">".
"<input type=\"file\" name=\"gradefile\" size=30>\n".
"</form></td></tr>";

The next line (in the original grades.php) after these newly added lines should be:

echo "</TABLE>";

Make sure that you use a plain text editor to edit grades.php, NOT a word processor.
In reply to Zbigniew Fiedorowicz

Re: importing grades from external data

by Stephen Edwards -
Thanks for the contribution! I'll try it out on my own installation while I am waiting (and drooling!) for the gradebook2 features to be fully ready. I'm an OSU alum, too, so I'm glad to hear Moodle is seeing some action there.
In reply to Zbigniew Fiedorowicz

Re: importing grades from external data

by Jim Hardy -
Well, I think I followed your instructions to the letter and it looks like your routine is exactly what I've been looking for. Only one small problem, I can't seem to get it to work.

I placed import_grades.php in the courses folder and modified grades.php as outlined above.

I bring up the grade book and the buttons for import and selection of a file are now present. I then determined the assignment number and created a file that looks like this:

username,201
bob,30
lawanda,40
waldo, 50

I can select the file but when I try to import the file, I'm told that the module is incorrect.

Any suggestions?
In reply to Jim Hardy

Re: importing grades from external data

by Zbigniew Fiedorowicz -
That indicates that the 201 in the first line:

username,201

is not the correct number.  How did you get 201?

If you got this directly from the mysql database, you should be looking for the course_module id, not the assignment id.
In reply to Zbigniew Fiedorowicz

Re: importing grades from external data

by Jim Hardy -
I selected the gradebook entry (outside entry) which listed:
http://server/mod/outside/view.php?id=201

I figured I was doing something wrong.

I'll give it another try tomorrow using the the id from the mysql database. I guess that means I need to finally get around to learning how to use phpMyAdmin to find the outside event and the ID number.

Thanks.
In reply to Jim Hardy

Re: importing grades from external data

by Zbigniew Fiedorowicz -
It seems that you are using gradebook2?  Moodle v. 1.4.1 doesn't have a mod/outside  The import grades script imports into mod/assignment only.
In reply to Zbigniew Fiedorowicz

Re: importing grades from external data

by Jim Hardy -
I'm using the standard 1.4.1 gradebook. With all of the versions floating around, I figured it was best to stick with the original.

"Outside events" is a separate resource module and will show up in the gradebook. Still, if the only module one can import to is an assignment, I'll modify my classroom exam scores to fit the assignment module. Given the fact that the "Outside events" module does not sort alphabetically for score entry, I'll likey be happier after making the change.

I'll let you know how it turns out and thanks for the help. I guess that what people say at the U of Akron about OSU faculty is not true afterall.