public static function get_recent_courses(int $userid = 0, int $limit = 0, int $offset = 0, string $sort = null) {
        global $USER, $PAGE;

        if (empty($userid)) {
            $userid = $USER->id;
        }

        $params = self::validate_parameters(self::get_recent_courses_parameters(),
            array(
                'userid' => $userid,
                'limit' => $limit,
                'offset' => $offset,
                'sort' => $sort
            )
        );

        $userid = $params['userid'];
        $limit = $params['limit'];
        $offset = $params['offset'];
        $sort = $params['sort'];

        $usercontext = context_user::instance($userid);

        self::validate_context($usercontext);

        if ($userid != $USER->id and !has_capability('moodle/user:viewdetails', $usercontext)) {
            return array();
        }

        $courses = course_get_recent_courses($userid, $limit, $offset, $sort);

        $renderer = $PAGE->get_renderer('core');

        $recentcourses = array_map(function($course) use ($renderer) {
            context_helper::preload_from_record($course);
            $context = context_course::instance($course->id);
            $isfavourite = !empty($course->component);
            $exporter = new course_summary_exporter($course, ['context' => $context, 'isfavourite' => $isfavourite]);
            return $exporter->export($renderer);
        }, $courses);

        return $recentcourses;
    }