You are here

function course_outline_list in Course 6

Same name and namespace in other branches
  1. 7.2 includes/course.outline.inc \course_outline_list()
  2. 7 includes/course.outline.inc \course_outline_list()

Generate HTML of the course outline.

Parameters

object $node:

Return value

course outline list.

1 call to course_outline_list()
_course_block_outline_view in includes/course.block.inc
Course block callback: outline view.
2 string references to 'course_outline_list'
CourseObjectBook::optionsForm in modules/course_book/course_book.classes.inc
Default options form for all course objects.
course_course_handlers in ./course.module
Implements hook_course_handlers().

File

includes/course.outline.inc, line 414
course_outline.inc

Code

function course_outline_list($node) {
  global $user;
  $course = course_get_course($node, $user);

  // Iterate over objects.
  $workflow = array();
  $prev_req = NULL;
  foreach ($course
    ->getObjects() as $key => $courseObject) {
    $step = array();
    $step['style'] = 'not-started';
    $step['id'] = 'course-object-' . $courseObject
      ->getId();
    $step['image'] = '';
    $step['status'] = '';
    if (!$courseObject
      ->access('see')) {
      if ($status = $courseObject
        ->getStatus()) {
        drupal_set_message(filter_xss($status), 'info');
      }
      continue;
    }
    if ($courseObject
      ->access('take')) {

      // User can take this course object.
      $step['link'] = $courseObject
        ->getUrl();
      if (!$prev_req || $prev_req
        ->getFulfillment()
        ->isComplete()) {
        $step['status'] = 'Begin';
      }

      // Step is complete.
      if ($courseObject
        ->getFulfillment()
        ->isComplete()) {
        $step['class'] = 'completed';
        $step['status'] = 'Complete';
        $step['image'] = 'misc/watchdog-ok.png';
      }
      elseif ($courseObject
        ->getFulfillment()
        ->getId()) {
        $step['status'] = 'Continue';
        $step['class'] = 'continue';
        $step['image'] = 'misc/menu-collapsed.png';
        if ($course
          ->getActive() === $courseObject) {
          $step['status'] = $courseObject
            ->getStatus();
          if (!$step['status'] && $courseObject
            ->getCourse()
            ->getActive()
            ->getId() == $courseObject
            ->getId()) {
            $step['status'] = 'In progress';
            $step['class'] = 'in-progress';
            $step['image'] = 'misc/watchdog-warning.png';
          }
        }
      }
    }
    else {

      // User cannot access this step yet.
      $step['style'] = 'not-started';
      $step['status'] = implode('<br/>', $courseObject
        ->getAccessMessages());
    }
    $img = theme('image', $step['image']);
    if (empty($step['link'])) {
      $data = $courseObject
        ->getTitle() . '<br/><span class="course-outline-status">' . $step['status'] . '</span>';
    }
    else {
      $data = $img . ' ' . l("{$courseObject->getTitle()}<br/>", $step['link'], array(
        'html' => TRUE,
      )) . '<span class="course-outline-status">' . $step['status'] . '</span>';
    }
    $item = array(
      'data' => $data,
      'id' => $step['id'],
      'class' => $step['style'],
    );

    // Allow other modules to modify this list item.
    $courseObject
      ->overrideOutlineListItem($item);

    // Add this item to the list.
    $workflow[] = $item;

    // We have to clone it, otherwise $courseObject becomes the next object.
    $prev_req = clone $courseObject;
  }
  if ($prev_req && $prev_req
    ->getFulfillment()
    ->isComplete()) {
    $workflow[] = array(
      'data' => $img . ' ' . l(t('Complete'), "node/{$node->nid}/course-complete", array(
        'html' => TRUE,
      )),
      'id' => 'complete',
    );
  }
  $output = '';
  if ($workflow) {
    $output .= '<div class="course-outline">';
    $output .= '<span class="trigger"></span>';
    $output .= '<h4 class="course-title">' . filter_xss($node->title) . '</h4>';
    $output .= theme('item_list', $workflow);
    $output .= '</div>';
  }
  return $output;
}