You are here

function CourseObject::buildContent in Course 7

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

Builds a structured array representing the entity's content.

Overrides Entity::buildContent

See also

entity_build_content()

File

includes/CourseObject.inc, line 1056

Class

CourseObject
Parent abstract base class of all course objects.

Code

function buildContent($view_mode = 'full', $langcode = NULL) {
  $content = parent::buildContent($view_mode, $langcode);
  $step = array();
  $step['id'] = 'course-object-' . $this
    ->getId();
  $step['image'] = '';
  $step['status'] = '';
  if ($this
    ->access('see')) {
    if ($this
      ->access('take')) {

      // User can take this course object.
      $step['link'] = $this
        ->getUrl();
      $step['class'][] = 'accessible';
      $step['status'] = t('Not started');

      // Step is complete.
      if ($this
        ->getFulfillment()
        ->isComplete()) {
        $step['class'][] = 'completed';
        $step['status'] = t('Complete');
        $step['image'] = 'misc/watchdog-ok.png';
      }
      elseif ($this
        ->getFulfillment()
        ->getId()) {
        $step['status'] = t('In progress');
        $step['class'][] = 'in-progress';
        $step['image'] = '';
      }
      if ($this
        ->getCourse()
        ->getActive() === $this) {
        $step['class'][] = 'active';
      }
    }
    else {

      // User cannot access this step yet.
      $step['class'] = array(
        'not-accessible',
      );
      $step['status'] = implode('<br/>', $this
        ->getAccessMessages());
    }
    if ($this
      ->isRequired()) {
      $step['class'][] = 'required';
    }
    $step['class'][] = drupal_html_class($this
      ->getComponent() . '_' . $this
      ->getModule());
    $img = !empty($step['image']) ? theme('image', array(
      'path' => $step['image'],
      'alt' => strip_tags($step['status']),
    )) : '';
    $content['course_outline_image'] = array(
      '#markup' => $img,
    );
    $content['course_outline_link'] = array(
      '#markup' => $this
        ->access('take') ? l($this
        ->getTitle(), $this
        ->getUrl()) : $this
        ->getTitle(),
    );
    $content['course_outline_status'] = array(
      '#markup' => $step['status'],
      '#prefix' => '<div>',
      '#suffix' => '</div>',
    );
  }
  return $content;
}