You are here

final public function CourseObject::takeCourseObject in Course 7

Same name and namespace in other branches
  1. 6 includes/course_object.core.inc \CourseObject::takeCourseObject()
  2. 7.2 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/CourseObject.inc, line 562

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', REQUEST_TIME)
        ->save();
    }
  }
  else {

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

  // 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).
      drupal_goto($url, array(
        'external' => TRUE,
      ));
  }
}