You are here

function course_access_course in Course 7.2

Same name and namespace in other branches
  1. 7 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.

12 calls to course_access_course()
CourseAccessTestCase::testDurationExpiration in tests/CourseAccessTestCase.test
Test the enrollment duration. This does not test the enrollment end date being set correctly.
CourseAccessTestCase::testReleaseExpiration in tests/CourseAccessTestCase.test
Test the open/close date functionality.
CourseEnrollmentTestCase::testCourseEnrollment in tests/CourseEnrollmentTestCase.test
Test for enrollment access and timestamping.
CourseObject::access in includes/CourseObject.inc
Access functionality for course objects.
CourseObjectUbercartTestCase::testDelayedPayment in modules/course_uc/course_uc.test

... See full list

File

./course.module, line 2245
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,
    );
  }
}