so i have the user id and the course id
whats the code to test if the user is enrolled in the course?
I have $USER->id and $course->id how do i test if the user is enrolled
av dirty slit -
Antall svar: 3
Som svar til dirty slit
Re: I have $USER->id and $course->id how do i test if the user is enrolled
av Sam Hemelryk -
Hi,
The following will return true if the user is enrolled in the course given $courseid, and $userid.
Cheers
Sam
The following will return true if the user is enrolled in the course given $courseid, and $userid.
$context = get_context_instance(CONTEXT_COURSE, $courseid);
is_enrolled($context, $userid);
Cheers
Sam
Som svar til Sam Hemelryk
Re: I have $USER->id and $course->id how do i test if the user is enrolled
av dirty slit -
Hi Sam,
I am currently using moodle 1.9 and I get this error with your code
Fatal error: Call to undefined function is_enrolled()
The function is_enrolled() is not listed here either http://xref.moodle.org/nav.html?_functions
How are you able to use this function?
I am currently using moodle 1.9 and I get this error with your code
Fatal error: Call to undefined function is_enrolled()
The function is_enrolled() is not listed here either http://xref.moodle.org/nav.html?_functions
How are you able to use this function?
Som svar til dirty slit
Re: I have $USER->id and $course->id how do i test if the user is enrolled
av Shane Elliott -
Sam was referring to a moodle 2.0 function. In 1.9 the concept of "enrolled" is a bit different. You are really checking who can view the course so the following should suffice:
HTH
Shane.
$context = get_context_instance(CONTEXT_COURSE, $courseid);
if (has_capability('moodle/course:view', $context, $userid)) {
/// user can view the course
}
HTH
Shane.