You are here

function course_access_course in Course 7

Same name and namespace in other branches
  1. 7.2 course.module \course_access_course()

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 $flush: Flag to flush the internal cache.

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.

4 calls to course_access_course()
CourseObject::access in includes/CourseObject.inc
Access functionality for course objects.
course_enroll in ./course.module
Enrolls a user in a course.
course_enroll_access in ./course.module
course_take_course_access in ./course.module

File

./course.module, line 2216
course.module Core functionality for Courses.

Code

function course_access_course($op, $node, $account = NULL, $flush = FALSE, $all = FALSE) {
  $courses =& drupal_static(__FUNCTION__, array());
  if (!$account) {
    global $user;
    $account = $user;
  }
  if (!isset($courses[$node->nid][$op]) || $flush) {

    // Allow modules to set self-enrollment access for a user.
    $hooks = module_invoke_all('course_access', $op, $node, $account);
    drupal_alter('course_access', $hooks, $op, $node, $account);
    uasort($hooks, 'drupal_sort_weight');
    $courses[$node->nid][$op] = $hooks;
  }
  if ($all) {
    return $courses[$node->nid][$op];
  }
  else {
    foreach ($courses[$node->nid][$op] as $key => $hook) {
      if (is_array($hook) && !$hook['success']) {
        return $hook;
      }
    }

    // Add a default success hook in case no others are returned.
    return array(
      'success' => TRUE,
    );
  }
}