Two fetches, one order

Author Message

Lo' F.

Friday 03 December 2010 10:43:48 am

Hi!

I was wondering...

I have two fetch statements retrieving objects of a specific class.

The first fetches a number of objects (10) having a certain attribute set to true.

The second one fetches the objects only if the first one gets less then the limit set to 10.

Something like this...

{def $sel_items=fetch('content', 'tree', hash('parent_node_id', 2, 'sort_by', array('attribute', false(), 'article/publish_date'), 'class_filter_type', 'include', 'class_filter_array', array('article'), 'limit', 10, 'attribute_filter', array(array('article/highlight', '=', 1))))}



{def $counter=0}
{foreach $sel_items as $sel_item}
{set $counter= inc($counter)}
  ...
{/foreach}

{def $limit = 10|sub($counter) }
{if $limit|gt(0)}
{def $fill_items=fetch('content', 'tree', hash('parent_node_id', 2, 'sort_by', array('attribute', false(), 'article/publish_date'), 'class_filter_type', 'include', 'class_filter_array', array('article'), 'limit', $limit, 'attribute_filter', array(array('article/highlight', '=', 0))))}



{foreach $fill_items as $fill_item}
  ...
{/foreach}

I need to sort them by their publish date, but in this way I get two separated lists sorted by date.

e.g. 2.12.2010 - 30.11.2010 - 28.11.2010 (1st fetch) - 1.12.2010 - 29.11.2010 - 25.11.2010 - ... (2nd fetch)

I can't figure out how to list these two giving a unique discending order...

What can you suggest?

loredanaebook.it

Jean-Luc Chassaing

Friday 03 December 2010 11:57:08 pm

Hello,

Why don't you make one single fetch using a double sort array so you can sort them by your attribute "article/highlight" and then by publish date with a limit of 10. So that you'll first have the highlighted nodes listed by publish date and then the others..

Lo' F.

Saturday 04 December 2010 6:15:19 am

"

Why don't you make one single fetch using a double sort array so you can sort them by your attribute "article/highlight" and then by publish date with a limit of 10. So that you'll first have the highlighted nodes listed by publish date and then the others..

"

Hi Jean-Luc, thanks for your reply. Surely a neater way ..

{def $items=fetch('content', 'tree', hash('parent_node_id', 2, 'sort_by', array( array( 'attribute', false(), 'article/highlight' ), array(  'attribute', false(), 'article/publish_date')), 'class_filter_type', 'include', 'class_filter_array', array('article'), 'limit', 10))}
...

But what I need to do is arranging those fetched items according to their publish date and push the highlithed ones in the list keeping just one order

In other words, instead of getting this result..

e.g. 2.12.2010 - 30.11.2010 - 28.11.2010 (the highlighted ones) - 1.12.2010 - 29.11.2010 - 25.11.2010 - ... (the others)

I should get..

2.12.2010 (highlighted) - 1.12.2010 - 30.11.2010 (highlighted) - 29.11.2010 - 28.11.2010 (highlighted) - 25.11.2010 - ...

Well, someone may say "then why don't you just sort by date without using any attribute_filter?!"

The thing is that if the 10th item is dated, let's say, 30.7.2010, and there's a need to highlight one dated 1.7.2010, this one should be forced to be the last of the list of 10 items and get the place of 30.7.2010...

loredanaebook.it

Jean-Luc Chassaing

Sunday 05 December 2010 12:38:34 am

Ok,

So let me just try to turn that an other way... you want to sort your items from the oldest one to the soonest and I suppose that if two of them have the same publish date, the highlighted one should come first.

But if the 10th is not highlighted and there is a sooner one highlighted, you want it to take the 10th rank.

As you said, why don't you just sort them by publish date and highlighted but the other way from the sonest to the oldest.... And if you want them to apear in the oder way just display the result array from the last to the first one.

Lo' F.

Sunday 05 December 2010 8:05:48 am

"

So let me just try to turn that an other way... you want to sort your items from the oldest one to the soonest and I suppose that if two of them have the same publish date, the highlighted one should come first.

But if the 10th is not highlighted and there is a sooner one highlighted, you want it to take the 10th rank.

"

..Precisely!

But by sorting them this way I still get the two sets of dates as two separated blocks (when the first ends the other set starts), while I need to force the highlighted items inside the list of ten (pushing the others away if there's not space for them) but always keeping one sequence of date from the latest to the oldest...

How can I sort the result array based on this logic? Do I need to make something up inside the foreach before I can display them?

loredanaebook.it

Jean-Luc Chassaing

Sunday 05 December 2010 1:21:14 pm

I think you should make your on tool to solv your problem. Otherwise you'll have to make to much "php like" data manipulation in your template.

To do so, you can have a look to this tutorial to make your on fetch function : http://share.ez.no/learn/ez-publish/understanding-and-developing-fetch-functions .

And other way would be to make a template operator.

Lo' F.

Monday 06 December 2010 10:40:32 am

Thanks!

I will look into it and give a try to make a custom fetch or a template operator.

Hope to come back soon with a nice solution!

loredanaebook.it

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 18 2025 04:56:33
Script start
Timing: Jan 18 2025 04:56:33
Module start 'layout'
Timing: Jan 18 2025 04:56:33
Module start 'content'
Timing: Jan 18 2025 04:56:34
Module end 'content'
Timing: Jan 18 2025 04:56:34
Script end

Main resources:

Total runtime1.1941 sec
Peak memory usage4,096.0000 KB
Database Queries70

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0102 587.8906152.6094
Module start 'layout' 0.01030.0037 740.500039.4219
Module start 'content' 0.01401.1788 779.9219604.7734
Module end 'content' 1.19280.0012 1,384.695320.8125
Script end 1.1940  1,405.5078 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00380.3152160.0002
Check MTime0.00140.1138160.0001
Mysql Total
Database connection0.00160.131710.0016
Mysqli_queries1.108692.8409700.0158
Looping result0.00070.0574680.0000
Template Total1.152496.520.5762
Template load0.00200.170720.0010
Template processing1.150396.338620.5752
Template load and register function0.00010.009610.0001
states
state_id_array0.00080.069310.0008
state_identifier_array0.00110.090920.0005
Override
Cache load0.00190.1570570.0000
Sytem overhead
Fetch class attribute can translate value0.00090.077020.0005
Fetch class attribute name0.00120.099190.0001
XML
Image XML parsing0.00310.261220.0016
class_abstraction
Instantiating content class attribute0.00000.0030140.0000
General
dbfile0.00460.3870220.0002
String conversion0.00000.000940.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
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/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
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 33
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs