You are here

function course_course_can_enrol in Course 6

Implements hook_course_can_enrol().

Block enrollments when a course has either not yet started or is expired.

File

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

Code

function course_course_can_enrol($node, $user) {
  if (!node_access('view', $node)) {
    return array(
      array(
        'success' => FALSE,
        'header' => t('Access denied'),
        'message' => t('You do not have permission to enroll into this course'),
      ),
    );
  }
  if (!empty($node->course['open']) && time() < $node->course['open']) {
    return array(
      array(
        'success' => FALSE,
        'message' => t('This course opens on %date.', array(
          '%date' => format_date($node->course['open'], 'custom', 'F, jS Y'),
        )),
      ),
    );
  }
  if (!empty($node->course['close']) && time() > $node->course['close']) {
    return array(
      array(
        'success' => FALSE,
        'message' => t('This course closed on %date and is no longer available for enrollments.', array(
          '%date' => format_date($node->course['close'], 'custom', 'F, jS Y'),
        )),
      ),
    );
  }
  if (!empty($node->course['live_from_date']) && REQUEST_TIME > $node->course['live_from_date']) {
    return array(
      'course_live_started' => array(
        'success' => FALSE,
        'message' => t('This live activity started on %date and is no longer available for enrollments.', array(
          '%date' => date('F, jS Y', $node->course['live_from_date']),
        )),
      ),
    );
  }
}