Latest forum activity - how to fetch

Author Message

Radek Kuchta

Wednesday 03 October 2007 9:03:31 am

Hi,

How to use fetch function to get latest forum activity? - the same as here: http://ez.no/developer (with a number of reply).

http://ez.no/certification/verify/272582

Mads Ovesen

Saturday 06 October 2007 12:54:31 pm

Asuming each forum activity is a node in the content tree:

{$array = fetch( 'content', 'list', hash( 'parent_node_id', <parent_node_id>,
                                                     'class_filter_type', 'include',
                                                     'class_filter_array', array( 'forum_activity' ),
                                                     'limit',10,
                                                     'sort_by', array( 'published', false() ) ) ) }

/m

Radek Kuchta

Tuesday 09 October 2007 11:11:19 am

Hi Mads,

I know that each forum activity is a node (the same is a forum topic and a forum reply).
But what I need, is a fetch that bring me a last forum reply (as a <b>unique</b> link to that reply - the last reply to the topic, like in the right column here http://ez.no/developer). I think taht regular content tree function is not enough.

http://ez.no/certification/verify/272582

André R.

Tuesday 09 October 2007 1:13:18 pm

Well you need to sort by modified_subnode, add a loop to loop over the array and count its children(the replys).

something like this:

{def $topics = fetch( 'content', 'tree', hash( 
                            'parent_node_id', <parent_node_id>, 
                            'class_filter_type', 'include', 
                            'class_filter_array', array( 'forum_topic' ), 
                            'limit', 10,
                            'depth', 4,
                            'depth_operator', 'lt',
                            'load_data_map', false(),
                            'sort_by', array( 'modified_subnode', false() ) ) ) }
{if $topics}
  {foreach $topics as $topic}
    <a href={$topic.url_alias|ezurl}>{$topic.name|wash}</a> ({$topic.children_count})<br />
  {/foreach}
{/if}

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Ole Morten Halvorsen

Wednesday 10 October 2007 2:18:23 am

Hi,

As André mentioned, you need to fetch forum messages sorted on modified_subnode.

Here's the code we use to generate the Latest forum activity on ez.no/developer.

{let forum_list=fetch_alias( lastest_forum_replies, hash( parent_node_id, 308 ) )}
{section show=$forum_list}
    <ul class="linklist">
        {section loop=$forum_list}
            {let last_reply_array=fetch_alias( last_forum_reply, hash( parent_node_id, $:item.node_id ))
                 last_reply=$last_reply_array.0}
            <li>
                {section show=$:last_reply}
                    {node_view_gui view=listitem content_node=$:last_reply show_extra_info=true()}
                {section-else}
                    {node_view_gui view=listitem content_node=$:item show_extra_info=true()}
                {/section}
            </li>
            {/let}
        {/section}
        </ul>
{/section}
{/let}

- lastest_forum_replies is defined as following:

[lastest_forum_replies]
Module=content
FunctionName=tree
Parameter[parent_node_id]=parent_node_id
Constant[sort_by]=modified_subnode;0
Constant[depth]=2
Constant[limit]=10
Constant[class_filter_type]=include
Constant[class_filter_array]=forum_message

- last_forum_reply is defined like this:

[last_forum_reply]
Module=content
FunctionName=list
Parameter[parent_node_id]=parent_node_id
Constant[sort_by]=published;0
Constant[limit]=1
Constant[class_filter_type]=include
Constant[class_filter_array]=forum_message

Here's the listitem view for the forum message:

{* List item for form message *}

{* Parameters:
   - show_extra_info = Boolean true(), false()
     Shows extra info such as date, author and number of replies.
     Typicaly used by the community frontpage.
     Default is false()
*}

<div class="content-view-list">
<div class="class-forummessage">

{def $post_count_html=""}

{if $node.parent.object.contentclass_id|eq( 14 )}
    {def $offset=0
         $post_count=$node.parent.children_count}
    
    {if $show_extra_info}
        {set $post_count_html=concat('&nbsp;<span class="forum-replies">(', $post_count, ')</span>' )}
    {/if}
    {include uri="design:parts/forum/calc_offset.tpl" count=$post_count}

    {if $offset|le( 0 )}
        <h3><a title="Posted by: {$node.object.owner.name}: {$node.data_map.message.content|wash|shorten( 400 )}" href={concat( $node.parent.url_alias, '#msg', $node.node_id )|ezurl}>{$node.parent.name|wash}</a>{$post_count_html}</h3>
    {else}
        <h3><a title="Posted by: {$node.object.owner.name}: {$node.data_map.message.content|wash|shorten( 400 )}" href={concat( $node.parent.url_alias, '/(offset)/', $offset, '/#msg', $node.node_id )|ezurl}>{$node.parent.name|wash}</a>{$post_count_html}</h3>
    {/if}
{else}
    {if $show_extra_info}
        {set $post_count_html='&nbsp;<span class="forum-replies">(0)</span>'}
    {/if}
    
    <h3><a title="Posted by: {$node.object.owner.name}: {$node.data_map.message.content|wash|shorten( 400 )}" href={concat( $node.url_alias, '#msg', $node.node_id )|ezurl}>{$node.name|wash}</a>{$post_count_html}</h3>
{/if}

{if $show_extra_info}
    <div class="attribute-byline float-break">
        <p class="date">{$node.object.published|l10n( 'shortdatetime' )}</p>
        <p class="author">{$node.object.owner.name}</p>
    </div>
{/if}

</div>
</div>

and finally the "calc_offset.tpl" template which does just that, calculate the offset.

{set offset=$count|div( 20 )|ceil()|sub( 1 )|mul( 20 )}

Make sure you add an unique anchor each of your forum messages when viewing a thread. The {$node.node_id} is perfect for that.
I hope this helps :)

Senior Software Engineer - Vision with Technology

http://www.visionwt.com
http://www.omh.cc
http://www.twitter.com/omh

eZ Certified Developer
http://ez.no/certification/verify/358441
http://ez.no/certification/verify/272578

Radek Kuchta

Sunday 14 October 2007 8:32:52 am

Ole, It is exactly what I need. It works correctly of course. Thanks a lot.

http://ez.no/certification/verify/272582

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 07:28:13
Script start
Timing: Jan 19 2025 07:28:13
Module start 'layout'
Timing: Jan 19 2025 07:28:13
Module start 'content'
Timing: Jan 19 2025 07:28:14
Module end 'content'
Timing: Jan 19 2025 07:28:14
Script end

Main resources:

Total runtime1.2941 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.0061 589.2578152.6250
Module start 'layout' 0.00610.0040 741.882839.4453
Module start 'content' 0.01011.2825 781.3281674.9063
Module end 'content' 1.29250.0015 1,456.234420.7813
Script end 1.2940  1,477.0156 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.2407160.0002
Check MTime0.00130.1008160.0001
Mysql Total
Database connection0.00110.086110.0011
Mysqli_queries1.221194.3645700.0174
Looping result0.00070.0538680.0000
Template Total1.247996.420.6240
Template load0.00210.163020.0011
Template processing1.245896.270720.6229
Template load and register function0.00010.008110.0001
states
state_id_array0.00130.099810.0013
state_identifier_array0.00120.094420.0006
Override
Cache load0.00180.1387370.0000
Sytem overhead
Fetch class attribute can translate value0.00060.048240.0002
Fetch class attribute name0.00090.069080.0001
XML
Image XML parsing0.00160.124340.0004
class_abstraction
Instantiating content class attribute0.00000.0016100.0000
General
dbfile0.00960.7437230.0004
String conversion0.00000.000840.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/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
6content/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
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.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: 7

Time used to render debug report: 0.0001 secs