eZ Community » Forums » Developer » Filtering by publish and unpublish date
expandshrink

Filtering by publish and unpublish date

Filtering by publish and unpublish date

Wednesday 26 June 2013 5:19:46 pm - 6 replies

Hi there.

I have a class "news" with two fields: from_time and to_time

to_time field may be empty, and I need to show my news following this criteria:

- if to_time has a value, I have to consider it together with publish_date
- if from_time is empty, I have to consider ONLY publish_date, because this news never expires.

 

I tried this kind of fetch:

{def $first_news=fetch( 'content',
                                 'list',
                                 hash('parent_node_id', 128, 
                                         'class_filter_type', 'include',
                                         'class_filter_array', array( 'news' ),
                                         'attribute_filter', array('or',
                                                                       array( 'and', array( 'news/from_time', '<=', $today),
                                                                                         array( 'news/to_time', '=', 'null' ) ),  
                                                                       array( 'and', array( 'news/from_time', '<=', $today ),
                                               array( 'news/to_time', '>=', $oggi ),
         array( 'news/to_time', '!=', 'null') )  ),
'sort_by', array(array( 'priority', false() ),
                                              array( 'attribute', false(), 'news/from_time') ),                               
                 'limit',1  ) )} 

but I get this error:

Cannot retrieve attribute of a NULL

 

How can I solve it? Where's my mistake?

Thank you very much!

Modified on Wednesday 26 June 2013 5:26:48 pm by Simone Conti

Wednesday 26 June 2013 8:54:30 pm

Hello Simone,

It might help to post your code to a gist, pastebin or use share.ez.no source code formatting options. It would really help make your code more easily understandable and readable.

I noticed a solution article with a similar solution on eZpedia today: http://www.ezpedia.org/solution/how_to_fetch_content_based_on_view_parameter_date_range

I hope this helps

Cheers,
//kracker
Theme:  K.Flay - You Say ...
Mirror: https://soundcloud.com/kflay/k-flay-you-say

Modified on Wednesday 26 June 2013 8:56:21 pm by // kracker

Wednesday 26 June 2013 9:31:48 pm

Hi, Simone.

I think you would benefit greatly from implementing an extended_attribute_filter solution here, and do the actual filtering logic in sql. Both for the speed advantage it will give, but mostly for the improved readability of the template code.

Good luck. happy.gif Emoticon

Thursday 27 June 2013 11:48:01 am

Quote from // kracker :

Hello Simone,

It might help to post your code to a gist, pastebin or use share.ez.no source code formatting options. It would really help make your code more easily understandable and readable.

I noticed a solution article with a similar solution on eZpedia today: http://www.ezpedia.org/solution/how_to_fetch_content_based_on_view_parameter_date_range

I hope this helps

Cheers,
//kracker
Theme:  K.Flay - You Say ...
Mirror: https://soundcloud.com/kflay/k-flay-you-say

Unfortunately this is not what I need.

Thursday 27 June 2013 11:49:59 am

Quote from Arne Bakkebo :

Hi, Simone.

I think you would benefit greatly from implementing an extended_attribute_filter solution here, and do the actual filtering logic in sql. Both for the speed advantage it will give, but mostly for the improved readability of the template code.

Good luck. happy.gif Emoticon

I was afraid of this answer! sad.gif Emoticon

I really don't know how, but I'll try to implement an extended filter. Is it difficult? 

Thursday 27 June 2013 6:43:40 pm

Quote from Arne Bakkebo :

Hi, Simone.

I think you would benefit greatly from implementing an extended_attribute_filter solution here, and do the actual filtering logic in sql. Both for the speed advantage it will give, but mostly for the improved readability of the template code.

Good luck. happy.gif Emoticon

Hi, Simone

As Arne said implementing an extended_attribute_filter is the way to go, on our Blog at Mugo Web we have a post about it (Extended attribute filters: advanced content retrieval in eZ Publish), in that post we have created two extended_attribute_filter's one of them is to filter from common fields using multiple content classes, and the other one is to let us use multiple extended_attribute_filter's at a time, so you can do some complex filtering, and as well they are really easy to extend according to your needs.

Regards,

Ernesto Buenrostro

Thursday 27 June 2013 7:40:11 pm

The extended_attribute_filter concept is not really difficult, but requires a thorough understanding of SQL and the database structure of eZ Publish. However, once you learn it, the advantages in making flexible and clean fetch filters and sort options are overwhelming and infinite.

In addition to Ernestos url (I like your filters), you'll find an explanation and examples in the eZ Publish standard docs:

http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Modules/content/Fetch-functions/list#eztoc87605_0_0_6

I also recommend this page for an explanation on extended sorting:

http://www.ezpedia.org/ez/extended_sort

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from