You are here

function hook_course_access in Course 7

Same name and namespace in other branches
  1. 8.3 course.api.php \hook_course_access()
  2. 8.2 course.api.php \hook_course_access()
  3. 7.2 course.api.php \hook_course_access()
  4. 3.x course.api.php \hook_course_access()

Allow modules to determine if this course should be restricted.

If any module implementing this hook returns FALSE or an array containing 'success' => FALSE, the course will be restricted.

Parameters

string $op: Either 'enroll' or 'take'.

object $node: The course node.

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

Return value

boolean|array Either FALSE, or an array containing:

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

See also

course_take_course_access()

course_enroll_access()

4 functions implement hook_course_access()

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

course_course_access in ./course.module
Implements hook_course_access().
course_signup_course_access in modules/course_signup/course_signup.module
Implements hook_course_access().
course_take_course_access in ./course.module
course_uc_course_access in modules/course_uc/course_uc.module
Implements hook_course_access().
1 invocation of hook_course_access()
course_access_course in ./course.module
Check whether or not a user can self-enroll in a course.

File

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

Code

function hook_course_access($op, $node, $user) {
  if ($op == 'take') {

    // 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;
  }
  if ($op == 'enroll') {

    // Same usage as $op == 'take'.
  }
}