what about some more filter operators for date module to use in views? At the moment there are only the three standard operators (equal to, not equal to, matches the pattern). For a date filter there should be at least the two operators "greater than" and "less than" to show lists of upcoming events or passed entries, so users aren't forced to use the event module to do such queries (the event module is really great, but not everybody needs calendar views and such things).

Comments

tmp’s picture

I couldn't agree more ! Please have a look at my feature request regarding date.module and views : http://drupal.org/node/69872

RayZ’s picture

I also need these extra filters ... @KarenS any chance of you adding these soon? If not, could you spare a few minutes to explain briefly what needs to be done where in the code? I might be able to do it myselft with a little guidance. Likewise for the issue on arguments mentioned above.

KarenS’s picture

I'm going to be out of town for the next week and a half or so. I was trying to get to this before I left, but it's not looking like I will. I still have tomorrow, but if I don't get it done then I'll try to outline what is needed before I go.

RayZ’s picture

You have no idea how happy it would make me if you do get to it :-) (non-profit site I'm doing wants to go live in a few days and needs it). I suppose the only alternative short term is switch from a date field to event-enabling the content type and using the event fields, right?

Btw, as I was looking through the code, it doesn't look like there is any direct support for views in the date.module. Are you planning to implement this through event_views, or directly in the date.module?

Thanks.

KarenS’s picture

I was actually waiting to see what if anything happened to the views patches for cck, since that affects what is done in the date module. I may just end up doing something separately, though.

KarenS’s picture

I see that JonBob has just added some views argument handlers to the cck version of the date.module, so I have added them to this module as well. I also added less than and greater than to the date filters. The argument handlers work for the iso date field but still need to be adapted for the timestamp date field.

These additions should make the module more functional. I went ahead and added them without spending a lot of time testing them because I am going out of town and I know people need these ASAP, so just post any issues that come up (and you're more than welcome to post patches!)

More changes are needed, and I plan to spend more time on this when I get back.

RayZ’s picture

Sweet!!
A quick test shows that date>2006-08-04T00:00:00 gives me a list of future dates. Using 'now' as the value did not work, however.
Thank you.

RayZ’s picture

I even found a workaround to implement the date_field > now. I set up a filter that has date_field > 'some_arbitrary_date_value', then in the argument handling code, I entered:

if (!function_exists('date_unix2iso')) {
  include_once(drupal_get_path('module', 'date') .'/date.inc');
}
$view->filter[2]['value'] = date_unix2iso(date_gmadj_zone(time()));

You have to enable at least one argument defined for the view for this to work, and of course you have to make sure you put the value in the correct filter. E.g. I have a taxonomy argument whose default is to display all values.

RayZ’s picture

Quick update ... turns out the call to date_gmadj_zone() is not needed. Without it I get the correct behavior, with it things are off by 4 hours (EDT).

drubb’s picture

Thanks, RayZ, great idea. I altered it this way:

- filter 'greater than or equal to' without argument
- dummy argument #1, e.g. 'node id', standard 'Display all values'
- argument handling code:

$view->filter[1]['value'] = date('Y-m-d');

This shows a list of nodes with upcoming date entries.

dodorama’s picture

any plan to add date:day, date:week, date:month filters as implemented on event.views ?

KarenS’s picture

I just committed changes to the cvs version of the date module adding lots of new date range capabilities to arguments (see http://drupal.org/node/69872). Once those seem to be working reliably, I'll tackle filters. In the meantime, I'd love to get feedback on the new date range argument features.

fronbow’s picture

Is it possible to see an export as I can't work out how to get the filter to look for dates >= today?

All I seem to get is an sql error, so I'm guessing I'm doing something wrong?

Warning: You have an error in your SQL syntax near ''2006-09-11T22:13:58') ' at line 1 query: 
SELECT count(node.nid) FROM d_node node 
LEFT JOIN d_term_node term_node ON node.nid = term_node.nid 
LEFT JOIN d_node_content_event node_data_field_end_date_2 ON node.vid = node_data_field_end_date_2.vid 
LEFT JOIN d_node_content_event node_data_field_summary ON node.vid = node_data_field_summary.vid 
LEFT JOIN d_node_content_event node_data_field_event_date_2 ON node.vid = node_data_field_event_date_2.vid 
WHERE (node.status = '1') AND (node.type IN ('content_event')) 
AND (term_node.tid IN ('78')) AND (node_data_field_end_date_2.field_end_date_2_value >= '') 
AND (. '2006-09-11T22:13:58') 

this is the first part of the error; the second part doesn't look like it would retrieve anything relevant at all!

Cheers

pulpzebra’s picture

I got it working simply adding a cck date field to the filter list and setting "greater than or equal to" operator AND leaving empty the "value" field of the filter. Am I wrong if I say that $view->filter[1] ... corresponds actually to the second filter criteria set?

KarenS’s picture

I've started the process of expanding on the filters options in the latest commit (both cvs and 4.7). There will be more coming later.

drewish’s picture

as a temporary hack i added an date field argument to the view and used the following code to specify a default argument:

if (!isset($args[0])) {
  $args[] = '@--@P1M';
}
return $args;
KarenS’s picture

Status: Active » Fixed

Finally got this done, more filters are available in latest commit for both 4.7 and cvs. Also, the filters now properly handle 'now' + $delta values.

KarenS’s picture

If people want to request additional filters besides the ones I just added, please start a new feature request rather than using this one. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)
zilverdistel’s picture

Version: 7.x-1.x-dev » 4.7.x-1.x-dev

No idea how this got into the 7.x issues. Changed it to what I think it should be.