Forums / Developer / Sorting and Selectively Displaying Custom Objects By Date/String Attribute

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

eZ debug

Timing: Jan 18 2025 19:09:36
Script start
Timing: Jan 18 2025 19:09:36
Module start 'content'
Timing: Jan 18 2025 19:09:37
Module end 'content'
Timing: Jan 18 2025 19:09:37
Script end

Main resources:

Total runtime1.0438 sec
Peak memory usage4,096.0000 KB
Database Queries194

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0079 588.0938180.7813
Module start 'content' 0.00790.8649 768.8750529.2422
Module end 'content' 0.87290.1709 1,298.1172336.7109
Script end 1.0437  1,634.8281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00440.4175210.0002
Check MTime0.00170.1585210.0001
Mysql Total
Database connection0.00180.167910.0018
Mysqli_queries0.953691.36001940.0049
Looping result0.00270.26291920.0000
Template Total1.012097.020.5060
Template load0.00210.197020.0010
Template processing1.009996.753920.5050
Template load and register function0.00010.010110.0001
states
state_id_array0.00150.141710.0015
state_identifier_array0.00090.083220.0004
Override
Cache load0.00150.1477640.0000
Sytem overhead
Fetch class attribute can translate value0.00200.188230.0007
Fetch class attribute name0.00160.152440.0004
XML
Image XML parsing0.00100.091930.0003
class_abstraction
Instantiating content class attribute0.00000.001350.0000
General
dbfile0.00540.5136270.0002
String conversion0.00000.000730.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 6

Time used to render debug report: 0.0002 secs