After fixing all the other bugs I ran through in earlier issues, I got to the point of trying to format a date field value into the right format. The problem here is that Date relies on the default method of creating views fields in Drupal 7 which does NOT retrieve the value of the date field, it only retrieves the nid of the node that has the field on it. Views does this for all fields, this is the new way that fields are handled. The problem is that passing the nid to the function that tries to format it into a date just gives you ridiculous results. Even if you adjust the logic to do a node_load() with the value, it has no idea which date field to pull up (if there is more than one date field on the node) or which value to use once it has the right field (from date or to date? delta 0 or delta 1 or delta 2?).

This part of the code will have to be totally refactored to account for the fact that Views is not retrieving the values we had available in D6.

This is where I am stopping after spending all morning trying to get this fixed. Maybe someone with more energy can figure out where to take it next.

Comments

karens’s picture

Just a note, no time to try this out at the moment. It may be that the Timeline plugin will have to add the date fields to the query once the user has specified which fields to use. If the plugin does that, it will also need to test whether they have already been added so they don't get added twice, then we would look for the date fields by name in the results, rather than the normal field result (which will be the nid).

This means that the handling for a date field will be totally different than the handling for something like the node updated date. I've already run into this in Date and Calendar, I had to create different processing depending on the type of field.

xamanu’s picture

I took a look on that. And it should be somehow possible to get/load the necessary values through something like this:

$this->view->field[$field['fieldname']]->get_value($row); (for example in TimelineEvent.class.inc, Line 93)

I have to stop on this, for now. Just wanted to tell it.

dark11star’s picture

subscribe

Anonymous’s picture

I'm working on a client project that requires me to get a working Drupal 7 versions of this module up. Which is exciting because I'll be able to get it at least to beta phase.

However, I'm having a heck of a time even figuring out what sections of code I should be looking at. I have a tiny bit of experience with views plugins, but not enough to really help me quickly orient myself to the state of this port and what needs to be done next.

I've tracked down the lines referenced in this issue and I think I have a slight grasp on them.

I'd really love to connect on IRC or Skype or email with someone who can orient me to the code and the current state of the module. I'm available 9:00am to 4:00pm PST (pacific US time) Monday through Friday and could connect other times. I'm thinking KarenS and Xamanu are likely candidates at this point, but if anyone else is familiar with the state of this port, that would help me a ton. You can email me at jblanchard ( -at- ) concentricsky.com

Thanks!

kcoop’s picture

Very interested in this too. I can't get timeline to work at all in d7.

Anonymous’s picture

StatusFileSize
new5.54 KB

So I managed to start understanding the code.

I've attached a patch that represents the beginning of my work.

How to test
* Create a content type with a field_date using a timestamp (aka datestamp) type of date.
* Create a few test nodes. Set the start/end date as the same for some and set different start/end dates for others.
* Create a view of those nodes using the timeline view style and choose a "fields" style query not a "nodes" query.
* Add fields for the title and date
* In the Settings for the Timeline style, select your SINGLE or SEPARATE date fields for the start and end date. If you select the same field for both, it'll use the end date.
* Display the view on a page.
* You can see it! Woot!

