Sorting and Selectively Displaying Custom Objects By Date/String Attribute

Author Message

Paul Wilson

Thursday 25 September 2003 5:08:52 am

##CORE ISSUE/QUESTION

I have two strings representing dates for custom "event" objects and want to use these to display only current events in a folder.

...Anyone got any good ideas? I think it should be simple - my objective and approach so far is outlined below.

## OBJECTIVE
To create a folder containing events objects that are sorted by the event's date, and to only display the events that are >= today

##APPROACH SO FAR

In work towards this objective , I have:
- Created a custom "events" object
- This includes a textline attribute (event_date) to represent the event date.
- The event_date attribute is used in the "object name pattern" of the Event Class (ie <event_date> | <name>). This allows me to use the Folder sort settings to put the events into event_date order.
- I've created a folder template to display a brief section of introductory text and each of the events.

##PROBLEM

Almost everything works well ... events are displayed in event_date order, BUT I can't seem to get the logic for only displaying events with event_date >=today.

Summarised, template code for the folder is as follows:

{* code to display folder header details *}

{* select the event objects (id 17), sort by name *}

{section loop=fetch(content,list,hash(parent_node_id,$node.node_id, class_filter_type, "include", class_filter_array, array(17),sort_by,array(array(name))))}

{* PROBLEM HERE - decide whether objectdate >=today *}

{section show=ge($:item.data_map.event_date.data_text,currentdate()|datetime(custom,"20%y-%m-%d"))}

{* code to display a current event goes here *}

{/section}
{/section}

==
Looking at the values,
{$:item.data_map.event_final_date.data_text} =shows=> "2003-10-10"

and

{currentdate()|datetime(custom,"20%y-%m-%d")} =shows=> "2003-09-25"

##PLEA FOR HELP!

Any ideas on the right way to use these two values to select between events >= today? Is there another better approach?

Any thoughts, hints or insights gratefully accepted!

Thanks & happy coding

- Paul

Paul Wilson

Thursday 25 September 2003 11:56:04 pm

Problem Solved.

For anyone interested and keen enough to read some or all of the above, the code/method I used was as follows...

{let year=currentdate()|datetime(custom,"%Y")}
{let month=currentdate()|datetime(custom,"%m")}
{let day=currentdate()|datetime(custom,"%d")}

{* class 17 is my "events" class *}
{section loop=fetch(content,list,hash(parent_node_id,$node.node_id, class_filter_type, "include", class_filter_array, array(17),sort_by,array(array(name))))}

{let eventyear=$:item.data_map.event_final_date_std.content.year}
{let eventmonth=$:item.data_map.event_final_date_std.content.month}
{let eventday=$:item.data_map.event_final_date_std.content.day}

{* Remove Past Events From Display *}
{section show=or($eventyear|gt($year), and($eventyear|eq($year),$eventmonth|gt($month)), and($eventyear|eq($year),$eventmonth|eq($month),$eventday|ge($day)))}

>>> Code to display current event goes here <<<

{ /section }
{/let}
{/let}
{/let}
{/section}
{/let}
{/let}
{/let}

Regards

- Paul

Mubdi Rahman

Wednesday 01 September 2004 6:44:52 pm

Beautiful, absolutely beautiful! Thanks so much Paul!

-Mubdi

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.