You are here

function course_can_take_course in Course 6

Implements hook_can_take_course().

Check for built-in access restrictions (enrollment, release/expiration).

Parameters

object $node The course node.:

object $user The user to check.:

File

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

Code

function course_can_take_course($node, $user) {
  if (!node_access('view', $node)) {
    return array(
      array(
        'success' => FALSE,
        'header' => t('Access denied'),
        'message' => t('You do not have permission to take this course.'),
      ),
    );
  }
  $sql = "SELECT * FROM {course_enrolment} WHERE nid = %d AND uid = %d";
  if ($row = db_fetch_object(db_query($sql, $node->nid, $user->uid))) {
    if ($row->enrol_end > 0 && time() > $row->enrol_end) {
      return array(
        array(
          'success' => FALSE,
          'message' => 'Sorry, your enrollment has expired for this course.',
        ),
      );
    }
  }
  if (isset($node->course['close']) && $node->course['close']) {
    if (time() > $node->course['close']) {
      return array(
        array(
          'success' => FALSE,
          'message' => 'Sorry, this course is expired.',
        ),
      );
    }
  }
}