Things included in this patch:
* Grabs the start and end date in a slightly ugly but functioning fashion
* Uses datestamp as the format it will accept from a Date field. Need to have discussion as to what makes the most sense here or if all formats can be supported at once.
* Small improvement to the inclusion of the javascript: it now gets the full basepath instead of the relative path.
* Added explicit calls to theme.inc file so it gets included properly
* Updated "arguments" to "variables" for hook_theme function (that's the new D7 pattern)

Things to be concerned about this patch:
* I switched the date format in the plugin from "date" to "datestamp" so it would work for the data I had. I was confused why it was "date" in the first place. Anyone know?
* I'm almost certain it won't work for "created" and "updated" fields, just a Date field.

I will submit more patches as I clean things up more, but this seems to be a step forward. I can actually see the timeline now!

I suggest other folks work on cleaning this up and testing it for other use cases to find the other areas that need porting. I've only had time to test it for my narrow use case.

dark11star’s picture

I still get this error with the patch:

Warning: DateTime::__construct() [datetime.--construct]: Failed to parse time string (2) at position 0 (2): Unexpected character in timeline_convert_to_iso() (line 152 of .../sites/all/modules/timeline/timeline.module).
Warning: DateTime::__construct() [datetime.--construct]: Failed to parse time string (2) at position 0 (2): Unexpected character in timeline_convert_to_timestamp() (line 168 of .../sites/all/modules/timeline/timeline.module).

Maybe I didn't install the patch correctly?

Jason

Anonymous’s picture

You probably did install the patch correctly. I'd find that line and do a print statement to see what's being passed in.

What field do you have on your content type?

What page did you load to get that error?

karens’s picture

Status: Active » Needs review
StatusFileSize
new11.44 KB

I have done some work on getting the date values to be computed correctly. I used the ideas in #2 to detect the actual values of the field. That led me to the next problem, the date_format was incorrect, so I added a method to fix that.

I fixed two unrelated issues because they were keeping me from fixing other things. I added the file name to hook_theme() and I set it up to not include javascript in the Views preview because that javascript makes it impossible to alter the timeline settings.

Those fixes then led me to the next problem, which is that the timeline module insists on doing a timezone conversion for every field, ignoring the type of field. Historical dates and date fields that have no time do not use timezone conversion, so I needed to add a method of controlling the timezone conversion.

And *that* led me to problems in getDefinedDateField(), which it is doing *another* timezone conversion on date values that have already been converted, so I tried to fix that too (setting both the timezone and db_timezone to the site timezone, since by that time the dates seem to already have been converted.)

I believe this patch gets the dates to the right values. I can't actually see the timeline yet but I think that is some sort of javascript problem I am having locally. Looking at the values going into the theme I think they are right.

There is one last situation that is not resolved here. If you have a multiple value date field I am not sure it will pick the right value out. I don't have anything set up to test that, and if it is a problem it may just be something that needs to be identified as a limitation of the module.

Anyway, sorry for all the additional stuff in this patch, but here is what I have.

karens’s picture

Or if I'm wrong that getDefinedDateField() is processing dates that have already been converted, then it needs to use the same plugins that are used elsewhere to process dates and not directly call functions like timeline_convert_to_gregorian().

Also one other situation that is not yet handled correctly. It is possible to define date fields that have their own timezones. The current code is going to ignore that and display them in the site timezone, which may or may not be what is desired.

karens’s picture

StatusFileSize
new11.66 KB

I've done some more work. I have timelines working for both system post dates and date field dates. The only major problem I still have is I'm not getting the date duration -- only the start date is showing up, not the range between the start and end date.

karens’s picture

StatusFileSize
new11.66 KB

Doh! All fixed now. I had gotten rid of the end date while debugging changes and forgot to add it back.

karens’s picture

Found one additional tiny fix needed if you choose the option to start with the middle date. It needs to be rounded so you don't end up with a timestamp value that has a decimal. So the function should look like the following (the change is the line "$middle = round(($start + $end) / 2, 0);"):

  function getDefinedDateField($option, $options_field = '') {
    $timezone = timeline_get_timezone();

    // Make sure that if there is no result that a valid date (today) is getting served.
    if ($option != 'today' && $option != 'custom' && count($this->data['events']['events']) == 0) {
      $option = 'today';
    }
    switch ($option) {
      case 'today':
        return timeline_convert_to_gregorian(REQUEST_TIME, 'timestamp', $timezone, $timezone);
      case 'first':
        return timeline_convert_to_gregorian($this->data['events']['events'][0]['start'], 'iso8601', $timezone, $timezone);
      case 'last':
        return timeline_convert_to_gregorian($this->data['events']['events'][count($this->data['events']['events']) - 1]['start'], 'iso8601', $timezone, $timezone);
      case 'middle':
        $end = timeline_convert_to_timestamp($this->data['events']['events'][count($this->data['events']['events']) - 1]['start'], 'iso8601', $timezone, $timezone);
        $start = timeline_convert_to_timestamp($this->data['events']['events'][0]['start'], 'iso8601', $timezone, $timezone);
        $middle = round(($start + $end) / 2, 0);
        return timeline_convert_to_gregorian($middle, 'timestamp', $timezone, $timezone);
      case 'median':
        foreach ($this->data['events']['events'] as $date) {
          $t[] = timeline_convert_to_timestamp($date['start'], 'iso8601', $timezone, $timezone);
        }
        sort($t);
        return timeline_convert_to_gregorian($t[round(count($t)/2)], 'timestamp', $timezone, $timezone);
      case 'custom':
        if ($options_field != '') {
          return timeline_convert_to_gregorian(strtotime($options_field), 'timestamp', $timezone, $timezone);
        }
    }
    return FALSE;
  }

Can't roll a patch right now, just posting this so it can get incorporated into the commit or the next patch.

This is still working beautifully for me with a date field and both modern and historical dates. Once I get this on a live site I'll post a link.

jn2’s picture

Status: Needs review » Needs work

Neither of the patches in this thread worked for me. I first tried the patch in #12 with the fix in #13. The timeline settings form in the view's Format section would not even recognize my date field as an option for the 'start date'. (I tried several different field configurations - date and timestamp.) It did recognize the node dates, such as post date and updated date, but did not show anything in the timeline.

So I tried the patch in #6. That did recognize my date field, but after that produced nothing but error messages.

This is my first time using this module, so I am well aware of the possibility of user error. To be sure I was doing it right, I got it set up in D6 and had no trouble getting the same configuration of fields working.

tvilms’s picture

Hi, I've tried both sets of patches, both in #6 and #12. No luck getting it working for D7. I noticed two things.

1) For both patches, when configuring Timeline Settings in the View UI, I could only select a Start and End date if I was using a "Content: Post Date" type of date field. Although @KarenS says in #12 that she has the patch working with a normal date filed, I couldn't verify that.

