You are here

function views_gantt_plugin_style_gantt::render in Views Gantt 7.2

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

Render the given style.

Overrides views_plugin_style::render

File

./views_gantt_plugin_style_gantt.inc, line 187
Contains the list style plugin.

Class

views_gantt_plugin_style_gantt
Style plugin to render Gantt charts.

Code

function render() {

  // Check for live preview.
  if (isset($this->view->live_preview)) {
    return t('Gantt Chart not compatible with live preview.');
  }

  // Get columns
  if (!empty($this->options['columns'])) {
    $fields = $this->display->handler
      ->get_handlers('field');
    foreach ($this->options['columns'] as $field) {
      if (!empty($field) && !empty($fields[$field])) {
        $this->columns[$field] = $fields[$field]
          ->label();
      }
    }
  }
  $this
    ->options_fields();
  $this
    ->options_node();

  // Get project data.
  if (!$this
    ->get_project()) {
    return;
  }

  // Get array of tasks.
  foreach ($this->view->result as $key => $row) {
    $this
      ->add_task($row, 'view', $key);
  }
  foreach ($this->tasks as $key => $task) {
    $this
      ->load_missing_tasks($key);
    $this
      ->load_missing_values($key);
  }

  // Allow to alter tasks array before next modifications.
  drupal_alter('views_gantt_tasks_prerender', $this->tasks);

  // Remove tasks marked for deletion
  foreach ($this->tasks as $key => $value) {
    if ($this
      ->is_delete($key)) {
      unset($this->tasks[$key]);
    }
  }

  // Build hierarchical tree of tasks and fix incorrect values.
  $tree = $this
    ->build_tree($this->tasks);
  foreach ($tree as $key => $task) {
    $this
      ->check_date($task);
    $this
      ->check_duration($task);
    $this
      ->calculate_progress($task);
  }

  // Exclude incorrect tasks.
  foreach ($this->tasks as $key => $value) {
    if (!$this
      ->is_correct($key)) {
      unset($this->tasks[$key]);
    }
  }
  $this
    ->mark_modified_tasks();
  $this
    ->views_gantt_before_render();
  return parent::render();
}