Get student grades from a deleted course?

Get student grades from a deleted course?

by Mike Brinkman -
Number of replies: 10
I have a faculty member who needs grades for a student in one of his courses. The problem is the course was deleted from our Moodle instance. If I know the course ID & student ID, is it possible for me to query the moodle database to retrieve their grades in some form that would be useful?
In reply to Mike Brinkman

Re: Get student grades from a deleted course?

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

It would be as easy to restore the course from backup if you have one.

In reply to Emma Richardson

Re: Get student grades from a deleted course?

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Unfortunately when you delete a course, all data including grades, is deleted too. However, as Emma mentions, if you have a course or site backup from before the course was deleted, you can obtain the grades from it.

In reply to Helen Foster

Re: Get student grades from a deleted course?

by Mike Brinkman -

Hmm. I thought the data was still in the database, but marked as deleted?

In reply to Mike Brinkman

Re: Get student grades from a deleted course?

by Perry Way -

Grade history is kept but it requires the course related records to exist in order to retrieve the grades for a report, otherwise you'd need to build your own report that works without requiring course data. Restoring the course would make grade retrieval possible in Moodle again, But yes, you are correct, the grade history is kept. The details of how this works can be found in the unit /lib/gradelib.php. Look for the function remove_course_grades($courseid, $showfeedback). This function is called from the function remove_course_contents($courseid, $showfeedback = true, array $options = null) found in the unit /lib/moodlelib.php and that function is called from the function delete_course($courseorid, $showfeedback = true) also found in the same unit /lib/moodlelib.php.

In reply to Emma Richardson

Re: Get student grades from a deleted course?

by Mike Brinkman -

Unfortunately, we don't save student data when we archive courses. Not my decision, but that's the policy. mixed

In reply to Mike Brinkman

Re: Get student grades from a deleted course?

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

I guess you could try restoring and reenrolling students and see if grades show up.  I, like you, actually thought they were still in the database somewhere...It always seems to me that Moodle never really deletes anything...expect plugins maybe!  I will defer however to Helen as the expert!

In reply to Mike Brinkman

Re: Get student grades from a deleted course?

by Perry Way -

You can retrieve grades yes, but in the instance of a quiz with multiple attempts you will find all attempts in the history and no correlating record summarizing the scores into one final score. That record is gone when you delete the course. The best way to get this grade information again in a manner you can retrieve would be to restore the original course. That will restore the final grade assessments in the cases of multiple scores per item.

In reply to Mike Brinkman

Re: Get student grades from a deleted course?

by Bob Puffer -

My recommendation:

  1. Make sure you have the site setting for restoring grades for re-enrollments set to yes (default is no, beats me)
  2. Restore the course without students
  3. Physically change the course id in the course table back to the original
  4. re-enroll the students
In reply to Mike Brinkman

Re: Get student grades from a deleted course?

by Bob Puffer -

My recommendation:

  1. Make sure you have the site setting for restoring grades for re-enrollments set to yes (default is no, beats me)
  2. Restore the course without students
  3. Physically change the course id in the course table back to the original
  4. re-enroll the students
In reply to Bob Puffer

Re: Get student grades from a deleted course?

by Peter Bowen -

If you have an SQL guru around, you may be able to get the information you want.

The table mdl_grades_items_history has the list of all historical grade items - if you know the old course id you can get a report on what grade items are stored in history. (One for overall and one for each module)

You then take that information and look in the mdl_grades_grades_history table - this will have the student grades for each of the grade items.

You may be able to get this put into a nice report with student name, item, grade etc if the SQL skills are up to scratch. smile

Cheers
Peter