2) Ultimately I was unable from seeing the view result with either of the patches. I was getting the following error:

Warning: include(/Applications/MAMP/htdocs/sites/all/modules/timeline/views-view-timeline.tpl.php) [function.include]: failed to open stream: No such file or directory in theme_render_template() (line 1382 of /Applications/MAMP/htdocs/includes/theme.inc).
Warning: include() [function.include]: Failed opening '/Applications/MAMP/htdocs/sites/all/modules/timeline/views-view-timeline.tpl.php' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.3.6/lib/php') in theme_render_template() (line 1382 of /Applications/MAMP/htdocs/includes/theme.inc).

karens’s picture

I have a link now to the site using all the changes I have posted: http://elderweb.com/history-timeline. As you can see, it is working fine.

That view is using a Date field with historical dates.

scottrigby’s picture

Status: Needs work » Needs review

@KarenS hi - here's a git-formatted patch against 7.x-3.x from #12, with the round() fix to getDefinedDateField() in #13.

When you get a chance, would you check if this matches the code you have on your site? I'm asking because like #14 & #15, I still two issues with this:

  1. Date fields aren't selectable in the timeline display settings (only system post date).
  2. When I do try to use the system post date, the timeline view contains only empty divs

For the second issue, i enabled debug mode, and pasting the output here in case it's revealing in any way:

