You are here

function course_cron in Course 7

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

Implements hook_cron().

Revoke access to inaccessible objects.

File

./course.module, line 2633
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.
    $sql = "SELECT * FROM {course_outline}\n    INNER JOIN {course_outline_fulfillment} USING (coid)\n    WHERE module IN (:modules)";
    $result = db_query($sql, array(
      ':modules' => $modules,
    ));
    while ($row = $result
      ->fetch()) {
      $extra = unserialize($row->data);
      if (!empty($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)) {

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