protected function get_user_grade($courseitemid, $userid) {
        // If the user grade for this course is not available, get all the grades for the course.
        if (!isset($this->coursesgrades[$courseitemid])) {
            // Ony a course is cached to avoid high memory usage.
            unset($this->coursesgrades);
            $gg = new \grade_grade(null, false);
            $usersgrades = $gg->fetch_all(array('itemid' => $courseitemid));

            if ($usersgrades) {
                foreach ($usersgrades as $ug) {
                    $this->coursesgrades[$courseitemid][$ug->userid] = $ug->finalgrade;
                }
            }
        }

        if (!isset($this->coursesgrades[$courseitemid][$userid])) {
            $this->coursesgrades[$courseitemid][$userid] = null;
        }

        return $this->coursesgrades[$courseitemid][$userid];
    }