function course_enrol_access in Course 6
Check whether or not a user can self-enroll in a course.
This function should be called by any module providing means of self-enrollment (e.g., course_uc, course_signup) then act accordingly by blocking that ability.
Parameters
object $node: A node.
object $user: A user.
bool $all: Return all values from implementations.
Return value
array An array with values 'success', to indicate whether or not the user has permission to self-enroll in this course, and 'message', a module-provided message that should be displayed to the user.
5 calls to course_enrol_access()
- CourseAccessTestCase::testReleaseExpiration in tests/
CourseAccessTestCase.test - Test the open/close date functionality.
- CourseEnrollmentTestCase::testCourseEnrollment in tests/
CourseEnrollmentTestCase.test - Test for enrollment access and timestamping.
- CourseObjectUbercartTestCase::testUbercartEnrollment in modules/
course_uc/ course_uc.test - course_render_button in ./
course.module - Check the permissions of showing the take course button, and return the HTML.
- course_take_course in ./
course.module - Take a course.
File
- ./
course.module, line 2239 - course.module Core functionality for Courses.
Code
function course_enrol_access($node, $user = NULL, $flush = FALSE, $all = FALSE) {
static $courses = array();
if (!$user) {
global $user;
}
if (!isset($courses[$node->nid]) || $flush || $all) {
if ($flush) {
$courses = array();
}
// Allow modules to set self-enrollment access for a user.
$hooks = module_invoke_all('course_can_enrol', $node, $user);
if ($all) {
return $hooks;
}
$courses[$node->nid]['success'] = TRUE;
foreach ($hooks as $key => $hook) {
if (is_array($hook) && !$hook['success']) {
$courses[$node->nid] = $hook;
return $hook;
}
}
}
return $courses[$node->nid];
}