This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Setup & design » Fetch by published date

Fetch by published date

Fetch by published date

Wednesday 23 August 2006 4:52:04 pm - 15 replies


I want to make a list of how many articles etc have been published the last 24hours/the last day.

I've looked into attribute-fetch, but it seems as you can only fetch on class attributes you specify for yourself (like title, intro etc), and not on obligational ez attributes, like published?

I also thought about using the publish_date of the search fetch, but that gets stopped by having to enter text, and I only want to search by class id and published date.

Does anyone have any hints? Any help is greatly appriciated happy.gif Emoticon


Wednesday 23 August 2006 5:43:11 pm

I've created such a simply extension, but Ive never published.
I can look for this one.

Wednesday 23 August 2006 6:19:45 pm

Take a look at these topics:

Thursday 24 August 2006 10:46:07 am

Thanks for the replies happy.gif Emoticon

All the links were using attributes containing dates to narrow down the fetch (like from_date and to_date).

But I want to use the publish-date of the object ($node.published). Anyone got anything on this?

Thursday 24 August 2006 12:19:50 pm

Hi Eivind
I've just found this extension. Perhaps U need this one.

Thursday 24 August 2006 1:40:41 pm

Hi Marcin, and thanks alot!

I've got the extension up and running, but I'm running in to some problems.

I'm using the following template code:

{def $currentDate=currentdate()
    $timestamp = maketime( 0, 0, 0, $current.month, $, $current.year )}

{let medlemmer=fetch( objectcountdate, object_count_date, hash( class_id, 2,
                        date_from, $timestamp,
                        date_to,  $currentDate) ) }

nye medlemmer: {$medlemmer}

This outputs:

nye medlemmer: 0

Using only the date_from like this:

{def $currentDate=currentdate()
    $timestamp = maketime( 0, 0, 0, $current.month, $, $current.year )}

{let medlemmer=fetch( objectcountdate, object_count_date, hash( class_id, 4,
                        date_from, $timestamp ) ) }

nye medlemmer: {$medlemmer}



nye medlemmer: 8

The problem is that I know we've had almost 100 hundred new objects of this class the last 24 hours, most of them during today. What could be wrong? Do I need any further setup than unpacking and enabling the extension?

Looks like a nice extension, though! happy.gif Emoticon

Thursday 24 August 2006 2:59:19 pm

Hi Eivind
I've just installed this extension, and pasted your first code (and add some articles) and it works for me, hmmm

I observed on your first and the second code, class_id, 2 and class_id, 4.
Could U try first code with class_id, 4 ?

Thursday 24 August 2006 3:19:36 pm

Ah, my bad about the class_id, sorry.

When corrected to 4 (which is, correctly, the user class), they both display 8.

Does it search the entire content tree? Since the users are stored under User Accounts and not Content, that might be a problem, I mean?

Thursday 24 August 2006 3:45:41 pm

Hello Eivind,

As far as I know the basic fetch functionfor content nodes can actually do attribute filtering on the 'published' date (and on the 'priority') of a node (it also says so in the documentation). So no extension needed.
Here an example:

{def $startTime = currentdate()|sub(24|mul(3600))
     $newNodesCnt = fetch('content', 'tree_count', hash('parent_node_id', 2,
                              'attribute_filter', array(array('published', '>=', $startTime))))}

First the start of the timeperiod is defined, which is the current time (as unix timestamp) minus one day (24 times 3600 seconds). Then only the nodes whose published date is later or equal to the start of the timeperiod are fetched.

Greetings from Luxembourg


Thursday 24 August 2006 6:18:33 pm

Hi Claudia
U are right, and we can use 'modified_subnode' too,
but I'm not convinced that fetch(tree_count) with parent_node_id=2 is really fast.
I think that the simple SQL query is (much?) faster than tree_count (but I dont know how many object should I have?)

Thursday 24 August 2006 8:00:55 pm

Hi Claudia, and thanks, your code works great!

And now for something completely different! Ehrm, I mean, related:

I'm using this counter as a teaser for the not logged in users on my site, like telling them "200 forum posts last 24 hours, 150 messages sent last 24 hours" and so on, to make them register.

But the problem is that with a list_count, they'll only get a count of the nodes they're allowed to see (by permissions settings), which is, when not logged in, <i>none</i>.

So, does anybody have any ideas here? One sollution is granting them read access to the different classes, and then doing permission-checking on a template-level, but I don't think that will be very easy on the system load..

Thursday 24 August 2006 8:42:43 pm

You can use the limitation parameter with an empty array, then all read policies will be bypassed.

$newNodesCnt = fetch('content', 'tree_count', hash('parent_node_id', 2, 'limitation', array(),
                             'attribute_filter', array(array('published', '>=', $startTime))))}

See also

Thursday 24 August 2006 8:45:53 pm

Hi there,


Frankly I have no idea about what is faster. The tree_count makes only two sql queries so I don't think that you can be much faster using an extension. On the other hand the tree_count takes about 100 ms on my server (which is admittedly very slow) so if you have any ideas tell me.

You can use the limitiation parameter from the 'list' fetch function here as well. Although it is not directly mentioned in the documentation it works alright (at least on the tree_count, I have not tried the list_count). So just add 'limitation', array() to your hash and you should get all nodes.

Greetings from Luxembourg


Thursday 24 August 2006 8:53:45 pm

tree_count and list_count actually use the same PHP function, they only have other default parameters. Same case for tree and list.

Thursday 24 August 2006 9:00:05 pm

Ah, great! Works like a charm big-smile.gif Emoticon

And for the norwegian speaking of you, you can see the code in action at happy.gif Emoticon

Thanks for your help!

Modified on Wednesday 30 August 2006 11:10:53 am by Eivind Marienborg

Sunday 23 November 2008 8:18:33 pm

Hi there,

Can somebody help me on this please? Newbie to the system.

i have a page the displays the line view(summary of records) in a folder. i want to display the date each record has been published.

i can only display the date published if i display the detailed info but not on the line view.

when i use this code - {$node.object.published|l10n( shortdatetime )}

it only display the date of the folder. not the date of the sub items in the folder.

thanks heaps....



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

36 542 Users on board!

Forums menu

Proudly Developed with from