You are here

function course_cron in Course 6

Same name and namespace in other branches
  1. 8.3 course.module \course_cron()
  2. 8.2 course.module \course_cron()
  3. 7.2 course.module \course_cron()
  4. 7 course.module \course_cron()

Implements hook_cron().

Revoke access to inaccessible objects.

File

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

Code

function course_cron() {
  $handlers = course_get_handlers('object');
  $modules = array();
  foreach ($handlers as $module => $object) {
    foreach ($object as $key => $info) {
      if (is_subclass_of($info['class'], 'CourseObjectNode')) {

        // This module provides an object of type CourseObjectNode.
        $modules[] = $module;
      }
    }
  }
  if ($modules) {

    // Get a list of fulfillments for CourseObjectNodes.
    $placeholders = db_placeholders($modules, 'varchar');
    $sql = "SELECT * FROM {course_outline}\n    INNER JOIN {course_outline_fulfillment} USING (coid)\n    WHERE module in ({$placeholders})";
    $result = db_query($sql, $modules);
    while ($row = db_fetch_object($result)) {
      $extra = unserialize($row->data);
      if ($extra['private']) {

        // This fulfillment used private content.
        $user = user_load($row->uid);
        $courseObject = course_get_course_object_by_id($row->coid, $user);
        if (!$courseObject
          ->access('take')) {

          // User has no access to take this course object. Revoke access.
          $courseObject
            ->revoke();
        }
      }
    }
  }
}