You are here

function views_gantt_plugin_style_gantt::views_gantt_before_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::views_gantt_before_render()
1 call to views_gantt_plugin_style_gantt::views_gantt_before_render()
views_gantt_plugin_style_gantt::render in ./views_gantt_plugin_style_gantt.inc
Render the given style.

File

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

Class

views_gantt_plugin_style_gantt
Style plugin to render Gantt charts.

Code

function views_gantt_before_render() {

  // Save view name to variable.
  variable_set('views_gantt_view_name', $this->view->name);

  // Save data in session to use it when we will build XML file for chart.
  $_SESSION['views_gantt']['project'] = $this->project;
  $_SESSION['views_gantt']['tasks'] = $this->tasks;
  $fields = array(
    'project_field' => $this->options['project_id_field'],
    'parent_field' => $this->options['parent_id_field'],
  );
  foreach ($fields as $key => $value) {
    foreach ($this->view->display as $display) {
      $display_options = $display->display_options;
      if (isset($display_options['style_plugin']) && $display_options['style_plugin'] == 'gantt') {
        if (isset($display->display_options['fields'][$value])) {
          $fields[$key] = $display->display_options['fields'][$value]['field'];
        }
        break;
      }
    }
  }
  $_SESSION['views_gantt']['project_field'] = $fields['project_field'];
  $_SESSION['views_gantt']['parent_field'] = $fields['parent_field'];

  // IF we have the progress in columns, we need to change key for
  // automatical update when updating task.
  $columns = array();
  foreach ($this->columns as $key => $value) {
    if ($this->options['progress_field'] == $key) {
      $columns['progress'] = $value;
    }
    else {
      $columns[$key] = $value;
    }
  }
  $this->columns = $columns;

  // Add dhtmlxgantt library.
  $library = libraries_load('dhtmlxgantt');

  // Add css to fix chart style.
  drupal_add_css(drupal_get_path('module', 'views_gantt') . "/css/reset.css");

  // Add js.
  drupal_add_js(drupal_get_path('module', 'views_gantt') . "/js/views_gantt.js");

  // Add jquery ui Dialog library.
  drupal_add_library('system', 'ui.dialog');
  drupal_add_library('system', 'jquery.cookie');

  // Add globals variables to use it in js.
  $settings = array(
    'views_gantt' => array(
      'project_id' => $this->project['id'],
      'exposed_input' => isset($this->view->exposed_input) ? $this->view->exposed_input : NULL,
      'fullscreen_button' => '<a class="gantt-fullscreen">Fullscreen</a>',
      'columns' => $this->columns,
      'task_type' => $this->options['task_type'],
      'add_task' => $this->options['add_task'],
      'edit_task' => $this->options['edit_task'],
      'scale' => $this->options['scale'],
      'ajax_path' => url('views/ajax'),
      'view' => array(
        'href' => url(current_path(), array(
          'query' => drupal_get_query_parameters(),
        )),
        'settings' => array(
          'view_name' => $this->view->name,
          'view_display_id' => $this->view->current_display,
          'view_args' => check_plain(implode('/', $this->view->args)),
          'view_path' => check_plain(current_path()),
          'view_base_path' => $this->view
            ->get_path(),
          'view_dom_id' => $this->view->dom_id,
          'pager_element' => isset($this->view->query->pager) ? $this->view->query->pager
            ->get_pager_id() : 0,
        ),
      ),
    ),
  );

  // Send view settings to js.
  drupal_add_js($settings, 'setting');

  // Add js for proper work Views with ajax.
  views_add_js('ajax_view');
}