You are here

function course_take_course_access in Course 6

Same name and namespace in other branches
  1. 7 course.module \course_take_course_access()

Determine if taking this course should be restricted.

Parameters

object $node: By reference. The course node.

Return value

boolean|array Either FALSE, or an array containing:

  • success: Boolean. Indicates whether or not the user has permission to take this course.
  • message: String. If success is FALSE, a message to display to the user.
5 calls to course_take_course_access()
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.
CourseObjectUbercartTestCase::testUbercartEnrollment in modules/course_uc/course_uc.test
course_take_course in ./course.module
Take a course.

File

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

Code

function course_take_course_access($node, $account = NULL, $flush = FALSE) {
  if (!$account) {
    global $user;
    $account = $user;
  }
  static $courses = array();

  // Don't let anonymous users see /takecourse. Also keeps from being indexed.
  if (arg(2) == 'takecourse' && !user_is_logged_in() && $_SERVER['SCRIPT_NAME'] != '/cron.php') {
    drupal_set_message(t('You must login or register before taking this course.'));
    drupal_goto('user/login', drupal_get_destination());
  }
  if (!isset($courses[$node->nid]) || $flush) {
    $courses[$node->nid]['success'] = TRUE;

    // Allow modules to determine if this course should be restricted.
    $hooks = module_invoke_all('can_take_course', $node, $account);
    foreach ($hooks as $key => $hook) {
      if (!$hook) {

        // Ok. Old style blocker. But look for messages.
        $courses[$node->nid] = FALSE;
      }
      if (is_array($hook) && !$hook['success']) {

        // New style blocker, return immediately.
        $courses[$node->nid] = $hook;
        return $hook;
      }
    }
  }
  if (is_array($courses[$node->nid])) {
    return $courses[$node->nid];
  }
  else {
    return array(
      'success' => $courses[$node->nid],
      'message' => "Old style blocker",
    );
  }
}