Adding Columns to the Grades page.

Adding Columns to the Grades page.

by Drew Thomas -
Number of replies: 1
First let me say that I think moodle is a wonderful thing.  I'm a student assistant that is customizing moodle for use at my school, and I am not a PHP master by any means nor a MySQL master.  What I'm trying to do is add some columns to the ../course/grades.php page.  I got some easyones like the users E-mail and and other items that are in the mdl_user table, but what we really want is to add the date that they took the quiz.  The problem that I am having is that I really can't tell where they are getting the grades from.  I beleive that its the mdl_quiz_grades table, and if thats the case I can just take the timemotified column and use the Date() to get the month, day, year out of that.  But I just can't read the code to see exactly where I should do this.

The only thing that I've figured is that I need to create a new variable (lets call it dateTaken) that I put in the block:

    foreach ($students as $student) {
        $grades[$student->id] = array();    // Collect all grades in this array
        $gradeshtml[$student->id] = array(); // Collect all grades html formatted in this array
        $totals[$student->id] = array();    // Collect all totals in this array
        $dateTaken[$student->id] = array();  // Collect the date taken in this array
    }

Other then that I don't have much of an idea.  I couldn't find where its actually pulling the grade data from the database

Any help that you all could provide would be welcomed and appriciated!


Thanks,

Drew
Average of ratings: -
In reply to Drew Thomas

Re: Adding Columns to the Grades page.

by John Papaioannou -
Hi Drew,

Your first assumption about being able to get the date from the timemodified column is correct indeed (although I think that column tells when the user's last attempt was, not when his best attempt was). smile

The pulling out of grades from the db is done in the function quiz_grades, in /mod/quiz/lib.php. The problem is that this function only pulls out the userid and grade, not timemodified:
$return->grades = get_records_menu('quiz_grades', 'quiz', $quiz->id, '', 'userid, grade');

Now you could probably add 'timemodified' to that list at the end, but I 'm not sure how the /course/grades.php code would react to that. But it would be the first step.

You 'd then need to add the date to the $gradeshtml array. In this piece of code:

if (!empty($modgrades->grades[$student->id])) {
$grades[$student->id][] = $currentstudentgrade = $modgrades->grades[$student->id];
if ($mod->visible) {
$gradeshtml[$student->id][] = $modgrades->grades[$student->id];
} else {
$gradeshtml[$student->id][] = "<font class=\"dimmed_text\">".
$modgrades->grades[$student->id].
"</font>";
}
}

you 'll have to change the red lines and assign some extra output to the elements of the $gradeshtml array, obviously taken from $modgrades. But only if $mod->modname == 'quiz', of course ($mod is the module being currently processed at that point in the code).

Hope this helps!

Jon