public static function get_course_blocks($courseid, $returncontents = false) {
        global $PAGE;

        $warnings = array();
        $params = self::validate_parameters(self::get_course_blocks_parameters(),
            ['courseid' => $courseid, 'returncontents' => $returncontents]);

        $course = get_course($params['courseid']);
        $context = context_course::instance($course->id);
        self::validate_context($context);

        // Specific layout for frontpage course.
        if ($course->id == SITEID) {
            $PAGE->set_pagelayout('frontpage');
            $PAGE->set_pagetype('site-index');
        } else {
            $PAGE->set_pagelayout('course');
            // Ensure course format is set (view course/view.php).
            $course->format = course_get_format($course)->get_format();
            $PAGE->set_pagetype('course-view-' . $course->format);
        }

        $allblocks = self::get_all_current_page_blocks(false, $params['returncontents']);

        return array(
            'blocks' => $allblocks,
            'warnings' => $warnings
        );
    }