public function get_scale_id($scalevalues, $competencyname) {
        global $CFG, $USER;

        require_once($CFG->libdir . '/gradelib.php');

        if (empty($this->scalecache)) {
            $allscales = grade_scale::fetch_all_global();
            foreach ($allscales as $scale) {
                $scale->load_items();
                $this->scalecache[$scale->compact_items()] = $scale;
            }
        }
        $matchingscale = false;
        if (isset($this->scalecache[$scalevalues])) {
            $matchingscale = $this->scalecache[$scalevalues];
        }
        if (!$matchingscale) {
            // Create it.
            $newscale = new grade_scale();
            $newscale->name = get_string('competencyscale', 'tool_lpimportcsv', $competencyname);
            $newscale->courseid = 0;
            $newscale->userid = $USER->id;
            $newscale->scale = $scalevalues;
            $newscale->description = get_string('competencyscaledescription', 'tool_lpimportcsv');
            $newscale->insert();
            $this->scalecache[$scalevalues] = $newscale;
            return $newscale->id;
        }
        return $matchingscale->id;
    }