Gradebook

Get percentage grades depending if the scale

 
This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.
Picture of Yeiner Fernández
Get percentage grades depending if the scale
 

Hi there,

Im conecting my application with Moodle, and need that the grades in one place be the same in the other place.

In my app, grades are stored as percents, depending of the scale that the user uses. Example, if the scale is 0-10, the student can have a grade from zero (equals 0%)  to 10 (equals 100%).  The teacher and the student see the number, but the application stores the percentage.

So I need to get the grades of any quiz or module in percentages, but don't understand how to figure this.

In my plugin, im using this two functions:

quiz_get_user_grades($module, 0);

and 

grade_get_grades($cm->course, $itemtype, 'quiz', $module->id);

But, no one of those helps me.

What do I have to do?

This is a part of my function:

$cms = $DB->get_records_list('course_modules','idnumber',$options['idnumbers']);

$grades = array();

foreach($cms as $cm){
                
    $cmmodule = $DB->get_record('modules', array( 'id' => $cm->module ));
    $module = $DB->get_record( $cmmodule->name, array( 'id' => $cm->instance ) );
    $itemmodule = $cmmodule->name;
                
    require_once( $CFG->dirroot .'/'.$itemtype.'/'.$itemmodule.'/lib.php' );
                
    $function =  $itemmodule."_get_user_grades";
    $cmgrades = $function( $module, 0);

    foreach($cmgrades as $id => $grade){

      $grade->cmidnumber = $cm->idnumber;

      $user = $DB->get_record('user', array('id' => $grade->userid), 'id, idnumber');
      $grade->user = (array) $user;
      $grades[] = (array) $grade;

    }

  // $grades[] = grade_get_grades($cm->course, $itemtype, $cmmodule->name, $module->id);
  
}