You are here

function course_node_view in Course 7

Same name and namespace in other branches
  1. 7.2 course.module \course_node_view()

Implements hook_node_view().

File

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

Code

function course_node_view($node, $view_mode, $langcode) {
  if (course_node_is_course($node)) {
    global $user;
    $enrollment = course_enrollment_load($node->nid, $user->uid);
    if (!empty($enrollment) && $enrollment->status) {

      // User is already in course. Check take access.
      $access = course_take_course_access($node, $user);
    }
    else {

      // User not in course. Check enroll access.
      $access = course_enroll_access($node, $user);
    }
    if (!$access['success']) {
      $node->content['course_messages']['#markup'] = '<div class="course-restriction">' . "<h4>" . $access['header'] . "</h4>" . '<div class="course-restriction-message">' . $access['message'] . '</div></div>';
    }
    else {

      // Render take course button.
      $node->content['course']['#markup'] = theme('course_take_course_button', array(
        'node' => $node,
      ));
    }
  }
}