Arto,
First of all, thank you for the big job in this module, it's a big add-on that was missing.
According to that thread http://drupal.org/node/92901 It seems that timeline doesn't play well with CCK date field.
In my case I have setted up a new node type to print project on a Gantt diagram like using the timeline module. I put two date fields in a new CCK node type, one field for the start date the second for the end. But I fallen to manage to get timeline module take them into account.
Is timeline module supposed to work only with event module or creation date of a node or should it also work with CCK date field ? If the last case is true, do you have any idea of what's going wrong ?
Thank you, regards,
Eric

Comments

Arto’s picture

Title: Timeline doesn't work with date cck field » Timeline doesn't work with CCK date field
Version: master » 4.7.x-1.x-dev
Assigned: Unassigned » Arto
nickbits’s picture

Hi All,

I can confirm this is creating issues. Not sure if this will help to sort the issue, I create a new node type using CCK. The node type has:

- A title
- A description
- A start date
- An end date

I then setup the timeline view so that the last two fields correspond to the start and end date in the view as stated in the instructions. I have also filtered the view so only this node type is used. However, the timeline only displays the date the node was created and not the dates entered. I have tried the two fields as both a date and a stamp with no luck.

Nick

MrTaco’s picture

here's a replacement timeline_data function that fixes that problem

function timeline_data($view, $view_args = array(), $teasers = TRUE, $links = TRUE) {

  $vd = fopen( "/home/lowessigns/public_html/files/vd.txt" , "w" );
  fputs( $vd, "\r\rview data = " . print_r( $view, true ) );
  
  $start_field = !empty($view->field[0]['field']) ? $view->field[0]['queryname'] : NULL;
  $end_field   = !empty($view->field[1]['field']) ? $view->field[1]['queryname'] : NULL;
  $title_field = !empty($view->field[2]['field']) ? $view->field[2]['queryname'] : NULL;

  $items = (object)views_build_view('items', $view, $view_args, FALSE, $view->nodes_per_page);
  $nids = array_map(create_function('$item', 'return $item->nid;'), $items->items);

  fputs( $vd, "\r\r  items = " . print_r( $items, true ) );
    
  $events = array();
  foreach ($items->items as $item) {
  
    $node = node_load(array( 'nid' => $item->nid ));
  
    $start_value = $node->created;
    $start_value = !empty( $item->$start_field ) ? $item->$start_field : $start_value;
  
    $end_value = NULL;
    $end_value = !empty( $item->$end_field ) ? $item->$end_field : $end_value;
  
    $node_title = $node->title;
    $node_title = !empty( $item->$title_field ) ? $item->$title_field : $node_title;
    
    fputs( $vd, "\r\r  node = " . print_r( $node, true ) );
    fputs( $vd, "\r\r  start_field = $start_field = " . print_r( $start_value, true ) );
    fputs( $vd, "\r  end_field = $end_field = " . print_r( $end_value, true ) );
    
    $event = array(
      'title'       => $node_title,
      'link'        => url( "node/$node->nid/" ),
      'start'       => timeline_format_date( $start_value ),
      'end'         => timeline_format_date( $end_value ),
      //'isDuration'  => $end_field ? 'true' : 'false', // NOTE: not actually needed
      'description' => $node->teaser,
    );
    
    if (is_null($event['end'])) unset($event['end']);
    
    $events[] = $event;
  }
  
  fputs( $vd, "\r\revents = " . print_r( $events, true ) );
    
  fclose( $vd );
  
  return $events;
}
Arto’s picture

Status: Active » Needs review

Thanks for the fix, John. I will apply it to CVS as soon as I get a chance to review it. (If at all possible, please submit fixes in patch file format, since that makes seeing the actual changes a lot easier and speeds up integrating the fix.)

Arto’s picture

Status: Needs review » Fixed

CCK compatibility implemented in CVS commit [47570], and successfully tested with Views 4.7.x-1.2, CCK 4.7.x-1.0, Date 4.7.x-1.0 and Event 4.7.x-1.x-dev.

Use the first and second fields in the view for the start/end dates, respectively, and if you add a third field, too, then that will be used for the timeline event's title.

fm’s picture

Title: Timeline doesn't work with CCK date field » MrTaco's replacement code

John, I upgraded to php5 and swapped in your code. After some cursory tests, it seems to work like a charm. Thanks!

Next, I'm going to try to install the ADOdb Date Library and see if I can't roll the date range back to 100 AD.

fm’s picture

Title: MrTaco's replacement code » Timeline doesn't work with CCK date field

Oops, accidentally changed issue title. Changing it back herewith.

Arto’s picture

Pete, there is no need to swap in John's code - his fix has been integrated into the official version of the module Timeline for a while now. Just grab release 4.7.x-1.0.

Anonymous’s picture

Status: Fixed » Closed (fixed)