array (
  'events' => 
  array (
    'events' => 
    array (
      0 => 
      array (
        'title' => 'Photosynthesis',
        'link' => false,
        'start' => '2012-01-15T00:24:34Z',
        'durationEvent' => false,
        'color' => '#0A3FAC',
        'classname' => 'timeline-set-0',
        'description' => '  
  <div class="views-field views-field-title">        <span class="field-content"><a href="/topic/photosynthesis">Photosynthesis</a></span>  </div>  
  <div class="views-field views-field-field-date">    <span class="views-label views-label-field-date">Date: </span>    <div class="field-content"><span class="date-display-single" property="dc:date" datatype="xsd:dateTime" content="2012-01-21T07:45:00-05:00">01/21/2012 - 07:45</span></div>  </div>  
  <div class="views-field views-field-body">        <div class="field-content"><h2>Resources</h2>
<p><a href="http://www.youtube.com/watch?v=C1_uez5WX1o">http://www.youtube.com/watch?v=C1_uez5WX1o</a><br /><a href="http://www.youtube.com/watch?v=LgYPeeABoUs">http://www.youtube.com/watch?v=LgYPeeABoUs</a><br /><a href="http://www.education.com/worksheet/article/photosynthesis-for-kids-coloring-page/">http://www.education.com/worksheet/article/photosynthesis-for-kids-color...</a><br /><a href="http://www.biology4kids.com/files/plants_photosynthesis.html">http://www.biology4kids.com/files/plants_photosynthesis.html</a><br /><a href="http://www.kidzpark.com/content.asp?c_id=34">http://www.kidzpark.com/content.asp?c_id=34</a></p>
<h2>Objectives</h2>
<ul><li>Explore how plants eat, breathe, and grow.</li>
<li>Recognize that people and animals need oxygen to breath.</li>
<li>Use this a tool to talk about the environment, preservation of natural spaces, earth stewardship, along with practicing handwriting, vocabulary and some math and measuring.</li>
</ul><h2>Project</h2>
<p>Water plant experiment.</p>
<h3>Materials</h3>
<ul><li>Hydrilla plant</li>
<li>Test tube</li>
<li>Funnel</li>
<li>Glass jar</li>
<li>water</li>
</ul><h3>Procedure</h3>
<p>In order to show the production of oxygen during photosynthesis, you can use a water plant. As shown in figure , immerse the plant in a tankard of water, cover the plant with a transparent funnel and put a test tube on the funnel. Make sure at the beginning there are no air bubbles in the tube. Expose the plant to sunlight and after some time you will see bubbles of oxygen gather on the test tube then collect to form a larger bubble.</p>
<p>Photograph the results.</p>
<h2>Vocabulary and Spelling words</h2>
<ul><li>Chlorophyll</li>
<li>Carbon dioxide</li>
<li>water</li>
<li>nutrients</li>
<li>greensunlight</li>
<li>oxygen</li>
</ul></div>  </div>  
  <div class="views-field views-field-created">    <span class="views-label views-label-created">Post date: </span>    <span class="field-content">01/15/2012 - 00:24</span>  </div>',
      ),
    ),
    'dateTimeFormat' => 'iso8601',
  ),
  'id' => 'timeline',
  'orientation' => 0,
  'initial_focus' => 'Jan 21 2012 17:07:06',
  'timezone' => 0,
  'controls' => false,
  'bands' => 
  array (
    0 => 'DAY',
  ),
  'summary' => 'MONTH',
  'band1_unit_width' => '10',
  'band2_unit_width' => '10',
  'theme' => 'LightTheme',
  'bubble_max_height' => '',
  'bubble_width' => '250',
)

^ This is homeschooling site for our preschooler btw :)

scottrigby’s picture

StatusFileSize
new12.62 KB

The patch would help ;) Here it is

lavamind’s picture

Patch in #18 works for me, thanks!

> Date fields aren't selectable in the timeline display settings (only system post date).

I found that if you change 'field_type' => 'date', to 'field_type' => 'datetime', in plugins/date_sources/date_field.inc, then "regular" Date fields are selectable and usable. I don't really know why that is, though...

xamanu’s picture

Status: Needs review » Fixed

I reviewed the code, committed it to the module and made a D7 development release.
Thank you all!

jgarbe’s picture

Version: master » 7.x-3.x-dev

For what it's worth, on D7 after downloading the latest 7.x version I still had to change "date" to "datetime" to get it to allow me to use CCK date fields.

I'm still however not getting a timeline to display at all. Debug timeline output is showing that content is being selected for it. I'm getting two script errors:

