You are here

function views_timelinejs_plugin_style_timelinejs::render in Views TimelineJS integration 7.3

Same name and namespace in other branches
  1. 7 views_timelinejs_plugin_style_timelinejs.inc \views_timelinejs_plugin_style_timelinejs::render()

Render the display in this style.

Overrides views_plugin_style::render

File

./views_timelinejs_plugin_style_timelinejs.inc, line 316

Class

views_timelinejs_plugin_style_timelinejs
Style plugin to render items as TimelineJS3 slides.

Code

function render() {

  // Return if the start date field mapping is not configured.
  if (empty($this->options['timeline_fields']['start_date'])) {
    drupal_set_message(t('The Start date field mapping must be configured in the TimelineJS format settings before any slides or eras can be rendered.'), 'warning');
    return;
  }
  $timeline = new Timeline();

  // Render the fields.  If it isn't done now then the row_index will be unset
  // the first time that get_field() is called, resulting in an undefined
  // property exception.
  $this
    ->render_fields($this->view->result);

  // Render slide arrays from the views data.
  foreach ($this->view->result as $row_index => $row) {
    $this->view->row_index = $row_index;

    // Determine the type of timeline entity to build.
    $type = 'event';
    if ($this->options['timeline_fields']['type']) {
      $type = $this
        ->get_field($row_index, $this->options['timeline_fields']['type']);
    }
    switch ($type) {
      case 'title':
      case 'timeline_title_slide':
        $slide = $this
          ->build_title_slide();

        // Ensure the slide was built.
        if (!empty($slide)) {
          $timeline
            ->setTitleSlide($slide);
        }
        break;
      case 'era':
      case 'timeline_era':
        $era = $this
          ->build_era();

        // Ensure the era was built.
        if (!empty($era)) {
          $timeline
            ->addEra($era);
        }
        break;
      default:
        $slide = $this
          ->build_slide();

        // Ensure the slide was built.
        if (!empty($slide)) {
          $timeline
            ->addEvent($slide);
        }
    }
  }
  unset($this->view->row_index);

  // Skip theming if the view is being edited or previewed.
  if ($this->view->editing) {
    return '<pre>' . print_r($timeline
      ->buildArray(), 1) . '</pre>';
  }

  // Prepare the options array.
  $this
    ->prepare_timeline_options();
  return theme('views_timelinejs', array(
    'view' => $this->view,
    'timeline_options' => $this->options['timeline_config'],
    'timeline_font' => $this->options['additional_config']['font'],
    'rows' => $timeline
      ->buildArray(),
  ));
}