protected static function get_cached_grade_score($gradeitemid, $courseid,
            $grabthelot=false, $userid=0) {
        global $USER, $DB;
        if (!$userid) {
            $userid = $USER->id;
        }
        $cache = \cache::make('availability_grade', 'scores');
        if (($cachedgrades = $cache->get($userid)) === false) {
            $cachedgrades = array();
        }
        if (!array_key_exists($gradeitemid, $cachedgrades)) {
            if ($grabthelot) {
                // Get all grades for the current course.
                $rs = $DB->get_recordset_sql('
                        SELECT
                            gi.id,gg.finalgrade,gg.rawgrademin,gg.rawgrademax
                        FROM
                            {grade_items} gi
                            LEFT JOIN {grade_grades} gg ON gi.id=gg.itemid AND gg.userid=?
                        WHERE
                            gi.courseid = ?', array($userid, $courseid));
                foreach ($rs as $record) {
                    // This function produces division by zero error warnings when rawgrademax and rawgrademin
                    // are equal. Below change does not affect function behavior, just avoids the warning.
                    if (is_null($record->finalgrade) || $record->rawgrademax == $record->rawgrademin) {
                        // No grade = false.
                        $cachedgrades[$record->id] = false;
                    } else {
                        // Otherwise convert grade to percentage.
                        $cachedgrades[$record->id] =
                                (($record->finalgrade - $record->rawgrademin) * 100) /
                                ($record->rawgrademax - $record->rawgrademin);
                    }
                }
                $rs->close();
                // And if it's still not set, well it doesn't exist (eg
                // maybe the user set it as a condition, then deleted the
                // grade item) so we call it false.
                if (!array_key_exists($gradeitemid, $cachedgrades)) {
                    $cachedgrades[$gradeitemid] = false;
                }
            } else {
                // Just get current grade.
                $record = $DB->get_record('grade_grades', array(
                    'userid' => $userid, 'itemid' => $gradeitemid));
                // This function produces division by zero error warnings when rawgrademax and rawgrademin
                // are equal. Below change does not affect function behavior, just avoids the warning.
                if ($record && !is_null($record->finalgrade) && $record->rawgrademax != $record->rawgrademin) {
                    $score = (($record->finalgrade - $record->rawgrademin) * 100) /
                        ($record->rawgrademax - $record->rawgrademin);
                } else {
                    // Treat the case where row exists but is null, same as
                    // case where row doesn't exist.
                    $score = false;
                }
                $cachedgrades[$gradeitemid] = $score;
            }
            $cache->set($userid, $cachedgrades);
        }
        return $cachedgrades[$gradeitemid];
    }
protected static function get_cached_grade_score($gradeitemid, $courseid,
            $grabthelot=false, $userid=0) {
        global $USER, $DB;
        if (!$userid) {
            $userid = $USER->id;
        }
        $cache = \cache::make('availability_grade', 'scores');
        if (($cachedgrades = $cache->get($userid)) === false) {
            $cachedgrades = array();
        }
        if (!array_key_exists($gradeitemid, $cachedgrades)) {
            if ($grabthelot) {
                // Get all grades for the current course.
                $rs = $DB->get_recordset_sql('
                        SELECT
                            gi.id,gg.finalgrade,gg.rawgrademin,gg.rawgrademax
                        FROM
                            {grade_items} gi
                            LEFT JOIN {grade_grades} gg ON gi.id=gg.itemid AND gg.userid=?
                        WHERE
                            gi.courseid = ?', array($userid, $courseid));
                foreach ($rs as $record) {
                    // This function produces division by zero error warnings when rawgrademax and rawgrademin
                    // are equal. Below change does not affect function behavior, just avoids the warning.
                    if (is_null($record->finalgrade) || $record->rawgrademax == $record->rawgrademin) {
                        // No grade = false.
                        $cachedgrades[$record->id] = false;
                    } else {
                        // Otherwise convert grade to percentage.
                        $cachedgrades[$record->id] =
                                (($record->finalgrade - $record->rawgrademin) * 100) /
                                ($record->rawgrademax - $record->rawgrademin);
                    }
                }
                $rs->close();
                // And if it's still not set, well it doesn't exist (eg
                // maybe the user set it as a condition, then deleted the
                // grade item) so we call it false.
                if (!array_key_exists($gradeitemid, $cachedgrades)) {
                    $cachedgrades[$gradeitemid] = false;
                }
            } else {
                // Just get current grade.
                $record = $DB->get_record('grade_grades', array(
                    'userid' => $userid, 'itemid' => $gradeitemid));
                // This function produces division by zero error warnings when rawgrademax and rawgrademin
                // are equal. Below change does not affect function behavior, just avoids the warning.
                if ($record && !is_null($record->finalgrade) && $record->rawgrademax != $record->rawgrademin) {
                    $score = (($record->finalgrade - $record->rawgrademin) * 100) /
                        ($record->rawgrademax - $record->rawgrademin);
                } else {
                    // Treat the case where row exists but is null, same as
                    // case where row doesn't exist.
                    $score = false;
                }
                $cachedgrades[$gradeitemid] = $score;
            }
            $cache->set($userid, $cachedgrades);
        }
        return $cachedgrades[$gradeitemid];
    }
protected static function get_cached_grade_score ( $ gradeitemid , $ courseid , $ grabthelot = false , $ userid = 0 ) { global $ USER , $ DB ; if ( ! $ userid ) { $ userid = $ USER -> id ; } $ cache = \ cache :: make ( 'availability_grade' , 'scores' ) ; if ( ( $ cachedgrades = $ cache -> get ( $ userid ) ) === false ) { $ cachedgrades = array ( ) ; } if ( ! array_key_exists ( $ gradeitemid , $ cachedgrades ) ) { if ( $ grabthelot ) { // Get all grades for the current course. $ rs = $ DB -> get_recordset_sql ( '
                        SELECT
                            gi.id,gg.finalgrade,gg.rawgrademin,gg.rawgrademax
                        FROM
                            {grade_items} gi
                            LEFT JOIN {grade_grades} gg ON gi.id=gg.itemid AND gg.userid=?
                        WHERE
                            gi.courseid = ?' , array ( $ userid , $ courseid ) ) ; foreach ( $ rs as $ record ) { // This function produces division by zero error warnings when rawgrademax and rawgrademin // are equal. Below change does not affect function behavior, just avoids the warning. if ( is_null ( $ record -> finalgrade ) || $ record -> rawgrademax == $ record -> rawgrademin ) { // No grade = false. $ cachedgrades [ $ record -> id ] = false ; } else { // Otherwise convert grade to percentage. $ cachedgrades [ $ record -> id ] = ( ( $ record -> finalgrade - $ record -> rawgrademin ) * 100 ) / ( $ record -> rawgrademax - $ record -> rawgrademin ) ; } } $ rs -> close ( ) ; // And if it's still not set, well it doesn't exist (eg // maybe the user set it as a condition, then deleted the // grade item) so we call it false. if ( ! array_key_exists ( $ gradeitemid , $ cachedgrades ) ) { $ cachedgrades [ $ gradeitemid ] = false ; } } else { // Just get current grade. $ record = $ DB -> get_record ( 'grade_grades' , array ( 'userid' => $ userid , 'itemid' => $ gradeitemid ) ) ; // This function produces division by zero error warnings when rawgrademax and rawgrademin // are equal. Below change does not affect function behavior, just avoids the warning. if ( $ record && ! is_null ( $ record -> finalgrade ) && $ record -> rawgrademax != $ record -> rawgrademin ) { $ score = ( ( $ record -> finalgrade - $ record -> rawgrademin ) * 100 ) / ( $ record -> rawgrademax - $ record -> rawgrademin ) ; } else { // Treat the case where row exists but is null, same as // case where row doesn't exist. $ score = false ; } $ cachedgrades [ $ gradeitemid ] = $ score ; } $ cache -> set ( $ userid , $ cachedgrades ) ; } return $ cachedgrades [ $ gradeitemid ] ; }
Obtains a grade score. Note that this score should not be displayed to
the user, because gradebook rules might prohibit that. It may be a
non-final score subject to adjustment later.

@param int $gradeitemid Grade item ID we're interested in
@param int $courseid Course id
@param bool $grabthelot If true, grabs all scores for current user on
this course, so that later ones come from cache
@param int $userid Set if requesting grade for a different user (does
not use cache)
@return float Grade score as a percentage in range 0-100 (e.g. 100.0
or 37.21), or false if user does not have a grade yet
Obtains a grade score . Note that this score should not be displayed to the user because gradebook rules might prohibit that . It may be a non - final score subject to adjustment later .