You are here

function course_signup_course_access in Course 7

Same name and namespace in other branches
  1. 7.2 modules/course_signup/course_signup.module \course_signup_course_access()

Implements hook_course_access().

File

modules/course_signup/course_signup.module, line 239

Code

function course_signup_course_access($op, $node, $user) {
  if ($op == 'enroll') {
    $hooks = array();

    // We depend on Signup Restrict by Role for enrollment access per role.
    if (module_exists('signup_restrict_by_role')) {
      $check = signup_restrict_by_role_access_signup($node, $user);
      $check['message'] = str_replace('signup', 'course enrollment', $check['message']);
      $hooks[] = $check;
    }
    if (!empty($node->signup)) {
      if (!empty($node->signup_status)) {
        module_load_include('inc', 'signup', 'includes/date');
        if (($field = signup_date_field($node->type)) && $field != 'none') {
          $items = field_get_items('node', $node, $field['field_name']);
          if (!empty($items[0]['value'])) {

            // This node is signup-enabled and closed by date.
            $close_stamp = strtotime($items[0]['value'] . ' UTC');
            $signup_close_early = variable_get('signup_close_early', 0);
            $close_stamp -= $signup_close_early * 3600;
            if (REQUEST_TIME > $close_stamp) {
              $hooks['course_signup'] = array(
                'header' => t(''),
                'success' => FALSE,
                'message' => t('Enrollments closed on @date.', array(
                  '@date' => format_date($close_stamp, 'long'),
                )),
                'weight' => 100,
              );
            }
          }
        }
      }
      else {

        // This node is signup-enabled and closed.
        $hooks['course_signup'] = array(
          'header' => t(''),
          'success' => FALSE,
          'message' => t('Enrollments are closed.'),
          'weight' => 100,
        );
      }
    }
    return $hooks;
  }
}