public static function get_user_grade($lessonid, $userid = null) {
        global $CFG, $USER;
        require_once($CFG->libdir . '/gradelib.php');

        $params = array(
            'lessonid' => $lessonid,
            'userid' => $userid,
        );
        $params = self::validate_parameters(self::get_user_grade_parameters(), $params);
        $warnings = array();

        list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']);

        // Default value for userid.
        if (empty($params['userid'])) {
            $params['userid'] = $USER->id;
        }

        // Extra checks so only users with permissions can view other users attempts.
        if ($USER->id != $params['userid']) {
            self::check_can_view_user_data($params['userid'], $course, $cm, $context);
        }

        $grade = null;
        $formattedgrade = null;
        $grades = lesson_get_user_grades($lesson, $params['userid']);
        if (!empty($grades)) {
            $grade = $grades[$params['userid']]->rawgrade;
            $params = array(
                'itemtype' => 'mod',
                'itemmodule' => 'lesson',
                'iteminstance' => $lesson->id,
                'courseid' => $course->id,
                'itemnumber' => 0
            );
            $gradeitem = grade_item::fetch($params);
            $formattedgrade = grade_format_gradevalue($grade, $gradeitem);
        }

        $result = array();
        $result['grade'] = $grade;
        $result['formattedgrade'] = $formattedgrade;
        $result['warnings'] = $warnings;
        return $result;
    }
public static function get_user_grade($lessonid, $userid = null) {
        global $CFG, $USER;
        require_once($CFG->libdir . '/gradelib.php');

        $params = array(
            'lessonid' => $lessonid,
            'userid' => $userid,
        );
        $params = self::validate_parameters(self::get_user_grade_parameters(), $params);
        $warnings = array();

        list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']);

        // Default value for userid.
        if (empty($params['userid'])) {
            $params['userid'] = $USER->id;
        }

        // Extra checks so only users with permissions can view other users attempts.
        if ($USER->id != $params['userid']) {
            self::check_can_view_user_data($params['userid'], $course, $cm, $context);
        }

        $grade = null;
        $formattedgrade = null;
        $grades = lesson_get_user_grades($lesson, $params['userid']);
        if (!empty($grades)) {
            $grade = $grades[$params['userid']]->rawgrade;
            $params = array(
                'itemtype' => 'mod',
                'itemmodule' => 'lesson',
                'iteminstance' => $lesson->id,
                'courseid' => $course->id,
                'itemnumber' => 0
            );
            $gradeitem = grade_item::fetch($params);
            $formattedgrade = grade_format_gradevalue($grade, $gradeitem);
        }

        $result = array();
        $result['grade'] = $grade;
        $result['formattedgrade'] = $formattedgrade;
        $result['warnings'] = $warnings;
        return $result;
    }
public static function get_user_grade ( $ lessonid , $ userid = null ) { global $ CFG , $ USER ; require_once ( $ CFG -> libdir . '/gradelib.php' ) ; $ params = array ( 'lessonid' => $ lessonid , 'userid' => $ userid , ) ; $ params = self :: validate_parameters ( self :: get_user_grade_parameters ( ) , $ params ) ; $ warnings = array ( ) ; list ( $ lesson , $ course , $ cm , $ context , $ lessonrecord ) = self :: validate_lesson ( $ params [ 'lessonid' ] ) ; // Default value for userid. if ( empty ( $ params [ 'userid' ] ) ) { $ params [ 'userid' ] = $ USER -> id ; } // Extra checks so only users with permissions can view other users attempts. if ( $ USER -> id != $ params [ 'userid' ] ) { self :: check_can_view_user_data ( $ params [ 'userid' ] , $ course , $ cm , $ context ) ; } $ grade = null ; $ formattedgrade = null ; $ grades = lesson_get_user_grades ( $ lesson , $ params [ 'userid' ] ) ; if ( ! empty ( $ grades ) ) { $ grade = $ grades [ $ params [ 'userid' ] ] -> rawgrade ; $ params = array ( 'itemtype' => 'mod' , 'itemmodule' => 'lesson' , 'iteminstance' => $ lesson -> id , 'courseid' => $ course -> id , 'itemnumber' => 0 ) ; $ gradeitem = grade_item :: fetch ( $ params ) ; $ formattedgrade = grade_format_gradevalue ( $ grade , $ gradeitem ) ; } $ result = array ( ) ; $ result [ 'grade' ] = $ grade ; $ result [ 'formattedgrade' ] = $ formattedgrade ; $ result [ 'warnings' ] = $ warnings ; return $ result ; }
Return the final grade in the lesson for the given user.

@param int $lessonid lesson instance id
@param int $userid only fetch grades of this user
@return array of warnings and page attempts
@since Moodle 3.3
@throws moodle_exception
Return the final grade in the lesson for the given user .