General developer forum

How to get a list of custom courses

 
Picture of Sanya Gold
How to get a list of custom courses
 

I need to display a list of courses that the user entered.

 
Average of ratings: -
Picture of Howard Miller
Re: How to get a list of custom courses
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

I've no idea what you are asking. Can you explain how the user entered the courses? 

If you just mean courses they have enrolled on then that's on their profile page. 

 
Average of ratings: -
Picture of Sanya Gold
Re: How to get a list of custom courses
 

I want to display the list in my plugin

 
Average of ratings: -
Picture of Darko Miletić
Re: How to get a list of custom courses
Core developersParticularly helpful Moodlers

Unless you clarify your question nobody will be able to assist you. We expect a question like this:

I would like to display list of courses in which user entered in my plugin. "Entered a course" means user actually clicked on the course link.


Or something like this. We do not know what it is that you think - only you do. Be more precise.

 
Average of ratings: Useful (1)
Picture of Sanya Gold
Re: How to get a list of custom courses
 
This is my code: 

function user_get_user_courses($user, array $userfields = array()) {

  // List of courses where the user is enrolled.

    if (in_array('enrolledcourses', $userfields) && !isset($hiddenfields['mycourses'])) {

        $enrolledcourses = array();

        if ($mycourses = enrol_get_users_courses($user->id, true)) {

            foreach ($mycourses as $mycourse) {

                if ($mycourse->category) {

                    $coursecontext = context_course::instance($mycourse->id);

                    $enrolledcourse = array();

                    $enrolledcourse['id'] = $mycourse->id;

                    $enrolledcourse['fullname'] = format_string($mycourse->fullname, true, array('context' => $coursecontext));

                    $enrolledcourse['shortname'] = format_string($mycourse->shortname, true, array('context' => $coursecontext));

                    $enrolledcourses[] = $enrolledcourse;

                }

            }

            $userdetails['enrolledcourses'] = $enrolledcourses;

        }

    }

return $userdetails;

}

How to derive a function?

 
Average of ratings: -