You are here

function course_init in Course 7

Same name and namespace in other branches
  1. 8.3 course.module \course_init()
  2. 8.2 course.module \course_init()
  3. 6 course.module \course_init()
  4. 7.2 course.module \course_init()
  5. 3.x course.module \course_init()

Implements hook_init().

Detect and set course context. Adds javascript for course objects that require polling. Hack for #1902104.

File

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

Code

function course_init() {
  course_context();
  if (!($courseNode = course_get_context())) {

    // Set course context for all modules that define course context handlers.
    // @see hook_course_handlers().
    $modules = course_get_handlers('object');
    foreach ($modules as $module => $handlers) {
      if (is_array($handlers)) {
        foreach ($handlers as $handler) {

          // We expect query parameters suitable for course_determine_context().
          if ($params = call_user_func(array(
            $handler['class'],
            'context',
          ))) {
            if (is_array($params) && isset($params['object_type']) && isset($params['instance'])) {
              if ($courseNode = course_determine_context($module, $params['object_type'], $params['instance'])) {
                course_set_context($courseNode);
              }
            }
          }
        }
      }
    }
  }
  if (class_exists('Course') && $courseNode) {

    // Check that Course exists for a special use case where Autoload hasn't yet
    // cached the Course class.
    $course = course_get_course($courseNode);
    if ($course && ($active = $course
      ->getActive())) {
      if ($active
        ->hasPolling()) {
        drupal_add_js(array(
          'courseAjaxNavPath' => url('node/' . $courseNode->nid . '/course-object/' . $course
            ->getActive()
            ->getId() . '/ajax/nav'),
        ), array(
          'type' => 'setting',
          'scope' => JS_DEFAULT,
        ));
      }
    }
  }
}