You are here

final public function CourseObject::takeCourseObject in Course 6

Same name and namespace in other branches
  1. 7.2 includes/CourseObject.inc \CourseObject::takeCourseObject()
  2. 7 includes/CourseObject.inc \CourseObject::takeCourseObject()

Take a course object.

  • Set the session of this course object being taken. This allows for non-node objects to be tracked.
  • Delegate the course object take functionality

Return value

mixed HTML content or a redirect.

File

includes/course_object.core.inc, line 534

Class

CourseObject
Parent abstract base class of all course objects.

Code

public final function takeCourseObject() {
  $_SESSION['course']['active'] = $this
    ->getCourseNid();
  $_SESSION['course'][$this
    ->getCourseNid()]['taking']['active'] = $this
    ->getId();

  // Run access checks.
  if ($this
    ->access('take')) {

    // Grant access to external course object.
    $this
      ->grant();

    // Record start date.
    if (!$this
      ->getFulfillment()
      ->getOption('date_started')) {
      $this
        ->getFulfillment()
        ->setOption('date_started', time());
    }
  }
  else {

    // User can't access this object, revoke access.
    $this
      ->revoke();
    return FALSE;
  }

  // Save fulfillment record.
  $this
    ->getFulfillment()
    ->save();

  // If we're not displaying any content but we want to fire take() anyway, to
  // let the course object know we sent the user.
  $out = $this
    ->take();
  $url = $this
    ->getTakeUrl();
  switch ($this
    ->getTakeType()) {
    case 'iframe':
      return course_iframe($url);
    case 'popup':
      return "will popup {$url}";
    case 'content':
      return $out;
    case 'redirect':
    default:

      // This URL should have already been url()'d (it might be external).
      session_write_close();
      header("Location: {$url}");
      exit;
  }
}