"JQuery is undefined" at line 72 timeline
and
"JQuery is undefined" at line 382 drupal.js?lzpzkg

I saw what (maybe?) is a similar issue in the 6 branch, but quite frankly I was befuddled by the code and thought I'd give you a heads up here. Great module by the way, hope the problem is easily fixed!

xamanu’s picture

Status: Fixed » Needs work

Thanks for reporting, jgarbe. I reopened this.

The jQuery error I have seen when using newest Simile Timeline libs from their SVN repo. Please use the ones from the github repo. We need somehow a better solution on how to handle versions of time Simile Libs for our module...

jindustry’s picture

I had similar jQuery errors from both the github and svn sources listed in the install.txt. On a whim, I tried the 2.x branch on github and the timeline is at least rendering now.

scoff’s picture

I'm kinda lost. All patches rejected.
Please tell me if there's a solution for a date field with "collect end date" enabled.
I've changed 'field_type' => 'datetime' and still I can't select my custom date field (with end date enabled) in Timeline settings.

Also I get "There is no data available to show on the timeline" but if I swith to "unformatted list" there's a node.

efarg’s picture

The same problem!
Furthermore: Date fields not showing up as options for the timeline
:-((

tigunn’s picture

Hello, I installed the patch to take into account the date in datetime format, and then it seemed to me that the end date of a period is taken into account with this correction. But this is not the case with me, even if in the configuration I chose an end date, the display is always the current date is taken into account. On the frieze, all my periods ending at the current date. Do you have any idea to correct?

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Reply:
in fact the fix works, it must be a typo in this method:

diff --git a/includes/TimelineEvent.class.inc b/includes/TimelineEvent.class.inc
index 697bebb..c784068 100644
--- a/includes/TimelineEvent.class.inc
+++ b/includes/TimelineEvent.class.inc
@@ -90,9 +90,25 @@ class TimelineEvent {
$field = $this->getDefinedFieldUsage($event_field);
if (isset($row->{$field['alias']})) {
// Loading plugin to handle date format
+ $value = $this->view->field[$field['fieldname']]->get_value($row);
+ // If this is a date field, get_value() returns an array of values.
+ if (is_array($value)) {
+ // @TODO Need to confirm if this will retrieve the right value for multiple value fields.
+ $value = array_shift($value);
+ switch ($event_field) {
+ case 'start':
+ case 'earliestStart':
+ $value = $value['value'];
+ break;
+ case 'end':
+ case 'latestEnd':
+ $value = $value['value']; // AND not : $value = $value['value2'];
+ break;
+ }
+ }
if ($conversion_callback = timeline_plugins_get_callback($field['handler'], 'date_sources')) {
- $event[$event_field]['formated'] = call_user_func($conversion_callback, $row->{$field['alias']}, 'iso8601', array('field' => $field));
- $event[$event_field]['timestamp'] = call_user_func($conversion_callback, $row->{$field['alias']}, 'timestamp', array('field' => $field));
+ $event[$event_field]['formated'] = call_user_func($conversion_callback, $value, 'iso8601', array('field' => $field));
+ $event[$event_field]['timestamp'] = call_user_func($conversion_callback, $value, 'timestamp', array('field' => $field));
}
}
}

Thank you very much for your excellent work.

blogbold’s picture

Issue summary: View changes

Hi,
just a note: the "['value2']" is correct for Drupal 7 date fields with the option "Collect an end date" activated. This means one field stores two date values.

The database table of such a date field has two columns for these values.
For example a field named "timeline earliest latest" has these (value) columns then:
- field_timeline_earliest_latest_value ... stores the "earliest" date
- field_timeline_earliest_latest_value2 ... stores the "latest" date
The Timeline module retrieves the "earliest" date from column "field_timeline_earliest_latest_value" and the "latest" date from column "field_timeline_earliest_latest_value2". So this is the reason for the "['value2']".

Using such a date field it is possible to have all four ("earliest", "start", "end", "latest") Timeline dates in just two Drupal 7 View fields (i.e. two database tables instead of four).