Help with code: Comments in frontpage

Author Message

Shurbann Martes

Friday 02 January 2004 11:05:08 am

Im trying to make all the comments to shwo up in the frontpage of my site:

- The idea is to show them sorted by published date.
- The name of the news of wich the comment is made is shown.
- If there is a news with more then 1 comment, it will show only one, the most recent comment.

This is the code:
{let comment_parent_array=array(0) comment_list=fetch(content,list,hash(parent_node_id,2,limit,6,depth,5,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array('comment')))}
{section name=Comment loop=$comment_list}
{section show=not($comment_parent_array|contains($Comment:item.id)) comment_parent_array=$comment_parent_array|insert($Comment:item.id)}
{node_view_gui view=line content_node=$Comment:item}
{/section}
{/section}
{/let}

line_view_comment:
{let ParentNode=fetch(content,node,hash(node_id,$node.parent_node_id))}
<div class="small">{$node.object.published|datetime(custom,"%H:%i")} <a class="small" href={$ParentNode.url_alias|ezurl}>{$ParentNode.object.name|upfirst|shorten(20)}</a></div>

So 1 and 2 is accomplished but the last part I don't know how to do it.
Do you have some ideas?

-Shurbann

Shurbann Martes

Saturday 03 January 2004 3:03:39 am

Mabe I was not clear enough:

I want to just show the latest commment of each news.

Marco Zinn

Saturday 03 January 2004 4:14:10 am

Hi,

well, i didn't completely understand the code:
{let comment_parent_array=array(0) comment_list=fetch(content,list,hash(parent_node_id,2,limit,6,depth,5,sort_by,array(published,false()),class_filter_type,include,class_filter_array,array('comment')))}
{section name=Comment loop=$comment_list}
{section show=not($comment_parent_array|contains($Comment:item.id)) comment_parent_array=$comment_parent_array|insert($Comment:item.id)}
[..]
What is $comment_parent_array used for? You want to store the IDs of the articles in the array and check, if and ID already exists?
Nice idea :)

But you say, it does not work.
First, I thought "use max=1 in the loop", so you will get only one comment. But you seem to fetch all commments with one single fetch.
Then, maybe you should try something like this (pseudo-code ;) )
Fetch all articles
section loop=article
fetch all comments, where the current article is parent node, sorted by date
section loop=comments, max=1 show=comments
print comment with parent node name
/section
/section

This might work, but the drawback is, that you need LOTS of DB fetches.

Marco
http://www.hyperroad-design.com

Shurbann Martes

Saturday 03 January 2004 4:23:50 am

Ok Marco....

Thanks for the pseudo-code. I'm only going to put the last 8 comments more or less. So it means 8x more fetches :(

Yeah the idea was to put the ID's of the articles in the parent_array and check if it already exist in the array and if this is the case don't show the comment.. .
I think I have the well known problem with namesection. I have to print the array to see if it the array exist in that section.

But thanks for the idea. If I don't solve the problem above I will implement the code as you told me.
Cheers!!

-Shurbann

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 19 2025 04:17:53
Script start
Timing: Jan 19 2025 04:17:53
Module start 'layout'
Timing: Jan 19 2025 04:17:53
Module start 'content'
Timing: Jan 19 2025 04:17:54
Module end 'content'
Timing: Jan 19 2025 04:17:54
Script end

Main resources:

Total runtime0.7729 sec
Peak memory usage4,096.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0075 590.3125152.6250
Module start 'layout' 0.00750.0028 742.937539.4453
Module start 'content' 0.01030.7610 782.3828558.1328
Module end 'content' 0.77130.0016 1,340.515612.1563
Script end 0.7729  1,352.6719 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.4615160.0002
Check MTime0.00150.1901160.0001
Mysql Total
Database connection0.00140.181410.0014
Mysqli_queries0.712892.2267600.0119
Looping result0.00060.0722580.0000
Template Total0.739895.720.3699
Template load0.00250.317220.0012
Template processing0.737395.391920.3687
Template load and register function0.00020.023810.0002
states
state_id_array0.00180.232910.0018
state_identifier_array0.00090.122820.0005
Override
Cache load0.00200.2621530.0000
Sytem overhead
Fetch class attribute can translate value0.00080.108520.0004
Fetch class attribute name0.00100.135750.0002
XML
Image XML parsing0.00070.093320.0004
class_abstraction
Instantiating content class attribute0.00000.001350.0000
General
dbfile0.00090.1215160.0001
String conversion0.00000.001340.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
4content/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
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 27
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs