public static function convert_flat_displaytypes_to_array($displaytypes) {
        $types = array();

        // We have a single grade display type constant.
        if (is_int($displaytypes)) {
            $displaytype = clean_param($displaytypes, PARAM_INT);

            // Let's set a default value, will be replaced below by the grade display type constant.
            $display[$displaytype] = 1;
        } else {
            // Multiple grade display types constants.
            $display = array_flip(explode(',', $displaytypes));
        }

        // Now, create the array in the required format by grade exporting class.
        foreach ($display as $type => $value) {
            $type = clean_param($type, PARAM_INT);
            if ($type == GRADE_DISPLAY_TYPE_LETTER) {
                $types['letter'] = GRADE_DISPLAY_TYPE_LETTER;
            } else if ($type == GRADE_DISPLAY_TYPE_PERCENTAGE) {
                $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE;
            } else if ($type == GRADE_DISPLAY_TYPE_REAL) {
                $types['real'] = GRADE_DISPLAY_TYPE_REAL;
            } else if ($type == GRADE_DISPLAY_TYPE_REAL_PERCENTAGE) {
                $types['real'] = GRADE_DISPLAY_TYPE_REAL;
                $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE;
            } else if ($type == GRADE_DISPLAY_TYPE_REAL_LETTER) {
                $types['real'] = GRADE_DISPLAY_TYPE_REAL;
                $types['letter'] = GRADE_DISPLAY_TYPE_LETTER;
            } else if ($type == GRADE_DISPLAY_TYPE_LETTER_REAL) {
                $types['letter'] = GRADE_DISPLAY_TYPE_LETTER;
                $types['real'] = GRADE_DISPLAY_TYPE_REAL;
            } else if ($type == GRADE_DISPLAY_TYPE_LETTER_PERCENTAGE) {
                $types['letter'] = GRADE_DISPLAY_TYPE_LETTER;
                $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE;
            } else if ($type == GRADE_DISPLAY_TYPE_PERCENTAGE_LETTER) {
                $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE;
                $types['letter'] = GRADE_DISPLAY_TYPE_LETTER;
            } else if ($type == GRADE_DISPLAY_TYPE_PERCENTAGE_REAL) {
                $types['percentage'] = GRADE_DISPLAY_TYPE_PERCENTAGE;
                $types['real'] = GRADE_DISPLAY_TYPE_REAL;
            }
        }
        return $types;
    }