You are here

function views_gantt_data_json in Views Gantt 7.2

1 string reference to 'views_gantt_data_json'
views_gantt_menu in ./views_gantt.module
Implements hook_menu().

File

./views_gantt.module, line 64
Module file for Views Gantt

Code

function views_gantt_data_json() {
  $data = array();
  $links = array();
  if (!isset($_SESSION['views_gantt']) && isset($_GET['view'], $_GET['display'], $_GET['project'])) {
    _views_gantt_load_view($_GET['view'], $_GET['display'], $_GET['project']);
  }
  if (isset($_SESSION['views_gantt'])) {
    $project_id = $_SESSION['views_gantt']['project']['id'];
    foreach ($_SESSION['views_gantt']['tasks'] as $id => $task) {
      if (!$task['parent_id'] && $id != $project_id) {
        $task['parent_id'] = $project_id;
      }
      $row = array(
        'id' => $id,
        'text' => $task['name'],
        'start_date' => $task['est'],
        'duration' => $task['duration'] / 8,
        'progress' => $task['percentcompleted'] / 100,
        'parent' => $task['parent_id'],
        'open' => TRUE,
        'type' => $id == $project_id ? 'project' : 'task',
      );
      if (!empty($task['columns'])) {
        foreach ($task['columns'] as $col_key => $col_val) {
          if (!array_key_exists($col_key, $row)) {
            $row[$col_key] = $col_val;
          }
        }
      }
      $data[] = $row;
      if ($task['predecessortasks']) {
        $links[] = array(
          'id' => $task['predecessortasks'] . '_' . $id,
          'source' => $task['predecessortasks'],
          'target' => $id,
          'type' => 0,
        );
      }
    }
  }
  drupal_json_output(array(
    'data' => $data,
    'links' => $links,
  ));
}