Need the code to get the total grade

Need the code to get the total grade

by Chardelle Busch -
Number of replies: 3
Picture of Core developers
I'm hoping someone with gradebook code experience can help me.  I am using the add-on certificate module and would like to be able to add the total grade to it for a student.  I am able to insert other things into a certificate, for example, the course name, the student's name, etc.  But I have not yet been successful with the total grade (points?).  I tried this code from grade/index.php, but it didn't work:

   if ($grades_by_student["$student"]["$category"]['stats']['points'] != $strexcluded) {
                            if ($grades_by_student["$student"]["$category"]['stats']['points'] != '-') {
                                $grades_by_student["$student"]['student_data']['points'] = $grades_by_student["$student"]['student_data']['points'] + $grades_by_student["$student"]["$category"]['stats']['points'];
                            }
                            $grades_by_student["$student"]['student_data']['totalpoints'] = $grades_by_student["$student"]['student_data']['totalpoints'] + $grades_by_student["$student"]["$category"]['stats']['totalpoints'];
                       
    $pdf->ezText($grades_by_student->totalpoints,22,array('justification'=>'centre'));
    }


Thanks so much if anyone has an idea about how to do this.
In reply to Chardelle Busch

Re: Need the code to get the total grade

by Jeff Graham -
Hi Chardelle,

The students grade information can be found through the $grades_by_student data structure returned by grade_get_formatted_grades() the following are probably what you are looking for:
  • points: $grades_by_student[USERID]['student_data']['points']
  • totalpoints: $grades_by_student[USERID]['student_data']['totalpoints']
  • percent: $grades_by_student[USERID]['student_data']['percent']
  • weighted grade: $grades_by_student[USERID]['student_data']['weighted']
Of course you will need to replace USERID with the value of the user information you are trying to get at. To populate the $grades_by_student variable do the following:
list($grades_by_student, $all_categories) = grade_get_formatted_grades();
this will also populate $all_categories which will have all sorts of information present. Note that you will need to have your $course variable set appropriately before calling this function.

Hope that helps
Jeff
In reply to Jeff Graham

Re: Need the code to get the total grade

by Chardelle Busch -
Picture of Core developers
Hi Jeff,

Unfortunately, I just don't know enough about it to get it to work. And maybe it just isn't possible, since it seems like the things that are added come directly from the database.  But thank you very much for the info.

Chardelle
In reply to Jeff Graham

Re: Need the code to get the total grade

by Kyle Claypool -
Jeff,

I need to do something similar, but need to export the date a quiz or activity was taken/modified. Is there some way of doing this? I figured it would be something like:

$grades_by_student[USERID]['student_data']['timemodified']

but had no luck. Any help would be much appreciated. Is there a resource somewhere that lists the different keywords like 'totalpoints', 'percent', etc.?

Best,
Kyle Claypool