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;
    }
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;
    }
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 ; }
Get last accessed courses adding additional course information like images.

@param int $userid User id from which the courses will be obtained
@param int $limit Restrict result set to this amount
@param int $offset Skip this number of records from the start of the result set
@param string|null $sort SQL string for sorting
@return array List of courses
@throws  invalid_parameter_exception
Get last accessed courses adding additional course information like images .