Author
|
Message
|
Eivind Marienborg
|
Wednesday 23 August 2006 7:52:04 am
Hi! 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 :) Eivind
|
Marcin Drozd
|
Wednesday 23 August 2006 8:43:11 am
Hi
I've created such a simply extension, but Ive never published. I can look for this one.
http://ez-publish.pl
|
Kristof Coomans
|
Wednesday 23 August 2006 9:19:45 am
Take a look at these topics:
http://ez.no/community/forum/general/show_events_for_the_next_x_days
http://ez.no/community/forum/developer/more_date_sorting
http://ez.no/community/forum/developer/custum_template_trouble http://ez.no/community/forum/general/get_last_published_article_since_a_date
independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org
|
Eivind Marienborg
|
Thursday 24 August 2006 1:46:07 am
Thanks for the replies :) 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?
|
Marcin Drozd
|
Thursday 24 August 2006 3:19:50 am
Hi Eivind
I've just found this extension. Perhaps U need this one. See http://ez.no/community/contribs/applications/count_object_by_classid_and_published_date
http://ez-publish.pl
|
Eivind Marienborg
|
Thursday 24 August 2006 4:40:41 am
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()
$current=gettime($currentDate)
$timestamp = maketime( 0, 0, 0, $current.month, $current.day, $current.year )}
{let medlemmer=fetch( objectcountdate, object_count_date, hash( class_id, 2,
date_from, $timestamp,
date_to, $currentDate) ) }
nye medlemmer: {$medlemmer}
{/let}
This outputs:
nye medlemmer: 0
Using only the date_from like this:
{def $currentDate=currentdate()
$current=gettime($currentDate)
$timestamp = maketime( 0, 0, 0, $current.month, $current.day, $current.year )}
{let medlemmer=fetch( objectcountdate, object_count_date, hash( class_id, 4,
date_from, $timestamp ) ) }
nye medlemmer: {$medlemmer}
{/let}
outputs:
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! :)
|
Marcin Drozd
|
Thursday 24 August 2006 5:59:19 am
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 ?
http://ez-publish.pl
|
Eivind Marienborg
|
Thursday 24 August 2006 6:19:36 am
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?
|
Claudia Kosny
|
Thursday 24 August 2006 6:45:41 am
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 Claudia
|
Marcin Drozd
|
Thursday 24 August 2006 9:18:33 am
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?) Thanks
http://ez-publish.pl
|
Eivind Marienborg
|
Thursday 24 August 2006 11:00:55 am
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..
|
Kristof Coomans
|
Thursday 24 August 2006 11:42:43 am
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 http://ez.no/community/forum/setup_design/fetch_limitation_parameter
independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org
|
Claudia Kosny
|
Thursday 24 August 2006 11:45:53 am
Hi there, @Marcin: 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.
@Eivind 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 Claudia
|
Kristof Coomans
|
Thursday 24 August 2006 11:53:45 am
tree_count and list_count actually use the same PHP function, they only have other default parameters. Same case for tree and list.
independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org
|
Eivind Marienborg
|
Thursday 24 August 2006 12:00:05 pm
Ah, great! Works like a charm :D And for the norwegian speaking of you, you can see the code in action at http://www.diil.no/d0607/users/statusrapport :) Thanks for your help!
|
meriam santos
|
Sunday 23 November 2008 11:18:33 am
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.... meriam
|