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.

eZ debug

Timing: Jan 31 2025 06:25:47
Script start
Timing: Jan 31 2025 06:25:47
Module start 'layout'
Timing: Jan 31 2025 06:25:47
Module start 'content'
Timing: Jan 31 2025 06:25:48
Module end 'content'
Timing: Jan 31 2025 06:25:48
Script end

Main resources:

Total runtime1.1550 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0055 588.6250151.2734
Module start 'layout' 0.00550.0029 739.898436.7266
Module start 'content' 0.00841.1458 776.6250947.4297
Module end 'content' 1.15410.0009 1,724.054711.7500
Script end 1.1550  1,735.8047 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.2690160.0002
Check MTime0.00130.1120160.0001
Mysql Total
Database connection0.00100.085510.0010
Mysqli_queries1.082993.7564570.0190
Looping result0.00050.0457550.0000
Template Total1.116196.620.5580
Template load0.00220.188120.0011
Template processing1.113996.435420.5569
Template load and register function0.00110.095610.0011
states
state_id_array0.00160.136010.0016
state_identifier_array0.00170.148620.0009
Override
Cache load0.00190.1662640.0000
Sytem overhead
Fetch class attribute can translate value0.00050.045820.0003
Fetch class attribute name0.00240.208440.0006
XML
Image XML parsing0.00170.143220.0008
class_abstraction
Instantiating content class attribute0.00000.001150.0000
General
dbfile0.00190.1684160.0001
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
12content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
9content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs