You are here

function hook_course_can_enrol in Course 6

Allow modules to set self-enrollment access for a user.

Modules implementating This hook should return the status, and optionally a failure message if success is FALSE.

Parameters

object $node: The course node.

object $user: The user who may or may not take the course.

Return value

array An associative array of access arrays, each containing an array of:

  • success: Boolean. Indicates whether or not the user has permission to self-enroll in this course.
  • message: String. If success is FALSE, a message to display to the user.

See also

course_enrol_access()

3 functions implement hook_course_can_enrol()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

course_course_can_enrol in ./course.module
Implements hook_course_can_enrol().
course_signup_course_can_enrol in modules/course_signup/course_signup.module
Implements hook_course_can_enrol().
course_uc_course_can_enrol in modules/course_uc/course_uc.module
Implements hook_course_can_enrol().
1 invocation of hook_course_can_enrol()
course_enrol_access in ./course.module
Check whether or not a user can self-enroll in a course.

File

./course.api.php, line 278
Hooks provided by Course module.

Code

function hook_course_can_enrol($node, $user) {

  // Example: do not allow users to take courses on Wednesdays.
  if (date('L') == 'wednesday') {
    $hooks[] = array(
      'success' => FALSE,
      'message' => t('Courses are closed on Wednesdays.'),
    );
  }
  elseif (date('m') == 12 && date('d') == 25) {
    $hooks[] = array(
      'success' => TRUE,
    );
  }
  return $hooks;
}